| 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/services/network/public/interfaces/network_service.mojom.h" | 9 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| 10 #include "sky/viewer/document_view.h" | 10 #include "sky/viewer/document_view.h" |
| 11 | 11 |
| 12 namespace sky { | 12 namespace sky { |
| 13 | 13 |
| 14 class SkyApplication : public mojo::Application { | 14 class SkyApplication : public mojo::Application { |
| 15 public: | 15 public: |
| 16 SkyApplication(mojo::ShellPtr shell, | 16 SkyApplication(mojo::ShellPtr shell, |
| 17 mojo::URLResponsePtr response) | 17 mojo::URLResponsePtr response, |
| 18 bool is_testing) |
| 18 : url_(response->url), | 19 : url_(response->url), |
| 19 shell_(shell.Pass()), | 20 shell_(shell.Pass()), |
| 20 initial_response_(response.Pass()) { | 21 initial_response_(response.Pass()), |
| 22 is_testing_(is_testing) { |
| 21 shell_.set_client(this); | 23 shell_.set_client(this); |
| 22 mojo::ServiceProviderPtr service_provider; | 24 mojo::ServiceProviderPtr service_provider; |
| 23 shell_->ConnectToApplication("mojo:network_service", | 25 shell_->ConnectToApplication("mojo:network_service", |
| 24 mojo::GetProxy(&service_provider)); | 26 mojo::GetProxy(&service_provider)); |
| 25 mojo::ConnectToService(service_provider.get(), &network_service_); | 27 mojo::ConnectToService(service_provider.get(), &network_service_); |
| 26 } | 28 } |
| 27 | 29 |
| 28 void Initialize(mojo::Array<mojo::String> args) override {} | 30 void Initialize(mojo::Array<mojo::String> args) override {} |
| 29 | 31 |
| 30 void AcceptConnection(const mojo::String& requestor_url, | 32 void AcceptConnection(const mojo::String& requestor_url, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 48 base::Bind(&SkyApplication::OnResponseReceived, | 50 base::Bind(&SkyApplication::OnResponseReceived, |
| 49 base::Unretained(this), base::Passed(&loader), | 51 base::Unretained(this), base::Passed(&loader), |
| 50 base::Passed(&provider))); | 52 base::Passed(&provider))); |
| 51 } | 53 } |
| 52 } | 54 } |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 void OnResponseReceived(mojo::URLLoaderPtr loader, | 57 void OnResponseReceived(mojo::URLLoaderPtr loader, |
| 56 mojo::ServiceProviderPtr provider, | 58 mojo::ServiceProviderPtr provider, |
| 57 mojo::URLResponsePtr response) { | 59 mojo::URLResponsePtr response) { |
| 58 new DocumentView(provider.Pass(), response.Pass(), shell_.get()); | 60 new DocumentView(provider.Pass(), response.Pass(), shell_.get(), |
| 61 is_testing_); |
| 59 } | 62 } |
| 60 | 63 |
| 61 mojo::String url_; | 64 mojo::String url_; |
| 62 mojo::ShellPtr shell_; | 65 mojo::ShellPtr shell_; |
| 63 mojo::NetworkServicePtr network_service_; | 66 mojo::NetworkServicePtr network_service_; |
| 64 mojo::URLResponsePtr initial_response_; | 67 mojo::URLResponsePtr initial_response_; |
| 68 bool is_testing_; |
| 65 }; | 69 }; |
| 66 | 70 |
| 67 ContentHandlerImpl::ContentHandlerImpl() { | 71 ContentHandlerImpl::ContentHandlerImpl(bool is_testing) { |
| 72 is_testing_ = is_testing; |
| 68 } | 73 } |
| 69 | 74 |
| 70 ContentHandlerImpl::~ContentHandlerImpl() { | 75 ContentHandlerImpl::~ContentHandlerImpl() { |
| 71 } | 76 } |
| 72 | 77 |
| 73 void ContentHandlerImpl::StartApplication(mojo::ShellPtr shell, | 78 void ContentHandlerImpl::StartApplication(mojo::ShellPtr shell, |
| 74 mojo::URLResponsePtr response) { | 79 mojo::URLResponsePtr response) { |
| 75 new SkyApplication(shell.Pass(), response.Pass()); | 80 new SkyApplication(shell.Pass(), response.Pass(), is_testing_); |
| 76 } | 81 } |
| 77 | 82 |
| 78 } // namespace sky | 83 } // namespace sky |
| OLD | NEW |