[email protected] | 6bd1513 | 2012-02-14 22:29:03 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 5 | #include "chrome/browser/chrome_browser_main_win.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 6 | |
[email protected] | 71b73f0 | 2011-04-06 15:57:29 | [diff] [blame] | 7 | #include <windows.h> |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame] | 8 | #include <shellapi.h> |
[email protected] | 4a0765a | 2009-05-08 23:12:25 | [diff] [blame] | 9 | |
[email protected] | c83dd91 | 2010-04-06 18:50:51 | [diff] [blame] | 10 | #include <algorithm> |
| 11 | |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | ae0f077 | 2010-08-13 04:54:10 | [diff] [blame] | 13 | #include "base/environment.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
[email protected] | 7cf1b6ce | 2010-03-20 06:37:01 | [diff] [blame] | 15 | #include "base/i18n/rtl.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 16 | #include "base/memory/scoped_ptr.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 17 | #include "base/path_service.h" |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame] | 18 | #include "base/scoped_native_library.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 19 | #include "base/strings/string_number_conversions.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 20 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 3e13864 | 2012-04-12 23:07:22 | [diff] [blame] | 21 | #include "base/win/metro.h" |
[email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 22 | #include "base/win/windows_version.h" |
[email protected] | ecb924c | 2011-03-17 00:34:09 | [diff] [blame] | 23 | #include "base/win/wrapped_window_proc.h" |
[email protected] | a3abd557 | 2011-04-15 02:09:33 | [diff] [blame] | 24 | #include "chrome/browser/browser_util_win.h" |
[email protected] | 8f685f6 | 2013-11-13 22:44:18 | [diff] [blame] | 25 | #include "chrome/browser/install_verification/win/install_verification.h" |
[email protected] | f8b2ca3 | 2011-11-22 14:58:23 | [diff] [blame] | 26 | #include "chrome/browser/profiles/profile_info_cache.h" |
[email protected] | f89b50f | 2012-08-16 21:36:50 | [diff] [blame] | 27 | #include "chrome/browser/profiles/profile_shortcut_manager.h" |
[email protected] | 5ad23621 | 2012-10-05 23:19:44 | [diff] [blame] | 28 | #include "chrome/browser/shell_integration.h" |
[email protected] | b50892c5f | 2012-05-13 07:34:14 | [diff] [blame] | 29 | #include "chrome/browser/ui/simple_message_box.h" |
[email protected] | aab81df | 2012-05-14 19:24:18 | [diff] [blame] | 30 | #include "chrome/browser/ui/uninstall_browser_prompt.h" |
[email protected] | ecb924c | 2011-03-17 00:34:09 | [diff] [blame] | 31 | #include "chrome/common/chrome_constants.h" |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 32 | #include "chrome/common/chrome_result_codes.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 33 | #include "chrome/common/chrome_switches.h" |
[email protected] | c8e8cb94 | 2013-09-10 23:36:08 | [diff] [blame] | 34 | #include "chrome/common/chrome_version_info.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 35 | #include "chrome/common/env_vars.h" |
[email protected] | a149a39 | 2012-12-05 05:46:44 | [diff] [blame] | 36 | #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
[email protected] | bf6117c7e | 2010-12-01 06:00:25 | [diff] [blame] | 37 | #include "chrome/installer/util/browser_distribution.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 38 | #include "chrome/installer/util/helper.h" |
| 39 | #include "chrome/installer/util/install_util.h" |
[email protected] | b4d08ea | 2012-05-24 19:26:57 | [diff] [blame] | 40 | #include "chrome/installer/util/l10n_string_util.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 41 | #include "chrome/installer/util/shell_util.h" |
[email protected] | 2c05d91 | 2013-10-08 17:53:31 | [diff] [blame] | 42 | #include "content/public/browser/browser_thread.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 43 | #include "content/public/common/main_function_params.h" |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 44 | #include "grit/app_locale_settings.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 45 | #include "grit/chromium_strings.h" |
| 46 | #include "grit/generated_resources.h" |
[email protected] | b4d08ea | 2012-05-24 19:26:57 | [diff] [blame] | 47 | #include "installer_util_strings/installer_util_strings.h" |
[email protected] | 12d8cfc | 2013-07-10 02:10:34 | [diff] [blame] | 48 | #include "ui/base/cursor/cursor_loader_win.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 49 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 50 | #include "ui/base/l10n/l10n_util_win.h" |
[email protected] | 8a6aaa7 | 2012-04-20 20:53:58 | [diff] [blame] | 51 | #include "ui/base/ui_base_switches.h" |
[email protected] | 3455af4e | 2012-03-12 15:35:12 | [diff] [blame] | 52 | #include "ui/base/win/message_box_win.h" |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 53 | #include "ui/gfx/platform_font_win.h" |
[email protected] | 0661d81 | 2013-11-12 05:25:29 | [diff] [blame] | 54 | #include "ui/gfx/switches.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 55 | |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 56 | namespace { |
[email protected] | ecb924c | 2011-03-17 00:34:09 | [diff] [blame] | 57 | |
[email protected] | a08ba82 | 2011-02-20 07:45:47 | [diff] [blame] | 58 | typedef HRESULT (STDAPICALLTYPE* RegisterApplicationRestartProc)( |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 59 | const wchar_t* command_line, |
| 60 | DWORD flags); |
[email protected] | ecb924c | 2011-03-17 00:34:09 | [diff] [blame] | 61 | |
| 62 | void InitializeWindowProcExceptions() { |
| 63 | // Get the breakpad pointer from chrome.exe |
| 64 | base::win::WinProcExceptionFilter exception_filter = |
| 65 | reinterpret_cast<base::win::WinProcExceptionFilter>( |
| 66 | ::GetProcAddress(::GetModuleHandle( |
| 67 | chrome::kBrowserProcessExecutableName), |
| 68 | "CrashForException")); |
| 69 | exception_filter = base::win::SetWinProcExceptionFilter(exception_filter); |
| 70 | DCHECK(!exception_filter); |
| 71 | } |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 72 | |
| 73 | // gfx::Font callbacks |
| 74 | void AdjustUIFont(LOGFONT* logfont) { |
| 75 | l10n_util::AdjustUIFont(logfont); |
| 76 | } |
| 77 | |
| 78 | int GetMinimumFontSize() { |
| 79 | int min_font_size; |
| 80 | base::StringToInt(l10n_util::GetStringUTF16(IDS_MINIMUM_UI_FONT_SIZE), |
| 81 | &min_font_size); |
| 82 | return min_font_size; |
| 83 | } |
| 84 | |
[email protected] | b4d08ea | 2012-05-24 19:26:57 | [diff] [blame] | 85 | class TranslationDelegate : public installer::TranslationDelegate { |
| 86 | public: |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 87 | virtual base::string16 GetLocalizedString(int installer_string_id) OVERRIDE; |
[email protected] | b4d08ea | 2012-05-24 19:26:57 | [diff] [blame] | 88 | }; |
| 89 | |
[email protected] | 0661d81 | 2013-11-12 05:25:29 | [diff] [blame] | 90 | bool IsSafeModeStart() { |
| 91 | return ::GetEnvironmentVariableA(chrome::kSafeModeEnvVar, NULL, 0) != 0; |
| 92 | } |
| 93 | |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 94 | } // namespace |
| 95 | |
[email protected] | 53c38d23 | 2009-02-13 20:52:18 | [diff] [blame] | 96 | void ShowCloseBrowserFirstMessageBox() { |
[email protected] | 5ad23621 | 2012-10-05 23:19:44 | [diff] [blame] | 97 | int message_id = IDS_UNINSTALL_CLOSE_APP; |
| 98 | if (base::win::GetVersion() >= base::win::VERSION_WIN8 && |
[email protected] | 8988665 | 2012-12-11 18:09:07 | [diff] [blame] | 99 | (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT)) { |
[email protected] | 5ad23621 | 2012-10-05 23:19:44 | [diff] [blame] | 100 | message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE; |
| 101 | } |
[email protected] | d3322029 | 2012-07-04 01:41:27 | [diff] [blame] | 102 | chrome::ShowMessageBox(NULL, |
| 103 | l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
[email protected] | 5ad23621 | 2012-10-05 23:19:44 | [diff] [blame] | 104 | l10n_util::GetStringUTF16(message_id), |
[email protected] | d3322029 | 2012-07-04 01:41:27 | [diff] [blame] | 105 | chrome::MESSAGE_BOX_TYPE_WARNING); |
[email protected] | 53c38d23 | 2009-02-13 20:52:18 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | int DoUninstallTasks(bool chrome_still_running) { |
[email protected] | a173cc9 | 2009-08-20 23:26:37 | [diff] [blame] | 109 | // We want to show a warning to user (and exit) if Chrome is already running |
| 110 | // *before* we show the uninstall confirmation dialog box. But while the |
| 111 | // uninstall confirmation dialog is up, user might start Chrome, so we |
| 112 | // check once again after user acknowledges Uninstall dialog. |
[email protected] | 53c38d23 | 2009-02-13 20:52:18 | [diff] [blame] | 113 | if (chrome_still_running) { |
| 114 | ShowCloseBrowserFirstMessageBox(); |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 115 | return chrome::RESULT_CODE_UNINSTALL_CHROME_ALIVE; |
[email protected] | 53c38d23 | 2009-02-13 20:52:18 | [diff] [blame] | 116 | } |
[email protected] | a149a39 | 2012-12-05 05:46:44 | [diff] [blame] | 117 | int result = chrome::ShowUninstallBrowserPrompt( |
| 118 | !chrome_launcher_support::IsAppLauncherPresent()); |
| 119 | // Don't offer to delete the profile if the App Launcher is also installed. |
[email protected] | a3abd557 | 2011-04-15 02:09:33 | [diff] [blame] | 120 | if (browser_util::IsBrowserAlreadyRunning()) { |
[email protected] | a173cc9 | 2009-08-20 23:26:37 | [diff] [blame] | 121 | ShowCloseBrowserFirstMessageBox(); |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 122 | return chrome::RESULT_CODE_UNINSTALL_CHROME_ALIVE; |
[email protected] | a173cc9 | 2009-08-20 23:26:37 | [diff] [blame] | 123 | } |
| 124 | |
[email protected] | aab81df | 2012-05-14 19:24:18 | [diff] [blame] | 125 | if (result != chrome::RESULT_CODE_UNINSTALL_USER_CANCEL) { |
[email protected] | 4df8786f | 2009-04-17 13:24:57 | [diff] [blame] | 126 | // The following actions are just best effort. |
[email protected] | 2f5bc32 | 2013-12-04 08:58:15 | [diff] [blame] | 127 | // TODO(gab): Look into removing this code which is now redundant with the |
| 128 | // work done by setup.exe on uninstall. |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 129 | VLOG(1) << "Executing uninstall actions"; |
[email protected] | dfa08b04 | 2011-12-28 23:07:21 | [diff] [blame] | 130 | if (!first_run::RemoveSentinel()) |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 131 | VLOG(1) << "Failed to delete sentinel file."; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 132 | base::FilePath chrome_exe; |
[email protected] | 2be1633 | 2012-10-23 19:36:31 | [diff] [blame] | 133 | if (PathService::Get(base::FILE_EXE, &chrome_exe)) { |
[email protected] | 2d457e95 | 2012-11-07 20:37:51 | [diff] [blame] | 134 | ShellUtil::ShortcutLocation user_shortcut_locations[] = { |
| 135 | ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
| 136 | ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, |
[email protected] | 2f5bc32 | 2013-12-04 08:58:15 | [diff] [blame] | 137 | ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
| 138 | ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, |
[email protected] | ec509ee1 | 2012-10-30 04:57:32 | [diff] [blame] | 139 | }; |
[email protected] | 5a050ff | 2013-01-04 04:49:50 | [diff] [blame] | 140 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
[email protected] | ec509ee1 | 2012-10-30 04:57:32 | [diff] [blame] | 141 | for (size_t i = 0; i < arraysize(user_shortcut_locations); ++i) { |
[email protected] | 4a1925c | 2013-05-06 19:58:23 | [diff] [blame] | 142 | if (!ShellUtil::RemoveShortcuts(user_shortcut_locations[i], dist, |
| 143 | ShellUtil::CURRENT_USER, chrome_exe)) { |
[email protected] | ec509ee1 | 2012-10-30 04:57:32 | [diff] [blame] | 144 | VLOG(1) << "Failed to delete shortcut at location " |
| 145 | << user_shortcut_locations[i]; |
| 146 | } |
[email protected] | 2be1633 | 2012-10-23 19:36:31 | [diff] [blame] | 147 | } |
[email protected] | 2be1633 | 2012-10-23 19:36:31 | [diff] [blame] | 148 | } else { |
| 149 | NOTREACHED(); |
[email protected] | f8b2ca3 | 2011-11-22 14:58:23 | [diff] [blame] | 150 | } |
[email protected] | 4df8786f | 2009-04-17 13:24:57 | [diff] [blame] | 151 | } |
[email protected] | aab81df | 2012-05-14 19:24:18 | [diff] [blame] | 152 | return result; |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 153 | } |
| 154 | |
[email protected] | c9343f1 | 2013-10-25 23:38:45 | [diff] [blame] | 155 | void MaybeEnableHighResolutionTimeEverywhere() { |
| 156 | chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 157 | bool user_enabled = CommandLine::ForCurrentProcess()->HasSwitch( |
| 158 | switches::kEnableHighResolutionTime); |
| 159 | if (user_enabled || channel == chrome::VersionInfo::CHANNEL_CANARY) { |
| 160 | bool is_enabled = base::TimeTicks::SetNowIsHighResNowIfSupported(); |
| 161 | if (is_enabled && !user_enabled) { |
| 162 | // Ensure that all of the renderers will enable it too. |
| 163 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 164 | switches::kEnableHighResolutionTime); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 169 | // ChromeBrowserMainPartsWin --------------------------------------------------- |
| 170 | |
| 171 | ChromeBrowserMainPartsWin::ChromeBrowserMainPartsWin( |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 172 | const content::MainFunctionParams& parameters) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 173 | : ChromeBrowserMainParts(parameters) { |
[email protected] | c9343f1 | 2013-10-25 23:38:45 | [diff] [blame] | 174 | MaybeEnableHighResolutionTimeEverywhere(); |
[email protected] | a144407 | 2012-06-22 20:51:38 | [diff] [blame] | 175 | if (base::win::IsMetroProcess()) { |
| 176 | typedef const wchar_t* (*GetMetroSwitches)(void); |
| 177 | GetMetroSwitches metro_switches_proc = reinterpret_cast<GetMetroSwitches>( |
| 178 | GetProcAddress(base::win::GetMetroModule(), |
| 179 | "GetMetroCommandLineSwitches")); |
[email protected] | 42049379 | 2012-09-14 19:33:51 | [diff] [blame] | 180 | if (metro_switches_proc) { |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 181 | base::string16 metro_switches = (*metro_switches_proc)(); |
[email protected] | 42049379 | 2012-09-14 19:33:51 | [diff] [blame] | 182 | if (!metro_switches.empty()) { |
| 183 | CommandLine extra_switches(CommandLine::NO_PROGRAM); |
| 184 | extra_switches.ParseFromString(metro_switches); |
| 185 | CommandLine::ForCurrentProcess()->AppendArguments(extra_switches, |
| 186 | false); |
| 187 | } |
[email protected] | a144407 | 2012-06-22 20:51:38 | [diff] [blame] | 188 | } |
[email protected] | 26af27c | 2012-06-19 00:03:08 | [diff] [blame] | 189 | } |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | b83575d | 2012-04-25 18:35:08 | [diff] [blame] | 192 | ChromeBrowserMainPartsWin::~ChromeBrowserMainPartsWin() { |
| 193 | } |
| 194 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 195 | void ChromeBrowserMainPartsWin::ToolkitInitialized() { |
| 196 | ChromeBrowserMainParts::ToolkitInitialized(); |
| 197 | gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; |
| 198 | gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; |
[email protected] | 12d8cfc | 2013-07-10 02:10:34 | [diff] [blame] | 199 | #if defined(USE_AURA) |
| 200 | ui::CursorLoaderWin::SetCursorResourceModule(chrome::kBrowserResourcesDll); |
| 201 | #endif |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 202 | } |
| 203 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 204 | void ChromeBrowserMainPartsWin::PreMainMessageLoopStart() { |
[email protected] | 1851bc5 | 2012-05-30 20:58:44 | [diff] [blame] | 205 | // installer_util references strings that are normally compiled into |
| 206 | // setup.exe. In Chrome, these strings are in the locale files. |
| 207 | SetupInstallerUtilStrings(); |
| 208 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 209 | ChromeBrowserMainParts::PreMainMessageLoopStart(); |
[email protected] | 716476c | 2011-12-29 00:07:03 | [diff] [blame] | 210 | if (!parameters().ui_task) { |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 211 | // Make sure that we know how to handle exceptions from the message loop. |
| 212 | InitializeWindowProcExceptions(); |
| 213 | } |
| 214 | } |
| 215 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 216 | int ChromeBrowserMainPartsWin::PreCreateThreads() { |
[email protected] | 96668ca | 2013-07-15 23:33:57 | [diff] [blame] | 217 | int rv = ChromeBrowserMainParts::PreCreateThreads(); |
| 218 | |
[email protected] | 0661d81 | 2013-11-12 05:25:29 | [diff] [blame] | 219 | if (IsSafeModeStart()) { |
| 220 | // TODO(cpu): disable other troublesome features for safe mode. |
| 221 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 222 | switches::kDisableGpu); |
| 223 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 224 | switches::kHighDPISupport, "0"); |
| 225 | } |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 226 | // TODO(viettrungluu): why don't we run this earlier? |
| 227 | if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs) && |
| 228 | base::win::GetVersion() < base::win::VERSION_XP) { |
| 229 | chrome::ShowMessageBox(NULL, |
| 230 | l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
| 231 | l10n_util::GetStringUTF16(IDS_UNSUPPORTED_OS_PRE_WIN_XP), |
| 232 | chrome::MESSAGE_BOX_TYPE_WARNING); |
| 233 | } |
| 234 | |
[email protected] | 96668ca | 2013-07-15 23:33:57 | [diff] [blame] | 235 | return rv; |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 236 | } |
| 237 | |
[email protected] | 60e78b5 | 2012-11-30 02:06:21 | [diff] [blame] | 238 | void ChromeBrowserMainPartsWin::ShowMissingLocaleMessageBox() { |
[email protected] | cc2a2a2 | 2013-12-24 23:12:15 | [diff] [blame] | 239 | ui::MessageBox(NULL, |
| 240 | base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataMessage), |
| 241 | base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataTitle), |
[email protected] | 60e78b5 | 2012-11-30 02:06:21 | [diff] [blame] | 242 | MB_OK | MB_ICONERROR | MB_TOPMOST); |
| 243 | } |
| 244 | |
[email protected] | 2c05d91 | 2013-10-08 17:53:31 | [diff] [blame] | 245 | void ChromeBrowserMainPartsWin::PostBrowserStart() { |
| 246 | ChromeBrowserMainParts::PostBrowserStart(); |
| 247 | |
| 248 | // Set up a task to verify installed modules in the current process. Use a |
| 249 | // delay to reduce the impact on startup time. |
| 250 | content::BrowserThread::GetMessageLoopProxyForThread( |
| 251 | content::BrowserThread::UI)->PostDelayedTask( |
| 252 | FROM_HERE, |
[email protected] | 8f685f6 | 2013-11-13 22:44:18 | [diff] [blame] | 253 | base::Bind(&VerifyInstallation), |
[email protected] | 2c05d91 | 2013-10-08 17:53:31 | [diff] [blame] | 254 | base::TimeDelta::FromSeconds(45)); |
| 255 | } |
| 256 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 257 | // static |
| 258 | void ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment( |
| 259 | const CommandLine& parsed_command_line) { |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 260 | // Clear this var so child processes don't show the dialog by default. |
[email protected] | ae0f077 | 2010-08-13 04:54:10 | [diff] [blame] | 261 | scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 262 | env->UnSetVar(env_vars::kShowRestart); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 263 | |
| 264 | // For non-interactive tests we don't restart on crash. |
[email protected] | ae0f077 | 2010-08-13 04:54:10 | [diff] [blame] | 265 | if (env->HasVar(env_vars::kHeadless)) |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 266 | return; |
| 267 | |
| 268 | // If the known command-line test options are used we don't create the |
| 269 | // environment block which means we don't get the restart dialog. |
| 270 | if (parsed_command_line.HasSwitch(switches::kBrowserCrashTest) || |
| 271 | parsed_command_line.HasSwitch(switches::kBrowserAssertTest) || |
| 272 | parsed_command_line.HasSwitch(switches::kNoErrorDialogs)) |
| 273 | return; |
| 274 | |
| 275 | // The encoding we use for the info is "title|context|direction" where |
| 276 | // direction is either env_vars::kRtlLocale or env_vars::kLtrLocale depending |
| 277 | // on the current locale. |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 278 | base::string16 dlg_strings(l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_TITLE)); |
[email protected] | 6baca1a | 2010-08-14 00:17:05 | [diff] [blame] | 279 | dlg_strings.push_back('|'); |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 280 | base::string16 adjusted_string( |
[email protected] | 1c53ffde1 | 2010-08-17 22:40:31 | [diff] [blame] | 281 | l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_CONTENT)); |
[email protected] | c32d31e | 2010-11-24 07:27:42 | [diff] [blame] | 282 | base::i18n::AdjustStringForLocaleDirection(&adjusted_string); |
[email protected] | 6baca1a | 2010-08-14 00:17:05 | [diff] [blame] | 283 | dlg_strings.append(adjusted_string); |
| 284 | dlg_strings.push_back('|'); |
[email protected] | cc2a2a2 | 2013-12-24 23:12:15 | [diff] [blame] | 285 | dlg_strings.append(base::ASCIIToUTF16( |
[email protected] | 6baca1a | 2010-08-14 00:17:05 | [diff] [blame] | 286 | base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale)); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 287 | |
[email protected] | cc2a2a2 | 2013-12-24 23:12:15 | [diff] [blame] | 288 | env->SetVar(env_vars::kRestartInfo, base::UTF16ToUTF8(dlg_strings)); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 289 | } |
| 290 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 291 | // static |
| 292 | void ChromeBrowserMainPartsWin::RegisterApplicationRestart( |
| 293 | const CommandLine& parsed_command_line) { |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 294 | DCHECK(base::win::GetVersion() >= base::win::VERSION_VISTA); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 295 | base::ScopedNativeLibrary library(base::FilePath(L"kernel32.dll")); |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 296 | // Get the function pointer for RegisterApplicationRestart. |
[email protected] | a08ba82 | 2011-02-20 07:45:47 | [diff] [blame] | 297 | RegisterApplicationRestartProc register_application_restart = |
[email protected] | c51f6c0 | 2013-05-30 18:45:44 | [diff] [blame] | 298 | reinterpret_cast<RegisterApplicationRestartProc>( |
[email protected] | a08ba82 | 2011-02-20 07:45:47 | [diff] [blame] | 299 | library.GetFunctionPointer("RegisterApplicationRestart")); |
[email protected] | 7b67275 | 2011-07-07 06:39:15 | [diff] [blame] | 300 | if (!register_application_restart) { |
| 301 | LOG(WARNING) << "Cannot find RegisterApplicationRestart in kernel32.dll"; |
| 302 | return; |
| 303 | } |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 304 | // The Windows Restart Manager expects a string of command line flags only, |
| 305 | // without the program. |
| 306 | CommandLine command_line(CommandLine::NO_PROGRAM); |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 307 | command_line.AppendArguments(parsed_command_line, false); |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 308 | if (!command_line.HasSwitch(switches::kRestoreLastSession)) |
| 309 | command_line.AppendSwitch(switches::kRestoreLastSession); |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 310 | |
| 311 | // Restart Chrome if the computer is restarted as the result of an update. |
| 312 | // This could be extended to handle crashes, hangs, and patches. |
[email protected] | 9dc12406b | 2011-03-03 15:50:30 | [diff] [blame] | 313 | HRESULT hr = register_application_restart( |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 314 | command_line.GetCommandLineString().c_str(), |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 315 | RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH); |
[email protected] | ffd3171 | 2012-03-10 18:38:14 | [diff] [blame] | 316 | if (FAILED(hr)) { |
[email protected] | e85646a1 | 2012-03-10 20:01:13 | [diff] [blame] | 317 | if (hr == E_INVALIDARG) { |
| 318 | LOG(WARNING) << "Command line too long for RegisterApplicationRestart"; |
| 319 | } else { |
| 320 | NOTREACHED() << "RegisterApplicationRestart failed. hr: " << hr << |
| 321 | ", command_line: " << command_line.GetCommandLineString(); |
| 322 | } |
[email protected] | ffd3171 | 2012-03-10 18:38:14 | [diff] [blame] | 323 | } |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 324 | } |
| 325 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 326 | // static |
| 327 | int ChromeBrowserMainPartsWin::HandleIconsCommands( |
| 328 | const CommandLine& parsed_command_line) { |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 329 | if (parsed_command_line.HasSwitch(switches::kHideIcons)) { |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 330 | base::string16 cp_applet; |
[email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 331 | base::win::Version version = base::win::GetVersion(); |
| 332 | if (version >= base::win::VERSION_VISTA) { |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 333 | cp_applet.assign(L"Programs and Features"); // Windows Vista and later. |
[email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 334 | } else if (version >= base::win::VERSION_XP) { |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 335 | cp_applet.assign(L"Add/Remove Programs"); // Windows XP. |
| 336 | } else { |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 337 | return chrome::RESULT_CODE_UNSUPPORTED_PARAM; // Not supported |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 338 | } |
| 339 | |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 340 | const base::string16 msg = |
[email protected] | 0f26d7b | 2011-01-05 19:10:44 | [diff] [blame] | 341 | l10n_util::GetStringFUTF16(IDS_HIDE_ICONS_NOT_SUPPORTED, cp_applet); |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 342 | const base::string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 343 | const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST; |
[email protected] | 75b6805 | 2011-02-03 06:01:16 | [diff] [blame] | 344 | if (IDOK == ui::MessageBox(NULL, msg, caption, flags)) |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 345 | ShellExecute(NULL, NULL, L"appwiz.cpl", NULL, NULL, SW_SHOWNORMAL); |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 346 | |
| 347 | // Exit as we are not launching the browser. |
| 348 | return content::RESULT_CODE_NORMAL_EXIT; |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 349 | } |
| 350 | // We don't hide icons so we shouldn't do anything special to show them |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 351 | return chrome::RESULT_CODE_UNSUPPORTED_PARAM; |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 352 | } |
| 353 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 354 | // static |
| 355 | bool ChromeBrowserMainPartsWin::CheckMachineLevelInstall() { |
[email protected] | bf6117c7e | 2010-12-01 06:00:25 | [diff] [blame] | 356 | // TODO(tommi): Check if using the default distribution is always the right |
| 357 | // thing to do. |
| 358 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame^] | 359 | Version version; |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 360 | InstallUtil::GetChromeVersion(dist, true, &version); |
| 361 | if (version.IsValid()) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 362 | base::FilePath exe_path; |
[email protected] | b969648 | 2010-11-30 23:56:18 | [diff] [blame] | 363 | PathService::Get(base::DIR_EXE, &exe_path); |
| 364 | std::wstring exe = exe_path.value(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 365 | base::FilePath user_exe_path(installer::GetChromeInstallPath(false, dist)); |
| 366 | if (base::FilePath::CompareEqualIgnoreCase(exe, user_exe_path.value())) { |
[email protected] | 33a7e08 | 2012-11-21 21:07:50 | [diff] [blame] | 367 | bool is_metro = base::win::IsMetroProcess(); |
| 368 | if (!is_metro) { |
| 369 | // The dialog cannot be shown in Win8 Metro as doing so hangs Chrome on |
| 370 | // an invisible dialog. |
| 371 | // TODO (gab): Get rid of this dialog altogether and auto-launch |
| 372 | // system-level Chrome instead. |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 373 | const base::string16 text = |
[email protected] | 33a7e08 | 2012-11-21 21:07:50 | [diff] [blame] | 374 | l10n_util::GetStringUTF16(IDS_MACHINE_LEVEL_INSTALL_CONFLICT); |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 375 | const base::string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
[email protected] | 33a7e08 | 2012-11-21 21:07:50 | [diff] [blame] | 376 | const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST; |
| 377 | ui::MessageBox(NULL, text, caption, flags); |
| 378 | } |
[email protected] | e5fbd496 | 2011-02-11 16:30:43 | [diff] [blame] | 379 | CommandLine uninstall_cmd( |
| 380 | InstallUtil::GetChromeUninstallCmd(false, dist->GetType())); |
| 381 | if (!uninstall_cmd.GetProgram().empty()) { |
[email protected] | 6d2bd3f | 2013-01-05 01:16:08 | [diff] [blame] | 382 | uninstall_cmd.AppendSwitch(installer::switches::kSelfDestruct); |
[email protected] | 74ca044 | 2010-12-15 14:44:50 | [diff] [blame] | 383 | uninstall_cmd.AppendSwitch(installer::switches::kForceUninstall); |
[email protected] | e6124ad5 | 2010-11-15 04:17:52 | [diff] [blame] | 384 | uninstall_cmd.AppendSwitch( |
[email protected] | 74ca044 | 2010-12-15 14:44:50 | [diff] [blame] | 385 | installer::switches::kDoNotRemoveSharedItems); |
[email protected] | 6d2bd3f | 2013-01-05 01:16:08 | [diff] [blame] | 386 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 387 | const base::FilePath setup_exe(uninstall_cmd.GetProgram()); |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 388 | const base::string16 params(uninstall_cmd.GetArgumentsString()); |
[email protected] | 6d2bd3f | 2013-01-05 01:16:08 | [diff] [blame] | 389 | |
| 390 | SHELLEXECUTEINFO sei = { sizeof(sei) }; |
| 391 | sei.fMask = SEE_MASK_NOASYNC; |
| 392 | sei.nShow = SW_SHOWNORMAL; |
| 393 | sei.lpFile = setup_exe.value().c_str(); |
| 394 | sei.lpParameters = params.c_str(); |
| 395 | // On Windows 8 SEE_MASK_FLAG_LOG_USAGE is necessary to guarantee we |
| 396 | // flip to the Desktop when launching. |
[email protected] | 33a7e08 | 2012-11-21 21:07:50 | [diff] [blame] | 397 | if (is_metro) |
[email protected] | 6d2bd3f | 2013-01-05 01:16:08 | [diff] [blame] | 398 | sei.fMask |= SEE_MASK_FLAG_LOG_USAGE; |
| 399 | |
| 400 | if (!::ShellExecuteEx(&sei)) |
| 401 | DPCHECK(false); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 402 | } |
| 403 | return true; |
| 404 | } |
| 405 | } |
| 406 | return false; |
| 407 | } |
[email protected] | b4d08ea | 2012-05-24 19:26:57 | [diff] [blame] | 408 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 409 | base::string16 TranslationDelegate::GetLocalizedString( |
| 410 | int installer_string_id) { |
[email protected] | b4d08ea | 2012-05-24 19:26:57 | [diff] [blame] | 411 | int resource_id = 0; |
| 412 | switch (installer_string_id) { |
| 413 | // HANDLE_STRING is used by the DO_INSTALLER_STRING_MAPPING macro which is in |
| 414 | // the generated header installer_util_strings.h. |
| 415 | #define HANDLE_STRING(base_id, chrome_id) \ |
| 416 | case base_id: \ |
| 417 | resource_id = chrome_id; \ |
| 418 | break; |
| 419 | DO_INSTALLER_STRING_MAPPING |
| 420 | #undef HANDLE_STRING |
| 421 | default: |
| 422 | NOTREACHED(); |
| 423 | } |
| 424 | if (resource_id) |
| 425 | return l10n_util::GetStringUTF16(resource_id); |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 426 | return base::string16(); |
[email protected] | b4d08ea | 2012-05-24 19:26:57 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | // static |
| 430 | void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() { |
| 431 | CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ()); |
| 432 | installer::SetTranslationDelegate(&delegate); |
| 433 | } |