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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "mojo/application/application_runner_chromium.h" | 7 #include "mojo/application/application_runner_chromium.h" |
8 #include "mojo/application/content_handler_factory.h" | 8 #include "mojo/application/content_handler_factory.h" |
9 #include "mojo/common/data_pipe_utils.h" | 9 #include "mojo/common/data_pipe_utils.h" |
10 #include "mojo/public/c/system/main.h" | 10 #include "mojo/public/c/system/main.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 ShellPtr shell_; | 50 ShellPtr shell_; |
51 }; | 51 }; |
52 | 52 |
53 class ForwardingContentHandler : public ApplicationDelegate, | 53 class ForwardingContentHandler : public ApplicationDelegate, |
54 public ContentHandlerFactory::ManagedDelegate { | 54 public ContentHandlerFactory::ManagedDelegate { |
55 public: | 55 public: |
56 ForwardingContentHandler() : content_handler_factory_(this) {} | 56 ForwardingContentHandler() : content_handler_factory_(this) {} |
57 | 57 |
58 private: | 58 private: |
59 // Overridden from ApplicationDelegate: | 59 // Overridden from ApplicationDelegate: |
60 virtual bool ConfigureIncomingConnection( | 60 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
61 ApplicationConnection* connection) override { | |
62 connection->AddService(&content_handler_factory_); | 61 connection->AddService(&content_handler_factory_); |
63 return true; | 62 return true; |
64 } | 63 } |
65 | 64 |
66 // Overridden from ContentHandlerFactory::ManagedDelegate: | 65 // Overridden from ContentHandlerFactory::ManagedDelegate: |
67 virtual scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> | 66 scoped_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 ContentHandlerFactory content_handler_factory_; | 80 ContentHandlerFactory content_handler_factory_; |
82 | 81 |
83 DISALLOW_COPY_AND_ASSIGN(ForwardingContentHandler); | 82 DISALLOW_COPY_AND_ASSIGN(ForwardingContentHandler); |
84 }; | 83 }; |
85 | 84 |
86 } // namespace examples | 85 } // namespace examples |
87 } // namespace mojo | 86 } // namespace mojo |
88 | 87 |
89 MojoResult MojoMain(MojoHandle shell_handle) { | 88 MojoResult MojoMain(MojoHandle shell_handle) { |
90 mojo::ApplicationRunnerChromium runner( | 89 mojo::ApplicationRunnerChromium runner( |
91 new mojo::examples::ForwardingContentHandler()); | 90 new mojo::examples::ForwardingContentHandler()); |
92 return runner.Run(shell_handle); | 91 return runner.Run(shell_handle); |
93 } | 92 } |
OLD | NEW |