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 <windows.h> // NOLINT | 5 #include <windows.h> // NOLINT |
6 #include <shlwapi.h> // NOLINT | 6 #include <shlwapi.h> // NOLINT |
7 | 7 |
8 #include "chrome/app/main_dll_loader_win.h" | 8 #include "chrome/app/main_dll_loader_win.h" |
9 | 9 |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
11 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/environment.h" | 14 #include "base/environment.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
23 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
24 #include "base/version.h" | |
25 #include "base/win/metro.h" | |
24 #include "base/win/scoped_handle.h" | 26 #include "base/win/scoped_handle.h" |
25 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
26 #include "chrome/app/chrome_crash_reporter_client.h" | 28 #include "chrome/app/chrome_crash_reporter_client.h" |
27 #include "chrome/app/chrome_watcher_client_win.h" | 29 #include "chrome/app/chrome_watcher_client_win.h" |
28 #include "chrome/app/chrome_watcher_command_line_win.h" | 30 #include "chrome/app/chrome_watcher_command_line_win.h" |
29 #include "chrome/app/file_pre_reader_win.h" | 31 #include "chrome/app/file_pre_reader_win.h" |
30 #include "chrome/app/kasko_client.h" | 32 #include "chrome/app/kasko_client.h" |
31 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" | 33 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" |
32 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
33 #include "chrome/common/chrome_paths.h" | 35 #include "chrome/common/chrome_paths.h" |
34 #include "chrome/common/chrome_result_codes.h" | 36 #include "chrome/common/chrome_result_codes.h" |
35 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
36 #include "chrome/common/env_vars.h" | 38 #include "chrome/common/env_vars.h" |
37 #include "chrome/installer/util/google_update_constants.h" | 39 #include "chrome/installer/util/google_update_constants.h" |
38 #include "chrome/installer/util/google_update_settings.h" | 40 #include "chrome/installer/util/google_update_settings.h" |
39 #include "chrome/installer/util/install_util.h" | 41 #include "chrome/installer/util/install_util.h" |
40 #include "chrome/installer/util/module_util_win.h" | 42 #include "chrome/installer/util/module_util_win.h" |
41 #include "chrome/installer/util/util_constants.h" | 43 #include "chrome/installer/util/util_constants.h" |
42 #include "components/crash/content/app/breakpad_win.h" | |
43 #include "components/crash/content/app/crash_reporter_client.h" | 44 #include "components/crash/content/app/crash_reporter_client.h" |
45 #include "components/crash/content/app/crashpad.h" | |
44 #include "content/public/app/sandbox_helper_win.h" | 46 #include "content/public/app/sandbox_helper_win.h" |
45 #include "content/public/common/content_switches.h" | 47 #include "content/public/common/content_switches.h" |
46 #include "sandbox/win/src/sandbox.h" | 48 #include "sandbox/win/src/sandbox.h" |
47 | 49 |
48 namespace { | 50 namespace { |
49 // The entry point signature of chrome.dll. | 51 // The entry point signature of chrome.dll. |
50 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); | 52 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); |
51 | 53 |
52 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); | 54 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); |
53 | 55 |
(...skipping 26 matching lines...) Expand all Loading... | |
80 GoogleUpdateSettings::UpdateDidRunState(false, system_level); | 82 GoogleUpdateSettings::UpdateDidRunState(false, system_level); |
81 } | 83 } |
82 | 84 |
83 bool InMetroMode() { | 85 bool InMetroMode() { |
84 return (wcsstr( | 86 return (wcsstr( |
85 ::GetCommandLineW(), L" -ServerName:DefaultBrowserServer") != nullptr); | 87 ::GetCommandLineW(), L" -ServerName:DefaultBrowserServer") != nullptr); |
86 } | 88 } |
87 | 89 |
88 typedef int (*InitMetro)(); | 90 typedef int (*InitMetro)(); |
89 | 91 |
92 // Returns the directory in which the currently running executable resides. | |
scottmg
2015/11/07 00:39:43
This was copied verbatim from the breakpad integra
| |
93 base::FilePath GetExecutableDir() { | |
94 base::char16 path[MAX_PATH]; | |
95 ::GetModuleFileNameW(nullptr, path, MAX_PATH); | |
96 return base::FilePath(path).DirName(); | |
97 } | |
98 | |
99 bool WrapMessageBoxWithSEH(const wchar_t* text, | |
100 const wchar_t* caption, | |
101 UINT flags, | |
102 bool* exit_now) { | |
103 // We wrap the call to MessageBoxW with a SEH handler because it some | |
104 // machines with CursorXP, PeaDict or with FontExplorer installed it crashes | |
105 // uncontrollably here. Being this a best effort deal we better go away. | |
106 __try { | |
107 *exit_now = (IDOK != ::MessageBoxW(NULL, text, caption, flags)); | |
108 } __except(EXCEPTION_EXECUTE_HANDLER) { | |
109 // Its not safe to continue executing, exit silently here. | |
110 ::TerminateProcess( | |
111 ::GetCurrentProcess(), | |
112 g_chrome_crash_client.Pointer()->GetResultCodeRespawnFailed()); | |
113 } | |
114 | |
115 return true; | |
116 } | |
117 | |
118 // This function is executed by the child process that DumpDoneCallback() | |
119 // spawned and basically just shows the 'chrome has crashed' dialog if | |
120 // the CHROME_CRASHED environment variable is present. | |
121 bool ShowRestartDialogIfCrashed(bool* exit_now) { | |
122 // If we are being launched in metro mode don't try to show the dialog. | |
123 if (base::win::IsMetroProcess()) | |
124 return false; | |
125 | |
126 base::string16 message; | |
127 base::string16 title; | |
128 bool is_rtl_locale; | |
129 if (!g_chrome_crash_client.Pointer()->ShouldShowRestartDialog( | |
130 &title, &message, &is_rtl_locale)) { | |
131 return false; | |
132 } | |
133 | |
134 // If the UI layout is right-to-left, we need to pass the appropriate MB_XXX | |
135 // flags so that an RTL message box is displayed. | |
136 UINT flags = MB_OKCANCEL | MB_ICONWARNING; | |
137 if (is_rtl_locale) | |
138 flags |= MB_RIGHT | MB_RTLREADING; | |
139 | |
140 return WrapMessageBoxWithSEH(message.c_str(), title.c_str(), flags, exit_now); | |
141 } | |
142 | |
90 } // namespace | 143 } // namespace |
91 | 144 |
92 //============================================================================= | 145 //============================================================================= |
93 | 146 |
94 MainDllLoader::MainDllLoader() | 147 MainDllLoader::MainDllLoader() |
95 : dll_(nullptr), metro_mode_(InMetroMode()) { | 148 : dll_(nullptr), metro_mode_(InMetroMode()) { |
96 } | 149 } |
97 | 150 |
98 MainDllLoader::~MainDllLoader() { | 151 MainDllLoader::~MainDllLoader() { |
99 } | 152 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 if (metro_mode_) { | 202 if (metro_mode_) { |
150 HMODULE metro_dll = Load(&version, &file); | 203 HMODULE metro_dll = Load(&version, &file); |
151 if (!metro_dll) | 204 if (!metro_dll) |
152 return chrome::RESULT_CODE_MISSING_DATA; | 205 return chrome::RESULT_CODE_MISSING_DATA; |
153 | 206 |
154 InitMetro chrome_metro_main = | 207 InitMetro chrome_metro_main = |
155 reinterpret_cast<InitMetro>(::GetProcAddress(metro_dll, "InitMetro")); | 208 reinterpret_cast<InitMetro>(::GetProcAddress(metro_dll, "InitMetro")); |
156 return chrome_metro_main(); | 209 return chrome_metro_main(); |
157 } | 210 } |
158 | 211 |
212 chrome::RegisterPathProvider(); | |
213 | |
159 if (process_type_ == "watcher") { | 214 if (process_type_ == "watcher") { |
160 chrome::RegisterPathProvider(); | |
161 | 215 |
162 base::win::ScopedHandle parent_process; | 216 base::win::ScopedHandle parent_process; |
163 base::win::ScopedHandle on_initialized_event; | 217 base::win::ScopedHandle on_initialized_event; |
164 DWORD main_thread_id = 0; | 218 DWORD main_thread_id = 0; |
165 if (!InterpretChromeWatcherCommandLine(cmd_line, &parent_process, | 219 if (!InterpretChromeWatcherCommandLine(cmd_line, &parent_process, |
166 &main_thread_id, | 220 &main_thread_id, |
167 &on_initialized_event)) { | 221 &on_initialized_event)) { |
168 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; | 222 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; |
169 } | 223 } |
170 | 224 |
(...skipping 29 matching lines...) Expand all Loading... | |
200 message_window_name.c_str(), channel_name.c_str()); | 254 message_window_name.c_str(), channel_name.c_str()); |
201 } | 255 } |
202 | 256 |
203 // Initialize the sandbox services. | 257 // Initialize the sandbox services. |
204 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 258 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
205 content::InitializeSandboxInfo(&sandbox_info); | 259 content::InitializeSandboxInfo(&sandbox_info); |
206 | 260 |
207 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); | 261 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); |
208 bool exit_now = true; | 262 bool exit_now = true; |
209 if (process_type_.empty()) { | 263 if (process_type_.empty()) { |
210 if (breakpad::ShowRestartDialogIfCrashed(&exit_now)) { | 264 if (ShowRestartDialogIfCrashed(&exit_now)) { |
211 // We restarted because of a previous crash. Ask user if we should | 265 // We restarted because of a previous crash. Ask user if we should |
212 // Relaunch. Only for the browser process. See crbug.com/132119. | 266 // Relaunch. Only for the browser process. See crbug.com/132119. |
213 if (exit_now) | 267 if (exit_now) |
214 return content::RESULT_CODE_NORMAL_EXIT; | 268 return content::RESULT_CODE_NORMAL_EXIT; |
215 } | 269 } |
216 } | 270 } |
217 breakpad::InitCrashReporter(process_type_); | 271 |
272 crash_reporter::InitializeCrashpad(process_type_ == "", process_type_); | |
218 | 273 |
219 dll_ = Load(&version, &file); | 274 dll_ = Load(&version, &file); |
220 if (!dll_) | 275 if (!dll_) |
221 return chrome::RESULT_CODE_MISSING_DATA; | 276 return chrome::RESULT_CODE_MISSING_DATA; |
222 | 277 |
223 scoped_ptr<base::Environment> env(base::Environment::Create()); | 278 scoped_ptr<base::Environment> env(base::Environment::Create()); |
224 env->SetVar(chrome::kChromeVersionEnvVar, base::WideToUTF8(version)); | 279 env->SetVar(chrome::kChromeVersionEnvVar, base::WideToUTF8(version)); |
225 | 280 |
226 OnBeforeLaunch(process_type_, file); | 281 OnBeforeLaunch(process_type_, file); |
227 DLL_MAIN chrome_main = | 282 DLL_MAIN chrome_main = |
228 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain")); | 283 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain")); |
229 int rc = chrome_main(instance, &sandbox_info); | 284 int rc = chrome_main(instance, &sandbox_info); |
230 rc = OnBeforeExit(rc, file); | 285 rc = OnBeforeExit(rc, file); |
231 // Sandboxed processes close some system DLL handles after lockdown so ignore | |
232 // EXCEPTION_INVALID_HANDLE generated on Windows 10 during shutdown of these | |
233 // processes. | |
234 // TODO(wfh): Check whether MS have fixed this in Win10 RTM. crbug.com/456193 | |
235 if (base::win::GetVersion() >= base::win::VERSION_WIN10) | |
236 breakpad::ConsumeInvalidHandleExceptions(); | |
237 return rc; | 286 return rc; |
238 } | 287 } |
239 | 288 |
240 void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { | 289 void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { |
241 if (!dll_) | 290 if (!dll_) |
242 return; | 291 return; |
243 | 292 |
244 RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function = | 293 RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function = |
245 reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>( | 294 reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>( |
246 ::GetProcAddress(dll_, | 295 ::GetProcAddress(dll_, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 } | 389 } |
341 }; | 390 }; |
342 | 391 |
343 MainDllLoader* MakeMainDllLoader() { | 392 MainDllLoader* MakeMainDllLoader() { |
344 #if defined(GOOGLE_CHROME_BUILD) | 393 #if defined(GOOGLE_CHROME_BUILD) |
345 return new ChromeDllLoader(); | 394 return new ChromeDllLoader(); |
346 #else | 395 #else |
347 return new ChromiumDllLoader(); | 396 return new ChromiumDllLoader(); |
348 #endif | 397 #endif |
349 } | 398 } |
OLD | NEW |