| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/web/webui/web_ui_ios_data_source_impl.h" | 5 #include "ios/web/webui/web_ui_ios_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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 WebUIIOSDataSourceImpl* parent_; | 61 WebUIIOSDataSourceImpl* parent_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 WebUIIOSDataSourceImpl::WebUIIOSDataSourceImpl(const std::string& source_name) | 64 WebUIIOSDataSourceImpl::WebUIIOSDataSourceImpl(const std::string& source_name) |
| 65 : URLDataSourceIOSImpl(source_name, new InternalDataSource(this)), | 65 : URLDataSourceIOSImpl(source_name, new InternalDataSource(this)), |
| 66 source_name_(source_name), | 66 source_name_(source_name), |
| 67 default_resource_(-1), | 67 default_resource_(-1), |
| 68 deny_xframe_options_(true), | 68 deny_xframe_options_(true), |
| 69 load_time_data_defaults_added_(true), | 69 load_time_data_defaults_added_(false), |
| 70 replace_existing_source_(true) {} | 70 replace_existing_source_(true) {} |
| 71 | 71 |
| 72 WebUIIOSDataSourceImpl::~WebUIIOSDataSourceImpl() {} | 72 WebUIIOSDataSourceImpl::~WebUIIOSDataSourceImpl() {} |
| 73 | 73 |
| 74 void WebUIIOSDataSourceImpl::AddString(const std::string& name, | 74 void WebUIIOSDataSourceImpl::AddString(const std::string& name, |
| 75 const base::string16& value) { | 75 const base::string16& value) { |
| 76 localized_strings_.SetString(name, value); | 76 localized_strings_.SetString(name, value); |
| 77 replacements_[name] = base::UTF16ToUTF8(value); | 77 replacements_[name] = base::UTF16ToUTF8(value); |
| 78 } | 78 } |
| 79 | 79 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 if (base::EndsWith(path, ".css", base::CompareCase::INSENSITIVE_ASCII)) | 135 if (base::EndsWith(path, ".css", base::CompareCase::INSENSITIVE_ASCII)) |
| 136 return "text/css"; | 136 return "text/css"; |
| 137 | 137 |
| 138 if (base::EndsWith(path, ".svg", base::CompareCase::INSENSITIVE_ASCII)) | 138 if (base::EndsWith(path, ".svg", base::CompareCase::INSENSITIVE_ASCII)) |
| 139 return "image/svg+xml"; | 139 return "image/svg+xml"; |
| 140 | 140 |
| 141 return "text/html"; | 141 return "text/html"; |
| 142 } | 142 } |
| 143 | 143 |
| 144 void WebUIIOSDataSourceImpl::EnsureLoadTimeDataDefaultsAdded() { | 144 void WebUIIOSDataSourceImpl::EnsureLoadTimeDataDefaultsAdded() { |
| 145 if (!load_time_data_defaults_added_) | 145 if (load_time_data_defaults_added_) |
| 146 return; | 146 return; |
| 147 | 147 |
| 148 load_time_data_defaults_added_ = false; | 148 load_time_data_defaults_added_ = true; |
| 149 base::DictionaryValue defaults; | 149 base::DictionaryValue defaults; |
| 150 webui::SetLoadTimeDataDefaults(web::GetWebClient()->GetApplicationLocale(), | 150 webui::SetLoadTimeDataDefaults(web::GetWebClient()->GetApplicationLocale(), |
| 151 &defaults); | 151 &defaults); |
| 152 AddLocalizedStrings(defaults); | 152 AddLocalizedStrings(defaults); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void WebUIIOSDataSourceImpl::StartDataRequest( | 155 void WebUIIOSDataSourceImpl::StartDataRequest( |
| 156 const std::string& path, | 156 const std::string& path, |
| 157 const URLDataSourceIOS::GotDataCallback& callback) { | 157 const URLDataSourceIOS::GotDataCallback& callback) { |
| 158 EnsureLoadTimeDataDefaultsAdded(); | 158 EnsureLoadTimeDataDefaultsAdded(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 189 std::string replaced = ui::ReplaceTemplateExpressions( | 189 std::string replaced = ui::ReplaceTemplateExpressions( |
| 190 base::StringPiece(response->front_as<char>(), response->size()), | 190 base::StringPiece(response->front_as<char>(), response->size()), |
| 191 replacements_); | 191 replacements_); |
| 192 response = base::RefCountedString::TakeString(&replaced); | 192 response = base::RefCountedString::TakeString(&replaced); |
| 193 } | 193 } |
| 194 | 194 |
| 195 callback.Run(response); | 195 callback.Run(response); |
| 196 } | 196 } |
| 197 | 197 |
| 198 } // namespace web | 198 } // namespace web |
| OLD | NEW |