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 | |
52 void WebUIDataSource::Add(BrowserContext* browser_context, | 27 void WebUIDataSource::Add(BrowserContext* browser_context, |
53 WebUIDataSource* source) { | 28 WebUIDataSource* source) { |
54 URLDataManager::AddWebUIDataSource(browser_context, source); | 29 URLDataManager::AddWebUIDataSource(browser_context, source); |
55 } | 30 } |
56 | 31 |
57 // Internal class to hide the fact that WebUIDataSourceImpl implements | 32 // Internal class to hide the fact that WebUIDataSourceImpl implements |
58 // URLDataSource. | 33 // URLDataSource. |
59 class WebUIDataSourceImpl::InternalDataSource : public URLDataSource { | 34 class WebUIDataSourceImpl::InternalDataSource : public URLDataSource { |
60 public: | 35 public: |
61 InternalDataSource(WebUIDataSourceImpl* parent) : parent_(parent) { | 36 InternalDataSource(WebUIDataSourceImpl* parent) : parent_(parent) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 129 |
155 void WebUIDataSourceImpl::SetDefaultResource(int resource_id) { | 130 void WebUIDataSourceImpl::SetDefaultResource(int resource_id) { |
156 default_resource_ = resource_id; | 131 default_resource_ = resource_id; |
157 } | 132 } |
158 | 133 |
159 void WebUIDataSourceImpl::SetRequestFilter( | 134 void WebUIDataSourceImpl::SetRequestFilter( |
160 const WebUIDataSource::HandleRequestCallback& callback) { | 135 const WebUIDataSource::HandleRequestCallback& callback) { |
161 filter_callback_ = callback; | 136 filter_callback_ = callback; |
162 } | 137 } |
163 | 138 |
| 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 |
164 void WebUIDataSourceImpl::DisableReplaceExistingSource() { | 157 void WebUIDataSourceImpl::DisableReplaceExistingSource() { |
165 replace_existing_source_ = false; | 158 replace_existing_source_ = false; |
166 } | 159 } |
167 | 160 |
168 void WebUIDataSourceImpl::DisableContentSecurityPolicy() { | 161 void WebUIDataSourceImpl::DisableContentSecurityPolicy() { |
169 add_csp_ = false; | 162 add_csp_ = false; |
170 } | 163 } |
171 | 164 |
172 void WebUIDataSourceImpl::OverrideContentSecurityPolicyObjectSrc( | 165 void WebUIDataSourceImpl::OverrideContentSecurityPolicyObjectSrc( |
173 const std::string& data) { | 166 const std::string& data) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 238 } |
246 | 239 |
247 void WebUIDataSourceImpl::SendFromResourceBundle( | 240 void WebUIDataSourceImpl::SendFromResourceBundle( |
248 const URLDataSource::GotDataCallback& callback, int idr) { | 241 const URLDataSource::GotDataCallback& callback, int idr) { |
249 scoped_refptr<base::RefCountedStaticMemory> response( | 242 scoped_refptr<base::RefCountedStaticMemory> response( |
250 GetContentClient()->GetDataResourceBytes(idr)); | 243 GetContentClient()->GetDataResourceBytes(idr)); |
251 callback.Run(response.get()); | 244 callback.Run(response.get()); |
252 } | 245 } |
253 | 246 |
254 } // namespace content | 247 } // namespace content |
OLD | NEW |