]> khamidou — GitHub mirrors - electron.git/commitdiff
Implement browser related functions in Windows.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 4 Jul 2013 12:58:28 +0000 (20:58 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 4 Jul 2013 12:58:28 +0000 (20:58 +0800)
atom.gyp
browser/browser_win.cc [new file with mode: 0644]

index 533ffcb11dd7da24f558053e143b0bc75629a6dc..f45b7f870120cfec3630a5b18a144f8be5e51d04 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -81,6 +81,7 @@
       'browser/browser.cc',
       'browser/browser.h',
       'browser/browser_mac.mm',
+      'browser/browser_win.cc',
       'browser/browser_observer.h',
       'browser/crash_reporter.h',
       'browser/crash_reporter_mac.mm',
diff --git a/browser/browser_win.cc b/browser/browser_win.cc
new file mode 100644 (file)
index 0000000..786ec87
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "browser/browser.h"
+
+#include <windows.h>
+
+#include "base/base_paths.h"
+#include "base/file_version_info.h"
+#include "base/files/file_path.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/path_service.h"
+#include "base/strings/utf_string_conversions.h"
+
+namespace atom {
+
+namespace {
+
+BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
+  DWORD target_process_id = *reinterpret_cast<DWORD*>(param);
+  DWORD process_id = 0;
+
+  GetWindowThreadProcessId(hwnd, &process_id);
+  if (process_id == target_process_id) {
+    SetFocus(hwnd);
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
+}  // namespace
+
+void Browser::Terminate() {
+  is_quiting_ = true;
+  PostQuitMessage(0);
+}
+
+void Browser::Focus() {
+  // On Windows we just focus on the first window found for this process.
+  DWORD pid = GetCurrentProcessId();
+  EnumWindows(&WindowsEnumerationHandler, reinterpret_cast<LPARAM>(&pid));
+}
+
+std::string Browser::GetVersion() {
+  base::FilePath path;
+  if (PathService::Get(base::FILE_EXE, &path)) {
+    scoped_ptr<FileVersionInfo> version_info(
+        FileVersionInfo::CreateFileVersionInfo(path));
+    return UTF16ToUTF8(version_info->product_version());
+  }
+
+  return "";
+}
+
+void Browser::CancelQuit() {
+  // TODO: Research on how to cancel shutdown in Windows.
+}
+
+}  // namespace atom