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