diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 11:47:45 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 11:47:45 +0000 |
commit | 147f809faed46a296cd07c4a936d9d2005a2ce93 (patch) | |
tree | f92c7922475b0412dd24f61abfe9687c36e494f8 /content | |
parent | b76d5e3565454534a3e8c165c450925bb3a5a25c (diff) | |
download | chromium_src-147f809faed46a296cd07c4a936d9d2005a2ce93.zip chromium_src-147f809faed46a296cd07c4a936d9d2005a2ce93.tar.gz chromium_src-147f809faed46a296cd07c4a936d9d2005a2ce93.tar.bz2 |
Implement a ShellBrowserMain in content_shell, so we can emulate DRT's server mode
BUG=111316
TEST=run content_shell without parameters, no observable change, run with --dump-render-tree and start typing URLs. Should open the URLs. Type QUIT to exit.
Review URL: http://codereview.chromium.org/9699120
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127937 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/content_shell.gypi | 5 | ||||
-rw-r--r-- | content/public/browser/browser_main_runner.h | 2 | ||||
-rw-r--r-- | content/shell/shell_browser_context.cc | 2 | ||||
-rw-r--r-- | content/shell/shell_browser_main.cc | 151 | ||||
-rw-r--r-- | content/shell/shell_browser_main.h | 47 | ||||
-rw-r--r-- | content/shell/shell_browser_main_parts.cc | 108 | ||||
-rw-r--r-- | content/shell/shell_browser_main_parts.h | 60 | ||||
-rw-r--r-- | content/shell/shell_browser_main_parts_mac.mm (renamed from content/shell/shell_browser_main_mac.mm) | 2 | ||||
-rw-r--r-- | content/shell/shell_content_browser_client.cc | 6 | ||||
-rw-r--r-- | content/shell/shell_content_browser_client.h | 3 | ||||
-rw-r--r-- | content/shell/shell_main_delegate.cc | 6 |
11 files changed, 254 insertions, 138 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi index 3d7176e..97699ed 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -41,6 +41,7 @@ '../webkit/support/webkit_support.gyp:fileapi', '../webkit/support/webkit_support.gyp:glue', '../webkit/support/webkit_support.gyp:quota', + '../webkit/support/webkit_support.gyp:webkit_support', ], 'include_dirs': [ '..', @@ -57,7 +58,9 @@ 'shell/shell_browser_context.h', 'shell/shell_browser_main.cc', 'shell/shell_browser_main.h', - 'shell/shell_browser_main_mac.mm', + 'shell/shell_browser_main_parts.cc', + 'shell/shell_browser_main_parts.h', + 'shell/shell_browser_main_parts_mac.mm', 'shell/shell_content_browser_client.cc', 'shell/shell_content_browser_client.h', 'shell/shell_content_client.cc', diff --git a/content/public/browser/browser_main_runner.h b/content/public/browser/browser_main_runner.h index 97fbf42..4490d64 100644 --- a/content/public/browser/browser_main_runner.h +++ b/content/public/browser/browser_main_runner.h @@ -14,7 +14,7 @@ namespace content { struct MainFunctionParams; // This class is responsible for browser initialization, running and shutdown. -class BrowserMainRunner { +class CONTENT_EXPORT BrowserMainRunner { public: virtual ~BrowserMainRunner() {} diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc index 4872dc6..c8bb4e3 100644 --- a/content/shell/shell_browser_context.cc +++ b/content/shell/shell_browser_context.cc @@ -14,7 +14,7 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/geolocation_permission_context.h" #include "content/public/browser/speech_recognition_preferences.h" -#include "content/shell/shell_browser_main.h" +#include "content/shell/shell_browser_main_parts.h" #include "content/shell/shell_download_manager_delegate.h" #include "content/shell/shell_resource_context.h" #include "content/shell/shell_url_request_context_getter.h" diff --git a/content/shell/shell_browser_main.cc b/content/shell/shell_browser_main.cc index eeaa23f6..5a1755a 100644 --- a/content/shell/shell_browser_main.cc +++ b/content/shell/shell_browser_main.cc @@ -4,102 +4,79 @@ #include "content/shell/shell_browser_main.h" -#include "base/bind.h" #include "base/command_line.h" -#include "base/message_loop.h" -#include "base/string_number_conversions.h" -#include "base/threading/thread.h" -#include "base/threading/thread_restrictions.h" -#include "content/browser/browser_process_sub_thread.h" -#include "content/browser/download/download_file_manager.h" -#include "content/browser/download/save_file_manager.h" -#include "content/browser/plugin_service_impl.h" -#include "content/public/common/content_switches.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/browser/browser_main_runner.h" #include "content/shell/shell.h" #include "content/shell/shell_browser_context.h" #include "content/shell/shell_content_browser_client.h" -#include "content/shell/shell_devtools_delegate.h" -#include "net/base/net_module.h" -#include "ui/base/clipboard/clipboard.h" - -namespace content { - -static GURL GetStartupURL() { - const CommandLine::StringVector& args = - CommandLine::ForCurrentProcess()->GetArgs(); - if (args.empty()) - return GURL("http://www.google.com/"); - - return GURL(args[0]); -} - -ShellBrowserMainParts::ShellBrowserMainParts( - const content::MainFunctionParams& parameters) - : BrowserMainParts(), - devtools_delegate_(NULL) { - ShellContentBrowserClient* shell_browser_client = - static_cast<ShellContentBrowserClient*>( - content::GetContentClient()->browser()); - shell_browser_client->set_shell_browser_main_parts(this); -} - -ShellBrowserMainParts::~ShellBrowserMainParts() { -} - -#if !defined(OS_MACOSX) -void ShellBrowserMainParts::PreMainMessageLoopStart() { -} -#endif - -MessageLoop* ShellBrowserMainParts::GetMainMessageLoop() { - return NULL; -} - -int ShellBrowserMainParts::PreCreateThreads() { - return 0; +#include "content/shell/shell_switches.h" +#include "webkit/support/webkit_support.h" + +namespace { + +GURL GetURLForLayoutTest(const char* test_name) { + std::string path_or_url = test_name; + std::string pixel_hash; + std::string timeout; + std::string::size_type separator_position = path_or_url.find(' '); + if (separator_position != std::string::npos) { + timeout = path_or_url.substr(separator_position + 1); + path_or_url.erase(separator_position); + separator_position = path_or_url.find(' '); + if (separator_position != std::string::npos) { + pixel_hash = timeout.substr(separator_position + 1); + timeout.erase(separator_position); + } + } + // TODO(jochen): use pixel_hash and timeout. + GURL test_url = webkit_support::CreateURLForPathOrURL(path_or_url); + webkit_support::SetCurrentDirectoryForFileURL(test_url); + return test_url; } -void ShellBrowserMainParts::PreMainMessageLoopRun() { - browser_context_.reset(new ShellBrowserContext(this)); - - Shell::PlatformInitialize(); - net::NetModule::SetResourceProvider(Shell::PlatformResourceProvider); +} // namespace - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { - std::string port_str = - command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); - int port; - if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) { - devtools_delegate_ = new ShellDevToolsDelegate( - port, - browser_context_->GetRequestContext()); - } else { - DLOG(WARNING) << "Invalid http debugger port number " << port; +// Main routine for running as the Browser process. +int ShellBrowserMain(const content::MainFunctionParams& parameters) { + scoped_ptr<content::BrowserMainRunner> main_runner_( + content::BrowserMainRunner::Create()); + + int exit_code = main_runner_->Initialize(parameters); + if (exit_code >= 0) + return exit_code; + + bool layout_test_mode = + CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); + + if (layout_test_mode) { + char test_string[2048]; + content::ShellBrowserContext* browser_context = + static_cast<content::ShellContentBrowserClient*>( + content::GetContentClient()->browser())->browser_context(); + + while (fgets(test_string, sizeof(test_string), stdin)) { + char *new_line_position = strchr(test_string, '\n'); + if (new_line_position) + *new_line_position = '\0'; + if (test_string[0] == '\0') + continue; + if (!strcmp(test_string, "QUIT")) + break; + content::Shell::CreateNewWindow(browser_context, + GetURLForLayoutTest(test_string), + NULL, + MSG_ROUTING_NONE, + NULL); + main_runner_->Run(); + // TODO(jochen): Figure out a way to close shell. } + exit_code = 0; + } else { + exit_code = main_runner_->Run(); } - Shell::CreateNewWindow(browser_context_.get(), - GetStartupURL(), - NULL, - MSG_ROUTING_NONE, - NULL); -} - -void ShellBrowserMainParts::PostMainMessageLoopRun() { - if (devtools_delegate_) - devtools_delegate_->Stop(); - browser_context_.reset(); -} - -bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { - return false; -} + main_runner_->Shutdown(); -ui::Clipboard* ShellBrowserMainParts::GetClipboard() { - if (!clipboard_.get()) - clipboard_.reset(new ui::Clipboard()); - return clipboard_.get(); + return exit_code; } - -} // namespace diff --git a/content/shell/shell_browser_main.h b/content/shell/shell_browser_main.h index f91fad3..3939efa 100644 --- a/content/shell/shell_browser_main.h +++ b/content/shell/shell_browser_main.h @@ -6,53 +6,10 @@ #define CONTENT_SHELL_SHELL_BROWSER_MAIN_H_ #pragma once -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "content/public/browser/browser_main_parts.h" - -namespace base { -class Thread; -} - -namespace ui { -class Clipboard; -} - namespace content { - -class ShellBrowserContext; -class ShellDevToolsDelegate; struct MainFunctionParams; +} -class ShellBrowserMainParts : public BrowserMainParts { - public: - explicit ShellBrowserMainParts(const content::MainFunctionParams& parameters); - virtual ~ShellBrowserMainParts(); - - virtual void PreEarlyInitialization() OVERRIDE {} - virtual void PostEarlyInitialization() OVERRIDE {} - virtual void PreMainMessageLoopStart() OVERRIDE; - virtual MessageLoop* GetMainMessageLoop() OVERRIDE; - virtual void PostMainMessageLoopStart() OVERRIDE {} - virtual void ToolkitInitialized() OVERRIDE {} - virtual int PreCreateThreads() OVERRIDE; - virtual void PreMainMessageLoopRun() OVERRIDE; - virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; - virtual void PostMainMessageLoopRun() OVERRIDE; - virtual void PostDestroyThreads() OVERRIDE {} - - ui::Clipboard* GetClipboard(); - ShellDevToolsDelegate* devtools_delegate() { return devtools_delegate_; } - - private: - scoped_ptr<ShellBrowserContext> browser_context_; - - scoped_ptr<ui::Clipboard> clipboard_; - ShellDevToolsDelegate* devtools_delegate_; - - DISALLOW_COPY_AND_ASSIGN(ShellBrowserMainParts); -}; - -} // namespace content +int ShellBrowserMain(const content::MainFunctionParams& parameters); #endif // CONTENT_SHELL_SHELL_BROWSER_MAIN_H_ diff --git a/content/shell/shell_browser_main_parts.cc b/content/shell/shell_browser_main_parts.cc new file mode 100644 index 0000000..d9beba8 --- /dev/null +++ b/content/shell/shell_browser_main_parts.cc @@ -0,0 +1,108 @@ +// Copyright (c) 2012 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 "content/shell/shell_browser_main_parts.h" + +#include "base/bind.h" +#include "base/command_line.h" +#include "base/message_loop.h" +#include "base/string_number_conversions.h" +#include "base/threading/thread.h" +#include "base/threading/thread_restrictions.h" +#include "content/browser/browser_process_sub_thread.h" +#include "content/browser/download/download_file_manager.h" +#include "content/browser/download/save_file_manager.h" +#include "content/browser/plugin_service_impl.h" +#include "content/public/common/content_switches.h" +#include "content/shell/shell.h" +#include "content/shell/shell_browser_context.h" +#include "content/shell/shell_content_browser_client.h" +#include "content/shell/shell_devtools_delegate.h" +#include "content/shell/shell_switches.h" +#include "net/base/net_module.h" +#include "ui/base/clipboard/clipboard.h" + +namespace content { + +static GURL GetStartupURL() { + const CommandLine::StringVector& args = + CommandLine::ForCurrentProcess()->GetArgs(); + if (args.empty()) + return GURL("http://www.google.com/"); + + return GURL(args[0]); +} + +ShellBrowserMainParts::ShellBrowserMainParts( + const content::MainFunctionParams& parameters) + : BrowserMainParts(), + devtools_delegate_(NULL) { + ShellContentBrowserClient* shell_browser_client = + static_cast<ShellContentBrowserClient*>( + content::GetContentClient()->browser()); + shell_browser_client->set_shell_browser_main_parts(this); +} + +ShellBrowserMainParts::~ShellBrowserMainParts() { +} + +#if !defined(OS_MACOSX) +void ShellBrowserMainParts::PreMainMessageLoopStart() { +} +#endif + +MessageLoop* ShellBrowserMainParts::GetMainMessageLoop() { + return NULL; +} + +int ShellBrowserMainParts::PreCreateThreads() { + return 0; +} + +void ShellBrowserMainParts::PreMainMessageLoopRun() { + browser_context_.reset(new ShellBrowserContext(this)); + + Shell::PlatformInitialize(); + net::NetModule::SetResourceProvider(Shell::PlatformResourceProvider); + + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { + std::string port_str = + command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); + int port; + if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) { + devtools_delegate_ = new ShellDevToolsDelegate( + port, + browser_context_->GetRequestContext()); + } else { + DLOG(WARNING) << "Invalid http debugger port number " << port; + } + } + + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { + Shell::CreateNewWindow(browser_context_.get(), + GetStartupURL(), + NULL, + MSG_ROUTING_NONE, + NULL); + } +} + +void ShellBrowserMainParts::PostMainMessageLoopRun() { + if (devtools_delegate_) + devtools_delegate_->Stop(); + browser_context_.reset(); +} + +bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { + return false; +} + +ui::Clipboard* ShellBrowserMainParts::GetClipboard() { + if (!clipboard_.get()) + clipboard_.reset(new ui::Clipboard()); + return clipboard_.get(); +} + +} // namespace diff --git a/content/shell/shell_browser_main_parts.h b/content/shell/shell_browser_main_parts.h new file mode 100644 index 0000000..2476747 --- /dev/null +++ b/content/shell/shell_browser_main_parts.h @@ -0,0 +1,60 @@ +// Copyright (c) 2012 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 CONTENT_SHELL_SHELL_BROWSER_MAIN_PARTS_H_ +#define CONTENT_SHELL_SHELL_BROWSER_MAIN_PARTS_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/browser/browser_main_parts.h" + +namespace base { +class Thread; +} + +namespace ui { +class Clipboard; +} + +namespace content { + +class ShellBrowserContext; +class ShellDevToolsDelegate; +struct MainFunctionParams; + +class ShellBrowserMainParts : public BrowserMainParts { + public: + explicit ShellBrowserMainParts(const content::MainFunctionParams& parameters); + virtual ~ShellBrowserMainParts(); + + virtual void PreEarlyInitialization() OVERRIDE {} + virtual void PostEarlyInitialization() OVERRIDE {} + virtual void PreMainMessageLoopStart() OVERRIDE; + virtual MessageLoop* GetMainMessageLoop() OVERRIDE; + virtual void PostMainMessageLoopStart() OVERRIDE {} + virtual void ToolkitInitialized() OVERRIDE {} + virtual int PreCreateThreads() OVERRIDE; + virtual void PreMainMessageLoopRun() OVERRIDE; + virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; + virtual void PostMainMessageLoopRun() OVERRIDE; + virtual void PostDestroyThreads() OVERRIDE {} + + ui::Clipboard* GetClipboard(); + ShellDevToolsDelegate* devtools_delegate() { return devtools_delegate_; } + + ShellBrowserContext* browser_context() { return browser_context_.get(); } + + private: + scoped_ptr<ShellBrowserContext> browser_context_; + + scoped_ptr<ui::Clipboard> clipboard_; + ShellDevToolsDelegate* devtools_delegate_; + + DISALLOW_COPY_AND_ASSIGN(ShellBrowserMainParts); +}; + +} // namespace content + +#endif // CONTENT_SHELL_SHELL_BROWSER_MAIN_PARTS_H_ diff --git a/content/shell/shell_browser_main_mac.mm b/content/shell/shell_browser_main_parts_mac.mm index 5b8eacc..1aeac32 100644 --- a/content/shell/shell_browser_main_mac.mm +++ b/content/shell/shell_browser_main_parts_mac.mm @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/shell/shell_browser_main.h" +#include "content/shell/shell_browser_main_parts.h" #import <Cocoa/Cocoa.h> diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index 1991fbd..cdc5d3e 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -7,7 +7,7 @@ #include "base/command_line.h" #include "base/file_path.h" #include "content/shell/shell.h" -#include "content/shell/shell_browser_main.h" +#include "content/shell/shell_browser_main_parts.h" #include "content/shell/shell_devtools_delegate.h" #include "content/shell/shell_render_view_host_observer.h" #include "content/shell/shell_switches.h" @@ -351,4 +351,8 @@ crypto::CryptoModuleBlockingPasswordDelegate* } #endif +ShellBrowserContext* ShellContentBrowserClient::browser_context() { + return shell_browser_main_parts_->browser_context(); +} + } // namespace content diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index a7322ab..03b389d 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -14,6 +14,7 @@ namespace content { +class ShellBrowserContext; class ShellBrowserMainParts; class ShellContentBrowserClient : public ContentBrowserClient { @@ -183,6 +184,8 @@ class ShellContentBrowserClient : public ContentBrowserClient { const GURL& url) OVERRIDE; #endif + ShellBrowserContext* browser_context(); + private: ShellBrowserMainParts* shell_browser_main_parts_; }; diff --git a/content/shell/shell_main_delegate.cc b/content/shell/shell_main_delegate.cc index 91a92d1..05db0d3 100644 --- a/content/shell/shell_main_delegate.cc +++ b/content/shell/shell_main_delegate.cc @@ -9,6 +9,7 @@ #include "base/path_service.h" #include "content/public/common/content_paths.h" #include "content/public/common/content_switches.h" +#include "content/shell/shell_browser_main.h" #include "content/shell/shell_content_browser_client.h" #include "content/shell/shell_content_plugin_client.h" #include "content/shell/shell_content_renderer_client.h" @@ -84,7 +85,10 @@ void ShellMainDelegate::SandboxInitialized(const std::string& process_type) { int ShellMainDelegate::RunProcess( const std::string& process_type, const content::MainFunctionParams& main_function_params) { - return -1; + if (process_type != "") + return -1; + + return ShellBrowserMain(main_function_params); } void ShellMainDelegate::ProcessExiting(const std::string& process_type) { |