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.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 shell_.set_client(this); | |
55 ServiceProviderPtr service_provider; | |
56 shell_->ConnectToApplication("mojo:network_service", | |
57 GetProxy(&service_provider)); | |
58 ConnectToService(service_provider.get(), &network_service_); | |
59 } | |
60 | |
61 void Initialize(Array<String> args) override {} | |
62 | |
63 void AcceptConnection(const String& requestor_url, | |
64 ServiceProviderPtr provider) override { | |
65 if (initial_response_) { | |
66 OnResponseReceived(URLLoaderPtr(), provider.Pass(), | |
67 initial_response_.Pass()); | |
68 } else { | |
69 URLLoaderPtr loader; | |
70 network_service_->CreateURLLoader(GetProxy(&loader)); | |
71 URLRequestPtr request(URLRequest::New()); | |
72 request->url = url_; | |
73 request->auto_follow_redirects = true; | |
74 | |
75 // |loader| will be pass to the OnResponseReceived method through a | |
76 // callback. Because order of evaluation is undefined, a reference to the | |
77 // raw pointer is needed. | |
78 URLLoader* raw_loader = loader.get(); | |
79 raw_loader->Start( | |
80 request.Pass(), | |
81 base::Bind(&HTMLViewerApplication::OnResponseReceived, | |
82 base::Unretained(this), base::Passed(&loader), | |
83 base::Passed(&provider))); | |
84 } | |
85 } | |
86 | |
87 private: | |
88 void OnResponseReceived(URLLoaderPtr loader, | |
89 ServiceProviderPtr provider, | |
90 URLResponsePtr response) { | |
91 new HTMLDocument(provider.Pass(), response.Pass(), shell_.get(), | |
Aaron Boodman
2014/12/10 08:54:28
Now, HTMLDocument can live past the lifetime of sh
| |
92 compositor_thread_, web_media_player_factory_); | |
93 } | |
94 | |
95 String url_; | |
96 ShellPtr shell_; | |
97 NetworkServicePtr network_service_; | |
98 URLResponsePtr initial_response_; | |
99 scoped_refptr<base::MessageLoopProxy> compositor_thread_; | |
100 WebMediaPlayerFactory* web_media_player_factory_; | |
101 }; | |
102 | |
41 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { | 103 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { |
42 public: | 104 public: |
43 ContentHandlerImpl(scoped_refptr<base::MessageLoopProxy> compositor_thread, | 105 ContentHandlerImpl(scoped_refptr<base::MessageLoopProxy> compositor_thread, |
44 WebMediaPlayerFactory* web_media_player_factory) | 106 WebMediaPlayerFactory* web_media_player_factory) |
45 : compositor_thread_(compositor_thread), | 107 : compositor_thread_(compositor_thread), |
46 web_media_player_factory_(web_media_player_factory) {} | 108 web_media_player_factory_(web_media_player_factory) {} |
47 ~ContentHandlerImpl() override {} | 109 ~ContentHandlerImpl() override {} |
48 | 110 |
49 private: | 111 private: |
50 // Overridden from ContentHandler: | 112 // Overridden from ContentHandler: |
51 void StartApplication(ShellPtr shell, URLResponsePtr response) override { | 113 void StartApplication(ShellPtr shell, URLResponsePtr response) override { |
52 new HTMLDocumentView(response.Pass(), | 114 new HTMLViewerApplication(shell.Pass(), response.Pass(), compositor_thread_, |
53 shell.Pass(), | 115 web_media_player_factory_); |
54 compositor_thread_, | |
55 web_media_player_factory_); | |
56 } | 116 } |
57 | 117 |
58 scoped_refptr<base::MessageLoopProxy> compositor_thread_; | 118 scoped_refptr<base::MessageLoopProxy> compositor_thread_; |
59 WebMediaPlayerFactory* web_media_player_factory_; | 119 WebMediaPlayerFactory* web_media_player_factory_; |
60 | 120 |
61 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); | 121 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); |
62 }; | 122 }; |
63 | 123 |
64 class HTMLViewer : public ApplicationDelegate, | 124 class HTMLViewer : public ApplicationDelegate, |
65 public InterfaceFactory<ContentHandler> { | 125 public InterfaceFactory<ContentHandler> { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 | 186 |
127 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); | 187 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); |
128 }; | 188 }; |
129 | 189 |
130 } // namespace mojo | 190 } // namespace mojo |
131 | 191 |
132 MojoResult MojoMain(MojoHandle shell_handle) { | 192 MojoResult MojoMain(MojoHandle shell_handle) { |
133 mojo::ApplicationRunnerChromium runner(new mojo::HTMLViewer); | 193 mojo::ApplicationRunnerChromium runner(new mojo::HTMLViewer); |
134 return runner.Run(shell_handle); | 194 return runner.Run(shell_handle); |
135 } | 195 } |
OLD | NEW |