| 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> | 5 #include <windows.h> // NOLINT |
| 6 #include <shlwapi.h> | 6 #include <shlwapi.h> // NOLINT |
| 7 |
| 8 #include "chrome/app/main_dll_loader_win.h" |
| 7 | 9 |
| 8 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 9 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
| 10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 11 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 12 #include "base/environment.h" | 14 #include "base/environment.h" |
| 13 #include "base/file_version_info.h" | |
| 14 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 18 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
| 23 #include "base/version.h" | |
| 24 #include "base/win/scoped_handle.h" | 24 #include "base/win/scoped_handle.h" |
| 25 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
| 26 #include "chrome/app/chrome_crash_reporter_client.h" | 26 #include "chrome/app/chrome_crash_reporter_client.h" |
| 27 #include "chrome/app/chrome_watcher_client_win.h" | 27 #include "chrome/app/chrome_watcher_client_win.h" |
| 28 #include "chrome/app/chrome_watcher_command_line_win.h" | 28 #include "chrome/app/chrome_watcher_command_line_win.h" |
| 29 #include "chrome/app/client_util.h" | |
| 30 #include "chrome/app/image_pre_reader_win.h" | 29 #include "chrome/app/image_pre_reader_win.h" |
| 31 #include "chrome/app/kasko_client.h" | 30 #include "chrome/app/kasko_client.h" |
| 32 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" | 31 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" |
| 33 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
| 34 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
| 35 #include "chrome/common/chrome_result_codes.h" | 34 #include "chrome/common/chrome_result_codes.h" |
| 36 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/env_vars.h" | 36 #include "chrome/common/env_vars.h" |
| 38 #include "chrome/installer/util/google_update_constants.h" | 37 #include "chrome/installer/util/google_update_constants.h" |
| 39 #include "chrome/installer/util/google_update_settings.h" | 38 #include "chrome/installer/util/google_update_settings.h" |
| 40 #include "chrome/installer/util/install_util.h" | 39 #include "chrome/installer/util/install_util.h" |
| 40 #include "chrome/installer/util/module_util_win.h" |
| 41 #include "chrome/installer/util/util_constants.h" | 41 #include "chrome/installer/util/util_constants.h" |
| 42 #include "components/crash/content/app/breakpad_win.h" | 42 #include "components/crash/content/app/breakpad_win.h" |
| 43 #include "components/crash/content/app/crash_reporter_client.h" | 43 #include "components/crash/content/app/crash_reporter_client.h" |
| 44 #include "content/public/app/sandbox_helper_win.h" | 44 #include "content/public/app/sandbox_helper_win.h" |
| 45 #include "content/public/common/content_switches.h" | 45 #include "content/public/common/content_switches.h" |
| 46 #include "sandbox/win/src/sandbox.h" | 46 #include "sandbox/win/src/sandbox.h" |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| 49 // The entry point signature of chrome.dll. | 49 // The entry point signature of chrome.dll. |
| 50 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); | 50 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 GoogleUpdateSettings::UpdateDidRunState(false, system_level); | 82 GoogleUpdateSettings::UpdateDidRunState(false, system_level); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool InMetroMode() { | 85 bool InMetroMode() { |
| 86 return (wcsstr( | 86 return (wcsstr( |
| 87 ::GetCommandLineW(), L" -ServerName:DefaultBrowserServer") != nullptr); | 87 ::GetCommandLineW(), L" -ServerName:DefaultBrowserServer") != nullptr); |
| 88 } | 88 } |
| 89 | 89 |
| 90 typedef int (*InitMetro)(); | 90 typedef int (*InitMetro)(); |
| 91 | 91 |
| 92 // Returns the directory in which the currently running executable resides. | |
| 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 } // namespace | 92 } // namespace |
| 100 | 93 |
| 101 base::string16 GetCurrentModuleVersion() { | |
| 102 scoped_ptr<FileVersionInfo> file_version_info( | |
| 103 CREATE_FILE_VERSION_INFO_FOR_CURRENT_MODULE()); | |
| 104 if (file_version_info.get()) { | |
| 105 base::string16 version_string(file_version_info->file_version()); | |
| 106 if (Version(base::UTF16ToASCII(version_string)).IsValid()) | |
| 107 return version_string; | |
| 108 } | |
| 109 return base::string16(); | |
| 110 } | |
| 111 | |
| 112 //============================================================================= | 94 //============================================================================= |
| 113 | 95 |
| 114 MainDllLoader::MainDllLoader() | 96 MainDllLoader::MainDllLoader() |
| 115 : dll_(nullptr), metro_mode_(InMetroMode()) { | 97 : dll_(nullptr), metro_mode_(InMetroMode()) { |
| 116 } | 98 } |
| 117 | 99 |
| 118 MainDllLoader::~MainDllLoader() { | 100 MainDllLoader::~MainDllLoader() { |
| 119 } | 101 } |
| 120 | 102 |
| 121 // Loading chrome is an interesting affair. First we try loading from the | 103 // Loading chrome is an interesting affair. First we try loading from the |
| 122 // current directory to support run-what-you-compile and other development | 104 // current directory to support run-what-you-compile and other development |
| 123 // scenarios. | 105 // scenarios. |
| 124 // If that fails then we look at the version resource in the current | 106 // If that fails then we look at the version resource in the current |
| 125 // module. This is the expected path for chrome.exe browser instances in an | 107 // module. This is the expected path for chrome.exe browser instances in an |
| 126 // installed build. | 108 // installed build. |
| 127 HMODULE MainDllLoader::Load(base::string16* version, base::FilePath* module) { | 109 HMODULE MainDllLoader::Load(base::string16* version, base::FilePath* module) { |
| 128 const base::char16* dll_name = nullptr; | 110 const base::char16* dll_name = nullptr; |
| 129 if (metro_mode_) { | 111 if (metro_mode_) { |
| 130 dll_name = installer::kChromeMetroDll; | 112 dll_name = installer::kChromeMetroDll; |
| 131 } else if (process_type_ == "service" || process_type_.empty()) { | 113 } else if (process_type_ == "service" || process_type_.empty()) { |
| 132 dll_name = installer::kChromeDll; | 114 dll_name = installer::kChromeDll; |
| 133 } else if (process_type_ == "watcher") { | 115 } else if (process_type_ == "watcher") { |
| 134 dll_name = kChromeWatcherDll; | 116 dll_name = kChromeWatcherDll; |
| 135 } else { | 117 } else { |
| 136 #if defined(CHROME_MULTIPLE_DLL) | 118 #if defined(CHROME_MULTIPLE_DLL) |
| 137 dll_name = installer::kChromeChildDll; | 119 dll_name = installer::kChromeChildDll; |
| 138 #else | 120 #else |
| 139 dll_name = installer::kChromeDll; | 121 dll_name = installer::kChromeDll; |
| 140 #endif | 122 #endif |
| 141 } | 123 } |
| 142 | 124 |
| 125 *module = installer::GetModulePath(dll_name, version); |
| 126 if (module->empty()) { |
| 127 PLOG(ERROR) << "Cannot find module " << dll_name; |
| 128 return nullptr; |
| 129 } |
| 143 const bool pre_read = !metro_mode_; | 130 const bool pre_read = !metro_mode_; |
| 144 base::FilePath module_dir = GetExecutableDir(); | |
| 145 *module = module_dir.Append(dll_name); | |
| 146 HMODULE dll = LoadModuleWithDirectory(*module, pre_read); | 131 HMODULE dll = LoadModuleWithDirectory(*module, pre_read); |
| 147 if (!dll) { | 132 if (!dll) { |
| 148 base::string16 version_string(GetCurrentModuleVersion()); | 133 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value(); |
| 149 if (version_string.empty()) { | 134 return nullptr; |
| 150 LOG(ERROR) << "No valid Chrome version found"; | |
| 151 return nullptr; | |
| 152 } | |
| 153 *version = version_string; | |
| 154 *module = module_dir.Append(version_string).Append(dll_name); | |
| 155 dll = LoadModuleWithDirectory(*module, pre_read); | |
| 156 if (!dll) { | |
| 157 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value(); | |
| 158 return nullptr; | |
| 159 } | |
| 160 } | 135 } |
| 161 | 136 |
| 162 DCHECK(dll); | 137 DCHECK(dll); |
| 163 return dll; | 138 return dll; |
| 164 } | 139 } |
| 165 | 140 |
| 166 // Launching is a matter of loading the right dll, setting the CHROME_VERSION | 141 // Launching is a matter of loading the right dll, setting the CHROME_VERSION |
| 167 // environment variable and just calling the entry point. Derived classes can | 142 // environment variable and just calling the entry point. Derived classes can |
| 168 // add custom code in the OnBeforeLaunch callback. | 143 // add custom code in the OnBeforeLaunch callback. |
| 169 int MainDllLoader::Launch(HINSTANCE instance) { | 144 int MainDllLoader::Launch(HINSTANCE instance) { |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 342 } |
| 368 }; | 343 }; |
| 369 | 344 |
| 370 MainDllLoader* MakeMainDllLoader() { | 345 MainDllLoader* MakeMainDllLoader() { |
| 371 #if defined(GOOGLE_CHROME_BUILD) | 346 #if defined(GOOGLE_CHROME_BUILD) |
| 372 return new ChromeDllLoader(); | 347 return new ChromeDllLoader(); |
| 373 #else | 348 #else |
| 374 return new ChromiumDllLoader(); | 349 return new ChromiumDllLoader(); |
| 375 #endif | 350 #endif |
| 376 } | 351 } |
| OLD | NEW |