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 <atlbase.h> | 5 #include <atlbase.h> |
6 #include <atlcom.h> | 6 #include <atlcom.h> |
7 #include <atlctl.h> | 7 #include <atlctl.h> |
8 #include <initguid.h> | 8 #include <initguid.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/process/kill.h" | 15 #include "base/process/kill.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "base/win/scoped_com_initializer.h" | 17 #include "base/win/scoped_com_initializer.h" |
18 #include "base/win/scoped_comptr.h" | 18 #include "base/win/scoped_comptr.h" |
19 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
| 20 #include "base/win/windows_version.h" |
20 #include "breakpad/src/client/windows/handler/exception_handler.h" | 21 #include "breakpad/src/client/windows/handler/exception_handler.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/installer/util/browser_distribution.h" | 23 #include "chrome/installer/util/browser_distribution.h" |
23 #include "win8/delegate_execute/command_execute_impl.h" | 24 #include "win8/delegate_execute/command_execute_impl.h" |
24 #include "win8/delegate_execute/crash_server_init.h" | 25 #include "win8/delegate_execute/crash_server_init.h" |
25 #include "win8/delegate_execute/delegate_execute_operation.h" | 26 #include "win8/delegate_execute/delegate_execute_operation.h" |
26 #include "win8/delegate_execute/resource.h" | 27 #include "win8/delegate_execute/resource.h" |
27 | 28 |
28 using namespace ATL; | 29 using namespace ATL; |
29 | 30 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 AtlTrace("%ds timeout. Killing Chrome %d\n", kWaitSeconds, pid); | 111 AtlTrace("%ds timeout. Killing Chrome %d\n", kWaitSeconds, pid); |
111 base::KillProcessById(pid, 0, false); | 112 base::KillProcessById(pid, 0, false); |
112 } else { | 113 } else { |
113 AtlTrace("Failed to wait for relaunch mutex, result is 0x%x\n", result); | 114 AtlTrace("Failed to wait for relaunch mutex, result is 0x%x\n", result); |
114 } | 115 } |
115 } else { | 116 } else { |
116 // It is possible that chrome exits so fast that the mutex is not there. | 117 // It is possible that chrome exits so fast that the mutex is not there. |
117 AtlTrace("No relaunch mutex found\n"); | 118 AtlTrace("No relaunch mutex found\n"); |
118 } | 119 } |
119 | 120 |
120 base::win::ScopedCOMInitializer com_initializer; | 121 // On Windows 8+ to launch Chrome we rely on Windows to use the |
| 122 // IExecuteCommand interface exposed by delegate_execute to launch Chrome |
| 123 // into Windows 8 metro mode or desktop. |
| 124 // On Windows 7 we don't use delegate_execute and instead use plain vanilla |
| 125 // ShellExecute to launch Chrome into ASH or desktop. |
| 126 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| 127 base::win::ScopedCOMInitializer com_initializer; |
121 | 128 |
122 base::string16 relaunch_flags(operation.relaunch_flags()); | 129 base::string16 relaunch_flags(operation.relaunch_flags()); |
123 SHELLEXECUTEINFO sei = { sizeof(sei) }; | 130 SHELLEXECUTEINFO sei = { sizeof(sei) }; |
124 sei.fMask = SEE_MASK_FLAG_LOG_USAGE; | 131 sei.fMask = SEE_MASK_FLAG_LOG_USAGE; |
125 sei.nShow = SW_SHOWNORMAL; | 132 sei.nShow = SW_SHOWNORMAL; |
126 sei.lpFile = operation.shortcut().value().c_str(); | 133 sei.lpFile = operation.shortcut().value().c_str(); |
127 sei.lpParameters = relaunch_flags.c_str(); | 134 sei.lpParameters = relaunch_flags.c_str(); |
128 | 135 |
129 AtlTrace(L"Relaunching Chrome via shortcut [%ls]\n", sei.lpFile); | 136 AtlTrace(L"Relaunching Chrome via shortcut [%ls]\n", sei.lpFile); |
130 | 137 |
131 if (!::ShellExecuteExW(&sei)) { | 138 if (!::ShellExecuteExW(&sei)) { |
132 int error = HRESULT_FROM_WIN32(::GetLastError()); | 139 int error = HRESULT_FROM_WIN32(::GetLastError()); |
133 AtlTrace("ShellExecute returned 0x%08X\n", error); | 140 AtlTrace("ShellExecute returned 0x%08X\n", error); |
134 return error; | 141 return error; |
| 142 } |
| 143 } else { |
| 144 base::FilePath chrome_exe_path; |
| 145 bool found_exe = CommandExecuteImpl::FindChromeExe(&chrome_exe_path); |
| 146 DCHECK(found_exe); |
| 147 if (found_exe) { |
| 148 bool launch_ash = CommandLine::ForCurrentProcess()->HasSwitch( |
| 149 switches::kForceImmersive); |
| 150 if (launch_ash) { |
| 151 AtlTrace(L"Relaunching Chrome into Windows ASH on Windows 7\n"); |
| 152 } else { |
| 153 AtlTrace(L"Relaunching Chrome into Desktop From ASH on Windows 7\n"); |
| 154 } |
| 155 SHELLEXECUTEINFO sei = { sizeof(sei) }; |
| 156 sei.fMask = SEE_MASK_FLAG_LOG_USAGE; |
| 157 sei.nShow = SW_SHOWNORMAL; |
| 158 // No point in using the shortcut if we are launching into ASH as any |
| 159 // additonal command line switches specified in the shortcut will be |
| 160 // ignored. This is because we don't have a good way to send the command |
| 161 // line switches from the viewer to the browser process. |
| 162 sei.lpFile = (launch_ash || operation.shortcut().empty()) ? |
| 163 chrome_exe_path.value().c_str() : |
| 164 operation.shortcut().value().c_str(); |
| 165 sei.lpParameters = |
| 166 launch_ash ? L"-ServerName:DefaultBrowserServer" : NULL; |
| 167 if (!::ShellExecuteExW(&sei)) { |
| 168 int error = HRESULT_FROM_WIN32(::GetLastError()); |
| 169 AtlTrace("ShellExecute returned 0x%08X\n", error); |
| 170 return error; |
| 171 } |
| 172 } |
135 } | 173 } |
136 return S_OK; | 174 return S_OK; |
137 } | 175 } |
138 | 176 |
139 extern "C" int WINAPI _tWinMain(HINSTANCE , HINSTANCE, LPTSTR, int nShowCmd) { | 177 extern "C" int WINAPI _tWinMain(HINSTANCE , HINSTANCE, LPTSTR, int nShowCmd) { |
140 scoped_ptr<google_breakpad::ExceptionHandler> breakpad = | 178 scoped_ptr<google_breakpad::ExceptionHandler> breakpad = |
141 delegate_execute::InitializeCrashReporting(); | 179 delegate_execute::InitializeCrashReporting(); |
142 | 180 |
143 base::AtExitManager exit_manager; | 181 base::AtExitManager exit_manager; |
144 AtlTrace("delegate_execute enter\n"); | 182 AtlTrace("delegate_execute enter\n"); |
145 | 183 |
146 CommandLine::Init(0, NULL); | 184 CommandLine::Init(0, NULL); |
147 HRESULT ret_code = E_UNEXPECTED; | 185 HRESULT ret_code = E_UNEXPECTED; |
148 DelegateExecuteOperation operation; | 186 DelegateExecuteOperation operation; |
149 if (operation.Init(CommandLine::ForCurrentProcess())) { | 187 if (operation.Init(CommandLine::ForCurrentProcess())) { |
150 switch (operation.operation_type()) { | 188 switch (operation.operation_type()) { |
151 case DelegateExecuteOperation::DELEGATE_EXECUTE: | 189 case DelegateExecuteOperation::DELEGATE_EXECUTE: |
152 ret_code = _AtlModule.WinMain(nShowCmd); | 190 ret_code = _AtlModule.WinMain(nShowCmd); |
153 break; | 191 break; |
154 case DelegateExecuteOperation::RELAUNCH_CHROME: | 192 case DelegateExecuteOperation::RELAUNCH_CHROME: |
155 ret_code = RelaunchChrome(operation); | 193 ret_code = RelaunchChrome(operation); |
156 break; | 194 break; |
157 default: | 195 default: |
158 NOTREACHED(); | 196 NOTREACHED(); |
159 } | 197 } |
160 } | 198 } |
161 AtlTrace("delegate_execute exit, code = %d\n", ret_code); | 199 AtlTrace("delegate_execute exit, code = %d\n", ret_code); |
162 return ret_code; | 200 return ret_code; |
163 } | 201 } |
OLD | NEW |