| 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 "sky/viewer/content_handler_impl.h" | 5 #include "sky/viewer/content_handler_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "mojo/public/cpp/application/connect.h" | 8 #include "mojo/public/cpp/application/connect.h" |
| 9 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 9 #include "mojo/public/cpp/utility/run_loop.h" | 10 #include "mojo/public/cpp/utility/run_loop.h" |
| 10 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 11 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| 11 #include "sky/viewer/document_view.h" | 12 #include "sky/viewer/document_view.h" |
| 12 | 13 |
| 13 namespace sky { | 14 namespace sky { |
| 14 | 15 |
| 15 class SkyApplication : public mojo::Application { | 16 class SkyApplication : public mojo::Application { |
| 16 public: | 17 public: |
| 17 SkyApplication(mojo::ShellPtr shell, | 18 SkyApplication(mojo::InterfaceRequest<mojo::Application> application, |
| 18 mojo::URLResponsePtr response) | 19 mojo::URLResponsePtr response) |
| 19 : url_(response->url), | 20 : url_(response->url), |
| 20 shell_(shell.Pass()), | 21 binding_(this, application.Pass()), |
| 21 initial_response_(response.Pass()) { | 22 initial_response_(response.Pass()) {} |
| 22 shell_.set_client(this); | 23 |
| 24 void Initialize(mojo::ShellPtr shell, |
| 25 mojo::Array<mojo::String> args) override { |
| 26 shell_ = shell.Pass(); |
| 23 mojo::ServiceProviderPtr service_provider; | 27 mojo::ServiceProviderPtr service_provider; |
| 24 shell_->ConnectToApplication("mojo:network_service", | 28 shell_->ConnectToApplication("mojo:network_service", |
| 25 mojo::GetProxy(&service_provider), nullptr); | 29 mojo::GetProxy(&service_provider), nullptr); |
| 26 mojo::ConnectToService(service_provider.get(), &network_service_); | 30 mojo::ConnectToService(service_provider.get(), &network_service_); |
| 27 } | 31 } |
| 28 | 32 |
| 29 void Initialize(mojo::Array<mojo::String> args) override {} | |
| 30 | |
| 31 void AcceptConnection(const mojo::String& requestor_url, | 33 void AcceptConnection(const mojo::String& requestor_url, |
| 32 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 34 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 33 mojo::ServiceProviderPtr exposed_services) override { | 35 mojo::ServiceProviderPtr exposed_services) override { |
| 34 if (initial_response_) { | 36 if (initial_response_) { |
| 35 OnResponseReceived(mojo::URLLoaderPtr(), services.Pass(), | 37 OnResponseReceived(mojo::URLLoaderPtr(), services.Pass(), |
| 36 exposed_services.Pass(), initial_response_.Pass()); | 38 exposed_services.Pass(), initial_response_.Pass()); |
| 37 } else { | 39 } else { |
| 38 mojo::URLLoaderPtr loader; | 40 mojo::URLLoaderPtr loader; |
| 39 network_service_->CreateURLLoader(mojo::GetProxy(&loader)); | 41 network_service_->CreateURLLoader(mojo::GetProxy(&loader)); |
| 40 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 42 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 61 void OnResponseReceived( | 63 void OnResponseReceived( |
| 62 mojo::URLLoaderPtr loader, | 64 mojo::URLLoaderPtr loader, |
| 63 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 65 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 64 mojo::ServiceProviderPtr exposed_services, | 66 mojo::ServiceProviderPtr exposed_services, |
| 65 mojo::URLResponsePtr response) { | 67 mojo::URLResponsePtr response) { |
| 66 new DocumentView(services.Pass(), exposed_services.Pass(), response.Pass(), | 68 new DocumentView(services.Pass(), exposed_services.Pass(), response.Pass(), |
| 67 shell_.get()); | 69 shell_.get()); |
| 68 } | 70 } |
| 69 | 71 |
| 70 mojo::String url_; | 72 mojo::String url_; |
| 73 mojo::StrongBinding<mojo::Application> binding_; |
| 71 mojo::ShellPtr shell_; | 74 mojo::ShellPtr shell_; |
| 72 mojo::NetworkServicePtr network_service_; | 75 mojo::NetworkServicePtr network_service_; |
| 73 mojo::URLResponsePtr initial_response_; | 76 mojo::URLResponsePtr initial_response_; |
| 74 }; | 77 }; |
| 75 | 78 |
| 76 ContentHandlerImpl::ContentHandlerImpl() { | 79 ContentHandlerImpl::ContentHandlerImpl() { |
| 77 } | 80 } |
| 78 | 81 |
| 79 ContentHandlerImpl::~ContentHandlerImpl() { | 82 ContentHandlerImpl::~ContentHandlerImpl() { |
| 80 } | 83 } |
| 81 | 84 |
| 82 void ContentHandlerImpl::StartApplication(mojo::ShellPtr shell, | 85 void ContentHandlerImpl::StartApplication( |
| 83 mojo::URLResponsePtr response) { | 86 mojo::InterfaceRequest<mojo::Application> application, |
| 84 new SkyApplication(shell.Pass(), response.Pass()); | 87 mojo::URLResponsePtr response) { |
| 88 new SkyApplication(application.Pass(), response.Pass()); |
| 85 } | 89 } |
| 86 | 90 |
| 87 } // namespace sky | 91 } // namespace sky |
| OLD | NEW |