OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/notifications/desktop_notification_profile_util.h" | 5 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
6 | 6 |
7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "components/content_settings/core/browser/host_content_settings_map.h" | 9 #include "components/content_settings/core/browser/host_content_settings_map.h" |
10 #include "components/content_settings/core/common/content_settings_pattern.h" | 10 #include "components/content_settings/core/common/content_settings_pattern.h" |
11 | 11 |
12 void DesktopNotificationProfileUtil::ResetToDefaultContentSetting( | 12 void DesktopNotificationProfileUtil::ResetToDefaultContentSetting( |
13 Profile* profile) { | 13 Profile* profile) { |
14 HostContentSettingsMapFactory::GetForProfile(profile) | 14 HostContentSettingsMapFactory::GetForProfile(profile) |
15 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 15 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
16 CONTENT_SETTING_DEFAULT); | 16 CONTENT_SETTING_DEFAULT); |
17 } | 17 } |
18 | 18 |
19 // Clears the notifications setting for the given pattern. | 19 // Clears the notifications setting for the given pattern. |
20 void DesktopNotificationProfileUtil::ClearSetting( | 20 void DesktopNotificationProfileUtil::ClearSetting(Profile* profile, |
21 Profile* profile, const ContentSettingsPattern& pattern) { | 21 const GURL& origin) { |
22 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting( | 22 HostContentSettingsMapFactory::GetForProfile(profile) |
23 pattern, | 23 ->SetContentSettingDefaultScope( |
24 ContentSettingsPattern::Wildcard(), | 24 origin, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
25 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 25 content_settings::ResourceIdentifier(), CONTENT_SETTING_DEFAULT); |
26 content_settings::ResourceIdentifier(), | |
27 CONTENT_SETTING_DEFAULT); | |
28 } | 26 } |
29 | 27 |
30 // Methods to setup and modify permission preferences. | 28 // Methods to setup and modify permission preferences. |
31 void DesktopNotificationProfileUtil::GrantPermission( | 29 void DesktopNotificationProfileUtil::GrantPermission( |
32 Profile* profile, const GURL& origin) { | 30 Profile* profile, const GURL& origin) { |
33 ContentSettingsPattern primary_pattern = | 31 HostContentSettingsMapFactory::GetForProfile(profile) |
34 ContentSettingsPattern::FromURLNoWildcard(origin); | 32 ->SetContentSettingDefaultScope( |
35 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting( | 33 origin, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
36 primary_pattern, | 34 content_settings::ResourceIdentifier(), CONTENT_SETTING_ALLOW); |
37 ContentSettingsPattern::Wildcard(), | |
38 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
39 content_settings::ResourceIdentifier(), | |
40 CONTENT_SETTING_ALLOW); | |
41 } | 35 } |
42 | 36 |
43 void DesktopNotificationProfileUtil::DenyPermission( | 37 void DesktopNotificationProfileUtil::DenyPermission( |
44 Profile* profile, const GURL& origin) { | 38 Profile* profile, const GURL& origin) { |
45 ContentSettingsPattern primary_pattern = | 39 HostContentSettingsMapFactory::GetForProfile(profile) |
46 ContentSettingsPattern::FromURLNoWildcard(origin); | 40 ->SetContentSettingDefaultScope( |
47 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting( | 41 origin, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
48 primary_pattern, | 42 content_settings::ResourceIdentifier(), CONTENT_SETTING_BLOCK); |
49 ContentSettingsPattern::Wildcard(), | |
50 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
51 content_settings::ResourceIdentifier(), | |
52 CONTENT_SETTING_BLOCK); | |
53 } | 43 } |
54 | 44 |
55 void DesktopNotificationProfileUtil::GetNotificationsSettings( | 45 void DesktopNotificationProfileUtil::GetNotificationsSettings( |
56 Profile* profile, ContentSettingsForOneType* settings) { | 46 Profile* profile, ContentSettingsForOneType* settings) { |
57 HostContentSettingsMapFactory::GetForProfile(profile) | 47 HostContentSettingsMapFactory::GetForProfile(profile) |
58 ->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 48 ->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
59 content_settings::ResourceIdentifier(), | 49 content_settings::ResourceIdentifier(), |
60 settings); | 50 settings); |
61 } | 51 } |
62 | 52 |
63 ContentSetting DesktopNotificationProfileUtil::GetContentSetting( | 53 ContentSetting DesktopNotificationProfileUtil::GetContentSetting( |
64 Profile* profile, const GURL& origin) { | 54 Profile* profile, const GURL& origin) { |
65 return HostContentSettingsMapFactory::GetForProfile(profile) | 55 return HostContentSettingsMapFactory::GetForProfile(profile) |
66 ->GetContentSetting(origin, | 56 ->GetContentSetting(origin, |
67 origin, | 57 origin, |
68 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 58 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
69 content_settings::ResourceIdentifier()); | 59 content_settings::ResourceIdentifier()); |
70 } | 60 } |
OLD | NEW |