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