| 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 <windows.h> | 7 #include <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "chrome/installer/util/browser_distribution.h" | 50 #include "chrome/installer/util/browser_distribution.h" |
| 51 #include "chrome/installer/util/helper.h" | 51 #include "chrome/installer/util/helper.h" |
| 52 #include "chrome/installer/util/install_util.h" | 52 #include "chrome/installer/util/install_util.h" |
| 53 #include "chrome/installer/util/installer_util_strings.h" | 53 #include "chrome/installer/util/installer_util_strings.h" |
| 54 #include "chrome/installer/util/l10n_string_util.h" | 54 #include "chrome/installer/util/l10n_string_util.h" |
| 55 #include "chrome/installer/util/shell_util.h" | 55 #include "chrome/installer/util/shell_util.h" |
| 56 #include "content/public/browser/browser_thread.h" | 56 #include "content/public/browser/browser_thread.h" |
| 57 #include "content/public/browser/utility_process_host.h" | 57 #include "content/public/browser/utility_process_host.h" |
| 58 #include "content/public/browser/utility_process_host_client.h" | 58 #include "content/public/browser/utility_process_host_client.h" |
| 59 #include "content/public/common/content_switches.h" | 59 #include "content/public/common/content_switches.h" |
| 60 #include "content/public/common/dwrite_font_platform_win.h" | |
| 61 #include "content/public/common/main_function_params.h" | 60 #include "content/public/common/main_function_params.h" |
| 62 #include "ui/base/cursor/cursor_loader_win.h" | 61 #include "ui/base/cursor/cursor_loader_win.h" |
| 63 #include "ui/base/l10n/l10n_util.h" | 62 #include "ui/base/l10n/l10n_util.h" |
| 64 #include "ui/base/l10n/l10n_util_win.h" | 63 #include "ui/base/l10n/l10n_util_win.h" |
| 65 #include "ui/base/ui_base_switches.h" | 64 #include "ui/base/ui_base_switches.h" |
| 66 #include "ui/base/win/message_box_win.h" | 65 #include "ui/base/win/message_box_win.h" |
| 67 #include "ui/gfx/platform_font_win.h" | 66 #include "ui/gfx/platform_font_win.h" |
| 68 #include "ui/gfx/switches.h" | 67 #include "ui/gfx/switches.h" |
| 69 #include "ui/gfx/win/direct_write.h" | 68 #include "ui/gfx/win/direct_write.h" |
| 70 #include "ui/strings/grit/app_locale_settings.h" | 69 #include "ui/strings/grit/app_locale_settings.h" |
| 71 | 70 |
| 72 #if defined(GOOGLE_CHROME_BUILD) | 71 #if defined(GOOGLE_CHROME_BUILD) |
| 73 #include "chrome/browser/google/did_run_updater_win.h" | 72 #include "chrome/browser/google/did_run_updater_win.h" |
| 74 #endif | 73 #endif |
| 75 | 74 |
| 76 #if defined(KASKO) | 75 #if defined(KASKO) |
| 77 #include "syzygy/kasko/api/reporter.h" | 76 #include "syzygy/kasko/api/reporter.h" |
| 78 #endif | 77 #endif |
| 79 | 78 |
| 80 namespace { | 79 namespace { |
| 81 | 80 |
| 82 typedef HRESULT (STDAPICALLTYPE* RegisterApplicationRestartProc)( | 81 typedef HRESULT (STDAPICALLTYPE* RegisterApplicationRestartProc)( |
| 83 const wchar_t* command_line, | 82 const wchar_t* command_line, |
| 84 DWORD flags); | 83 DWORD flags); |
| 85 | 84 |
| 85 const char kFontCacheSharedSectionName[] = "ChromeDWriteFontCache"; |
| 86 |
| 86 void InitializeWindowProcExceptions() { | 87 void InitializeWindowProcExceptions() { |
| 87 // Get the breakpad pointer from chrome.exe | 88 // Get the breakpad pointer from chrome.exe |
| 88 base::win::WinProcExceptionFilter exception_filter = | 89 base::win::WinProcExceptionFilter exception_filter = |
| 89 reinterpret_cast<base::win::WinProcExceptionFilter>( | 90 reinterpret_cast<base::win::WinProcExceptionFilter>( |
| 90 ::GetProcAddress(::GetModuleHandle( | 91 ::GetProcAddress(::GetModuleHandle( |
| 91 chrome::kBrowserProcessExecutableName), | 92 chrome::kBrowserProcessExecutableName), |
| 92 "CrashForException")); | 93 "CrashForException")); |
| 93 exception_filter = base::win::SetWinProcExceptionFilter(exception_filter); | 94 exception_filter = base::win::SetWinProcExceptionFilter(exception_filter); |
| 94 DCHECK(!exception_filter); | 95 DCHECK(!exception_filter); |
| 95 } | 96 } |
| 96 | 97 |
| 97 // gfx::Font callbacks | 98 // gfx::Font callbacks |
| 98 void AdjustUIFont(LOGFONT* logfont) { | 99 void AdjustUIFont(LOGFONT* logfont) { |
| 99 l10n_util::AdjustUIFont(logfont); | 100 l10n_util::AdjustUIFont(logfont); |
| 100 } | 101 } |
| 101 | 102 |
| 102 int GetMinimumFontSize() { | 103 int GetMinimumFontSize() { |
| 103 int min_font_size; | 104 int min_font_size; |
| 104 base::StringToInt(l10n_util::GetStringUTF16(IDS_MINIMUM_UI_FONT_SIZE), | 105 base::StringToInt(l10n_util::GetStringUTF16(IDS_MINIMUM_UI_FONT_SIZE), |
| 105 &min_font_size); | 106 &min_font_size); |
| 106 return min_font_size; | 107 return min_font_size; |
| 107 } | 108 } |
| 108 | 109 |
| 109 class TranslationDelegate : public installer::TranslationDelegate { | 110 class TranslationDelegate : public installer::TranslationDelegate { |
| 110 public: | 111 public: |
| 111 base::string16 GetLocalizedString(int installer_string_id) override; | 112 base::string16 GetLocalizedString(int installer_string_id) override; |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 void ExecuteFontCacheBuildTask(const base::FilePath& path) { | |
| 115 base::WeakPtr<content::UtilityProcessHost> utility_process_host( | |
| 116 content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr()); | |
| 117 utility_process_host->SetName(l10n_util::GetStringUTF16( | |
| 118 IDS_UTILITY_PROCESS_FONT_CACHE_BUILDER_NAME)); | |
| 119 utility_process_host->DisableSandbox(); | |
| 120 utility_process_host->Send( | |
| 121 new ChromeUtilityHostMsg_BuildDirectWriteFontCache(path)); | |
| 122 } | |
| 123 | |
| 124 #if defined(KASKO) | 115 #if defined(KASKO) |
| 125 void ObserveFailedCrashReportDirectory(const base::FilePath& path, bool error) { | 116 void ObserveFailedCrashReportDirectory(const base::FilePath& path, bool error) { |
| 126 DCHECK(!error); | 117 DCHECK(!error); |
| 127 if (error) | 118 if (error) |
| 128 return; | 119 return; |
| 129 base::FileEnumerator enumerator(path, true, base::FileEnumerator::FILES); | 120 base::FileEnumerator enumerator(path, true, base::FileEnumerator::FILES); |
| 130 for (base::FilePath report_file = enumerator.Next(); !report_file.empty(); | 121 for (base::FilePath report_file = enumerator.Next(); !report_file.empty(); |
| 131 report_file = enumerator.Next()) { | 122 report_file = enumerator.Next()) { |
| 132 if (report_file.Extension() == | 123 if (report_file.Extension() == |
| 133 kasko::api::kPermanentFailureMinidumpExtension) { | 124 kasko::api::kPermanentFailureMinidumpExtension) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 199 |
| 209 // Look for the DLLs used to implement the FTH and other compat hacks. | 200 // Look for the DLLs used to implement the FTH and other compat hacks. |
| 210 if (GetModuleHandleW(L"AcLayers.dll") != NULL) | 201 if (GetModuleHandleW(L"AcLayers.dll") != NULL) |
| 211 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED); | 202 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED); |
| 212 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL) | 203 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL) |
| 213 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED); | 204 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED); |
| 214 | 205 |
| 215 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT); | 206 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT); |
| 216 } | 207 } |
| 217 | 208 |
| 209 void DeleteDirectWriteFontCache(base::FilePath path) { |
| 210 // Attempt to delete the font cache and ignore any errors. |
| 211 base::DeleteFile(path, false /*recursive*/); |
| 212 } |
| 213 |
| 218 } // namespace | 214 } // namespace |
| 219 | 215 |
| 220 void ShowCloseBrowserFirstMessageBox() { | 216 void ShowCloseBrowserFirstMessageBox() { |
| 221 int message_id = IDS_UNINSTALL_CLOSE_APP; | 217 int message_id = IDS_UNINSTALL_CLOSE_APP; |
| 222 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && | 218 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && |
| 223 (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT)) { | 219 (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT)) { |
| 224 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE; | 220 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE; |
| 225 } | 221 } |
| 226 chrome::ShowMessageBox(NULL, | 222 chrome::ShowMessageBox(NULL, |
| 227 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | 223 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 void ChromeBrowserMainPartsWin::ShowMissingLocaleMessageBox() { | 331 void ChromeBrowserMainPartsWin::ShowMissingLocaleMessageBox() { |
| 336 ui::MessageBox(NULL, | 332 ui::MessageBox(NULL, |
| 337 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataMessage), | 333 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataMessage), |
| 338 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataTitle), | 334 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataTitle), |
| 339 MB_OK | MB_ICONERROR | MB_TOPMOST); | 335 MB_OK | MB_ICONERROR | MB_TOPMOST); |
| 340 } | 336 } |
| 341 | 337 |
| 342 void ChromeBrowserMainPartsWin::PostProfileInit() { | 338 void ChromeBrowserMainPartsWin::PostProfileInit() { |
| 343 ChromeBrowserMainParts::PostProfileInit(); | 339 ChromeBrowserMainParts::PostProfileInit(); |
| 344 | 340 |
| 345 // DirectWrite support is mainly available Windows 7 and up. | |
| 346 if (gfx::win::ShouldUseDirectWrite()) { | 341 if (gfx::win::ShouldUseDirectWrite()) { |
| 342 // Clean up the direct write font cache since we no longer use that |
| 343 // codepath. |
| 344 // TODO(kulshin): remove this code after several releases. |
| 347 base::FilePath path( | 345 base::FilePath path( |
| 348 profile()->GetPath().AppendASCII(content::kFontCacheSharedSectionName)); | 346 profile()->GetPath().AppendASCII(kFontCacheSharedSectionName)); |
| 349 // This function will create a read only section if cache file exists | 347 const int kBuildFontCacheDelaySec = 30; |
| 350 // otherwise it will spawn utility process to build cache file, which will | 348 content::BrowserThread::PostDelayedTask( |
| 351 // be used during next browser start/postprofileinit. | 349 content::BrowserThread::FILE, FROM_HERE, |
| 352 if (!content::LoadFontCache(path)) { | 350 base::Bind(DeleteDirectWriteFontCache, path), |
| 353 // We delay building of font cache until first startup page loads. | 351 base::TimeDelta::FromSeconds(kBuildFontCacheDelaySec)); |
| 354 // During first renderer start there are lot of things happening | |
| 355 // simultaneously some of them are: | |
| 356 // - Renderer is going through all font files on the system to create | |
| 357 // a font collection. | |
| 358 // - Renderer loading up startup URL, accessing HTML/JS File cache, | |
| 359 // net activity etc. | |
| 360 // - Extension initialization. | |
| 361 // We delay building of cache mainly to avoid parallel font file | |
| 362 // loading along with Renderer. Some systems have significant number of | |
| 363 // font files which takes long time to process. | |
| 364 // Related information is at http://crbug.com/436195. | |
| 365 const int kBuildFontCacheDelaySec = 30; | |
| 366 content::BrowserThread::PostDelayedTask( | |
| 367 content::BrowserThread::IO, | |
| 368 FROM_HERE, | |
| 369 base::Bind(ExecuteFontCacheBuildTask, path), | |
| 370 base::TimeDelta::FromSeconds(kBuildFontCacheDelaySec)); | |
| 371 } | |
| 372 } | 352 } |
| 373 } | 353 } |
| 374 | 354 |
| 375 void ChromeBrowserMainPartsWin::PostBrowserStart() { | 355 void ChromeBrowserMainPartsWin::PostBrowserStart() { |
| 376 ChromeBrowserMainParts::PostBrowserStart(); | 356 ChromeBrowserMainParts::PostBrowserStart(); |
| 377 | 357 |
| 378 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice()); | 358 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice()); |
| 379 | 359 |
| 380 // Set up a task to verify installed modules in the current process. | 360 // Set up a task to verify installed modules in the current process. |
| 381 content::BrowserThread::PostAfterStartupTask( | 361 content::BrowserThread::PostAfterStartupTask( |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 if (resource_id) | 553 if (resource_id) |
| 574 return l10n_util::GetStringUTF16(resource_id); | 554 return l10n_util::GetStringUTF16(resource_id); |
| 575 return base::string16(); | 555 return base::string16(); |
| 576 } | 556 } |
| 577 | 557 |
| 578 // static | 558 // static |
| 579 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() { | 559 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() { |
| 580 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ()); | 560 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ()); |
| 581 installer::SetTranslationDelegate(&delegate); | 561 installer::SetTranslationDelegate(&delegate); |
| 582 } | 562 } |
| OLD | NEW |