Index: headless/lib/headless_shell_main_delegate.cc |
diff --git a/headless/lib/headless_shell_main_delegate.cc b/headless/lib/headless_shell_main_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..437dfa792344fe16beeebbe6dd48f3f73f79cbc0 |
--- /dev/null |
+++ b/headless/lib/headless_shell_main_delegate.cc |
@@ -0,0 +1,125 @@ |
+// Copyright 2015 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 "headless/lib/headless_shell_main_delegate.h" |
+ |
+#include "headless/lib/browser/headless_content_browser_client.h" |
+#include "headless/lib/renderer/headless_content_renderer_client.h" |
+#include "headless/lib/utility/headless_content_utility_client.h" |
+ |
+#include "base/command_line.h" |
+#include "base/logging.h" |
+#include "base/path_service.h" |
+#include "base/run_loop.h" |
+#include "base/trace_event/trace_event.h" |
+#include "content/common/content_constants_internal.h" |
+#include "content/public/browser/browser_main_runner.h" |
+#include "content/public/common/content_switches.h" |
+#include "ui/base/resource/resource_bundle.h" |
+#include "ui/ozone/public/ozone_switches.h" |
+#include "headless/lib/headless_browser_impl.h" |
+ |
+namespace { |
+ |
+void InitLogging() { |
+ base::FilePath log_filename; |
+ PathService::Get(base::DIR_EXE, &log_filename); |
+ log_filename = log_filename.AppendASCII("headless_test_shell.log"); |
+ logging::LoggingSettings settings; |
+ settings.logging_dest = logging::LOG_TO_ALL; |
+ settings.log_file = log_filename.value().c_str(); |
+ settings.delete_old = logging::DELETE_OLD_LOG_FILE; |
+ logging::InitLogging(settings); |
+ logging::SetLogItems(true, true, true, true); |
+} |
+ |
+} // namespace |
+ |
+namespace headless { |
+ |
+HeadlessShellMainDelegate::HeadlessShellMainDelegate( |
+ HeadlessBrowserImpl* browser) |
+ : browser_(browser) { } |
+ |
+HeadlessShellMainDelegate::~HeadlessShellMainDelegate() { } |
+ |
+bool HeadlessShellMainDelegate::BasicStartupComplete(int* exit_code) { |
+ base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); |
+ |
+ InitLogging(); |
+ |
+ command_line.AppendSwitch(switches::kNoSandbox); |
+ command_line.AppendSwitch(switches::kSingleProcess); |
+ |
+ // TODO(skyostil): Investigate using Mesa/SwiftShader for output. |
+ command_line.AppendSwitch(switches::kDisableGpu); |
+ |
+ SetContentClient(&content_client_); |
+ return false; |
+} |
+ |
+void HeadlessShellMainDelegate::PreSandboxStartup() { |
+ InitializeResourceBundle(); |
+} |
+ |
+int HeadlessShellMainDelegate::RunProcess( |
+ const std::string& process_type, |
+ const content::MainFunctionParams& main_function_params) { |
+ if (!process_type.empty()) |
+ return -1; |
+ |
+ base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser"); |
+ base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex( |
+ content::kTraceEventBrowserProcessSortIndex); |
+ |
+ scoped_ptr<content::BrowserMainRunner> browser_runner_( |
+ content::BrowserMainRunner::Create()); |
+ |
+ int exit_code = browser_runner_->Initialize(main_function_params); |
+ |
+ DCHECK_LT(exit_code, 0) << "content::BrowserMainRunner::Initialize failed in " |
+ "HeadlessShellMainDelegate::RunProcess"; |
+ |
+ browser_->RunOnStartCallback(); |
+ |
+ browser_runner_->Run(); |
+ |
+ browser_runner_->Shutdown(); |
+ |
+ // Return value >=0 here to disable calling content::BrowserMain. |
+ return 0; |
+} |
+ |
+void HeadlessShellMainDelegate::ZygoteForked() { |
+ // TODO(skyostil): Disable the zygote host. |
+} |
+ |
+// static |
+void HeadlessShellMainDelegate::InitializeResourceBundle() { |
+ base::FilePath pak_file; |
+ bool r = PathService::Get(base::DIR_MODULE, &pak_file); |
+ DCHECK(r); |
+ pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak")); |
+ ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); |
+} |
+ |
+content::ContentBrowserClient* |
+HeadlessShellMainDelegate::CreateContentBrowserClient() { |
+ browser_client_.reset(new HeadlessContentBrowserClient(browser_)); |
+ return browser_client_.get(); |
+} |
+ |
+content::ContentRendererClient* |
+HeadlessShellMainDelegate::CreateContentRendererClient() { |
+ renderer_client_.reset(new HeadlessContentRendererClient); |
+ return renderer_client_.get(); |
+} |
+ |
+content::ContentUtilityClient* |
+HeadlessShellMainDelegate::CreateContentUtilityClient() { |
+ utility_client_.reset(new HeadlessContentUtilityClient); |
+ return utility_client_.get(); |
+} |
+ |
+} // namespace headless |