| OLD | NEW |
| 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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 using mojo::InterfaceRequest; | 48 using mojo::InterfaceRequest; |
| 49 using mojo::ServiceProvider; | 49 using mojo::ServiceProvider; |
| 50 using mojo::ServiceProviderPtr; | 50 using mojo::ServiceProviderPtr; |
| 51 using mojo::ShellPtr; | 51 using mojo::ShellPtr; |
| 52 using mojo::String; | 52 using mojo::String; |
| 53 using mojo::URLLoaderPtr; | 53 using mojo::URLLoaderPtr; |
| 54 using mojo::URLResponsePtr; | 54 using mojo::URLResponsePtr; |
| 55 using resource_provider::ResourceLoader; | 55 using resource_provider::ResourceLoader; |
| 56 | 56 |
| 57 namespace html_viewer { | 57 namespace html_viewer { |
| 58 | 58 namespace { |
| 59 // Switches for html_viewer. | 59 // Switches for html_viewer. |
| 60 | 60 |
| 61 // Enable MediaRenderer in media pipeline instead of using the internal | 61 // Enable MediaRenderer in media pipeline instead of using the internal |
| 62 // media::Renderer implementation. | 62 // media::Renderer implementation. |
| 63 const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer"; | 63 const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer"; |
| 64 | 64 |
| 65 // Disables support for (unprefixed) Encrypted Media Extensions. | 65 // Disables support for (unprefixed) Encrypted Media Extensions. |
| 66 const char kDisableEncryptedMedia[] = "disable-encrypted-media"; | 66 const char kDisableEncryptedMedia[] = "disable-encrypted-media"; |
| 67 | 67 |
| 68 // Prevents creation of any output surface. | 68 // Prevents creation of any output surface. |
| 69 const char kIsHeadless[] = "is-headless"; | 69 const char kIsHeadless[] = "is-headless"; |
| 70 | 70 |
| 71 size_t kDesiredMaxMemory = 20 * 1024 * 1024; | 71 size_t kDesiredMaxMemory = 20 * 1024 * 1024; |
| 72 | 72 |
| 73 // Paths resources are loaded from. |
| 74 const char kResourceIcudtl[] = "icudtl.dat"; |
| 75 const char kResourceResourcesPak[] = "html_viewer_resources.pak"; |
| 76 const char kResourceUIPak[] = "ui_test.pak"; |
| 77 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 78 const char kResourceNativesBlob[] = "natives_blob.bin"; |
| 79 const char kResourceSnapshotBlob[] = "snapshot_blob.bin"; |
| 80 #endif |
| 81 |
| 82 } // namespace |
| 83 |
| 73 class HTMLViewer; | 84 class HTMLViewer; |
| 74 | 85 |
| 75 class HTMLViewerApplication : public mojo::Application { | 86 class HTMLViewerApplication : public mojo::Application { |
| 76 public: | 87 public: |
| 77 HTMLViewerApplication(InterfaceRequest<Application> request, | 88 HTMLViewerApplication(InterfaceRequest<Application> request, |
| 78 URLResponsePtr response, | 89 URLResponsePtr response, |
| 79 scoped_refptr<base::MessageLoopProxy> compositor_thread, | 90 scoped_refptr<base::MessageLoopProxy> compositor_thread, |
| 80 WebMediaPlayerFactory* web_media_player_factory, | 91 WebMediaPlayerFactory* web_media_player_factory, |
| 81 bool is_headless) | 92 bool is_headless) |
| 82 : url_(response->url), | 93 : url_(response->url), |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 HTMLViewer() | 186 HTMLViewer() |
| 176 : discardable_memory_allocator_(kDesiredMaxMemory), | 187 : discardable_memory_allocator_(kDesiredMaxMemory), |
| 177 compositor_thread_("compositor thread"), | 188 compositor_thread_("compositor thread"), |
| 178 is_headless_(false) {} | 189 is_headless_(false) {} |
| 179 | 190 |
| 180 ~HTMLViewer() override { blink::shutdown(); } | 191 ~HTMLViewer() override { blink::shutdown(); } |
| 181 | 192 |
| 182 private: | 193 private: |
| 183 // Overridden from ApplicationDelegate: | 194 // Overridden from ApplicationDelegate: |
| 184 void Initialize(mojo::ApplicationImpl* app) override { | 195 void Initialize(mojo::ApplicationImpl* app) override { |
| 185 // TODO(sky): make this typesafe and not leak. | |
| 186 std::set<std::string> paths; | 196 std::set<std::string> paths; |
| 187 paths.insert("icudtl.dat"); | 197 paths.insert(kResourceResourcesPak); |
| 188 paths.insert("ui_test.pak"); | 198 paths.insert(kResourceIcudtl); |
| 199 paths.insert(kResourceUIPak); |
| 189 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 200 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 190 paths.insert("natives_blob.bin"); | 201 paths.insert(kResourceNativesBlob); |
| 191 paths.insert("snapshot_blob.bin"); | 202 paths.insert(kResourceSnapshotBlob); |
| 192 #endif | 203 #endif |
| 193 ResourceLoader resource_loader(app->shell(), paths); | 204 ResourceLoader resource_loader(app->shell(), paths); |
| 194 if (!resource_loader.BlockUntilLoaded()) { | 205 if (!resource_loader.BlockUntilLoaded()) { |
| 195 // Assume on error we're being shut down. | 206 // Assume on error we're being shut down. |
| 196 LOG(WARNING) << "html_viewer errored getting resources, exiting"; | 207 LOG(WARNING) << "html_viewer errored getting resources, exiting"; |
| 197 mojo::ApplicationImpl::Terminate(); | 208 mojo::ApplicationImpl::Terminate(); |
| 198 return; | 209 return; |
| 199 } | 210 } |
| 200 | 211 |
| 201 ResourceLoader::ResourceMap resource_map(resource_loader.resource_map()); | |
| 202 | |
| 203 ui_setup_.reset(new UISetup); | 212 ui_setup_.reset(new UISetup); |
| 204 base::DiscardableMemoryAllocator::SetInstance( | 213 base::DiscardableMemoryAllocator::SetInstance( |
| 205 &discardable_memory_allocator_); | 214 &discardable_memory_allocator_); |
| 206 | 215 |
| 207 renderer_scheduler_ = scheduler::RendererScheduler::Create(); | 216 renderer_scheduler_ = scheduler::RendererScheduler::Create(); |
| 208 blink_platform_.reset( | 217 blink_platform_.reset( |
| 209 new BlinkPlatformImpl(app, renderer_scheduler_.get())); | 218 new BlinkPlatformImpl(app, renderer_scheduler_.get())); |
| 210 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 219 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 211 // Note: this requires file system access. | 220 // Note: this requires file system access. |
| 212 CHECK(gin::V8Initializer::LoadV8SnapshotFromFD( | 221 CHECK(gin::V8Initializer::LoadV8SnapshotFromFD( |
| 213 resource_map["natives_blob.bin"], 0u, 0u, | 222 resource_loader.ReleaseFile(kResourceNativesBlob).TakePlatformFile(), |
| 214 resource_map["snapshot_blob.bin"], 0u, 0u)); | 223 0u, 0u, |
| 224 resource_loader.ReleaseFile(kResourceSnapshotBlob).TakePlatformFile(), |
| 225 0u, 0u)); |
| 215 #endif | 226 #endif |
| 216 blink::initialize(blink_platform_.get()); | 227 blink::initialize(blink_platform_.get()); |
| 217 base::i18n::InitializeICUWithFileDescriptor( | 228 base::i18n::InitializeICUWithFileDescriptor( |
| 218 resource_map["icudtl.dat"], base::MemoryMappedFile::Region::kWholeFile); | 229 resource_loader.ReleaseFile(kResourceIcudtl).TakePlatformFile(), |
| 230 base::MemoryMappedFile::Region::kWholeFile); |
| 219 | 231 |
| 220 ui::RegisterPathProvider(); | 232 ui::RegisterPathProvider(); |
| 221 | 233 |
| 222 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 234 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 223 | 235 |
| 224 logging::LoggingSettings settings; | 236 logging::LoggingSettings settings; |
| 225 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 237 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 226 logging::InitLogging(settings); | 238 logging::InitLogging(settings); |
| 227 // Display process ID, thread ID and timestamp in logs. | 239 // Display process ID, thread ID and timestamp in logs. |
| 228 logging::SetLogItems(true, true, true, false); | 240 logging::SetLogItems(true, true, true, false); |
| 229 | 241 |
| 230 if (command_line->HasSwitch(kDisableEncryptedMedia)) | 242 if (command_line->HasSwitch(kDisableEncryptedMedia)) |
| 231 blink::WebRuntimeFeatures::enableEncryptedMedia(false); | 243 blink::WebRuntimeFeatures::enableEncryptedMedia(false); |
| 232 | 244 |
| 233 is_headless_ = command_line->HasSwitch(kIsHeadless); | 245 is_headless_ = command_line->HasSwitch(kIsHeadless); |
| 234 if (!is_headless_) { | 246 if (!is_headless_) { |
| 235 // TODO(sky): fix lifetime here. | |
| 236 MojoPlatformHandle platform_handle = resource_map["ui_test.pak"]; | |
| 237 // TODO(sky): the first call should be for strings, not images. | |
| 238 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 247 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
| 239 base::File(platform_handle).Pass(), | 248 resource_loader.ReleaseFile(kResourceResourcesPak), |
| 240 base::MemoryMappedFile::Region::kWholeFile); | 249 base::MemoryMappedFile::Region::kWholeFile); |
| 241 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 250 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( |
| 242 base::File(platform_handle).Pass(), ui::SCALE_FACTOR_100P); | 251 resource_loader.ReleaseFile(kResourceUIPak), ui::SCALE_FACTOR_100P); |
| 243 } | 252 } |
| 244 | 253 |
| 245 compositor_thread_.Start(); | 254 compositor_thread_.Start(); |
| 246 #if defined(OS_ANDROID) | 255 #if defined(OS_ANDROID) |
| 247 // TODO(sky): Get WebMediaPlayerFactory working on android. | 256 // TODO(sky): Get WebMediaPlayerFactory working on android. |
| 248 NOTIMPLEMENTED(); | 257 NOTIMPLEMENTED(); |
| 249 #else | 258 #else |
| 250 bool enable_mojo_media_renderer = | 259 bool enable_mojo_media_renderer = |
| 251 command_line->HasSwitch(kEnableMojoMediaRenderer); | 260 command_line->HasSwitch(kEnableMojoMediaRenderer); |
| 252 | 261 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 | 297 |
| 289 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); | 298 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); |
| 290 }; | 299 }; |
| 291 | 300 |
| 292 } // namespace html_viewer | 301 } // namespace html_viewer |
| 293 | 302 |
| 294 MojoResult MojoMain(MojoHandle shell_handle) { | 303 MojoResult MojoMain(MojoHandle shell_handle) { |
| 295 mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer); | 304 mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer); |
| 296 return runner.Run(shell_handle); | 305 return runner.Run(shell_handle); |
| 297 } | 306 } |
| OLD | NEW |