Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / notifications / notification_permission_context.cc
blob06037ae2409ba04171ebe604daf1d13d2bc13922
1 // Copyright 2015 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/notification_permission_context.h"
7 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
8 #include "components/content_settings/core/common/content_settings_pattern.h"
9 #include "url/gurl.h"
11 NotificationPermissionContext::NotificationPermissionContext(Profile* profile)
12 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {}
14 NotificationPermissionContext::~NotificationPermissionContext() {}
16 void NotificationPermissionContext::ResetPermission(
17 const GURL& requesting_origin,
18 const GURL& embedder_origin) {
19 DesktopNotificationProfileUtil::ClearSetting(
20 profile(), ContentSettingsPattern::FromURLNoWildcard(requesting_origin));
23 // Unlike other permission types, granting a notification for a given origin
24 // will not take into account the |embedder_origin|, it will only be based
25 // on the requesting iframe origin.
26 // TODO(mukai) Consider why notifications behave differently than
27 // other permissions. https://crbug.com/416894
28 void NotificationPermissionContext::UpdateContentSetting(
29 const GURL& requesting_origin,
30 const GURL& embedder_origin,
31 ContentSetting content_setting) {
32 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
33 content_setting == CONTENT_SETTING_BLOCK);
35 if (content_setting == CONTENT_SETTING_ALLOW) {
36 DesktopNotificationProfileUtil::GrantPermission(profile(),
37 requesting_origin);
38 } else {
39 DesktopNotificationProfileUtil::DenyPermission(profile(),
40 requesting_origin);
44 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const {
45 return false;