blob: 9a19ceb12f19b9ba43f6364fe48998ddeb9a70f3 [file] [log] [blame]
[email protected]6bd15132012-02-14 22:29:031// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]5c9587c2008-12-09 21:20:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e6b5bc22011-09-08 22:01:565#include "chrome/browser/chrome_browser_main_win.h"
[email protected]5c9587c2008-12-09 21:20:166
[email protected]71b73f02011-04-06 15:57:297#include <windows.h>
[email protected]e0785902011-05-19 23:34:178#include <shellapi.h>
[email protected]4a0765a2009-05-08 23:12:259
[email protected]c83dd912010-04-06 18:50:5110#include <algorithm>
11
[email protected]5c9587c2008-12-09 21:20:1612#include "base/command_line.h"
[email protected]ae0f0772010-08-13 04:54:1013#include "base/environment.h"
[email protected]57999812013-02-24 05:40:5214#include "base/files/file_path.h"
[email protected]7cf1b6ce2010-03-20 06:37:0115#include "base/i18n/rtl.h"
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/scoped_ptr.h"
[email protected]5c9587c2008-12-09 21:20:1617#include "base/path_service.h"
[email protected]e0785902011-05-19 23:34:1718#include "base/scoped_native_library.h"
[email protected]3ea1b182013-02-08 22:38:4119#include "base/strings/string_number_conversions.h"
[email protected]135cb802013-06-09 16:44:2020#include "base/strings/utf_string_conversions.h"
[email protected]3e138642012-04-12 23:07:2221#include "base/win/metro.h"
[email protected]935aa542010-10-15 01:59:1522#include "base/win/windows_version.h"
[email protected]ecb924c2011-03-17 00:34:0923#include "base/win/wrapped_window_proc.h"
[email protected]a3abd5572011-04-15 02:09:3324#include "chrome/browser/browser_util_win.h"
[email protected]8f685f62013-11-13 22:44:1825#include "chrome/browser/install_verification/win/install_verification.h"
[email protected]f8b2ca32011-11-22 14:58:2326#include "chrome/browser/profiles/profile_info_cache.h"
[email protected]f89b50f2012-08-16 21:36:5027#include "chrome/browser/profiles/profile_shortcut_manager.h"
[email protected]5ad236212012-10-05 23:19:4428#include "chrome/browser/shell_integration.h"
[email protected]b50892c5f2012-05-13 07:34:1429#include "chrome/browser/ui/simple_message_box.h"
[email protected]aab81df2012-05-14 19:24:1830#include "chrome/browser/ui/uninstall_browser_prompt.h"
[email protected]ecb924c2011-03-17 00:34:0931#include "chrome/common/chrome_constants.h"
[email protected]1fcfb202011-07-19 19:53:1432#include "chrome/common/chrome_result_codes.h"
[email protected]5c9587c2008-12-09 21:20:1633#include "chrome/common/chrome_switches.h"
[email protected]c8e8cb942013-09-10 23:36:0834#include "chrome/common/chrome_version_info.h"
[email protected]5c9587c2008-12-09 21:20:1635#include "chrome/common/env_vars.h"
[email protected]a149a392012-12-05 05:46:4436#include "chrome/installer/launcher_support/chrome_launcher_support.h"
[email protected]bf6117c7e2010-12-01 06:00:2537#include "chrome/installer/util/browser_distribution.h"
[email protected]5c9587c2008-12-09 21:20:1638#include "chrome/installer/util/helper.h"
39#include "chrome/installer/util/install_util.h"
[email protected]b4d08ea2012-05-24 19:26:5740#include "chrome/installer/util/l10n_string_util.h"
[email protected]5c9587c2008-12-09 21:20:1641#include "chrome/installer/util/shell_util.h"
[email protected]2c05d912013-10-08 17:53:3142#include "content/public/browser/browser_thread.h"
[email protected]4573fbd2011-10-31 20:25:1843#include "content/public/common/main_function_params.h"
[email protected]c7480942011-11-08 19:18:2744#include "grit/app_locale_settings.h"
[email protected]34ac8f32009-02-22 23:03:2745#include "grit/chromium_strings.h"
46#include "grit/generated_resources.h"
[email protected]b4d08ea2012-05-24 19:26:5747#include "installer_util_strings/installer_util_strings.h"
[email protected]12d8cfc2013-07-10 02:10:3448#include "ui/base/cursor/cursor_loader_win.h"
[email protected]c051a1b2011-01-21 23:30:1749#include "ui/base/l10n/l10n_util.h"
[email protected]c7480942011-11-08 19:18:2750#include "ui/base/l10n/l10n_util_win.h"
[email protected]8a6aaa72012-04-20 20:53:5851#include "ui/base/ui_base_switches.h"
[email protected]3455af4e2012-03-12 15:35:1252#include "ui/base/win/message_box_win.h"
[email protected]c7480942011-11-08 19:18:2753#include "ui/gfx/platform_font_win.h"
[email protected]0661d812013-11-12 05:25:2954#include "ui/gfx/switches.h"
[email protected]5c9587c2008-12-09 21:20:1655
[email protected]0fd23af2011-02-20 06:33:0456namespace {
[email protected]ecb924c2011-03-17 00:34:0957
[email protected]a08ba822011-02-20 07:45:4758typedef HRESULT (STDAPICALLTYPE* RegisterApplicationRestartProc)(
[email protected]0fd23af2011-02-20 06:33:0459 const wchar_t* command_line,
60 DWORD flags);
[email protected]ecb924c2011-03-17 00:34:0961
62void 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]c7480942011-11-08 19:18:2772
73// gfx::Font callbacks
74void AdjustUIFont(LOGFONT* logfont) {
75 l10n_util::AdjustUIFont(logfont);
76}
77
78int 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]b4d08ea2012-05-24 19:26:5785class TranslationDelegate : public installer::TranslationDelegate {
86 public:
[email protected]96920152013-12-04 21:00:1687 virtual base::string16 GetLocalizedString(int installer_string_id) OVERRIDE;
[email protected]b4d08ea2012-05-24 19:26:5788};
89
[email protected]0661d812013-11-12 05:25:2990bool IsSafeModeStart() {
91 return ::GetEnvironmentVariableA(chrome::kSafeModeEnvVar, NULL, 0) != 0;
92}
93
[email protected]0fd23af2011-02-20 06:33:0494} // namespace
95
[email protected]53c38d232009-02-13 20:52:1896void ShowCloseBrowserFirstMessageBox() {
[email protected]5ad236212012-10-05 23:19:4497 int message_id = IDS_UNINSTALL_CLOSE_APP;
98 if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
[email protected]89886652012-12-11 18:09:0799 (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT)) {
[email protected]5ad236212012-10-05 23:19:44100 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE;
101 }
[email protected]d33220292012-07-04 01:41:27102 chrome::ShowMessageBox(NULL,
103 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
[email protected]5ad236212012-10-05 23:19:44104 l10n_util::GetStringUTF16(message_id),
[email protected]d33220292012-07-04 01:41:27105 chrome::MESSAGE_BOX_TYPE_WARNING);
[email protected]53c38d232009-02-13 20:52:18106}
107
108int DoUninstallTasks(bool chrome_still_running) {
[email protected]a173cc92009-08-20 23:26:37109 // 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]53c38d232009-02-13 20:52:18113 if (chrome_still_running) {
114 ShowCloseBrowserFirstMessageBox();
[email protected]1fcfb202011-07-19 19:53:14115 return chrome::RESULT_CODE_UNINSTALL_CHROME_ALIVE;
[email protected]53c38d232009-02-13 20:52:18116 }
[email protected]a149a392012-12-05 05:46:44117 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]a3abd5572011-04-15 02:09:33120 if (browser_util::IsBrowserAlreadyRunning()) {
[email protected]a173cc92009-08-20 23:26:37121 ShowCloseBrowserFirstMessageBox();
[email protected]1fcfb202011-07-19 19:53:14122 return chrome::RESULT_CODE_UNINSTALL_CHROME_ALIVE;
[email protected]a173cc92009-08-20 23:26:37123 }
124
[email protected]aab81df2012-05-14 19:24:18125 if (result != chrome::RESULT_CODE_UNINSTALL_USER_CANCEL) {
[email protected]4df8786f2009-04-17 13:24:57126 // The following actions are just best effort.
[email protected]2f5bc322013-12-04 08:58:15127 // TODO(gab): Look into removing this code which is now redundant with the
128 // work done by setup.exe on uninstall.
[email protected]8e96e502010-10-21 20:57:12129 VLOG(1) << "Executing uninstall actions";
[email protected]dfa08b042011-12-28 23:07:21130 if (!first_run::RemoveSentinel())
[email protected]8e96e502010-10-21 20:57:12131 VLOG(1) << "Failed to delete sentinel file.";
[email protected]650b2d52013-02-10 03:41:45132 base::FilePath chrome_exe;
[email protected]2be16332012-10-23 19:36:31133 if (PathService::Get(base::FILE_EXE, &chrome_exe)) {
[email protected]2d457e952012-11-07 20:37:51134 ShellUtil::ShortcutLocation user_shortcut_locations[] = {
135 ShellUtil::SHORTCUT_LOCATION_DESKTOP,
136 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH,
[email protected]2f5bc322013-12-04 08:58:15137 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
138 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
[email protected]ec509ee12012-10-30 04:57:32139 };
[email protected]5a050ff2013-01-04 04:49:50140 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
[email protected]ec509ee12012-10-30 04:57:32141 for (size_t i = 0; i < arraysize(user_shortcut_locations); ++i) {
[email protected]4a1925c2013-05-06 19:58:23142 if (!ShellUtil::RemoveShortcuts(user_shortcut_locations[i], dist,
143 ShellUtil::CURRENT_USER, chrome_exe)) {
[email protected]ec509ee12012-10-30 04:57:32144 VLOG(1) << "Failed to delete shortcut at location "
145 << user_shortcut_locations[i];
146 }
[email protected]2be16332012-10-23 19:36:31147 }
[email protected]2be16332012-10-23 19:36:31148 } else {
149 NOTREACHED();
[email protected]f8b2ca32011-11-22 14:58:23150 }
[email protected]4df8786f2009-04-17 13:24:57151 }
[email protected]aab81df2012-05-14 19:24:18152 return result;
[email protected]5c9587c2008-12-09 21:20:16153}
154
[email protected]c9343f12013-10-25 23:38:45155void 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]b48c9182011-10-26 18:03:30169// ChromeBrowserMainPartsWin ---------------------------------------------------
170
171ChromeBrowserMainPartsWin::ChromeBrowserMainPartsWin(
[email protected]4573fbd2011-10-31 20:25:18172 const content::MainFunctionParams& parameters)
[email protected]b48c9182011-10-26 18:03:30173 : ChromeBrowserMainParts(parameters) {
[email protected]c9343f12013-10-25 23:38:45174 MaybeEnableHighResolutionTimeEverywhere();
[email protected]a1444072012-06-22 20:51:38175 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]420493792012-09-14 19:33:51180 if (metro_switches_proc) {
[email protected]96920152013-12-04 21:00:16181 base::string16 metro_switches = (*metro_switches_proc)();
[email protected]420493792012-09-14 19:33:51182 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]a1444072012-06-22 20:51:38188 }
[email protected]26af27c2012-06-19 00:03:08189 }
[email protected]b48c9182011-10-26 18:03:30190}
191
[email protected]b83575d2012-04-25 18:35:08192ChromeBrowserMainPartsWin::~ChromeBrowserMainPartsWin() {
193}
194
[email protected]c7480942011-11-08 19:18:27195void ChromeBrowserMainPartsWin::ToolkitInitialized() {
196 ChromeBrowserMainParts::ToolkitInitialized();
197 gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont;
198 gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize;
[email protected]12d8cfc2013-07-10 02:10:34199#if defined(USE_AURA)
200 ui::CursorLoaderWin::SetCursorResourceModule(chrome::kBrowserResourcesDll);
201#endif
[email protected]c7480942011-11-08 19:18:27202}
203
[email protected]b48c9182011-10-26 18:03:30204void ChromeBrowserMainPartsWin::PreMainMessageLoopStart() {
[email protected]1851bc52012-05-30 20:58:44205 // 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]c7480942011-11-08 19:18:27209 ChromeBrowserMainParts::PreMainMessageLoopStart();
[email protected]716476c2011-12-29 00:07:03210 if (!parameters().ui_task) {
[email protected]b48c9182011-10-26 18:03:30211 // Make sure that we know how to handle exceptions from the message loop.
212 InitializeWindowProcExceptions();
213 }
214}
215
[email protected]e8b6ca02013-07-10 18:00:51216int ChromeBrowserMainPartsWin::PreCreateThreads() {
[email protected]96668ca2013-07-15 23:33:57217 int rv = ChromeBrowserMainParts::PreCreateThreads();
218
[email protected]0661d812013-11-12 05:25:29219 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]e8b6ca02013-07-10 18:00:51226 // 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]96668ca2013-07-15 23:33:57235 return rv;
[email protected]e8b6ca02013-07-10 18:00:51236}
237
[email protected]60e78b52012-11-30 02:06:21238void ChromeBrowserMainPartsWin::ShowMissingLocaleMessageBox() {
[email protected]cc2a2a22013-12-24 23:12:15239 ui::MessageBox(NULL,
240 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataMessage),
241 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataTitle),
[email protected]60e78b52012-11-30 02:06:21242 MB_OK | MB_ICONERROR | MB_TOPMOST);
243}
244
[email protected]2c05d912013-10-08 17:53:31245void 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]8f685f62013-11-13 22:44:18253 base::Bind(&VerifyInstallation),
[email protected]2c05d912013-10-08 17:53:31254 base::TimeDelta::FromSeconds(45));
255}
256
[email protected]b48c9182011-10-26 18:03:30257// static
258void ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment(
259 const CommandLine& parsed_command_line) {
[email protected]5c9587c2008-12-09 21:20:16260 // Clear this var so child processes don't show the dialog by default.
[email protected]ae0f0772010-08-13 04:54:10261 scoped_ptr<base::Environment> env(base::Environment::Create());
262 env->UnSetVar(env_vars::kShowRestart);
[email protected]5c9587c2008-12-09 21:20:16263
264 // For non-interactive tests we don't restart on crash.
[email protected]ae0f0772010-08-13 04:54:10265 if (env->HasVar(env_vars::kHeadless))
[email protected]5c9587c2008-12-09 21:20:16266 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]96920152013-12-04 21:00:16278 base::string16 dlg_strings(l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_TITLE));
[email protected]6baca1a2010-08-14 00:17:05279 dlg_strings.push_back('|');
[email protected]96920152013-12-04 21:00:16280 base::string16 adjusted_string(
[email protected]1c53ffde12010-08-17 22:40:31281 l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_CONTENT));
[email protected]c32d31e2010-11-24 07:27:42282 base::i18n::AdjustStringForLocaleDirection(&adjusted_string);
[email protected]6baca1a2010-08-14 00:17:05283 dlg_strings.append(adjusted_string);
284 dlg_strings.push_back('|');
[email protected]cc2a2a22013-12-24 23:12:15285 dlg_strings.append(base::ASCIIToUTF16(
[email protected]6baca1a2010-08-14 00:17:05286 base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale));
[email protected]5c9587c2008-12-09 21:20:16287
[email protected]cc2a2a22013-12-24 23:12:15288 env->SetVar(env_vars::kRestartInfo, base::UTF16ToUTF8(dlg_strings));
[email protected]5c9587c2008-12-09 21:20:16289}
290
[email protected]b48c9182011-10-26 18:03:30291// static
292void ChromeBrowserMainPartsWin::RegisterApplicationRestart(
293 const CommandLine& parsed_command_line) {
[email protected]0fd23af2011-02-20 06:33:04294 DCHECK(base::win::GetVersion() >= base::win::VERSION_VISTA);
[email protected]650b2d52013-02-10 03:41:45295 base::ScopedNativeLibrary library(base::FilePath(L"kernel32.dll"));
[email protected]0fd23af2011-02-20 06:33:04296 // Get the function pointer for RegisterApplicationRestart.
[email protected]a08ba822011-02-20 07:45:47297 RegisterApplicationRestartProc register_application_restart =
[email protected]c51f6c02013-05-30 18:45:44298 reinterpret_cast<RegisterApplicationRestartProc>(
[email protected]a08ba822011-02-20 07:45:47299 library.GetFunctionPointer("RegisterApplicationRestart"));
[email protected]7b672752011-07-07 06:39:15300 if (!register_application_restart) {
301 LOG(WARNING) << "Cannot find RegisterApplicationRestart in kernel32.dll";
302 return;
303 }
[email protected]0fd23af2011-02-20 06:33:04304 // 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]a40ca4302011-05-14 01:10:24307 command_line.AppendArguments(parsed_command_line, false);
[email protected]0fd23af2011-02-20 06:33:04308 if (!command_line.HasSwitch(switches::kRestoreLastSession))
309 command_line.AppendSwitch(switches::kRestoreLastSession);
[email protected]0fd23af2011-02-20 06:33:04310
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]9dc12406b2011-03-03 15:50:30313 HRESULT hr = register_application_restart(
[email protected]61a4c6f2011-07-20 04:54:52314 command_line.GetCommandLineString().c_str(),
[email protected]0fd23af2011-02-20 06:33:04315 RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH);
[email protected]ffd31712012-03-10 18:38:14316 if (FAILED(hr)) {
[email protected]e85646a12012-03-10 20:01:13317 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]ffd31712012-03-10 18:38:14323 }
[email protected]0fd23af2011-02-20 06:33:04324}
325
[email protected]b48c9182011-10-26 18:03:30326// static
327int ChromeBrowserMainPartsWin::HandleIconsCommands(
328 const CommandLine& parsed_command_line) {
[email protected]5c9587c2008-12-09 21:20:16329 if (parsed_command_line.HasSwitch(switches::kHideIcons)) {
[email protected]96920152013-12-04 21:00:16330 base::string16 cp_applet;
[email protected]935aa542010-10-15 01:59:15331 base::win::Version version = base::win::GetVersion();
332 if (version >= base::win::VERSION_VISTA) {
[email protected]5c9587c2008-12-09 21:20:16333 cp_applet.assign(L"Programs and Features"); // Windows Vista and later.
[email protected]935aa542010-10-15 01:59:15334 } else if (version >= base::win::VERSION_XP) {
[email protected]5c9587c2008-12-09 21:20:16335 cp_applet.assign(L"Add/Remove Programs"); // Windows XP.
336 } else {
[email protected]1fcfb202011-07-19 19:53:14337 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; // Not supported
[email protected]5c9587c2008-12-09 21:20:16338 }
339
[email protected]96920152013-12-04 21:00:16340 const base::string16 msg =
[email protected]0f26d7b2011-01-05 19:10:44341 l10n_util::GetStringFUTF16(IDS_HIDE_ICONS_NOT_SUPPORTED, cp_applet);
[email protected]96920152013-12-04 21:00:16342 const base::string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
[email protected]5c9587c2008-12-09 21:20:16343 const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST;
[email protected]75b68052011-02-03 06:01:16344 if (IDOK == ui::MessageBox(NULL, msg, caption, flags))
[email protected]5c9587c2008-12-09 21:20:16345 ShellExecute(NULL, NULL, L"appwiz.cpl", NULL, NULL, SW_SHOWNORMAL);
[email protected]1fcfb202011-07-19 19:53:14346
347 // Exit as we are not launching the browser.
348 return content::RESULT_CODE_NORMAL_EXIT;
[email protected]5c9587c2008-12-09 21:20:16349 }
350 // We don't hide icons so we shouldn't do anything special to show them
[email protected]1fcfb202011-07-19 19:53:14351 return chrome::RESULT_CODE_UNSUPPORTED_PARAM;
[email protected]5c9587c2008-12-09 21:20:16352}
353
[email protected]b48c9182011-10-26 18:03:30354// static
355bool ChromeBrowserMainPartsWin::CheckMachineLevelInstall() {
[email protected]bf6117c7e2010-12-01 06:00:25356 // TODO(tommi): Check if using the default distribution is always the right
357 // thing to do.
358 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
[email protected]c5e4a2222014-01-03 16:06:13359 Version version;
[email protected]12126d372012-07-11 18:40:53360 InstallUtil::GetChromeVersion(dist, true, &version);
361 if (version.IsValid()) {
[email protected]650b2d52013-02-10 03:41:45362 base::FilePath exe_path;
[email protected]b9696482010-11-30 23:56:18363 PathService::Get(base::DIR_EXE, &exe_path);
364 std::wstring exe = exe_path.value();
[email protected]650b2d52013-02-10 03:41:45365 base::FilePath user_exe_path(installer::GetChromeInstallPath(false, dist));
366 if (base::FilePath::CompareEqualIgnoreCase(exe, user_exe_path.value())) {
[email protected]33a7e082012-11-21 21:07:50367 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]96920152013-12-04 21:00:16373 const base::string16 text =
[email protected]33a7e082012-11-21 21:07:50374 l10n_util::GetStringUTF16(IDS_MACHINE_LEVEL_INSTALL_CONFLICT);
[email protected]96920152013-12-04 21:00:16375 const base::string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
[email protected]33a7e082012-11-21 21:07:50376 const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST;
377 ui::MessageBox(NULL, text, caption, flags);
378 }
[email protected]e5fbd4962011-02-11 16:30:43379 CommandLine uninstall_cmd(
380 InstallUtil::GetChromeUninstallCmd(false, dist->GetType()));
381 if (!uninstall_cmd.GetProgram().empty()) {
[email protected]6d2bd3f2013-01-05 01:16:08382 uninstall_cmd.AppendSwitch(installer::switches::kSelfDestruct);
[email protected]74ca0442010-12-15 14:44:50383 uninstall_cmd.AppendSwitch(installer::switches::kForceUninstall);
[email protected]e6124ad52010-11-15 04:17:52384 uninstall_cmd.AppendSwitch(
[email protected]74ca0442010-12-15 14:44:50385 installer::switches::kDoNotRemoveSharedItems);
[email protected]6d2bd3f2013-01-05 01:16:08386
[email protected]650b2d52013-02-10 03:41:45387 const base::FilePath setup_exe(uninstall_cmd.GetProgram());
[email protected]96920152013-12-04 21:00:16388 const base::string16 params(uninstall_cmd.GetArgumentsString());
[email protected]6d2bd3f2013-01-05 01:16:08389
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]33a7e082012-11-21 21:07:50397 if (is_metro)
[email protected]6d2bd3f2013-01-05 01:16:08398 sei.fMask |= SEE_MASK_FLAG_LOG_USAGE;
399
400 if (!::ShellExecuteEx(&sei))
401 DPCHECK(false);
[email protected]5c9587c2008-12-09 21:20:16402 }
403 return true;
404 }
405 }
406 return false;
407}
[email protected]b4d08ea2012-05-24 19:26:57408
[email protected]6a72a632013-12-12 22:22:00409base::string16 TranslationDelegate::GetLocalizedString(
410 int installer_string_id) {
[email protected]b4d08ea2012-05-24 19:26:57411 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]96920152013-12-04 21:00:16426 return base::string16();
[email protected]b4d08ea2012-05-24 19:26:57427}
428
429// static
430void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() {
431 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ());
432 installer::SetTranslationDelegate(&delegate);
433}