Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2211)

Unified Diff: chrome/browser/notifications/notification_permission_context.cc

Issue 1207363002: Simplify permission-related code for Web Notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/notification_permission_context.cc
diff --git a/chrome/browser/notifications/notification_permission_context.cc b/chrome/browser/notifications/notification_permission_context.cc
new file mode 100644
index 0000000000000000000000000000000000000000..06037ae2409ba04171ebe604daf1d13d2bc13922
--- /dev/null
+++ b/chrome/browser/notifications/notification_permission_context.cc
@@ -0,0 +1,46 @@
+// Copyright 2015 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/notification_permission_context.h"
+
+#include "chrome/browser/notifications/desktop_notification_profile_util.h"
+#include "components/content_settings/core/common/content_settings_pattern.h"
+#include "url/gurl.h"
+
+NotificationPermissionContext::NotificationPermissionContext(Profile* profile)
+ : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {}
+
+NotificationPermissionContext::~NotificationPermissionContext() {}
+
+void NotificationPermissionContext::ResetPermission(
+ const GURL& requesting_origin,
+ const GURL& embedder_origin) {
+ DesktopNotificationProfileUtil::ClearSetting(
+ profile(), ContentSettingsPattern::FromURLNoWildcard(requesting_origin));
+}
+
+// Unlike other permission types, granting a notification for a given origin
+// will not take into account the |embedder_origin|, it will only be based
+// on the requesting iframe origin.
+// TODO(mukai) Consider why notifications behave differently than
+// other permissions. https://crbug.com/416894
+void NotificationPermissionContext::UpdateContentSetting(
+ const GURL& requesting_origin,
+ const GURL& embedder_origin,
+ ContentSetting content_setting) {
+ DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
+ content_setting == CONTENT_SETTING_BLOCK);
+
+ if (content_setting == CONTENT_SETTING_ALLOW) {
+ DesktopNotificationProfileUtil::GrantPermission(profile(),
+ requesting_origin);
+ } else {
+ DesktopNotificationProfileUtil::DenyPermission(profile(),
+ requesting_origin);
+ }
+}
+
+bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const {
+ return false;
+}

Powered by Google App Engine
This is Rietveld 408576698