Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <shellapi.h> | 7 #include <shellapi.h> |
| 8 #include <shobjidl.h> | |
| 8 | 9 |
| 9 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #include "base/process_util.h" | 14 #include "base/process_util.h" |
| 14 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 16 #include "base/win/metro.h" | 17 #include "base/win/metro.h" |
| 18 #include "base/win/scoped_com_initializer.h" | |
| 19 #include "base/win/scoped_comptr.h" | |
| 17 #include "base/win/scoped_handle.h" | 20 #include "base/win/scoped_handle.h" |
| 18 #include "base/win/wrapped_window_proc.h" | 21 #include "base/win/wrapped_window_proc.h" |
| 19 #include "chrome/browser/ui/simple_message_box.h" | 22 #include "chrome/browser/ui/simple_message_box.h" |
| 20 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 24 #include "chrome/installer/util/browser_distribution.h" | |
| 25 #include "chrome/installer/util/shell_util.h" | |
| 21 #include "chrome/installer/util/wmi.h" | 26 #include "chrome/installer/util/wmi.h" |
| 22 #include "content/public/common/result_codes.h" | 27 #include "content/public/common/result_codes.h" |
| 23 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
| 24 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 25 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/win/hwnd_util.h" | 32 #include "ui/base/win/hwnd_util.h" |
| 28 | 33 |
| 29 namespace { | 34 namespace { |
| 30 | 35 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 | 118 |
| 114 // Get command line. | 119 // Get command line. |
| 115 const std::wstring cmd_line = | 120 const std::wstring cmd_line = |
| 116 msg.substr(second_null + 1, third_null - second_null); | 121 msg.substr(second_null + 1, third_null - second_null); |
| 117 *parsed_command_line = CommandLine::FromString(cmd_line); | 122 *parsed_command_line = CommandLine::FromString(cmd_line); |
| 118 return true; | 123 return true; |
| 119 } | 124 } |
| 120 return false; | 125 return false; |
| 121 } | 126 } |
| 122 | 127 |
| 128 bool ActivateMetroChrome() { | |
| 129 base::win::ScopedCOMInitializer com_init; | |
|
cpu_(ooo_6.6-7.5)
2012/09/17 20:39:06
we are trying to limit the com initialization to o
ananta
2012/09/17 22:16:31
Removed
| |
| 130 | |
| 131 FilePath chrome_exe; | |
| 132 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | |
| 133 NOTREACHED() << "Failed to get chrome exe path"; | |
| 134 return false; | |
| 135 } | |
| 136 string16 app_id = ShellUtil::GetBrowserModelId( | |
| 137 BrowserDistribution::GetDistribution(), chrome_exe.value()); | |
| 138 if (app_id.empty()) { | |
| 139 NOTREACHED() << "Failed to get chrome app user model id."; | |
| 140 return false; | |
| 141 } | |
| 142 | |
| 143 base::win::ScopedComPtr<IApplicationActivationManager> activation_manager; | |
| 144 HRESULT hr = activation_manager.CreateInstance( | |
| 145 CLSID_ApplicationActivationManager); | |
| 146 if (!activation_manager) { | |
| 147 NOTREACHED() << "Failed to cocreate activation manager. Error: " << hr; | |
| 148 return false; | |
| 149 } | |
| 150 | |
| 151 unsigned long pid = 0; | |
| 152 hr = activation_manager->ActivateApplication(app_id.c_str(), | |
| 153 L"open", | |
| 154 AO_NONE, | |
| 155 &pid); | |
| 156 if (FAILED(hr)) { | |
| 157 NOTREACHED() << "Failed to activate metro chrome. Error: " << hr; | |
| 158 return false; | |
| 159 } | |
| 160 return true; | |
| 161 } | |
| 162 | |
| 123 } // namespace | 163 } // namespace |
| 124 | 164 |
| 125 // Microsoft's Softricity virtualization breaks the sandbox processes. | 165 // Microsoft's Softricity virtualization breaks the sandbox processes. |
| 126 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to | 166 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to |
| 127 // break out of the virtualization environment. | 167 // break out of the virtualization environment. |
| 128 // http://code.google.com/p/chromium/issues/detail?id=43650 | 168 // http://code.google.com/p/chromium/issues/detail?id=43650 |
| 129 bool ProcessSingleton::EscapeVirtualization(const FilePath& user_data_dir) { | 169 bool ProcessSingleton::EscapeVirtualization(const FilePath& user_data_dir) { |
| 130 if (::GetModuleHandle(L"sftldr_wow64.dll") || | 170 if (::GetModuleHandle(L"sftldr_wow64.dll") || |
| 131 ::GetModuleHandle(L"sftldr.dll")) { | 171 ::GetModuleHandle(L"sftldr.dll")) { |
| 132 int process_id; | 172 int process_id; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 NULL, | 343 NULL, |
| 304 reinterpret_cast<LPARAM>(&cds), | 344 reinterpret_cast<LPARAM>(&cds), |
| 305 SMTO_ABORTIFHUNG, | 345 SMTO_ABORTIFHUNG, |
| 306 kTimeoutInSeconds * 1000, | 346 kTimeoutInSeconds * 1000, |
| 307 &result)) { | 347 &result)) { |
| 308 // It is possible that the process owning this window may have died by now. | 348 // It is possible that the process owning this window may have died by now. |
| 309 if (!result) { | 349 if (!result) { |
| 310 remote_window_ = NULL; | 350 remote_window_ = NULL; |
| 311 return PROCESS_NONE; | 351 return PROCESS_NONE; |
| 312 } | 352 } |
| 353 | |
|
cpu_(ooo_6.6-7.5)
2012/09/17 20:39:06
check for win8 or bigger here, that is less expens
ananta
2012/09/17 22:16:31
Done.
| |
| 354 base::win::ScopedHandle process_handle; | |
| 355 if (base::OpenProcessHandleWithAccess( | |
| 356 process_id, PROCESS_QUERY_INFORMATION, | |
| 357 process_handle.Receive())) { | |
| 358 if (base::win::IsImmersiveProcess(process_handle.Get())) | |
| 359 ActivateMetroChrome(); | |
| 360 } | |
| 313 return PROCESS_NOTIFIED; | 361 return PROCESS_NOTIFIED; |
| 314 } | 362 } |
| 315 | 363 |
| 316 // It is possible that the process owning this window may have died by now. | 364 // It is possible that the process owning this window may have died by now. |
| 317 if (!IsWindow(remote_window_)) { | 365 if (!IsWindow(remote_window_)) { |
| 318 remote_window_ = NULL; | 366 remote_window_ = NULL; |
| 319 return PROCESS_NONE; | 367 return PROCESS_NONE; |
| 320 } | 368 } |
| 321 | 369 |
| 322 // The window is hung. Scan for every window to find a visible one. | 370 // The window is hung. Scan for every window to find a visible one. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 switch (message) { | 450 switch (message) { |
| 403 case WM_COPYDATA: | 451 case WM_COPYDATA: |
| 404 return OnCopyData(reinterpret_cast<HWND>(wparam), | 452 return OnCopyData(reinterpret_cast<HWND>(wparam), |
| 405 reinterpret_cast<COPYDATASTRUCT*>(lparam)); | 453 reinterpret_cast<COPYDATASTRUCT*>(lparam)); |
| 406 default: | 454 default: |
| 407 break; | 455 break; |
| 408 } | 456 } |
| 409 | 457 |
| 410 return ::DefWindowProc(hwnd, message, wparam, lparam); | 458 return ::DefWindowProc(hwnd, message, wparam, lparam); |
| 411 } | 459 } |
| OLD | NEW |