| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/logging.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "content/grit/content_resources.h" | 18 #include "content/grit/content_resources.h" |
| 18 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
| 19 #include "content/public/common/content_client.h" | 20 #include "content/public/common/content_client.h" |
| 20 #include "ui/base/template_expressions.h" | 21 #include "ui/base/template_expressions.h" |
| 21 #include "ui/base/webui/jstemplate_builder.h" | 22 #include "ui/base/webui/jstemplate_builder.h" |
| 22 #include "ui/base/webui/web_ui_util.h" | 23 #include "ui/base/webui/web_ui_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 68 } |
| 68 std::string GetContentSecurityPolicyChildSrc() const override { | 69 std::string GetContentSecurityPolicyChildSrc() const override { |
| 69 if (parent_->frame_src_set_) | 70 if (parent_->frame_src_set_) |
| 70 return parent_->frame_src_; | 71 return parent_->frame_src_; |
| 71 return URLDataSource::GetContentSecurityPolicyChildSrc(); | 72 return URLDataSource::GetContentSecurityPolicyChildSrc(); |
| 72 } | 73 } |
| 73 bool ShouldDenyXFrameOptions() const override { | 74 bool ShouldDenyXFrameOptions() const override { |
| 74 return parent_->deny_xframe_options_; | 75 return parent_->deny_xframe_options_; |
| 75 } | 76 } |
| 76 bool IsGzipped(const std::string& path) const override { | 77 bool IsGzipped(const std::string& path) const override { |
| 77 if (!parent_->json_path_.empty() && path == parent_->json_path_) | 78 return parent_->use_gzip_for_all_paths_ && |
| 78 return false; | 79 parent_->excluded_paths_.find(path) == parent_->excluded_paths_.end(); |
| 79 return parent_->use_gzip_for_all_paths_; | |
| 80 } | 80 } |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 WebUIDataSourceImpl* parent_; | 83 WebUIDataSourceImpl* parent_; |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 WebUIDataSourceImpl::WebUIDataSourceImpl(const std::string& source_name) | 86 WebUIDataSourceImpl::WebUIDataSourceImpl(const std::string& source_name) |
| 87 : URLDataSourceImpl(source_name, new InternalDataSource(this)), | 87 : URLDataSourceImpl(source_name, new InternalDataSource(this)), |
| 88 source_name_(source_name), | 88 source_name_(source_name), |
| 89 default_resource_(-1), | 89 default_resource_(-1), |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // localization. The boolean values are not added to |replacements_| | 140 // localization. The boolean values are not added to |replacements_| |
| 141 // for the same reason, that they are used as flags, rather than string | 141 // for the same reason, that they are used as flags, rather than string |
| 142 // replacements. | 142 // replacements. |
| 143 } | 143 } |
| 144 | 144 |
| 145 void WebUIDataSourceImpl::AddInteger(const std::string& name, int32_t value) { | 145 void WebUIDataSourceImpl::AddInteger(const std::string& name, int32_t value) { |
| 146 localized_strings_.SetInteger(name, value); | 146 localized_strings_.SetInteger(name, value); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void WebUIDataSourceImpl::SetJsonPath(const std::string& path) { | 149 void WebUIDataSourceImpl::SetJsonPath(const std::string& path) { |
| 150 DCHECK(json_path_.empty()); |
| 151 DCHECK(!path.empty()); |
| 152 |
| 150 json_path_ = path; | 153 json_path_ = path; |
| 154 ExcludePathFromGzip(json_path_); |
| 151 } | 155 } |
| 152 | 156 |
| 153 void WebUIDataSourceImpl::AddResourcePath(const std::string &path, | 157 void WebUIDataSourceImpl::AddResourcePath(const std::string &path, |
| 154 int resource_id) { | 158 int resource_id) { |
| 155 path_to_idr_map_[path] = resource_id; | 159 path_to_idr_map_[path] = resource_id; |
| 156 } | 160 } |
| 157 | 161 |
| 158 void WebUIDataSourceImpl::SetDefaultResource(int resource_id) { | 162 void WebUIDataSourceImpl::SetDefaultResource(int resource_id) { |
| 159 default_resource_ = resource_id; | 163 default_resource_ = resource_id; |
| 160 } | 164 } |
| 161 | 165 |
| 162 void WebUIDataSourceImpl::SetRequestFilter( | 166 void WebUIDataSourceImpl::SetRequestFilter( |
| 163 const WebUIDataSource::HandleRequestCallback& callback) { | 167 const WebUIDataSource::HandleRequestCallback& callback) { |
| 164 filter_callback_ = callback; | 168 filter_callback_ = callback; |
| 165 } | 169 } |
| 166 | 170 |
| 167 void WebUIDataSourceImpl::DisableReplaceExistingSource() { | 171 void WebUIDataSourceImpl::DisableReplaceExistingSource() { |
| 168 replace_existing_source_ = false; | 172 replace_existing_source_ = false; |
| 169 } | 173 } |
| 170 | 174 |
| 175 void WebUIDataSourceImpl::ExcludePathFromGzip(const std::string& path) { |
| 176 excluded_paths_.insert(path); |
| 177 } |
| 178 |
| 171 void WebUIDataSourceImpl::DisableContentSecurityPolicy() { | 179 void WebUIDataSourceImpl::DisableContentSecurityPolicy() { |
| 172 add_csp_ = false; | 180 add_csp_ = false; |
| 173 } | 181 } |
| 174 | 182 |
| 175 void WebUIDataSourceImpl::OverrideContentSecurityPolicyObjectSrc( | 183 void WebUIDataSourceImpl::OverrideContentSecurityPolicyObjectSrc( |
| 176 const std::string& data) { | 184 const std::string& data) { |
| 177 object_src_set_ = true; | 185 object_src_set_ = true; |
| 178 object_src_ = data; | 186 object_src_ = data; |
| 179 } | 187 } |
| 180 | 188 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 274 } |
| 267 | 275 |
| 268 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( | 276 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( |
| 269 const URLDataSource::GotDataCallback& callback) { | 277 const URLDataSource::GotDataCallback& callback) { |
| 270 std::string template_data; | 278 std::string template_data; |
| 271 webui::AppendJsonJS(&localized_strings_, &template_data); | 279 webui::AppendJsonJS(&localized_strings_, &template_data); |
| 272 callback.Run(base::RefCountedString::TakeString(&template_data)); | 280 callback.Run(base::RefCountedString::TakeString(&template_data)); |
| 273 } | 281 } |
| 274 | 282 |
| 275 } // namespace content | 283 } // namespace content |
| OLD | NEW |