| 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 <utility> |
| 6 |
| 5 #include "base/macros.h" | 7 #include "base/macros.h" |
| 6 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 7 #include "mojo/application/application_runner_chromium.h" | 9 #include "mojo/application/application_runner_chromium.h" |
| 8 #include "mojo/application/content_handler_factory.h" | 10 #include "mojo/application/content_handler_factory.h" |
| 9 #include "mojo/data_pipe_utils/data_pipe_utils.h" | 11 #include "mojo/data_pipe_utils/data_pipe_utils.h" |
| 10 #include "mojo/public/c/system/main.h" | 12 #include "mojo/public/c/system/main.h" |
| 11 #include "mojo/public/cpp/application/application_connection.h" | 13 #include "mojo/public/cpp/application/application_connection.h" |
| 12 #include "mojo/public/cpp/application/application_delegate.h" | 14 #include "mojo/public/cpp/application/application_delegate.h" |
| 13 #include "mojo/public/cpp/application/interface_factory_impl.h" | 15 #include "mojo/public/cpp/application/interface_factory_impl.h" |
| 14 #include "mojo/public/cpp/bindings/binding.h" | 16 #include "mojo/public/cpp/bindings/binding.h" |
| 15 #include "mojo/public/cpp/utility/run_loop.h" | 17 #include "mojo/public/cpp/utility/run_loop.h" |
| 16 #include "mojo/public/interfaces/application/application.mojom.h" | 18 #include "mojo/public/interfaces/application/application.mojom.h" |
| 17 #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" | 19 #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" |
| 18 | 20 |
| 19 namespace mojo { | 21 namespace mojo { |
| 20 namespace examples { | 22 namespace examples { |
| 21 | 23 |
| 22 class ForwardingApplicationImpl : public Application { | 24 class ForwardingApplicationImpl : public Application { |
| 23 public: | 25 public: |
| 24 ForwardingApplicationImpl(InterfaceRequest<Application> request, | 26 ForwardingApplicationImpl(InterfaceRequest<Application> request, |
| 25 std::string target_url) | 27 std::string target_url) |
| 26 : binding_(this, request.Pass()), | 28 : binding_(this, request.Pass()), |
| 27 target_url_(target_url) { | 29 target_url_(target_url) { |
| 28 } | 30 } |
| 29 | 31 |
| 30 private: | 32 private: |
| 31 // Application: | 33 // Application: |
| 32 void Initialize(ShellPtr shell, | 34 void Initialize(InterfaceHandle<Shell> shell, |
| 33 Array<String> args, | 35 Array<String> args, |
| 34 const mojo::String& url) override { | 36 const mojo::String& url) override { |
| 35 shell_ = shell.Pass(); | 37 shell_ = ShellPtr::Create(std::move(shell)); |
| 36 } | 38 } |
| 37 void AcceptConnection(const String& requestor_url, | 39 void AcceptConnection(const String& requestor_url, |
| 38 InterfaceRequest<ServiceProvider> services, | 40 InterfaceRequest<ServiceProvider> services, |
| 39 ServiceProviderPtr exposed_services, | 41 InterfaceHandle<ServiceProvider> exposed_services, |
| 40 const String& requested_url) override { | 42 const String& requested_url) override { |
| 41 shell_->ConnectToApplication(target_url_, services.Pass(), | 43 shell_->ConnectToApplication(target_url_, services.Pass(), |
| 42 exposed_services.Pass()); | 44 exposed_services.Pass()); |
| 43 } | 45 } |
| 44 void RequestQuit() override { | 46 void RequestQuit() override { |
| 45 RunLoop::current()->Quit(); | 47 RunLoop::current()->Quit(); |
| 46 } | 48 } |
| 47 | 49 |
| 48 Binding<Application> binding_; | 50 Binding<Application> binding_; |
| 49 std::string target_url_; | 51 std::string target_url_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 return true; | 64 return true; |
| 63 } | 65 } |
| 64 | 66 |
| 65 // Overridden from ContentHandlerFactory::ManagedDelegate: | 67 // Overridden from ContentHandlerFactory::ManagedDelegate: |
| 66 scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> | 68 scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> |
| 67 CreateApplication(InterfaceRequest<Application> application_request, | 69 CreateApplication(InterfaceRequest<Application> application_request, |
| 68 URLResponsePtr response) override { | 70 URLResponsePtr response) override { |
| 69 CHECK(!response.is_null()); | 71 CHECK(!response.is_null()); |
| 70 const std::string requestor_url(response->url); | 72 const std::string requestor_url(response->url); |
| 71 std::string target_url; | 73 std::string target_url; |
| 72 if(!common::BlockingCopyToString(response->body.Pass(), &target_url)) { | 74 if (!common::BlockingCopyToString(response->body.Pass(), &target_url)) { |
| 73 LOG(WARNING) << "unable to read target URL from " << requestor_url; | 75 LOG(WARNING) << "unable to read target URL from " << requestor_url; |
| 74 return nullptr; | 76 return nullptr; |
| 75 } | 77 } |
| 76 return make_handled_factory_holder( | 78 return make_handled_factory_holder( |
| 77 new ForwardingApplicationImpl(application_request.Pass(), target_url)); | 79 new ForwardingApplicationImpl(application_request.Pass(), target_url)); |
| 78 } | 80 } |
| 79 | 81 |
| 80 ContentHandlerFactory content_handler_factory_; | 82 ContentHandlerFactory content_handler_factory_; |
| 81 | 83 |
| 82 DISALLOW_COPY_AND_ASSIGN(ForwardingContentHandler); | 84 DISALLOW_COPY_AND_ASSIGN(ForwardingContentHandler); |
| 83 }; | 85 }; |
| 84 | 86 |
| 85 } // namespace examples | 87 } // namespace examples |
| 86 } // namespace mojo | 88 } // namespace mojo |
| 87 | 89 |
| 88 MojoResult MojoMain(MojoHandle application_request) { | 90 MojoResult MojoMain(MojoHandle application_request) { |
| 89 mojo::ApplicationRunnerChromium runner( | 91 mojo::ApplicationRunnerChromium runner( |
| 90 new mojo::examples::ForwardingContentHandler()); | 92 new mojo::examples::ForwardingContentHandler()); |
| 91 return runner.Run(application_request); | 93 return runner.Run(application_request); |
| 92 } | 94 } |
| OLD | NEW |