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