diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-08 19:41:43 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-08 19:41:43 +0000 |
commit | c1702d71f2fb3ba58cceb044c8e7401da1d5c9c8 (patch) | |
tree | d4295fc8a134647c4672b7eeb7a8617e4f2a19df /content | |
parent | 4de8252c14229f47df5fb78363d6bdb72c927d27 (diff) | |
download | chromium_src-c1702d71f2fb3ba58cceb044c8e7401da1d5c9c8.zip chromium_src-c1702d71f2fb3ba58cceb044c8e7401da1d5c9c8.tar.gz chromium_src-c1702d71f2fb3ba58cceb044c8e7401da1d5c9c8.tar.bz2 |
Refactor some more BrowserMain code. Move the small bit of remaining code that's required by all embedders to content.
BUG=90445
Review URL: http://codereview.chromium.org/7840041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100223 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/browser_main.cc | 138 | ||||
-rw-r--r-- | content/browser/browser_main.h | 14 | ||||
-rw-r--r-- | content/common/content_switches.cc | 6 | ||||
-rw-r--r-- | content/common/content_switches.h | 4 | ||||
-rw-r--r-- | content/content_browser.gypi | 7 |
5 files changed, 138 insertions, 31 deletions
diff --git a/content/browser/browser_main.cc b/content/browser/browser_main.cc index 7d7a599..dd497bf 100644 --- a/content/browser/browser_main.cc +++ b/content/browser/browser_main.cc @@ -11,26 +11,38 @@ #include "base/metrics/field_trial.h" #include "base/metrics/histogram.h" #include "base/system_monitor/system_monitor.h" +#include "base/threading/thread_restrictions.h" #include "content/browser/browser_thread.h" #include "content/browser/content_browser_client.h" #include "content/common/content_switches.h" #include "content/common/hi_res_timer_manager.h" #include "content/common/main_function_params.h" +#include "content/common/result_codes.h" #include "content/common/sandbox_policy.h" +#include "crypto/nss_util.h" #include "net/base/network_change_notifier.h" #include "net/base/ssl_config_service.h" +#include "net/socket/client_socket_factory.h" #include "net/socket/tcp_client_socket.h" #if defined(OS_WIN) #include <windows.h> #include <commctrl.h> +#include <ole2.h> #include <shellapi.h> +#include "base/win/scoped_com_initializer.h" +#include "net/base/winsock_init.h" #include "sandbox/src/sandbox.h" +#include "ui/base/l10n/l10n_util_win.h" #endif #if defined(OS_POSIX) && !defined(OS_MACOSX) #include <dbus/dbus-glib.h> +#include <sys/stat.h> + +#include "content/browser/renderer_host/render_sandbox_host_linux.h" +#include "content/browser/zygote_host_linux.h" #endif #if defined(TOOLKIT_USES_GTK) @@ -39,11 +51,10 @@ namespace { -// Windows-specific initialization code for the sandbox broker services. This -// is just a NOP on non-Windows platforms to reduce ifdefs later on. +#if defined(OS_WIN) +// Windows-specific initialization code for the sandbox broker services. void InitializeBrokerServices(const MainFunctionParams& parameters, const CommandLine& parsed_command_line) { -#if defined(OS_WIN) sandbox::BrokerServices* broker_services = parameters.sandbox_info_.BrokerServices(); if (broker_services) { @@ -58,8 +69,36 @@ void InitializeBrokerServices(const MainFunctionParams& parameters, policy->Release(); } } +} +#elif defined(OS_POSIX) && !defined(OS_MACOSX) +void SetupSandbox(const CommandLine& parsed_command_line) { + // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this + // code en masse out of chrome_main for now. + const char* sandbox_binary = NULL; + struct stat st; + + // In Chromium branded builds, developers can set an environment variable to + // use the development sandbox. See + // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment + if (stat("/proc/self/exe", &st) == 0 && st.st_uid == getuid()) + sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); + +#if defined(LINUX_SANDBOX_PATH) + if (!sandbox_binary) + sandbox_binary = LINUX_SANDBOX_PATH; #endif + + std::string sandbox_cmd; + if (sandbox_binary && !parsed_command_line.HasSwitch(switches::kNoSandbox)) + sandbox_cmd = sandbox_binary; + + // Tickle the sandbox host and zygote host so they fork now. + RenderSandboxHostLinux* shost = RenderSandboxHostLinux::GetInstance(); + shost->Init(sandbox_cmd); + ZygoteHost* zhost = ZygoteHost::GetInstance(); + zhost->Init(sandbox_cmd); } +#endif #if defined(TOOLKIT_USES_GTK) static void GLibLogHandler(const gchar* log_domain, @@ -119,7 +158,8 @@ namespace content { BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters) : parameters_(parameters), - parsed_command_line_(parameters.command_line_) { + parsed_command_line_(parameters.command_line_), + result_code_(content::RESULT_CODE_NORMAL_EXIT) { } BrowserMainParts::~BrowserMainParts() { @@ -128,11 +168,32 @@ BrowserMainParts::~BrowserMainParts() { void BrowserMainParts::EarlyInitialization() { PreEarlyInitialization(); - if (parsed_command_line().HasSwitch(switches::kEnableBenchmarking)) - base::FieldTrial::EnableBenchmarking(); +#if defined(OS_WIN) + net::EnsureWinsockInit(); +#endif + + // Use NSS for SSL by default. + // The default client socket factory uses NSS for SSL by default on + // Windows and Mac. +#if defined(OS_WIN) || defined(OS_MACOSX) + if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { + net::ClientSocketFactory::UseSystemSSL(); + } else { +#elif defined(USE_NSS) + if (true) { +#else + if (false) { +#endif + // We want to be sure to init NSPR on the main thread. + crypto::EnsureNSPRInit(); + } - InitializeSSL(); +#if defined(OS_POSIX) && !defined(OS_MACOSX) + SetupSandbox(parsed_command_line()); +#endif + if (parsed_command_line().HasSwitch(switches::kEnableBenchmarking)) + base::FieldTrial::EnableBenchmarking(); if (parsed_command_line().HasSwitch(switches::kDisableSSLFalseStart)) net::SSLConfigService::DisableFalseStart(); if (parsed_command_line().HasSwitch(switches::kEnableSSLCachedInfo)) @@ -145,7 +206,7 @@ void BrowserMainParts::EarlyInitialization() { } // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't - // seem dependent on InitializeSSL(). + // seem dependent on SSL initialization(). if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen)) net::set_tcp_fastopen_enabled(true); @@ -155,6 +216,17 @@ void BrowserMainParts::EarlyInitialization() { void BrowserMainParts::MainMessageLoopStart() { PreMainMessageLoopStart(); +#if defined(OS_WIN) + OleInitialize(NULL); + + // If we're running tests (ui_task is non-null), then the ResourceBundle + // has already been initialized. + if (!parameters().ui_task) { + // Override the configured locale with the user's preferred UI language. + l10n_util::OverrideLocaleWithUILanguageList(); + } +#endif + main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); // TODO(viettrungluu): should these really go before setting the thread name? @@ -168,6 +240,19 @@ void BrowserMainParts::MainMessageLoopStart() { PostMainMessageLoopStart(); } +void BrowserMainParts::RunMainMessageLoopParts() { + PreMainMessageLoopRun(); + + TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); + // If the UI thread blocks, the whole UI is unresponsive. + // Do not allow disk IO from the UI thread. + base::ThreadRestrictions::SetIOAllowed(false); + MainMessageLoopRun(); + TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); + + PostMainMessageLoopRun(); +} + void BrowserMainParts::InitializeMainThread() { const char* kThreadName = "CrBrowserMain"; base::PlatformThread::SetName(kThreadName); @@ -214,7 +299,6 @@ void BrowserMainParts::InitializeToolkit() { #endif #if defined(OS_WIN) - // Init common control sex. INITCOMMONCONTROLSEX config; config.dwSize = sizeof(config); config.dwICC = ICC_WIN95_CLASSES; @@ -237,14 +321,21 @@ void BrowserMainParts::PreMainMessageLoopStart() { void BrowserMainParts::PostMainMessageLoopStart() { } -void BrowserMainParts::InitializeSSL() { +void BrowserMainParts::PreMainMessageLoopRun() { } -void BrowserMainParts::ToolkitInitialized() { +void BrowserMainParts::MainMessageLoopRun() { +#if defined(OS_MACOSX) + MessageLoopForUI::current()->Run(); +#else + MessageLoopForUI::current()->Run(NULL); +#endif } -int BrowserMainParts::TemporaryContinue() { - return 0; +void BrowserMainParts::PostMainMessageLoopRun() { +} + +void BrowserMainParts::ToolkitInitialized() { } } // namespace content @@ -288,32 +379,29 @@ int BrowserMain(const MainFunctionParams& parameters) { // Thanks! // TODO(viettrungluu): put the remainder into BrowserMainParts - const CommandLine& parsed_command_line = parameters.command_line_; -#if defined(OS_WIN) && !defined(NO_TCMALLOC) +#if defined(OS_WIN) +#if !defined(NO_TCMALLOC) // When linking shared libraries, NO_TCMALLOC is defined, and dynamic // allocator selection is not supported. // Make this call before going multithreaded, or spawning any subprocesses. base::allocator::SetupSubprocessAllocator(); -#endif // OS_WIN - +#endif // The broker service initialization needs to run early because it will // initialize the sandbox broker, which requires the process to swap its // window station. During this time all the UI will be broken. This has to // run before threads and windows are created. - InitializeBrokerServices(parameters, parsed_command_line); + InitializeBrokerServices(parameters, parameters.command_line_); + + base::win::ScopedCOMInitializer com_initializer; +#endif // OS_WIN // Initialize histogram statistics gathering system. base::StatisticsRecorder statistics; - // TODO(jam): bring the content parts from this chrome function here. - int result_code = parts->TemporaryContinue(); - - // Release BrowserMainParts here, before shutting down CrosLibrary, since - // some of the classes initialized there have CrosLibrary dependencies. - parts.reset(NULL); + parts->RunMainMessageLoopParts(); TRACE_EVENT_END_ETW("BrowserMain", 0, 0); - return result_code; + return parts->result_code(); } diff --git a/content/browser/browser_main.h b/content/browser/browser_main.h index 931bd9a..bab45a0 100644 --- a/content/browser/browser_main.h +++ b/content/browser/browser_main.h @@ -73,11 +73,11 @@ class BrowserMainParts { // Parts to be called by |BrowserMain()|. void EarlyInitialization(); - void MainMessageLoopStart(); void InitializeToolkit(); + void MainMessageLoopStart(); + void RunMainMessageLoopParts(); - // Temporary function since not all the code from chrome is moved over yet. - virtual int TemporaryContinue(); + int result_code() const { return result_code_; } protected: // Methods to be overridden to provide platform-specific code; these @@ -86,9 +86,9 @@ class BrowserMainParts { virtual void PostEarlyInitialization(); virtual void PreMainMessageLoopStart(); virtual void PostMainMessageLoopStart(); - - // Used to initialize NSPR where appropriate. - virtual void InitializeSSL(); + virtual void PreMainMessageLoopRun(); + virtual void MainMessageLoopRun(); + virtual void PostMainMessageLoopRun(); // Allows an embedder to do any extra toolkit initialization. virtual void ToolkitInitialized(); @@ -103,6 +103,7 @@ class BrowserMainParts { MessageLoop& main_message_loop() const { return *main_message_loop_; } + void set_result_code(int result_code) { result_code_ = result_code; } private: void InitializeMainThread(); @@ -111,6 +112,7 @@ class BrowserMainParts { const MainFunctionParams& parameters_; const CommandLine& parsed_command_line_; + int result_code_; // Members initialized in |MainMessageLoopStart()| --------------------------- scoped_ptr<MessageLoop> main_message_loop_; diff --git a/content/common/content_switches.cc b/content/common/content_switches.cc index 31d4b93..0587a60 100644 --- a/content/common/content_switches.cc +++ b/content/common/content_switches.cc @@ -503,6 +503,12 @@ const char kAuditAllHandles[] = "enable-handle-auditing-all"; const char kScrollPixels[] = "scroll-pixels"; #endif +#if defined(OS_MACOSX) || defined(OS_WIN) +// Use the system SSL library (Secure Transport on Mac, SChannel on Windows) +// instead of NSS for SSL. +const char kUseSystemSSL[] = "use-system-ssl"; +#endif + #if !defined(OFFICIAL_BUILD) // Causes the renderer process to throw an assertion on launch. const char kRendererCheckFalseTest[] = "renderer-check-false-test"; diff --git a/content/common/content_switches.h b/content/common/content_switches.h index 07e1c97..478b9b8 100644 --- a/content/common/content_switches.h +++ b/content/common/content_switches.h @@ -162,6 +162,10 @@ extern const char kAuditAllHandles[]; extern const char kScrollPixels[]; #endif +#if defined(OS_MACOSX) || defined(OS_WIN) +extern const char kUseSystemSSL[]; +#endif + #if !defined(OFFICIAL_BUILD) extern const char kRendererCheckFalseTest[]; #endif diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 2ecde32..7700d44 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -570,6 +570,13 @@ '../build/linux/system.gyp:x11', '../dbus/dbus.gyp:dbus', ], + 'conditions': [ + ['linux_sandbox_path != ""', { + 'defines': [ + 'LINUX_SANDBOX_PATH="<(linux_sandbox_path)"', + ], + }], + ], }], ['OS=="linux" and toolkit_views==1',{ 'dependencies': [ |