| 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/chrome_browser_main_win.h" | 5 #include "chrome/browser/chrome_browser_main_win.h" |
| 6 | 6 |
| 7 #include <shellapi.h> | 7 #include <shellapi.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 9 #include <windows.h> | 10 #include <windows.h> |
| 10 | 11 |
| 11 #include <algorithm> | 12 #include <algorithm> |
| 12 #include <memory> | 13 #include <memory> |
| 13 | 14 |
| 14 #include "base/base_switches.h" | 15 #include "base/base_switches.h" |
| 15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 16 #include "base/environment.h" | 17 #include "base/environment.h" |
| 17 #include "base/files/file_enumerator.h" | 18 #include "base/files/file_enumerator.h" |
| 18 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 19 #include "base/files/file_util.h" | 20 #include "base/files/file_util.h" |
| 20 #include "base/i18n/rtl.h" | 21 #include "base/i18n/rtl.h" |
| 21 #include "base/location.h" | 22 #include "base/location.h" |
| 22 #include "base/macros.h" | 23 #include "base/macros.h" |
| 23 #include "base/metrics/histogram_macros.h" | 24 #include "base/metrics/histogram_macros.h" |
| 24 #include "base/path_service.h" | 25 #include "base/path_service.h" |
| 25 #include "base/scoped_native_library.h" | 26 #include "base/scoped_native_library.h" |
| 26 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/win/pe_image.h" |
| 28 #include "base/win/registry.h" | 30 #include "base/win/registry.h" |
| 29 #include "base/win/win_util.h" | 31 #include "base/win/win_util.h" |
| 30 #include "base/win/windows_version.h" | 32 #include "base/win/windows_version.h" |
| 31 #include "base/win/wrapped_window_proc.h" | 33 #include "base/win/wrapped_window_proc.h" |
| 34 #include "chrome/browser/conflicts/module_database_win.h" |
| 35 #include "chrome/browser/conflicts/module_event_sink_impl_win.h" |
| 32 #include "chrome/browser/first_run/first_run.h" | 36 #include "chrome/browser/first_run/first_run.h" |
| 33 #include "chrome/browser/install_verification/win/install_verification.h" | 37 #include "chrome/browser/install_verification/win/install_verification.h" |
| 34 #include "chrome/browser/profiles/profile_shortcut_manager.h" | 38 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
| 35 #include "chrome/browser/shell_integration.h" | 39 #include "chrome/browser/shell_integration.h" |
| 36 #include "chrome/browser/ui/simple_message_box.h" | 40 #include "chrome/browser/ui/simple_message_box.h" |
| 37 #include "chrome/browser/ui/uninstall_browser_prompt.h" | 41 #include "chrome/browser/ui/uninstall_browser_prompt.h" |
| 38 #include "chrome/browser/win/browser_util.h" | 42 #include "chrome/browser/win/browser_util.h" |
| 39 #include "chrome/browser/win/chrome_elf_init.h" | 43 #include "chrome/browser/win/chrome_elf_init.h" |
| 40 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" | 44 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" |
| 41 #include "chrome/common/chrome_constants.h" | 45 #include "chrome/common/chrome_constants.h" |
| 46 #include "chrome/common/chrome_features.h" |
| 42 #include "chrome/common/chrome_paths.h" | 47 #include "chrome/common/chrome_paths.h" |
| 43 #include "chrome/common/chrome_result_codes.h" | 48 #include "chrome/common/chrome_result_codes.h" |
| 44 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
| 45 #include "chrome/common/chrome_utility_messages.h" | 50 #include "chrome/common/chrome_utility_messages.h" |
| 51 #include "chrome/common/conflicts/module_watcher_win.h" |
| 46 #include "chrome/common/crash_keys.h" | 52 #include "chrome/common/crash_keys.h" |
| 47 #include "chrome/common/env_vars.h" | 53 #include "chrome/common/env_vars.h" |
| 48 #include "chrome/grit/chromium_strings.h" | 54 #include "chrome/grit/chromium_strings.h" |
| 49 #include "chrome/grit/generated_resources.h" | 55 #include "chrome/grit/generated_resources.h" |
| 50 #include "chrome/installer/util/browser_distribution.h" | 56 #include "chrome/installer/util/browser_distribution.h" |
| 51 #include "chrome/installer/util/helper.h" | 57 #include "chrome/installer/util/helper.h" |
| 52 #include "chrome/installer/util/install_util.h" | 58 #include "chrome/installer/util/install_util.h" |
| 53 #include "chrome/installer/util/installer_util_strings.h" | 59 #include "chrome/installer/util/installer_util_strings.h" |
| 54 #include "chrome/installer/util/l10n_string_util.h" | 60 #include "chrome/installer/util/l10n_string_util.h" |
| 55 #include "chrome/installer/util/shell_util.h" | 61 #include "chrome/installer/util/shell_util.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 201 |
| 196 // Look for the DLLs used to implement the FTH and other compat hacks. | 202 // Look for the DLLs used to implement the FTH and other compat hacks. |
| 197 if (GetModuleHandleW(L"AcLayers.dll") != NULL) | 203 if (GetModuleHandleW(L"AcLayers.dll") != NULL) |
| 198 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED); | 204 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED); |
| 199 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL) | 205 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL) |
| 200 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED); | 206 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED); |
| 201 | 207 |
| 202 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT); | 208 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT); |
| 203 } | 209 } |
| 204 | 210 |
| 211 // Helper function for getting the time date stamp associated with a module in |
| 212 // this process. |
| 213 uint32_t GetModuleTimeDateStamp(const void* module_load_address) { |
| 214 base::win::PEImage pe_image(module_load_address); |
| 215 return pe_image.GetNTHeaders()->FileHeader.TimeDateStamp; |
| 216 } |
| 217 |
| 218 // Used as the callback for ModuleWatcher events in this process. Dispatches |
| 219 // them to the ModuleDatabase. |
| 220 void OnModuleEvent(uint32_t process_id, |
| 221 uint64_t creation_time, |
| 222 const ModuleWatcher::ModuleEvent& event) { |
| 223 auto* module_database = ModuleDatabase::GetInstance(); |
| 224 uintptr_t load_address = |
| 225 reinterpret_cast<uintptr_t>(event.module_load_address); |
| 226 |
| 227 switch (event.event_type) { |
| 228 case mojom::ModuleEventType::MODULE_ALREADY_LOADED: |
| 229 case mojom::ModuleEventType::MODULE_LOADED: { |
| 230 module_database->OnModuleLoad( |
| 231 process_id, creation_time, event.module_path, event.module_size, |
| 232 GetModuleTimeDateStamp(event.module_load_address), load_address); |
| 233 return; |
| 234 } |
| 235 |
| 236 case mojom::ModuleEventType::MODULE_UNLOADED: { |
| 237 module_database->OnModuleUnload(process_id, creation_time, load_address); |
| 238 return; |
| 239 } |
| 240 } |
| 241 } |
| 242 |
| 243 // Helper function for initializing the module database subsystem. Populates |
| 244 // the provided |module_watcher|. |
| 245 void SetupModuleDatabase(std::unique_ptr<ModuleWatcher>* module_watcher) { |
| 246 uint64_t creation_time = 0; |
| 247 ModuleEventSinkImpl::GetProcessCreationTime(::GetCurrentProcess(), |
| 248 &creation_time); |
| 249 ModuleDatabase::SetInstance(base::MakeUnique<ModuleDatabase>( |
| 250 content::BrowserThread::GetTaskRunnerForThread( |
| 251 content::BrowserThread::UI))); |
| 252 auto* module_database = ModuleDatabase::GetInstance(); |
| 253 uint32_t process_id = ::GetCurrentProcessId(); |
| 254 |
| 255 // The ModuleWatcher will immediately start emitting module events, but the |
| 256 // ModuleDatabase expects an OnProcessStarted event prior to that. For child |
| 257 // processes this is handled via the ModuleEventSinkImpl. For the browser |
| 258 // process a manual notification is sent before wiring up the ModuleWatcher. |
| 259 module_database->OnProcessStarted(process_id, creation_time, |
| 260 content::PROCESS_TYPE_BROWSER); |
| 261 *module_watcher = ModuleWatcher::Create( |
| 262 base::Bind(&OnModuleEvent, process_id, creation_time)); |
| 263 } |
| 264 |
| 205 } // namespace | 265 } // namespace |
| 206 | 266 |
| 207 void ShowCloseBrowserFirstMessageBox() { | 267 void ShowCloseBrowserFirstMessageBox() { |
| 208 int message_id = IDS_UNINSTALL_CLOSE_APP; | 268 int message_id = IDS_UNINSTALL_CLOSE_APP; |
| 209 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && | 269 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && |
| 210 (shell_integration::GetDefaultBrowser() == | 270 (shell_integration::GetDefaultBrowser() == |
| 211 shell_integration::IS_DEFAULT)) { | 271 shell_integration::IS_DEFAULT)) { |
| 212 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE; | 272 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE; |
| 213 } | 273 } |
| 214 chrome::ShowWarningMessageBox(NULL, | 274 chrome::ShowWarningMessageBox(NULL, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 ChromeBrowserMainParts::PostProfileInit(); | 379 ChromeBrowserMainParts::PostProfileInit(); |
| 320 | 380 |
| 321 // TODO(kulshin): remove this cleanup code in 2017. http://crbug.com/603718 | 381 // TODO(kulshin): remove this cleanup code in 2017. http://crbug.com/603718 |
| 322 // Attempt to delete the font cache and ignore any errors. | 382 // Attempt to delete the font cache and ignore any errors. |
| 323 base::FilePath path( | 383 base::FilePath path( |
| 324 profile()->GetPath().AppendASCII("ChromeDWriteFontCache")); | 384 profile()->GetPath().AppendASCII("ChromeDWriteFontCache")); |
| 325 content::BrowserThread::PostAfterStartupTask( | 385 content::BrowserThread::PostAfterStartupTask( |
| 326 FROM_HERE, content::BrowserThread::GetTaskRunnerForThread( | 386 FROM_HERE, content::BrowserThread::GetTaskRunnerForThread( |
| 327 content::BrowserThread::FILE), | 387 content::BrowserThread::FILE), |
| 328 base::Bind(base::IgnoreResult(&base::DeleteFile), path, false)); | 388 base::Bind(base::IgnoreResult(&base::DeleteFile), path, false)); |
| 389 |
| 390 // Create the module database and hook up the in-process module watcher. This |
| 391 // needs to be done before any child processes are initialized as the |
| 392 // ModuleDatabase is an endpoint for IPC from child processes. |
| 393 if (base::FeatureList::IsEnabled(features::kModuleDatabase)) |
| 394 SetupModuleDatabase(&module_watcher_); |
| 329 } | 395 } |
| 330 | 396 |
| 331 void ChromeBrowserMainPartsWin::PostBrowserStart() { | 397 void ChromeBrowserMainPartsWin::PostBrowserStart() { |
| 332 ChromeBrowserMainParts::PostBrowserStart(); | 398 ChromeBrowserMainParts::PostBrowserStart(); |
| 333 | 399 |
| 334 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice(nullptr)); | 400 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice(nullptr)); |
| 335 | 401 |
| 336 // Set up a task to verify installed modules in the current process. | 402 // Set up a task to verify installed modules in the current process. |
| 337 content::BrowserThread::PostAfterStartupTask( | 403 content::BrowserThread::PostAfterStartupTask( |
| 338 FROM_HERE, content::BrowserThread::GetBlockingPool(), | 404 FROM_HERE, content::BrowserThread::GetBlockingPool(), |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 if (resource_id) | 589 if (resource_id) |
| 524 return l10n_util::GetStringUTF16(resource_id); | 590 return l10n_util::GetStringUTF16(resource_id); |
| 525 return base::string16(); | 591 return base::string16(); |
| 526 } | 592 } |
| 527 | 593 |
| 528 // static | 594 // static |
| 529 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() { | 595 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() { |
| 530 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ()); | 596 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ()); |
| 531 installer::SetTranslationDelegate(&delegate); | 597 installer::SetTranslationDelegate(&delegate); |
| 532 } | 598 } |
| OLD | NEW |