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/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/content_settings/content_settings_details.h" | 16 #include "chrome/browser/content_settings/content_settings_details.h" |
17 #include "chrome/browser/content_settings/content_settings_pattern.h" | 17 #include "chrome/browser/content_settings/content_settings_pattern.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/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
(...skipping 25 matching lines...) Expand all Loading... |
54 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { | 55 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { |
55 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, | 56 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, |
56 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, | 57 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, |
57 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, | 58 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, |
58 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, | 59 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, |
59 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, | 60 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, |
60 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, | 61 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, |
61 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, | 62 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, |
62 {CONTENT_SETTINGS_TYPE_INTENTS, "intents"}, | 63 {CONTENT_SETTINGS_TYPE_INTENTS, "intents"}, |
63 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, | 64 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, |
| 65 {CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY, "cookies-session-only"}, |
64 }; | 66 }; |
65 COMPILE_ASSERT(arraysize(kContentSettingsTypeGroupNames) == | 67 COMPILE_ASSERT(arraysize(kContentSettingsTypeGroupNames) == |
66 CONTENT_SETTINGS_NUM_TYPES, | 68 CONTENT_SETTINGS_NUM_TYPES, |
67 MISSING_CONTENT_SETTINGS_TYPE); | 69 MISSING_CONTENT_SETTINGS_TYPE); |
68 | 70 |
69 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { | 71 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { |
70 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { | 72 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { |
71 if (name == kContentSettingsTypeGroupNames[i].name) | 73 if (name == kContentSettingsTypeGroupNames[i].name) |
72 return kContentSettingsTypeGroupNames[i].type; | 74 return kContentSettingsTypeGroupNames[i].type; |
73 } | 75 } |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 NOTREACHED(); | 609 NOTREACHED(); |
608 return; | 610 return; |
609 } | 611 } |
610 | 612 |
611 ContentSetting default_setting = ContentSettingFromString(setting); | 613 ContentSetting default_setting = ContentSettingFromString(setting); |
612 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); | 614 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); |
613 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 615 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
614 Profile* profile = Profile::FromWebUI(web_ui_); | 616 Profile* profile = Profile::FromWebUI(web_ui_); |
615 DesktopNotificationServiceFactory::GetForProfile(profile)-> | 617 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
616 SetDefaultContentSetting(default_setting); | 618 SetDefaultContentSetting(default_setting); |
| 619 } else if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
| 620 GetCookieSettings()->SetDefaultSetting(default_setting); |
617 } else { | 621 } else { |
618 GetContentSettingsMap()-> | 622 GetContentSettingsMap()-> |
619 SetDefaultContentSetting(content_type, default_setting); | 623 SetDefaultContentSetting(content_type, default_setting); |
620 } | 624 } |
621 } | 625 } |
622 | 626 |
623 void ContentSettingsHandler::RemoveException(const ListValue* args) { | 627 void ContentSettingsHandler::RemoveException(const ListValue* args) { |
624 size_t arg_i = 0; | 628 size_t arg_i = 0; |
625 std::string type_string; | 629 std::string type_string; |
626 CHECK(args->GetString(arg_i++, &type_string)); | 630 CHECK(args->GetString(arg_i++, &type_string)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 bool rv = args->GetString(arg_i++, &mode); | 663 bool rv = args->GetString(arg_i++, &mode); |
660 DCHECK(rv); | 664 DCHECK(rv); |
661 | 665 |
662 std::string pattern; | 666 std::string pattern; |
663 rv = args->GetString(arg_i++, &pattern); | 667 rv = args->GetString(arg_i++, &pattern); |
664 DCHECK(rv); | 668 DCHECK(rv); |
665 | 669 |
666 HostContentSettingsMap* settings_map = | 670 HostContentSettingsMap* settings_map = |
667 mode == "normal" ? GetContentSettingsMap() : | 671 mode == "normal" ? GetContentSettingsMap() : |
668 GetOTRContentSettingsMap(); | 672 GetOTRContentSettingsMap(); |
| 673 |
669 // The settings map could be null if the mode was OTR but the OTR profile | 674 // The settings map could be null if the mode was OTR but the OTR profile |
670 // got destroyed before we received this message. | 675 // got destroyed before we received this message. |
671 if (settings_map) { | 676 if (settings_map) { |
672 settings_map->SetContentSetting( | 677 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
673 ContentSettingsPattern::FromString(pattern), | 678 CookieSettings* cookie_settings = |
674 ContentSettingsPattern::Wildcard(), | 679 mode == "normal" ? GetCookieSettings() : GetOTRCookieSettings(); |
675 ContentSettingsTypeFromGroupName(type_string), | 680 if (cookie_settings == NULL) { |
676 "", | 681 NOTREACHED(); |
677 CONTENT_SETTING_DEFAULT); | 682 return; |
| 683 } |
| 684 cookie_settings->ResetCookieSetting( |
| 685 ContentSettingsPattern::FromString(pattern)); |
| 686 } else { |
| 687 settings_map->SetContentSetting( |
| 688 ContentSettingsPattern::FromString(pattern), |
| 689 ContentSettingsPattern::Wildcard(), |
| 690 ContentSettingsTypeFromGroupName(type_string), |
| 691 "", |
| 692 CONTENT_SETTING_DEFAULT); |
| 693 } |
678 } | 694 } |
679 } | 695 } |
680 } | 696 } |
681 | 697 |
682 void ContentSettingsHandler::SetException(const ListValue* args) { | 698 void ContentSettingsHandler::SetException(const ListValue* args) { |
683 size_t arg_i = 0; | 699 size_t arg_i = 0; |
684 std::string type_string; | 700 std::string type_string; |
685 CHECK(args->GetString(arg_i++, &type_string)); | 701 CHECK(args->GetString(arg_i++, &type_string)); |
686 std::string mode; | 702 std::string mode; |
687 CHECK(args->GetString(arg_i++, &mode)); | 703 CHECK(args->GetString(arg_i++, &mode)); |
688 std::string pattern; | 704 std::string pattern; |
689 CHECK(args->GetString(arg_i++, &pattern)); | 705 CHECK(args->GetString(arg_i++, &pattern)); |
690 std::string setting; | 706 std::string setting; |
691 CHECK(args->GetString(arg_i++, &setting)); | 707 CHECK(args->GetString(arg_i++, &setting)); |
692 | 708 |
693 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 709 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); |
694 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || | 710 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || |
695 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 711 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
696 NOTREACHED(); | 712 NOTREACHED(); |
697 return; | 713 return; |
698 } | 714 } |
699 | 715 |
700 HostContentSettingsMap* settings_map = | 716 HostContentSettingsMap* settings_map = |
701 mode == "normal" ? GetContentSettingsMap() : | 717 mode == "normal" ? GetContentSettingsMap() : |
702 GetOTRContentSettingsMap(); | 718 GetOTRContentSettingsMap(); |
703 | |
704 // The settings map could be null if the mode was OTR but the OTR profile | 719 // The settings map could be null if the mode was OTR but the OTR profile |
705 // got destroyed before we received this message. | 720 // got destroyed before we received this message. |
706 if (!settings_map) | 721 if (!settings_map) |
707 return; | 722 return; |
708 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), | 723 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
709 ContentSettingsPattern::Wildcard(), | 724 CookieSettings* cookie_settings = |
710 type, | 725 mode == "normal" ? GetCookieSettings() : GetOTRCookieSettings(); |
711 "", | 726 DCHECK(cookie_settings != NULL); |
712 ContentSettingFromString(setting)); | 727 cookie_settings->SetCookieSetting( |
| 728 ContentSettingsPattern::FromString(pattern), |
| 729 ContentSettingFromString(setting)); |
| 730 } else { |
| 731 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), |
| 732 ContentSettingsPattern::Wildcard(), |
| 733 type, |
| 734 "", |
| 735 ContentSettingFromString(setting)); |
| 736 } |
713 } | 737 } |
714 | 738 |
715 void ContentSettingsHandler::CheckExceptionPatternValidity( | 739 void ContentSettingsHandler::CheckExceptionPatternValidity( |
716 const ListValue* args) { | 740 const ListValue* args) { |
717 size_t arg_i = 0; | 741 size_t arg_i = 0; |
718 Value* type; | 742 Value* type; |
719 CHECK(args->Get(arg_i++, &type)); | 743 CHECK(args->Get(arg_i++, &type)); |
720 std::string mode_string; | 744 std::string mode_string; |
721 CHECK(args->GetString(arg_i++, &mode_string)); | 745 CHECK(args->GetString(arg_i++, &mode_string)); |
722 std::string pattern_string; | 746 std::string pattern_string; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); | 781 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); |
758 } | 782 } |
759 | 783 |
760 HostContentSettingsMap* | 784 HostContentSettingsMap* |
761 ContentSettingsHandler::GetOTRContentSettingsMap() { | 785 ContentSettingsHandler::GetOTRContentSettingsMap() { |
762 Profile* profile = Profile::FromWebUI(web_ui_); | 786 Profile* profile = Profile::FromWebUI(web_ui_); |
763 if (profile->HasOffTheRecordProfile()) | 787 if (profile->HasOffTheRecordProfile()) |
764 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 788 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
765 return NULL; | 789 return NULL; |
766 } | 790 } |
| 791 |
| 792 CookieSettings* ContentSettingsHandler::GetCookieSettings() { |
| 793 return CookieSettings::GetForProfile(Profile::FromWebUI(web_ui_)); |
| 794 } |
| 795 |
| 796 CookieSettings* ContentSettingsHandler::GetOTRCookieSettings() { |
| 797 Profile* profile = Profile::FromWebUI(web_ui_); |
| 798 if (profile->HasOffTheRecordProfile()) |
| 799 return CookieSettings::GetForProfile( |
| 800 profile->GetOffTheRecordProfile()); |
| 801 return NULL; |
| 802 } |
OLD | NEW |