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( ...@@ -340,8 +340,7 @@ static void SetNotificationSettingForOrigin(
ContentSetting setting = (ContentSetting) value; ContentSetting setting = (ContentSetting) value;
switch (setting) { switch (setting) {
case CONTENT_SETTING_DEFAULT: case CONTENT_SETTING_DEFAULT:
DesktopNotificationProfileUtil::ClearSetting( DesktopNotificationProfileUtil::ClearSetting(profile, url);
profile, ContentSettingsPattern::FromURLNoWildcard(url));
break; break;
case CONTENT_SETTING_ALLOW: case CONTENT_SETTING_ALLOW:
DesktopNotificationProfileUtil::GrantPermission(profile, url); DesktopNotificationProfileUtil::GrantPermission(profile, url);
......
...@@ -17,39 +17,29 @@ void DesktopNotificationProfileUtil::ResetToDefaultContentSetting( ...@@ -17,39 +17,29 @@ void DesktopNotificationProfileUtil::ResetToDefaultContentSetting(
} }
// Clears the notifications setting for the given pattern. // Clears the notifications setting for the given pattern.
void DesktopNotificationProfileUtil::ClearSetting( void DesktopNotificationProfileUtil::ClearSetting(Profile* profile,
Profile* profile, const ContentSettingsPattern& pattern) { const GURL& origin) {
HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting( HostContentSettingsMapFactory::GetForProfile(profile)
pattern, ->SetContentSettingDefaultScope(
ContentSettingsPattern::Wildcard(), origin, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
CONTENT_SETTINGS_TYPE_NOTIFICATIONS, content_settings::ResourceIdentifier(), CONTENT_SETTING_DEFAULT);
content_settings::ResourceIdentifier(),
CONTENT_SETTING_DEFAULT);
} }
// Methods to setup and modify permission preferences. // Methods to setup and modify permission preferences.
void DesktopNotificationProfileUtil::GrantPermission( void DesktopNotificationProfileUtil::GrantPermission(
Profile* profile, const GURL& origin) { Profile* profile, const GURL& origin) {
ContentSettingsPattern primary_pattern = HostContentSettingsMapFactory::GetForProfile(profile)
ContentSettingsPattern::FromURLNoWildcard(origin); ->SetContentSettingDefaultScope(
HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting( origin, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
primary_pattern, content_settings::ResourceIdentifier(), CONTENT_SETTING_ALLOW);
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
content_settings::ResourceIdentifier(),
CONTENT_SETTING_ALLOW);
} }
void DesktopNotificationProfileUtil::DenyPermission( void DesktopNotificationProfileUtil::DenyPermission(
Profile* profile, const GURL& origin) { Profile* profile, const GURL& origin) {
ContentSettingsPattern primary_pattern = HostContentSettingsMapFactory::GetForProfile(profile)
ContentSettingsPattern::FromURLNoWildcard(origin); ->SetContentSettingDefaultScope(
HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting( origin, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
primary_pattern, content_settings::ResourceIdentifier(), CONTENT_SETTING_BLOCK);
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
content_settings::ResourceIdentifier(),
CONTENT_SETTING_BLOCK);
} }
void DesktopNotificationProfileUtil::GetNotificationsSettings( void DesktopNotificationProfileUtil::GetNotificationsSettings(
......
...@@ -17,9 +17,8 @@ class DesktopNotificationProfileUtil { ...@@ -17,9 +17,8 @@ class DesktopNotificationProfileUtil {
// NOTE: This should only be called on the UI thread. // NOTE: This should only be called on the UI thread.
static void ResetToDefaultContentSetting(Profile* profile); static void ResetToDefaultContentSetting(Profile* profile);
// Clears the notifications setting for the given pattern. // Clears the notifications setting for the given url.
static void ClearSetting( static void ClearSetting(Profile* profile, const GURL& origin);
Profile* profile, const ContentSettingsPattern& pattern);
// Methods to setup and modify permission preferences. // Methods to setup and modify permission preferences.
static void GrantPermission(Profile* profile, const GURL& origin); static void GrantPermission(Profile* profile, const GURL& origin);
......
...@@ -350,8 +350,16 @@ void MessageCenterSettingsController::SetNotifierEnabled( ...@@ -350,8 +350,16 @@ void MessageCenterSettingsController::SetNotifierEnabled(
<< notifier.notifier_id.url.spec(); << notifier.notifier_id.url.spec();
} }
if (pattern.IsValid()) if (pattern.IsValid()) {
DesktopNotificationProfileUtil::ClearSetting(profile, pattern); // 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 { } else {
NotifierStateTrackerFactory::GetForProfile(profile) NotifierStateTrackerFactory::GetForProfile(profile)
......
...@@ -387,8 +387,7 @@ bool NotificationsTest::CheckOriginInSetting( ...@@ -387,8 +387,7 @@ bool NotificationsTest::CheckOriginInSetting(
} }
void NotificationsTest::DropOriginPreference(const GURL& origin) { void NotificationsTest::DropOriginPreference(const GURL& origin) {
DesktopNotificationProfileUtil::ClearSetting(browser()->profile(), DesktopNotificationProfileUtil::ClearSetting(browser()->profile(), origin);
ContentSettingsPattern::FromURLNoWildcard(origin));
} }
// Flaky on Windows, Mac, Linux: http://crbug.com/437414. // Flaky on Windows, Mac, Linux: http://crbug.com/437414.
......
...@@ -170,8 +170,7 @@ NotificationPermissionContext::~NotificationPermissionContext() {} ...@@ -170,8 +170,7 @@ NotificationPermissionContext::~NotificationPermissionContext() {}
void NotificationPermissionContext::ResetPermission( void NotificationPermissionContext::ResetPermission(
const GURL& requesting_origin, const GURL& requesting_origin,
const GURL& embedder_origin) { const GURL& embedder_origin) {
DesktopNotificationProfileUtil::ClearSetting( DesktopNotificationProfileUtil::ClearSetting(profile(), requesting_origin);
profile(), ContentSettingsPattern::FromURLNoWildcard(requesting_origin));
} }
void NotificationPermissionContext::CancelPermissionRequest( 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