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/content_settings_helper.h" | 28 #include "chrome/common/content_settings_helper.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
54 | 55 |
55 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { | 56 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { |
56 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, | 57 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, |
57 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, | 58 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, |
58 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, | 59 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, |
59 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, | 60 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, |
60 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, | 61 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, |
61 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, | 62 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, |
62 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, | 63 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, |
63 {CONTENT_SETTINGS_TYPE_INTENTS, "intents"}, | 64 {CONTENT_SETTINGS_TYPE_INTENTS, "intents"}, |
65 {CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY, "cookies-session-only"}, | |
Bernhard Bauer
2011/08/28 19:18:49
This seems weird, as this content type isn't expos
marja
2011/08/30 10:10:38
What breaks if that is simply removed: ContentSett
Bernhard Bauer
2011/08/30 11:03:12
Ah, I missed |ContentSettingsTypeToGroupName| belo
markusheintz_
2011/08/30 11:49:34
How about providing a method that converts a Conte
| |
64 }; | 66 }; |
65 | 67 |
66 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { | 68 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { |
67 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { | 69 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { |
68 if (name == kContentSettingsTypeGroupNames[i].name) | 70 if (name == kContentSettingsTypeGroupNames[i].name) |
69 return kContentSettingsTypeGroupNames[i].type; | 71 return kContentSettingsTypeGroupNames[i].type; |
70 } | 72 } |
71 | 73 |
72 NOTREACHED() << name << " is not a recognized content settings type."; | 74 NOTREACHED() << name << " is not a recognized content settings type."; |
73 return CONTENT_SETTINGS_TYPE_DEFAULT; | 75 return CONTENT_SETTINGS_TYPE_DEFAULT; |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
600 NOTREACHED(); | 602 NOTREACHED(); |
601 return; | 603 return; |
602 } | 604 } |
603 | 605 |
604 ContentSetting default_setting = ContentSettingFromString(setting); | 606 ContentSetting default_setting = ContentSettingFromString(setting); |
605 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); | 607 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); |
606 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 608 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
607 Profile* profile = Profile::FromWebUI(web_ui_); | 609 Profile* profile = Profile::FromWebUI(web_ui_); |
608 DesktopNotificationServiceFactory::GetForProfile(profile)-> | 610 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
609 SetDefaultContentSetting(default_setting); | 611 SetDefaultContentSetting(default_setting); |
612 } else if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { | |
613 GetContentSettingsMap()->GetCookieSettings()->SetDefaultSetting( | |
614 default_setting); | |
615 | |
610 } else { | 616 } else { |
611 GetContentSettingsMap()-> | 617 GetContentSettingsMap()-> |
612 SetDefaultContentSetting(content_type, default_setting); | 618 SetDefaultContentSetting(content_type, default_setting); |
613 } | 619 } |
614 } | 620 } |
615 | 621 |
616 void ContentSettingsHandler::RemoveException(const ListValue* args) { | 622 void ContentSettingsHandler::RemoveException(const ListValue* args) { |
617 size_t arg_i = 0; | 623 size_t arg_i = 0; |
618 std::string type_string; | 624 std::string type_string; |
619 CHECK(args->GetString(arg_i++, &type_string)); | 625 CHECK(args->GetString(arg_i++, &type_string)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 bool rv = args->GetString(arg_i++, &mode); | 661 bool rv = args->GetString(arg_i++, &mode); |
656 DCHECK(rv); | 662 DCHECK(rv); |
657 | 663 |
658 std::string pattern; | 664 std::string pattern; |
659 rv = args->GetString(arg_i++, &pattern); | 665 rv = args->GetString(arg_i++, &pattern); |
660 DCHECK(rv); | 666 DCHECK(rv); |
661 | 667 |
662 HostContentSettingsMap* settings_map = | 668 HostContentSettingsMap* settings_map = |
663 mode == "normal" ? GetContentSettingsMap() : | 669 mode == "normal" ? GetContentSettingsMap() : |
664 GetOTRContentSettingsMap(); | 670 GetOTRContentSettingsMap(); |
671 | |
665 // The settings map could be null if the mode was OTR but the OTR profile | 672 // The settings map could be null if the mode was OTR but the OTR profile |
666 // got destroyed before we received this message. | 673 // got destroyed before we received this message. |
667 if (settings_map) { | 674 if (settings_map) { |
668 settings_map->SetContentSetting( | 675 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
669 ContentSettingsPattern::FromString(pattern), | 676 settings_map->GetCookieSettings()->ResetCookieAllowed( |
670 ContentSettingsPattern::Wildcard(), | 677 ContentSettingsPattern::FromString(pattern), |
671 ContentSettingsTypeFromGroupName(type_string), | 678 ContentSettingsPattern::Wildcard()); |
672 "", | 679 settings_map->GetCookieSettings()->ResetCookieSessionOnly( |
673 CONTENT_SETTING_DEFAULT); | 680 ContentSettingsPattern::FromString(pattern)); |
681 } else { | |
682 settings_map->SetContentSetting( | |
683 ContentSettingsPattern::FromString(pattern), | |
684 ContentSettingsPattern::Wildcard(), | |
685 ContentSettingsTypeFromGroupName(type_string), | |
686 "", | |
687 CONTENT_SETTING_DEFAULT); | |
688 } | |
674 } | 689 } |
675 } | 690 } |
676 } | 691 } |
677 | 692 |
678 void ContentSettingsHandler::SetException(const ListValue* args) { | 693 void ContentSettingsHandler::SetException(const ListValue* args) { |
679 size_t arg_i = 0; | 694 size_t arg_i = 0; |
680 std::string type_string; | 695 std::string type_string; |
681 CHECK(args->GetString(arg_i++, &type_string)); | 696 CHECK(args->GetString(arg_i++, &type_string)); |
682 std::string mode; | 697 std::string mode; |
683 CHECK(args->GetString(arg_i++, &mode)); | 698 CHECK(args->GetString(arg_i++, &mode)); |
684 std::string pattern; | 699 std::string pattern; |
685 CHECK(args->GetString(arg_i++, &pattern)); | 700 CHECK(args->GetString(arg_i++, &pattern)); |
686 std::string setting; | 701 std::string setting; |
687 CHECK(args->GetString(arg_i++, &setting)); | 702 CHECK(args->GetString(arg_i++, &setting)); |
688 | 703 |
689 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 704 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); |
690 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || | 705 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || |
691 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 706 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
692 NOTREACHED(); | 707 NOTREACHED(); |
693 return; | 708 return; |
694 } | 709 } |
695 | 710 |
696 HostContentSettingsMap* settings_map = | 711 HostContentSettingsMap* settings_map = |
697 mode == "normal" ? GetContentSettingsMap() : | 712 mode == "normal" ? GetContentSettingsMap() : |
698 GetOTRContentSettingsMap(); | 713 GetOTRContentSettingsMap(); |
699 | |
700 // The settings map could be null if the mode was OTR but the OTR profile | 714 // The settings map could be null if the mode was OTR but the OTR profile |
701 // got destroyed before we received this message. | 715 // got destroyed before we received this message. |
702 if (!settings_map) | 716 if (!settings_map) |
703 return; | 717 return; |
704 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), | 718 |
705 ContentSettingsPattern::Wildcard(), | 719 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
706 type, | 720 ContentSetting content_setting = ContentSettingFromString(setting); |
707 "", | 721 CookieSettings* cookie_settings = settings_map->GetCookieSettings(); |
708 ContentSettingFromString(setting)); | 722 bool allow = (content_setting == CONTENT_SETTING_ALLOW || |
723 content_setting == CONTENT_SETTING_SESSION_ONLY); | |
724 bool session_only = (content_setting == CONTENT_SETTING_SESSION_ONLY); | |
725 cookie_settings->SetCookieAllowed( | |
726 ContentSettingsPattern::FromString(pattern), | |
727 ContentSettingsPattern::Wildcard(), allow); | |
728 cookie_settings->SetCookieSessionOnly( | |
729 ContentSettingsPattern::FromString(pattern), session_only); | |
Bernhard Bauer
2011/08/28 19:18:49
Maybe we could add a convenience method for this t
marja
2011/09/01 11:03:19
Now there is CookieSettings::SetCookieSetting, whi
Bernhard Bauer
2011/09/01 11:41:54
Nice, thank you!
| |
730 } else { | |
731 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), | |
732 ContentSettingsPattern::Wildcard(), | |
733 type, | |
734 "", | |
735 ContentSettingFromString(setting)); | |
736 } | |
709 } | 737 } |
710 | 738 |
711 void ContentSettingsHandler::CheckExceptionPatternValidity( | 739 void ContentSettingsHandler::CheckExceptionPatternValidity( |
712 const ListValue* args) { | 740 const ListValue* args) { |
713 size_t arg_i = 0; | 741 size_t arg_i = 0; |
714 Value* type; | 742 Value* type; |
715 CHECK(args->Get(arg_i++, &type)); | 743 CHECK(args->Get(arg_i++, &type)); |
716 std::string mode_string; | 744 std::string mode_string; |
717 CHECK(args->GetString(arg_i++, &mode_string)); | 745 CHECK(args->GetString(arg_i++, &mode_string)); |
718 std::string pattern_string; | 746 std::string pattern_string; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); | 781 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); |
754 } | 782 } |
755 | 783 |
756 HostContentSettingsMap* | 784 HostContentSettingsMap* |
757 ContentSettingsHandler::GetOTRContentSettingsMap() { | 785 ContentSettingsHandler::GetOTRContentSettingsMap() { |
758 Profile* profile = Profile::FromWebUI(web_ui_); | 786 Profile* profile = Profile::FromWebUI(web_ui_); |
759 if (profile->HasOffTheRecordProfile()) | 787 if (profile->HasOffTheRecordProfile()) |
760 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 788 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
761 return NULL; | 789 return NULL; |
762 } | 790 } |
OLD | NEW |