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 const std::string& url, |
| 18 URLResponsePtr content) |
| 19 : JSApp(app_delegate_impl), |
| 20 url_(url), |
| 21 content_(content.Pass()) { |
| 22 } |
| 23 |
| 24 virtual bool Load(std::string* source, std::string* file_name) override { |
| 25 *file_name = url_; |
| 26 if (content_.is_null()) |
| 27 return false; |
| 28 return common::BlockingCopyToString(content_->body.Pass(), source); |
| 29 } |
| 30 |
| 31 private: |
| 32 std::string url_; |
| 33 URLResponsePtr content_; |
| 34 }; |
| 35 |
| 36 |
| 37 ContentHandlerImpl::ContentHandlerImpl(ApplicationDelegateImpl* app) |
| 38 : app_delegate_impl_(app) { |
| 39 } |
| 40 |
| 41 ContentHandlerImpl::~ContentHandlerImpl() { |
| 42 } |
| 43 |
| 44 void ContentHandlerImpl::OnConnect( |
| 45 const mojo::String& url, |
| 46 URLResponsePtr content, |
| 47 InterfaceRequest<ServiceProvider> service_provider) { |
| 48 scoped_ptr<JSApp> js_app( |
| 49 new ContentHandlerJSApp(app_delegate_impl_, |
| 50 url.To<std::string>(), |
| 51 content.Pass())); |
| 52 app_delegate_impl_->StartJSApp(js_app.Pass()); |
| 53 } |
| 54 |
| 55 } // namespace apps |
| 56 } // namespace mojo |
OLD | NEW |