NaCl: Increase validation cache size.
[chromium-blink-merge.git] / components / html_viewer / setup.cc
blob74a53b8781d905b16c6df8e908ff73874ae8a5de
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.
5 #include "components/html_viewer/setup.h"
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/i18n/icu_util.h"
10 #include "base/logging.h"
11 #include "components/html_viewer/blink_platform_impl.h"
12 #include "components/html_viewer/web_media_player_factory.h"
13 #include "components/scheduler/renderer/renderer_scheduler.h"
14 #include "gin/v8_initializer.h"
15 #include "mojo/application/public/cpp/application_impl.h"
16 #include "third_party/WebKit/public/web/WebKit.h"
17 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/base/ui_base_paths.h"
21 #if defined(OS_ANDROID)
22 #include "components/html_viewer/ui_setup_android.h"
23 #else
24 #include "components/html_viewer/ui_setup.h"
25 #endif
27 namespace html_viewer {
29 namespace {
31 // Enable MediaRenderer in media pipeline instead of using the internal
32 // media::Renderer implementation.
33 const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer";
35 // Disables support for (unprefixed) Encrypted Media Extensions.
36 const char kDisableEncryptedMedia[] = "disable-encrypted-media";
38 // Prevents creation of any output surface.
39 const char kIsHeadless[] = "is-headless";
41 size_t kDesiredMaxMemory = 20 * 1024 * 1024;
43 // Paths resources are loaded from.
44 const char kResourceIcudtl[] = "icudtl.dat";
45 const char kResourceResourcesPak[] = "html_viewer_resources.pak";
46 const char kResourceUIPak[] = "ui_test.pak";
47 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
48 const char kResourceNativesBlob[] = "natives_blob.bin";
49 const char kResourceSnapshotBlob[] = "snapshot_blob.bin";
50 #endif
52 std::set<std::string> GetResourcePaths() {
53 std::set<std::string> paths;
54 paths.insert(kResourceResourcesPak);
55 paths.insert(kResourceIcudtl);
56 paths.insert(kResourceUIPak);
57 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
58 paths.insert(kResourceNativesBlob);
59 paths.insert(kResourceSnapshotBlob);
60 #endif
61 return paths;
64 } // namespace
66 Setup::Setup(mojo::ApplicationImpl* app)
67 : app_(app),
68 resource_loader_(app->shell(), GetResourcePaths()),
69 is_headless_(
70 base::CommandLine::ForCurrentProcess()->HasSwitch(kIsHeadless)),
71 did_init_(false),
72 device_pixel_ratio_(1.f),
73 discardable_memory_allocator_(kDesiredMaxMemory),
74 compositor_thread_("compositor thread") {
75 if (is_headless_)
76 InitHeadless();
79 Setup::~Setup() {
82 void Setup::InitHeadless() {
83 DCHECK(!did_init_);
84 is_headless_ = true;
85 InitIfNecessary(gfx::Size(1024, 1024), 1.f);
88 void Setup::InitIfNecessary(const gfx::Size& screen_size_in_pixels,
89 float device_pixel_ratio) {
90 if (did_init_)
91 return;
93 DCHECK_NE(0.f, device_pixel_ratio);
95 did_init_ = true;
96 device_pixel_ratio_ = device_pixel_ratio;
97 screen_size_in_pixels_ = screen_size_in_pixels;
99 if (!resource_loader_.BlockUntilLoaded()) {
100 // Assume on error we're being shut down.
101 app_->Terminate();
102 return;
105 ui_setup_.reset(new UISetup(screen_size_in_pixels, device_pixel_ratio));
106 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_);
108 renderer_scheduler_ = scheduler::RendererScheduler::Create();
109 blink_platform_.reset(new BlinkPlatformImpl(app_, renderer_scheduler_.get()));
110 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
111 CHECK(gin::V8Initializer::LoadV8SnapshotFromFD(
112 resource_loader_.ReleaseFile(kResourceNativesBlob).TakePlatformFile(), 0u,
114 resource_loader_.ReleaseFile(kResourceSnapshotBlob).TakePlatformFile(),
115 0u, 0u));
116 #endif
117 blink::initialize(blink_platform_.get());
118 base::i18n::InitializeICUWithFileDescriptor(
119 resource_loader_.ReleaseFile(kResourceIcudtl).TakePlatformFile(),
120 base::MemoryMappedFile::Region::kWholeFile);
122 ui::RegisterPathProvider();
124 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
126 logging::LoggingSettings settings;
127 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
128 logging::InitLogging(settings);
129 // Display process ID, thread ID and timestamp in logs.
130 logging::SetLogItems(true, true, true, false);
132 if (command_line->HasSwitch(kDisableEncryptedMedia))
133 blink::WebRuntimeFeatures::enableEncryptedMedia(false);
135 if (!is_headless_) {
136 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
137 resource_loader_.ReleaseFile(kResourceResourcesPak),
138 base::MemoryMappedFile::Region::kWholeFile);
139 // TODO(sky): why is this always using 100?
140 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
141 resource_loader_.ReleaseFile(kResourceUIPak), ui::SCALE_FACTOR_100P);
144 compositor_thread_.Start();
145 #if defined(OS_ANDROID)
146 // TODO(sky): Get WebMediaPlayerFactory working on android.
147 NOTIMPLEMENTED();
148 #else
149 bool enable_mojo_media_renderer =
150 command_line->HasSwitch(kEnableMojoMediaRenderer);
152 web_media_player_factory_.reset(new WebMediaPlayerFactory(
153 compositor_thread_.message_loop_proxy(), enable_mojo_media_renderer));
154 #endif
157 } // namespace html_viewer