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

Side by Side Diff: chrome/browser/notifications/desktop_notification_service.h

Issue 376253005: Migrate the notification permission to the new common permission classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ 6 #define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/prefs/pref_member.h" 16 #include "base/prefs/pref_member.h"
17 #include "base/scoped_observer.h" 17 #include "base/scoped_observer.h"
18 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
19 #include "chrome/browser/content_settings/content_settings_provider.h" 19 #include "chrome/browser/content_settings/content_settings_provider.h"
20 #include "chrome/browser/content_settings/permission_context_base.h"
20 #include "chrome/browser/notifications/extension_welcome_notification.h" 21 #include "chrome/browser/notifications/extension_welcome_notification.h"
21 #include "chrome/common/content_settings.h" 22 #include "chrome/common/content_settings.h"
22 #include "components/keyed_service/core/keyed_service.h" 23 #include "components/keyed_service/core/keyed_service.h"
23 #include "extensions/browser/extension_registry_observer.h" 24 #include "extensions/browser/extension_registry_observer.h"
24 #include "third_party/WebKit/public/web/WebNotificationPresenter.h" 25 #include "third_party/WebKit/public/web/WebNotificationPresenter.h"
25 #include "third_party/WebKit/public/web/WebTextDirection.h" 26 #include "third_party/WebKit/public/web/WebTextDirection.h"
26 #include "ui/message_center/notifier_settings.h" 27 #include "ui/message_center/notifier_settings.h"
27 #include "url/gurl.h" 28 #include "url/gurl.h"
28 29
29 class ContentSettingsPattern; 30 class ContentSettingsPattern;
(...skipping 16 matching lines...) Expand all
46 class Image; 47 class Image;
47 } 48 }
48 49
49 namespace user_prefs { 50 namespace user_prefs {
50 class PrefRegistrySyncable; 51 class PrefRegistrySyncable;
51 } 52 }
52 53
53 // The DesktopNotificationService is an object, owned by the Profile, 54 // The DesktopNotificationService is an object, owned by the Profile,
54 // which provides the creation of desktop "toasts" to web pages and workers. 55 // which provides the creation of desktop "toasts" to web pages and workers.
55 class DesktopNotificationService 56 class DesktopNotificationService
56 : public KeyedService, 57 : public PermissionContextBase,
57 public extensions::ExtensionRegistryObserver { 58 public extensions::ExtensionRegistryObserver {
58 public: 59 public:
59 // Register profile-specific prefs of notifications. 60 // Register profile-specific prefs of notifications.
60 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); 61 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs);
61 62
62 DesktopNotificationService(Profile* profile, 63 DesktopNotificationService(Profile* profile,
63 NotificationUIManager* ui_manager); 64 NotificationUIManager* ui_manager);
64 virtual ~DesktopNotificationService(); 65 virtual ~DesktopNotificationService();
65 66
66 // Requests permission for a given origin. |callback| is run when the UI
67 // finishes.
68 void RequestPermission(const GURL& origin,
69 content::RenderFrameHost* render_frame_host,
70 const base::Closure& callback);
71 67
72 // Show a desktop notification. If |cancel_callback| is non-null, it's set to 68 // Show a desktop notification. If |cancel_callback| is non-null, it's set to
73 // a callback which can be used to cancel the notification. 69 // a callback which can be used to cancel the notification.
74 void ShowDesktopNotification( 70 void ShowDesktopNotification(
75 const content::ShowDesktopNotificationHostMsgParams& params, 71 const content::ShowDesktopNotificationHostMsgParams& params,
76 content::RenderFrameHost* render_frame_host, 72 content::RenderFrameHost* render_frame_host,
77 content::DesktopNotificationDelegate* delegate, 73 content::DesktopNotificationDelegate* delegate,
78 base::Closure* cancel_callback); 74 base::Closure* cancel_callback);
79 75
80 // Methods to setup and modify permission preferences.
81 void GrantPermission(const GURL& origin);
82 void DenyPermission(const GURL& origin);
83
84 // Creates a data:xxxx URL which contains the full HTML for a notification 76 // Creates a data:xxxx URL which contains the full HTML for a notification
85 // using supplied icon, title, and text, run through a template which contains 77 // using supplied icon, title, and text, run through a template which contains
86 // the standard formatting for notifications. 78 // the standard formatting for notifications.
87 static base::string16 CreateDataUrl(const GURL& icon_url, 79 static base::string16 CreateDataUrl(const GURL& icon_url,
88 const base::string16& title, 80 const base::string16& title,
89 const base::string16& body, 81 const base::string16& body,
90 blink::WebTextDirection dir); 82 blink::WebTextDirection dir);
91 83
92 // Creates a data:xxxx URL which contains the full HTML for a notification 84 // Creates a data:xxxx URL which contains the full HTML for a notification
93 // using resource template which contains the standard formatting for 85 // using resource template which contains the standard formatting for
94 // notifications. 86 // notifications.
95 static base::string16 CreateDataUrl(int resource, 87 static base::string16 CreateDataUrl(int resource,
96 const std::vector<std::string>& subst); 88 const std::vector<std::string>& subst);
97 89
98 // Add a desktop notification. 90 // Add a desktop notification.
99 static std::string AddIconNotification(const GURL& origin_url, 91 static std::string AddIconNotification(const GURL& origin_url,
100 const base::string16& title, 92 const base::string16& title,
101 const base::string16& message, 93 const base::string16& message,
102 const gfx::Image& icon, 94 const gfx::Image& icon,
103 const base::string16& replace_id, 95 const base::string16& replace_id,
104 NotificationDelegate* delegate, 96 NotificationDelegate* delegate,
105 Profile* profile); 97 Profile* profile);
106 98
107 // The default content setting determines how to handle origins that haven't
108 // been allowed or denied yet. If |provider_id| is not NULL, the id of the
109 // provider which provided the default setting is assigned to it.
110 ContentSetting GetDefaultContentSetting(std::string* provider_id);
111 void SetDefaultContentSetting(ContentSetting setting);
112
113 // NOTE: This should only be called on the UI thread.
114 void ResetToDefaultContentSetting();
115
116 // Returns all notifications settings. |settings| is cleared before
117 // notifications setting are passed to it.
118 void GetNotificationsSettings(ContentSettingsForOneType* settings);
119
120 // Clears the notifications setting for the given pattern.
121 void ClearSetting(const ContentSettingsPattern& pattern);
122
123 // Clears the sets of explicitly allowed and denied origins.
124 void ResetAllOrigins();
125
126 ContentSetting GetContentSetting(const GURL& origin);
127
128 // Returns true if the notifier with |notifier_id| is allowed to send 99 // Returns true if the notifier with |notifier_id| is allowed to send
129 // notifications. 100 // notifications.
130 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id); 101 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id);
131 102
132 // Updates the availability of the notifier. 103 // Updates the availability of the notifier.
133 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, 104 void SetNotifierEnabled(const message_center::NotifierId& notifier_id,
134 bool enabled); 105 bool enabled);
135 106
136 // Adds in a the welcome notification if required for components built 107 // Adds in a the welcome notification if required for components built
137 // into Chrome that show notifications like Chrome Now. 108 // into Chrome that show notifications like Chrome Now.
138 void ShowWelcomeNotificationIfNecessary(const Notification& notification); 109 void ShowWelcomeNotificationIfNecessary(const Notification& notification);
139 110
140 private: 111 private:
141 // Returns a display name for an origin in the process id, to be used in 112 // Returns a display name for an origin in the process id, to be used in
142 // permission infobar or on the frame of the notification toast. Different 113 // permission infobar or on the frame of the notification toast. Different
143 // from the origin itself when dealing with extensions. 114 // from the origin itself when dealing with extensions.
144 base::string16 DisplayNameForOriginInProcessId(const GURL& origin, 115 base::string16 DisplayNameForOriginInProcessId(const GURL& origin,
145 int process_id); 116 int process_id);
146
147 // Notifies the observers when permissions settings change.
148 void NotifySettingsChange();
149
150 NotificationUIManager* GetUIManager(); 117 NotificationUIManager* GetUIManager();
151 118
152 // Called when the string list pref has been changed. 119 // Called when the string list pref has been changed.
153 void OnStringListPrefChanged( 120 void OnStringListPrefChanged(
154 const char* pref_name, std::set<std::string>* ids_field); 121 const char* pref_name, std::set<std::string>* ids_field);
155 122
156 // Called when the disabled_extension_id pref has been changed. 123 // Called when the disabled_extension_id pref has been changed.
157 void OnDisabledExtensionIdsChanged(); 124 void OnDisabledExtensionIdsChanged();
158 125
159 // Called when the disabled_system_component_id pref has been changed. 126 // Called when the disabled_system_component_id pref has been changed.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 extensions::ExtensionRegistryObserver> 160 extensions::ExtensionRegistryObserver>
194 extension_registry_observer_; 161 extension_registry_observer_;
195 162
196 // Welcome Notification 163 // Welcome Notification
197 scoped_ptr<ExtensionWelcomeNotification> chrome_now_welcome_notification_; 164 scoped_ptr<ExtensionWelcomeNotification> chrome_now_welcome_notification_;
198 165
199 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); 166 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService);
200 }; 167 };
201 168
202 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ 169 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698