summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/desktop_notification_profile_util.cc
blob: 22f9d16a2ffd897ac0c923bf10c48e71ca3f5233 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/notifications/desktop_notification_profile_util.h"

#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings_pattern.h"

void DesktopNotificationProfileUtil::ResetToDefaultContentSetting(
    Profile* profile) {
  HostContentSettingsMapFactory::GetForProfile(profile)
      ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
                                 CONTENT_SETTING_DEFAULT);
}

// Clears the notifications setting for the given pattern.
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) {
  HostContentSettingsMapFactory::GetForProfile(profile)
      ->SetContentSettingDefaultScope(
          origin, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
          content_settings::ResourceIdentifier(), CONTENT_SETTING_ALLOW);
}

void DesktopNotificationProfileUtil::DenyPermission(
    Profile* profile, const GURL& origin) {
  HostContentSettingsMapFactory::GetForProfile(profile)
      ->SetContentSettingDefaultScope(
          origin, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
          content_settings::ResourceIdentifier(), CONTENT_SETTING_BLOCK);
}

void DesktopNotificationProfileUtil::GetNotificationsSettings(
    Profile* profile, ContentSettingsForOneType* settings) {
  HostContentSettingsMapFactory::GetForProfile(profile)
      ->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
                              content_settings::ResourceIdentifier(),
                              settings);
}

ContentSetting DesktopNotificationProfileUtil::GetContentSetting(
    Profile* profile, const GURL& origin) {
  return HostContentSettingsMapFactory::GetForProfile(profile)
      ->GetContentSetting(origin,
                          origin,
                          CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
                          content_settings::ResourceIdentifier());
}