| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 const URLDataSource::GotDataCallback& callback) override { | 54 const URLDataSource::GotDataCallback& callback) override { |
| 55 return parent_->StartDataRequest(path, wc_getter, callback); | 55 return parent_->StartDataRequest(path, wc_getter, callback); |
| 56 } | 56 } |
| 57 bool ShouldReplaceExistingSource() const override { | 57 bool ShouldReplaceExistingSource() const override { |
| 58 return parent_->replace_existing_source_; | 58 return parent_->replace_existing_source_; |
| 59 } | 59 } |
| 60 bool AllowCaching() const override { return false; } | 60 bool AllowCaching() const override { return false; } |
| 61 bool ShouldAddContentSecurityPolicy() const override { | 61 bool ShouldAddContentSecurityPolicy() const override { |
| 62 return parent_->add_csp_; | 62 return parent_->add_csp_; |
| 63 } | 63 } |
| 64 std::string GetContentSecurityPolicyScriptSrc() const override { |
| 65 if (parent_->script_src_set_) |
| 66 return parent_->script_src_; |
| 67 return URLDataSource::GetContentSecurityPolicyScriptSrc(); |
| 68 } |
| 64 std::string GetContentSecurityPolicyObjectSrc() const override { | 69 std::string GetContentSecurityPolicyObjectSrc() const override { |
| 65 if (parent_->object_src_set_) | 70 if (parent_->object_src_set_) |
| 66 return parent_->object_src_; | 71 return parent_->object_src_; |
| 67 return URLDataSource::GetContentSecurityPolicyObjectSrc(); | 72 return URLDataSource::GetContentSecurityPolicyObjectSrc(); |
| 68 } | 73 } |
| 69 std::string GetContentSecurityPolicyChildSrc() const override { | 74 std::string GetContentSecurityPolicyChildSrc() const override { |
| 70 if (parent_->frame_src_set_) | 75 if (parent_->frame_src_set_) |
| 71 return parent_->frame_src_; | 76 return parent_->frame_src_; |
| 72 return URLDataSource::GetContentSecurityPolicyChildSrc(); | 77 return URLDataSource::GetContentSecurityPolicyChildSrc(); |
| 73 } | 78 } |
| 74 bool ShouldDenyXFrameOptions() const override { | 79 bool ShouldDenyXFrameOptions() const override { |
| 75 return parent_->deny_xframe_options_; | 80 return parent_->deny_xframe_options_; |
| 76 } | 81 } |
| 77 bool IsGzipped(const std::string& path) const override { | 82 bool IsGzipped(const std::string& path) const override { |
| 78 return parent_->use_gzip_for_all_paths_ && | 83 return parent_->use_gzip_for_all_paths_ && |
| 79 parent_->excluded_paths_.find(path) == parent_->excluded_paths_.end(); | 84 parent_->excluded_paths_.find(path) == parent_->excluded_paths_.end(); |
| 80 } | 85 } |
| 81 | 86 |
| 82 private: | 87 private: |
| 83 WebUIDataSourceImpl* parent_; | 88 WebUIDataSourceImpl* parent_; |
| 84 }; | 89 }; |
| 85 | 90 |
| 86 WebUIDataSourceImpl::WebUIDataSourceImpl(const std::string& source_name) | 91 WebUIDataSourceImpl::WebUIDataSourceImpl(const std::string& source_name) |
| 87 : URLDataSourceImpl(source_name, new InternalDataSource(this)), | 92 : URLDataSourceImpl(source_name, new InternalDataSource(this)), |
| 88 source_name_(source_name), | 93 source_name_(source_name), |
| 89 default_resource_(-1), | 94 default_resource_(-1), |
| 90 add_csp_(true), | 95 add_csp_(true), |
| 96 script_src_set_(false), |
| 91 object_src_set_(false), | 97 object_src_set_(false), |
| 92 frame_src_set_(false), | 98 frame_src_set_(false), |
| 93 deny_xframe_options_(true), | 99 deny_xframe_options_(true), |
| 94 add_load_time_data_defaults_(true), | 100 add_load_time_data_defaults_(true), |
| 95 replace_existing_source_(true), | 101 replace_existing_source_(true), |
| 96 use_gzip_for_all_paths_(false) {} | 102 use_gzip_for_all_paths_(false) {} |
| 97 | 103 |
| 98 WebUIDataSourceImpl::~WebUIDataSourceImpl() { | 104 WebUIDataSourceImpl::~WebUIDataSourceImpl() { |
| 99 } | 105 } |
| 100 | 106 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 179 } |
| 174 | 180 |
| 175 void WebUIDataSourceImpl::ExcludePathFromGzip(const std::string& path) { | 181 void WebUIDataSourceImpl::ExcludePathFromGzip(const std::string& path) { |
| 176 excluded_paths_.insert(path); | 182 excluded_paths_.insert(path); |
| 177 } | 183 } |
| 178 | 184 |
| 179 void WebUIDataSourceImpl::DisableContentSecurityPolicy() { | 185 void WebUIDataSourceImpl::DisableContentSecurityPolicy() { |
| 180 add_csp_ = false; | 186 add_csp_ = false; |
| 181 } | 187 } |
| 182 | 188 |
| 189 void WebUIDataSourceImpl::OverrideContentSecurityPolicyScriptSrc( |
| 190 const std::string& data) { |
| 191 script_src_set_ = true; |
| 192 script_src_ = data; |
| 193 } |
| 194 |
| 183 void WebUIDataSourceImpl::OverrideContentSecurityPolicyObjectSrc( | 195 void WebUIDataSourceImpl::OverrideContentSecurityPolicyObjectSrc( |
| 184 const std::string& data) { | 196 const std::string& data) { |
| 185 object_src_set_ = true; | 197 object_src_set_ = true; |
| 186 object_src_ = data; | 198 object_src_ = data; |
| 187 } | 199 } |
| 188 | 200 |
| 189 void WebUIDataSourceImpl::OverrideContentSecurityPolicyChildSrc( | 201 void WebUIDataSourceImpl::OverrideContentSecurityPolicyChildSrc( |
| 190 const std::string& data) { | 202 const std::string& data) { |
| 191 frame_src_set_ = true; | 203 frame_src_set_ = true; |
| 192 frame_src_ = data; | 204 frame_src_ = data; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 286 } |
| 275 | 287 |
| 276 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( | 288 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( |
| 277 const URLDataSource::GotDataCallback& callback) { | 289 const URLDataSource::GotDataCallback& callback) { |
| 278 std::string template_data; | 290 std::string template_data; |
| 279 webui::AppendJsonJS(&localized_strings_, &template_data); | 291 webui::AppendJsonJS(&localized_strings_, &template_data); |
| 280 callback.Run(base::RefCountedString::TakeString(&template_data)); | 292 callback.Run(base::RefCountedString::TakeString(&template_data)); |
| 281 } | 293 } |
| 282 | 294 |
| 283 } // namespace content | 295 } // namespace content |
| OLD | NEW |