| 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_impl.h" | |
| 6 | |
| 7 #include "mojo/apps/js/application_delegate_impl.h" | |
| 8 #include "mojo/apps/js/js_app.h" | |
| 9 #include "mojo/common/data_pipe_utils.h" | |
| 10 | |
| 11 namespace mojo { | |
| 12 namespace apps { | |
| 13 | |
| 14 class ContentHandlerJSApp : public JSApp { | |
| 15 public: | |
| 16 ContentHandlerJSApp(ApplicationDelegateImpl* app_delegate_impl, | |
| 17 URLResponsePtr content, | |
| 18 InterfaceRequest<ServiceProvider> sp) | |
| 19 : JSApp(app_delegate_impl), | |
| 20 content_(content.Pass()), | |
| 21 requestor_service_provider_(sp.Pass()) { | |
| 22 } | |
| 23 | |
| 24 bool Load(std::string* source, std::string* file_name) override { | |
| 25 *file_name = content_->url; | |
| 26 if (content_.is_null()) | |
| 27 return false; | |
| 28 return common::BlockingCopyToString(content_->body.Pass(), source); | |
| 29 } | |
| 30 | |
| 31 virtual MessagePipeHandle RequestorMessagePipeHandle() override { | |
| 32 return requestor_service_provider_.PassMessagePipe().release(); | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 URLResponsePtr content_; | |
| 37 InterfaceRequest<ServiceProvider> requestor_service_provider_; | |
| 38 }; | |
| 39 | |
| 40 | |
| 41 ContentHandlerImpl::ContentHandlerImpl(ApplicationDelegateImpl* app) | |
| 42 : app_delegate_impl_(app) { | |
| 43 } | |
| 44 | |
| 45 ContentHandlerImpl::~ContentHandlerImpl() { | |
| 46 } | |
| 47 | |
| 48 void ContentHandlerImpl::OnConnect( | |
| 49 const mojo::String& requestor_url, | |
| 50 URLResponsePtr content, | |
| 51 InterfaceRequest<ServiceProvider> sp) { | |
| 52 scoped_ptr<JSApp> js_app( | |
| 53 new ContentHandlerJSApp(app_delegate_impl_, content.Pass(), sp.Pass())); | |
| 54 app_delegate_impl_->StartJSApp(js_app.Pass()); | |
| 55 } | |
| 56 | |
| 57 } // namespace apps | |
| 58 } // namespace mojo | |
| OLD | NEW |