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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 type_string, exceptions); | 551 type_string, exceptions); |
548 | 552 |
549 // This is mainly here to keep this function ideologically parallel to | 553 // This is mainly here to keep this function ideologically parallel to |
550 // UpdateExceptionsViewFromHostContentSettingsMap(). | 554 // UpdateExceptionsViewFromHostContentSettingsMap(). |
551 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 555 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
552 } | 556 } |
553 | 557 |
554 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( | 558 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( |
555 ContentSettingsType type) { | 559 ContentSettingsType type) { |
556 HostContentSettingsMap::SettingsForOneType entries; | 560 HostContentSettingsMap::SettingsForOneType entries; |
557 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); | 561 if (type == CONTENT_SETTINGS_TYPE_COOKIES) |
| 562 GetCookieSettings()->GetCookieSettings(&entries); |
| 563 else |
| 564 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); |
558 | 565 |
559 ListValue exceptions; | 566 ListValue exceptions; |
560 for (size_t i = 0; i < entries.size(); ++i) { | 567 for (size_t i = 0; i < entries.size(); ++i) { |
561 // Skip default settings from extensions and policy, and the default content | 568 // Skip default settings from extensions and policy, and the default content |
562 // settings; all of them will affect the default setting UI. | 569 // settings; all of them will affect the default setting UI. |
563 if (entries[i].a == ContentSettingsPattern::Wildcard() && | 570 if (entries[i].a == ContentSettingsPattern::Wildcard() && |
564 entries[i].b == ContentSettingsPattern::Wildcard() && | 571 entries[i].b == ContentSettingsPattern::Wildcard() && |
565 entries[i].d != "preference") { | 572 entries[i].d != "preference") { |
566 continue; | 573 continue; |
567 } | 574 } |
(...skipping 23 matching lines...) Expand all Loading... |
591 UpdateSettingDefaultFromModel(type); | 598 UpdateSettingDefaultFromModel(type); |
592 } | 599 } |
593 | 600 |
594 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( | 601 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( |
595 ContentSettingsType type) { | 602 ContentSettingsType type) { |
596 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); | 603 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); |
597 if (!otr_settings_map) | 604 if (!otr_settings_map) |
598 return; | 605 return; |
599 | 606 |
600 HostContentSettingsMap::SettingsForOneType otr_entries; | 607 HostContentSettingsMap::SettingsForOneType otr_entries; |
601 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); | 608 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
| 609 const CookieSettings* otr_cookie_settings = GetOTRCookieSettings(); |
| 610 if (!otr_cookie_settings) |
| 611 return; |
| 612 otr_cookie_settings->GetCookieSettings(&otr_entries); |
| 613 } else { |
| 614 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); |
| 615 } |
602 | 616 |
603 ListValue otr_exceptions; | 617 ListValue otr_exceptions; |
604 for (size_t i = 0; i < otr_entries.size(); ++i) { | 618 for (size_t i = 0; i < otr_entries.size(); ++i) { |
605 // Off-the-record HostContentSettingsMap contains incognito content settings | 619 // Off-the-record HostContentSettingsMap contains incognito content settings |
606 // as well as normal content settings. Here, we use the incongnito settings | 620 // as well as normal content settings. Here, we use the incongnito settings |
607 // only. | 621 // only. |
608 if (!otr_entries[i].e) | 622 if (!otr_entries[i].e) |
609 continue; | 623 continue; |
610 // The content settings UI does not support secondary content settings | 624 // The content settings UI does not support secondary content settings |
611 // pattern yet. For content settings set through the content settings UI the | 625 // pattern yet. For content settings set through the content settings UI the |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 ClearSetting(ContentSettingsPattern::FromString(origin)); | 715 ClearSetting(ContentSettingsPattern::FromString(origin)); |
702 } else { | 716 } else { |
703 std::string mode; | 717 std::string mode; |
704 bool rv = args->GetString(arg_i++, &mode); | 718 bool rv = args->GetString(arg_i++, &mode); |
705 DCHECK(rv); | 719 DCHECK(rv); |
706 | 720 |
707 std::string pattern; | 721 std::string pattern; |
708 rv = args->GetString(arg_i++, &pattern); | 722 rv = args->GetString(arg_i++, &pattern); |
709 DCHECK(rv); | 723 DCHECK(rv); |
710 | 724 |
711 HostContentSettingsMap* settings_map = | 725 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
712 mode == "normal" ? GetContentSettingsMap() : | 726 CookieSettings* cookie_settings = |
713 GetOTRContentSettingsMap(); | 727 mode == "normal" ? GetCookieSettings() : |
714 // The settings map could be null if the mode was OTR but the OTR profile | 728 GetOTRCookieSettings(); |
715 // got destroyed before we received this message. | 729 // |cookie_settings| could be null if the mode was OTR but the OTR profile |
716 if (settings_map) { | 730 // got destroyed before we received this message. |
717 settings_map->SetContentSetting( | 731 if (cookie_settings) { |
718 ContentSettingsPattern::FromString(pattern), | 732 cookie_settings->ResetCookieSetting( |
719 ContentSettingsPattern::Wildcard(), | 733 ContentSettingsPattern::FromString(pattern), |
720 ContentSettingsTypeFromGroupName(type_string), | 734 ContentSettingsPattern::Wildcard()); |
721 "", | 735 } |
722 CONTENT_SETTING_DEFAULT); | 736 } else { |
| 737 HostContentSettingsMap* settings_map = |
| 738 mode == "normal" ? GetContentSettingsMap() : |
| 739 GetOTRContentSettingsMap(); |
| 740 // |settings_map| could be null if the mode was OTR but the OTR profile |
| 741 // got destroyed before we received this message. |
| 742 if (settings_map) { |
| 743 settings_map->SetContentSetting( |
| 744 ContentSettingsPattern::FromString(pattern), |
| 745 ContentSettingsPattern::Wildcard(), |
| 746 ContentSettingsTypeFromGroupName(type_string), |
| 747 "", |
| 748 CONTENT_SETTING_DEFAULT); |
| 749 } |
723 } | 750 } |
724 } | 751 } |
725 } | 752 } |
726 | 753 |
727 void ContentSettingsHandler::SetException(const ListValue* args) { | 754 void ContentSettingsHandler::SetException(const ListValue* args) { |
728 size_t arg_i = 0; | 755 size_t arg_i = 0; |
729 std::string type_string; | 756 std::string type_string; |
730 CHECK(args->GetString(arg_i++, &type_string)); | 757 CHECK(args->GetString(arg_i++, &type_string)); |
731 std::string mode; | 758 std::string mode; |
732 CHECK(args->GetString(arg_i++, &mode)); | 759 CHECK(args->GetString(arg_i++, &mode)); |
733 std::string pattern; | 760 std::string pattern; |
734 CHECK(args->GetString(arg_i++, &pattern)); | 761 CHECK(args->GetString(arg_i++, &pattern)); |
735 std::string setting; | 762 std::string setting; |
736 CHECK(args->GetString(arg_i++, &setting)); | 763 CHECK(args->GetString(arg_i++, &setting)); |
737 | 764 |
738 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 765 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); |
739 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || | 766 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || |
740 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 767 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
741 NOTREACHED(); | 768 NOTREACHED(); |
742 return; | 769 return; |
743 } | 770 } |
744 | 771 |
745 HostContentSettingsMap* settings_map = | 772 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
746 mode == "normal" ? GetContentSettingsMap() : | 773 CookieSettings* cookie_settings = |
747 GetOTRContentSettingsMap(); | 774 mode == "normal" ? GetCookieSettings() : |
| 775 GetOTRCookieSettings(); |
748 | 776 |
749 // The settings map could be null if the mode was OTR but the OTR profile | 777 // |cookie_settings| could be null if the mode was OTR but the OTR profile |
750 // got destroyed before we received this message. | 778 // got destroyed before we received this message. |
751 if (!settings_map) | 779 if (!cookie_settings) |
752 return; | 780 return; |
753 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), | 781 cookie_settings->SetCookieSetting( |
754 ContentSettingsPattern::Wildcard(), | 782 ContentSettingsPattern::FromString(pattern), |
755 type, | 783 ContentSettingsPattern::Wildcard(), |
756 "", | 784 ContentSettingFromString(setting)); |
757 ContentSettingFromString(setting)); | 785 } else { |
| 786 HostContentSettingsMap* settings_map = |
| 787 mode == "normal" ? GetContentSettingsMap() : |
| 788 GetOTRContentSettingsMap(); |
| 789 |
| 790 // |settings_map| could be null if the mode was OTR but the OTR profile |
| 791 // got destroyed before we received this message. |
| 792 if (!settings_map) |
| 793 return; |
| 794 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), |
| 795 ContentSettingsPattern::Wildcard(), |
| 796 type, |
| 797 "", |
| 798 ContentSettingFromString(setting)); |
| 799 } |
758 } | 800 } |
759 | 801 |
760 void ContentSettingsHandler::CheckExceptionPatternValidity( | 802 void ContentSettingsHandler::CheckExceptionPatternValidity( |
761 const ListValue* args) { | 803 const ListValue* args) { |
762 size_t arg_i = 0; | 804 size_t arg_i = 0; |
763 Value* type; | 805 Value* type; |
764 CHECK(args->Get(arg_i++, &type)); | 806 CHECK(args->Get(arg_i++, &type)); |
765 std::string mode_string; | 807 std::string mode_string; |
766 CHECK(args->GetString(arg_i++, &mode_string)); | 808 CHECK(args->GetString(arg_i++, &mode_string)); |
767 std::string pattern_string; | 809 std::string pattern_string; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); | 844 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); |
803 } | 845 } |
804 | 846 |
805 HostContentSettingsMap* | 847 HostContentSettingsMap* |
806 ContentSettingsHandler::GetOTRContentSettingsMap() { | 848 ContentSettingsHandler::GetOTRContentSettingsMap() { |
807 Profile* profile = Profile::FromWebUI(web_ui_); | 849 Profile* profile = Profile::FromWebUI(web_ui_); |
808 if (profile->HasOffTheRecordProfile()) | 850 if (profile->HasOffTheRecordProfile()) |
809 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 851 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
810 return NULL; | 852 return NULL; |
811 } | 853 } |
| 854 |
| 855 CookieSettings* ContentSettingsHandler::GetCookieSettings() { |
| 856 return CookieSettings::GetForProfile(Profile::FromWebUI(web_ui_)); |
| 857 } |
| 858 |
| 859 CookieSettings* ContentSettingsHandler::GetOTRCookieSettings() { |
| 860 Profile* profile = Profile::FromWebUI(web_ui_); |
| 861 if (profile->HasOffTheRecordProfile()) |
| 862 return CookieSettings::GetForProfile(profile->GetOffTheRecordProfile()); |
| 863 return NULL; |
| 864 } |
OLD | NEW |