| 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 <dlfcn.h> | 5 #include <dlfcn.h> |
| 6 #include <python2.7/Python.h> | 6 #include <python2.7/Python.h> |
| 7 | 7 |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/i18n/icu_util.h" | 10 #include "base/i18n/icu_util.h" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "mojo/application/application_runner_chromium.h" | |
| 14 #include "mojo/application/content_handler_factory.h" | 13 #include "mojo/application/content_handler_factory.h" |
| 15 #include "mojo/data_pipe_utils/data_pipe_utils.h" | 14 #include "mojo/data_pipe_utils/data_pipe_utils.h" |
| 16 #include "mojo/public/c/system/main.h" | 15 #include "mojo/public/c/system/main.h" |
| 17 #include "mojo/public/cpp/application/application_delegate.h" | 16 #include "mojo/public/cpp/application/application_impl_base.h" |
| 18 #include "mojo/public/cpp/application/application_impl.h" | 17 #include "mojo/public/cpp/application/run_application.h" |
| 19 #include "mojo/public/python/src/common.h" | 18 #include "mojo/public/python/src/common.h" |
| 20 #include "third_party/zlib/google/zip_reader.h" | 19 #include "third_party/zlib/google/zip_reader.h" |
| 21 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 22 | 21 |
| 23 char kMojoSystem[] = "mojo_system"; | 22 char kMojoSystem[] = "mojo_system"; |
| 24 char kMojoSystemImpl[] = "mojo_system_impl"; | 23 char kMojoSystemImpl[] = "mojo_system_impl"; |
| 25 char kMojoMain[] = "MojoMain"; | 24 char kMojoMain[] = "MojoMain"; |
| 26 | 25 |
| 27 extern "C" { | 26 extern "C" { |
| 28 void initmojo_system(); | 27 void initmojo_system(); |
| 29 void initmojo_system_impl(); | 28 void initmojo_system_impl(); |
| 30 } | 29 } |
| 31 | 30 |
| 32 namespace services { | 31 namespace services { |
| 33 namespace python { | 32 namespace python { |
| 34 namespace content_handler { | 33 namespace content_handler { |
| 35 | 34 |
| 36 using mojo::Application; | 35 using mojo::Application; |
| 37 using mojo::ApplicationDelegate; | 36 using mojo::ApplicationImplBase; |
| 38 using mojo::ContentHandlerFactory; | 37 using mojo::ContentHandlerFactory; |
| 39 using mojo::InterfaceRequest; | 38 using mojo::InterfaceRequest; |
| 40 using mojo::ScopedDataPipeConsumerHandle; | 39 using mojo::ScopedDataPipeConsumerHandle; |
| 41 using mojo::URLResponsePtr; | 40 using mojo::URLResponsePtr; |
| 42 using mojo::python::ScopedPyRef; | 41 using mojo::python::ScopedPyRef; |
| 43 | 42 |
| 44 class PythonContentHandler : public ContentHandlerFactory::Delegate { | 43 class PythonContentHandler : public ContentHandlerFactory::Delegate { |
| 45 public: | 44 public: |
| 46 PythonContentHandler(bool debug) : debug_(debug) {} | 45 PythonContentHandler(bool debug) : debug_(debug) {} |
| 47 | 46 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 bool result = mojo::common::BlockingCopyToString(body.Pass(), &body_str); | 193 bool result = mojo::common::BlockingCopyToString(body.Pass(), &body_str); |
| 195 DCHECK(result); | 194 DCHECK(result); |
| 196 return body_str; | 195 return body_str; |
| 197 } | 196 } |
| 198 | 197 |
| 199 bool debug_; | 198 bool debug_; |
| 200 | 199 |
| 201 DISALLOW_COPY_AND_ASSIGN(PythonContentHandler); | 200 DISALLOW_COPY_AND_ASSIGN(PythonContentHandler); |
| 202 }; | 201 }; |
| 203 | 202 |
| 204 class PythonContentHandlerApp : public ApplicationDelegate { | 203 class PythonContentHandlerApp : public ApplicationImplBase { |
| 205 public: | 204 public: |
| 206 PythonContentHandlerApp() | 205 PythonContentHandlerApp() |
| 207 : content_handler_(false), debug_content_handler_(true) {} | 206 : content_handler_(false), debug_content_handler_(true) {} |
| 208 | 207 |
| 209 private: | 208 private: |
| 210 // Overridden from ApplicationDelegate: | 209 // Overridden from ApplicationImplBase: |
| 211 bool ConfigureIncomingConnection( | 210 bool OnAcceptConnection( |
| 212 mojo::ServiceProviderImpl* service_provider_impl) override { | 211 mojo::ServiceProviderImpl* service_provider_impl) override { |
| 213 if (IsDebug(service_provider_impl->connection_context().connection_url)) { | 212 if (IsDebug(service_provider_impl->connection_context().connection_url)) { |
| 214 service_provider_impl->AddService<mojo::ContentHandler>( | 213 service_provider_impl->AddService<mojo::ContentHandler>( |
| 215 ContentHandlerFactory::GetInterfaceRequestHandler( | 214 ContentHandlerFactory::GetInterfaceRequestHandler( |
| 216 &debug_content_handler_)); | 215 &debug_content_handler_)); |
| 217 } else { | 216 } else { |
| 218 service_provider_impl->AddService<mojo::ContentHandler>( | 217 service_provider_impl->AddService<mojo::ContentHandler>( |
| 219 ContentHandlerFactory::GetInterfaceRequestHandler(&content_handler_)); | 218 ContentHandlerFactory::GetInterfaceRequestHandler(&content_handler_)); |
| 220 } | 219 } |
| 221 return true; | 220 return true; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 236 PythonContentHandler debug_content_handler_; | 235 PythonContentHandler debug_content_handler_; |
| 237 | 236 |
| 238 DISALLOW_COPY_AND_ASSIGN(PythonContentHandlerApp); | 237 DISALLOW_COPY_AND_ASSIGN(PythonContentHandlerApp); |
| 239 }; | 238 }; |
| 240 | 239 |
| 241 } // namespace content_handler | 240 } // namespace content_handler |
| 242 } // namespace python | 241 } // namespace python |
| 243 } // namespace services | 242 } // namespace services |
| 244 | 243 |
| 245 MojoResult MojoMain(MojoHandle application_request) { | 244 MojoResult MojoMain(MojoHandle application_request) { |
| 246 mojo::ApplicationRunnerChromium runner( | 245 services::python::content_handler::PythonContentHandlerApp |
| 247 new services::python::content_handler::PythonContentHandlerApp()); | 246 python_content_handler_app; |
| 248 return runner.Run(application_request); | 247 return mojo::RunMainApplication(application_request, |
| 248 &python_content_handler_app); |
| 249 } | 249 } |
| OLD | NEW |