| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/content_settings_handler.h" | 5 #include "chrome/browser/dom_ui/content_settings_handler.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 UpdateImagesExceptionsViewFromModel(); | 254 UpdateImagesExceptionsViewFromModel(); |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 | 257 |
| 258 // TODO(estade): generalize this function to work on all content settings types | 258 // TODO(estade): generalize this function to work on all content settings types |
| 259 // rather than just images. | 259 // rather than just images. |
| 260 void ContentSettingsHandler::UpdateImagesExceptionsViewFromModel() { | 260 void ContentSettingsHandler::UpdateImagesExceptionsViewFromModel() { |
| 261 HostContentSettingsMap::SettingsForOneType entries; | 261 HostContentSettingsMap::SettingsForOneType entries; |
| 262 const HostContentSettingsMap* settings_map = | 262 const HostContentSettingsMap* settings_map = |
| 263 dom_ui_->GetProfile()->GetHostContentSettingsMap(); | 263 dom_ui_->GetProfile()->GetHostContentSettingsMap(); |
| 264 settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, &entries); | 264 settings_map->GetSettingsForOneType( |
| 265 CONTENT_SETTINGS_TYPE_IMAGES, "", &entries); |
| 265 | 266 |
| 266 ListValue exceptions; | 267 ListValue exceptions; |
| 267 for (size_t i = 0; i < entries.size(); ++i) { | 268 for (size_t i = 0; i < entries.size(); ++i) { |
| 268 ListValue* exception = new ListValue(); | 269 ListValue* exception = new ListValue(); |
| 269 exception->Append(new StringValue(entries[i].first.AsString())); | 270 exception->Append(new StringValue(entries[i].first.AsString())); |
| 270 exception->Append( | 271 exception->Append( |
| 271 new StringValue(ContentSettingToString(entries[i].second))); | 272 new StringValue(ContentSettingToString(entries[i].second))); |
| 272 exceptions.Append(exception); | 273 exceptions.Append(exception); |
| 273 } | 274 } |
| 274 | 275 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 const ListValue* list_value = static_cast<const ListValue*>(value); | 320 const ListValue* list_value = static_cast<const ListValue*>(value); |
| 320 | 321 |
| 321 HostContentSettingsMap* settings_map = | 322 HostContentSettingsMap* settings_map = |
| 322 dom_ui_->GetProfile()->GetHostContentSettingsMap(); | 323 dom_ui_->GetProfile()->GetHostContentSettingsMap(); |
| 323 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 324 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
| 324 std::string pattern; | 325 std::string pattern; |
| 325 bool rv = list_value->GetString(i, &pattern); | 326 bool rv = list_value->GetString(i, &pattern); |
| 326 DCHECK(rv); | 327 DCHECK(rv); |
| 327 settings_map->SetContentSetting(HostContentSettingsMap::Pattern(pattern), | 328 settings_map->SetContentSetting(HostContentSettingsMap::Pattern(pattern), |
| 328 CONTENT_SETTINGS_TYPE_IMAGES, | 329 CONTENT_SETTINGS_TYPE_IMAGES, |
| 330 "", |
| 329 CONTENT_SETTING_DEFAULT); | 331 CONTENT_SETTING_DEFAULT); |
| 330 } | 332 } |
| 331 } | 333 } |
| 332 | 334 |
| 333 // TODO(estade): generalize this function to work on all content settings types | 335 // TODO(estade): generalize this function to work on all content settings types |
| 334 // rather than just images. | 336 // rather than just images. |
| 335 void ContentSettingsHandler::SetException(const Value* value) { | 337 void ContentSettingsHandler::SetException(const Value* value) { |
| 336 const ListValue* list_value = static_cast<const ListValue*>(value); | 338 const ListValue* list_value = static_cast<const ListValue*>(value); |
| 337 std::string pattern; | 339 std::string pattern; |
| 338 bool rv = list_value->GetString(0, &pattern); | 340 bool rv = list_value->GetString(0, &pattern); |
| 339 DCHECK(rv); | 341 DCHECK(rv); |
| 340 std::string setting; | 342 std::string setting; |
| 341 rv = list_value->GetString(1, &setting); | 343 rv = list_value->GetString(1, &setting); |
| 342 DCHECK(rv); | 344 DCHECK(rv); |
| 343 | 345 |
| 344 HostContentSettingsMap* settings_map = | 346 HostContentSettingsMap* settings_map = |
| 345 dom_ui_->GetProfile()->GetHostContentSettingsMap(); | 347 dom_ui_->GetProfile()->GetHostContentSettingsMap(); |
| 346 settings_map->SetContentSetting(HostContentSettingsMap::Pattern(pattern), | 348 settings_map->SetContentSetting(HostContentSettingsMap::Pattern(pattern), |
| 347 CONTENT_SETTINGS_TYPE_IMAGES, | 349 CONTENT_SETTINGS_TYPE_IMAGES, |
| 350 "", |
| 348 ContentSettingFromString(setting)); | 351 ContentSettingFromString(setting)); |
| 349 } | 352 } |
| OLD | NEW |