OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/webui/web_ui_data_source_impl.h" | 5 #include "content/browser/webui/web_ui_data_source_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "content/grit/content_resources.h" | 12 #include "content/grit/content_resources.h" |
13 #include "content/public/browser/content_browser_client.h" | 13 #include "content/public/browser/content_browser_client.h" |
14 #include "content/public/common/content_client.h" | 14 #include "content/public/common/content_client.h" |
15 #include "mojo/public/js/constants.h" | 15 #include "mojo/public/js/constants.h" |
16 #include "ui/base/webui/jstemplate_builder.h" | 16 #include "ui/base/webui/jstemplate_builder.h" |
17 #include "ui/base/webui/web_ui_util.h" | 17 #include "ui/base/webui/web_ui_util.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 // static | 21 // static |
22 WebUIDataSource* WebUIDataSource::Create(const std::string& source_name) { | 22 WebUIDataSource* WebUIDataSource::Create(const std::string& source_name) { |
23 return new WebUIDataSourceImpl(source_name); | 23 return new WebUIDataSourceImpl(source_name); |
24 } | 24 } |
25 | 25 |
26 // static | 26 // static |
| 27 WebUIDataSource* WebUIDataSource::AddMojoDataSource( |
| 28 BrowserContext* browser_context) { |
| 29 WebUIDataSource* mojo_source = Create("mojo"); |
| 30 |
| 31 static const struct { |
| 32 const char* path; |
| 33 int id; |
| 34 } resources[] = { |
| 35 { mojo::kBindingsModuleName, IDR_MOJO_BINDINGS_JS }, |
| 36 { mojo::kBufferModuleName, IDR_MOJO_BUFFER_JS }, |
| 37 { mojo::kCodecModuleName, IDR_MOJO_CODEC_JS }, |
| 38 { mojo::kConnectionModuleName, IDR_MOJO_CONNECTION_JS }, |
| 39 { mojo::kConnectorModuleName, IDR_MOJO_CONNECTOR_JS }, |
| 40 { mojo::kRouterModuleName, IDR_MOJO_ROUTER_JS }, |
| 41 { mojo::kUnicodeModuleName, IDR_MOJO_UNICODE_JS }, |
| 42 { mojo::kValidatorModuleName, IDR_MOJO_VALIDATOR_JS }, |
| 43 }; |
| 44 for (size_t i = 0; i < arraysize(resources); ++i) |
| 45 mojo_source->AddResourcePath(resources[i].path, resources[i].id); |
| 46 |
| 47 URLDataManager::AddWebUIDataSource(browser_context, mojo_source); |
| 48 return mojo_source; |
| 49 } |
| 50 |
| 51 // static |
27 void WebUIDataSource::Add(BrowserContext* browser_context, | 52 void WebUIDataSource::Add(BrowserContext* browser_context, |
28 WebUIDataSource* source) { | 53 WebUIDataSource* source) { |
29 URLDataManager::AddWebUIDataSource(browser_context, source); | 54 URLDataManager::AddWebUIDataSource(browser_context, source); |
30 } | 55 } |
31 | 56 |
32 // Internal class to hide the fact that WebUIDataSourceImpl implements | 57 // Internal class to hide the fact that WebUIDataSourceImpl implements |
33 // URLDataSource. | 58 // URLDataSource. |
34 class WebUIDataSourceImpl::InternalDataSource : public URLDataSource { | 59 class WebUIDataSourceImpl::InternalDataSource : public URLDataSource { |
35 public: | 60 public: |
36 InternalDataSource(WebUIDataSourceImpl* parent) : parent_(parent) { | 61 InternalDataSource(WebUIDataSourceImpl* parent) : parent_(parent) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 154 |
130 void WebUIDataSourceImpl::SetDefaultResource(int resource_id) { | 155 void WebUIDataSourceImpl::SetDefaultResource(int resource_id) { |
131 default_resource_ = resource_id; | 156 default_resource_ = resource_id; |
132 } | 157 } |
133 | 158 |
134 void WebUIDataSourceImpl::SetRequestFilter( | 159 void WebUIDataSourceImpl::SetRequestFilter( |
135 const WebUIDataSource::HandleRequestCallback& callback) { | 160 const WebUIDataSource::HandleRequestCallback& callback) { |
136 filter_callback_ = callback; | 161 filter_callback_ = callback; |
137 } | 162 } |
138 | 163 |
139 void WebUIDataSourceImpl::AddMojoResources() { | |
140 static const struct { | |
141 const char* path; | |
142 int id; | |
143 } resources[] = { | |
144 {mojo::kBindingsModuleName, IDR_MOJO_BINDINGS_JS}, | |
145 {mojo::kBufferModuleName, IDR_MOJO_BUFFER_JS}, | |
146 {mojo::kCodecModuleName, IDR_MOJO_CODEC_JS}, | |
147 {mojo::kConnectionModuleName, IDR_MOJO_CONNECTION_JS}, | |
148 {mojo::kConnectorModuleName, IDR_MOJO_CONNECTOR_JS}, | |
149 {mojo::kRouterModuleName, IDR_MOJO_ROUTER_JS}, | |
150 {mojo::kUnicodeModuleName, IDR_MOJO_UNICODE_JS}, | |
151 {mojo::kValidatorModuleName, IDR_MOJO_VALIDATOR_JS}, | |
152 }; | |
153 for (size_t i = 0; i < arraysize(resources); ++i) | |
154 AddResourcePath(resources[i].path, resources[i].id); | |
155 } | |
156 | |
157 void WebUIDataSourceImpl::DisableReplaceExistingSource() { | 164 void WebUIDataSourceImpl::DisableReplaceExistingSource() { |
158 replace_existing_source_ = false; | 165 replace_existing_source_ = false; |
159 } | 166 } |
160 | 167 |
161 void WebUIDataSourceImpl::DisableContentSecurityPolicy() { | 168 void WebUIDataSourceImpl::DisableContentSecurityPolicy() { |
162 add_csp_ = false; | 169 add_csp_ = false; |
163 } | 170 } |
164 | 171 |
165 void WebUIDataSourceImpl::OverrideContentSecurityPolicyObjectSrc( | 172 void WebUIDataSourceImpl::OverrideContentSecurityPolicyObjectSrc( |
166 const std::string& data) { | 173 const std::string& data) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 245 } |
239 | 246 |
240 void WebUIDataSourceImpl::SendFromResourceBundle( | 247 void WebUIDataSourceImpl::SendFromResourceBundle( |
241 const URLDataSource::GotDataCallback& callback, int idr) { | 248 const URLDataSource::GotDataCallback& callback, int idr) { |
242 scoped_refptr<base::RefCountedStaticMemory> response( | 249 scoped_refptr<base::RefCountedStaticMemory> response( |
243 GetContentClient()->GetDataResourceBytes(idr)); | 250 GetContentClient()->GetDataResourceBytes(idr)); |
244 callback.Run(response.get()); | 251 callback.Run(response.get()); |
245 } | 252 } |
246 | 253 |
247 } // namespace content | 254 } // namespace content |
OLD | NEW |