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 "chrome/browser/ui/webui/options/options_ui.h" | 5 #include "chrome/browser/ui/webui/options/options_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 public: | 193 public: |
194 // The constructor takes over ownership of |localized_strings|. | 194 // The constructor takes over ownership of |localized_strings|. |
195 explicit OptionsUIHTMLSource(base::DictionaryValue* localized_strings); | 195 explicit OptionsUIHTMLSource(base::DictionaryValue* localized_strings); |
196 | 196 |
197 // content::URLDataSource implementation. | 197 // content::URLDataSource implementation. |
198 std::string GetSource() const override; | 198 std::string GetSource() const override; |
199 void StartDataRequest( | 199 void StartDataRequest( |
200 const std::string& path, | 200 const std::string& path, |
201 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 201 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
202 const content::URLDataSource::GotDataCallback& callback) override; | 202 const content::URLDataSource::GotDataCallback& callback) override; |
| 203 bool AllowCaching() const override; |
203 std::string GetMimeType(const std::string&) const override; | 204 std::string GetMimeType(const std::string&) const override; |
204 bool ShouldDenyXFrameOptions() const override; | 205 bool ShouldDenyXFrameOptions() const override; |
205 | 206 |
206 private: | 207 private: |
207 ~OptionsUIHTMLSource() override; | 208 ~OptionsUIHTMLSource() override; |
208 void CreateDataSourceMap(); | 209 void CreateDataSourceMap(); |
209 | 210 |
210 // Localized strings collection. | 211 // Localized strings collection. |
211 std::unique_ptr<base::DictionaryValue> localized_strings_; | 212 std::unique_ptr<base::DictionaryValue> localized_strings_; |
212 std::map<std::string, int> path_to_idr_map_; | 213 std::map<std::string, int> path_to_idr_map_; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 std::string replaced = ui::ReplaceTemplateExpressions( | 264 std::string replaced = ui::ReplaceTemplateExpressions( |
264 base::StringPiece(response_bytes->front_as<char>(), | 265 base::StringPiece(response_bytes->front_as<char>(), |
265 response_bytes->size()), | 266 response_bytes->size()), |
266 replacements_); | 267 replacements_); |
267 response_bytes = base::RefCountedString::TakeString(&replaced); | 268 response_bytes = base::RefCountedString::TakeString(&replaced); |
268 } | 269 } |
269 | 270 |
270 callback.Run(response_bytes.get()); | 271 callback.Run(response_bytes.get()); |
271 } | 272 } |
272 | 273 |
| 274 bool OptionsUIHTMLSource::AllowCaching() const { |
| 275 // Should not be cached to reflect dynamically-generated contents that depends |
| 276 // on the current locale. |
| 277 return false; |
| 278 } |
| 279 |
273 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { | 280 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { |
274 if (base::EndsWith(path, ".js", base::CompareCase::INSENSITIVE_ASCII)) | 281 if (base::EndsWith(path, ".js", base::CompareCase::INSENSITIVE_ASCII)) |
275 return "application/javascript"; | 282 return "application/javascript"; |
276 | 283 |
277 return "text/html"; | 284 return "text/html"; |
278 } | 285 } |
279 | 286 |
280 bool OptionsUIHTMLSource::ShouldDenyXFrameOptions() const { | 287 bool OptionsUIHTMLSource::ShouldDenyXFrameOptions() const { |
281 return false; | 288 return false; |
282 } | 289 } |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 // Add only if handler's service is enabled. | 636 // Add only if handler's service is enabled. |
630 if (handler->IsEnabled()) { | 637 if (handler->IsEnabled()) { |
631 // Add handler to the list and also pass the ownership. | 638 // Add handler to the list and also pass the ownership. |
632 web_ui()->AddMessageHandler(std::move(handler)); | 639 web_ui()->AddMessageHandler(std::move(handler)); |
633 handler_raw->GetLocalizedValues(localized_strings); | 640 handler_raw->GetLocalizedValues(localized_strings); |
634 handlers_.push_back(handler_raw); | 641 handlers_.push_back(handler_raw); |
635 } | 642 } |
636 } | 643 } |
637 | 644 |
638 } // namespace options | 645 } // namespace options |
OLD | NEW |