| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 private: | 103 private: |
| 104 WebUIDataSourceImpl* parent_; | 104 WebUIDataSourceImpl* parent_; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 WebUIDataSourceImpl::WebUIDataSourceImpl(const std::string& source_name) | 107 WebUIDataSourceImpl::WebUIDataSourceImpl(const std::string& source_name) |
| 108 : URLDataSourceImpl( | 108 : URLDataSourceImpl( |
| 109 source_name, | 109 source_name, |
| 110 new InternalDataSource(this)), | 110 new InternalDataSource(this)), |
| 111 source_name_(source_name), | 111 source_name_(source_name), |
| 112 default_resource_(-1), | 112 default_resource_(-1), |
| 113 json_js_format_v2_(false), | |
| 114 add_csp_(true), | 113 add_csp_(true), |
| 115 object_src_set_(false), | 114 object_src_set_(false), |
| 116 frame_src_set_(false), | 115 frame_src_set_(false), |
| 117 deny_xframe_options_(true), | 116 deny_xframe_options_(true), |
| 118 disable_set_font_strings_(false), | 117 disable_set_font_strings_(false), |
| 119 replace_existing_source_(true) { | 118 replace_existing_source_(true) { |
| 120 } | 119 } |
| 121 | 120 |
| 122 WebUIDataSourceImpl::~WebUIDataSourceImpl() { | 121 WebUIDataSourceImpl::~WebUIDataSourceImpl() { |
| 123 } | 122 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 144 } | 143 } |
| 145 | 144 |
| 146 void WebUIDataSourceImpl::AddBoolean(const std::string& name, bool value) { | 145 void WebUIDataSourceImpl::AddBoolean(const std::string& name, bool value) { |
| 147 localized_strings_.SetBoolean(name, value); | 146 localized_strings_.SetBoolean(name, value); |
| 148 } | 147 } |
| 149 | 148 |
| 150 void WebUIDataSourceImpl::SetJsonPath(const std::string& path) { | 149 void WebUIDataSourceImpl::SetJsonPath(const std::string& path) { |
| 151 json_path_ = path; | 150 json_path_ = path; |
| 152 } | 151 } |
| 153 | 152 |
| 154 void WebUIDataSourceImpl::SetUseJsonJSFormatV2() { | |
| 155 json_js_format_v2_ = true; | |
| 156 } | |
| 157 | |
| 158 void WebUIDataSourceImpl::AddResourcePath(const std::string &path, | 153 void WebUIDataSourceImpl::AddResourcePath(const std::string &path, |
| 159 int resource_id) { | 154 int resource_id) { |
| 160 path_to_idr_map_[path] = resource_id; | 155 path_to_idr_map_[path] = resource_id; |
| 161 } | 156 } |
| 162 | 157 |
| 163 void WebUIDataSourceImpl::SetDefaultResource(int resource_id) { | 158 void WebUIDataSourceImpl::SetDefaultResource(int resource_id) { |
| 164 default_resource_ = resource_id; | 159 default_resource_ = resource_id; |
| 165 } | 160 } |
| 166 | 161 |
| 167 void WebUIDataSourceImpl::SetRequestFilter( | 162 void WebUIDataSourceImpl::SetRequestFilter( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 DCHECK_NE(resource_id, -1); | 231 DCHECK_NE(resource_id, -1); |
| 237 SendFromResourceBundle(callback, resource_id); | 232 SendFromResourceBundle(callback, resource_id); |
| 238 } | 233 } |
| 239 | 234 |
| 240 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( | 235 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( |
| 241 const URLDataSource::GotDataCallback& callback) { | 236 const URLDataSource::GotDataCallback& callback) { |
| 242 std::string template_data; | 237 std::string template_data; |
| 243 if (!disable_set_font_strings_) | 238 if (!disable_set_font_strings_) |
| 244 webui::SetFontAndTextDirection(&localized_strings_); | 239 webui::SetFontAndTextDirection(&localized_strings_); |
| 245 | 240 |
| 246 scoped_ptr<webui::UseVersion2> version2; | |
| 247 if (json_js_format_v2_) | |
| 248 version2.reset(new webui::UseVersion2); | |
| 249 | |
| 250 webui::AppendJsonJS(&localized_strings_, &template_data); | 241 webui::AppendJsonJS(&localized_strings_, &template_data); |
| 251 callback.Run(base::RefCountedString::TakeString(&template_data)); | 242 callback.Run(base::RefCountedString::TakeString(&template_data)); |
| 252 } | 243 } |
| 253 | 244 |
| 254 void WebUIDataSourceImpl::SendFromResourceBundle( | 245 void WebUIDataSourceImpl::SendFromResourceBundle( |
| 255 const URLDataSource::GotDataCallback& callback, int idr) { | 246 const URLDataSource::GotDataCallback& callback, int idr) { |
| 256 scoped_refptr<base::RefCountedStaticMemory> response( | 247 scoped_refptr<base::RefCountedStaticMemory> response( |
| 257 GetContentClient()->GetDataResourceBytes(idr)); | 248 GetContentClient()->GetDataResourceBytes(idr)); |
| 258 callback.Run(response.get()); | 249 callback.Run(response.get()); |
| 259 } | 250 } |
| 260 | 251 |
| 261 } // namespace content | 252 } // namespace content |
| OLD | NEW |