Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / mojo / services / html_viewer / html_viewer.cc
blob3ec9e45815ec99990dfdaea2d68edd2a2ffc716b
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
3 // found in the LICENSE file.
5 #include "base/macros.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/threading/thread.h"
8 #include "mojo/application/application_runner_chromium.h"
9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/public/cpp/application/interface_factory_impl.h"
14 #include "mojo/services/html_viewer/html_document_view.h"
15 #include "mojo/services/html_viewer/mojo_blink_platform_impl.h"
16 #include "mojo/services/html_viewer/webmediaplayer_factory.h"
17 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h"
18 #include "third_party/WebKit/public/web/WebKit.h"
20 #if !defined(COMPONENT_BUILD)
21 #include "base/i18n/icu_util.h"
22 #include "base/path_service.h"
23 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/base/ui_base_paths.h"
25 #endif
27 namespace mojo {
29 // Switches for html_viewer to be used with "--args-for". For example:
30 // --args-for='mojo:html_viewer --enable-mojo-media-renderer'
32 // Enable mojo::MediaRenderer in media pipeline instead of using the internal
33 // media::Renderer implementation.
34 const char kEnableMojoMediaRenderer[] = "--enable-mojo-media-renderer";
36 class HTMLViewer;
38 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> {
39 public:
40 ContentHandlerImpl(scoped_refptr<base::MessageLoopProxy> compositor_thread,
41 WebMediaPlayerFactory* web_media_player_factory)
42 : compositor_thread_(compositor_thread),
43 web_media_player_factory_(web_media_player_factory) {}
44 ~ContentHandlerImpl() override {}
46 private:
47 // Overridden from ContentHandler:
48 void StartApplication(ShellPtr shell, URLResponsePtr response) override {
49 new HTMLDocumentView(response.Pass(),
50 shell.Pass(),
51 compositor_thread_,
52 web_media_player_factory_);
55 scoped_refptr<base::MessageLoopProxy> compositor_thread_;
56 WebMediaPlayerFactory* web_media_player_factory_;
58 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl);
61 class HTMLViewer : public ApplicationDelegate,
62 public InterfaceFactory<ContentHandler> {
63 public:
64 HTMLViewer() : compositor_thread_("compositor thread") {}
66 ~HTMLViewer() override { blink::shutdown(); }
68 private:
69 // Overridden from ApplicationDelegate:
70 void Initialize(ApplicationImpl* app) override {
71 blink_platform_.reset(new MojoBlinkPlatformImpl(app));
72 blink::initialize(blink_platform_.get());
73 #if !defined(COMPONENT_BUILD)
74 base::i18n::InitializeICU();
76 ui::RegisterPathProvider();
78 base::FilePath ui_test_pak_path;
79 CHECK(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
80 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
81 #endif
83 bool enable_mojo_media_renderer = false;
84 for (const auto& arg : app->args()) {
85 if (arg == kEnableMojoMediaRenderer) {
86 enable_mojo_media_renderer = true;
87 break;
91 compositor_thread_.Start();
92 web_media_player_factory_.reset(new WebMediaPlayerFactory(
93 compositor_thread_.message_loop_proxy(), enable_mojo_media_renderer));
96 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
97 connection->AddService(this);
98 return true;
101 // Overridden from InterfaceFactory<ContentHandler>
102 void Create(ApplicationConnection* connection,
103 InterfaceRequest<ContentHandler> request) override {
104 BindToRequest(
105 new ContentHandlerImpl(compositor_thread_.message_loop_proxy(),
106 web_media_player_factory_.get()),
107 &request);
110 scoped_ptr<MojoBlinkPlatformImpl> blink_platform_;
111 base::Thread compositor_thread_;
112 scoped_ptr<WebMediaPlayerFactory> web_media_player_factory_;
114 DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
117 } // namespace mojo
119 MojoResult MojoMain(MojoHandle shell_handle) {
120 mojo::ApplicationRunnerChromium runner(new mojo::HTMLViewer);
121 return runner.Run(shell_handle);