chrome_browser_main_win.cc revision 6d86b77056ed63eb6871182f42a9fd5f07550f90
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chrome_browser_main_win.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <windows.h> 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <shellapi.h> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <algorithm> 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/environment.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/i18n/rtl.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/metrics/histogram.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/path_service.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/scoped_native_library.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/strings/string_number_conversions.h" 21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/metro.h" 23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/win/win_util.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/windows_version.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/wrapped_window_proc.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browser_util_win.h" 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chrome_elf_init_win.h" 28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/first_run/first_run.h" 29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/install_verification/win/install_verification.h" 306d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "chrome/browser/prefs/incognito_mode_prefs.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_info_cache.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_shortcut_manager.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/shell_integration.h" 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/simple_message_box.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/uninstall_browser_prompt.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_constants.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_result_codes.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 3958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/common/chrome_version_info.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/env_vars.h" 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/installer/launcher_support/chrome_launcher_support.h" 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/browser_distribution.h" 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/helper.h" 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/install_util.h" 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/l10n_string_util.h" 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/shell_util.h" 474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/browser/browser_thread.h" 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/main_function_params.h" 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/app_locale_settings.h" 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/chromium_strings.h" 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/generated_resources.h" 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "installer_util_strings/installer_util_strings.h" 537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "ui/base/cursor/cursor_loader_win.h" 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util_win.h" 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/ui_base_switches.h" 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/win/message_box_win.h" 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/platform_font_win.h" 590f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "ui/gfx/switches.h" 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef HRESULT (STDAPICALLTYPE* RegisterApplicationRestartProc)( 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const wchar_t* command_line, 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DWORD flags); 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void InitializeWindowProcExceptions() { 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the breakpad pointer from chrome.exe 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::win::WinProcExceptionFilter exception_filter = 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) reinterpret_cast<base::win::WinProcExceptionFilter>( 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ::GetProcAddress(::GetModuleHandle( 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::kBrowserProcessExecutableName), 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "CrashForException")); 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) exception_filter = base::win::SetWinProcExceptionFilter(exception_filter); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(!exception_filter); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// gfx::Font callbacks 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AdjustUIFont(LOGFONT* logfont) { 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) l10n_util::AdjustUIFont(logfont); 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int GetMinimumFontSize() { 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int min_font_size; 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::StringToInt(l10n_util::GetStringUTF16(IDS_MINIMUM_UI_FONT_SIZE), 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &min_font_size); 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return min_font_size; 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TranslationDelegate : public installer::TranslationDelegate { 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 92a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual base::string16 GetLocalizedString(int installer_string_id) OVERRIDE; 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 950f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)bool IsSafeModeStart() { 96f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return ::GetEnvironmentVariableA(chrome::kSafeModeEnvVar, NULL, 0) != 0; 970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShowCloseBrowserFirstMessageBox() { 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int message_id = IDS_UNINSTALL_CLOSE_APP; 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (base::win::GetVersion() >= base::win::VERSION_WIN8 && 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT)) { 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE; 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::ShowMessageBox(NULL, 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) l10n_util::GetStringUTF16(message_id), 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::MESSAGE_BOX_TYPE_WARNING); 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int DoUninstallTasks(bool chrome_still_running) { 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We want to show a warning to user (and exit) if Chrome is already running 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // *before* we show the uninstall confirmation dialog box. But while the 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // uninstall confirmation dialog is up, user might start Chrome, so we 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // check once again after user acknowledges Uninstall dialog. 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (chrome_still_running) { 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShowCloseBrowserFirstMessageBox(); 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return chrome::RESULT_CODE_UNINSTALL_CHROME_ALIVE; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int result = chrome::ShowUninstallBrowserPrompt( 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) !chrome_launcher_support::IsAppLauncherPresent()); 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Don't offer to delete the profile if the App Launcher is also installed. 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (browser_util::IsBrowserAlreadyRunning()) { 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShowCloseBrowserFirstMessageBox(); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return chrome::RESULT_CODE_UNINSTALL_CHROME_ALIVE; 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (result != chrome::RESULT_CODE_UNINSTALL_USER_CANCEL) { 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The following actions are just best effort. 132a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TODO(gab): Look into removing this code which is now redundant with the 133a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // work done by setup.exe on uninstall. 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Executing uninstall actions"; 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath chrome_exe; 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (PathService::Get(base::FILE_EXE, &chrome_exe)) { 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::ShortcutLocation user_shortcut_locations[] = { 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_DESKTOP, 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, 140a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, 141a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < arraysize(user_shortcut_locations); ++i) { 145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!ShellUtil::RemoveShortcuts(user_shortcut_locations[i], dist, 146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ShellUtil::CURRENT_USER, chrome_exe)) { 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VLOG(1) << "Failed to delete shortcut at location " 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << user_shortcut_locations[i]; 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED(); 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return result; 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void MaybeEnableHighResolutionTimeEverywhere() { 15958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 16058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) bool user_enabled = CommandLine::ForCurrentProcess()->HasSwitch( 16158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) switches::kEnableHighResolutionTime); 16258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (user_enabled || channel == chrome::VersionInfo::CHANNEL_CANARY) { 16358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) bool is_enabled = base::TimeTicks::SetNowIsHighResNowIfSupported(); 16458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (is_enabled && !user_enabled) { 16558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Ensure that all of the renderers will enable it too. 16658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) CommandLine::ForCurrentProcess()->AppendSwitch( 16758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) switches::kEnableHighResolutionTime); 16858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 16958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 17058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 17158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ChromeBrowserMainPartsWin --------------------------------------------------- 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ChromeBrowserMainPartsWin::ChromeBrowserMainPartsWin( 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::MainFunctionParams& parameters) 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : ChromeBrowserMainParts(parameters) { 17758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) MaybeEnableHighResolutionTimeEverywhere(); 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (base::win::IsMetroProcess()) { 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef const wchar_t* (*GetMetroSwitches)(void); 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetMetroSwitches metro_switches_proc = reinterpret_cast<GetMetroSwitches>( 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetProcAddress(base::win::GetMetroModule(), 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "GetMetroCommandLineSwitches")); 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (metro_switches_proc) { 184a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 metro_switches = (*metro_switches_proc)(); 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!metro_switches.empty()) { 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CommandLine extra_switches(CommandLine::NO_PROGRAM); 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extra_switches.ParseFromString(metro_switches); 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CommandLine::ForCurrentProcess()->AppendArguments(extra_switches, 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false); 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ChromeBrowserMainPartsWin::~ChromeBrowserMainPartsWin() { 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ChromeBrowserMainPartsWin::ToolkitInitialized() { 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeBrowserMainParts::ToolkitInitialized(); 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; 2027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#if defined(USE_AURA) 2037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch ui::CursorLoaderWin::SetCursorResourceModule(chrome::kBrowserResourcesDll); 2047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#endif 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ChromeBrowserMainPartsWin::PreMainMessageLoopStart() { 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // installer_util references strings that are normally compiled into 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // setup.exe. In Chrome, these strings are in the locale files. 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetupInstallerUtilStrings(); 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ChromeBrowserMainParts::PreMainMessageLoopStart(); 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!parameters().ui_task) { 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make sure that we know how to handle exceptions from the message loop. 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InitializeWindowProcExceptions(); 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2176d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 2186d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) IncognitoModePrefs::InitializePlatformParentalControls(); 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochint ChromeBrowserMainPartsWin::PreCreateThreads() { 2227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch int rv = ChromeBrowserMainParts::PreCreateThreads(); 2237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 2240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (IsSafeModeStart()) { 225f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // TODO(cpu): disable other troublesome features for safe mode. 226f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) CommandLine::ForCurrentProcess()->AppendSwitch( 227f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) switches::kDisableGpu); 2280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) } 2297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // TODO(viettrungluu): why don't we run this earlier? 2307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs) && 2317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch base::win::GetVersion() < base::win::VERSION_XP) { 2327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chrome::ShowMessageBox(NULL, 2337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), 2347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch l10n_util::GetStringUTF16(IDS_UNSUPPORTED_OS_PRE_WIN_XP), 2357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chrome::MESSAGE_BOX_TYPE_WARNING); 2367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 2377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 2387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return rv; 2397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 2407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ChromeBrowserMainPartsWin::ShowMissingLocaleMessageBox() { 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::MessageBox(NULL, 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataMessage), 2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataTitle), 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MB_OK | MB_ICONERROR | MB_TOPMOST); 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void ChromeBrowserMainPartsWin::PostBrowserStart() { 2494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ChromeBrowserMainParts::PostBrowserStart(); 2504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 251cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice()); 252cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 2534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Set up a task to verify installed modules in the current process. Use a 2544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // delay to reduce the impact on startup time. 2554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::BrowserThread::GetMessageLoopProxyForThread( 2564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::BrowserThread::UI)->PostDelayedTask( 2574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) FROM_HERE, 258f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) base::Bind(&VerifyInstallation), 2594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) base::TimeDelta::FromSeconds(45)); 2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) InitializeChromeElf(); 2624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment( 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const CommandLine& parsed_command_line) { 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Clear this var so child processes don't show the dialog by default. 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<base::Environment> env(base::Environment::Create()); 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) env->UnSetVar(env_vars::kShowRestart); 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For non-interactive tests we don't restart on crash. 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (env->HasVar(env_vars::kHeadless)) 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the known command-line test options are used we don't create the 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // environment block which means we don't get the restart dialog. 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (parsed_command_line.HasSwitch(switches::kBrowserCrashTest) || 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parsed_command_line.HasSwitch(switches::kBrowserAssertTest) || 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parsed_command_line.HasSwitch(switches::kNoErrorDialogs)) 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The encoding we use for the info is "title|context|direction" where 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // direction is either env_vars::kRtlLocale or env_vars::kLtrLocale depending 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on the current locale. 285a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 dlg_strings(l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_TITLE)); 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) dlg_strings.push_back('|'); 287a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 adjusted_string( 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_CONTENT)); 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::i18n::AdjustStringForLocaleDirection(&adjusted_string); 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) dlg_strings.append(adjusted_string); 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) dlg_strings.push_back('|'); 2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dlg_strings.append(base::ASCIIToUTF16( 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale)); 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) env->SetVar(env_vars::kRestartInfo, base::UTF16ToUTF8(dlg_strings)); 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ChromeBrowserMainPartsWin::RegisterApplicationRestart( 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const CommandLine& parsed_command_line) { 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(base::win::GetVersion() >= base::win::VERSION_VISTA); 3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::ScopedNativeLibrary library(base::FilePath(L"kernel32.dll")); 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the function pointer for RegisterApplicationRestart. 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RegisterApplicationRestartProc register_application_restart = 305868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) reinterpret_cast<RegisterApplicationRestartProc>( 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) library.GetFunctionPointer("RegisterApplicationRestart")); 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!register_application_restart) { 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(WARNING) << "Cannot find RegisterApplicationRestart in kernel32.dll"; 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The Windows Restart Manager expects a string of command line flags only, 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // without the program. 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CommandLine command_line(CommandLine::NO_PROGRAM); 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) command_line.AppendArguments(parsed_command_line, false); 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!command_line.HasSwitch(switches::kRestoreLastSession)) 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) command_line.AppendSwitch(switches::kRestoreLastSession); 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Restart Chrome if the computer is restarted as the result of an update. 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This could be extended to handle crashes, hangs, and patches. 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HRESULT hr = register_application_restart( 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) command_line.GetCommandLineString().c_str(), 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH); 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (FAILED(hr)) { 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (hr == E_INVALIDARG) { 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOG(WARNING) << "Command line too long for RegisterApplicationRestart"; 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED() << "RegisterApplicationRestart failed. hr: " << hr << 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ", command_line: " << command_line.GetCommandLineString(); 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int ChromeBrowserMainPartsWin::HandleIconsCommands( 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const CommandLine& parsed_command_line) { 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (parsed_command_line.HasSwitch(switches::kHideIcons)) { 337a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 cp_applet; 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::win::Version version = base::win::GetVersion(); 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (version >= base::win::VERSION_VISTA) { 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cp_applet.assign(L"Programs and Features"); // Windows Vista and later. 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else if (version >= base::win::VERSION_XP) { 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cp_applet.assign(L"Add/Remove Programs"); // Windows XP. 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return chrome::RESULT_CODE_UNSUPPORTED_PARAM; // Not supported 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 347a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 msg = 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) l10n_util::GetStringFUTF16(IDS_HIDE_ICONS_NOT_SUPPORTED, cp_applet); 349a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST; 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IDOK == ui::MessageBox(NULL, msg, caption, flags)) 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellExecute(NULL, NULL, L"appwiz.cpl", NULL, NULL, SW_SHOWNORMAL); 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Exit as we are not launching the browser. 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return content::RESULT_CODE_NORMAL_EXIT; 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We don't hide icons so we shouldn't do anything special to show them 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return chrome::RESULT_CODE_UNSUPPORTED_PARAM; 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool ChromeBrowserMainPartsWin::CheckMachineLevelInstall() { 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(tommi): Check if using the default distribution is always the right 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // thing to do. 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Version version; 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallUtil::GetChromeVersion(dist, true, &version); 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (version.IsValid()) { 3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath exe_path; 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PathService::Get(base::DIR_EXE, &exe_path); 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::wstring exe = exe_path.value(); 3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath user_exe_path(installer::GetChromeInstallPath(false, dist)); 3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (base::FilePath::CompareEqualIgnoreCase(exe, user_exe_path.value())) { 3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool is_metro = base::win::IsMetroProcess(); 3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!is_metro) { 3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The dialog cannot be shown in Win8 Metro as doing so hangs Chrome on 3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // an invisible dialog. 3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO (gab): Get rid of this dialog altogether and auto-launch 3792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // system-level Chrome instead. 380a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 text = 3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_MACHINE_LEVEL_INSTALL_CONFLICT); 382a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 3832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST; 3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::MessageBox(NULL, text, caption, flags); 3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CommandLine uninstall_cmd( 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstallUtil::GetChromeUninstallCmd(false, dist->GetType())); 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!uninstall_cmd.GetProgram().empty()) { 3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) uninstall_cmd.AppendSwitch(installer::switches::kSelfDestruct); 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uninstall_cmd.AppendSwitch(installer::switches::kForceUninstall); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uninstall_cmd.AppendSwitch( 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::switches::kDoNotRemoveSharedItems); 3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 394a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Trigger Active Setup for the system-level Chrome to make sure 395a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // per-user shortcuts to the system-level Chrome are created. Skip this 396a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // if the system-level Chrome will undergo first run anyway, as Active 397a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Setup is triggered on system-level Chrome's first run. 398a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // TODO(gab): Instead of having callers of Active Setup think about 399a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // other callers, have Active Setup itself register when it ran and 400a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // no-op otherwise (http://crbug.com/346843). 401a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!first_run::IsChromeFirstRun()) 402a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) uninstall_cmd.AppendSwitch(installer::switches::kTriggerActiveSetup); 403a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath setup_exe(uninstall_cmd.GetProgram()); 405a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 params(uninstall_cmd.GetArgumentsString()); 4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SHELLEXECUTEINFO sei = { sizeof(sei) }; 4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) sei.fMask = SEE_MASK_NOASYNC; 4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) sei.nShow = SW_SHOWNORMAL; 4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) sei.lpFile = setup_exe.value().c_str(); 4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) sei.lpParameters = params.c_str(); 4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // On Windows 8 SEE_MASK_FLAG_LOG_USAGE is necessary to guarantee we 4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // flip to the Desktop when launching. 4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (is_metro) 4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) sei.fMask |= SEE_MASK_FLAG_LOG_USAGE; 4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!::ShellExecuteEx(&sei)) 4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DPCHECK(false); 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::string16 TranslationDelegate::GetLocalizedString( 4275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int installer_string_id) { 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int resource_id = 0; 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (installer_string_id) { 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // HANDLE_STRING is used by the DO_INSTALLER_STRING_MAPPING macro which is in 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the generated header installer_util_strings.h. 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define HANDLE_STRING(base_id, chrome_id) \ 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case base_id: \ 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) resource_id = chrome_id; \ 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DO_INSTALLER_STRING_MAPPING 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#undef HANDLE_STRING 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED(); 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (resource_id) 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return l10n_util::GetStringUTF16(resource_id); 443a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return base::string16(); 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() { 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ()); 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::SetTranslationDelegate(&delegate); 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 451