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

Side by Side Diff: headless/lib/headless_content_main_delegate.cc

Issue 1969313005: [headless] Embed pak file into binary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated years in copyright Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « headless/lib/embed_data.py ('k') | headless/lib/util/embedded_file.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "headless/lib/headless_content_main_delegate.h" 5 #include "headless/lib/headless_content_main_delegate.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "content/public/browser/browser_main_runner.h" 13 #include "content/public/browser/browser_main_runner.h"
14 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
15 #include "headless/lib/browser/headless_browser_impl.h" 15 #include "headless/lib/browser/headless_browser_impl.h"
16 #include "headless/lib/browser/headless_content_browser_client.h" 16 #include "headless/lib/browser/headless_content_browser_client.h"
17 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/base/ui_base_switches.h" 18 #include "ui/base/ui_base_switches.h"
19 #include "ui/gfx/switches.h" 19 #include "ui/gfx/switches.h"
20 #include "ui/gl/gl_switches.h" 20 #include "ui/gl/gl_switches.h"
21 #include "ui/ozone/public/ozone_switches.h" 21 #include "ui/ozone/public/ozone_switches.h"
22 22
23 #ifdef HEADLESS_USE_EMBEDDED_RESOURCES
24 #include "headless/embedded_resource_pak.h"
25 #endif
26
23 namespace headless { 27 namespace headless {
24 namespace { 28 namespace {
25 // Keep in sync with content/common/content_constants_internal.h. 29 // Keep in sync with content/common/content_constants_internal.h.
26 // TODO(skyostil): Add a tracing test for this. 30 // TODO(skyostil): Add a tracing test for this.
27 const int kTraceEventBrowserProcessSortIndex = -6; 31 const int kTraceEventBrowserProcessSortIndex = -6;
28 32
29 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; 33 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr;
30 } // namespace 34 } // namespace
31 35
32 HeadlessContentMainDelegate::HeadlessContentMainDelegate( 36 HeadlessContentMainDelegate::HeadlessContentMainDelegate(
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 base::FilePath dir_module; 174 base::FilePath dir_module;
171 base::FilePath pak_file; 175 base::FilePath pak_file;
172 bool result = PathService::Get(base::DIR_MODULE, &dir_module); 176 bool result = PathService::Get(base::DIR_MODULE, &dir_module);
173 DCHECK(result); 177 DCHECK(result);
174 178
175 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 179 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
176 const std::string locale = command_line->GetSwitchValueASCII(switches::kLang); 180 const std::string locale = command_line->GetSwitchValueASCII(switches::kLang);
177 ui::ResourceBundle::InitSharedInstanceWithLocale( 181 ui::ResourceBundle::InitSharedInstanceWithLocale(
178 locale, nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); 182 locale, nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
179 183
184 #ifdef HEADLESS_USE_EMBEDDED_RESOURCES
185 ResourceBundle::GetSharedInstance().AddDataPackFromBuffer(
186 base::StringPiece(
187 reinterpret_cast<const char*>(kHeadlessResourcePak.contents),
188 kHeadlessResourcePak.length),
189 ui::SCALE_FACTOR_NONE);
190 #else
180 // Try loading the headless library pak file first. If it doesn't exist (i.e., 191 // Try loading the headless library pak file first. If it doesn't exist (i.e.,
181 // when we're running with the --headless switch), fall back to the browser's 192 // when we're running with the --headless switch), fall back to the browser's
182 // resource pak. 193 // resource pak.
183 pak_file = dir_module.Append(FILE_PATH_LITERAL("headless_lib.pak")); 194 pak_file = dir_module.Append(FILE_PATH_LITERAL("headless_lib.pak"));
184 if (!base::PathExists(pak_file)) 195 if (!base::PathExists(pak_file))
185 pak_file = dir_module.Append(FILE_PATH_LITERAL("resources.pak")); 196 pak_file = dir_module.Append(FILE_PATH_LITERAL("resources.pak"));
186 ResourceBundle::GetSharedInstance().AddDataPackFromPath( 197 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
187 pak_file, ui::SCALE_FACTOR_NONE); 198 pak_file, ui::SCALE_FACTOR_NONE);
199 #endif
188 } 200 }
189 201
190 content::ContentBrowserClient* 202 content::ContentBrowserClient*
191 HeadlessContentMainDelegate::CreateContentBrowserClient() { 203 HeadlessContentMainDelegate::CreateContentBrowserClient() {
192 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); 204 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get()));
193 return browser_client_.get(); 205 return browser_client_.get();
194 } 206 }
195 207
196 } // namespace headless 208 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/embed_data.py ('k') | headless/lib/util/embedded_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698