| 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 "mojo/apps/js/application_delegate_impl.h" | 5 #include "mojo/apps/js/application_delegate_impl.h" |
| 6 | 6 |
| 7 #include "mojo/apps/js/js_app.h" | 7 #include "mojo/apps/js/js_app.h" |
| 8 #include "mojo/public/cpp/application/application_impl.h" | 8 #include "mojo/public/cpp/application/application_impl.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| 11 namespace apps { | 11 namespace apps { |
| 12 | 12 |
| 13 ContentHandlerImpl::ContentHandlerImpl(ApplicationDelegateImpl* app) | |
| 14 : content_handler_(app) { | |
| 15 } | |
| 16 | |
| 17 ContentHandlerImpl::~ContentHandlerImpl() { | |
| 18 } | |
| 19 | |
| 20 void ContentHandlerImpl::OnConnect( | |
| 21 const mojo::String& url, | |
| 22 URLResponsePtr content, | |
| 23 InterfaceRequest<ServiceProvider> service_provider) { | |
| 24 content_handler_->StartJSApp(url.To<std::string>(), content.Pass()); | |
| 25 } | |
| 26 | |
| 27 ApplicationDelegateImpl::ApplicationDelegateImpl() | 13 ApplicationDelegateImpl::ApplicationDelegateImpl() |
| 28 : application_impl_(NULL), content_handler_factory_(this) { | 14 : application_impl_(nullptr) { |
| 29 } | 15 } |
| 30 | 16 |
| 31 void ApplicationDelegateImpl::Initialize(ApplicationImpl* app) { | 17 void ApplicationDelegateImpl::Initialize(ApplicationImpl* app) { |
| 32 application_impl_ = app; | 18 application_impl_ = app; |
| 33 } | 19 } |
| 34 | 20 |
| 35 ApplicationDelegateImpl::~ApplicationDelegateImpl() { | 21 ApplicationDelegateImpl::~ApplicationDelegateImpl() { |
| 36 } | 22 } |
| 37 | 23 |
| 38 bool ApplicationDelegateImpl::ConfigureIncomingConnection( | 24 void ApplicationDelegateImpl::StartJSApp(scoped_ptr<JSApp> app_ptr) { |
| 39 ApplicationConnection* connection) { | 25 JSApp *app = app_ptr.release(); |
| 40 connection->AddService(&content_handler_factory_); | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 void ApplicationDelegateImpl::StartJSApp(const std::string& url, | |
| 45 URLResponsePtr content) { | |
| 46 JSApp* app = new JSApp(this, url, content.Pass()); | |
| 47 app_vector_.push_back(app); | 26 app_vector_.push_back(app); |
| 48 // TODO(hansmuller): deal with the Start() return value. | 27 // TODO(hansmuller): deal with the Start() return value. |
| 49 app->Start(); | 28 app->Start(); |
| 50 } | 29 } |
| 51 | 30 |
| 52 void ApplicationDelegateImpl::QuitJSApp(JSApp* app) { | 31 void ApplicationDelegateImpl::QuitJSApp(JSApp* app) { |
| 53 AppVector::iterator itr = | 32 AppVector::iterator itr = |
| 54 std::find(app_vector_.begin(), app_vector_.end(), app); | 33 std::find(app_vector_.begin(), app_vector_.end(), app); |
| 55 if (itr != app_vector_.end()) | 34 if (itr != app_vector_.end()) |
| 56 app_vector_.erase(itr); | 35 app_vector_.erase(itr); |
| 57 } | 36 } |
| 58 | 37 |
| 59 void ApplicationDelegateImpl::ConnectToService( | 38 void ApplicationDelegateImpl::ConnectToService( |
| 60 ScopedMessagePipeHandle pipe_handle, | 39 ScopedMessagePipeHandle pipe_handle, |
| 61 const std::string& application_url, | 40 const std::string& application_url, |
| 62 const std::string& interface_name) { | 41 const std::string& interface_name) { |
| 63 CHECK(application_impl_); | 42 CHECK(application_impl_); |
| 64 ServiceProvider* service_provider = | 43 ServiceProvider* service_provider = |
| 65 application_impl_->ConnectToApplication(application_url) | 44 application_impl_->ConnectToApplication(application_url) |
| 66 ->GetServiceProvider(); | 45 ->GetServiceProvider(); |
| 67 service_provider->ConnectToService(interface_name, pipe_handle.Pass()); | 46 service_provider->ConnectToService(interface_name, pipe_handle.Pass()); |
| 68 } | 47 } |
| 69 | 48 |
| 70 } // namespace apps | 49 } // namespace apps |
| 71 } // namespace mojo | 50 } // namespace mojo |
| OLD | NEW |