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

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
« no previous file with comments | « base/win/metro.cc ('k') | chrome/browser/ui/startup/startup_browser_creator_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/stringprintf.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "base/win/metro.h"
13 #include "base/win/scoped_handle.h" 15 #include "base/win/scoped_handle.h"
14 #include "base/win/wrapped_window_proc.h" 16 #include "base/win/wrapped_window_proc.h"
15 #include "chrome/browser/ui/simple_message_box.h" 17 #include "chrome/browser/ui/simple_message_box.h"
16 #include "chrome/common/chrome_constants.h" 18 #include "chrome/common/chrome_constants.h"
17 #include "chrome/installer/util/wmi.h" 19 #include "chrome/installer/util/wmi.h"
18 #include "content/public/common/result_codes.h" 20 #include "content/public/common/result_codes.h"
19 #include "grit/chromium_strings.h" 21 #include "grit/chromium_strings.h"
20 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
23 #include "net/base/escape.h"
21 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/win/hwnd_util.h" 25 #include "ui/base/win/hwnd_util.h"
23 26
24 namespace { 27 namespace {
25 28
26 const char kLockfile[] = "lockfile"; 29 const char kLockfile[] = "lockfile";
27 30
31 const char kSearchUrl[] =
32 "http://www.google.com/search?q=%s&sourceid=chrome&ie=UTF-8";
33
28 // Checks the visibility of the enumerated window and signals once a visible 34 // Checks the visibility of the enumerated window and signals once a visible
29 // window has been found. 35 // window has been found.
30 BOOL CALLBACK BrowserWindowEnumeration(HWND window, LPARAM param) { 36 BOOL CALLBACK BrowserWindowEnumeration(HWND window, LPARAM param) {
31 bool* result = reinterpret_cast<bool*>(param); 37 bool* result = reinterpret_cast<bool*>(param);
32 *result = IsWindowVisible(window) != 0; 38 *result = IsWindowVisible(window) != 0;
33 // Stops enumeration if a visible window has been found. 39 // Stops enumeration if a visible window has been found.
34 return !*result; 40 return !*result;
35 } 41 }
36 42
37 // This function thunks to the object's version of the windowproc, taking in 43 // This function thunks to the object's version of the windowproc, taking in
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 238 }
233 239
234 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { 240 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() {
235 if (is_virtualized_) 241 if (is_virtualized_)
236 return PROCESS_NOTIFIED; // We already spawned the process in this case. 242 return PROCESS_NOTIFIED; // We already spawned the process in this case.
237 if (lock_file_ == INVALID_HANDLE_VALUE && !remote_window_) 243 if (lock_file_ == INVALID_HANDLE_VALUE && !remote_window_)
238 return LOCK_ERROR; 244 return LOCK_ERROR;
239 else if (!remote_window_) 245 else if (!remote_window_)
240 return PROCESS_NONE; 246 return PROCESS_NONE;
241 247
242 // Found another window, send our command line to it 248 DWORD process_id = 0;
249 DWORD thread_id = GetWindowThreadProcessId(remote_window_, &process_id);
250 // It is possible that the process owning this window may have died by now.
251 if (!thread_id || !process_id) {
252 remote_window_ = NULL;
253 return PROCESS_NONE;
254 }
255
256 if (base::win::IsMetroProcess()) {
257 // Interesting corner case. We are launched as a metro process but we
258 // found another chrome running. Since metro enforces single instance then
259 // the other chrome must be desktop chrome and this must be a search charm
260 // activation. This scenario is unique; other cases should be properly
261 // handled by the delegate_execute which will not activate a second chrome.
262 string16 terms;
263 base::win::MetroLaunchType launch = base::win::GetMetroLaunchParams(&terms);
264 if (launch != base::win::METRO_SEARCH) {
265 LOG(WARNING) << "In metro mode, but and launch is " << launch;
266 } else {
267 std::string query = net::EscapeQueryParamValue(UTF16ToUTF8(terms), true);
268 std::string url = base::StringPrintf(kSearchUrl, query.c_str());
269 SHELLEXECUTEINFOA sei = { sizeof(sei) };
270 sei.fMask = SEE_MASK_FLAG_LOG_USAGE;
271 sei.nShow = SW_SHOWNORMAL;
272 sei.lpFile = url.c_str();
273 OutputDebugStringA(sei.lpFile);
274 sei.lpDirectory = "";
275 ::ShellExecuteExA(&sei);
276 }
277 return PROCESS_NOTIFIED;
278 }
279 // Non-metro mode, send our command line to the other chrome message window.
243 // format is "START\0<<<current directory>>>\0<<<commandline>>>". 280 // format is "START\0<<<current directory>>>\0<<<commandline>>>".
244 std::wstring to_send(L"START\0", 6); // want the NULL in the string. 281 std::wstring to_send(L"START\0", 6); // want the NULL in the string.
245 FilePath cur_dir; 282 FilePath cur_dir;
246 if (!PathService::Get(base::DIR_CURRENT, &cur_dir)) 283 if (!PathService::Get(base::DIR_CURRENT, &cur_dir))
247 return PROCESS_NONE; 284 return PROCESS_NONE;
248 to_send.append(cur_dir.value()); 285 to_send.append(cur_dir.value());
249 to_send.append(L"\0", 1); // Null separator. 286 to_send.append(L"\0", 1); // Null separator.
250 to_send.append(GetCommandLineW()); 287 to_send.append(GetCommandLineW());
251 to_send.append(L"\0", 1); // Null separator. 288 to_send.append(L"\0", 1); // Null separator.
252 289
253 // Allow the current running browser window making itself the foreground 290 // Allow the current running browser window making itself the foreground
254 // window (otherwise it will just flash in the taskbar). 291 // 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); 292 AllowSetForegroundWindow(process_id);
264 293
265 COPYDATASTRUCT cds; 294 COPYDATASTRUCT cds;
266 cds.dwData = 0; 295 cds.dwData = 0;
267 cds.cbData = static_cast<DWORD>((to_send.length() + 1) * sizeof(wchar_t)); 296 cds.cbData = static_cast<DWORD>((to_send.length() + 1) * sizeof(wchar_t));
268 cds.lpData = const_cast<wchar_t*>(to_send.c_str()); 297 cds.lpData = const_cast<wchar_t*>(to_send.c_str());
269 DWORD_PTR result = 0; 298 DWORD_PTR result = 0;
270 if (SendMessageTimeout(remote_window_, 299 if (SendMessageTimeout(remote_window_,
271 WM_COPYDATA, 300 WM_COPYDATA,
272 NULL, 301 NULL,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 switch (message) { 400 switch (message) {
372 case WM_COPYDATA: 401 case WM_COPYDATA:
373 return OnCopyData(reinterpret_cast<HWND>(wparam), 402 return OnCopyData(reinterpret_cast<HWND>(wparam),
374 reinterpret_cast<COPYDATASTRUCT*>(lparam)); 403 reinterpret_cast<COPYDATASTRUCT*>(lparam));
375 default: 404 default:
376 break; 405 break;
377 } 406 }
378 407
379 return ::DefWindowProc(hwnd, message, wparam, lparam); 408 return ::DefWindowProc(hwnd, message, wparam, lparam);
380 } 409 }
OLDNEW
« no previous file with comments | « base/win/metro.cc ('k') | chrome/browser/ui/startup/startup_browser_creator_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698