OLD | NEW |
---|---|
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/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "chrome/browser/content_settings/content_settings_provider.h" | 18 #include "chrome/browser/content_settings/content_settings_provider.h" |
19 #include "chrome/browser/content_settings/permission_context_base.h" | |
19 #include "chrome/browser/notifications/extension_welcome_notification.h" | 20 #include "chrome/browser/notifications/extension_welcome_notification.h" |
20 #include "chrome/common/content_settings.h" | 21 #include "chrome/common/content_settings.h" |
21 #include "components/keyed_service/core/keyed_service.h" | 22 #include "components/keyed_service/core/keyed_service.h" |
Peter Beverloo
2014/07/10 11:29:39
We don't have to include keyed_service.h directly
Miguel Garcia
2014/07/17 17:24:48
Done.
| |
22 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.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; |
30 class Notification; | 31 class Notification; |
31 class NotificationDelegate; | 32 class NotificationDelegate; |
32 class NotificationUIManager; | 33 class NotificationUIManager; |
33 class Profile; | 34 class Profile; |
34 | 35 |
35 namespace content { | 36 namespace content { |
36 class DesktopNotificationDelegate; | 37 class DesktopNotificationDelegate; |
37 class RenderFrameHost; | 38 class RenderFrameHost; |
38 struct ShowDesktopNotificationHostMsgParams; | 39 struct ShowDesktopNotificationHostMsgParams; |
39 } | 40 } |
40 | 41 |
41 namespace gfx { | 42 namespace gfx { |
42 class Image; | 43 class Image; |
43 } | 44 } |
44 | 45 |
45 namespace user_prefs { | 46 namespace user_prefs { |
46 class PrefRegistrySyncable; | 47 class PrefRegistrySyncable; |
47 } | 48 } |
48 | 49 |
49 // The DesktopNotificationService is an object, owned by the Profile, | 50 // The DesktopNotificationService is an object, owned by the Profile, |
50 // which provides the creation of desktop "toasts" to web pages and workers. | 51 // which provides the creation of desktop "toasts" to web pages and workers. |
51 class DesktopNotificationService : public KeyedService, | 52 class DesktopNotificationService : public PermissionContextBase, |
52 public content::NotificationObserver { | 53 public content::NotificationObserver { |
53 public: | 54 public: |
54 // Register profile-specific prefs of notifications. | 55 // Register profile-specific prefs of notifications. |
55 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); | 56 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); |
56 | 57 |
57 DesktopNotificationService(Profile* profile, | 58 DesktopNotificationService(Profile* profile, |
58 NotificationUIManager* ui_manager); | 59 NotificationUIManager* ui_manager); |
59 virtual ~DesktopNotificationService(); | 60 virtual ~DesktopNotificationService(); |
60 | 61 |
61 // Requests permission for a given origin. |callback| is run when the UI | |
62 // finishes. | |
63 void RequestPermission(const GURL& origin, | |
64 content::RenderFrameHost* render_frame_host, | |
65 const base::Closure& callback); | |
66 | |
67 // Show a desktop notification. If |cancel_callback| is non-null, it's set to | 62 // Show a desktop notification. If |cancel_callback| is non-null, it's set to |
68 // a callback which can be used to cancel the notification. | 63 // a callback which can be used to cancel the notification. |
69 void ShowDesktopNotification( | 64 void ShowDesktopNotification( |
70 const content::ShowDesktopNotificationHostMsgParams& params, | 65 const content::ShowDesktopNotificationHostMsgParams& params, |
71 content::RenderFrameHost* render_frame_host, | 66 content::RenderFrameHost* render_frame_host, |
72 content::DesktopNotificationDelegate* delegate, | 67 content::DesktopNotificationDelegate* delegate, |
73 base::Closure* cancel_callback); | 68 base::Closure* cancel_callback); |
74 | 69 |
75 // Methods to setup and modify permission preferences. | 70 // Methods to setup and modify permission preferences. |
76 void GrantPermission(const GURL& origin); | 71 void GrantPermission(const GURL& origin); |
(...skipping 18 matching lines...) Expand all Loading... | |
95 const base::string16& title, | 90 const base::string16& title, |
96 const base::string16& message, | 91 const base::string16& message, |
97 const gfx::Image& icon, | 92 const gfx::Image& icon, |
98 const base::string16& replace_id, | 93 const base::string16& replace_id, |
99 NotificationDelegate* delegate, | 94 NotificationDelegate* delegate, |
100 Profile* profile); | 95 Profile* profile); |
101 | 96 |
102 // The default content setting determines how to handle origins that haven't | 97 // The default content setting determines how to handle origins that haven't |
103 // been allowed or denied yet. If |provider_id| is not NULL, the id of the | 98 // been allowed or denied yet. If |provider_id| is not NULL, the id of the |
104 // provider which provided the default setting is assigned to it. | 99 // provider which provided the default setting is assigned to it. |
105 ContentSetting GetDefaultContentSetting(std::string* provider_id); | |
106 void SetDefaultContentSetting(ContentSetting setting); | |
107 | |
108 // NOTE: This should only be called on the UI thread. | |
109 void ResetToDefaultContentSetting(); | |
110 | 100 |
111 // Returns all notifications settings. |settings| is cleared before | 101 // Returns all notifications settings. |settings| is cleared before |
112 // notifications setting are passed to it. | 102 // notifications setting are passed to it. |
113 void GetNotificationsSettings(ContentSettingsForOneType* settings); | 103 void GetNotificationsSettings(ContentSettingsForOneType* settings); |
114 | 104 |
115 // Clears the notifications setting for the given pattern. | |
116 void ClearSetting(const ContentSettingsPattern& pattern); | |
117 | |
118 // Clears the sets of explicitly allowed and denied origins. | |
119 void ResetAllOrigins(); | |
120 | |
121 ContentSetting GetContentSetting(const GURL& origin); | 105 ContentSetting GetContentSetting(const GURL& origin); |
122 | 106 |
123 // Returns true if the notifier with |notifier_id| is allowed to send | 107 // Returns true if the notifier with |notifier_id| is allowed to send |
124 // notifications. | 108 // notifications. |
125 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id); | 109 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id); |
126 | 110 |
127 // Updates the availability of the notifier. | 111 // Updates the availability of the notifier. |
128 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, | 112 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, |
129 bool enabled); | 113 bool enabled); |
130 | 114 |
131 // Adds in a the welcome notification if required for components built | 115 // Adds in a the welcome notification if required for components built |
132 // into Chrome that show notifications like Chrome Now. | 116 // into Chrome that show notifications like Chrome Now. |
133 void ShowWelcomeNotificationIfNecessary(const Notification& notification); | 117 void ShowWelcomeNotificationIfNecessary(const Notification& notification); |
134 | 118 |
135 private: | 119 private: |
136 // Returns a display name for an origin in the process id, to be used in | 120 // Returns a display name for an origin in the process id, to be used in |
137 // permission infobar or on the frame of the notification toast. Different | 121 // permission infobar or on the frame of the notification toast. Different |
138 // from the origin itself when dealing with extensions. | 122 // from the origin itself when dealing with extensions. |
139 base::string16 DisplayNameForOriginInProcessId(const GURL& origin, | 123 base::string16 DisplayNameForOriginInProcessId(const GURL& origin, |
140 int process_id); | 124 int process_id); |
141 | 125 |
142 // Notifies the observers when permissions settings change. | |
143 void NotifySettingsChange(); | |
144 | |
145 NotificationUIManager* GetUIManager(); | 126 NotificationUIManager* GetUIManager(); |
146 | 127 |
147 // Called when the string list pref has been changed. | 128 // Called when the string list pref has been changed. |
148 void OnStringListPrefChanged( | 129 void OnStringListPrefChanged( |
149 const char* pref_name, std::set<std::string>* ids_field); | 130 const char* pref_name, std::set<std::string>* ids_field); |
150 | 131 |
151 // Called when the disabled_extension_id pref has been changed. | 132 // Called when the disabled_extension_id pref has been changed. |
152 void OnDisabledExtensionIdsChanged(); | 133 void OnDisabledExtensionIdsChanged(); |
153 | 134 |
154 // Called when the disabled_system_component_id pref has been changed. | 135 // Called when the disabled_system_component_id pref has been changed. |
(...skipping 30 matching lines...) Expand all Loading... | |
185 // Registrar for the other kind of notifications (event signaling). | 166 // Registrar for the other kind of notifications (event signaling). |
186 content::NotificationRegistrar registrar_; | 167 content::NotificationRegistrar registrar_; |
187 | 168 |
188 // Welcome Notification | 169 // Welcome Notification |
189 scoped_ptr<ExtensionWelcomeNotification> chrome_now_welcome_notification_; | 170 scoped_ptr<ExtensionWelcomeNotification> chrome_now_welcome_notification_; |
190 | 171 |
191 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); | 172 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); |
192 }; | 173 }; |
193 | 174 |
194 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ | 175 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ |
OLD | NEW |