summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-16 17:47:57 +0000
committerpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-16 17:47:57 +0000
commit1bcdb53dbddb785f5538cb7081b073db90c822d1 (patch)
tree9b67e0a51f98ff2d0f0bb3462f530a08a8b7e6c4 /chrome/browser
parent091db5d0615084d28dfbb78d8dd6c0e169b510a4 (diff)
downloadchromium_src-1bcdb53dbddb785f5538cb7081b073db90c822d1.zip
chromium_src-1bcdb53dbddb785f5538cb7081b073db90c822d1.tar.gz
chromium_src-1bcdb53dbddb785f5538cb7081b073db90c822d1.tar.bz2
mac bootstrapping of browser main and app startup bits
Review URL: http://codereview.chromium.org/18112 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8185 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/app_controller_mac.h21
-rw-r--r--chrome/browser/app_controller_mac.mm27
-rw-r--r--chrome/browser/browser_main.cc132
-rw-r--r--chrome/browser/browser_main_mac.mm61
-rw-r--r--chrome/browser/browser_main_win.h2
-rw-r--r--chrome/browser/plugin_service.cc2
-rw-r--r--chrome/browser/plugin_service.h1
7 files changed, 192 insertions, 54 deletions
diff --git a/chrome/browser/app_controller_mac.h b/chrome/browser/app_controller_mac.h
new file mode 100644
index 0000000..09fa014
--- /dev/null
+++ b/chrome/browser/app_controller_mac.h
@@ -0,0 +1,21 @@
+// Copyright (c) 2009 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.
+
+#ifndef CHROME_BROWSER_APP_CONTROLLER_MAC_H_
+#define CHROME_BROWSER_APP_CONTROLLER_MAC_H_
+
+#import <Cocoa/Cocoa.h>
+
+// The application controller object, created by loading the MainMenu nib.
+// This handles things like responding to menus when there are no windows
+// open, etc and acts as the NSApplication delegate.
+@interface AppController : NSObject {
+ @public
+}
+
+- (IBAction)quit:(id)sender;
+
+@end
+
+#endif
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
new file mode 100644
index 0000000..cf0c49f
--- /dev/null
+++ b/chrome/browser/app_controller_mac.mm
@@ -0,0 +1,27 @@
+// Copyright (c) 2009 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.
+
+#import "app_controller_mac.h"
+
+#import "base/message_loop.h"
+
+@implementation AppController
+
+// We can't use the standard terminate: method because it will abrubptly exit
+// the app and leave things on the stack in an unfinalized state. We need to
+// post a quit message to our run loop so the stack can gracefully unwind.
+- (IBAction)quit:(id)sender {
+ // TODO(pinkerton):
+ // since we have to roll it ourselves, ask the delegate (ourselves, really)
+ // if we should terminate. For example, we might not want to if the user
+ // has ongoing downloads or multiple windows/tabs open. However, this would
+ // require posting UI and may require spinning up another run loop to
+ // handle it. If it says to continue, post the quit message, otherwise
+ // go back to normal.
+
+ MessageLoopForUI::current()->Quit();
+}
+
+
+@end
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 5c4e21d..c95acae 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -4,11 +4,41 @@
#include "build/build_config.h"
+#include <algorithm>
+
#include "base/command_line.h"
+#include "base/field_trial.h"
+#include "base/file_util.h"
+#include "base/histogram.h"
+#include "base/lazy_instance.h"
+#include "base/path_service.h"
+#include "base/process_util.h"
+#include "base/string_piece.h"
+#include "base/string_util.h"
+#include "base/system_monitor.h"
+#include "base/tracked_objects.h"
+#include "base/values.h"
+#include "chrome/app/result_codes.h"
+#include "chrome/browser/browser_main_win.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/plugin_service.h"
+#include "chrome/browser/shell_integration.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/jstemplate_builder.h"
+#include "chrome/common/l10n_util.h"
#include "chrome/common/main_function_params.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/pref_service.h"
-#if defined(OS_WIN)
-#include "sandbox/src/sandbox.h"
+#include "chromium_strings.h"
+#include "generated_resources.h"
+
+#if defined(OS_POSIX)
+// TODO(port): get rid of this include. It's used just to provide declarations
+// and stub definitions for classes we encouter during the porting effort.
+#include "chrome/common/temp_scaffolding_stubs.h"
#endif
// TODO(port): several win-only methods have been pulled out of this, but
@@ -21,25 +51,12 @@
#include <windows.h>
#include <shellapi.h>
-#include <algorithm>
-
-#include "base/file_util.h"
-#include "base/histogram.h"
-#include "base/lazy_instance.h"
-#include "base/path_service.h"
-#include "base/process_util.h"
#include "base/registry.h"
-#include "base/string_piece.h"
-#include "base/string_util.h"
-#include "base/system_monitor.h"
-#include "base/tracked_objects.h"
#include "base/win_util.h"
-#include "chrome/app/result_codes.h"
#include "chrome/browser/automation/automation_provider.h"
#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"
@@ -53,22 +70,13 @@
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/net/dns_global.h"
#include "chrome/browser/net/sdch_dictionary_fetcher.h"
-#include "chrome/browser/plugin_service.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/rlz/rlz.h"
-#include "chrome/browser/shell_integration.h"
#include "chrome/browser/url_fixer_upper.h"
#include "chrome/browser/user_data_manager.h"
#include "chrome/browser/views/user_data_dir_dialog.h"
-#include "chrome/common/chrome_constants.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/env_vars.h"
-#include "chrome/common/jstemplate_builder.h"
-#include "chrome/common/l10n_util.h"
#include "chrome/common/resource_bundle.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/common/pref_service.h"
#include "chrome/common/win_util.h"
#include "chrome/installer/util/google_update_settings.h"
#include "chrome/installer/util/helper.h"
@@ -81,11 +89,31 @@
#include "net/base/sdch_manager.h"
#include "net/base/winsock_init.h"
#include "net/http/http_network_layer.h"
+#include "sandbox/src/sandbox.h"
-#include "chromium_strings.h"
-#include "generated_resources.h"
#include "net_resources.h"
+#endif
+
+namespace Platform {
+
+void WillInitializeMainMessageLoop(const CommandLine & command_line);
+void WillTerminate();
+
+#if defined(OS_WIN) || defined(OS_LINUX)
+// Perform any platform-specific work that needs to be done before the main
+// message loop is created and initialized.
+void WillInitializeMainMessageLoop(const CommandLine & command_line) {
+}
+
+// Perform platform-specific work that needs to be done after the main event
+// loop has ended.
+void WillTerminate() {
+}
+#endif
+
+} // namespace Platform
+
namespace {
// This function provides some ways to test crash and assertion handling
@@ -103,6 +131,7 @@ void HandleErrorTestParameters(const CommandLine& command_line) {
}
}
+#if defined(OS_WIN)
// The net module doesn't have access to this HTML or the strings that need to
// be localized. The Chrome locale will never change while we're running, so
// it's safe to have a static string that we always return a pointer into.
@@ -141,14 +170,13 @@ StringPiece NetResourceProvider(int key) {
return ResourceBundle::GetSharedInstance().GetRawDataResource(key);
}
+#endif
} // namespace
// Main routine for running as the Browser process.
int BrowserMain(const MainFunctionParams& parameters) {
CommandLine& parsed_command_line = parameters.command_line_;
- sandbox::BrokerServices* broker_services =
- parameters.sandbox_info_.BrokerServices();
// WARNING: If we get a WM_ENDSESSION objects created on the stack here
// are NOT deleted. If you need something to run during WM_ENDSESSION add it
@@ -164,6 +192,11 @@ int BrowserMain(const MainFunctionParams& parameters) {
tracked_objects::AutoTracking tracking_objects;
#endif
+ // Do platform-specific things (such as finishing initiailizing Cocoa)
+ // prior to instantiating the message loop. This could be turned into a
+ // broadcast notification.
+ Platform::WillInitializeMainMessageLoop(parsed_command_line);
+
MessageLoop main_message_loop(MessageLoop::TYPE_UI);
// Initialize the SystemMonitor
@@ -258,13 +291,17 @@ int BrowserMain(const MainFunctionParams& parameters) {
parent_local_state.GetString(prefs::kApplicationLocale));
}
+#if defined(OS_WIN)
ResourceBundle::InitSharedInstance(
local_state->GetString(prefs::kApplicationLocale));
// We only load the theme dll in the browser process.
ResourceBundle::GetSharedInstance().LoadThemeResources();
+#endif
if (!parsed_command_line.HasSwitch(switches::kNoErrorDialogs)) {
// Display a warning if the user is running windows 2000.
+ // TODO(port). We should probably change this to a "check for minimum
+ // requirements" function, implemented by each platform.
CheckForWin2000();
}
@@ -278,6 +315,7 @@ int BrowserMain(const MainFunctionParams& parameters) {
ProfileManager* profile_manager = browser_process->profile_manager();
Profile* profile = profile_manager->GetDefaultProfile(user_data_dir);
if (!profile) {
+#if defined(OS_WIN)
user_data_dir = UserDataDirDialog::RunUserDataDirDialog(user_data_dir);
// Flush the message loop which lets the UserDataDirDialog close.
MessageLoop::current()->Run();
@@ -297,6 +335,7 @@ int BrowserMain(const MainFunctionParams& parameters) {
}
return ResultCodes::NORMAL_EXIT;
+#endif
}
PrefService* user_prefs = profile->GetPrefs();
@@ -313,10 +352,12 @@ int BrowserMain(const MainFunctionParams& parameters) {
// unless we detect another chrome browser running.
if (parsed_command_line.HasSwitch(switches::kUninstall)) {
if (already_running) {
+#if defined(OS_WIN)
const std::wstring text = l10n_util::GetString(IDS_UNINSTALL_CLOSE_APP);
const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME);
win_util::MessageBox(NULL, text, caption,
MB_OK | MB_ICONWARNING | MB_TOPMOST);
+#endif
return ResultCodes::UNINSTALL_CHROME_ALIVE;
} else {
return DoUninstallTasks();
@@ -380,6 +421,7 @@ int BrowserMain(const MainFunctionParams& parameters) {
// testing against a bunch of special cases that are taken care early on.
PrepareRestartOnCrashEnviroment(parsed_command_line);
+#if defined(OS_WIN)
// Initialize Winsock.
net::EnsureWinsockInit();
@@ -408,7 +450,10 @@ int BrowserMain(const MainFunctionParams& parameters) {
RegisterURLRequestChromeJob();
RegisterExtensionProtocols();
+ sandbox::BrokerServices* broker_services =
+ parameters.sandbox_info_.BrokerServices();
browser_process->InitBrokerServices(broker_services);
+#endif
// In unittest mode, this will do nothing. In normal mode, this will create
// the global GoogleURLTracker instance, which will promptly go to sleep for
@@ -428,6 +473,7 @@ int BrowserMain(const MainFunctionParams& parameters) {
// Have Chrome plugins write their data to the profile directory.
PluginService::GetInstance()->SetChromePluginDataDir(profile->GetPath());
+#if defined(OS_WIN)
// Initialize the CertStore.
CertStore::Initialize();
@@ -441,6 +487,7 @@ int BrowserMain(const MainFunctionParams& parameters) {
WideToASCII(parsed_command_line.GetSwitchValue(switches::kSdchFilter));
}
sdch_manager.EnableSdchSupport(switch_domain);
+#endif
MetricsService* metrics = NULL;
if (!parsed_command_line.HasSwitch(switches::kDisableMetrics)) {
@@ -467,10 +514,12 @@ int BrowserMain(const MainFunctionParams& parameters) {
}
InstallJankometer(parsed_command_line);
+#if defined(OS_WIN)
if (parsed_command_line.HasSwitch(switches::kDebugPrint)) {
browser_process->print_job_manager()->set_debug_dump_path(
parsed_command_line.GetSwitchValue(switches::kDebugPrint));
}
+#endif
HandleErrorTestParameters(parsed_command_line);
@@ -479,9 +528,15 @@ int BrowserMain(const MainFunctionParams& parameters) {
int result_code = ResultCodes::NORMAL_EXIT;
if (BrowserInit::ProcessCommandLine(parsed_command_line, L"", local_state,
true, profile, &result_code)) {
+#if defined(OS_WIN)
MessageLoopForUI::current()->Run(browser_process->accelerator_handler());
+#elif defined(OS_POSIX)
+ MessageLoopForUI::current()->Run();
+#endif
}
+ Platform::WillTerminate();
+
if (metrics)
metrics->Stop();
@@ -493,24 +548,3 @@ int BrowserMain(const MainFunctionParams& parameters) {
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(const MainFunctionParams& parameters) {
- 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
index c6c4381..8f493f3 100644
--- a/chrome/browser/browser_main_mac.mm
+++ b/chrome/browser/browser_main_mac.mm
@@ -1,11 +1,66 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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.
#include <Cocoa/Cocoa.h>
#include "base/command_line.h"
+#include "chrome/app/result_codes.h"
+#include "chrome/browser/app_controller_mac.h"
+#include "chrome/browser/browser_main_win.h"
#include <crt_externs.h>
-int StartPlatformMessageLoop() {
- return NSApplicationMain(*_NSGetArgc(), (const char**)*_NSGetArgv());
+namespace Platform {
+
+// Perform and platform-specific work that needs to be done before the main
+// message loop is created and initialized.
+//
+// For Mac, this involves telling Cooca to finish its initalization, which we
+// want to do manually instead of calling NSApplicationMain(). The primary
+// reason is that NSAM() never returns, which would leave all the objects
+// currently on the stack in scoped_ptrs hanging and never cleaned up. We then
+// load the main nib directly. The main event loop is run from common code using
+// the MessageLoop API, which works out ok for us because it's a wrapper around
+// CFRunLoop.
+void WillInitializeMainMessageLoop(const CommandLine & command_line) {
+ [NSApplication sharedApplication];
+ [NSBundle loadNibNamed:@"MainMenu" owner:NSApp];
+}
+
+// Perform platform-specific work that needs to be done after the main event
+// loop has ended. We need to send the notifications that Cooca normally would
+// telling everyone the app is about to end.
+void WillTerminate() {
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:NSApplicationWillTerminateNotification
+ object:NSApp];
+}
+
+}
+
+// From browser_main_win.h, stubs until we figure out the right thing...
+
+int DoUninstallTasks() {
+ return ResultCodes::NORMAL_EXIT;
+}
+
+bool DoUpgradeTasks(const CommandLine& command_line) {
+ return ResultCodes::NORMAL_EXIT;
+}
+
+bool CheckForWin2000() {
+ return false;
+}
+
+int HandleIconsCommands(const CommandLine &parsed_command_line) {
+ return 0;
+}
+
+bool CheckMachineLevelInstall() {
+ return false;
+}
+
+void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) {
+}
+
+void RecordBreakpadStatusUMA(MetricsService* metrics) {
}
diff --git a/chrome/browser/browser_main_win.h b/chrome/browser/browser_main_win.h
index d44958f..9069058 100644
--- a/chrome/browser/browser_main_win.h
+++ b/chrome/browser/browser_main_win.h
@@ -43,4 +43,4 @@ bool DoUpgradeTasks(const CommandLine& command_line);
// 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
+#endif // CHROME_BROWSER_BROWSER_MAIN_WIN_H_
diff --git a/chrome/browser/plugin_service.cc b/chrome/browser/plugin_service.cc
index fc95294..235ccf4 100644
--- a/chrome/browser/plugin_service.cc
+++ b/chrome/browser/plugin_service.cc
@@ -23,8 +23,8 @@ PluginService* PluginService::GetInstance() {
PluginService::PluginService()
: main_message_loop_(MessageLoop::current()),
- ui_locale_(g_browser_process->GetApplicationLocale()),
resource_dispatcher_host_(NULL),
+ ui_locale_(g_browser_process->GetApplicationLocale()),
plugin_shutdown_handler_(new ShutdownHandler) {
// Have the NPAPI plugin list search for Chrome plugins as well.
ChromePluginLib::RegisterPluginsWithNPAPI();
diff --git a/chrome/browser/plugin_service.h b/chrome/browser/plugin_service.h
index 1355b64..c37b362 100644
--- a/chrome/browser/plugin_service.h
+++ b/chrome/browser/plugin_service.h
@@ -176,6 +176,7 @@ class PluginProcessHostIterator {
PluginProcessHostIterator& operator=(
const PluginProcessHostIterator& instance) {
iterator_ = instance.iterator_;
+ return *this;
}
const PluginProcessHost* operator->() const {