Index: chrome/browser/ui/webui/options/content_settings_handler.cc |
diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc |
index 33dc90c6060aa495685b34b52d691207776a6a7f..45c1febfa812c6ee2f241603cbb4f2a1bdd9fede 100644 |
--- a/chrome/browser/ui/webui/options/content_settings_handler.cc |
+++ b/chrome/browser/ui/webui/options/content_settings_handler.cc |
@@ -16,6 +16,7 @@ |
#include "chrome/browser/content_settings/content_settings_details.h" |
#include "chrome/browser/content_settings/content_settings_pattern.h" |
#include "chrome/browser/content_settings/content_settings_utils.h" |
+#include "chrome/browser/content_settings/cookie_settings.h" |
#include "chrome/browser/content_settings/host_content_settings_map.h" |
#include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
#include "chrome/browser/notifications/desktop_notification_service.h" |
@@ -62,6 +63,7 @@ const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { |
{CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, |
{CONTENT_SETTINGS_TYPE_INTENTS, "intents"}, |
{CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, |
+ {CONTENT_SETTINGS_TYPE_PERMANENT_COOKIES, "permanent-cookies"}, |
}; |
COMPILE_ASSERT(arraysize(kContentSettingsTypeGroupNames) == |
CONTENT_SETTINGS_NUM_TYPES, |
@@ -371,6 +373,9 @@ std::string ContentSettingsHandler::GetSettingDefaultFromModel( |
default_setting = |
DesktopNotificationServiceFactory::GetForProfile(profile)-> |
GetDefaultContentSetting(); |
+ } else if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
+ default_setting = |
+ CookieSettings::GetForProfile(profile)->GetDefaultCookieSetting(); |
} else { |
default_setting = |
profile->GetHostContentSettingsMap()->GetDefaultContentSetting(type); |
@@ -409,6 +414,10 @@ void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { |
// for this content type and we skip it here. |
if (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE) |
continue; |
+ // No UI for permanent cookies; cookie settings are handled by |
+ // CONTENT_SETTINGS_TYPE_COOKIES. |
+ if (type == CONTENT_SETTINGS_TYPE_PERMANENT_COOKIES) |
+ continue; |
UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); |
} |
} |
@@ -416,6 +425,10 @@ void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { |
void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { |
for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
+ // No UI for permanent cookies; cookie settings are handled by |
+ // CONTENT_SETTINGS_TYPE_COOKIES. |
+ if (type == CONTENT_SETTINGS_TYPE_PERMANENT_COOKIES) |
+ continue; |
UpdateOTRExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); |
} |
} |
@@ -429,6 +442,9 @@ void ContentSettingsHandler::UpdateExceptionsViewFromModel( |
case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
UpdateNotificationExceptionsView(); |
break; |
+ case CONTENT_SETTINGS_TYPE_COOKIES: |
+ UpdateCookieExceptionsView(); |
+ break; |
default: |
UpdateExceptionsViewFromHostContentSettingsMap(type); |
break; |
@@ -534,6 +550,36 @@ void ContentSettingsHandler::UpdateNotificationExceptionsView() { |
UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
} |
+void ContentSettingsHandler::UpdateCookieExceptionsView() { |
+ UpdateCookieExceptionsViewFromCookieSettings( |
+ GetCookieSettings(), "ContentSettings.setExceptions"); |
+ UpdateCookieExceptionsViewFromCookieSettings( |
+ GetOTRCookieSettings(), "ContentSettings.setOTRExceptions"); |
+ // This is mainly here to keep this function ideologically parallel to |
+ // UpdateExceptionsViewFromHostContentSettingsMap(). |
+ UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_COOKIES); |
+} |
+ |
+void ContentSettingsHandler::UpdateCookieExceptionsViewFromCookieSettings( |
+ CookieSettings* cookie_settings, |
+ const std::string& function_name) { |
+ if (!cookie_settings) |
+ return; |
+ |
+ HostContentSettingsMap::SettingsForOneType entries; |
+ cookie_settings->GetCookieSettings(&entries); |
+ |
+ ListValue exceptions; |
+ for (size_t i = 0; i < entries.size(); ++i) { |
+ exceptions.Append( |
+ GetExceptionForPage(entries[i].a, entries[i].c, entries[i].d)); |
+ } |
+ |
+ StringValue type_string( |
+ ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_COOKIES)); |
+ web_ui_->CallJavascriptFunction(function_name, type_string, exceptions); |
+} |
+ |
void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( |
ContentSettingsType type) { |
HostContentSettingsMap::SettingsForOneType entries; |
@@ -617,6 +663,8 @@ void ContentSettingsHandler::SetContentFilter(const ListValue* args) { |
Profile* profile = Profile::FromWebUI(web_ui_); |
DesktopNotificationServiceFactory::GetForProfile(profile)-> |
SetDefaultContentSetting(default_setting); |
+ } else if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
+ GetCookieSettings()->SetDefaultCookieSetting(default_setting); |
} else { |
GetContentSettingsMap()-> |
SetDefaultContentSetting(content_type, default_setting); |
@@ -672,12 +720,23 @@ void ContentSettingsHandler::RemoveException(const ListValue* args) { |
// The settings map could be null if the mode was OTR but the OTR profile |
// got destroyed before we received this message. |
if (settings_map) { |
- settings_map->SetContentSetting( |
- ContentSettingsPattern::FromString(pattern), |
- ContentSettingsPattern::Wildcard(), |
- ContentSettingsTypeFromGroupName(type_string), |
- "", |
- CONTENT_SETTING_DEFAULT); |
+ if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
+ CookieSettings* cookie_settings = |
+ mode == "normal" ? GetCookieSettings() : GetOTRCookieSettings(); |
+ if (cookie_settings == NULL) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ cookie_settings->ResetCookieSetting( |
+ ContentSettingsPattern::FromString(pattern)); |
+ } else { |
+ settings_map->SetContentSetting( |
+ ContentSettingsPattern::FromString(pattern), |
+ ContentSettingsPattern::Wildcard(), |
+ ContentSettingsTypeFromGroupName(type_string), |
+ "", |
+ CONTENT_SETTING_DEFAULT); |
+ } |
} |
} |
} |
@@ -703,16 +762,24 @@ void ContentSettingsHandler::SetException(const ListValue* args) { |
HostContentSettingsMap* settings_map = |
mode == "normal" ? GetContentSettingsMap() : |
GetOTRContentSettingsMap(); |
- |
// The settings map could be null if the mode was OTR but the OTR profile |
// got destroyed before we received this message. |
if (!settings_map) |
return; |
- settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), |
- ContentSettingsPattern::Wildcard(), |
- type, |
- "", |
- ContentSettingFromString(setting)); |
+ if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
+ CookieSettings* cookie_settings = |
+ mode == "normal" ? GetCookieSettings() : GetOTRCookieSettings(); |
+ DCHECK(cookie_settings != NULL); |
+ cookie_settings->SetCookieSetting( |
+ ContentSettingsPattern::FromString(pattern), |
+ ContentSettingFromString(setting)); |
+ } else { |
+ settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), |
+ ContentSettingsPattern::Wildcard(), |
+ type, |
+ "", |
+ ContentSettingFromString(setting)); |
+ } |
} |
void ContentSettingsHandler::CheckExceptionPatternValidity( |
@@ -767,3 +834,15 @@ HostContentSettingsMap* |
return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
return NULL; |
} |
+ |
+CookieSettings* ContentSettingsHandler::GetCookieSettings() { |
+ return CookieSettings::GetForProfile(Profile::FromWebUI(web_ui_)); |
+} |
+ |
+CookieSettings* ContentSettingsHandler::GetOTRCookieSettings() { |
+ Profile* profile = Profile::FromWebUI(web_ui_); |
+ if (profile->HasOffTheRecordProfile()) |
+ return CookieSettings::GetForProfile( |
+ profile->GetOffTheRecordProfile()); |
+ return NULL; |
+} |