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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "base/threading/thread.h" | 6 #include "base/threading/thread.h" |
7 #include "mojo/public/c/system/main.h" | 7 #include "mojo/public/c/system/main.h" |
8 #include "mojo/public/cpp/application/application_connection.h" | 8 #include "mojo/public/cpp/application/application_connection.h" |
9 #include "mojo/public/cpp/application/application_delegate.h" | 9 #include "mojo/public/cpp/application/application_delegate.h" |
10 #include "mojo/public/cpp/application/application_impl.h" | 10 #include "mojo/public/cpp/application/application_impl.h" |
11 #include "mojo/public/cpp/application/application_runner_chromium.h" | 11 #include "mojo/public/cpp/application/application_runner_chromium.h" |
12 #include "mojo/public/cpp/application/interface_factory_impl.h" | 12 #include "mojo/public/cpp/application/interface_factory_impl.h" |
13 #include "mojo/services/html_viewer/blink_platform_impl.h" | 13 #include "mojo/services/html_viewer/blink_platform_impl.h" |
14 #include "mojo/services/html_viewer/html_document_view.h" | 14 #include "mojo/services/html_viewer/html_document_view.h" |
| 15 #include "mojo/services/html_viewer/webmediaplayer_factory.h" |
15 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.
h" | 16 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.
h" |
16 #include "third_party/WebKit/public/web/WebKit.h" | 17 #include "third_party/WebKit/public/web/WebKit.h" |
17 | 18 |
18 namespace mojo { | 19 namespace mojo { |
19 | 20 |
20 class HTMLViewer; | 21 class HTMLViewer; |
21 | 22 |
22 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { | 23 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { |
23 public: | 24 public: |
24 ContentHandlerImpl(Shell* shell, | 25 ContentHandlerImpl(Shell* shell, |
25 scoped_refptr<base::MessageLoopProxy> compositor_thread) | 26 scoped_refptr<base::MessageLoopProxy> compositor_thread, |
26 : shell_(shell), compositor_thread_(compositor_thread) {} | 27 WebMediaPlayerFactory* web_media_player_factory) |
| 28 : shell_(shell), |
| 29 compositor_thread_(compositor_thread), |
| 30 web_media_player_factory_(web_media_player_factory) {} |
27 virtual ~ContentHandlerImpl() {} | 31 virtual ~ContentHandlerImpl() {} |
28 | 32 |
29 private: | 33 private: |
30 // Overridden from ContentHandler: | 34 // Overridden from ContentHandler: |
31 virtual void OnConnect( | 35 virtual void OnConnect( |
32 const mojo::String& url, | 36 const mojo::String& url, |
33 URLResponsePtr response, | 37 URLResponsePtr response, |
34 InterfaceRequest<ServiceProvider> service_provider_request) OVERRIDE { | 38 InterfaceRequest<ServiceProvider> service_provider_request) OVERRIDE { |
35 new HTMLDocumentView(response.Pass(), | 39 new HTMLDocumentView(response.Pass(), |
36 service_provider_request.Pass(), | 40 service_provider_request.Pass(), |
37 shell_, | 41 shell_, |
38 compositor_thread_); | 42 compositor_thread_, |
| 43 web_media_player_factory_); |
39 } | 44 } |
40 | 45 |
41 Shell* shell_; | 46 Shell* shell_; |
42 scoped_refptr<base::MessageLoopProxy> compositor_thread_; | 47 scoped_refptr<base::MessageLoopProxy> compositor_thread_; |
| 48 WebMediaPlayerFactory* web_media_player_factory_; |
43 | 49 |
44 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); | 50 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); |
45 }; | 51 }; |
46 | 52 |
47 class HTMLViewer : public ApplicationDelegate, | 53 class HTMLViewer : public ApplicationDelegate, |
48 public InterfaceFactory<ContentHandler> { | 54 public InterfaceFactory<ContentHandler> { |
49 public: | 55 public: |
50 HTMLViewer() : compositor_thread_("compositor thread") {} | 56 HTMLViewer() : compositor_thread_("compositor thread") {} |
51 | 57 |
52 virtual ~HTMLViewer() { blink::shutdown(); } | 58 virtual ~HTMLViewer() { blink::shutdown(); } |
53 | 59 |
54 private: | 60 private: |
55 // Overridden from ApplicationDelegate: | 61 // Overridden from ApplicationDelegate: |
56 virtual void Initialize(ApplicationImpl* app) OVERRIDE { | 62 virtual void Initialize(ApplicationImpl* app) OVERRIDE { |
57 shell_ = app->shell(); | 63 shell_ = app->shell(); |
58 blink_platform_impl_.reset(new BlinkPlatformImpl(app)); | 64 blink_platform_impl_.reset(new BlinkPlatformImpl(app)); |
59 blink::initialize(blink_platform_impl_.get()); | 65 blink::initialize(blink_platform_impl_.get()); |
60 compositor_thread_.Start(); | 66 compositor_thread_.Start(); |
| 67 web_media_player_factory_.reset(new WebMediaPlayerFactory( |
| 68 compositor_thread_.message_loop_proxy())); |
61 } | 69 } |
62 | 70 |
63 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 71 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
64 OVERRIDE { | 72 OVERRIDE { |
65 connection->AddService(this); | 73 connection->AddService(this); |
66 return true; | 74 return true; |
67 } | 75 } |
68 | 76 |
69 // Overridden from InterfaceFactory<ContentHandler> | 77 // Overridden from InterfaceFactory<ContentHandler> |
70 virtual void Create(ApplicationConnection* connection, | 78 virtual void Create(ApplicationConnection* connection, |
71 InterfaceRequest<ContentHandler> request) OVERRIDE { | 79 InterfaceRequest<ContentHandler> request) OVERRIDE { |
72 BindToRequest( | 80 BindToRequest( |
73 new ContentHandlerImpl(shell_, compositor_thread_.message_loop_proxy()), | 81 new ContentHandlerImpl(shell_, compositor_thread_.message_loop_proxy(), |
| 82 web_media_player_factory_.get()), |
74 &request); | 83 &request); |
75 } | 84 } |
76 | 85 |
77 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; | 86 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; |
78 Shell* shell_; | 87 Shell* shell_; |
79 base::Thread compositor_thread_; | 88 base::Thread compositor_thread_; |
| 89 scoped_ptr<WebMediaPlayerFactory> web_media_player_factory_; |
80 | 90 |
81 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); | 91 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); |
82 }; | 92 }; |
83 | 93 |
84 } // namespace mojo | 94 } // namespace mojo |
85 | 95 |
86 MojoResult MojoMain(MojoHandle shell_handle) { | 96 MojoResult MojoMain(MojoHandle shell_handle) { |
87 mojo::ApplicationRunnerChromium runner(new mojo::HTMLViewer); | 97 mojo::ApplicationRunnerChromium runner(new mojo::HTMLViewer); |
88 return runner.Run(shell_handle); | 98 return runner.Run(shell_handle); |
89 } | 99 } |
OLD | NEW |