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/logging.h" | 6 #include "base/logging.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
11 #include "mojo/application/application_runner_chromium.h" | 11 #include "mojo/application/application_runner_chromium.h" |
12 #include "mojo/public/c/system/main.h" | 12 #include "mojo/public/c/system/main.h" |
13 #include "mojo/public/cpp/application/application_connection.h" | 13 #include "mojo/public/cpp/application/application_connection.h" |
14 #include "mojo/public/cpp/application/application_delegate.h" | 14 #include "mojo/public/cpp/application/application_delegate.h" |
15 #include "mojo/public/cpp/application/application_impl.h" | 15 #include "mojo/public/cpp/application/application_impl.h" |
16 #include "mojo/public/cpp/application/connect.h" | |
16 #include "mojo/public/cpp/application/interface_factory_impl.h" | 17 #include "mojo/public/cpp/application/interface_factory_impl.h" |
17 #include "mojo/services/html_viewer/html_document_view.h" | 18 #include "mojo/services/html_viewer/html_document_view.h" |
18 #include "mojo/services/html_viewer/mojo_blink_platform_impl.h" | 19 #include "mojo/services/html_viewer/mojo_blink_platform_impl.h" |
19 #include "mojo/services/html_viewer/webmediaplayer_factory.h" | 20 #include "mojo/services/html_viewer/webmediaplayer_factory.h" |
20 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom. h" | 21 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom. h" |
22 #include "mojo/services/public/interfaces/network/network_service.mojom.h" | |
21 #include "third_party/WebKit/public/web/WebKit.h" | 23 #include "third_party/WebKit/public/web/WebKit.h" |
22 | 24 |
23 #if !defined(COMPONENT_BUILD) | 25 #if !defined(COMPONENT_BUILD) |
24 #include "base/i18n/icu_util.h" | 26 #include "base/i18n/icu_util.h" |
25 #include "base/path_service.h" | 27 #include "base/path_service.h" |
26 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
27 #include "ui/base/ui_base_paths.h" | 29 #include "ui/base/ui_base_paths.h" |
28 #endif | 30 #endif |
29 | 31 |
30 namespace mojo { | 32 namespace mojo { |
31 | 33 |
32 // Switches for html_viewer to be used with "--args-for". For example: | 34 // Switches for html_viewer to be used with "--args-for". For example: |
33 // --args-for='mojo:html_viewer --enable-mojo-media-renderer' | 35 // --args-for='mojo:html_viewer --enable-mojo-media-renderer' |
34 | 36 |
35 // Enable mojo::MediaRenderer in media pipeline instead of using the internal | 37 // Enable MediaRenderer in media pipeline instead of using the internal |
36 // media::Renderer implementation. | 38 // media::Renderer implementation. |
37 const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer"; | 39 const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer"; |
38 | 40 |
39 class HTMLViewer; | 41 class HTMLViewer; |
40 | 42 |
43 class HTMLViewerApplication : public Application { | |
44 public: | |
45 HTMLViewerApplication(ShellPtr shell, | |
46 URLResponsePtr response, | |
47 scoped_refptr<base::MessageLoopProxy> compositor_thread, | |
48 WebMediaPlayerFactory* web_media_player_factory) | |
49 : url_(response->url), | |
50 shell_(shell.Pass()), | |
51 initial_response_(response.Pass()), | |
52 compositor_thread_(compositor_thread), | |
53 web_media_player_factory_(web_media_player_factory), | |
54 view_count_(0) { | |
55 shell_.set_client(this); | |
56 ServiceProviderPtr service_provider; | |
57 shell_->ConnectToApplication("mojo:network_service", | |
58 GetProxy(&service_provider)); | |
59 ConnectToService(service_provider.get(), &network_service_); | |
60 } | |
61 | |
62 void Initialize(Array<String> args) override {} | |
63 | |
64 void AcceptConnection(const String& requestor_url, | |
65 ServiceProviderPtr provider) override { | |
66 ++view_count_; | |
67 if (initial_response_) { | |
68 OnResponseReceived(URLLoaderPtr(), provider.Pass(), | |
69 initial_response_.Pass()); | |
70 } else { | |
71 URLLoaderPtr loader; | |
72 network_service_->CreateURLLoader(GetProxy(&loader)); | |
73 URLRequestPtr request(URLRequest::New()); | |
74 request->url = url_; | |
75 request->auto_follow_redirects = true; | |
76 | |
77 // |loader| will be pass to the OnResponseReceived method through a | |
78 // callback. Because order of evaluation is undefined, a reference to the | |
79 // raw pointer is needed. | |
80 URLLoader* raw_loader = loader.get(); | |
81 raw_loader->Start( | |
82 request.Pass(), | |
83 base::Bind(&HTMLViewerApplication::OnResponseReceived, | |
84 base::Unretained(this), base::Passed(&loader), | |
85 base::Passed(&provider))); | |
86 } | |
87 } | |
88 | |
89 private: | |
90 void OnViewDestroyed() { | |
91 --view_count_; | |
92 if (view_count_ == 0) { | |
93 delete this; | |
94 } | |
95 } | |
96 | |
97 void OnResponseReceived(URLLoaderPtr loader, | |
98 ServiceProviderPtr provider, | |
99 URLResponsePtr response) { | |
100 new HTMLDocumentView(base::Bind(&HTMLViewerApplication::OnViewDestroyed, | |
Aaron Boodman
2014/12/03 16:42:11
I know this already existed, but naming nit: this
qsr
2014/12/03 16:56:53
Done.
| |
101 base::Unretained(this)), | |
Aaron Boodman
2014/12/03 16:42:11
Won't the application crash if HTMLViewerApplicati
qsr
2014/12/03 16:56:53
HTMLViewerApplication is self owned. It can only d
Aaron Boodman
2014/12/03 17:32:37
Ah, true.
| |
102 provider.Pass(), response.Pass(), shell_.get(), | |
103 compositor_thread_, web_media_player_factory_); | |
104 } | |
105 | |
106 String url_; | |
107 ShellPtr shell_; | |
108 NetworkServicePtr network_service_; | |
109 URLResponsePtr initial_response_; | |
110 scoped_refptr<base::MessageLoopProxy> compositor_thread_; | |
111 WebMediaPlayerFactory* web_media_player_factory_; | |
112 uint32_t view_count_; | |
113 }; | |
114 | |
41 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { | 115 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { |
42 public: | 116 public: |
43 ContentHandlerImpl(scoped_refptr<base::MessageLoopProxy> compositor_thread, | 117 ContentHandlerImpl(scoped_refptr<base::MessageLoopProxy> compositor_thread, |
44 WebMediaPlayerFactory* web_media_player_factory) | 118 WebMediaPlayerFactory* web_media_player_factory) |
45 : compositor_thread_(compositor_thread), | 119 : compositor_thread_(compositor_thread), |
46 web_media_player_factory_(web_media_player_factory) {} | 120 web_media_player_factory_(web_media_player_factory) {} |
47 ~ContentHandlerImpl() override {} | 121 ~ContentHandlerImpl() override {} |
48 | 122 |
49 private: | 123 private: |
50 // Overridden from ContentHandler: | 124 // Overridden from ContentHandler: |
51 void StartApplication(ShellPtr shell, URLResponsePtr response) override { | 125 void StartApplication(ShellPtr shell, URLResponsePtr response) override { |
52 new HTMLDocumentView(response.Pass(), | 126 new HTMLViewerApplication(shell.Pass(), response.Pass(), compositor_thread_, |
53 shell.Pass(), | 127 web_media_player_factory_); |
54 compositor_thread_, | |
55 web_media_player_factory_); | |
56 } | 128 } |
57 | 129 |
58 scoped_refptr<base::MessageLoopProxy> compositor_thread_; | 130 scoped_refptr<base::MessageLoopProxy> compositor_thread_; |
59 WebMediaPlayerFactory* web_media_player_factory_; | 131 WebMediaPlayerFactory* web_media_player_factory_; |
60 | 132 |
61 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); | 133 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); |
62 }; | 134 }; |
63 | 135 |
64 class HTMLViewer : public ApplicationDelegate, | 136 class HTMLViewer : public ApplicationDelegate, |
65 public InterfaceFactory<ContentHandler> { | 137 public InterfaceFactory<ContentHandler> { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 | 198 |
127 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); | 199 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); |
128 }; | 200 }; |
129 | 201 |
130 } // namespace mojo | 202 } // namespace mojo |
131 | 203 |
132 MojoResult MojoMain(MojoHandle shell_handle) { | 204 MojoResult MojoMain(MojoHandle shell_handle) { |
133 mojo::ApplicationRunnerChromium runner(new mojo::HTMLViewer); | 205 mojo::ApplicationRunnerChromium runner(new mojo::HTMLViewer); |
134 return runner.Run(shell_handle); | 206 return runner.Run(shell_handle); |
135 } | 207 } |
OLD | NEW |