OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chrome_browser_main_win.h" | 5 #include "chrome/browser/chrome_browser_main_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 void WarnAboutMinimumSystemRequirements() { | 67 void WarnAboutMinimumSystemRequirements() { |
68 if (base::win::GetVersion() < base::win::VERSION_XP) { | 68 if (base::win::GetVersion() < base::win::VERSION_XP) { |
69 // Display a warning message if the user is running chrome on Windows 2000. | 69 // Display a warning message if the user is running chrome on Windows 2000. |
70 const string16 text = | 70 const string16 text = |
71 l10n_util::GetStringUTF16(IDS_UNSUPPORTED_OS_PRE_WIN_XP); | 71 l10n_util::GetStringUTF16(IDS_UNSUPPORTED_OS_PRE_WIN_XP); |
72 const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 72 const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
73 ui::MessageBox(NULL, text, caption, MB_OK | MB_ICONWARNING | MB_TOPMOST); | 73 ui::MessageBox(NULL, text, caption, MB_OK | MB_ICONWARNING | MB_TOPMOST); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 #if !defined(USE_AURA) | |
78 void ShowMissingLocaleMessageBox() { | |
79 ui::MessageBox(NULL, ASCIIToUTF16(chrome_browser::kMissingLocaleDataMessage), | |
80 ASCIIToUTF16(chrome_browser::kMissingLocaleDataTitle), | |
81 MB_OK | MB_ICONERROR | MB_TOPMOST); | |
82 } | |
83 #endif | |
84 | |
85 void RecordBrowserStartupTime() { | 77 void RecordBrowserStartupTime() { |
86 // Calculate the time that has elapsed from our own process creation. | 78 // Calculate the time that has elapsed from our own process creation. |
87 FILETIME creation_time = {}; | 79 FILETIME creation_time = {}; |
88 FILETIME ignore = {}; | 80 FILETIME ignore = {}; |
89 ::GetProcessTimes(::GetCurrentProcess(), &creation_time, &ignore, &ignore, | 81 ::GetProcessTimes(::GetCurrentProcess(), &creation_time, &ignore, &ignore, |
90 &ignore); | 82 &ignore); |
91 | 83 |
92 RecordPreReadExperimentTime("Startup.BrowserMessageLoopStartTime", | 84 RecordPreReadExperimentTime("Startup.BrowserMessageLoopStartTime", |
93 base::Time::Now() - base::Time::FromFileTime(creation_time)); | 85 base::Time::Now() - base::Time::FromFileTime(creation_time)); |
94 } | 86 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 if (!ShellUtil::RemoveChromeDesktopShortcut(dist, ShellUtil::CURRENT_USER, | 126 if (!ShellUtil::RemoveChromeDesktopShortcut(dist, ShellUtil::CURRENT_USER, |
135 false)) | 127 false)) |
136 VLOG(1) << "Failed to delete desktop shortcut."; | 128 VLOG(1) << "Failed to delete desktop shortcut."; |
137 if (!ShellUtil::RemoveChromeQuickLaunchShortcut(dist, | 129 if (!ShellUtil::RemoveChromeQuickLaunchShortcut(dist, |
138 ShellUtil::CURRENT_USER)) | 130 ShellUtil::CURRENT_USER)) |
139 VLOG(1) << "Failed to delete quick launch shortcut."; | 131 VLOG(1) << "Failed to delete quick launch shortcut."; |
140 } | 132 } |
141 return ret; | 133 return ret; |
142 } | 134 } |
143 | 135 |
144 // Prepares the localized strings that are going to be displayed to | 136 // ChromeBrowserMainPartsWin --------------------------------------------------- |
145 // the user if the browser process dies. These strings are stored in the | 137 |
146 // environment block so they are accessible in the early stages of the | 138 ChromeBrowserMainPartsWin::ChromeBrowserMainPartsWin( |
147 // chrome executable's lifetime. | 139 const MainFunctionParams& parameters) |
148 void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) { | 140 : ChromeBrowserMainParts(parameters) { |
| 141 } |
| 142 |
| 143 void ChromeBrowserMainPartsWin::PreMainMessageLoopStart() { |
| 144 if (!parameters().ui_task) { |
| 145 // Make sure that we know how to handle exceptions from the message loop. |
| 146 InitializeWindowProcExceptions(); |
| 147 } |
| 148 } |
| 149 |
| 150 // static |
| 151 void ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment( |
| 152 const CommandLine& parsed_command_line) { |
149 // Clear this var so child processes don't show the dialog by default. | 153 // Clear this var so child processes don't show the dialog by default. |
150 scoped_ptr<base::Environment> env(base::Environment::Create()); | 154 scoped_ptr<base::Environment> env(base::Environment::Create()); |
151 env->UnSetVar(env_vars::kShowRestart); | 155 env->UnSetVar(env_vars::kShowRestart); |
152 | 156 |
153 // For non-interactive tests we don't restart on crash. | 157 // For non-interactive tests we don't restart on crash. |
154 if (env->HasVar(env_vars::kHeadless)) | 158 if (env->HasVar(env_vars::kHeadless)) |
155 return; | 159 return; |
156 | 160 |
157 // If the known command-line test options are used we don't create the | 161 // If the known command-line test options are used we don't create the |
158 // environment block which means we don't get the restart dialog. | 162 // environment block which means we don't get the restart dialog. |
(...skipping 11 matching lines...) Expand all Loading... |
170 l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_CONTENT)); | 174 l10n_util::GetStringUTF16(IDS_CRASH_RECOVERY_CONTENT)); |
171 base::i18n::AdjustStringForLocaleDirection(&adjusted_string); | 175 base::i18n::AdjustStringForLocaleDirection(&adjusted_string); |
172 dlg_strings.append(adjusted_string); | 176 dlg_strings.append(adjusted_string); |
173 dlg_strings.push_back('|'); | 177 dlg_strings.push_back('|'); |
174 dlg_strings.append(ASCIIToUTF16( | 178 dlg_strings.append(ASCIIToUTF16( |
175 base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale)); | 179 base::i18n::IsRTL() ? env_vars::kRtlLocale : env_vars::kLtrLocale)); |
176 | 180 |
177 env->SetVar(env_vars::kRestartInfo, UTF16ToUTF8(dlg_strings)); | 181 env->SetVar(env_vars::kRestartInfo, UTF16ToUTF8(dlg_strings)); |
178 } | 182 } |
179 | 183 |
180 void RegisterApplicationRestart(const CommandLine& parsed_command_line) { | 184 // static |
| 185 void ChromeBrowserMainPartsWin::RegisterApplicationRestart( |
| 186 const CommandLine& parsed_command_line) { |
181 DCHECK(base::win::GetVersion() >= base::win::VERSION_VISTA); | 187 DCHECK(base::win::GetVersion() >= base::win::VERSION_VISTA); |
182 base::ScopedNativeLibrary library(FilePath(L"kernel32.dll")); | 188 base::ScopedNativeLibrary library(FilePath(L"kernel32.dll")); |
183 // Get the function pointer for RegisterApplicationRestart. | 189 // Get the function pointer for RegisterApplicationRestart. |
184 RegisterApplicationRestartProc register_application_restart = | 190 RegisterApplicationRestartProc register_application_restart = |
185 static_cast<RegisterApplicationRestartProc>( | 191 static_cast<RegisterApplicationRestartProc>( |
186 library.GetFunctionPointer("RegisterApplicationRestart")); | 192 library.GetFunctionPointer("RegisterApplicationRestart")); |
187 if (!register_application_restart) { | 193 if (!register_application_restart) { |
188 LOG(WARNING) << "Cannot find RegisterApplicationRestart in kernel32.dll"; | 194 LOG(WARNING) << "Cannot find RegisterApplicationRestart in kernel32.dll"; |
189 return; | 195 return; |
190 } | 196 } |
191 // The Windows Restart Manager expects a string of command line flags only, | 197 // The Windows Restart Manager expects a string of command line flags only, |
192 // without the program. | 198 // without the program. |
193 CommandLine command_line(CommandLine::NO_PROGRAM); | 199 CommandLine command_line(CommandLine::NO_PROGRAM); |
194 command_line.AppendArguments(parsed_command_line, false); | 200 command_line.AppendArguments(parsed_command_line, false); |
195 if (!command_line.HasSwitch(switches::kRestoreLastSession)) | 201 if (!command_line.HasSwitch(switches::kRestoreLastSession)) |
196 command_line.AppendSwitch(switches::kRestoreLastSession); | 202 command_line.AppendSwitch(switches::kRestoreLastSession); |
197 if (command_line.GetCommandLineString().length() > RESTART_MAX_CMD_LINE) { | 203 if (command_line.GetCommandLineString().length() > RESTART_MAX_CMD_LINE) { |
198 LOG(WARNING) << "Command line too long for RegisterApplicationRestart"; | 204 LOG(WARNING) << "Command line too long for RegisterApplicationRestart"; |
199 return; | 205 return; |
200 } | 206 } |
201 | 207 |
202 // Restart Chrome if the computer is restarted as the result of an update. | 208 // Restart Chrome if the computer is restarted as the result of an update. |
203 // This could be extended to handle crashes, hangs, and patches. | 209 // This could be extended to handle crashes, hangs, and patches. |
204 HRESULT hr = register_application_restart( | 210 HRESULT hr = register_application_restart( |
205 command_line.GetCommandLineString().c_str(), | 211 command_line.GetCommandLineString().c_str(), |
206 RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH); | 212 RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH); |
207 DCHECK(SUCCEEDED(hr)) << "RegisterApplicationRestart failed."; | 213 DCHECK(SUCCEEDED(hr)) << "RegisterApplicationRestart failed."; |
208 } | 214 } |
209 | 215 |
210 // This method handles the --hide-icons and --show-icons command line options | 216 void ChromeBrowserMainPartsWin::ShowMissingLocaleMessageBox() { |
211 // for chrome that get triggered by Windows from registry entries | 217 ui::MessageBox(NULL, ASCIIToUTF16(chrome_browser::kMissingLocaleDataMessage), |
212 // HideIconsCommand & ShowIconsCommand. Chrome doesn't support hide icons | 218 ASCIIToUTF16(chrome_browser::kMissingLocaleDataTitle), |
213 // functionality so we just ask the users if they want to uninstall Chrome. | 219 MB_OK | MB_ICONERROR | MB_TOPMOST); |
214 int HandleIconsCommands(const CommandLine& parsed_command_line) { | 220 } |
| 221 |
| 222 // static |
| 223 int ChromeBrowserMainPartsWin::HandleIconsCommands( |
| 224 const CommandLine& parsed_command_line) { |
215 if (parsed_command_line.HasSwitch(switches::kHideIcons)) { | 225 if (parsed_command_line.HasSwitch(switches::kHideIcons)) { |
216 string16 cp_applet; | 226 string16 cp_applet; |
217 base::win::Version version = base::win::GetVersion(); | 227 base::win::Version version = base::win::GetVersion(); |
218 if (version >= base::win::VERSION_VISTA) { | 228 if (version >= base::win::VERSION_VISTA) { |
219 cp_applet.assign(L"Programs and Features"); // Windows Vista and later. | 229 cp_applet.assign(L"Programs and Features"); // Windows Vista and later. |
220 } else if (version >= base::win::VERSION_XP) { | 230 } else if (version >= base::win::VERSION_XP) { |
221 cp_applet.assign(L"Add/Remove Programs"); // Windows XP. | 231 cp_applet.assign(L"Add/Remove Programs"); // Windows XP. |
222 } else { | 232 } else { |
223 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; // Not supported | 233 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; // Not supported |
224 } | 234 } |
225 | 235 |
226 const string16 msg = | 236 const string16 msg = |
227 l10n_util::GetStringFUTF16(IDS_HIDE_ICONS_NOT_SUPPORTED, cp_applet); | 237 l10n_util::GetStringFUTF16(IDS_HIDE_ICONS_NOT_SUPPORTED, cp_applet); |
228 const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 238 const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
229 const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST; | 239 const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST; |
230 if (IDOK == ui::MessageBox(NULL, msg, caption, flags)) | 240 if (IDOK == ui::MessageBox(NULL, msg, caption, flags)) |
231 ShellExecute(NULL, NULL, L"appwiz.cpl", NULL, NULL, SW_SHOWNORMAL); | 241 ShellExecute(NULL, NULL, L"appwiz.cpl", NULL, NULL, SW_SHOWNORMAL); |
232 | 242 |
233 // Exit as we are not launching the browser. | 243 // Exit as we are not launching the browser. |
234 return content::RESULT_CODE_NORMAL_EXIT; | 244 return content::RESULT_CODE_NORMAL_EXIT; |
235 } | 245 } |
236 // We don't hide icons so we shouldn't do anything special to show them | 246 // We don't hide icons so we shouldn't do anything special to show them |
237 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; | 247 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; |
238 } | 248 } |
239 | 249 |
240 // Check if there is any machine level Chrome installed on the current | 250 // static |
241 // machine. If yes and the current Chrome process is user level, we do not | 251 bool ChromeBrowserMainPartsWin::CheckMachineLevelInstall() { |
242 // allow the user level Chrome to run. So we notify the user and uninstall | |
243 // user level Chrome. | |
244 bool CheckMachineLevelInstall() { | |
245 // TODO(tommi): Check if using the default distribution is always the right | 252 // TODO(tommi): Check if using the default distribution is always the right |
246 // thing to do. | 253 // thing to do. |
247 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 254 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
248 scoped_ptr<Version> version(InstallUtil::GetChromeVersion(dist, true)); | 255 scoped_ptr<Version> version(InstallUtil::GetChromeVersion(dist, true)); |
249 if (version.get()) { | 256 if (version.get()) { |
250 FilePath exe_path; | 257 FilePath exe_path; |
251 PathService::Get(base::DIR_EXE, &exe_path); | 258 PathService::Get(base::DIR_EXE, &exe_path); |
252 std::wstring exe = exe_path.value(); | 259 std::wstring exe = exe_path.value(); |
253 FilePath user_exe_path(installer::GetChromeInstallPath(false, dist)); | 260 FilePath user_exe_path(installer::GetChromeInstallPath(false, dist)); |
254 if (FilePath::CompareEqualIgnoreCase(exe, user_exe_path.value())) { | 261 if (FilePath::CompareEqualIgnoreCase(exe, user_exe_path.value())) { |
255 const string16 text = | 262 const string16 text = |
256 l10n_util::GetStringUTF16(IDS_MACHINE_LEVEL_INSTALL_CONFLICT); | 263 l10n_util::GetStringUTF16(IDS_MACHINE_LEVEL_INSTALL_CONFLICT); |
257 const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 264 const string16 caption = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
258 const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST; | 265 const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST; |
259 ui::MessageBox(NULL, text, caption, flags); | 266 ui::MessageBox(NULL, text, caption, flags); |
260 CommandLine uninstall_cmd( | 267 CommandLine uninstall_cmd( |
261 InstallUtil::GetChromeUninstallCmd(false, dist->GetType())); | 268 InstallUtil::GetChromeUninstallCmd(false, dist->GetType())); |
262 if (!uninstall_cmd.GetProgram().empty()) { | 269 if (!uninstall_cmd.GetProgram().empty()) { |
263 uninstall_cmd.AppendSwitch(installer::switches::kForceUninstall); | 270 uninstall_cmd.AppendSwitch(installer::switches::kForceUninstall); |
264 uninstall_cmd.AppendSwitch( | 271 uninstall_cmd.AppendSwitch( |
265 installer::switches::kDoNotRemoveSharedItems); | 272 installer::switches::kDoNotRemoveSharedItems); |
266 base::LaunchProcess(uninstall_cmd, base::LaunchOptions(), NULL); | 273 base::LaunchProcess(uninstall_cmd, base::LaunchOptions(), NULL); |
267 } | 274 } |
268 return true; | 275 return true; |
269 } | 276 } |
270 } | 277 } |
271 return false; | 278 return false; |
272 } | 279 } |
273 | |
274 // ChromeBrowserMainPartsWin --------------------------------------------------- | |
275 | |
276 ChromeBrowserMainPartsWin::ChromeBrowserMainPartsWin( | |
277 const MainFunctionParams& parameters) | |
278 : ChromeBrowserMainParts(parameters) { | |
279 } | |
280 | |
281 void ChromeBrowserMainPartsWin::PreMainMessageLoopStart() { | |
282 if (!parameters().ui_task) { | |
283 // Make sure that we know how to handle exceptions from the message loop. | |
284 InitializeWindowProcExceptions(); | |
285 } | |
286 } | |
OLD | NEW |