OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/content_settings_handler.h" | 5 #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/content_settings/content_settings_details.h" | 17 #include "chrome/browser/content_settings/content_settings_details.h" |
18 #include "chrome/browser/content_settings/content_settings_utils.h" | 18 #include "chrome/browser/content_settings/content_settings_utils.h" |
19 #include "chrome/browser/content_settings/cookie_settings.h" | |
19 #include "chrome/browser/content_settings/host_content_settings_map.h" | 20 #include "chrome/browser/content_settings/host_content_settings_map.h" |
20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 21 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
21 #include "chrome/browser/notifications/desktop_notification_service.h" | 22 #include "chrome/browser/notifications/desktop_notification_service.h" |
22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 23 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
25 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/content_settings_pattern.h" | 28 #include "chrome/common/content_settings_pattern.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 } | 378 } |
378 | 379 |
379 std::string ContentSettingsHandler::GetSettingDefaultFromModel( | 380 std::string ContentSettingsHandler::GetSettingDefaultFromModel( |
380 ContentSettingsType type, std::string* provider_id) { | 381 ContentSettingsType type, std::string* provider_id) { |
381 Profile* profile = Profile::FromWebUI(web_ui_); | 382 Profile* profile = Profile::FromWebUI(web_ui_); |
382 ContentSetting default_setting; | 383 ContentSetting default_setting; |
383 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 384 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
384 default_setting = | 385 default_setting = |
385 DesktopNotificationServiceFactory::GetForProfile(profile)-> | 386 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
386 GetDefaultContentSetting(provider_id); | 387 GetDefaultContentSetting(provider_id); |
388 } else if (type == CONTENT_SETTINGS_TYPE_COOKIES) { | |
389 default_setting = CookieSettings::GetForProfile(profile)-> | |
390 GetDefaultCookieSetting(provider_id); | |
387 } else { | 391 } else { |
388 default_setting = | 392 default_setting = |
389 profile->GetHostContentSettingsMap()-> | 393 profile->GetHostContentSettingsMap()-> |
390 GetDefaultContentSetting(type, provider_id); | 394 GetDefaultContentSetting(type, provider_id); |
391 } | 395 } |
392 | 396 |
393 return ContentSettingToString(default_setting); | 397 return ContentSettingToString(default_setting); |
394 } | 398 } |
395 | 399 |
396 void ContentSettingsHandler::UpdateHandlersEnabledRadios() { | 400 void ContentSettingsHandler::UpdateHandlersEnabledRadios() { |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 ClearSetting(ContentSettingsPattern::FromString(origin)); | 705 ClearSetting(ContentSettingsPattern::FromString(origin)); |
702 } else { | 706 } else { |
703 std::string mode; | 707 std::string mode; |
704 bool rv = args->GetString(arg_i++, &mode); | 708 bool rv = args->GetString(arg_i++, &mode); |
705 DCHECK(rv); | 709 DCHECK(rv); |
706 | 710 |
707 std::string pattern; | 711 std::string pattern; |
708 rv = args->GetString(arg_i++, &pattern); | 712 rv = args->GetString(arg_i++, &pattern); |
709 DCHECK(rv); | 713 DCHECK(rv); |
710 | 714 |
711 HostContentSettingsMap* settings_map = | 715 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
712 mode == "normal" ? GetContentSettingsMap() : | 716 CookieSettings* cookie_settings = |
713 GetOTRContentSettingsMap(); | 717 mode == "normal" ? GetCookieSettings() : |
714 // The settings map could be null if the mode was OTR but the OTR profile | 718 GetOTRCookieSettings(); |
715 // got destroyed before we received this message. | 719 // |cookie_settings| could be null if the mode was OTR but the OTR profile |
716 if (settings_map) { | 720 // got destroyed before we received this message. |
717 settings_map->SetContentSetting( | 721 if (cookie_settings) { |
718 ContentSettingsPattern::FromString(pattern), | 722 cookie_settings->ResetCookieSetting( |
719 ContentSettingsPattern::Wildcard(), | 723 ContentSettingsPattern::FromString(pattern)); |
Bernhard Bauer
2011/10/25 13:11:21
Is it actually necessary to go through CookieSetti
marja
2011/10/26 13:03:21
There are 2 approaches: 1) Everything goes via Coo
Bernhard Bauer
2011/10/26 13:24:09
I think it's fine if code that is not specific to
marja
2011/10/27 08:48:51
Ok, I removed the CookieSettings usage here.
| |
720 ContentSettingsTypeFromGroupName(type_string), | 724 } |
721 "", | 725 } else { |
722 CONTENT_SETTING_DEFAULT); | 726 HostContentSettingsMap* settings_map = |
727 mode == "normal" ? GetContentSettingsMap() : | |
728 GetOTRContentSettingsMap(); | |
729 // |settings_map| could be null if the mode was OTR but the OTR profile | |
730 // got destroyed before we received this message. | |
731 if (settings_map) { | |
732 settings_map->SetContentSetting( | |
733 ContentSettingsPattern::FromString(pattern), | |
734 ContentSettingsPattern::Wildcard(), | |
735 ContentSettingsTypeFromGroupName(type_string), | |
736 "", | |
737 CONTENT_SETTING_DEFAULT); | |
738 } | |
723 } | 739 } |
724 } | 740 } |
725 } | 741 } |
726 | 742 |
727 void ContentSettingsHandler::SetException(const ListValue* args) { | 743 void ContentSettingsHandler::SetException(const ListValue* args) { |
728 size_t arg_i = 0; | 744 size_t arg_i = 0; |
729 std::string type_string; | 745 std::string type_string; |
730 CHECK(args->GetString(arg_i++, &type_string)); | 746 CHECK(args->GetString(arg_i++, &type_string)); |
731 std::string mode; | 747 std::string mode; |
732 CHECK(args->GetString(arg_i++, &mode)); | 748 CHECK(args->GetString(arg_i++, &mode)); |
733 std::string pattern; | 749 std::string pattern; |
734 CHECK(args->GetString(arg_i++, &pattern)); | 750 CHECK(args->GetString(arg_i++, &pattern)); |
735 std::string setting; | 751 std::string setting; |
736 CHECK(args->GetString(arg_i++, &setting)); | 752 CHECK(args->GetString(arg_i++, &setting)); |
737 | 753 |
738 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 754 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); |
739 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || | 755 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || |
740 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 756 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
741 NOTREACHED(); | 757 NOTREACHED(); |
742 return; | 758 return; |
743 } | 759 } |
744 | 760 |
745 HostContentSettingsMap* settings_map = | 761 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
746 mode == "normal" ? GetContentSettingsMap() : | 762 CookieSettings* cookie_settings = |
747 GetOTRContentSettingsMap(); | 763 mode == "normal" ? GetCookieSettings() : |
764 GetOTRCookieSettings(); | |
748 | 765 |
749 // The settings map could be null if the mode was OTR but the OTR profile | 766 // |cookie_settings| could be null if the mode was OTR but the OTR profile |
750 // got destroyed before we received this message. | 767 // got destroyed before we received this message. |
751 if (!settings_map) | 768 if (!cookie_settings) |
752 return; | 769 return; |
753 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), | 770 cookie_settings->SetCookieSetting( |
754 ContentSettingsPattern::Wildcard(), | 771 ContentSettingsPattern::FromString(pattern), |
755 type, | 772 ContentSettingFromString(setting)); |
756 "", | 773 } else { |
757 ContentSettingFromString(setting)); | 774 HostContentSettingsMap* settings_map = |
775 mode == "normal" ? GetContentSettingsMap() : | |
776 GetOTRContentSettingsMap(); | |
777 | |
778 // |settings_map| could be null if the mode was OTR but the OTR profile | |
779 // got destroyed before we received this message. | |
780 if (!settings_map) | |
781 return; | |
782 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), | |
783 ContentSettingsPattern::Wildcard(), | |
784 type, | |
785 "", | |
786 ContentSettingFromString(setting)); | |
787 } | |
758 } | 788 } |
759 | 789 |
760 void ContentSettingsHandler::CheckExceptionPatternValidity( | 790 void ContentSettingsHandler::CheckExceptionPatternValidity( |
761 const ListValue* args) { | 791 const ListValue* args) { |
762 size_t arg_i = 0; | 792 size_t arg_i = 0; |
763 Value* type; | 793 Value* type; |
764 CHECK(args->Get(arg_i++, &type)); | 794 CHECK(args->Get(arg_i++, &type)); |
765 std::string mode_string; | 795 std::string mode_string; |
766 CHECK(args->GetString(arg_i++, &mode_string)); | 796 CHECK(args->GetString(arg_i++, &mode_string)); |
767 std::string pattern_string; | 797 std::string pattern_string; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
802 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); | 832 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); |
803 } | 833 } |
804 | 834 |
805 HostContentSettingsMap* | 835 HostContentSettingsMap* |
806 ContentSettingsHandler::GetOTRContentSettingsMap() { | 836 ContentSettingsHandler::GetOTRContentSettingsMap() { |
807 Profile* profile = Profile::FromWebUI(web_ui_); | 837 Profile* profile = Profile::FromWebUI(web_ui_); |
808 if (profile->HasOffTheRecordProfile()) | 838 if (profile->HasOffTheRecordProfile()) |
809 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 839 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
810 return NULL; | 840 return NULL; |
811 } | 841 } |
842 | |
843 CookieSettings* ContentSettingsHandler::GetCookieSettings() { | |
844 return CookieSettings::GetForProfile(Profile::FromWebUI(web_ui_)); | |
845 } | |
846 | |
847 CookieSettings* ContentSettingsHandler::GetOTRCookieSettings() { | |
848 Profile* profile = Profile::FromWebUI(web_ui_); | |
849 if (profile->HasOffTheRecordProfile()) | |
850 return CookieSettings::GetForProfile(profile->GetOffTheRecordProfile()); | |
851 return NULL; | |
852 } | |
OLD | NEW |