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