Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: content/browser/webui/web_ui_data_source_impl.cc

Issue 2399553002: Gzip compress chrome://accessibility resources (Closed)
Patch Set: showing agrieve@ what didn't work Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/webui/web_ui_data_source_impl.h ('k') | content/content_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 std::string GetContentSecurityPolicyChildSrc() const override { 68 std::string GetContentSecurityPolicyChildSrc() const override {
69 if (parent_->frame_src_set_) 69 if (parent_->frame_src_set_)
70 return parent_->frame_src_; 70 return parent_->frame_src_;
71 return URLDataSource::GetContentSecurityPolicyChildSrc(); 71 return URLDataSource::GetContentSecurityPolicyChildSrc();
72 } 72 }
73 bool ShouldDenyXFrameOptions() const override { 73 bool ShouldDenyXFrameOptions() const override {
74 return parent_->deny_xframe_options_; 74 return parent_->deny_xframe_options_;
75 } 75 }
76 bool IsGzipped(const std::string& path) const override { 76 bool IsGzipped(const std::string& path) const override {
77 if (!parent_->json_path_.empty() && path == parent_->json_path_) 77 return parent_->use_gzip_for_all_paths_ &&
78 return false; 78 parent_->GetResourceIdFromPath(path) != -1;
agrieve 2016/10/12 14:19:36 I think this would have worked: if (path == json_
Dan Beam 2016/10/12 16:26:32 this breaks when no json_path_ is set, but a .empt
79 return parent_->use_gzip_for_all_paths_;
80 } 79 }
81 80
82 private: 81 private:
83 WebUIDataSourceImpl* parent_; 82 WebUIDataSourceImpl* parent_;
84 }; 83 };
85 84
86 WebUIDataSourceImpl::WebUIDataSourceImpl(const std::string& source_name) 85 WebUIDataSourceImpl::WebUIDataSourceImpl(const std::string& source_name)
87 : URLDataSourceImpl(source_name, new InternalDataSource(this)), 86 : URLDataSourceImpl(source_name, new InternalDataSource(this)),
88 source_name_(source_name), 87 source_name_(source_name),
89 default_resource_(-1), 88 default_resource_(-1),
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 webui::SetLoadTimeDataDefaults(locale, &defaults); 232 webui::SetLoadTimeDataDefaults(locale, &defaults);
234 AddLocalizedStrings(defaults); 233 AddLocalizedStrings(defaults);
235 add_load_time_data_defaults_ = false; 234 add_load_time_data_defaults_ = false;
236 } 235 }
237 236
238 if (!json_path_.empty() && path == json_path_) { 237 if (!json_path_.empty() && path == json_path_) {
239 SendLocalizedStringsAsJSON(callback); 238 SendLocalizedStringsAsJSON(callback);
240 return; 239 return;
241 } 240 }
242 241
243 int resource_id = default_resource_; 242 int resource_id = GetResourceIdFromPath(path);
244 std::map<std::string, int>::iterator result;
245 // Remove the query string for named resource lookups.
246 std::string file_path = path.substr(0, path.find_first_of('?'));
247 result = path_to_idr_map_.find(file_path);
248 if (result != path_to_idr_map_.end())
249 resource_id = result->second;
250 DCHECK_NE(resource_id, -1); 243 DCHECK_NE(resource_id, -1);
251 scoped_refptr<base::RefCountedMemory> response( 244 scoped_refptr<base::RefCountedMemory> response(
252 GetContentClient()->GetDataResourceBytes(resource_id)); 245 GetContentClient()->GetDataResourceBytes(resource_id));
253 246
254 // TODO(dschuyler): improve filtering of which resource to run template 247 // TODO(dschuyler): improve filtering of which resource to run template
255 // expansion upon. TODO(dbeam): make a streaming filter that works on gzipped 248 // expansion upon. TODO(dbeam): make a streaming filter that works on gzipped
256 // content. 249 // content.
257 if (response.get() && GetMimeType(path) == "text/html" && 250 if (response.get() && GetMimeType(path) == "text/html" &&
258 !source()->IsGzipped(path)) { 251 !source()->IsGzipped(path)) {
259 std::string replaced = ui::ReplaceTemplateExpressions( 252 std::string replaced = ui::ReplaceTemplateExpressions(
260 base::StringPiece(response->front_as<char>(), response->size()), 253 base::StringPiece(response->front_as<char>(), response->size()),
261 replacements_); 254 replacements_);
262 response = base::RefCountedString::TakeString(&replaced); 255 response = base::RefCountedString::TakeString(&replaced);
263 } 256 }
264 257
265 callback.Run(response.get()); 258 callback.Run(response.get());
266 } 259 }
267 260
268 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( 261 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON(
269 const URLDataSource::GotDataCallback& callback) { 262 const URLDataSource::GotDataCallback& callback) {
270 std::string template_data; 263 std::string template_data;
271 webui::AppendJsonJS(&localized_strings_, &template_data); 264 webui::AppendJsonJS(&localized_strings_, &template_data);
272 callback.Run(base::RefCountedString::TakeString(&template_data)); 265 callback.Run(base::RefCountedString::TakeString(&template_data));
273 } 266 }
274 267
268 int WebUIDataSourceImpl::GetResourceIdFromPath(const std::string& path) const {
269 // Remove the query string for named resource lookups.
270 std::string file_path = path.substr(0, path.find_first_of('?'));
271 auto result = path_to_idr_map_.find(file_path);
272 return result != path_to_idr_map_.end() ? result->second : default_resource_;
273 }
274
275 } // namespace content 275 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/webui/web_ui_data_source_impl.h ('k') | content/content_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698