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/host_content_settings_map.h" | 19 #include "chrome/browser/content_settings/host_content_settings_map.h" |
20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
21 #include "chrome/browser/notifications/desktop_notification_service.h" | 21 #include "chrome/browser/notifications/desktop_notification_service.h" |
22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 23 #include "chrome/browser/prefs/pref_service.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.h" | 28 #include "chrome/common/content_settings.h" |
28 #include "chrome/common/content_settings_pattern.h" | 29 #include "chrome/common/content_settings_pattern.h" |
29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
30 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
31 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 base::Bind(&ContentSettingsHandler::RemoveException, | 663 base::Bind(&ContentSettingsHandler::RemoveException, |
663 base::Unretained(this))); | 664 base::Unretained(this))); |
664 web_ui()->RegisterMessageCallback("setException", | 665 web_ui()->RegisterMessageCallback("setException", |
665 base::Bind(&ContentSettingsHandler::SetException, | 666 base::Bind(&ContentSettingsHandler::SetException, |
666 base::Unretained(this))); | 667 base::Unretained(this))); |
667 web_ui()->RegisterMessageCallback("checkExceptionPatternValidity", | 668 web_ui()->RegisterMessageCallback("checkExceptionPatternValidity", |
668 base::Bind(&ContentSettingsHandler::CheckExceptionPatternValidity, | 669 base::Bind(&ContentSettingsHandler::CheckExceptionPatternValidity, |
669 base::Unretained(this))); | 670 base::Unretained(this))); |
670 } | 671 } |
671 | 672 |
| 673 void ContentSettingsHandler::ApplyWhitelist(ContentSettingsType content_type, |
| 674 ContentSetting default_setting) { |
| 675 Profile* profile = Profile::FromWebUI(web_ui()); |
| 676 HostContentSettingsMap* map = GetContentSettingsMap(); |
| 677 if (content_type != CONTENT_SETTINGS_TYPE_PLUGINS) |
| 678 return; |
| 679 const int kDefaultWhitelistVersion = 1; |
| 680 PrefService* prefs = profile->GetPrefs(); |
| 681 int version = prefs->GetInteger( |
| 682 prefs::kContentSettingsDefaultWhitelistVersion); |
| 683 if (version >= kDefaultWhitelistVersion) |
| 684 return; |
| 685 ContentSetting old_setting = |
| 686 map->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, NULL); |
| 687 if (old_setting == CONTENT_SETTING_ALLOW && |
| 688 default_setting == CONTENT_SETTING_ASK) { |
| 689 map->SetWebsiteSetting( |
| 690 ContentSettingsPattern::Wildcard(), |
| 691 ContentSettingsPattern::Wildcard(), |
| 692 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 693 "google-talk", |
| 694 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
| 695 } |
| 696 prefs->SetInteger(prefs::kContentSettingsDefaultWhitelistVersion, |
| 697 kDefaultWhitelistVersion); |
| 698 } |
| 699 |
672 void ContentSettingsHandler::SetContentFilter(const ListValue* args) { | 700 void ContentSettingsHandler::SetContentFilter(const ListValue* args) { |
673 DCHECK_EQ(2U, args->GetSize()); | 701 DCHECK_EQ(2U, args->GetSize()); |
674 std::string group, setting; | 702 std::string group, setting; |
675 if (!(args->GetString(0, &group) && | 703 if (!(args->GetString(0, &group) && |
676 args->GetString(1, &setting))) { | 704 args->GetString(1, &setting))) { |
677 NOTREACHED(); | 705 NOTREACHED(); |
678 return; | 706 return; |
679 } | 707 } |
680 | 708 |
681 ContentSetting default_setting = ContentSettingFromString(setting); | 709 ContentSetting default_setting = ContentSettingFromString(setting); |
682 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); | 710 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); |
683 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 711 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
684 Profile* profile = Profile::FromWebUI(web_ui()); | 712 Profile* profile = Profile::FromWebUI(web_ui()); |
685 DesktopNotificationServiceFactory::GetForProfile(profile)-> | 713 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
686 SetDefaultContentSetting(default_setting); | 714 SetDefaultContentSetting(default_setting); |
687 } else { | 715 } else { |
688 GetContentSettingsMap()-> | 716 HostContentSettingsMap* map = GetContentSettingsMap(); |
689 SetDefaultContentSetting(content_type, default_setting); | 717 ApplyWhitelist(content_type, default_setting); |
| 718 map->SetDefaultContentSetting(content_type, default_setting); |
690 } | 719 } |
691 switch (content_type) { | 720 switch (content_type) { |
692 case CONTENT_SETTINGS_TYPE_COOKIES: | 721 case CONTENT_SETTINGS_TYPE_COOKIES: |
693 content::RecordAction( | 722 content::RecordAction( |
694 UserMetricsAction("Options_DefaultCookieSettingChanged")); | 723 UserMetricsAction("Options_DefaultCookieSettingChanged")); |
695 break; | 724 break; |
696 case CONTENT_SETTINGS_TYPE_IMAGES: | 725 case CONTENT_SETTINGS_TYPE_IMAGES: |
697 content::RecordAction( | 726 content::RecordAction( |
698 UserMetricsAction("Options_DefaultImagesSettingChanged")); | 727 UserMetricsAction("Options_DefaultImagesSettingChanged")); |
699 break; | 728 break; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 return Profile::FromWebUI(web_ui())->GetProtocolHandlerRegistry(); | 896 return Profile::FromWebUI(web_ui())->GetProtocolHandlerRegistry(); |
868 } | 897 } |
869 | 898 |
870 HostContentSettingsMap* | 899 HostContentSettingsMap* |
871 ContentSettingsHandler::GetOTRContentSettingsMap() { | 900 ContentSettingsHandler::GetOTRContentSettingsMap() { |
872 Profile* profile = Profile::FromWebUI(web_ui()); | 901 Profile* profile = Profile::FromWebUI(web_ui()); |
873 if (profile->HasOffTheRecordProfile()) | 902 if (profile->HasOffTheRecordProfile()) |
874 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 903 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
875 return NULL; | 904 return NULL; |
876 } | 905 } |
OLD | NEW |