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