| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 #include "base/files/scoped_file.h" | 6 #include "base/files/scoped_file.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "mojo/application/application_runner_chromium.h" | 9 #include "mojo/application/application_runner_chromium.h" |
| 10 #include "mojo/application/content_handler_factory.h" | 10 #include "mojo/application/content_handler_factory.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 CHECK_EQ(fclose(file_stream), 0) << "Failed to close temp file"; | 67 CHECK_EQ(fclose(file_stream), 0) << "Failed to close temp file"; |
| 68 | 68 |
| 69 return desc; | 69 return desc; |
| 70 } | 70 } |
| 71 | 71 |
| 72 } // namespace | 72 } // namespace |
| 73 | 73 |
| 74 class NaClContentHandler : public mojo::ApplicationDelegate, | 74 class NaClContentHandler : public mojo::ApplicationDelegate, |
| 75 public mojo::ContentHandlerFactory::Delegate { | 75 public mojo::ContentHandlerFactory::Delegate { |
| 76 public: | 76 public: |
| 77 NaClContentHandler() : content_handler_factory_(this) {} | 77 NaClContentHandler() {} |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 // Overridden from ApplicationDelegate: | 80 // Overridden from ApplicationDelegate: |
| 81 void Initialize(mojo::ApplicationImpl* app) override { | 81 void Initialize(mojo::ApplicationImpl* app) override { |
| 82 url_ = GURL(app->url()); | 82 url_ = GURL(app->url()); |
| 83 | 83 |
| 84 mojo::NetworkServicePtr network_service; | 84 mojo::NetworkServicePtr network_service; |
| 85 mojo::ConnectToService(app->shell(), "mojo:network_service", | 85 mojo::ConnectToService(app->shell(), "mojo:network_service", |
| 86 GetProxy(&network_service)); | 86 GetProxy(&network_service)); |
| 87 | 87 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 99 CHECK(irt_url.is_valid()) << "Cannot resolve IRT URL"; | 99 CHECK(irt_url.is_valid()) << "Cannot resolve IRT URL"; |
| 100 | 100 |
| 101 irt_fp_ = TempFileForURL(url_loader, irt_url); | 101 irt_fp_ = TempFileForURL(url_loader, irt_url); |
| 102 CHECK(irt_fp_) << "Could not acquire the IRT"; | 102 CHECK(irt_fp_) << "Could not acquire the IRT"; |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Overridden from ApplicationDelegate: | 105 // Overridden from ApplicationDelegate: |
| 106 bool ConfigureIncomingConnection( | 106 bool ConfigureIncomingConnection( |
| 107 mojo::ServiceProviderImpl* service_provider_impl) override { | 107 mojo::ServiceProviderImpl* service_provider_impl) override { |
| 108 service_provider_impl->AddService<mojo::ContentHandler>( | 108 service_provider_impl->AddService<mojo::ContentHandler>( |
| 109 content_handler_factory_.GetInterfaceRequestHandler()); | 109 mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this)); |
| 110 return true; | 110 return true; |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Overridden from ContentHandlerFactory::Delegate: | 113 // Overridden from ContentHandlerFactory::Delegate: |
| 114 void RunApplication( | 114 void RunApplication( |
| 115 mojo::InterfaceRequest<mojo::Application> application_request, | 115 mojo::InterfaceRequest<mojo::Application> application_request, |
| 116 mojo::URLResponsePtr response) override { | 116 mojo::URLResponsePtr response) override { |
| 117 // Needed to use Mojo interfaces on this thread. | 117 // Needed to use Mojo interfaces on this thread. |
| 118 base::MessageLoop loop(mojo::common::MessagePumpMojo::Create()); | 118 base::MessageLoop loop(mojo::common::MessagePumpMojo::Create()); |
| 119 | 119 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 132 // Run. | 132 // Run. |
| 133 int exit_code = mojo::LaunchNaCl( | 133 int exit_code = mojo::LaunchNaCl( |
| 134 nexe_desc, irt_desc, 0, nullptr, | 134 nexe_desc, irt_desc, 0, nullptr, |
| 135 application_request.PassMessagePipe().release().value()); | 135 application_request.PassMessagePipe().release().value()); |
| 136 | 136 |
| 137 // Exits the process cleanly, does not return. | 137 // Exits the process cleanly, does not return. |
| 138 mojo::NaClExit(exit_code); | 138 mojo::NaClExit(exit_code); |
| 139 NOTREACHED(); | 139 NOTREACHED(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 mojo::ContentHandlerFactory content_handler_factory_; | |
| 143 GURL url_; | 142 GURL url_; |
| 144 base::ScopedFILE irt_fp_; | 143 base::ScopedFILE irt_fp_; |
| 145 | 144 |
| 146 mojo::URLLoaderPtr url_loader_; | 145 mojo::URLLoaderPtr url_loader_; |
| 147 | 146 |
| 148 DISALLOW_COPY_AND_ASSIGN(NaClContentHandler); | 147 DISALLOW_COPY_AND_ASSIGN(NaClContentHandler); |
| 149 }; | 148 }; |
| 150 | 149 |
| 151 } // namespace content_handler | 150 } // namespace content_handler |
| 152 } // namespace nacl | 151 } // namespace nacl |
| 153 | 152 |
| 154 MojoResult MojoMain(MojoHandle application_request) { | 153 MojoResult MojoMain(MojoHandle application_request) { |
| 155 mojo::ApplicationRunnerChromium runner( | 154 mojo::ApplicationRunnerChromium runner( |
| 156 new nacl::content_handler::NaClContentHandler()); | 155 new nacl::content_handler::NaClContentHandler()); |
| 157 return runner.Run(application_request); | 156 return runner.Run(application_request); |
| 158 } | 157 } |
| OLD | NEW |