[email protected] | 9e790bd | 2011-01-10 23:48:54 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 5 | #include "chrome/browser/browser_main.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 6 | #include "chrome/browser/browser_main_win.h" |
| 7 | |
[email protected] | 71b73f0 | 2011-04-06 15:57:29 | [diff] [blame] | 8 | #include <windows.h> |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame^] | 9 | #include <shellapi.h> |
[email protected] | 4a0765a | 2009-05-08 23:12:25 | [diff] [blame] | 10 | |
[email protected] | c83dd91 | 2010-04-06 18:50:51 | [diff] [blame] | 11 | #include <algorithm> |
| 12 | |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 13 | #include "base/command_line.h" |
[email protected] | ae0f077 | 2010-08-13 04:54:10 | [diff] [blame] | 14 | #include "base/environment.h" |
[email protected] | 7cf1b6ce | 2010-03-20 06:37:01 | [diff] [blame] | 15 | #include "base/i18n/rtl.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 16 | #include "base/memory/scoped_ptr.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 17 | #include "base/path_service.h" |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame^] | 18 | #include "base/scoped_native_library.h" |
[email protected] | fd59f82 | 2011-05-12 18:07:18 | [diff] [blame] | 19 | #include "base/time.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 20 | #include "base/utf_string_conversions.h" |
[email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 21 | #include "base/win/windows_version.h" |
[email protected] | ecb924c | 2011-03-17 00:34:09 | [diff] [blame] | 22 | #include "base/win/wrapped_window_proc.h" |
[email protected] | a3abd557 | 2011-04-15 02:09:33 | [diff] [blame] | 23 | #include "chrome/browser/browser_util_win.h" |
[email protected] | 82073579 | 2010-07-29 23:40:01 | [diff] [blame] | 24 | #include "chrome/browser/first_run/first_run.h" |
[email protected] | cd1adc2 | 2009-01-16 01:29:22 | [diff] [blame] | 25 | #include "chrome/browser/metrics/metrics_service.h" |
[email protected] | 71b73f0 | 2011-04-06 15:57:29 | [diff] [blame] | 26 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 9e790bd | 2011-01-10 23:48:54 | [diff] [blame] | 27 | #include "chrome/browser/ui/views/uninstall_view.h" |
[email protected] | ecb924c | 2011-03-17 00:34:09 | [diff] [blame] | 28 | #include "chrome/common/chrome_constants.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 29 | #include "chrome/common/chrome_switches.h" |
| 30 | #include "chrome/common/env_vars.h" |
[email protected] | bf6117c7e | 2010-12-01 06:00:25 | [diff] [blame] | 31 | #include "chrome/installer/util/browser_distribution.h" |
[email protected] | fd59f82 | 2011-05-12 18:07:18 | [diff] [blame] | 32 | #include "chrome/installer/util/google_update_settings.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 33 | #include "chrome/installer/util/helper.h" |
| 34 | #include "chrome/installer/util/install_util.h" |
| 35 | #include "chrome/installer/util/shell_util.h" |
[email protected] | 415c2cd | 2011-03-11 21:56:11 | [diff] [blame] | 36 | #include "content/common/main_function_params.h" |
[email protected] | 4dd5793 | 2011-03-17 06:06:12 | [diff] [blame] | 37 | #include "content/common/result_codes.h" |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame^] | 38 | #include "crypto/nss_util.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 39 | #include "grit/chromium_strings.h" |
| 40 | #include "grit/generated_resources.h" |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 41 | #include "net/base/winsock_init.h" |
[email protected] | 2380f37 | 2011-02-23 21:35:19 | [diff] [blame] | 42 | #include "net/socket/client_socket_factory.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 43 | #include "ui/base/l10n/l10n_util.h" |
| 44 | #include "ui/base/l10n/l10n_util_win.h" |
[email protected] | 75b6805 | 2011-02-03 06:01:16 | [diff] [blame] | 45 | #include "ui/base/message_box_win.h" |
[email protected] | 148d105 | 2009-07-31 22:53:37 | [diff] [blame] | 46 | #include "views/focus/accelerator_handler.h" |
[email protected] | 2362e4f | 2009-05-08 00:34:05 | [diff] [blame] | 47 | #include "views/window/window.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 48 | |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 49 | namespace { |
[email protected] | ecb924c | 2011-03-17 00:34:09 | [diff] [blame] | 50 | |
[email protected] | a08ba82 | 2011-02-20 07:45:47 | [diff] [blame] | 51 | typedef HRESULT (STDAPICALLTYPE* RegisterApplicationRestartProc)( |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 52 | const wchar_t* command_line, |
| 53 | DWORD flags); |
[email protected] | ecb924c | 2011-03-17 00:34:09 | [diff] [blame] | 54 | |
| 55 | void InitializeWindowProcExceptions() { |
| 56 | // Get the breakpad pointer from chrome.exe |
| 57 | base::win::WinProcExceptionFilter exception_filter = |
| 58 | reinterpret_cast<base::win::WinProcExceptionFilter>( |
| 59 | ::GetProcAddress(::GetModuleHandle( |
| 60 | chrome::kBrowserProcessExecutableName), |
| 61 | "CrashForException")); |
| 62 | exception_filter = base::win::SetWinProcExceptionFilter(exception_filter); |
| 63 | DCHECK(!exception_filter); |
| 64 | } |
| 65 | |
[email protected] | fd59f82 | 2011-05-12 18:07:18 | [diff] [blame] | 66 | // BrowserUsageUpdater -------------------------------------------------------- |
| 67 | // This class' job is to update the registry 'dr' value every 24 hours |
| 68 | // that way google update can accurately track browser usage without |
| 69 | // undercounting users that do not close chrome for long periods of time. |
| 70 | class BrowserUsageUpdater : public Task { |
| 71 | public: |
| 72 | virtual ~BrowserUsageUpdater() {} |
| 73 | |
| 74 | virtual void Run() OVERRIDE { |
| 75 | if (UpdateUsageRegKey()) |
| 76 | Track(); |
| 77 | } |
| 78 | |
| 79 | static void Track() { |
| 80 | BrowserThread::PostDelayedTask( |
| 81 | BrowserThread::FILE, |
| 82 | FROM_HERE, new BrowserUsageUpdater, |
| 83 | base::TimeDelta::FromHours(24).InMillisecondsRoundedUp()); |
| 84 | } |
| 85 | |
| 86 | private: |
| 87 | bool UpdateUsageRegKey() { |
| 88 | FilePath module_dir; |
| 89 | if (!PathService::Get(base::DIR_MODULE, &module_dir)) |
| 90 | return false; |
| 91 | bool system_level = |
| 92 | !InstallUtil::IsPerUserInstall(module_dir.value().c_str()); |
| 93 | return GoogleUpdateSettings::UpdateDidRunState(true, system_level); |
| 94 | } |
| 95 | }; |
| 96 | |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 97 | } // namespace |
| 98 | |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 99 | void DidEndMainMessageLoop() { |
[email protected] | b443cb04 | 2009-12-15 22:05:09 | [diff] [blame] | 100 | OleUninitialize(); |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void RecordBreakpadStatusUMA(MetricsService* metrics) { |
[email protected] | c83dd91 | 2010-04-06 18:50:51 | [diff] [blame] | 104 | DWORD len = ::GetEnvironmentVariableW( |
| 105 | ASCIIToWide(env_vars::kNoOOBreakpad).c_str() , NULL, 0); |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 106 | metrics->RecordBreakpadRegistration((len == 0)); |
| 107 | metrics->RecordBreakpadHasDebugger(TRUE == ::IsDebuggerPresent()); |
| 108 | } |
| 109 | |
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 110 | void WarnAboutMinimumSystemRequirements() { |
[email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 111 | if (base::win::GetVersion() < base::win::VERSION_XP) { |
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 112 | // Display a warning message if the user is running chrome on Windows 2000. |
[email protected] | 0f26d7b | 2011-01-05 19:10:44 | [diff] [blame] | 113 | const string16 text = |
| 114 | l10n_util::GetStringUTF16(IDS_UNSUPPORTED_OS_PRE_WIN_XP); |
| 115 | const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
[email protected] | 75b6805 | 2011-02-03 06:01:16 | [diff] [blame] | 116 | ui::MessageBox(NULL, text, caption, MB_OK | MB_ICONWARNING | MB_TOPMOST); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 117 | } |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 118 | } |
| 119 | |
[email protected] | 45d7276 | 2011-04-15 18:58:20 | [diff] [blame] | 120 | void RecordBrowserStartupTime() { |
| 121 | // Calculate the time that has elapsed from our own process creation. |
| 122 | FILETIME creation_time = {}; |
| 123 | FILETIME ignore = {}; |
| 124 | ::GetProcessTimes(::GetCurrentProcess(), &creation_time, &ignore, &ignore, |
| 125 | &ignore); |
| 126 | |
| 127 | base::TimeDelta elapsed_from_startup = |
| 128 | base::Time::Now() - base::Time::FromFileTime(creation_time); |
| 129 | |
| 130 | // Record the time to present in a histogram. |
| 131 | UMA_HISTOGRAM_MEDIUM_TIMES("Startup.BrowserMessageLoopStartTime", |
| 132 | elapsed_from_startup); |
| 133 | } |
| 134 | |
[email protected] | 4df8786f | 2009-04-17 13:24:57 | [diff] [blame] | 135 | int AskForUninstallConfirmation() { |
| 136 | int ret = ResultCodes::NORMAL_EXIT; |
[email protected] | a173cc9 | 2009-08-20 23:26:37 | [diff] [blame] | 137 | views::Window::CreateChromeWindow(NULL, gfx::Rect(), |
| 138 | new UninstallView(ret))->Show(); |
[email protected] | 047f622 | 2009-07-29 23:34:56 | [diff] [blame] | 139 | views::AcceleratorHandler accelerator_handler; |
| 140 | MessageLoopForUI::current()->Run(&accelerator_handler); |
[email protected] | 4df8786f | 2009-04-17 13:24:57 | [diff] [blame] | 141 | return ret; |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 142 | } |
| 143 | |
[email protected] | 53c38d23 | 2009-02-13 20:52:18 | [diff] [blame] | 144 | void ShowCloseBrowserFirstMessageBox() { |
[email protected] | 0f26d7b | 2011-01-05 19:10:44 | [diff] [blame] | 145 | const string16 text = l10n_util::GetStringUTF16(IDS_UNINSTALL_CLOSE_APP); |
| 146 | const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
[email protected] | 53c38d23 | 2009-02-13 20:52:18 | [diff] [blame] | 147 | const UINT flags = MB_OK | MB_ICONWARNING | MB_TOPMOST; |
[email protected] | 75b6805 | 2011-02-03 06:01:16 | [diff] [blame] | 148 | ui::MessageBox(NULL, text, caption, flags); |
[email protected] | 53c38d23 | 2009-02-13 20:52:18 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | int DoUninstallTasks(bool chrome_still_running) { |
[email protected] | a173cc9 | 2009-08-20 23:26:37 | [diff] [blame] | 152 | // We want to show a warning to user (and exit) if Chrome is already running |
| 153 | // *before* we show the uninstall confirmation dialog box. But while the |
| 154 | // uninstall confirmation dialog is up, user might start Chrome, so we |
| 155 | // check once again after user acknowledges Uninstall dialog. |
[email protected] | 53c38d23 | 2009-02-13 20:52:18 | [diff] [blame] | 156 | if (chrome_still_running) { |
| 157 | ShowCloseBrowserFirstMessageBox(); |
| 158 | return ResultCodes::UNINSTALL_CHROME_ALIVE; |
| 159 | } |
[email protected] | 4df8786f | 2009-04-17 13:24:57 | [diff] [blame] | 160 | int ret = AskForUninstallConfirmation(); |
[email protected] | a3abd557 | 2011-04-15 02:09:33 | [diff] [blame] | 161 | if (browser_util::IsBrowserAlreadyRunning()) { |
[email protected] | a173cc9 | 2009-08-20 23:26:37 | [diff] [blame] | 162 | ShowCloseBrowserFirstMessageBox(); |
| 163 | return ResultCodes::UNINSTALL_CHROME_ALIVE; |
| 164 | } |
| 165 | |
[email protected] | 4df8786f | 2009-04-17 13:24:57 | [diff] [blame] | 166 | if (ret != ResultCodes::UNINSTALL_USER_CANCEL) { |
| 167 | // The following actions are just best effort. |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 168 | VLOG(1) << "Executing uninstall actions"; |
[email protected] | 4df8786f | 2009-04-17 13:24:57 | [diff] [blame] | 169 | if (!FirstRun::RemoveSentinel()) |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 170 | VLOG(1) << "Failed to delete sentinel file."; |
[email protected] | 4df8786f | 2009-04-17 13:24:57 | [diff] [blame] | 171 | // We want to remove user level shortcuts and we only care about the ones |
| 172 | // created by us and not by the installer so |alternate| is false. |
[email protected] | bf6117c7e | 2010-12-01 06:00:25 | [diff] [blame] | 173 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 174 | if (!ShellUtil::RemoveChromeDesktopShortcut(dist, ShellUtil::CURRENT_USER, |
| 175 | false)) |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 176 | VLOG(1) << "Failed to delete desktop shortcut."; |
[email protected] | bf6117c7e | 2010-12-01 06:00:25 | [diff] [blame] | 177 | if (!ShellUtil::RemoveChromeQuickLaunchShortcut(dist, |
| 178 | ShellUtil::CURRENT_USER)) |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 179 | VLOG(1) << "Failed to delete quick launch shortcut."; |
[email protected] | 4df8786f | 2009-04-17 13:24:57 | [diff] [blame] | 180 | } |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 181 | return ret; |
| 182 | } |
| 183 | |
| 184 | // Prepares the localized strings that are going to be displayed to |
| 185 | // the user if the browser process dies. These strings are stored in the |
| 186 | // environment block so they are accessible in the early stages of the |
| 187 | // chrome executable's lifetime. |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 188 | void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) { |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 189 | // Clear this var so child processes don't show the dialog by default. |
[email protected] | ae0f077 | 2010-08-13 04:54:10 | [diff] [blame] | 190 | scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 191 | env->UnSetVar(env_vars::kShowRestart); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 192 | |
| 193 | // For non-interactive tests we don't restart on crash. |
[email protected] | ae0f077 | 2010-08-13 04:54:10 | [diff] [blame] | 194 | if (env->HasVar(env_vars::kHeadless)) |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 195 | return; |
| 196 | |
| 197 | // If the known command-line test options are used we don't create the |
| 198 | // environment block which means we don't get the restart dialog. |
| 199 | if (parsed_command_line.HasSwitch(switches::kBrowserCrashTest) || |
| 200 | parsed_command_line.HasSwitch(switches::kBrowserAssertTest) || |
| 201 | parsed_command_line.HasSwitch(switches::kNoErrorDialogs)) |
| 202 | return; |
| 203 | |
| 204 | // The encoding we use for the info is "title|context|direction" where |
| 205 | // direction is either env_vars::kRtlLocale or env_vars::kLtrLocale depending |
| 206 | // on the current locale. |
[email protected] | 6baca1a | 2010-08-14 00:17:05 | [diff] [blame] | 207 | string16 dlg_strings(l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_TITLE)); |
| 208 | dlg_strings.push_back('|'); |
[email protected] | 1c53ffde1 | 2010-08-17 22:40:31 | [diff] [blame] | 209 | string16 adjusted_string( |
| 210 | l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_CONTENT)); |
[email protected] | c32d31e | 2010-11-24 07:27:42 | [diff] [blame] | 211 | base::i18n::AdjustStringForLocaleDirection(&adjusted_string); |
[email protected] | 6baca1a | 2010-08-14 00:17:05 | [diff] [blame] | 212 | dlg_strings.append(adjusted_string); |
| 213 | dlg_strings.push_back('|'); |
| 214 | dlg_strings.append(ASCIIToUTF16( |
| 215 | base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale)); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 216 | |
[email protected] | 6baca1a | 2010-08-14 00:17:05 | [diff] [blame] | 217 | env->SetVar(env_vars::kRestartInfo, UTF16ToUTF8(dlg_strings)); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 218 | } |
| 219 | |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 220 | bool RegisterApplicationRestart(const CommandLine& parsed_command_line) { |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 221 | DCHECK(base::win::GetVersion() >= base::win::VERSION_VISTA); |
| 222 | base::ScopedNativeLibrary library(FilePath(L"kernel32.dll")); |
| 223 | // Get the function pointer for RegisterApplicationRestart. |
[email protected] | a08ba82 | 2011-02-20 07:45:47 | [diff] [blame] | 224 | RegisterApplicationRestartProc register_application_restart = |
| 225 | static_cast<RegisterApplicationRestartProc>( |
| 226 | library.GetFunctionPointer("RegisterApplicationRestart")); |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 227 | if (!register_application_restart) |
| 228 | return false; |
| 229 | |
| 230 | // The Windows Restart Manager expects a string of command line flags only, |
| 231 | // without the program. |
| 232 | CommandLine command_line(CommandLine::NO_PROGRAM); |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 233 | command_line.AppendArguments(parsed_command_line, false); |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 234 | // Ensure restore last session is set. |
| 235 | if (!command_line.HasSwitch(switches::kRestoreLastSession)) |
| 236 | command_line.AppendSwitch(switches::kRestoreLastSession); |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 237 | |
| 238 | // Restart Chrome if the computer is restarted as the result of an update. |
| 239 | // This could be extended to handle crashes, hangs, and patches. |
[email protected] | 9dc12406b | 2011-03-03 15:50:30 | [diff] [blame] | 240 | HRESULT hr = register_application_restart( |
| 241 | command_line.command_line_string().c_str(), |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 242 | RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH); |
| 243 | DCHECK(SUCCEEDED(hr)) << "RegisterApplicationRestart failed."; |
| 244 | return SUCCEEDED(hr); |
| 245 | } |
| 246 | |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 247 | // This method handles the --hide-icons and --show-icons command line options |
| 248 | // for chrome that get triggered by Windows from registry entries |
| 249 | // HideIconsCommand & ShowIconsCommand. Chrome doesn't support hide icons |
| 250 | // functionality so we just ask the users if they want to uninstall Chrome. |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 251 | int HandleIconsCommands(const CommandLine& parsed_command_line) { |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 252 | if (parsed_command_line.HasSwitch(switches::kHideIcons)) { |
[email protected] | 0f26d7b | 2011-01-05 19:10:44 | [diff] [blame] | 253 | string16 cp_applet; |
[email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 254 | base::win::Version version = base::win::GetVersion(); |
| 255 | if (version >= base::win::VERSION_VISTA) { |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 256 | cp_applet.assign(L"Programs and Features"); // Windows Vista and later. |
[email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 257 | } else if (version >= base::win::VERSION_XP) { |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 258 | cp_applet.assign(L"Add/Remove Programs"); // Windows XP. |
| 259 | } else { |
| 260 | return ResultCodes::UNSUPPORTED_PARAM; // Not supported |
| 261 | } |
| 262 | |
[email protected] | 0f26d7b | 2011-01-05 19:10:44 | [diff] [blame] | 263 | const string16 msg = |
| 264 | l10n_util::GetStringFUTF16(IDS_HIDE_ICONS_NOT_SUPPORTED, cp_applet); |
| 265 | const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 266 | const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST; |
[email protected] | 75b6805 | 2011-02-03 06:01:16 | [diff] [blame] | 267 | if (IDOK == ui::MessageBox(NULL, msg, caption, flags)) |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 268 | ShellExecute(NULL, NULL, L"appwiz.cpl", NULL, NULL, SW_SHOWNORMAL); |
| 269 | return ResultCodes::NORMAL_EXIT; // Exit as we are not launching browser. |
| 270 | } |
| 271 | // We don't hide icons so we shouldn't do anything special to show them |
| 272 | return ResultCodes::UNSUPPORTED_PARAM; |
| 273 | } |
| 274 | |
| 275 | // Check if there is any machine level Chrome installed on the current |
| 276 | // machine. If yes and the current Chrome process is user level, we do not |
| 277 | // allow the user level Chrome to run. So we notify the user and uninstall |
| 278 | // user level Chrome. |
| 279 | bool CheckMachineLevelInstall() { |
[email protected] | bf6117c7e | 2010-12-01 06:00:25 | [diff] [blame] | 280 | // TODO(tommi): Check if using the default distribution is always the right |
| 281 | // thing to do. |
| 282 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
[email protected] | 1db1b49 | 2010-12-16 19:03:37 | [diff] [blame] | 283 | scoped_ptr<Version> version(InstallUtil::GetChromeVersion(dist, true)); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 284 | if (version.get()) { |
[email protected] | b969648 | 2010-11-30 23:56:18 | [diff] [blame] | 285 | FilePath exe_path; |
| 286 | PathService::Get(base::DIR_EXE, &exe_path); |
| 287 | std::wstring exe = exe_path.value(); |
[email protected] | bf6117c7e | 2010-12-01 06:00:25 | [diff] [blame] | 288 | FilePath user_exe_path(installer::GetChromeInstallPath(false, dist)); |
| 289 | if (FilePath::CompareEqualIgnoreCase(exe, user_exe_path.value())) { |
[email protected] | 0f26d7b | 2011-01-05 19:10:44 | [diff] [blame] | 290 | const string16 text = |
| 291 | l10n_util::GetStringUTF16(IDS_MACHINE_LEVEL_INSTALL_CONFLICT); |
| 292 | const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 293 | const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST; |
[email protected] | 75b6805 | 2011-02-03 06:01:16 | [diff] [blame] | 294 | ui::MessageBox(NULL, text, caption, flags); |
[email protected] | e5fbd496 | 2011-02-11 16:30:43 | [diff] [blame] | 295 | CommandLine uninstall_cmd( |
| 296 | InstallUtil::GetChromeUninstallCmd(false, dist->GetType())); |
| 297 | if (!uninstall_cmd.GetProgram().empty()) { |
[email protected] | 74ca044 | 2010-12-15 14:44:50 | [diff] [blame] | 298 | uninstall_cmd.AppendSwitch(installer::switches::kForceUninstall); |
[email protected] | e6124ad5 | 2010-11-15 04:17:52 | [diff] [blame] | 299 | uninstall_cmd.AppendSwitch( |
[email protected] | 74ca044 | 2010-12-15 14:44:50 | [diff] [blame] | 300 | installer::switches::kDoNotRemoveSharedItems); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 301 | base::LaunchApp(uninstall_cmd, false, false, NULL); |
| 302 | } |
| 303 | return true; |
| 304 | } |
| 305 | } |
| 306 | return false; |
| 307 | } |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 308 | |
| 309 | // BrowserMainPartsWin --------------------------------------------------------- |
| 310 | |
| 311 | class BrowserMainPartsWin : public BrowserMainParts { |
| 312 | public: |
| 313 | explicit BrowserMainPartsWin(const MainFunctionParams& parameters) |
| 314 | : BrowserMainParts(parameters) {} |
| 315 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 316 | protected: |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 317 | virtual void PreEarlyInitialization() { |
| 318 | // Initialize Winsock. |
| 319 | net::EnsureWinsockInit(); |
| 320 | } |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 321 | |
| 322 | virtual void PreMainMessageLoopStart() { |
| 323 | OleInitialize(NULL); |
[email protected] | 337ca07 | 2010-11-16 15:28:45 | [diff] [blame] | 324 | |
| 325 | // If we're running tests (ui_task is non-null), then the ResourceBundle |
| 326 | // has already been initialized. |
| 327 | if (!parameters().ui_task) { |
| 328 | // Override the configured locale with the user's preferred UI language. |
| 329 | l10n_util::OverrideLocaleWithUILanguageList(); |
[email protected] | ecb924c | 2011-03-17 00:34:09 | [diff] [blame] | 330 | |
| 331 | // Make sure that we know how to handle exceptions from the message loop. |
| 332 | InitializeWindowProcExceptions(); |
[email protected] | 337ca07 | 2010-11-16 15:28:45 | [diff] [blame] | 333 | } |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 334 | } |
[email protected] | d7dbe28c | 2010-07-29 04:33:47 | [diff] [blame] | 335 | |
[email protected] | fd59f82 | 2011-05-12 18:07:18 | [diff] [blame] | 336 | virtual void PostMainMessageLoopStart() OVERRIDE { |
| 337 | MessageLoop::current()->PostDelayedTask( |
| 338 | FROM_HERE, |
| 339 | NewRunnableFunction(&BrowserUsageUpdater::Track), |
| 340 | base::TimeDelta::FromSeconds(30).InMillisecondsRoundedUp()); |
| 341 | } |
| 342 | |
[email protected] | d7dbe28c | 2010-07-29 04:33:47 | [diff] [blame] | 343 | private: |
| 344 | virtual void InitializeSSL() { |
| 345 | // Use NSS for SSL by default. |
[email protected] | 2380f37 | 2011-02-23 21:35:19 | [diff] [blame] | 346 | // The default client socket factory uses NSS for SSL by default on |
| 347 | // Windows. |
| 348 | if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { |
| 349 | net::ClientSocketFactory::UseSystemSSL(); |
| 350 | } else { |
[email protected] | d7dbe28c | 2010-07-29 04:33:47 | [diff] [blame] | 351 | // We want to be sure to init NSPR on the main thread. |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 352 | crypto::EnsureNSPRInit(); |
[email protected] | d7dbe28c | 2010-07-29 04:33:47 | [diff] [blame] | 353 | } |
| 354 | } |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | // static |
| 358 | BrowserMainParts* BrowserMainParts::CreateBrowserMainParts( |
| 359 | const MainFunctionParams& parameters) { |
| 360 | return new BrowserMainPartsWin(parameters); |
| 361 | } |