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> | 5 #include <utility> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "mojo/application/content_handler_factory.h" | 8 #include "mojo/application/content_handler_factory.h" |
10 #include "mojo/data_pipe_utils/data_pipe_utils.h" | 9 #include "mojo/data_pipe_utils/data_pipe_utils.h" |
11 #include "mojo/environment/scoped_chromium_init.h" | 10 #include "mojo/environment/scoped_chromium_init.h" |
12 #include "mojo/public/c/system/main.h" | 11 #include "mojo/public/c/system/main.h" |
13 #include "mojo/public/cpp/application/application_impl_base.h" | 12 #include "mojo/public/cpp/application/application_impl_base.h" |
14 #include "mojo/public/cpp/application/run_application.h" | 13 #include "mojo/public/cpp/application/run_application.h" |
15 #include "mojo/public/cpp/application/service_provider_impl.h" | 14 #include "mojo/public/cpp/application/service_provider_impl.h" |
16 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
17 #include "mojo/public/cpp/utility/run_loop.h" | 16 #include "mojo/public/cpp/utility/run_loop.h" |
18 #include "mojo/public/interfaces/application/application.mojom.h" | 17 #include "mojo/public/interfaces/application/application.mojom.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 56 |
58 private: | 57 private: |
59 // Overridden from ApplicationImplBase: | 58 // Overridden from ApplicationImplBase: |
60 bool OnAcceptConnection(ServiceProviderImpl* service_provider_impl) override { | 59 bool OnAcceptConnection(ServiceProviderImpl* service_provider_impl) override { |
61 service_provider_impl->AddService<ContentHandler>( | 60 service_provider_impl->AddService<ContentHandler>( |
62 ContentHandlerFactory::GetInterfaceRequestHandler(this)); | 61 ContentHandlerFactory::GetInterfaceRequestHandler(this)); |
63 return true; | 62 return true; |
64 } | 63 } |
65 | 64 |
66 // Overridden from ContentHandlerFactory::ManagedDelegate: | 65 // Overridden from ContentHandlerFactory::ManagedDelegate: |
67 scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> | 66 std::unique_ptr<ContentHandlerFactory::HandledApplicationHolder> |
68 CreateApplication(InterfaceRequest<Application> application_request, | 67 CreateApplication(InterfaceRequest<Application> application_request, |
69 URLResponsePtr response) override { | 68 URLResponsePtr response) override { |
70 CHECK(!response.is_null()); | 69 CHECK(!response.is_null()); |
71 const std::string requestor_url(response->url); | 70 const std::string requestor_url(response->url); |
72 std::string target_url; | 71 std::string target_url; |
73 if (!common::BlockingCopyToString(response->body.Pass(), &target_url)) { | 72 if (!common::BlockingCopyToString(response->body.Pass(), &target_url)) { |
74 LOG(WARNING) << "unable to read target URL from " << requestor_url; | 73 LOG(WARNING) << "unable to read target URL from " << requestor_url; |
75 return nullptr; | 74 return nullptr; |
76 } | 75 } |
77 return make_handled_factory_holder( | 76 return make_handled_factory_holder( |
78 new ForwardingApplicationImpl(application_request.Pass(), target_url)); | 77 new ForwardingApplicationImpl(application_request.Pass(), target_url)); |
79 } | 78 } |
80 | 79 |
81 DISALLOW_COPY_AND_ASSIGN(ForwardingContentHandler); | 80 DISALLOW_COPY_AND_ASSIGN(ForwardingContentHandler); |
82 }; | 81 }; |
83 | 82 |
84 } // namespace examples | 83 } // namespace examples |
85 } // namespace mojo | 84 } // namespace mojo |
86 | 85 |
87 MojoResult MojoMain(MojoHandle application_request) { | 86 MojoResult MojoMain(MojoHandle application_request) { |
88 mojo::ScopedChromiumInit init; | 87 mojo::ScopedChromiumInit init; |
89 mojo::examples::ForwardingContentHandler forwarding_content_handler; | 88 mojo::examples::ForwardingContentHandler forwarding_content_handler; |
90 return mojo::RunApplication(application_request, &forwarding_content_handler); | 89 return mojo::RunApplication(application_request, &forwarding_content_handler); |
91 } | 90 } |
OLD | NEW |