| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/apps/js/js_app.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "gin/array_buffer.h" | |
| 9 #include "gin/converter.h" | |
| 10 #include "mojo/apps/js/mojo_bridge_module.h" | |
| 11 #include "mojo/common/data_pipe_utils.h" | |
| 12 | |
| 13 namespace mojo { | |
| 14 namespace apps { | |
| 15 | |
| 16 JSApp::JSApp(ShellPtr shell, URLResponsePtr response) : shell_(shell.Pass()) { | |
| 17 // TODO(hansmuller): handle load failure here and below. | |
| 18 DCHECK(!response.is_null()); | |
| 19 file_name_ = response->url; | |
| 20 bool result = common::BlockingCopyToString(response->body.Pass(), &source_); | |
| 21 DCHECK(result); | |
| 22 | |
| 23 runner_delegate.AddBuiltinModule(MojoInternals::kModuleName, | |
| 24 base::Bind(MojoInternals::GetModule, this)); | |
| 25 shell_.set_client(this); | |
| 26 } | |
| 27 | |
| 28 JSApp::~JSApp() { | |
| 29 } | |
| 30 | |
| 31 void JSApp::Quit() { | |
| 32 isolate_holder_.RemoveRunMicrotasksObserver(); | |
| 33 base::MessageLoop::current()->PostTask( | |
| 34 FROM_HERE, base::Bind(&JSApp::QuitInternal, base::Unretained(this))); | |
| 35 } | |
| 36 | |
| 37 MessagePipeHandle JSApp::ConnectToApplication( | |
| 38 const std::string& application_url) { | |
| 39 MessagePipe pipe; | |
| 40 InterfaceRequest<ServiceProvider> request = | |
| 41 MakeRequest<ServiceProvider>(pipe.handle1.Pass()); | |
| 42 shell_->ConnectToApplication(application_url, request.Pass()); | |
| 43 return pipe.handle0.Pass().release(); | |
| 44 } | |
| 45 | |
| 46 MessagePipeHandle JSApp::RequestorMessagePipeHandle() { | |
| 47 return requestor_handle_.get(); | |
| 48 } | |
| 49 | |
| 50 void JSApp::AcceptConnection(const String& requestor_url, | |
| 51 ServiceProviderPtr provider) { | |
| 52 requestor_handle_ = provider.PassMessagePipe(); | |
| 53 | |
| 54 isolate_holder_.AddRunMicrotasksObserver(); | |
| 55 shell_runner_.reset( | |
| 56 new gin::ShellRunner(&runner_delegate, isolate_holder_.isolate())); | |
| 57 gin::Runner::Scope scope(shell_runner_.get()); | |
| 58 shell_runner_->Run(source_.c_str(), file_name_.c_str()); | |
| 59 } | |
| 60 | |
| 61 void JSApp::Initialize(Array<String> args) { | |
| 62 } | |
| 63 | |
| 64 void JSApp::QuitInternal() { | |
| 65 shell_runner_.reset(); | |
| 66 base::MessageLoop::current()->QuitWhenIdle(); | |
| 67 } | |
| 68 | |
| 69 } // namespace apps | |
| 70 } // namespace mojo | |
| OLD | NEW |