| 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/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 11 #include "gin/public/isolate_holder.h" | 12 #include "gin/public/isolate_holder.h" |
| 12 #include "mojo/application/application_runner_chromium.h" | 13 #include "mojo/application/application_runner_chromium.h" |
| 13 #include "mojo/services/html_viewer/discardable_memory_allocator.h" | 14 #include "mojo/services/html_viewer/discardable_memory_allocator.h" |
| 14 #include "mojo/services/html_viewer/html_document.h" | 15 #include "mojo/services/html_viewer/html_document.h" |
| 15 #include "mojo/services/html_viewer/mojo_blink_platform_impl.h" | 16 #include "mojo/services/html_viewer/mojo_blink_platform_impl.h" |
| 17 #include "mojo/services/html_viewer/public/interfaces/html_viewer.mojom.h" |
| 16 #include "mojo/services/html_viewer/webmediaplayer_factory.h" | 18 #include "mojo/services/html_viewer/webmediaplayer_factory.h" |
| 17 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 19 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| 18 #include "third_party/WebKit/public/web/WebKit.h" | 20 #include "third_party/WebKit/public/web/WebKit.h" |
| 19 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 21 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 20 #include "third_party/mojo/src/mojo/public/c/system/main.h" | 22 #include "third_party/mojo/src/mojo/public/c/system/main.h" |
| 21 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio
n.h" | 23 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio
n.h" |
| 22 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate.
h" | 24 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate.
h" |
| 23 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" | 25 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" |
| 24 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h" | 26 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h" |
| 25 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory_imp
l.h" | 27 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory_imp
l.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // Disables support for (unprefixed) Encrypted Media Extensions. | 59 // Disables support for (unprefixed) Encrypted Media Extensions. |
| 58 const char kDisableEncryptedMedia[] = "disable-encrypted-media"; | 60 const char kDisableEncryptedMedia[] = "disable-encrypted-media"; |
| 59 | 61 |
| 60 // Prevents creation of any output surface. | 62 // Prevents creation of any output surface. |
| 61 const char kIsHeadless[] = "is-headless"; | 63 const char kIsHeadless[] = "is-headless"; |
| 62 | 64 |
| 63 size_t kDesiredMaxMemory = 20 * 1024 * 1024; | 65 size_t kDesiredMaxMemory = 20 * 1024 * 1024; |
| 64 | 66 |
| 65 class HTMLViewer; | 67 class HTMLViewer; |
| 66 | 68 |
| 67 class HTMLViewerApplication : public mojo::Application { | 69 class HTMLViewerApplication |
| 70 : public mojo::Application, |
| 71 public mojo::InterfaceImpl<mojo::HTMLViewerTestAPI> { |
| 72 //, public mojo::InterfaceFactory<mojo::HTMLViewerTestAPI> { |
| 68 public: | 73 public: |
| 69 HTMLViewerApplication(InterfaceRequest<Application> request, | 74 HTMLViewerApplication(InterfaceRequest<Application> request, |
| 70 URLResponsePtr response, | 75 URLResponsePtr response, |
| 71 scoped_refptr<base::MessageLoopProxy> compositor_thread, | 76 scoped_refptr<base::MessageLoopProxy> compositor_thread, |
| 72 WebMediaPlayerFactory* web_media_player_factory, | 77 WebMediaPlayerFactory* web_media_player_factory, |
| 73 bool is_headless) | 78 bool is_headless) |
| 74 : url_(response->url), | 79 : url_(response->url), |
| 75 binding_(this, request.Pass()), | 80 binding_(this, request.Pass()), |
| 76 initial_response_(response.Pass()), | 81 initial_response_(response.Pass()), |
| 77 compositor_thread_(compositor_thread), | 82 compositor_thread_(compositor_thread), |
| 78 web_media_player_factory_(web_media_player_factory), | 83 web_media_player_factory_(web_media_player_factory), |
| 79 is_headless_(is_headless) {} | 84 is_headless_(is_headless) {} |
| 80 | 85 |
| 81 void Initialize(ShellPtr shell, | 86 void Initialize(ShellPtr shell, |
| 82 Array<String> args, | 87 Array<String> args, |
| 83 const String& url) override { | 88 const String& url) override { |
| 89 // std::string test_api_arg "--html_viewer_test_api"; |
| 90 // std::vector<std::string> arguments = args.To<std::vector<std::string>>(); |
| 91 // if (std::find(arguments.begin(), arguments.end(), test_api_arg) != argume
nts.end()) {} |
| 92 //ASSERT_TRUE(application_impl()->HasArg("--example_apptest_arg")); |
| 93 |
| 94 printf("MSW HTMLViewerApplication::Initialize\n"); |
| 84 ServiceProviderPtr service_provider; | 95 ServiceProviderPtr service_provider; |
| 85 shell_ = shell.Pass(); | 96 shell_ = shell.Pass(); |
| 86 shell_->ConnectToApplication("mojo:network_service", | 97 shell_->ConnectToApplication("mojo:network_service", |
| 87 GetProxy(&service_provider), nullptr); | 98 GetProxy(&service_provider), nullptr); |
| 88 ConnectToService(service_provider.get(), &network_service_); | 99 ConnectToService(service_provider.get(), &network_service_); |
| 89 } | 100 } |
| 90 | 101 |
| 91 void AcceptConnection(const String& requestor_url, | 102 void AcceptConnection(const String& requestor_url, |
| 92 InterfaceRequest<ServiceProvider> services, | 103 InterfaceRequest<ServiceProvider> services, |
| 93 ServiceProviderPtr exposed_services, | 104 ServiceProviderPtr exposed_services, |
| 94 const String& url) override { | 105 const String& url) override { |
| 106 //service_provider_.AddService<mojo::HTMLViewerTestAPI>(this); |
| 107 service_provider_.Bind(services.Pass()); |
| 108 |
| 109 printf("MSW HTMLViewerApplication::AcceptConnection " |
| 110 "requestor=[%s] url=[%s] (url_=[%s], initial_response_=[%d])\n", |
| 111 requestor_url.data(), url.data(), url_.data(), |
| 112 !initial_response_.is_null()); |
| 113 |
| 95 if (initial_response_) { | 114 if (initial_response_) { |
| 96 OnResponseReceived(URLLoaderPtr(), services.Pass(), | 115 OnResponseReceived(URLLoaderPtr(), initial_response_.Pass()); |
| 97 initial_response_.Pass()); | |
| 98 } else { | 116 } else { |
| 117 // TODO(msw): Is this dead code? When is this called? |
| 99 URLLoaderPtr loader; | 118 URLLoaderPtr loader; |
| 100 network_service_->CreateURLLoader(GetProxy(&loader)); | 119 network_service_->CreateURLLoader(GetProxy(&loader)); |
| 101 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 120 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 102 request->url = url_; | 121 request->url = url_; |
| 103 request->auto_follow_redirects = true; | 122 request->auto_follow_redirects = true; |
| 104 | 123 |
| 105 // |loader| will be pass to the OnResponseReceived method through a | 124 // |loader| will be pass to the OnResponseReceived method through a |
| 106 // callback. Because order of evaluation is undefined, a reference to the | 125 // callback. Because order of evaluation is undefined, a reference to the |
| 107 // raw pointer is needed. | 126 // raw pointer is needed. |
| 108 mojo::URLLoader* raw_loader = loader.get(); | 127 mojo::URLLoader* raw_loader = loader.get(); |
| 109 raw_loader->Start( | 128 raw_loader->Start( |
| 110 request.Pass(), | 129 request.Pass(), |
| 111 base::Bind(&HTMLViewerApplication::OnResponseReceived, | 130 base::Bind(&HTMLViewerApplication::OnResponseReceived, |
| 112 base::Unretained(this), base::Passed(&loader), | 131 base::Unretained(this), base::Passed(&loader))); |
| 113 base::Passed(&services))); | |
| 114 } | 132 } |
| 115 } | 133 } |
| 116 | 134 |
| 117 void RequestQuit() override {} | 135 void RequestQuit() override {} |
| 118 | 136 |
| 137 //// mojo::InterfaceImpl<mojo::HTMLViewerTestAPI>: |
| 138 // void WaitForHTMLDocument( |
| 139 // const WaitForHTMLDocumentCallback& callback) override { |
| 140 |
| 141 // // TODO(msw): How can we wait for document load/layout? |
| 142 // //base::RunLoop run_loop; |
| 143 // //run_loop.RunUntilIdle(); |
| 144 // //base::MessageLoop::current()->RunUntilIdle(); |
| 145 // //base::MessageLoop::current()->Run(); |
| 146 |
| 147 |
| 148 // printf("MSW HTMLViewerApplication::WaitForHTMLDocument:%d\n", |
| 149 // html_document_created_); |
| 150 // if (html_document_created_) { |
| 151 // callback.Run(); |
| 152 // return; |
| 153 // } |
| 154 // DCHECK(wait_for_html_document_callback_.is_null()); |
| 155 // wait_for_html_document_callback_ = callback; |
| 156 // } |
| 157 |
| 158 // // mojo::InterfaceFactory<mojo::HTMLViewerTestAPI>: |
| 159 // void Create( |
| 160 // ApplicationConnection* connection, |
| 161 // mojo::InterfaceRequest<mojo::HTMLViewerTestAPI> request) override { |
| 162 // printf("MSW HTMLViewerApplication::Create (HTMLViewerTestAPI)\n"); |
| 163 // // TODO(msw): Do not offer this service without --html-viewer-test-flag..
. |
| 164 // // TODO(msw): Is this safe/correct? Can we avoid InterfaceFactory? |
| 165 // // (getting flaky shutdown crashes w/base::MessageLoop dtor...) |
| 166 // BindToRequest(this, &request); |
| 167 // } |
| 168 |
| 119 private: | 169 private: |
| 120 void OnResponseReceived(URLLoaderPtr loader, | 170 void OnResponseReceived(URLLoaderPtr loader, URLResponsePtr response) { |
| 121 InterfaceRequest<ServiceProvider> services, | 171 printf("MSW HTMLViewerApplication::OnResponseReceived\n"); |
| 122 URLResponsePtr response) { | 172 new HTMLDocument(&service_provider_, response.Pass(), shell_.get(), |
| 123 new HTMLDocument(services.Pass(), response.Pass(), shell_.get(), | |
| 124 compositor_thread_, web_media_player_factory_, | 173 compositor_thread_, web_media_player_factory_, |
| 125 is_headless_); | 174 is_headless_); |
| 175 // html_document_created_ = true; |
| 176 // if (!wait_for_html_document_callback_.is_null()) |
| 177 // wait_for_html_document_callback_.Run(); |
| 126 } | 178 } |
| 127 | 179 |
| 128 String url_; | 180 String url_; |
| 129 mojo::StrongBinding<mojo::Application> binding_; | 181 mojo::StrongBinding<mojo::Application> binding_; |
| 182 mojo::ServiceProviderImpl service_provider_; |
| 130 ShellPtr shell_; | 183 ShellPtr shell_; |
| 131 mojo::NetworkServicePtr network_service_; | 184 mojo::NetworkServicePtr network_service_; |
| 132 URLResponsePtr initial_response_; | 185 URLResponsePtr initial_response_; |
| 133 scoped_refptr<base::MessageLoopProxy> compositor_thread_; | 186 scoped_refptr<base::MessageLoopProxy> compositor_thread_; |
| 134 WebMediaPlayerFactory* web_media_player_factory_; | 187 WebMediaPlayerFactory* web_media_player_factory_; |
| 135 bool is_headless_; | 188 bool is_headless_; |
| 189 //bool html_document_created_ = false; |
| 190 //WaitForHTMLDocumentCallback wait_for_html_document_callback_; |
| 136 }; | 191 }; |
| 137 | 192 |
| 138 class ContentHandlerImpl : public mojo::InterfaceImpl<ContentHandler> { | 193 class ContentHandlerImpl : public mojo::InterfaceImpl<ContentHandler> { |
| 139 public: | 194 public: |
| 140 ContentHandlerImpl(scoped_refptr<base::MessageLoopProxy> compositor_thread, | 195 ContentHandlerImpl(scoped_refptr<base::MessageLoopProxy> compositor_thread, |
| 141 WebMediaPlayerFactory* web_media_player_factory, | 196 WebMediaPlayerFactory* web_media_player_factory, |
| 142 bool is_headless) | 197 bool is_headless) |
| 143 : compositor_thread_(compositor_thread), | 198 : compositor_thread_(compositor_thread), |
| 144 web_media_player_factory_(web_media_player_factory), | 199 web_media_player_factory_(web_media_player_factory), |
| 145 is_headless_(is_headless) {} | 200 is_headless_(is_headless) { |
| 201 printf("MSW ContentHandlerImpl::ContentHandlerImpl\n"); |
| 202 } |
| 146 ~ContentHandlerImpl() override {} | 203 ~ContentHandlerImpl() override {} |
| 147 | 204 |
| 148 private: | 205 private: |
| 149 // Overridden from ContentHandler: | 206 // Overridden from ContentHandler: |
| 150 void StartApplication(InterfaceRequest<mojo::Application> request, | 207 void StartApplication(InterfaceRequest<mojo::Application> request, |
| 151 URLResponsePtr response) override { | 208 URLResponsePtr response) override { |
| 209 printf("MSW ContentHandlerImpl::StartApplication\n"); |
| 152 new HTMLViewerApplication(request.Pass(), response.Pass(), | 210 new HTMLViewerApplication(request.Pass(), response.Pass(), |
| 153 compositor_thread_, web_media_player_factory_, | 211 compositor_thread_, web_media_player_factory_, |
| 154 is_headless_); | 212 is_headless_); |
| 155 } | 213 } |
| 156 | 214 |
| 157 scoped_refptr<base::MessageLoopProxy> compositor_thread_; | 215 scoped_refptr<base::MessageLoopProxy> compositor_thread_; |
| 158 WebMediaPlayerFactory* web_media_player_factory_; | 216 WebMediaPlayerFactory* web_media_player_factory_; |
| 159 bool is_headless_; | 217 bool is_headless_; |
| 160 | 218 |
| 161 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); | 219 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 } | 287 } |
| 230 | 288 |
| 231 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 289 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
| 232 connection->AddService(this); | 290 connection->AddService(this); |
| 233 return true; | 291 return true; |
| 234 } | 292 } |
| 235 | 293 |
| 236 // Overridden from InterfaceFactory<ContentHandler> | 294 // Overridden from InterfaceFactory<ContentHandler> |
| 237 void Create(ApplicationConnection* connection, | 295 void Create(ApplicationConnection* connection, |
| 238 mojo::InterfaceRequest<ContentHandler> request) override { | 296 mojo::InterfaceRequest<ContentHandler> request) override { |
| 297 printf("MSW HTMLViewer::Create (ContentHandler)\n"); |
| 239 BindToRequest( | 298 BindToRequest( |
| 240 new ContentHandlerImpl(compositor_thread_.message_loop_proxy(), | 299 new ContentHandlerImpl(compositor_thread_.message_loop_proxy(), |
| 241 web_media_player_factory_.get(), is_headless_), | 300 web_media_player_factory_.get(), is_headless_), |
| 242 &request); | 301 &request); |
| 243 } | 302 } |
| 244 | 303 |
| 245 // Skia requires that we have one of these. Unlike the one used in chrome, | 304 // Skia requires that we have one of these. Unlike the one used in chrome, |
| 246 // this doesn't use purgable shared memory. Instead, it tries to free the | 305 // this doesn't use purgable shared memory. Instead, it tries to free the |
| 247 // oldest unlocked chunks on allocation. | 306 // oldest unlocked chunks on allocation. |
| 248 // | 307 // |
| 249 // TODO(erg): In the long run, delete this allocator and get the real shared | 308 // TODO(erg): In the long run, delete this allocator and get the real shared |
| 250 // memory based purging allocator working here. | 309 // memory based purging allocator working here. |
| 251 DiscardableMemoryAllocator discardable_memory_allocator_; | 310 DiscardableMemoryAllocator discardable_memory_allocator_; |
| 252 | 311 |
| 253 scoped_ptr<MojoBlinkPlatformImpl> blink_platform_; | 312 scoped_ptr<MojoBlinkPlatformImpl> blink_platform_; |
| 254 base::Thread compositor_thread_; | 313 base::Thread compositor_thread_; |
| 255 scoped_ptr<WebMediaPlayerFactory> web_media_player_factory_; | 314 scoped_ptr<WebMediaPlayerFactory> web_media_player_factory_; |
| 256 // Set if the content will never be displayed. | 315 // Set if the content will never be displayed. |
| 257 bool is_headless_; | 316 bool is_headless_; |
| 258 | 317 |
| 259 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); | 318 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); |
| 260 }; | 319 }; |
| 261 | 320 |
| 262 } // namespace html_viewer | 321 } // namespace html_viewer |
| 263 | 322 |
| 264 MojoResult MojoMain(MojoHandle shell_handle) { | 323 MojoResult MojoMain(MojoHandle shell_handle) { |
| 324 printf("MSW MojoMain\n"); |
| 265 mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer); | 325 mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer); |
| 266 return runner.Run(shell_handle); | 326 return runner.Run(shell_handle); |
| 267 } | 327 } |
| OLD | NEW |