diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-22 21:42:29 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-22 21:42:29 +0000 |
commit | f394bc63a63b5e30448c06d77d1019f933fe8890 (patch) | |
tree | 0fe00bbe8716440ebad299d40ae6bc7ffc6ef224 /chrome/browser/process_singleton_win.cc | |
parent | ab64a08647d7fb1189989d33b4c107c1950e471d (diff) | |
download | chromium_src-f394bc63a63b5e30448c06d77d1019f933fe8890.zip chromium_src-f394bc63a63b5e30448c06d77d1019f933fe8890.tar.gz chromium_src-f394bc63a63b5e30448c06d77d1019f933fe8890.tar.bz2 |
Implement forwarding of search queries for metro mode
If chrome is the default browser, launch from the search charm does not
use the delegate_execute so if desktop chrome is running, metro chrome
needs to forward the search string and quickly quite
The source of complexity here is that to form the full url, chrome needs
to access the profile which cannot be done from the metro chrome since
the desktop chrome has the profile locked.
Instead we leveage the kMetroNavigationAndSearchMessage from the singleton
code.
BUG=141032
TEST= see bug
Review URL: https://chromiumcodereview.appspot.com/10824387
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152818 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/process_singleton_win.cc')
-rw-r--r-- | chrome/browser/process_singleton_win.cc | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc index 3a259fe..62a469f 100644 --- a/chrome/browser/process_singleton_win.cc +++ b/chrome/browser/process_singleton_win.cc @@ -9,7 +9,9 @@ #include "base/file_path.h" #include "base/path_service.h" #include "base/process_util.h" +#include "base/stringprintf.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" @@ -18,6 +20,7 @@ #include "content/public/common/result_codes.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" +#include "net/base/escape.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/win/hwnd_util.h" @@ -25,6 +28,9 @@ namespace { const char kLockfile[] = "lockfile"; +const char kSearchUrl[] = + "http://www.google.com/search?q=%s&sourceid=chrome&ie=UTF-8"; + // Checks the visibility of the enumerated window and signals once a visible // window has been found. BOOL CALLBACK BrowserWindowEnumeration(HWND window, LPARAM param) { @@ -239,7 +245,38 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { 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 terms; + base::win::MetroLaunchType launch = base::win::GetMetroLaunchParams(&terms); + if (launch != base::win::METRO_SEARCH) { + LOG(WARNING) << "In metro mode, but and launch is " << launch; + } else { + std::string query = net::EscapeQueryParamValue(UTF16ToUTF8(terms), true); + std::string url = base::StringPrintf(kSearchUrl, query.c_str()); + SHELLEXECUTEINFOA sei = { sizeof(sei) }; + sei.fMask = SEE_MASK_FLAG_LOG_USAGE; + sei.nShow = SW_SHOWNORMAL; + sei.lpFile = url.c_str(); + OutputDebugStringA(sei.lpFile); + sei.lpDirectory = ""; + ::ShellExecuteExA(&sei); + } + 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 +289,6 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { // 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; |