Commit 71deb5f7 authored by lshang's avatar lshang Committed by Commit bot

Use GURLs instead of patterns in SetContentSetting in notification

DesktopNotificationProfileUtil::ClearSetting() is changed to take GURLs directly
which internally call HostContentSettingsMap::SetContentSettingDefaultScope().

For case in MessageCenterSettingsController, since the patterns are from user
input, SetContentSetting() is used instead of ClearSetting() to take patterns
directly.

BUG=551747

Review URL: https://codereview.chromium.org/1694923004

Cr-Commit-Position: refs/heads/master@{#381608}
parent ce72b266
......@@ -340,8 +340,7 @@ static void SetNotificationSettingForOrigin(
ContentSetting setting = (ContentSetting) value;
switch (setting) {
case CONTENT_SETTING_DEFAULT:
DesktopNotificationProfileUtil::ClearSetting(
profile, ContentSettingsPattern::FromURLNoWildcard(url));
DesktopNotificationProfileUtil::ClearSetting(profile, url);
break;
case CONTENT_SETTING_ALLOW:
DesktopNotificationProfileUtil::GrantPermission(profile, url);
......
......@@ -17,39 +17,29 @@ void DesktopNotificationProfileUtil::ResetToDefaultContentSetting(
}
// Clears the notifications setting for the given pattern.
void DesktopNotificationProfileUtil::ClearSetting(
Profile* profile, const ContentSettingsPattern& pattern) {
HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
content_settings::ResourceIdentifier(),
CONTENT_SETTING_DEFAULT);
void DesktopNotificationProfileUtil::ClearSetting(Profile* profile,
const GURL& origin) {
HostContentSettingsMapFactory::GetForProfile(profile)
->SetContentSettingDefaultScope(
origin, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
content_settings::ResourceIdentifier(), CONTENT_SETTING_DEFAULT);
}
// Methods to setup and modify permission preferences.
void DesktopNotificationProfileUtil::GrantPermission(
Profile* profile, const GURL& origin) {
ContentSettingsPattern primary_pattern =
ContentSettingsPattern::FromURLNoWildcard(origin);
HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting(
primary_pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
content_settings::ResourceIdentifier(),
CONTENT_SETTING_ALLOW);
HostContentSettingsMapFactory::GetForProfile(profile)
->SetContentSettingDefaultScope(
origin, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
content_settings::ResourceIdentifier(), CONTENT_SETTING_ALLOW);
}
void DesktopNotificationProfileUtil::DenyPermission(
Profile* profile, const GURL& origin) {
ContentSettingsPattern primary_pattern =
ContentSettingsPattern::FromURLNoWildcard(origin);
HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting(
primary_pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
content_settings::ResourceIdentifier(),
CONTENT_SETTING_BLOCK);
HostContentSettingsMapFactory::GetForProfile(profile)
->SetContentSettingDefaultScope(
origin, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
content_settings::ResourceIdentifier(), CONTENT_SETTING_BLOCK);
}
void DesktopNotificationProfileUtil::GetNotificationsSettings(
......
......@@ -17,9 +17,8 @@ class DesktopNotificationProfileUtil {
// NOTE: This should only be called on the UI thread.
static void ResetToDefaultContentSetting(Profile* profile);
// Clears the notifications setting for the given pattern.
static void ClearSetting(
Profile* profile, const ContentSettingsPattern& pattern);
// Clears the notifications setting for the given url.
static void ClearSetting(Profile* profile, const GURL& origin);
// Methods to setup and modify permission preferences.
static void GrantPermission(Profile* profile, const GURL& origin);
......
......@@ -350,8 +350,16 @@ void MessageCenterSettingsController::SetNotifierEnabled(
<< notifier.notifier_id.url.spec();
}
if (pattern.IsValid())
DesktopNotificationProfileUtil::ClearSetting(profile, pattern);
if (pattern.IsValid()) {
// Note that we don't use DesktopNotificationProfileUtil::ClearSetting()
// here because pattern might be from user manual input and not match
// the default one used by ClearSetting().
HostContentSettingsMapFactory::GetForProfile(profile)
->SetContentSetting(pattern, ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
content_settings::ResourceIdentifier(),
CONTENT_SETTING_DEFAULT);
}
}
} else {
NotifierStateTrackerFactory::GetForProfile(profile)
......
......@@ -387,8 +387,7 @@ bool NotificationsTest::CheckOriginInSetting(
}
void NotificationsTest::DropOriginPreference(const GURL& origin) {
DesktopNotificationProfileUtil::ClearSetting(browser()->profile(),
ContentSettingsPattern::FromURLNoWildcard(origin));
DesktopNotificationProfileUtil::ClearSetting(browser()->profile(), origin);
}
// Flaky on Windows, Mac, Linux: http://crbug.com/437414.
......
......@@ -170,8 +170,7 @@ NotificationPermissionContext::~NotificationPermissionContext() {}
void NotificationPermissionContext::ResetPermission(
const GURL& requesting_origin,
const GURL& embedder_origin) {
DesktopNotificationProfileUtil::ClearSetting(
profile(), ContentSettingsPattern::FromURLNoWildcard(requesting_origin));
DesktopNotificationProfileUtil::ClearSetting(profile(), requesting_origin);
}
void NotificationPermissionContext::CancelPermissionRequest(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment