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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/process_singleton.h" 5 #include "chrome/browser/process_singleton.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/process_util.h" 11 #include "base/process_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/win/metro.h"
13 #include "base/win/scoped_handle.h" 14 #include "base/win/scoped_handle.h"
14 #include "base/win/wrapped_window_proc.h" 15 #include "base/win/wrapped_window_proc.h"
15 #include "chrome/browser/ui/simple_message_box.h" 16 #include "chrome/browser/ui/simple_message_box.h"
16 #include "chrome/common/chrome_constants.h" 17 #include "chrome/common/chrome_constants.h"
17 #include "chrome/installer/util/wmi.h" 18 #include "chrome/installer/util/wmi.h"
18 #include "content/public/common/result_codes.h" 19 #include "content/public/common/result_codes.h"
19 #include "grit/chromium_strings.h" 20 #include "grit/chromium_strings.h"
20 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/win/hwnd_util.h" 23 #include "ui/base/win/hwnd_util.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 106
106 // Get command line. 107 // Get command line.
107 const std::wstring cmd_line = 108 const std::wstring cmd_line =
108 msg.substr(second_null + 1, third_null - second_null); 109 msg.substr(second_null + 1, third_null - second_null);
109 *parsed_command_line = CommandLine::FromString(cmd_line); 110 *parsed_command_line = CommandLine::FromString(cmd_line);
110 return true; 111 return true;
111 } 112 }
112 return false; 113 return false;
113 } 114 }
114 115
116 // Find any top level, visible chrome window. The name is fragile
117 // but the file that defines the name warns against modification.
118 BOOL CALLBACK TopWindowFinder(HWND hwnd, LPARAM result) {
119 char classname[128];
120 if (::GetClassNameA(hwnd, classname, arraysize(classname))) {
121 if (IsWindowVisible(hwnd)) {
122 if (lstrcmpiA("Chrome_WidgetWin_1", classname) == 0) {
123 *reinterpret_cast<HWND*>(result) = hwnd;
124 return FALSE;
125 }
126 }
127 }
128 return TRUE;
129 }
130
115 } // namespace 131 } // namespace
116 132
117 // Microsoft's Softricity virtualization breaks the sandbox processes. 133 // Microsoft's Softricity virtualization breaks the sandbox processes.
118 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to 134 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to
119 // break out of the virtualization environment. 135 // break out of the virtualization environment.
120 // http://code.google.com/p/chromium/issues/detail?id=43650 136 // http://code.google.com/p/chromium/issues/detail?id=43650
121 bool ProcessSingleton::EscapeVirtualization(const FilePath& user_data_dir) { 137 bool ProcessSingleton::EscapeVirtualization(const FilePath& user_data_dir) {
122 if (::GetModuleHandle(L"sftldr_wow64.dll") || 138 if (::GetModuleHandle(L"sftldr_wow64.dll") ||
123 ::GetModuleHandle(L"sftldr.dll")) { 139 ::GetModuleHandle(L"sftldr.dll")) {
124 int process_id; 140 int process_id;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 248 }
233 249
234 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { 250 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() {
235 if (is_virtualized_) 251 if (is_virtualized_)
236 return PROCESS_NOTIFIED; // We already spawned the process in this case. 252 return PROCESS_NOTIFIED; // We already spawned the process in this case.
237 if (lock_file_ == INVALID_HANDLE_VALUE && !remote_window_) 253 if (lock_file_ == INVALID_HANDLE_VALUE && !remote_window_)
238 return LOCK_ERROR; 254 return LOCK_ERROR;
239 else if (!remote_window_) 255 else if (!remote_window_)
240 return PROCESS_NONE; 256 return PROCESS_NONE;
241 257
242 // Found another window, send our command line to it 258 DWORD process_id = 0;
259 DWORD thread_id = GetWindowThreadProcessId(remote_window_, &process_id);
260 // It is possible that the process owning this window may have died by now.
261 if (!thread_id || !process_id) {
262 remote_window_ = NULL;
263 return PROCESS_NONE;
264 }
265
266 if (base::win::IsMetroProcess()) {
267 // Interesting corner case. We are launched as a metro process but we
268 // found another chrome running. Since metro enforces single instance then
269 // the other chrome must be desktop chrome and this must be a search charm
270 // activation. This scenario is unique; other cases should be properly
271 // handled by the delegate_execute which will not activate a second chrome.
272 string16 url;
273 base::win::MetroLaunchType launch = base::win::GetMetroLaunchParams(&url);
274 if (launch != base::win::METRO_SEARCH) {
275 LOG(WARNING) << "In metro mode, but and launch is " << launch;
276 } else {
277 // Need to find a top level window widget, the |remote_window_| does not
278 // handle the search navigation message.
279 HWND top_widget = NULL;
280 EnumThreadWindows(thread_id, &TopWindowFinder, LPARAM(&top_widget));
281 if (top_widget) {
282 UINT search_message =
283 RegisterWindowMessage(chrome::kMetroNavigationAndSearchMessage);
284 ATOM atom = GlobalAddAtomW(url.c_str());
285 PostMessage(top_widget, search_message, 0, atom);
286 LOG(INFO) << "Sent search term " << url;
287 } else {
288 LOG(WARNING) << "Could not find top level window";
289 }
290 }
291 return PROCESS_NOTIFIED;
292 }
293 // Non-metro mode, send our command line to the other chrome message window.
243 // format is "START\0<<<current directory>>>\0<<<commandline>>>". 294 // format is "START\0<<<current directory>>>\0<<<commandline>>>".
244 std::wstring to_send(L"START\0", 6); // want the NULL in the string. 295 std::wstring to_send(L"START\0", 6); // want the NULL in the string.
245 FilePath cur_dir; 296 FilePath cur_dir;
246 if (!PathService::Get(base::DIR_CURRENT, &cur_dir)) 297 if (!PathService::Get(base::DIR_CURRENT, &cur_dir))
247 return PROCESS_NONE; 298 return PROCESS_NONE;
248 to_send.append(cur_dir.value()); 299 to_send.append(cur_dir.value());
249 to_send.append(L"\0", 1); // Null separator. 300 to_send.append(L"\0", 1); // Null separator.
250 to_send.append(GetCommandLineW()); 301 to_send.append(GetCommandLineW());
251 to_send.append(L"\0", 1); // Null separator. 302 to_send.append(L"\0", 1); // Null separator.
252 303
253 // Allow the current running browser window making itself the foreground 304 // Allow the current running browser window making itself the foreground
254 // window (otherwise it will just flash in the taskbar). 305 // window (otherwise it will just flash in the taskbar).
255 DWORD process_id = 0;
256 DWORD thread_id = GetWindowThreadProcessId(remote_window_, &process_id);
257 // It is possible that the process owning this window may have died by now.
258 if (!thread_id || !process_id) {
259 remote_window_ = NULL;
260 return PROCESS_NONE;
261 }
262
263 AllowSetForegroundWindow(process_id); 306 AllowSetForegroundWindow(process_id);
264 307
265 COPYDATASTRUCT cds; 308 COPYDATASTRUCT cds;
266 cds.dwData = 0; 309 cds.dwData = 0;
267 cds.cbData = static_cast<DWORD>((to_send.length() + 1) * sizeof(wchar_t)); 310 cds.cbData = static_cast<DWORD>((to_send.length() + 1) * sizeof(wchar_t));
268 cds.lpData = const_cast<wchar_t*>(to_send.c_str()); 311 cds.lpData = const_cast<wchar_t*>(to_send.c_str());
269 DWORD_PTR result = 0; 312 DWORD_PTR result = 0;
270 if (SendMessageTimeout(remote_window_, 313 if (SendMessageTimeout(remote_window_,
271 WM_COPYDATA, 314 WM_COPYDATA,
272 NULL, 315 NULL,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 switch (message) { 414 switch (message) {
372 case WM_COPYDATA: 415 case WM_COPYDATA:
373 return OnCopyData(reinterpret_cast<HWND>(wparam), 416 return OnCopyData(reinterpret_cast<HWND>(wparam),
374 reinterpret_cast<COPYDATASTRUCT*>(lparam)); 417 reinterpret_cast<COPYDATASTRUCT*>(lparam));
375 default: 418 default:
376 break; 419 break;
377 } 420 }
378 421
379 return ::DefWindowProc(hwnd, message, wparam, lparam); 422 return ::DefWindowProc(hwnd, message, wparam, lparam);
380 } 423 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698