| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 if (result == nullptr) { | 92 if (result == nullptr) { |
| 93 LOG(ERROR) << "Error while configuring path"; | 93 LOG(ERROR) << "Error while configuring path"; |
| 94 PyErr_Print(); | 94 PyErr_Print(); |
| 95 return NULL; | 95 return NULL; |
| 96 } | 96 } |
| 97 | 97 |
| 98 return d; | 98 return d; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Overridden from ContentHandlerFactory::ManagedDelegate: | 101 // Overridden from ContentHandlerFactory::ManagedDelegate: |
| 102 void RunApplication(ShellPtr shell, URLResponsePtr response) override { | 102 void RunApplication(InterfaceRequest<Application> application_request, |
| 103 URLResponsePtr response) override { |
| 103 std::unique_ptr<base::ScopedTempDir> temp_dir = | 104 std::unique_ptr<base::ScopedTempDir> temp_dir = |
| 104 ExtractApplication(response.Pass()); | 105 ExtractApplication(response.Pass()); |
| 105 base::FilePath directory_path = temp_dir->path(); | 106 base::FilePath directory_path = temp_dir->path(); |
| 106 | 107 |
| 107 PyObject* d = SetupPythonEnvironment(directory_path.value()); | 108 PyObject* d = SetupPythonEnvironment(directory_path.value()); |
| 108 DCHECK(d); | 109 DCHECK(d); |
| 109 | 110 |
| 110 base::FilePath entry_path = directory_path.Append("__mojo__.py"); | 111 base::FilePath entry_path = directory_path.Append("__mojo__.py"); |
| 111 | 112 |
| 112 FILE* entry_file = base::OpenFile(entry_path, "r"); | 113 FILE* entry_file = base::OpenFile(entry_path, "r"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 128 ScopedPyRef py_function(PyMapping_GetItemString(d, kMojoMain)); | 129 ScopedPyRef py_function(PyMapping_GetItemString(d, kMojoMain)); |
| 129 | 130 |
| 130 if (py_function == NULL) { | 131 if (py_function == NULL) { |
| 131 LOG(ERROR) << "Locals size: " << PyMapping_Size(d); | 132 LOG(ERROR) << "Locals size: " << PyMapping_Size(d); |
| 132 LOG(ERROR) << "MojoMain not found"; | 133 LOG(ERROR) << "MojoMain not found"; |
| 133 PyErr_Print(); | 134 PyErr_Print(); |
| 134 return; | 135 return; |
| 135 } | 136 } |
| 136 | 137 |
| 137 if (PyCallable_Check(py_function)) { | 138 if (PyCallable_Check(py_function)) { |
| 138 MojoHandle shell_handle = shell.PassMessagePipe().release().value(); | 139 MojoHandle application_request_handle = |
| 139 ScopedPyRef py_input(PyInt_FromLong(shell_handle)); | 140 application_request.PassMessagePipe().release().value(); |
| 141 ScopedPyRef py_input(PyInt_FromLong(application_request_handle)); |
| 140 ScopedPyRef py_arguments(PyTuple_New(1)); | 142 ScopedPyRef py_arguments(PyTuple_New(1)); |
| 141 // py_input reference is stolen by py_arguments | 143 // py_input reference is stolen by py_arguments |
| 142 PyTuple_SetItem(py_arguments, 0, py_input.Release()); | 144 PyTuple_SetItem(py_arguments, 0, py_input.Release()); |
| 143 // Run MojoMain with shell_handle as the first and only argument. | 145 // Run MojoMain with application_request_handle as the first and only |
| 146 // argument. |
| 144 ScopedPyRef py_output(PyObject_CallObject(py_function, py_arguments)); | 147 ScopedPyRef py_output(PyObject_CallObject(py_function, py_arguments)); |
| 145 | 148 |
| 146 if (!py_output) { | 149 if (!py_output) { |
| 147 LOG(ERROR) << "Error while executing MojoMain"; | 150 LOG(ERROR) << "Error while executing MojoMain"; |
| 148 PyErr_Print(); | 151 PyErr_Print(); |
| 149 return; | 152 return; |
| 150 } | 153 } |
| 151 } else { | 154 } else { |
| 152 LOG(ERROR) << "MojoMain is not callable; it should be a function"; | 155 LOG(ERROR) << "MojoMain is not callable; it should be a function"; |
| 153 } | 156 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 168 }; | 171 }; |
| 169 | 172 |
| 170 } // namespace python | 173 } // namespace python |
| 171 } // namespace mojo | 174 } // namespace mojo |
| 172 | 175 |
| 173 MojoResult MojoMain(MojoHandle shell_handle) { | 176 MojoResult MojoMain(MojoHandle shell_handle) { |
| 174 mojo::ApplicationRunnerChromium runner( | 177 mojo::ApplicationRunnerChromium runner( |
| 175 new mojo::python::PythonContentHandler()); | 178 new mojo::python::PythonContentHandler()); |
| 176 return runner.Run(shell_handle); | 179 return runner.Run(shell_handle); |
| 177 } | 180 } |
| OLD | NEW |