Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Unified Diff: chrome/browser/process_singleton_win.cc

Issue 10824387: Implement forwarding of search queries for metro mode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/process_singleton_win.cc
===================================================================
--- chrome/browser/process_singleton_win.cc (revision 151723)
+++ chrome/browser/process_singleton_win.cc (working copy)
@@ -10,6 +10,7 @@
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/utf_string_conversions.h"
+#include "base/win/metro.h"
#include "base/win/scoped_handle.h"
#include "base/win/wrapped_window_proc.h"
#include "chrome/browser/ui/simple_message_box.h"
@@ -112,6 +113,21 @@
return false;
}
+// Find any top level, visible chrome window. The name is fragile
+// but the file that defines the name warns against modification.
+BOOL CALLBACK TopWindowFinder(HWND hwnd, LPARAM result) {
+ char classname[128];
+ if (::GetClassNameA(hwnd, classname, arraysize(classname))) {
+ if (IsWindowVisible(hwnd)) {
+ if (lstrcmpiA("Chrome_WidgetWin_1", classname) == 0) {
+ *reinterpret_cast<HWND*>(result) = hwnd;
+ return FALSE;
+ }
+ }
+ }
+ return TRUE;
+}
+
} // namespace
// Microsoft's Softricity virtualization breaks the sandbox processes.
@@ -239,7 +255,42 @@
else if (!remote_window_)
return PROCESS_NONE;
- // Found another window, send our command line to it
+ DWORD process_id = 0;
+ DWORD thread_id = GetWindowThreadProcessId(remote_window_, &process_id);
+ // It is possible that the process owning this window may have died by now.
+ if (!thread_id || !process_id) {
+ remote_window_ = NULL;
+ return PROCESS_NONE;
+ }
+
+ if (base::win::IsMetroProcess()) {
+ // Interesting corner case. We are launched as a metro process but we
+ // found another chrome running. Since metro enforces single instance then
+ // the other chrome must be desktop chrome and this must be a search charm
+ // activation. This scenario is unique; other cases should be properly
+ // handled by the delegate_execute which will not activate a second chrome.
+ string16 url;
+ base::win::MetroLaunchType launch = base::win::GetMetroLaunchParams(&url);
+ if (launch != base::win::METRO_SEARCH) {
+ LOG(WARNING) << "In metro mode, but and launch is " << launch;
+ } else {
+ // Need to find a top level window widget, the |remote_window_| does not
+ // handle the search navigation message.
+ HWND top_widget = NULL;
+ EnumThreadWindows(thread_id, &TopWindowFinder, LPARAM(&top_widget));
+ if (top_widget) {
+ UINT search_message =
+ RegisterWindowMessage(chrome::kMetroNavigationAndSearchMessage);
+ ATOM atom = GlobalAddAtomW(url.c_str());
+ PostMessage(top_widget, search_message, 0, atom);
+ LOG(INFO) << "Sent search term " << url;
+ } else {
+ LOG(WARNING) << "Could not find top level window";
+ }
+ }
+ return PROCESS_NOTIFIED;
+ }
+ // Non-metro mode, send our command line to the other chrome message window.
// format is "START\0<<<current directory>>>\0<<<commandline>>>".
std::wstring to_send(L"START\0", 6); // want the NULL in the string.
FilePath cur_dir;
@@ -252,14 +303,6 @@
// Allow the current running browser window making itself the foreground
// window (otherwise it will just flash in the taskbar).
- DWORD process_id = 0;
- DWORD thread_id = GetWindowThreadProcessId(remote_window_, &process_id);
- // It is possible that the process owning this window may have died by now.
- if (!thread_id || !process_id) {
- remote_window_ = NULL;
- return PROCESS_NONE;
- }
-
AllowSetForegroundWindow(process_id);
COPYDATASTRUCT cds;

Powered by Google App Engine
This is Rietveld 408576698