Update V8 to version 4.7.21.
[chromium-blink-merge.git] / chrome / browser / chrome_browser_main_win.cc
blob5a7e6fcba0c491ce1b2b290183ddde9fbed58478
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chrome_browser_main_win.h"
7 #include <windows.h>
8 #include <shellapi.h>
10 #include <algorithm>
12 #include "base/command_line.h"
13 #include "base/environment.h"
14 #include "base/files/file_enumerator.h"
15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h"
17 #include "base/i18n/rtl.h"
18 #include "base/location.h"
19 #include "base/macros.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "base/metrics/histogram.h"
22 #include "base/path_service.h"
23 #include "base/scoped_native_library.h"
24 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/utf_string_conversions.h"
26 #include "base/win/metro.h"
27 #include "base/win/registry.h"
28 #include "base/win/win_util.h"
29 #include "base/win/windows_version.h"
30 #include "base/win/wrapped_window_proc.h"
31 #include "chrome/browser/browser_util_win.h"
32 #include "chrome/browser/chrome_elf_init_win.h"
33 #include "chrome/browser/first_run/first_run.h"
34 #include "chrome/browser/install_verification/win/install_verification.h"
35 #include "chrome/browser/profiles/profile_info_cache.h"
36 #include "chrome/browser/profiles/profile_shortcut_manager.h"
37 #include "chrome/browser/shell_integration.h"
38 #include "chrome/browser/ui/simple_message_box.h"
39 #include "chrome/browser/ui/uninstall_browser_prompt.h"
40 #include "chrome/chrome_watcher/chrome_watcher_main_api.h"
41 #include "chrome/common/chrome_constants.h"
42 #include "chrome/common/chrome_paths.h"
43 #include "chrome/common/chrome_result_codes.h"
44 #include "chrome/common/chrome_switches.h"
45 #include "chrome/common/chrome_utility_messages.h"
46 #include "chrome/common/env_vars.h"
47 #include "chrome/grit/chromium_strings.h"
48 #include "chrome/grit/generated_resources.h"
49 #include "chrome/installer/util/browser_distribution.h"
50 #include "chrome/installer/util/helper.h"
51 #include "chrome/installer/util/install_util.h"
52 #include "chrome/installer/util/installer_util_strings.h"
53 #include "chrome/installer/util/l10n_string_util.h"
54 #include "chrome/installer/util/shell_util.h"
55 #include "content/public/browser/browser_thread.h"
56 #include "content/public/browser/utility_process_host.h"
57 #include "content/public/browser/utility_process_host_client.h"
58 #include "content/public/common/content_switches.h"
59 #include "content/public/common/dwrite_font_platform_win.h"
60 #include "content/public/common/main_function_params.h"
61 #include "ui/base/cursor/cursor_loader_win.h"
62 #include "ui/base/l10n/l10n_util.h"
63 #include "ui/base/l10n/l10n_util_win.h"
64 #include "ui/base/ui_base_switches.h"
65 #include "ui/base/win/message_box_win.h"
66 #include "ui/gfx/platform_font_win.h"
67 #include "ui/gfx/switches.h"
68 #include "ui/gfx/win/direct_write.h"
69 #include "ui/strings/grit/app_locale_settings.h"
71 #if defined(GOOGLE_CHROME_BUILD)
72 #include "chrome/browser/google/did_run_updater_win.h"
73 #endif
75 #if defined(KASKO)
76 #include "syzygy/kasko/api/reporter.h"
77 #endif
79 namespace {
81 typedef HRESULT (STDAPICALLTYPE* RegisterApplicationRestartProc)(
82 const wchar_t* command_line,
83 DWORD flags);
85 void InitializeWindowProcExceptions() {
86 // Get the breakpad pointer from chrome.exe
87 base::win::WinProcExceptionFilter exception_filter =
88 reinterpret_cast<base::win::WinProcExceptionFilter>(
89 ::GetProcAddress(::GetModuleHandle(
90 chrome::kBrowserProcessExecutableName),
91 "CrashForException"));
92 exception_filter = base::win::SetWinProcExceptionFilter(exception_filter);
93 DCHECK(!exception_filter);
96 // gfx::Font callbacks
97 void AdjustUIFont(LOGFONT* logfont) {
98 l10n_util::AdjustUIFont(logfont);
101 int GetMinimumFontSize() {
102 int min_font_size;
103 base::StringToInt(l10n_util::GetStringUTF16(IDS_MINIMUM_UI_FONT_SIZE),
104 &min_font_size);
105 return min_font_size;
108 class TranslationDelegate : public installer::TranslationDelegate {
109 public:
110 base::string16 GetLocalizedString(int installer_string_id) override;
113 void ExecuteFontCacheBuildTask(const base::FilePath& path) {
114 base::WeakPtr<content::UtilityProcessHost> utility_process_host(
115 content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr());
116 utility_process_host->SetName(l10n_util::GetStringUTF16(
117 IDS_UTILITY_PROCESS_FONT_CACHE_BUILDER_NAME));
118 utility_process_host->DisableSandbox();
119 utility_process_host->Send(
120 new ChromeUtilityHostMsg_BuildDirectWriteFontCache(path));
123 #if defined(KASKO)
124 void ObserveFailedCrashReportDirectory(const base::FilePath& path, bool error) {
125 DCHECK(!error);
126 if (error)
127 return;
128 base::FileEnumerator enumerator(path, true, base::FileEnumerator::FILES);
129 for (base::FilePath report_file = enumerator.Next(); !report_file.empty();
130 report_file = enumerator.Next()) {
131 if (report_file.Extension() ==
132 kasko::api::kPermanentFailureMinidumpExtension) {
133 UMA_HISTOGRAM_BOOLEAN("CrashReport.PermanentUploadFailure", true);
135 bool result = base::DeleteFile(report_file, false);
136 DCHECK(result);
140 void StartFailedKaskoCrashReportWatcher(base::FilePathWatcher* watcher) {
141 base::FilePath watcher_data_directory;
142 if (!PathService::Get(chrome::DIR_WATCHER_DATA, &watcher_data_directory)) {
143 NOTREACHED();
144 } else {
145 base::FilePath permanent_failure_directory =
146 watcher_data_directory.Append(kPermanentlyFailedReportsSubdir);
147 if (!watcher->Watch(permanent_failure_directory, true,
148 base::Bind(&ObserveFailedCrashReportDirectory))) {
149 NOTREACHED();
152 // Call it once to observe any files present prior to the Watch() call.
153 ObserveFailedCrashReportDirectory(permanent_failure_directory, false);
156 #endif
158 void DetectFaultTolerantHeap() {
159 enum FTHFlags {
160 FTH_HKLM = 1,
161 FTH_HKCU = 2,
162 FTH_ACLAYERS_LOADED = 4,
163 FTH_ACXTRNAL_LOADED = 8,
164 FTH_FLAGS_COUNT = 16
167 // The Fault Tolerant Heap (FTH) is enabled on some customer machines and is
168 // affecting their performance. We need to know how many machines are
169 // affected in order to decide what to do.
171 // The main way that the FTH is enabled is by having a value set in
172 // HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
173 // whose name is the full path to the executable and whose data is the
174 // string FaultTolerantHeap. Some documents suggest that this data may also
175 // be found in HKCU. There have also been cases observed where this registry
176 // key is set but the FTH is not enabled, so we also look for AcXtrnal.dll
177 // and AcLayers.dll which are used to implement the FTH on Windows 7 and 8
178 // respectively.
180 // Get the module path so that we can look for it in the registry.
181 wchar_t module_path[MAX_PATH];
182 GetModuleFileName(NULL, module_path, ARRAYSIZE(module_path));
183 // Force null-termination, necessary on Windows XP.
184 module_path[ARRAYSIZE(module_path)-1] = 0;
186 const wchar_t* const kRegPath = L"Software\\Microsoft\\Windows NT\\"
187 L"CurrentVersion\\AppCompatFlags\\Layers";
188 const wchar_t* const kFTHData = L"FaultTolerantHeap";
189 // We always want to read from the 64-bit version of the registry if present,
190 // since that is what the OS looks at, even for 32-bit processes.
191 const DWORD kRegFlags = KEY_READ | KEY_WOW64_64KEY;
193 base::win::RegKey FTH_HKLM_reg(HKEY_LOCAL_MACHINE, kRegPath, kRegFlags);
194 FTHFlags detected = FTHFlags();
195 base::string16 chrome_app_compat;
196 if (FTH_HKLM_reg.ReadValue(module_path, &chrome_app_compat) == 0) {
197 // This *usually* indicates that the fault tolerant heap is enabled.
198 if (wcsicmp(chrome_app_compat.c_str(), kFTHData) == 0)
199 detected = static_cast<FTHFlags>(detected | FTH_HKLM);
202 base::win::RegKey FTH_HKCU_reg(HKEY_CURRENT_USER, kRegPath, kRegFlags);
203 if (FTH_HKCU_reg.ReadValue(module_path, &chrome_app_compat) == 0) {
204 if (wcsicmp(chrome_app_compat.c_str(), kFTHData) == 0)
205 detected = static_cast<FTHFlags>(detected | FTH_HKCU);
208 // Look for the DLLs used to implement the FTH and other compat hacks.
209 if (GetModuleHandleW(L"AcLayers.dll") != NULL)
210 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED);
211 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL)
212 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED);
214 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT);
217 } // namespace
219 void ShowCloseBrowserFirstMessageBox() {
220 int message_id = IDS_UNINSTALL_CLOSE_APP;
221 if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
222 (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT)) {
223 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE;
225 chrome::ShowMessageBox(NULL,
226 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
227 l10n_util::GetStringUTF16(message_id),
228 chrome::MESSAGE_BOX_TYPE_WARNING);
231 int DoUninstallTasks(bool chrome_still_running) {
232 // We want to show a warning to user (and exit) if Chrome is already running
233 // *before* we show the uninstall confirmation dialog box. But while the
234 // uninstall confirmation dialog is up, user might start Chrome, so we
235 // check once again after user acknowledges Uninstall dialog.
236 if (chrome_still_running) {
237 ShowCloseBrowserFirstMessageBox();
238 return chrome::RESULT_CODE_UNINSTALL_CHROME_ALIVE;
240 int result = chrome::ShowUninstallBrowserPrompt();
241 if (browser_util::IsBrowserAlreadyRunning()) {
242 ShowCloseBrowserFirstMessageBox();
243 return chrome::RESULT_CODE_UNINSTALL_CHROME_ALIVE;
246 if (result != chrome::RESULT_CODE_UNINSTALL_USER_CANCEL) {
247 // The following actions are just best effort.
248 // TODO(gab): Look into removing this code which is now redundant with the
249 // work done by setup.exe on uninstall.
250 VLOG(1) << "Executing uninstall actions";
251 base::FilePath chrome_exe;
252 if (PathService::Get(base::FILE_EXE, &chrome_exe)) {
253 ShellUtil::ShortcutLocation user_shortcut_locations[] = {
254 ShellUtil::SHORTCUT_LOCATION_DESKTOP,
255 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH,
256 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
257 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
259 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
260 for (size_t i = 0; i < arraysize(user_shortcut_locations); ++i) {
261 if (!ShellUtil::RemoveShortcuts(user_shortcut_locations[i], dist,
262 ShellUtil::CURRENT_USER, chrome_exe)) {
263 VLOG(1) << "Failed to delete shortcut at location "
264 << user_shortcut_locations[i];
267 } else {
268 NOTREACHED();
271 return result;
274 // ChromeBrowserMainPartsWin ---------------------------------------------------
276 ChromeBrowserMainPartsWin::ChromeBrowserMainPartsWin(
277 const content::MainFunctionParams& parameters)
278 : ChromeBrowserMainParts(parameters) {
279 if (base::win::IsMetroProcess()) {
280 typedef const wchar_t* (*GetMetroSwitches)(void);
281 GetMetroSwitches metro_switches_proc = reinterpret_cast<GetMetroSwitches>(
282 GetProcAddress(base::win::GetMetroModule(),
283 "GetMetroCommandLineSwitches"));
284 if (metro_switches_proc) {
285 base::string16 metro_switches = (*metro_switches_proc)();
286 if (!metro_switches.empty()) {
287 base::CommandLine extra_switches(base::CommandLine::NO_PROGRAM);
288 extra_switches.ParseFromString(metro_switches);
289 base::CommandLine::ForCurrentProcess()->AppendArguments(extra_switches,
290 false);
296 ChromeBrowserMainPartsWin::~ChromeBrowserMainPartsWin() {
299 void ChromeBrowserMainPartsWin::ToolkitInitialized() {
300 ChromeBrowserMainParts::ToolkitInitialized();
301 gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont;
302 gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize;
303 ui::CursorLoaderWin::SetCursorResourceModule(chrome::kBrowserResourcesDll);
306 void ChromeBrowserMainPartsWin::PreMainMessageLoopStart() {
307 // installer_util references strings that are normally compiled into
308 // setup.exe. In Chrome, these strings are in the locale files.
309 SetupInstallerUtilStrings();
311 ChromeBrowserMainParts::PreMainMessageLoopStart();
312 if (!parameters().ui_task) {
313 // Make sure that we know how to handle exceptions from the message loop.
314 InitializeWindowProcExceptions();
318 int ChromeBrowserMainPartsWin::PreCreateThreads() {
319 int rv = ChromeBrowserMainParts::PreCreateThreads();
321 // TODO(viettrungluu): why don't we run this earlier?
322 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs) &&
323 base::win::GetVersion() < base::win::VERSION_XP) {
324 chrome::ShowMessageBox(NULL,
325 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
326 l10n_util::GetStringUTF16(IDS_UNSUPPORTED_OS_PRE_WIN_XP),
327 chrome::MESSAGE_BOX_TYPE_WARNING);
330 return rv;
333 void ChromeBrowserMainPartsWin::ShowMissingLocaleMessageBox() {
334 ui::MessageBox(NULL,
335 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataMessage),
336 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataTitle),
337 MB_OK | MB_ICONERROR | MB_TOPMOST);
340 void ChromeBrowserMainPartsWin::PostProfileInit() {
341 ChromeBrowserMainParts::PostProfileInit();
343 // DirectWrite support is mainly available Windows 7 and up.
344 if (gfx::win::ShouldUseDirectWrite()) {
345 base::FilePath path(
346 profile()->GetPath().AppendASCII(content::kFontCacheSharedSectionName));
347 // This function will create a read only section if cache file exists
348 // otherwise it will spawn utility process to build cache file, which will
349 // be used during next browser start/postprofileinit.
350 if (!content::LoadFontCache(path)) {
351 // We delay building of font cache until first startup page loads.
352 // During first renderer start there are lot of things happening
353 // simultaneously some of them are:
354 // - Renderer is going through all font files on the system to create
355 // a font collection.
356 // - Renderer loading up startup URL, accessing HTML/JS File cache,
357 // net activity etc.
358 // - Extension initialization.
359 // We delay building of cache mainly to avoid parallel font file
360 // loading along with Renderer. Some systems have significant number of
361 // font files which takes long time to process.
362 // Related information is at http://crbug.com/436195.
363 const int kBuildFontCacheDelaySec = 30;
364 content::BrowserThread::PostDelayedTask(
365 content::BrowserThread::IO,
366 FROM_HERE,
367 base::Bind(ExecuteFontCacheBuildTask, path),
368 base::TimeDelta::FromSeconds(kBuildFontCacheDelaySec));
373 void ChromeBrowserMainPartsWin::PostBrowserStart() {
374 ChromeBrowserMainParts::PostBrowserStart();
376 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice());
378 // Set up a task to verify installed modules in the current process.
379 content::BrowserThread::PostAfterStartupTask(
380 FROM_HERE, content::BrowserThread::GetBlockingPool(),
381 base::Bind(&VerifyInstallation));
383 InitializeChromeElf();
385 #if defined(KASKO)
386 content::BrowserThread::PostDelayedTask(
387 content::BrowserThread::FILE, FROM_HERE,
388 base::Bind(&StartFailedKaskoCrashReportWatcher,
389 base::Unretained(&failed_kasko_crash_report_watcher_)),
390 base::TimeDelta::FromMinutes(5));
391 #endif
393 #if defined(GOOGLE_CHROME_BUILD)
394 did_run_updater_.reset(new DidRunUpdater);
395 #endif
397 // Record UMA data about whether the fault-tolerant heap is enabled.
398 // Use a delayed task to minimize the impact on startup time.
399 content::BrowserThread::PostDelayedTask(
400 content::BrowserThread::UI,
401 FROM_HERE,
402 base::Bind(&DetectFaultTolerantHeap),
403 base::TimeDelta::FromMinutes(1));
406 // static
407 void ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment(
408 const base::CommandLine& parsed_command_line) {
409 // Clear this var so child processes don't show the dialog by default.
410 scoped_ptr<base::Environment> env(base::Environment::Create());
411 env->UnSetVar(env_vars::kShowRestart);
413 // For non-interactive tests we don't restart on crash.
414 if (env->HasVar(env_vars::kHeadless))
415 return;
417 // If the known command-line test options are used we don't create the
418 // environment block which means we don't get the restart dialog.
419 if (parsed_command_line.HasSwitch(switches::kBrowserCrashTest) ||
420 parsed_command_line.HasSwitch(switches::kNoErrorDialogs))
421 return;
423 // The encoding we use for the info is "title|context|direction" where
424 // direction is either env_vars::kRtlLocale or env_vars::kLtrLocale depending
425 // on the current locale.
426 base::string16 dlg_strings(
427 l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_TITLE));
428 dlg_strings.push_back('|');
429 base::string16 adjusted_string(
430 l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_CONTENT));
431 base::i18n::AdjustStringForLocaleDirection(&adjusted_string);
432 dlg_strings.append(adjusted_string);
433 dlg_strings.push_back('|');
434 dlg_strings.append(base::ASCIIToUTF16(
435 base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale));
437 env->SetVar(env_vars::kRestartInfo, base::UTF16ToUTF8(dlg_strings));
440 // static
441 void ChromeBrowserMainPartsWin::RegisterApplicationRestart(
442 const base::CommandLine& parsed_command_line) {
443 DCHECK(base::win::GetVersion() >= base::win::VERSION_VISTA);
444 base::ScopedNativeLibrary library(base::FilePath(L"kernel32.dll"));
445 // Get the function pointer for RegisterApplicationRestart.
446 RegisterApplicationRestartProc register_application_restart =
447 reinterpret_cast<RegisterApplicationRestartProc>(
448 library.GetFunctionPointer("RegisterApplicationRestart"));
449 if (!register_application_restart) {
450 LOG(WARNING) << "Cannot find RegisterApplicationRestart in kernel32.dll";
451 return;
453 // The Windows Restart Manager expects a string of command line flags only,
454 // without the program.
455 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
456 command_line.AppendArguments(parsed_command_line, false);
457 if (!command_line.HasSwitch(switches::kRestoreLastSession))
458 command_line.AppendSwitch(switches::kRestoreLastSession);
460 // Restart Chrome if the computer is restarted as the result of an update.
461 // This could be extended to handle crashes, hangs, and patches.
462 HRESULT hr = register_application_restart(
463 command_line.GetCommandLineString().c_str(),
464 RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH);
465 if (FAILED(hr)) {
466 if (hr == E_INVALIDARG) {
467 LOG(WARNING) << "Command line too long for RegisterApplicationRestart";
468 } else {
469 NOTREACHED() << "RegisterApplicationRestart failed. hr: " << hr <<
470 ", command_line: " << command_line.GetCommandLineString();
475 // static
476 int ChromeBrowserMainPartsWin::HandleIconsCommands(
477 const base::CommandLine& parsed_command_line) {
478 if (parsed_command_line.HasSwitch(switches::kHideIcons)) {
479 base::string16 cp_applet;
480 base::win::Version version = base::win::GetVersion();
481 if (version >= base::win::VERSION_VISTA) {
482 cp_applet.assign(L"Programs and Features"); // Windows Vista and later.
483 } else if (version >= base::win::VERSION_XP) {
484 cp_applet.assign(L"Add/Remove Programs"); // Windows XP.
485 } else {
486 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; // Not supported
489 const base::string16 msg =
490 l10n_util::GetStringFUTF16(IDS_HIDE_ICONS_NOT_SUPPORTED, cp_applet);
491 const base::string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
492 const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST;
493 if (IDOK == ui::MessageBox(NULL, msg, caption, flags))
494 ShellExecute(NULL, NULL, L"appwiz.cpl", NULL, NULL, SW_SHOWNORMAL);
496 // Exit as we are not launching the browser.
497 return content::RESULT_CODE_NORMAL_EXIT;
499 // We don't hide icons so we shouldn't do anything special to show them
500 return chrome::RESULT_CODE_UNSUPPORTED_PARAM;
503 // static
504 bool ChromeBrowserMainPartsWin::CheckMachineLevelInstall() {
505 // TODO(tommi): Check if using the default distribution is always the right
506 // thing to do.
507 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
508 Version version;
509 InstallUtil::GetChromeVersion(dist, true, &version);
510 if (version.IsValid()) {
511 base::FilePath exe_path;
512 PathService::Get(base::DIR_EXE, &exe_path);
513 std::wstring exe = exe_path.value();
514 base::FilePath user_exe_path(installer::GetChromeInstallPath(false, dist));
515 if (base::FilePath::CompareEqualIgnoreCase(exe, user_exe_path.value())) {
516 bool is_metro = base::win::IsMetroProcess();
517 if (!is_metro) {
518 // The dialog cannot be shown in Win8 Metro as doing so hangs Chrome on
519 // an invisible dialog.
520 // TODO (gab): Get rid of this dialog altogether and auto-launch
521 // system-level Chrome instead.
522 const base::string16 text =
523 l10n_util::GetStringUTF16(IDS_MACHINE_LEVEL_INSTALL_CONFLICT);
524 const base::string16 caption =
525 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
526 const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST;
527 ui::MessageBox(NULL, text, caption, flags);
529 base::CommandLine uninstall_cmd(
530 InstallUtil::GetChromeUninstallCmd(false, dist->GetType()));
531 if (!uninstall_cmd.GetProgram().empty()) {
532 uninstall_cmd.AppendSwitch(installer::switches::kSelfDestruct);
533 uninstall_cmd.AppendSwitch(installer::switches::kForceUninstall);
534 uninstall_cmd.AppendSwitch(
535 installer::switches::kDoNotRemoveSharedItems);
537 // Trigger Active Setup for the system-level Chrome to make sure
538 // per-user shortcuts to the system-level Chrome are created. Skip this
539 // if the system-level Chrome will undergo first run anyway, as Active
540 // Setup is triggered on system-level Chrome's first run.
541 // TODO(gab): Instead of having callers of Active Setup think about
542 // other callers, have Active Setup itself register when it ran and
543 // no-op otherwise (http://crbug.com/346843).
544 if (!first_run::IsChromeFirstRun())
545 uninstall_cmd.AppendSwitch(installer::switches::kTriggerActiveSetup);
547 const base::FilePath setup_exe(uninstall_cmd.GetProgram());
548 const base::string16 params(uninstall_cmd.GetArgumentsString());
550 SHELLEXECUTEINFO sei = { sizeof(sei) };
551 sei.fMask = SEE_MASK_NOASYNC;
552 sei.nShow = SW_SHOWNORMAL;
553 sei.lpFile = setup_exe.value().c_str();
554 sei.lpParameters = params.c_str();
555 // On Windows 8 SEE_MASK_FLAG_LOG_USAGE is necessary to guarantee we
556 // flip to the Desktop when launching.
557 if (is_metro)
558 sei.fMask |= SEE_MASK_FLAG_LOG_USAGE;
560 if (!::ShellExecuteEx(&sei))
561 DPCHECK(false);
563 return true;
566 return false;
569 base::string16 TranslationDelegate::GetLocalizedString(
570 int installer_string_id) {
571 int resource_id = 0;
572 switch (installer_string_id) {
573 // HANDLE_STRING is used by the DO_INSTALLER_STRING_MAPPING macro which is in
574 // the generated header installer_util_strings.h.
575 #define HANDLE_STRING(base_id, chrome_id) \
576 case base_id: \
577 resource_id = chrome_id; \
578 break;
579 DO_INSTALLER_STRING_MAPPING
580 #undef HANDLE_STRING
581 default:
582 NOTREACHED();
584 if (resource_id)
585 return l10n_util::GetStringUTF16(resource_id);
586 return base::string16();
589 // static
590 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() {
591 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ());
592 installer::SetTranslationDelegate(&delegate);