Chromium Code Reviews| 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 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 } | 205 } |
| 206 | 206 |
| 207 void WebUIDataSourceImpl::DisableDenyXFrameOptions() { | 207 void WebUIDataSourceImpl::DisableDenyXFrameOptions() { |
| 208 deny_xframe_options_ = false; | 208 deny_xframe_options_ = false; |
| 209 } | 209 } |
| 210 | 210 |
| 211 void WebUIDataSourceImpl::DisableI18nAndUseGzipForAllPaths() { | 211 void WebUIDataSourceImpl::DisableI18nAndUseGzipForAllPaths() { |
| 212 use_gzip_for_all_paths_ = true; | 212 use_gzip_for_all_paths_ = true; |
| 213 } | 213 } |
| 214 | 214 |
| 215 const ui::TemplateReplacements* WebUIDataSourceImpl::GetReplacements() const { | |
| 216 return &replacements_; | |
| 217 } | |
| 218 | |
| 215 std::string WebUIDataSourceImpl::GetSource() const { | 219 std::string WebUIDataSourceImpl::GetSource() const { |
| 216 return source_name_; | 220 return source_name_; |
| 217 } | 221 } |
| 218 | 222 |
| 219 std::string WebUIDataSourceImpl::GetMimeType(const std::string& path) const { | 223 std::string WebUIDataSourceImpl::GetMimeType(const std::string& path) const { |
| 220 // Remove the query string for to determine the mime type. | 224 // Remove the query string for to determine the mime type. |
| 221 std::string file_path = path.substr(0, path.find_first_of('?')); | 225 std::string file_path = path.substr(0, path.find_first_of('?')); |
| 222 | 226 |
| 223 if (base::EndsWith(file_path, ".css", base::CompareCase::INSENSITIVE_ASCII)) | 227 if (base::EndsWith(file_path, ".css", base::CompareCase::INSENSITIVE_ASCII)) |
| 224 return "text/css"; | 228 return "text/css"; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 int resource_id = default_resource_; | 267 int resource_id = default_resource_; |
| 264 std::map<std::string, int>::iterator result; | 268 std::map<std::string, int>::iterator result; |
| 265 // Remove the query string for named resource lookups. | 269 // Remove the query string for named resource lookups. |
| 266 std::string file_path = path.substr(0, path.find_first_of('?')); | 270 std::string file_path = path.substr(0, path.find_first_of('?')); |
| 267 result = path_to_idr_map_.find(file_path); | 271 result = path_to_idr_map_.find(file_path); |
| 268 if (result != path_to_idr_map_.end()) | 272 if (result != path_to_idr_map_.end()) |
| 269 resource_id = result->second; | 273 resource_id = result->second; |
| 270 DCHECK_NE(resource_id, -1); | 274 DCHECK_NE(resource_id, -1); |
| 271 scoped_refptr<base::RefCountedMemory> response( | 275 scoped_refptr<base::RefCountedMemory> response( |
| 272 GetContentClient()->GetDataResourceBytes(resource_id)); | 276 GetContentClient()->GetDataResourceBytes(resource_id)); |
| 273 | |
| 274 // TODO(dschuyler): improve filtering of which resource to run template | |
| 275 // expansion upon. TODO(dbeam): make a streaming filter that works on gzipped | |
| 276 // content. | |
| 277 if (response.get() && GetMimeType(path) == "text/html" && | |
|
Dan Beam
2016/12/01 23:32:23
so how are we only running replacements on text/ht
dschuyler
2016/12/02 20:14:00
Done.
| |
| 278 !source()->IsGzipped(path)) { | |
| 279 std::string replaced = ui::ReplaceTemplateExpressions( | |
| 280 base::StringPiece(response->front_as<char>(), response->size()), | |
| 281 replacements_); | |
| 282 response = base::RefCountedString::TakeString(&replaced); | |
| 283 } | |
| 284 | |
| 285 callback.Run(response.get()); | 277 callback.Run(response.get()); |
| 286 } | 278 } |
| 287 | 279 |
| 288 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( | 280 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( |
| 289 const URLDataSource::GotDataCallback& callback) { | 281 const URLDataSource::GotDataCallback& callback) { |
| 290 std::string template_data; | 282 std::string template_data; |
| 291 webui::AppendJsonJS(&localized_strings_, &template_data); | 283 webui::AppendJsonJS(&localized_strings_, &template_data); |
| 292 callback.Run(base::RefCountedString::TakeString(&template_data)); | 284 callback.Run(base::RefCountedString::TakeString(&template_data)); |
| 293 } | 285 } |
| 294 | 286 |
| 295 } // namespace content | 287 } // namespace content |
| OLD | NEW |