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

Side by Side Diff: components/html_viewer/html_viewer.cc

Issue 1130763004: Gets mandoline working on android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: get windows working Created 5 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/i18n/icu_util.h" 6 #include "base/i18n/icu_util.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
13 #include "components/html_viewer/blink_platform_impl.h" 13 #include "components/html_viewer/blink_platform_impl.h"
14 #include "components/html_viewer/discardable_memory_allocator.h" 14 #include "components/html_viewer/discardable_memory_allocator.h"
15 #include "components/html_viewer/html_document.h" 15 #include "components/html_viewer/html_document.h"
16 #include "components/html_viewer/web_media_player_factory.h" 16 #include "components/html_viewer/web_media_player_factory.h"
17 #include "components/resource_provider/public/cpp/resource_loader.h"
18 #include "components/resource_provider/public/interfaces/resource_provider.mojom .h"
17 #include "components/scheduler/renderer/renderer_scheduler.h" 19 #include "components/scheduler/renderer/renderer_scheduler.h"
18 #include "gin/v8_initializer.h" 20 #include "gin/v8_initializer.h"
19 #include "mojo/application/application_runner_chromium.h" 21 #include "mojo/application/application_runner_chromium.h"
22 #include "mojo/common/common_type_converters.h"
23 #include "mojo/platform_handle/platform_handle_functions.h"
20 #include "mojo/services/network/public/interfaces/network_service.mojom.h" 24 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
21 #include "third_party/WebKit/public/web/WebKit.h" 25 #include "third_party/WebKit/public/web/WebKit.h"
22 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 26 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
23 #include "third_party/mojo/src/mojo/public/c/system/main.h" 27 #include "third_party/mojo/src/mojo/public/c/system/main.h"
24 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio n.h" 28 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio n.h"
25 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate. h" 29 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate. h"
26 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" 30 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h"
27 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h" 31 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h"
28 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory_imp l.h" 32 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory_imp l.h"
29 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" 33 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
(...skipping 11 matching lines...) Expand all
41 using mojo::Array; 45 using mojo::Array;
42 using mojo::BindToRequest; 46 using mojo::BindToRequest;
43 using mojo::ContentHandler; 47 using mojo::ContentHandler;
44 using mojo::InterfaceRequest; 48 using mojo::InterfaceRequest;
45 using mojo::ServiceProvider; 49 using mojo::ServiceProvider;
46 using mojo::ServiceProviderPtr; 50 using mojo::ServiceProviderPtr;
47 using mojo::ShellPtr; 51 using mojo::ShellPtr;
48 using mojo::String; 52 using mojo::String;
49 using mojo::URLLoaderPtr; 53 using mojo::URLLoaderPtr;
50 using mojo::URLResponsePtr; 54 using mojo::URLResponsePtr;
55 using resource_provider::ResourceLoader;
51 56
52 namespace html_viewer { 57 namespace html_viewer {
53 58
54 // Switches for html_viewer. 59 // Switches for html_viewer.
55 60
56 // Enable MediaRenderer in media pipeline instead of using the internal 61 // Enable MediaRenderer in media pipeline instead of using the internal
57 // media::Renderer implementation. 62 // media::Renderer implementation.
58 const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer"; 63 const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer";
59 64
60 // Disables support for (unprefixed) Encrypted Media Extensions. 65 // Disables support for (unprefixed) Encrypted Media Extensions.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 bool is_headless_; 167 bool is_headless_;
163 168
164 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); 169 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl);
165 }; 170 };
166 171
167 class HTMLViewer : public mojo::ApplicationDelegate, 172 class HTMLViewer : public mojo::ApplicationDelegate,
168 public mojo::InterfaceFactory<ContentHandler> { 173 public mojo::InterfaceFactory<ContentHandler> {
169 public: 174 public:
170 HTMLViewer() 175 HTMLViewer()
171 : discardable_memory_allocator_(kDesiredMaxMemory), 176 : discardable_memory_allocator_(kDesiredMaxMemory),
172 compositor_thread_("compositor thread") {} 177 compositor_thread_("compositor thread"),
178 is_headless_(false) {}
173 179
174 ~HTMLViewer() override { blink::shutdown(); } 180 ~HTMLViewer() override { blink::shutdown(); }
175 181
176 private: 182 private:
177 // Overridden from ApplicationDelegate: 183 // Overridden from ApplicationDelegate:
178 void Initialize(mojo::ApplicationImpl* app) override { 184 void Initialize(mojo::ApplicationImpl* app) override {
185 // TODO(sky): make this typesafe and not leak.
186 std::set<std::string> paths;
187 paths.insert("icudtl.dat");
188 paths.insert("ui_test.pak");
189 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
190 paths.insert("natives_blob.bin");
Jay Civelli 2015/05/11 21:07:33 Should we use constants for these strings since th
sky 2015/05/11 21:13:35 Definitely. I'm hoping to do this later (see todo
191 paths.insert("snapshot_blob.bin");
192 #endif
193 ResourceLoader resource_loader(app->shell(), paths);
194 if (!resource_loader.BlockUntilLoaded()) {
195 // Assume on error we're being shut down.
196 LOG(WARNING) << "html_viewer errored getting resources, exiting";
197 mojo::ApplicationImpl::Terminate();
198 return;
199 }
200
201 ResourceLoader::ResourceMap resource_map(resource_loader.resource_map());
202
179 ui_setup_.reset(new UISetup); 203 ui_setup_.reset(new UISetup);
180 base::DiscardableMemoryAllocator::SetInstance( 204 base::DiscardableMemoryAllocator::SetInstance(
181 &discardable_memory_allocator_); 205 &discardable_memory_allocator_);
182 206
183 renderer_scheduler_ = scheduler::RendererScheduler::Create(); 207 renderer_scheduler_ = scheduler::RendererScheduler::Create();
184 blink_platform_.reset( 208 blink_platform_.reset(
185 new BlinkPlatformImpl(app, renderer_scheduler_.get())); 209 new BlinkPlatformImpl(app, renderer_scheduler_.get()));
186 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) 210 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
187 // Note: this requires file system access. 211 // Note: this requires file system access.
188 gin::V8Initializer::LoadV8Snapshot(); 212 CHECK(gin::V8Initializer::LoadV8SnapshotFromFD(
213 resource_map["natives_blob.bin"], 0u, 0u,
214 resource_map["snapshot_blob.bin"], 0u, 0u));
189 #endif 215 #endif
190 blink::initialize(blink_platform_.get()); 216 blink::initialize(blink_platform_.get());
191 base::i18n::InitializeICU(); 217 base::i18n::InitializeICUWithFileDescriptor(
218 resource_map["icudtl.dat"], base::MemoryMappedFile::Region::kWholeFile);
192 219
193 ui::RegisterPathProvider(); 220 ui::RegisterPathProvider();
194 221
195 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 222 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
196 223
197 logging::LoggingSettings settings; 224 logging::LoggingSettings settings;
198 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 225 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
199 logging::InitLogging(settings); 226 logging::InitLogging(settings);
200 // Display process ID, thread ID and timestamp in logs. 227 // Display process ID, thread ID and timestamp in logs.
201 logging::SetLogItems(true, true, true, false); 228 logging::SetLogItems(true, true, true, false);
202 229
203 if (command_line->HasSwitch(kDisableEncryptedMedia)) 230 if (command_line->HasSwitch(kDisableEncryptedMedia))
204 blink::WebRuntimeFeatures::enableEncryptedMedia(false); 231 blink::WebRuntimeFeatures::enableEncryptedMedia(false);
205 232
206 is_headless_ = command_line->HasSwitch(kIsHeadless); 233 is_headless_ = command_line->HasSwitch(kIsHeadless);
207 if (!is_headless_) { 234 if (!is_headless_) {
208 // TODO(sky): consider putting this into the .so so that we don't need 235 // TODO(sky): fix lifetime here.
209 // file system access. 236 MojoPlatformHandle platform_handle = resource_map["ui_test.pak"];
210 base::FilePath ui_test_pak_path; 237 // TODO(sky): the first call should be for strings, not images.
211 CHECK(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); 238 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
212 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); 239 base::File(platform_handle).Pass(),
240 base::MemoryMappedFile::Region::kWholeFile);
241 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
242 base::File(platform_handle).Pass(), ui::SCALE_FACTOR_100P);
213 } 243 }
214 244
215 compositor_thread_.Start(); 245 compositor_thread_.Start();
216 #if defined(OS_ANDROID) 246 #if defined(OS_ANDROID)
217 // TODO(sky): Get WebMediaPlayerFactory working on android. 247 // TODO(sky): Get WebMediaPlayerFactory working on android.
218 NOTIMPLEMENTED(); 248 NOTIMPLEMENTED();
219 #else 249 #else
220 bool enable_mojo_media_renderer = 250 bool enable_mojo_media_renderer =
221 command_line->HasSwitch(kEnableMojoMediaRenderer); 251 command_line->HasSwitch(kEnableMojoMediaRenderer);
222 252
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 288
259 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); 289 DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
260 }; 290 };
261 291
262 } // namespace html_viewer 292 } // namespace html_viewer
263 293
264 MojoResult MojoMain(MojoHandle shell_handle) { 294 MojoResult MojoMain(MojoHandle shell_handle) {
265 mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer); 295 mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer);
266 return runner.Run(shell_handle); 296 return runner.Run(shell_handle);
267 } 297 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698