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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "content/grit/content_resources.h" | 15 #include "content/grit/content_resources.h" |
16 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
17 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
18 #include "mojo/public/js/constants.h" | |
19 #include "ui/base/webui/jstemplate_builder.h" | 18 #include "ui/base/webui/jstemplate_builder.h" |
20 #include "ui/base/webui/web_ui_util.h" | 19 #include "ui/base/webui/web_ui_util.h" |
21 | 20 |
22 namespace content { | 21 namespace content { |
23 | 22 |
24 // static | 23 // static |
25 WebUIDataSource* WebUIDataSource::Create(const std::string& source_name) { | 24 WebUIDataSource* WebUIDataSource::Create(const std::string& source_name) { |
26 return new WebUIDataSourceImpl(source_name); | 25 return new WebUIDataSourceImpl(source_name); |
27 } | 26 } |
28 | 27 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 131 |
133 void WebUIDataSourceImpl::SetDefaultResource(int resource_id) { | 132 void WebUIDataSourceImpl::SetDefaultResource(int resource_id) { |
134 default_resource_ = resource_id; | 133 default_resource_ = resource_id; |
135 } | 134 } |
136 | 135 |
137 void WebUIDataSourceImpl::SetRequestFilter( | 136 void WebUIDataSourceImpl::SetRequestFilter( |
138 const WebUIDataSource::HandleRequestCallback& callback) { | 137 const WebUIDataSource::HandleRequestCallback& callback) { |
139 filter_callback_ = callback; | 138 filter_callback_ = callback; |
140 } | 139 } |
141 | 140 |
142 void WebUIDataSourceImpl::AddMojoResources() { | |
143 static const struct { | |
144 const char* path; | |
145 int id; | |
146 } resources[] = { | |
147 {mojo::kBindingsModuleName, IDR_MOJO_BINDINGS_JS}, | |
148 {mojo::kBufferModuleName, IDR_MOJO_BUFFER_JS}, | |
149 {mojo::kCodecModuleName, IDR_MOJO_CODEC_JS}, | |
150 {mojo::kConnectionModuleName, IDR_MOJO_CONNECTION_JS}, | |
151 {mojo::kConnectorModuleName, IDR_MOJO_CONNECTOR_JS}, | |
152 {mojo::kRouterModuleName, IDR_MOJO_ROUTER_JS}, | |
153 {mojo::kUnicodeModuleName, IDR_MOJO_UNICODE_JS}, | |
154 {mojo::kValidatorModuleName, IDR_MOJO_VALIDATOR_JS}, | |
155 }; | |
156 for (size_t i = 0; i < arraysize(resources); ++i) | |
157 AddResourcePath(resources[i].path, resources[i].id); | |
158 } | |
159 | |
160 void WebUIDataSourceImpl::DisableReplaceExistingSource() { | 141 void WebUIDataSourceImpl::DisableReplaceExistingSource() { |
161 replace_existing_source_ = false; | 142 replace_existing_source_ = false; |
162 } | 143 } |
163 | 144 |
164 void WebUIDataSourceImpl::DisableContentSecurityPolicy() { | 145 void WebUIDataSourceImpl::DisableContentSecurityPolicy() { |
165 add_csp_ = false; | 146 add_csp_ = false; |
166 } | 147 } |
167 | 148 |
168 void WebUIDataSourceImpl::OverrideContentSecurityPolicyObjectSrc( | 149 void WebUIDataSourceImpl::OverrideContentSecurityPolicyObjectSrc( |
169 const std::string& data) { | 150 const std::string& data) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 227 } |
247 | 228 |
248 void WebUIDataSourceImpl::SendFromResourceBundle( | 229 void WebUIDataSourceImpl::SendFromResourceBundle( |
249 const URLDataSource::GotDataCallback& callback, int idr) { | 230 const URLDataSource::GotDataCallback& callback, int idr) { |
250 scoped_refptr<base::RefCountedStaticMemory> response( | 231 scoped_refptr<base::RefCountedStaticMemory> response( |
251 GetContentClient()->GetDataResourceBytes(idr)); | 232 GetContentClient()->GetDataResourceBytes(idr)); |
252 callback.Run(response.get()); | 233 callback.Run(response.get()); |
253 } | 234 } |
254 | 235 |
255 } // namespace content | 236 } // namespace content |
OLD | NEW |