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 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 return URLDataSource::GetContentSecurityPolicyObjectSrc(); | 67 return URLDataSource::GetContentSecurityPolicyObjectSrc(); |
68 } | 68 } |
69 std::string GetContentSecurityPolicyChildSrc() const override { | 69 std::string GetContentSecurityPolicyChildSrc() const override { |
70 if (parent_->frame_src_set_) | 70 if (parent_->frame_src_set_) |
71 return parent_->frame_src_; | 71 return parent_->frame_src_; |
72 return URLDataSource::GetContentSecurityPolicyChildSrc(); | 72 return URLDataSource::GetContentSecurityPolicyChildSrc(); |
73 } | 73 } |
74 bool ShouldDenyXFrameOptions() const override { | 74 bool ShouldDenyXFrameOptions() const override { |
75 return parent_->deny_xframe_options_; | 75 return parent_->deny_xframe_options_; |
76 } | 76 } |
77 bool IsGzipped(const std::string& path) const override { | |
78 return parent_->use_gzip_for_all_paths_ && path != parent_->json_path_; | |
smaier
2016/07/15 14:44:47
Why do we care if we match the json_path_ of the p
Dan Beam
2016/07/15 16:44:40
because things like string.js aren't gzipped
| |
79 } | |
77 | 80 |
78 private: | 81 private: |
79 WebUIDataSourceImpl* parent_; | 82 WebUIDataSourceImpl* parent_; |
80 }; | 83 }; |
81 | 84 |
82 WebUIDataSourceImpl::WebUIDataSourceImpl(const std::string& source_name) | 85 WebUIDataSourceImpl::WebUIDataSourceImpl(const std::string& source_name) |
83 : URLDataSourceImpl(source_name, new InternalDataSource(this)), | 86 : URLDataSourceImpl(source_name, new InternalDataSource(this)), |
84 source_name_(source_name), | 87 source_name_(source_name), |
85 default_resource_(-1), | 88 default_resource_(-1), |
86 add_csp_(true), | 89 add_csp_(true), |
87 object_src_set_(false), | 90 object_src_set_(false), |
88 frame_src_set_(false), | 91 frame_src_set_(false), |
89 deny_xframe_options_(true), | 92 deny_xframe_options_(true), |
90 add_load_time_data_defaults_(true), | 93 add_load_time_data_defaults_(true), |
91 replace_existing_source_(true) {} | 94 replace_existing_source_(true), |
95 use_gzip_for_all_paths_(false) {} | |
92 | 96 |
93 WebUIDataSourceImpl::~WebUIDataSourceImpl() { | 97 WebUIDataSourceImpl::~WebUIDataSourceImpl() { |
94 } | 98 } |
95 | 99 |
96 void WebUIDataSourceImpl::AddString(const std::string& name, | 100 void WebUIDataSourceImpl::AddString(const std::string& name, |
97 const base::string16& value) { | 101 const base::string16& value) { |
98 // TODO(dschuyler): Share only one copy of these strings. | 102 // TODO(dschuyler): Share only one copy of these strings. |
99 localized_strings_.SetString(name, value); | 103 localized_strings_.SetString(name, value); |
100 replacements_[name] = base::UTF16ToUTF8(value); | 104 replacements_[name] = base::UTF16ToUTF8(value); |
101 } | 105 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 void WebUIDataSourceImpl::OverrideContentSecurityPolicyChildSrc( | 176 void WebUIDataSourceImpl::OverrideContentSecurityPolicyChildSrc( |
173 const std::string& data) { | 177 const std::string& data) { |
174 frame_src_set_ = true; | 178 frame_src_set_ = true; |
175 frame_src_ = data; | 179 frame_src_ = data; |
176 } | 180 } |
177 | 181 |
178 void WebUIDataSourceImpl::DisableDenyXFrameOptions() { | 182 void WebUIDataSourceImpl::DisableDenyXFrameOptions() { |
179 deny_xframe_options_ = false; | 183 deny_xframe_options_ = false; |
180 } | 184 } |
181 | 185 |
186 void WebUIDataSourceImpl::UseGzipForAllPaths() { | |
187 use_gzip_for_all_paths_ = true; | |
188 } | |
189 | |
182 std::string WebUIDataSourceImpl::GetSource() const { | 190 std::string WebUIDataSourceImpl::GetSource() const { |
183 return source_name_; | 191 return source_name_; |
184 } | 192 } |
185 | 193 |
186 std::string WebUIDataSourceImpl::GetMimeType(const std::string& path) const { | 194 std::string WebUIDataSourceImpl::GetMimeType(const std::string& path) const { |
187 // Remove the query string for to determine the mime type. | 195 // Remove the query string for to determine the mime type. |
188 std::string file_path = path.substr(0, path.find_first_of('?')); | 196 std::string file_path = path.substr(0, path.find_first_of('?')); |
189 | 197 |
190 if (base::EndsWith(file_path, ".css", base::CompareCase::INSENSITIVE_ASCII)) | 198 if (base::EndsWith(file_path, ".css", base::CompareCase::INSENSITIVE_ASCII)) |
191 return "text/css"; | 199 return "text/css"; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 } | 260 } |
253 | 261 |
254 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( | 262 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( |
255 const URLDataSource::GotDataCallback& callback) { | 263 const URLDataSource::GotDataCallback& callback) { |
256 std::string template_data; | 264 std::string template_data; |
257 webui::AppendJsonJS(&localized_strings_, &template_data); | 265 webui::AppendJsonJS(&localized_strings_, &template_data); |
258 callback.Run(base::RefCountedString::TakeString(&template_data)); | 266 callback.Run(base::RefCountedString::TakeString(&template_data)); |
259 } | 267 } |
260 | 268 |
261 } // namespace content | 269 } // namespace content |
OLD | NEW |