Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Unified Diff: headless/app/headless_shell_main_delegate.cc

Issue 1430673002: Headless demo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: headless/app/headless_shell_main_delegate.cc
diff --git a/headless/app/headless_shell_main_delegate.cc b/headless/app/headless_shell_main_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0ad1baffcadb1bb6ab1e58d845e31a04cad1770e
--- /dev/null
+++ b/headless/app/headless_shell_main_delegate.cc
@@ -0,0 +1,108 @@
+// 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/app/headless_shell_main_delegate.h"
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/path_service.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 "content/shell/browser/shell_browser_main.h"
+#include "content/shell/browser/shell_content_browser_client.h"
+#include "content/shell/renderer/shell_content_renderer_client.h"
+#include "content/shell/utility/shell_content_utility_client.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/ozone/public/ozone_switches.h"
+#include "headless/app/headless_browser_main.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 content {
+
+HeadlessShellMainDelegate::HeadlessShellMainDelegate() {}
+
+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 MainFunctionParams& main_function_params) {
+ if (!process_type.empty())
+ return -1;
+
+ base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser");
+ base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
+ kTraceEventBrowserProcessSortIndex);
+
+ scoped_ptr<BrowserMainRunner> browser_runner_(BrowserMainRunner::Create());
+ return HeadlessBrowserMain(main_function_params, browser_runner_.Pass());
+}
+
+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);
+}
+
+ContentBrowserClient*
+HeadlessShellMainDelegate::CreateContentBrowserClient() {
+ browser_client_.reset(new ShellContentBrowserClient);
+ return browser_client_.get();
+}
+
+ContentRendererClient*
+HeadlessShellMainDelegate::CreateContentRendererClient() {
+ renderer_client_.reset(new ShellContentRendererClient);
+ return renderer_client_.get();
+}
+
+ContentUtilityClient*
+HeadlessShellMainDelegate::CreateContentUtilityClient() {
+ utility_client_.reset(new ShellContentUtilityClient);
+ return utility_client_.get();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698