summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 21:20:16 +0000
committerpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 21:20:16 +0000
commit5c9587c69c6fc62164b35b24c92603935fb5dd2a (patch)
tree368ac11051119ff0e978c8ce9ee9fb7c8a8930e7 /chrome/browser
parentf52e5878b3bbf830b611d1d4d1e3d369b36f38d6 (diff)
downloadchromium_src-5c9587c69c6fc62164b35b24c92603935fb5dd2a.zip
chromium_src-5c9587c69c6fc62164b35b24c92603935fb5dd2a.tar.gz
chromium_src-5c9587c69c6fc62164b35b24c92603935fb5dd2a.tar.bz2
step one of some refactoring to allow other platforms to re-use the app initialization code.
Review URL: http://codereview.chromium.org/13295 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6627 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser.vcproj4
-rw-r--r--chrome/browser/browser_main.cc188
-rw-r--r--chrome/browser/browser_main_mac.mm11
-rw-r--r--chrome/browser/browser_main_win.cc178
-rw-r--r--chrome/browser/browser_main_win.h46
5 files changed, 275 insertions, 152 deletions
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index e853e3a..479d587 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -230,6 +230,10 @@
>
</File>
<File
+ RelativePath=".\browser_main_win.cc"
+ >
+ </File>
+ <File
RelativePath=".\browser_prefs.cc"
>
</File>
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 9e9b258..7e350d7 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -2,12 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "build/build_config.h"
+
+#include "base/command_line.h"
+#include "sandbox/src/sandbox.h"
+
+// TODO(port): several win-only methods have been pulled out of this, but
+// BrowserMain() as a whole needs to be broken apart so that it's usable by
+// other platforms. For now, it's just a stub. This is a serious work in
+// progress and should not be taken as an indication of a real refactoring.
+
+#if defined(OS_WIN)
+
#include <windows.h>
#include <shellapi.h>
#include <algorithm>
-#include "base/command_line.h"
#include "base/file_util.h"
#include "base/histogram.h"
#include "base/lazy_instance.h"
@@ -23,6 +34,7 @@
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_init.h"
#include "chrome/browser/browser_list.h"
+#include "chrome/browser/browser_main_win.h"
#include "chrome/browser/browser_prefs.h"
#include "chrome/browser/browser_process_impl.h"
#include "chrome/browser/browser_shutdown.h"
@@ -124,157 +136,6 @@ StringPiece NetResourceProvider(int key) {
return ResourceBundle::GetSharedInstance().GetRawDataResource(key);
}
-// Displays a warning message if the user is running chrome on windows 2000.
-// Returns true if the OS is win2000, false otherwise.
-bool CheckForWin2000() {
- if (win_util::GetWinVersion() == win_util::WINVERSION_2000) {
- const std::wstring text = l10n_util::GetString(IDS_UNSUPPORTED_OS_WIN2000);
- const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME);
- win_util::MessageBox(NULL, text, caption,
- MB_OK | MB_ICONWARNING | MB_TOPMOST);
- return true;
- }
- return false;
-}
-
-bool AskForUninstallConfirmation() {
- const std::wstring text = l10n_util::GetString(IDS_UNINSTALL_VERIFY);
- const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME);
- const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST;
- return (IDOK == win_util::MessageBox(NULL, text, caption, flags));
-}
-
-// Prepares the localized strings that are going to be displayed to
-// the user if the browser process dies. These strings are stored in the
-// environment block so they are accessible in the early stages of the
-// chrome executable's lifetime.
-void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) {
- // Clear this var so child processes don't show the dialog by default.
- ::SetEnvironmentVariableW(env_vars::kShowRestart, NULL);
-
- // For non-interactive tests we don't restart on crash.
- if (::GetEnvironmentVariableW(env_vars::kHeadless, NULL, 0))
- return;
-
- // If the known command-line test options are used we don't create the
- // environment block which means we don't get the restart dialog.
- if (parsed_command_line.HasSwitch(switches::kBrowserCrashTest) ||
- parsed_command_line.HasSwitch(switches::kBrowserAssertTest) ||
- parsed_command_line.HasSwitch(switches::kNoErrorDialogs))
- return;
-
- // The encoding we use for the info is "title|context|direction" where
- // direction is either env_vars::kRtlLocale or env_vars::kLtrLocale depending
- // on the current locale.
- std::wstring dlg_strings;
- dlg_strings.append(l10n_util::GetString(IDS_CRASH_RECOVERY_TITLE));
- dlg_strings.append(L"|");
- dlg_strings.append(l10n_util::GetString(IDS_CRASH_RECOVERY_CONTENT));
- dlg_strings.append(L"|");
- if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
- dlg_strings.append(env_vars::kRtlLocale);
- else
- dlg_strings.append(env_vars::kLtrLocale);
-
- ::SetEnvironmentVariableW(env_vars::kRestartInfo, dlg_strings.c_str());
-}
-
-int DoUninstallTasks() {
- if (!AskForUninstallConfirmation())
- return ResultCodes::UNINSTALL_USER_CANCEL;
- // The following actions are just best effort.
- LOG(INFO) << "Executing uninstall actions";
- ResultCodes::ExitCode ret = ResultCodes::NORMAL_EXIT;
- if (!FirstRun::RemoveSentinel())
- ret = ResultCodes::UNINSTALL_DELETE_FILE_ERROR;
- // We only want to modify user level shortcuts so pass false for system_level.
- if (!ShellUtil::RemoveChromeDesktopShortcut(ShellUtil::CURRENT_USER))
- ret = ResultCodes::UNINSTALL_DELETE_FILE_ERROR;
- if (!ShellUtil::RemoveChromeQuickLaunchShortcut(ShellUtil::CURRENT_USER))
- ret = ResultCodes::UNINSTALL_DELETE_FILE_ERROR;
- return ret;
-}
-
-// This method handles the --hide-icons and --show-icons command line options
-// for chrome that get triggered by Windows from registry entries
-// HideIconsCommand & ShowIconsCommand. Chrome doesn't support hide icons
-// functionality so we just ask the users if they want to uninstall Chrome.
-int HandleIconsCommands(const CommandLine &parsed_command_line) {
- if (parsed_command_line.HasSwitch(switches::kHideIcons)) {
- std::wstring cp_applet;
- if (win_util::GetWinVersion() == win_util::WINVERSION_VISTA) {
- cp_applet.assign(L"Programs and Features"); // Windows Vista and later.
- } else if (win_util::GetWinVersion() == win_util::WINVERSION_XP) {
- cp_applet.assign(L"Add/Remove Programs"); // Windows XP.
- } else {
- return ResultCodes::UNSUPPORTED_PARAM; // Not supported
- }
-
- const std::wstring msg = l10n_util::GetStringF(IDS_HIDE_ICONS_NOT_SUPPORTED,
- cp_applet);
- const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME);
- const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST;
- if (IDOK == win_util::MessageBox(NULL, msg, caption, flags))
- ShellExecute(NULL, NULL, L"appwiz.cpl", NULL, NULL, SW_SHOWNORMAL);
- return ResultCodes::NORMAL_EXIT; // Exit as we are not launching browser.
- }
- // We don't hide icons so we shouldn't do anything special to show them
- return ResultCodes::UNSUPPORTED_PARAM;
-}
-
-bool DoUpgradeTasks(const CommandLine& command_line) {
- if (!Upgrade::SwapNewChromeExeIfPresent())
- return false;
- // At this point the chrome.exe has been swapped with the new one.
- if (!Upgrade::RelaunchChromeBrowser(command_line)) {
- // The re-launch fails. Feel free to panic now.
- NOTREACHED();
- }
- return true;
-}
-
-// Check if there is any machine level Chrome installed on the current
-// machine. If yes and the current Chrome process is user level, we do not
-// allow the user level Chrome to run. So we notify the user and uninstall
-// user level Chrome.
-bool CheckMachineLevelInstall() {
- scoped_ptr<installer::Version> version(InstallUtil::GetChromeVersion(true));
- if (version.get()) {
- std::wstring exe;
- PathService::Get(base::DIR_EXE, &exe);
- std::transform(exe.begin(), exe.end(), exe.begin(), tolower);
- std::wstring user_exe_path = installer::GetChromeInstallPath(false);
- std::transform(user_exe_path.begin(), user_exe_path.end(),
- user_exe_path.begin(), tolower);
- if (exe == user_exe_path) {
- const std::wstring text =
- l10n_util::GetString(IDS_MACHINE_LEVEL_INSTALL_CONFLICT);
- const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME);
- const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST;
- win_util::MessageBox(NULL, text, caption, flags);
- std::wstring uninstall_cmd = InstallUtil::GetChromeUninstallCmd(false);
- if (!uninstall_cmd.empty()) {
- uninstall_cmd.append(L" --");
- uninstall_cmd.append(installer_util::switches::kForceUninstall);
- uninstall_cmd.append(L" --");
- uninstall_cmd.append(installer_util::switches::kDoNotRemoveSharedItems);
- base::LaunchApp(uninstall_cmd, false, false, NULL);
- }
- return true;
- }
- }
- return false;
-}
-
-// We record in UMA the conditions that can prevent breakpad from generating
-// and sending crash reports. Namely that the crash reporting registration
-// failed and that the process is being debugged.
-void RecordBreakpadStatusUMA(MetricsService* metrics) {
- DWORD len = ::GetEnvironmentVariableW(env_vars::kNoOOBreakpad, NULL, 0);
- metrics->RecordBreakpadRegistration((len == 0));
- metrics->RecordBreakpadHasDebugger(TRUE == ::IsDebuggerPresent());
-}
-
} // namespace
// Main routine for running as the Browser process.
@@ -636,3 +497,26 @@ int BrowserMain(CommandLine &parsed_command_line,
return result_code;
}
+
+#elif defined(OS_POSIX)
+
+// Call to kick off the main message loop. The implementation for this on Mac
+// must reside in another file because it has to call Cocoa functions and thus
+// cannot live in a .cc file.
+int StartPlatformMessageLoop();
+
+// TODO(port): merge this with above. Just a stub for now, not meant as a place
+// to duplicate code.
+// Main routine for running as the Browser process.
+int BrowserMain(CommandLine &parsed_command_line,
+ sandbox::BrokerServices* broker_services) {
+ return StartPlatformMessageLoop();
+}
+
+#if defined(OS_LINUX)
+void StartPlatformMessageLoop() {
+ return 0;
+}
+#endif
+
+#endif
diff --git a/chrome/browser/browser_main_mac.mm b/chrome/browser/browser_main_mac.mm
new file mode 100644
index 0000000..c6c4381
--- /dev/null
+++ b/chrome/browser/browser_main_mac.mm
@@ -0,0 +1,11 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <Cocoa/Cocoa.h>
+#include "base/command_line.h"
+#include <crt_externs.h>
+
+int StartPlatformMessageLoop() {
+ return NSApplicationMain(*_NSGetArgc(), (const char**)*_NSGetArgv());
+}
diff --git a/chrome/browser/browser_main_win.cc b/chrome/browser/browser_main_win.cc
new file mode 100644
index 0000000..8d939f1
--- /dev/null
+++ b/chrome/browser/browser_main_win.cc
@@ -0,0 +1,178 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/win_util.h"
+
+#include <shellapi.h>
+#include <windows.h>
+
+#include "chrome/browser/browser_main_win.h"
+
+#include "base/command_line.h"
+#include "base/path_service.h"
+#include "base/win_util.h"
+#include "chrome/app/result_codes.h"
+#include "chrome/browser/first_run.h"
+#include "chrome/browser/metrics_service.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/env_vars.h"
+#include "chrome/common/l10n_util.h"
+#include "chrome/installer/util/helper.h"
+#include "chrome/installer/util/install_util.h"
+#include "chrome/installer/util/shell_util.h"
+
+#include "chromium_strings.h"
+#include "generated_resources.h"
+
+// Displays a warning message if the user is running chrome on windows 2000.
+// Returns true if the OS is win2000, false otherwise.
+bool CheckForWin2000() {
+ if (win_util::GetWinVersion() == win_util::WINVERSION_2000) {
+ const std::wstring text = l10n_util::GetString(IDS_UNSUPPORTED_OS_WIN2000);
+ const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME);
+ win_util::MessageBox(NULL, text, caption,
+ MB_OK | MB_ICONWARNING | MB_TOPMOST);
+ return true;
+ }
+ return false;
+}
+
+bool AskForUninstallConfirmation() {
+ const std::wstring text = l10n_util::GetString(IDS_UNINSTALL_VERIFY);
+ const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME);
+ const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST;
+ return (IDOK == win_util::MessageBox(NULL, text, caption, flags));
+}
+
+int DoUninstallTasks() {
+ if (!AskForUninstallConfirmation())
+ return ResultCodes::UNINSTALL_USER_CANCEL;
+ // The following actions are just best effort.
+ LOG(INFO) << "Executing uninstall actions";
+ ResultCodes::ExitCode ret = ResultCodes::NORMAL_EXIT;
+ if (!FirstRun::RemoveSentinel())
+ ret = ResultCodes::UNINSTALL_DELETE_FILE_ERROR;
+ // We only want to modify user level shortcuts so pass false for system_level.
+ if (!ShellUtil::RemoveChromeDesktopShortcut(ShellUtil::CURRENT_USER))
+ ret = ResultCodes::UNINSTALL_DELETE_FILE_ERROR;
+ if (!ShellUtil::RemoveChromeQuickLaunchShortcut(ShellUtil::CURRENT_USER))
+ ret = ResultCodes::UNINSTALL_DELETE_FILE_ERROR;
+ return ret;
+}
+
+// Prepares the localized strings that are going to be displayed to
+// the user if the browser process dies. These strings are stored in the
+// environment block so they are accessible in the early stages of the
+// chrome executable's lifetime.
+void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) {
+ // Clear this var so child processes don't show the dialog by default.
+ ::SetEnvironmentVariableW(env_vars::kShowRestart, NULL);
+
+ // For non-interactive tests we don't restart on crash.
+ if (::GetEnvironmentVariableW(env_vars::kHeadless, NULL, 0))
+ return;
+
+ // If the known command-line test options are used we don't create the
+ // environment block which means we don't get the restart dialog.
+ if (parsed_command_line.HasSwitch(switches::kBrowserCrashTest) ||
+ parsed_command_line.HasSwitch(switches::kBrowserAssertTest) ||
+ parsed_command_line.HasSwitch(switches::kNoErrorDialogs))
+ return;
+
+ // The encoding we use for the info is "title|context|direction" where
+ // direction is either env_vars::kRtlLocale or env_vars::kLtrLocale depending
+ // on the current locale.
+ std::wstring dlg_strings;
+ dlg_strings.append(l10n_util::GetString(IDS_CRASH_RECOVERY_TITLE));
+ dlg_strings.append(L"|");
+ dlg_strings.append(l10n_util::GetString(IDS_CRASH_RECOVERY_CONTENT));
+ dlg_strings.append(L"|");
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
+ dlg_strings.append(env_vars::kRtlLocale);
+ else
+ dlg_strings.append(env_vars::kLtrLocale);
+
+ ::SetEnvironmentVariableW(env_vars::kRestartInfo, dlg_strings.c_str());
+}
+
+// This method handles the --hide-icons and --show-icons command line options
+// for chrome that get triggered by Windows from registry entries
+// HideIconsCommand & ShowIconsCommand. Chrome doesn't support hide icons
+// functionality so we just ask the users if they want to uninstall Chrome.
+int HandleIconsCommands(const CommandLine &parsed_command_line) {
+ if (parsed_command_line.HasSwitch(switches::kHideIcons)) {
+ std::wstring cp_applet;
+ if (win_util::GetWinVersion() == win_util::WINVERSION_VISTA) {
+ cp_applet.assign(L"Programs and Features"); // Windows Vista and later.
+ } else if (win_util::GetWinVersion() == win_util::WINVERSION_XP) {
+ cp_applet.assign(L"Add/Remove Programs"); // Windows XP.
+ } else {
+ return ResultCodes::UNSUPPORTED_PARAM; // Not supported
+ }
+
+ const std::wstring msg = l10n_util::GetStringF(IDS_HIDE_ICONS_NOT_SUPPORTED,
+ cp_applet);
+ const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME);
+ const UINT flags = MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST;
+ if (IDOK == win_util::MessageBox(NULL, msg, caption, flags))
+ ShellExecute(NULL, NULL, L"appwiz.cpl", NULL, NULL, SW_SHOWNORMAL);
+ return ResultCodes::NORMAL_EXIT; // Exit as we are not launching browser.
+ }
+ // We don't hide icons so we shouldn't do anything special to show them
+ return ResultCodes::UNSUPPORTED_PARAM;
+}
+
+// Check if there is any machine level Chrome installed on the current
+// machine. If yes and the current Chrome process is user level, we do not
+// allow the user level Chrome to run. So we notify the user and uninstall
+// user level Chrome.
+bool CheckMachineLevelInstall() {
+ scoped_ptr<installer::Version> version(InstallUtil::GetChromeVersion(true));
+ if (version.get()) {
+ std::wstring exe;
+ PathService::Get(base::DIR_EXE, &exe);
+ std::transform(exe.begin(), exe.end(), exe.begin(), tolower);
+ std::wstring user_exe_path = installer::GetChromeInstallPath(false);
+ std::transform(user_exe_path.begin(), user_exe_path.end(),
+ user_exe_path.begin(), tolower);
+ if (exe == user_exe_path) {
+ const std::wstring text =
+ l10n_util::GetString(IDS_MACHINE_LEVEL_INSTALL_CONFLICT);
+ const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME);
+ const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST;
+ win_util::MessageBox(NULL, text, caption, flags);
+ std::wstring uninstall_cmd = InstallUtil::GetChromeUninstallCmd(false);
+ if (!uninstall_cmd.empty()) {
+ uninstall_cmd.append(L" --");
+ uninstall_cmd.append(installer_util::switches::kForceUninstall);
+ uninstall_cmd.append(L" --");
+ uninstall_cmd.append(installer_util::switches::kDoNotRemoveSharedItems);
+ base::LaunchApp(uninstall_cmd, false, false, NULL);
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+bool DoUpgradeTasks(const CommandLine& command_line) {
+ if (!Upgrade::SwapNewChromeExeIfPresent())
+ return false;
+ // At this point the chrome.exe has been swapped with the new one.
+ if (!Upgrade::RelaunchChromeBrowser(command_line)) {
+ // The re-launch fails. Feel free to panic now.
+ NOTREACHED();
+ }
+ return true;
+}
+
+// We record in UMA the conditions that can prevent breakpad from generating
+// and sending crash reports. Namely that the crash reporting registration
+// failed and that the process is being debugged.
+void RecordBreakpadStatusUMA(MetricsService* metrics) {
+ DWORD len = ::GetEnvironmentVariableW(env_vars::kNoOOBreakpad, NULL, 0);
+ metrics->RecordBreakpadRegistration((len == 0));
+ metrics->RecordBreakpadHasDebugger(TRUE == ::IsDebuggerPresent());
+}
+
diff --git a/chrome/browser/browser_main_win.h b/chrome/browser/browser_main_win.h
new file mode 100644
index 0000000..d44958f
--- /dev/null
+++ b/chrome/browser/browser_main_win.h
@@ -0,0 +1,46 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Contains functions used by BrowserMain() that are win32-specific.
+
+#ifndef CHROME_BROWSER_BROWSER_MAIN_WIN_H_
+#define CHROME_BROWSER_BROWSER_MAIN_WIN_H_
+
+class CommandLine;
+class MetricsService;
+
+// Displays a warning message if the user is running chrome on windows 2000.
+// Returns true if the OS is win2000, false otherwise.
+bool CheckForWin2000();
+
+// Handle uninstallation when given the appropriate the command-line switch.
+int DoUninstallTasks();
+
+// Prepares the localized strings that are going to be displayed to
+// the user if the browser process dies. These strings are stored in the
+// environment block so they are accessible in the early stages of the
+// chrome executable's lifetime.
+void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line);
+
+// This method handles the --hide-icons and --show-icons command line options
+// for chrome that get triggered by Windows from registry entries
+// HideIconsCommand & ShowIconsCommand. Chrome doesn't support hide icons
+// functionality so we just ask the users if they want to uninstall Chrome.
+int HandleIconsCommands(const CommandLine &parsed_command_line);
+
+// Check if there is any machine level Chrome installed on the current
+// machine. If yes and the current Chrome process is user level, we do not
+// allow the user level Chrome to run. So we notify the user and uninstall
+// user level Chrome.
+bool CheckMachineLevelInstall();
+
+// Handle upgrades if Chromium was upgraded while it was last running.
+bool DoUpgradeTasks(const CommandLine& command_line);
+
+// We record in UMA the conditions that can prevent breakpad from generating
+// and sending crash reports. Namely that the crash reporting registration
+// failed and that the process is being debugged.
+void RecordBreakpadStatusUMA(MetricsService* metrics);
+
+#endif // CHROME_BROWSER_BROWSER_MAIN_WIN_H_ \ No newline at end of file