| 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/options/content_settings_handler.h" | 5 #include "chrome/browser/dom_ui/options/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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
| 13 #include "chrome/browser/content_settings/content_settings_details.h" |
| 13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 14 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 15 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 15 #include "chrome/browser/notifications/desktop_notification_service.h" | 16 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 16 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/content_settings_helper.h" | 19 #include "chrome/common/content_settings_helper.h" |
| 19 #include "chrome/common/notification_service.h" | 20 #include "chrome/common/notification_service.h" |
| 20 #include "chrome/common/notification_source.h" | 21 #include "chrome/common/notification_source.h" |
| 21 #include "chrome/common/notification_type.h" | 22 #include "chrome/common/notification_type.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 25 #include "grit/locale_settings.h" | 26 #include "grit/locale_settings.h" |
| 26 | 27 |
| 27 typedef HostContentSettingsMap::ContentSettingsDetails ContentSettingsDetails; | |
| 28 | |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 const char* kDisplayPattern = "displayPattern"; | 30 const char* kDisplayPattern = "displayPattern"; |
| 32 const char* kSetting = "setting"; | 31 const char* kSetting = "setting"; |
| 33 const char* kOrigin = "origin"; | 32 const char* kOrigin = "origin"; |
| 34 const char* kEmbeddingOrigin = "embeddingOrigin"; | 33 const char* kEmbeddingOrigin = "embeddingOrigin"; |
| 35 | 34 |
| 36 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { | 35 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { |
| 37 if (name == "cookies") | 36 if (name == "cookies") |
| 38 return CONTENT_SETTINGS_TYPE_COOKIES; | 37 return CONTENT_SETTINGS_TYPE_COOKIES; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 104 |
| 106 return indent + l10n_util::GetStringFUTF8( | 105 return indent + l10n_util::GetStringFUTF8( |
| 107 IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST, | 106 IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST, |
| 108 UTF8ToUTF16(content_settings_helper::OriginToString(embedding_origin))); | 107 UTF8ToUTF16(content_settings_helper::OriginToString(embedding_origin))); |
| 109 } | 108 } |
| 110 | 109 |
| 111 // Create a DictionaryValue* that will act as a data source for a single row | 110 // Create a DictionaryValue* that will act as a data source for a single row |
| 112 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). | 111 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). |
| 113 // Ownership of the pointer is passed to the caller. | 112 // Ownership of the pointer is passed to the caller. |
| 114 DictionaryValue* GetExceptionForPage( | 113 DictionaryValue* GetExceptionForPage( |
| 115 const HostContentSettingsMap::Pattern pattern, | 114 const ContentSettingsPattern pattern, |
| 116 ContentSetting setting) { | 115 ContentSetting setting) { |
| 117 DictionaryValue* exception = new DictionaryValue(); | 116 DictionaryValue* exception = new DictionaryValue(); |
| 118 exception->Set( | 117 exception->Set( |
| 119 kDisplayPattern, | 118 kDisplayPattern, |
| 120 new StringValue(pattern.AsString())); | 119 new StringValue(pattern.AsString())); |
| 121 exception->Set( | 120 exception->Set( |
| 122 kSetting, | 121 kSetting, |
| 123 new StringValue(ContentSettingToString(setting))); | 122 new StringValue(ContentSettingToString(setting))); |
| 124 return exception; | 123 return exception; |
| 125 } | 124 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 break; | 322 break; |
| 324 } | 323 } |
| 325 | 324 |
| 326 case NotificationType::OTR_PROFILE_CREATED: { | 325 case NotificationType::OTR_PROFILE_CREATED: { |
| 327 UpdateAllOTRExceptionsViewsFromModel(); | 326 UpdateAllOTRExceptionsViewsFromModel(); |
| 328 break; | 327 break; |
| 329 } | 328 } |
| 330 | 329 |
| 331 case NotificationType::CONTENT_SETTINGS_CHANGED: { | 330 case NotificationType::CONTENT_SETTINGS_CHANGED: { |
| 332 const ContentSettingsDetails* settings_details = | 331 const ContentSettingsDetails* settings_details = |
| 333 static_cast<Details<const ContentSettingsDetails> >(details).ptr(); | 332 Details<const ContentSettingsDetails>(details).ptr(); |
| 334 | 333 |
| 335 // TODO(estade): we pretend update_all() is always true. | 334 // TODO(estade): we pretend update_all() is always true. |
| 336 if (settings_details->update_all_types()) | 335 if (settings_details->update_all_types()) |
| 337 UpdateAllExceptionsViewsFromModel(); | 336 UpdateAllExceptionsViewsFromModel(); |
| 338 else | 337 else |
| 339 UpdateExceptionsViewFromModel(settings_details->type()); | 338 UpdateExceptionsViewFromModel(settings_details->type()); |
| 340 break; | 339 break; |
| 341 } | 340 } |
| 342 | 341 |
| 343 case NotificationType::PREF_CHANGED: { | 342 case NotificationType::PREF_CHANGED: { |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 rv = args->GetString(arg_i++, &pattern); | 625 rv = args->GetString(arg_i++, &pattern); |
| 627 DCHECK(rv); | 626 DCHECK(rv); |
| 628 | 627 |
| 629 HostContentSettingsMap* settings_map = | 628 HostContentSettingsMap* settings_map = |
| 630 mode == "normal" ? GetContentSettingsMap() : | 629 mode == "normal" ? GetContentSettingsMap() : |
| 631 GetOTRContentSettingsMap(); | 630 GetOTRContentSettingsMap(); |
| 632 // The settings map could be null if the mode was OTR but the OTR profile | 631 // The settings map could be null if the mode was OTR but the OTR profile |
| 633 // got destroyed before we received this message. | 632 // got destroyed before we received this message. |
| 634 if (settings_map) { | 633 if (settings_map) { |
| 635 settings_map->SetContentSetting( | 634 settings_map->SetContentSetting( |
| 636 HostContentSettingsMap::Pattern(pattern), | 635 ContentSettingsPattern(pattern), |
| 637 ContentSettingsTypeFromGroupName(type_string), | 636 ContentSettingsTypeFromGroupName(type_string), |
| 638 "", | 637 "", |
| 639 CONTENT_SETTING_DEFAULT); | 638 CONTENT_SETTING_DEFAULT); |
| 640 } | 639 } |
| 641 } | 640 } |
| 642 } | 641 } |
| 643 } | 642 } |
| 644 | 643 |
| 645 void ContentSettingsHandler::SetException(const ListValue* args) { | 644 void ContentSettingsHandler::SetException(const ListValue* args) { |
| 646 size_t arg_i = 0; | 645 size_t arg_i = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 662 | 661 |
| 663 HostContentSettingsMap* settings_map = | 662 HostContentSettingsMap* settings_map = |
| 664 mode == "normal" ? GetContentSettingsMap() : | 663 mode == "normal" ? GetContentSettingsMap() : |
| 665 GetOTRContentSettingsMap(); | 664 GetOTRContentSettingsMap(); |
| 666 | 665 |
| 667 // The settings map could be null if the mode was OTR but the OTR profile | 666 // The settings map could be null if the mode was OTR but the OTR profile |
| 668 // got destroyed before we received this message. | 667 // got destroyed before we received this message. |
| 669 if (!settings_map) | 668 if (!settings_map) |
| 670 return; | 669 return; |
| 671 | 670 |
| 672 settings_map-> | 671 settings_map->SetContentSetting(ContentSettingsPattern(pattern), |
| 673 SetContentSetting(HostContentSettingsMap::Pattern(pattern), | 672 type, |
| 674 type, | 673 "", |
| 675 "", | 674 ContentSettingFromString(setting)); |
| 676 ContentSettingFromString(setting)); | |
| 677 } | 675 } |
| 678 | 676 |
| 679 void ContentSettingsHandler::CheckExceptionPatternValidity( | 677 void ContentSettingsHandler::CheckExceptionPatternValidity( |
| 680 const ListValue* args) { | 678 const ListValue* args) { |
| 681 size_t arg_i = 0; | 679 size_t arg_i = 0; |
| 682 Value* type; | 680 Value* type; |
| 683 CHECK(args->Get(arg_i++, &type)); | 681 CHECK(args->Get(arg_i++, &type)); |
| 684 std::string mode_string; | 682 std::string mode_string; |
| 685 CHECK(args->GetString(arg_i++, &mode_string)); | 683 CHECK(args->GetString(arg_i++, &mode_string)); |
| 686 std::string pattern_string; | 684 std::string pattern_string; |
| 687 CHECK(args->GetString(arg_i++, &pattern_string)); | 685 CHECK(args->GetString(arg_i++, &pattern_string)); |
| 688 | 686 |
| 689 HostContentSettingsMap::Pattern pattern(pattern_string); | 687 ContentSettingsPattern pattern(pattern_string); |
| 690 | 688 |
| 691 scoped_ptr<Value> mode_value(Value::CreateStringValue(mode_string)); | 689 scoped_ptr<Value> mode_value(Value::CreateStringValue(mode_string)); |
| 692 scoped_ptr<Value> pattern_value(Value::CreateStringValue(pattern_string)); | 690 scoped_ptr<Value> pattern_value(Value::CreateStringValue(pattern_string)); |
| 693 scoped_ptr<Value> valid_value(Value::CreateBooleanValue(pattern.IsValid())); | 691 scoped_ptr<Value> valid_value(Value::CreateBooleanValue(pattern.IsValid())); |
| 694 | 692 |
| 695 dom_ui_->CallJavascriptFunction( | 693 dom_ui_->CallJavascriptFunction( |
| 696 L"ContentSettings.patternValidityCheckComplete", *type, | 694 L"ContentSettings.patternValidityCheckComplete", *type, |
| 697 *mode_value.get(), | 695 *mode_value.get(), |
| 698 *pattern_value.get(), | 696 *pattern_value.get(), |
| 699 *valid_value.get()); | 697 *valid_value.get()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 return dom_ui_->GetProfile()->GetHostContentSettingsMap(); | 730 return dom_ui_->GetProfile()->GetHostContentSettingsMap(); |
| 733 } | 731 } |
| 734 | 732 |
| 735 HostContentSettingsMap* | 733 HostContentSettingsMap* |
| 736 ContentSettingsHandler::GetOTRContentSettingsMap() { | 734 ContentSettingsHandler::GetOTRContentSettingsMap() { |
| 737 Profile* profile = dom_ui_->GetProfile(); | 735 Profile* profile = dom_ui_->GetProfile(); |
| 738 if (profile->HasOffTheRecordProfile()) | 736 if (profile->HasOffTheRecordProfile()) |
| 739 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 737 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
| 740 return NULL; | 738 return NULL; |
| 741 } | 739 } |
| OLD | NEW |