OLD | NEW |
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/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "content/public/browser/browser_main_runner.h" | 12 #include "content/public/browser/browser_main_runner.h" |
13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
14 #include "headless/lib/browser/headless_browser_impl.h" | 14 #include "headless/lib/browser/headless_browser_impl.h" |
15 #include "headless/lib/browser/headless_content_browser_client.h" | 15 #include "headless/lib/browser/headless_content_browser_client.h" |
16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/base/ui_base_switches.h" |
17 #include "ui/gfx/switches.h" | 18 #include "ui/gfx/switches.h" |
18 #include "ui/gl/gl_switches.h" | 19 #include "ui/gl/gl_switches.h" |
19 #include "ui/ozone/public/ozone_switches.h" | 20 #include "ui/ozone/public/ozone_switches.h" |
20 | 21 |
21 namespace headless { | 22 namespace headless { |
22 namespace { | 23 namespace { |
23 // Keep in sync with content/common/content_constants_internal.h. | 24 // Keep in sync with content/common/content_constants_internal.h. |
24 // TODO(skyostil): Add a tracing test for this. | 25 // TODO(skyostil): Add a tracing test for this. |
25 const int kTraceEventBrowserProcessSortIndex = -6; | 26 const int kTraceEventBrowserProcessSortIndex = -6; |
26 | 27 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 HeadlessContentMainDelegate* HeadlessContentMainDelegate::GetInstance() { | 108 HeadlessContentMainDelegate* HeadlessContentMainDelegate::GetInstance() { |
108 return g_current_headless_content_main_delegate; | 109 return g_current_headless_content_main_delegate; |
109 } | 110 } |
110 | 111 |
111 // static | 112 // static |
112 void HeadlessContentMainDelegate::InitializeResourceBundle() { | 113 void HeadlessContentMainDelegate::InitializeResourceBundle() { |
113 base::FilePath dir_module; | 114 base::FilePath dir_module; |
114 base::FilePath pak_file; | 115 base::FilePath pak_file; |
115 bool result = PathService::Get(base::DIR_MODULE, &dir_module); | 116 bool result = PathService::Get(base::DIR_MODULE, &dir_module); |
116 DCHECK(result); | 117 DCHECK(result); |
| 118 |
| 119 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 120 const std::string locale = command_line->GetSwitchValueASCII(switches::kLang); |
| 121 ui::ResourceBundle::InitSharedInstanceWithLocale( |
| 122 locale, nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); |
| 123 |
117 // Try loading the headless library pak file first. If it doesn't exist (i.e., | 124 // Try loading the headless library pak file first. If it doesn't exist (i.e., |
118 // when we're running with the --headless switch), fall back to the browser's | 125 // when we're running with the --headless switch), fall back to the browser's |
119 // resource pak. | 126 // resource pak. |
120 pak_file = dir_module.Append(FILE_PATH_LITERAL("headless_lib.pak")); | 127 pak_file = dir_module.Append(FILE_PATH_LITERAL("headless_lib.pak")); |
121 if (!base::PathExists(pak_file)) | 128 if (!base::PathExists(pak_file)) |
122 pak_file = dir_module.Append(FILE_PATH_LITERAL("resources.pak")); | 129 pak_file = dir_module.Append(FILE_PATH_LITERAL("resources.pak")); |
123 // TODO(skyostil): Use the locale-based loader instead. | 130 ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
124 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | 131 pak_file, ui::SCALE_FACTOR_NONE); |
125 } | 132 } |
126 | 133 |
127 content::ContentBrowserClient* | 134 content::ContentBrowserClient* |
128 HeadlessContentMainDelegate::CreateContentBrowserClient() { | 135 HeadlessContentMainDelegate::CreateContentBrowserClient() { |
129 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); | 136 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); |
130 return browser_client_.get(); | 137 return browser_client_.get(); |
131 } | 138 } |
132 | 139 |
133 } // namespace headless | 140 } // namespace headless |
OLD | NEW |