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 <python2.7/Python.h> | 5 #include <python2.7/Python.h> |
6 #include <dlfcn.h> | 6 #include <dlfcn.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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 char kMojoSystem[] = "mojo_system"; | 22 char kMojoSystem[] = "mojo_system"; |
23 char kMojoSystemImpl[] = "mojo_system_impl"; | 23 char kMojoSystemImpl[] = "mojo_system_impl"; |
24 char kMojoMain[] = "MojoMain"; | 24 char kMojoMain[] = "MojoMain"; |
25 | 25 |
26 extern "C" { | 26 extern "C" { |
27 void initmojo_system(); | 27 void initmojo_system(); |
28 void initmojo_system_impl(); | 28 void initmojo_system_impl(); |
29 } | 29 } |
30 | 30 |
31 namespace mojo { | 31 namespace services { |
32 namespace python { | 32 namespace python { |
| 33 namespace content_handler { |
| 34 |
| 35 using mojo::Application; |
| 36 using mojo::ApplicationConnection; |
| 37 using mojo::ApplicationDelegate; |
| 38 using mojo::ContentHandlerFactory; |
| 39 using mojo::InterfaceRequest; |
| 40 using mojo::ScopedDataPipeConsumerHandle; |
| 41 using mojo::URLResponsePtr; |
| 42 using mojo::python::ScopedPyRef; |
33 | 43 |
34 class PythonContentHandler : public ApplicationDelegate, | 44 class PythonContentHandler : public ApplicationDelegate, |
35 public ContentHandlerFactory::Delegate { | 45 public ContentHandlerFactory::Delegate { |
36 public: | 46 public: |
37 PythonContentHandler() : content_handler_factory_(this) {} | 47 PythonContentHandler() : content_handler_factory_(this) {} |
38 | 48 |
39 private: | 49 private: |
40 // Overridden from ApplicationDelegate: | 50 // Overridden from ApplicationDelegate: |
41 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 51 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
42 connection->AddService(&content_handler_factory_); | 52 connection->AddService(&content_handler_factory_); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 163 } |
154 } else { | 164 } else { |
155 LOG(ERROR) << "MojoMain is not callable; it should be a function"; | 165 LOG(ERROR) << "MojoMain is not callable; it should be a function"; |
156 } | 166 } |
157 } | 167 } |
158 Py_Finalize(); | 168 Py_Finalize(); |
159 } | 169 } |
160 | 170 |
161 std::string CopyToString(ScopedDataPipeConsumerHandle body) { | 171 std::string CopyToString(ScopedDataPipeConsumerHandle body) { |
162 std::string body_str; | 172 std::string body_str; |
163 bool result = common::BlockingCopyToString(body.Pass(), &body_str); | 173 bool result = mojo::common::BlockingCopyToString(body.Pass(), &body_str); |
164 DCHECK(result); | 174 DCHECK(result); |
165 return body_str; | 175 return body_str; |
166 } | 176 } |
167 | 177 |
168 ContentHandlerFactory content_handler_factory_; | 178 ContentHandlerFactory content_handler_factory_; |
169 | 179 |
170 DISALLOW_COPY_AND_ASSIGN(PythonContentHandler); | 180 DISALLOW_COPY_AND_ASSIGN(PythonContentHandler); |
171 }; | 181 }; |
172 | 182 |
| 183 } // namespace content_handler |
173 } // namespace python | 184 } // namespace python |
174 } // namespace mojo | 185 } // namespace services |
175 | 186 |
176 MojoResult MojoMain(MojoHandle shell_handle) { | 187 MojoResult MojoMain(MojoHandle shell_handle) { |
177 mojo::ApplicationRunnerChromium runner( | 188 mojo::ApplicationRunnerChromium runner( |
178 new mojo::python::PythonContentHandler()); | 189 new services::python::content_handler::PythonContentHandler()); |
179 return runner.Run(shell_handle); | 190 return runner.Run(shell_handle); |
180 } | 191 } |
OLD | NEW |