Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / notifications / desktop_notification_profile_util.cc
blob2a004193688506a49a9e525b33bbf1e17f460185
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
3 // found in the LICENSE file.
5 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "components/content_settings/core/browser/host_content_settings_map.h"
9 #include "components/content_settings/core/common/content_settings_pattern.h"
11 void DesktopNotificationProfileUtil::ResetToDefaultContentSetting(
12 Profile* profile) {
13 profile->GetHostContentSettingsMap()->SetDefaultContentSetting(
14 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_DEFAULT);
17 // Clears the notifications setting for the given pattern.
18 void DesktopNotificationProfileUtil::ClearSetting(
19 Profile* profile, const ContentSettingsPattern& pattern) {
20 profile->GetHostContentSettingsMap()->SetContentSetting(
21 pattern, ContentSettingsPattern::Wildcard(),
22 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
23 content_settings::ResourceIdentifier(), CONTENT_SETTING_DEFAULT);
26 // Methods to setup and modify permission preferences.
27 void DesktopNotificationProfileUtil::GrantPermission(
28 Profile* profile, const GURL& origin) {
29 ContentSettingsPattern primary_pattern =
30 ContentSettingsPattern::FromURLNoWildcard(origin);
31 profile->GetHostContentSettingsMap()->SetContentSetting(
32 primary_pattern, ContentSettingsPattern::Wildcard(),
33 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
34 content_settings::ResourceIdentifier(), CONTENT_SETTING_ALLOW);
37 void DesktopNotificationProfileUtil::DenyPermission(
38 Profile* profile, const GURL& origin) {
39 ContentSettingsPattern primary_pattern =
40 ContentSettingsPattern::FromURLNoWildcard(origin);
41 profile->GetHostContentSettingsMap()->SetContentSetting(
42 primary_pattern, ContentSettingsPattern::Wildcard(),
43 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
44 content_settings::ResourceIdentifier(), CONTENT_SETTING_BLOCK);
47 void DesktopNotificationProfileUtil::GetNotificationsSettings(
48 Profile* profile, ContentSettingsForOneType* settings) {
49 profile->GetHostContentSettingsMap()->GetSettingsForOneType(
50 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
51 content_settings::ResourceIdentifier(), settings);
54 ContentSetting DesktopNotificationProfileUtil::GetContentSetting(
55 Profile* profile, const GURL& origin) {
56 return profile->GetHostContentSettingsMap()->GetContentSetting(
57 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
58 content_settings::ResourceIdentifier());