OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "headless/lib/headless_main_delegate.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/logging.h" | |
9 #include "base/path_service.h" | |
10 #include "base/trace_event/trace_event.h" | |
11 #include "content/public/browser/browser_main_runner.h" | |
12 #include "content/public/browser/content_browser_client.h" | |
13 #include "content/public/common/content_client.h" | |
14 #include "content/public/common/content_switches.h" | |
15 #include "content/public/renderer/content_renderer_client.h" | |
16 #include "content/public/utility/content_utility_client.h" | |
17 #include "ui/base/resource/resource_bundle.h" | |
18 | |
19 namespace { | |
20 | |
21 void InitLogging() { | |
22 base::FilePath log_filename; | |
23 PathService::Get(base::DIR_EXE, &log_filename); | |
24 log_filename = log_filename.AppendASCII("headless_test_shell.log"); | |
25 logging::LoggingSettings settings; | |
26 settings.logging_dest = logging::LOG_TO_ALL; | |
27 settings.log_file = log_filename.value().c_str(); | |
28 settings.delete_old = logging::DELETE_OLD_LOG_FILE; | |
29 logging::InitLogging(settings); | |
30 logging::SetLogItems(true, true, true, true); | |
31 } | |
32 | |
33 } // namespace | |
34 | |
35 namespace headless { | |
36 | |
37 class HeadlessContentClient : public content::ContentClient {}; | |
38 | |
39 class HeadlessContentBrowserClient : public content::ContentBrowserClient {}; | |
40 | |
41 class HeadlessContentRendererClient : public content::ContentRendererClient {}; | |
42 | |
43 class HeadlessContentUtilityClient : public content::ContentUtilityClient {}; | |
44 | |
45 HeadlessMainDelegate::HeadlessMainDelegate() {} | |
46 | |
47 HeadlessMainDelegate::~HeadlessMainDelegate() {} | |
48 | |
49 bool HeadlessMainDelegate::BasicStartupComplete(int* exit_code) { | |
50 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); | |
51 | |
52 InitLogging(); | |
53 | |
54 command_line.AppendSwitch(switches::kNoSandbox); | |
55 command_line.AppendSwitch(switches::kSingleProcess); | |
56 | |
57 // TODO(skyostil): Investigate using Mesa/SwiftShader for output. | |
58 command_line.AppendSwitch(switches::kDisableGpu); | |
59 | |
60 content_client_.reset(new HeadlessContentClient); | |
61 SetContentClient(content_client_.get()); | |
62 | |
63 return false; | |
64 } | |
65 | |
66 void HeadlessMainDelegate::PreSandboxStartup() { | |
67 InitializeResourceBundle(); | |
68 } | |
69 | |
70 int HeadlessMainDelegate::RunProcess( | |
71 const std::string& process_type, | |
72 const content::MainFunctionParams& main_function_params) { | |
73 if (!process_type.empty()) | |
74 return -1; | |
75 | |
76 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser"); | |
77 | |
78 scoped_ptr<content::BrowserMainRunner> browser_runner( | |
79 content::BrowserMainRunner::Create()); | |
80 int exit_code = browser_runner->Initialize(main_function_params); | |
81 DCHECK_LT(exit_code, 0); | |
82 exit_code = browser_runner->Run(); | |
83 browser_runner->Shutdown(); | |
84 return exit_code; | |
85 } | |
86 | |
87 void HeadlessMainDelegate::ZygoteForked() { | |
88 // TODO(skyostil): Disable the zygote host. | |
89 } | |
90 | |
91 // static | |
92 void HeadlessMainDelegate::InitializeResourceBundle() { | |
93 base::FilePath pak_file; | |
94 bool r = PathService::Get(base::DIR_MODULE, &pak_file); | |
Peter Beverloo
2015/10/27 14:35:51
nit: const bool success?
| |
95 DCHECK(r); | |
96 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak")); | |
Peter Beverloo
2015/10/27 14:35:51
headless.pak
| |
97 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | |
98 } | |
99 | |
100 content::ContentBrowserClient* | |
101 HeadlessMainDelegate::CreateContentBrowserClient() { | |
102 browser_client_.reset(new HeadlessContentBrowserClient); | |
103 return browser_client_.get(); | |
104 } | |
105 | |
106 content::ContentRendererClient* | |
107 HeadlessMainDelegate::CreateContentRendererClient() { | |
108 renderer_client_.reset(new HeadlessContentRendererClient); | |
109 return renderer_client_.get(); | |
110 } | |
111 | |
112 content::ContentUtilityClient* | |
113 HeadlessMainDelegate::CreateContentUtilityClient() { | |
114 utility_client_.reset(new HeadlessContentUtilityClient); | |
115 return utility_client_.get(); | |
116 } | |
117 | |
118 } // namespace headless | |
OLD | NEW |