| 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 "services/js/js_app.h" | 5 #include "services/js/js_app.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "gin/converter.h" | 9 #include "gin/converter.h" |
| 10 #include "gin/modules/module_registry.h" | 10 #include "gin/modules/module_registry.h" |
| 11 #include "gin/try_catch.h" | 11 #include "gin/try_catch.h" |
| 12 #include "mojo/common/data_pipe_utils.h" | 12 #include "mojo/common/data_pipe_utils.h" |
| 13 #include "mojo/edk/js/core.h" | 13 #include "mojo/edk/js/core.h" |
| 14 #include "mojo/edk/js/handle.h" | 14 #include "mojo/edk/js/handle.h" |
| 15 #include "mojo/edk/js/support.h" | 15 #include "mojo/edk/js/support.h" |
| 16 #include "mojo/public/cpp/bindings/interface_request.h" | 16 #include "mojo/public/cpp/bindings/interface_request.h" |
| 17 #include "services/js/js_app_message_loop_observers.h" | 17 #include "services/js/js_app_message_loop_observers.h" |
| 18 | 18 |
| 19 namespace js { | 19 namespace js { |
| 20 | 20 |
| 21 const char JSApp::kMainModuleName[] = "main"; | 21 const char JSApp::kMainModuleName[] = "main"; |
| 22 | 22 |
| 23 JSApp::JSApp(mojo::ShellPtr shell, mojo::URLResponsePtr response) | 23 JSApp::JSApp(mojo::InterfaceRequest<mojo::Application> application_request, |
| 24 : shell_(shell.Pass()) { | 24 mojo::URLResponsePtr response) |
| 25 : application_request_(application_request.Pass()) { |
| 25 v8::Isolate* isolate = isolate_holder_.isolate(); | 26 v8::Isolate* isolate = isolate_holder_.isolate(); |
| 26 message_loop_observers_.reset(new JSAppMessageLoopObservers(isolate)); | 27 message_loop_observers_.reset(new JSAppMessageLoopObservers(isolate)); |
| 27 | 28 |
| 28 DCHECK(!response.is_null()); | 29 DCHECK(!response.is_null()); |
| 29 std::string url(response->url); | 30 std::string url(response->url); |
| 30 std::string source; | 31 std::string source; |
| 31 CHECK(mojo::common::BlockingCopyToString(response->body.Pass(), &source)); | 32 CHECK(mojo::common::BlockingCopyToString(response->body.Pass(), &source)); |
| 32 | 33 |
| 33 shell_runner_.reset(new gin::ShellRunner(&runner_delegate_, isolate)); | 34 shell_runner_.reset(new gin::ShellRunner(&runner_delegate_, isolate)); |
| 34 gin::Runner::Scope scope(shell_runner_.get()); | 35 gin::Runner::Scope scope(shell_runner_.get()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 45 JSApp::~JSApp() { | 46 JSApp::~JSApp() { |
| 46 app_instance_.Reset(); | 47 app_instance_.Reset(); |
| 47 } | 48 } |
| 48 | 49 |
| 49 void JSApp::OnAppLoaded(std::string url, v8::Handle<v8::Value> main_module) { | 50 void JSApp::OnAppLoaded(std::string url, v8::Handle<v8::Value> main_module) { |
| 50 gin::Runner::Scope scope(shell_runner_.get()); | 51 gin::Runner::Scope scope(shell_runner_.get()); |
| 51 gin::TryCatch try_catch; | 52 gin::TryCatch try_catch; |
| 52 v8::Isolate* isolate = isolate_holder_.isolate(); | 53 v8::Isolate* isolate = isolate_holder_.isolate(); |
| 53 | 54 |
| 54 v8::Handle<v8::Value> argv[] = { | 55 v8::Handle<v8::Value> argv[] = { |
| 55 gin::ConvertToV8(isolate, shell_.PassMessagePipe().release()), | 56 gin::ConvertToV8(isolate, |
| 56 gin::ConvertToV8(isolate, url) | 57 application_request_.PassMessagePipe().release()), |
| 57 }; | 58 gin::ConvertToV8(isolate, url)}; |
| 58 | 59 |
| 59 v8::Handle<v8::Function> app_class; | 60 v8::Handle<v8::Function> app_class; |
| 60 CHECK(gin::ConvertFromV8(isolate, main_module, &app_class)); | 61 CHECK(gin::ConvertFromV8(isolate, main_module, &app_class)); |
| 61 app_instance_.Reset(isolate, app_class->NewInstance(arraysize(argv), argv)); | 62 app_instance_.Reset(isolate, app_class->NewInstance(arraysize(argv), argv)); |
| 62 if (try_catch.HasCaught()) | 63 if (try_catch.HasCaught()) |
| 63 runner_delegate_.UnhandledException(shell_runner_.get(), try_catch); | 64 runner_delegate_.UnhandledException(shell_runner_.get(), try_catch); |
| 64 } | 65 } |
| 65 | 66 |
| 66 } // namespace js | 67 } // namespace js |
| 67 | 68 |
| OLD | NEW |