Chromium Code Reviews| Index: mojo/services/html_viewer/html_viewer.cc |
| diff --git a/mojo/services/html_viewer/html_viewer.cc b/mojo/services/html_viewer/html_viewer.cc |
| index 1391c1c7372f501971e944e68dc8913ac67031c2..dcb3fc94e04f3b01e9a4d197c9ed750af027fc5b 100644 |
| --- a/mojo/services/html_viewer/html_viewer.cc |
| +++ b/mojo/services/html_viewer/html_viewer.cc |
| @@ -13,6 +13,7 @@ |
| #include "mojo/services/html_viewer/discardable_memory_allocator.h" |
| #include "mojo/services/html_viewer/html_document.h" |
| #include "mojo/services/html_viewer/mojo_blink_platform_impl.h" |
| +#include "mojo/services/html_viewer/public/interfaces/html_viewer.mojom.h" |
| #include "mojo/services/html_viewer/webmediaplayer_factory.h" |
| #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| #include "third_party/WebKit/public/web/WebKit.h" |
| @@ -64,7 +65,10 @@ size_t kDesiredMaxMemory = 20 * 1024 * 1024; |
| class HTMLViewer; |
| -class HTMLViewerApplication : public mojo::Application { |
| +class HTMLViewerApplication |
| + : public mojo::Application, |
| + public mojo::InterfaceImpl<mojo::HTMLViewerTestAPI>, |
| + public mojo::InterfaceFactory<mojo::HTMLViewerTestAPI> { |
| public: |
| HTMLViewerApplication(InterfaceRequest<Application> request, |
| URLResponsePtr response, |
| @@ -81,6 +85,7 @@ class HTMLViewerApplication : public mojo::Application { |
| void Initialize(ShellPtr shell, |
| Array<String> args, |
| const String& url) override { |
| + printf("MSW HTMLViewerApplication::Initialize\n"); |
| ServiceProviderPtr service_provider; |
| shell_ = shell.Pass(); |
| shell_->ConnectToApplication("mojo:network_service", |
| @@ -92,10 +97,18 @@ class HTMLViewerApplication : public mojo::Application { |
| InterfaceRequest<ServiceProvider> services, |
| ServiceProviderPtr exposed_services, |
| const String& url) override { |
| + service_provider_.AddService<mojo::HTMLViewerTestAPI>(this); |
|
sky
2015/04/02 16:56:17
We should only do this if a command line switch is
|
| + service_provider_.Bind(services.Pass()); |
| + |
| + printf("MSW HTMLViewerApplication::AcceptConnection " |
| + "requestor=[%s] url=[%s] (url_=[%s], initial_response_=[%d])\n", |
| + requestor_url.data(), url.data(), url_.data(), |
| + !initial_response_.is_null()); |
| + |
| if (initial_response_) { |
| - OnResponseReceived(URLLoaderPtr(), services.Pass(), |
| - initial_response_.Pass()); |
| + OnResponseReceived(URLLoaderPtr(), initial_response_.Pass()); |
| } else { |
| + // TODO(msw): Is this dead code? When is this called? |
| URLLoaderPtr loader; |
| network_service_->CreateURLLoader(GetProxy(&loader)); |
| mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| @@ -109,30 +122,54 @@ class HTMLViewerApplication : public mojo::Application { |
| raw_loader->Start( |
| request.Pass(), |
| base::Bind(&HTMLViewerApplication::OnResponseReceived, |
| - base::Unretained(this), base::Passed(&loader), |
| - base::Passed(&services))); |
| + base::Unretained(this), base::Passed(&loader))); |
| } |
| } |
| void RequestQuit() override {} |
| + // mojo::InterfaceImpl<mojo::HTMLViewerTestAPI>: |
| + void WaitForLoad(const WaitForLoadCallback& callback) override { |
| + printf("MSW HTMLViewerApplication::WaitForLoad loaded:%d\n", loaded_); |
| + if (loaded_) |
| + callback.Run(); |
| + else |
| + wait_for_load_callback_ = callback; |
|
sky
2015/04/02 16:56:17
Log or DCHECK if already waiting?
|
| + } |
| + |
| + // mojo::InterfaceFactory<mojo::HTMLViewerTestAPI>: |
| + void Create( |
| + ApplicationConnection* connection, |
| + mojo::InterfaceRequest<mojo::HTMLViewerTestAPI> request) override { |
| + printf("MSW HTMLViewerApplication::Create (HTMLViewerTestAPI)\n"); |
| + // TODO(msw): Do not offer this service without --html-viewer-test-flag... |
| + // TODO(msw): Is this safe/correct? Can we avoid InterfaceFactory? |
| + // (getting flaky shutdown crashes w/base::MessageLoop dtor...) |
| + BindToRequest(this, &request); |
| + } |
| + |
| private: |
| - void OnResponseReceived(URLLoaderPtr loader, |
| - InterfaceRequest<ServiceProvider> services, |
| - URLResponsePtr response) { |
| - new HTMLDocument(services.Pass(), response.Pass(), shell_.get(), |
| + void OnResponseReceived(URLLoaderPtr loader, URLResponsePtr response) { |
| + loaded_ = true; |
|
sky
2015/04/02 16:56:17
Is this really loaded, or just created document?
|
| + printf("MSW HTMLViewerApplication::OnResponseReceived\n"); |
| + new HTMLDocument(&service_provider_, response.Pass(), shell_.get(), |
| compositor_thread_, web_media_player_factory_, |
| is_headless_); |
| + if (!wait_for_load_callback_.is_null()) |
| + wait_for_load_callback_.Run(); |
| } |
| String url_; |
| mojo::StrongBinding<mojo::Application> binding_; |
| + mojo::ServiceProviderImpl service_provider_; |
| ShellPtr shell_; |
| mojo::NetworkServicePtr network_service_; |
| URLResponsePtr initial_response_; |
| scoped_refptr<base::MessageLoopProxy> compositor_thread_; |
| WebMediaPlayerFactory* web_media_player_factory_; |
| bool is_headless_; |
| + bool loaded_ = false; |
| + WaitForLoadCallback wait_for_load_callback_; |
| }; |
| class ContentHandlerImpl : public mojo::InterfaceImpl<ContentHandler> { |
| @@ -142,13 +179,16 @@ class ContentHandlerImpl : public mojo::InterfaceImpl<ContentHandler> { |
| bool is_headless) |
| : compositor_thread_(compositor_thread), |
| web_media_player_factory_(web_media_player_factory), |
| - is_headless_(is_headless) {} |
| + is_headless_(is_headless) { |
| + printf("MSW ContentHandlerImpl::ContentHandlerImpl\n"); |
| + } |
| ~ContentHandlerImpl() override {} |
| private: |
| // Overridden from ContentHandler: |
| void StartApplication(InterfaceRequest<mojo::Application> request, |
| URLResponsePtr response) override { |
| + printf("MSW ContentHandlerImpl::StartApplication\n"); |
| new HTMLViewerApplication(request.Pass(), response.Pass(), |
| compositor_thread_, web_media_player_factory_, |
| is_headless_); |
| @@ -236,6 +276,7 @@ class HTMLViewer : public mojo::ApplicationDelegate, |
| // Overridden from InterfaceFactory<ContentHandler> |
| void Create(ApplicationConnection* connection, |
| mojo::InterfaceRequest<ContentHandler> request) override { |
| + printf("MSW HTMLViewer::Create (ContentHandler)\n"); |
| BindToRequest( |
| new ContentHandlerImpl(compositor_thread_.message_loop_proxy(), |
| web_media_player_factory_.get(), is_headless_), |
| @@ -262,6 +303,7 @@ class HTMLViewer : public mojo::ApplicationDelegate, |
| } // namespace html_viewer |
| MojoResult MojoMain(MojoHandle shell_handle) { |
| + printf("MSW MojoMain\n"); |
| mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer); |
| return runner.Run(shell_handle); |
| } |