| 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/application_delegate_impl.h" | |
| 6 | |
| 7 #include "gin/array_buffer.h" | |
| 8 #include "gin/public/isolate_holder.h" | |
| 9 #include "mojo/apps/js/js_app.h" | |
| 10 #include "mojo/public/cpp/application/application_impl.h" | |
| 11 | |
| 12 namespace mojo { | |
| 13 namespace apps { | |
| 14 | |
| 15 ApplicationDelegateImpl::ApplicationDelegateImpl() | |
| 16 : application_impl_(nullptr) { | |
| 17 } | |
| 18 | |
| 19 void ApplicationDelegateImpl::Initialize(ApplicationImpl* app) { | |
| 20 application_impl_ = app; | |
| 21 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, | |
| 22 gin::ArrayBufferAllocator::SharedInstance()); | |
| 23 } | |
| 24 | |
| 25 ApplicationDelegateImpl::~ApplicationDelegateImpl() { | |
| 26 } | |
| 27 | |
| 28 void ApplicationDelegateImpl::StartJSApp(scoped_ptr<JSApp> app_ptr) { | |
| 29 JSApp *app = app_ptr.release(); | |
| 30 app_vector_.push_back(app); | |
| 31 // TODO(hansmuller): deal with the Start() return value. | |
| 32 app->Start(); | |
| 33 } | |
| 34 | |
| 35 void ApplicationDelegateImpl::QuitJSApp(JSApp* app) { | |
| 36 AppVector::iterator itr = | |
| 37 std::find(app_vector_.begin(), app_vector_.end(), app); | |
| 38 if (itr != app_vector_.end()) | |
| 39 app_vector_.erase(itr); | |
| 40 if (app_vector_.empty()) | |
| 41 base::MessageLoop::current()->QuitNow(); | |
| 42 } | |
| 43 | |
| 44 void ApplicationDelegateImpl::ConnectToService( | |
| 45 ScopedMessagePipeHandle pipe_handle, | |
| 46 const std::string& application_url, | |
| 47 const std::string& interface_name) { | |
| 48 CHECK(application_impl_); | |
| 49 ServiceProvider* service_provider = | |
| 50 application_impl_->ConnectToApplication(application_url) | |
| 51 ->GetServiceProvider(); | |
| 52 service_provider->ConnectToService(interface_name, pipe_handle.Pass()); | |
| 53 } | |
| 54 | |
| 55 } // namespace apps | |
| 56 } // namespace mojo | |
| OLD | NEW |