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

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

Issue 376253005: Migrate the notification permission to the new common permission classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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/desktop_notification_profile_util.cc
diff --git a/chrome/browser/notifications/desktop_notification_profile_util.cc b/chrome/browser/notifications/desktop_notification_profile_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d3e3b968bb09600a2c2a2e764a383524ecaace69
--- /dev/null
+++ b/chrome/browser/notifications/desktop_notification_profile_util.cc
@@ -0,0 +1,83 @@
+// 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/content_settings_provider.h"
+#include "chrome/browser/content_settings/host_content_settings_map.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/content_settings_pattern.h"
+
Peter Beverloo 2014/07/18 10:42:38 micro nit: two white lines -> one of 'em.
Miguel Garcia 2014/07/18 12:27:09 Done.
+
+void DesktopNotificationProfileUtil::ResetToDefaultContentSetting(
+ Profile* profile) {
+ profile->GetHostContentSettingsMap()->SetDefaultContentSetting(
Peter Beverloo 2014/07/18 10:42:38 I'm in flux. Nothing in this class uses anything f
Miguel Garcia 2014/07/18 12:27:08 Acknowledged.
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_DEFAULT);
+}
+
+// Clears the notifications setting for the given pattern.
+void DesktopNotificationProfileUtil::ClearSetting(
Peter Beverloo 2014/07/18 10:42:38 static methods should be annotated with a comment
Miguel Garcia 2014/07/18 12:27:09 I think we usually do this when the class has both
+ Profile* profile, const ContentSettingsPattern& pattern) {
+ profile->GetHostContentSettingsMap()->SetContentSetting(
+ pattern,
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ NO_RESOURCE_IDENTIFIER,
+ CONTENT_SETTING_DEFAULT);
+
+}
+
+// Clears the sets of explicitly allowed and denied origins.
+void DesktopNotificationProfileUtil::ResetAllOrigins(Profile* profile) {
Peter Beverloo 2014/07/18 10:42:38 This method is only used for NotificationTest. Can
Miguel Garcia 2014/07/18 12:27:09 Good idea, it was only used once in the test so I
+ profile->GetHostContentSettingsMap()->ClearSettingsForOneType(
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+}
+
+// Methods to setup and modify permission preferences.
+void DesktopNotificationProfileUtil::GrantPermission(
+ Profile* profile, const GURL& origin) {
+ ContentSettingsPattern primary_pattern =
+ ContentSettingsPattern::FromURLNoWildcard(origin);
+ profile->GetHostContentSettingsMap()->SetContentSetting(
+ primary_pattern,
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ NO_RESOURCE_IDENTIFIER,
+ CONTENT_SETTING_ALLOW);
+}
+
+void DesktopNotificationProfileUtil::DenyPermission(
+ Profile* profile, const GURL& origin) {
+ ContentSettingsPattern primary_pattern =
+ ContentSettingsPattern::FromURLNoWildcard(origin);
+ profile->GetHostContentSettingsMap()->SetContentSetting(
+ primary_pattern,
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ NO_RESOURCE_IDENTIFIER,
+ CONTENT_SETTING_BLOCK);
+}
+
+void DesktopNotificationProfileUtil::GetNotificationsSettings(
+ Profile* profile, ContentSettingsForOneType* settings) {
+ profile->GetHostContentSettingsMap()->GetSettingsForOneType(
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ NO_RESOURCE_IDENTIFIER,
+ settings);
+}
+
+ContentSetting DesktopNotificationProfileUtil::GetContentSetting(
+ Profile* profile, const GURL& origin) {
+ return profile->GetHostContentSettingsMap()->GetContentSetting(
+ origin,
+ origin,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ NO_RESOURCE_IDENTIFIER);
+}
+
+void DesktopNotificationProfileUtil::SetDefaultContentSetting(
Peter Beverloo 2014/07/18 10:42:38 Dito, we can implement this as a helper method in
Miguel Garcia 2014/07/18 12:27:09 Done.
+ Profile* profile, ContentSetting setting) {
+ profile->GetHostContentSettingsMap()->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting);
+}

Powered by Google App Engine
This is Rietveld 408576698