OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "chrome/browser/notifications/notification.h" | 11 #include "chrome/browser/notifications/notification.h" |
12 #include "chrome/common/notification_registrar.h" | 12 #include "chrome/common/notification_registrar.h" |
13 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 | 15 |
16 class NotificationUIManager; | 16 class NotificationUIManager; |
17 class NotificationsPrefsCache; | 17 class NotificationsPrefsCache; |
18 class PrefService; | 18 class PrefService; |
19 class Profile; | 19 class Profile; |
20 class Task; | 20 class Task; |
21 | 21 |
22 // The DesktopNotificationService is an object, owned by the Profile, | 22 // The DesktopNotificationService is an object, owned by the Profile, |
23 // which provides the creation of desktop "toasts" to web pages and workers. | 23 // which provides the creation of desktop "toasts" to web pages and workers. |
24 class DesktopNotificationService : public NotificationObserver { | 24 class DesktopNotificationService { |
25 public: | 25 public: |
26 enum DesktopNotificationSource { | 26 enum DesktopNotificationSource { |
27 PageNotification, | 27 PageNotification, |
28 WorkerNotification | 28 WorkerNotification |
29 }; | 29 }; |
30 | 30 |
31 DesktopNotificationService(Profile* profile, | 31 DesktopNotificationService(Profile* profile, |
32 NotificationUIManager* ui_manager); | 32 NotificationUIManager* ui_manager); |
33 virtual ~DesktopNotificationService(); | 33 virtual ~DesktopNotificationService(); |
34 | 34 |
(...skipping 29 matching lines...) Expand all Loading... |
64 bool CancelDesktopNotification(int process_id, | 64 bool CancelDesktopNotification(int process_id, |
65 int route_id, | 65 int route_id, |
66 int notification_id); | 66 int notification_id); |
67 | 67 |
68 // Methods to setup and modify permission preferences. | 68 // Methods to setup and modify permission preferences. |
69 void GrantPermission(const GURL& origin); | 69 void GrantPermission(const GURL& origin); |
70 void DenyPermission(const GURL& origin); | 70 void DenyPermission(const GURL& origin); |
71 | 71 |
72 NotificationsPrefsCache* prefs_cache() { return prefs_cache_; } | 72 NotificationsPrefsCache* prefs_cache() { return prefs_cache_; } |
73 | 73 |
74 // NotificationObserver interface. | |
75 virtual void Observe(NotificationType type, | |
76 const NotificationSource& source, | |
77 const NotificationDetails& details); | |
78 | |
79 // Creates a data:xxxx URL which contains the full HTML for a notification | 74 // Creates a data:xxxx URL which contains the full HTML for a notification |
80 // using supplied icon, title, and text, run through a template which contains | 75 // using supplied icon, title, and text, run through a template which contains |
81 // the standard formatting for notifications. | 76 // the standard formatting for notifications. |
82 static string16 CreateDataUrl(const GURL& icon_url, const string16& title, | 77 static string16 CreateDataUrl(const GURL& icon_url, const string16& title, |
83 const string16& body); | 78 const string16& body); |
84 private: | 79 private: |
85 void InitPrefs(); | 80 void InitPrefs(); |
86 | 81 |
87 // Save a permission change to the profile. | 82 // Save a permission change to the profile. |
88 void PersistPermissionChange(const GURL& origin, bool is_allowed); | 83 void PersistPermissionChange(const GURL& origin, bool is_allowed); |
89 | 84 |
90 // Returns a display name for an origin, to be used in permission infobar | 85 // Returns a display name for an origin, to be used in permission infobar |
91 // or on the frame of the notification toast. Different from the origin | 86 // or on the frame of the notification toast. Different from the origin |
92 // itself when dealing with extensions. | 87 // itself when dealing with extensions. |
93 std::wstring DisplayNameForOrigin(const GURL& origin); | 88 std::wstring DisplayNameForOrigin(const GURL& origin); |
94 | 89 |
95 // The profile which owns this object. | 90 // The profile which owns this object. |
96 Profile* profile_; | 91 Profile* profile_; |
97 | 92 |
98 // A cache of preferences which is accessible only on the IO thread | 93 // A cache of preferences which is accessible only on the IO thread |
99 // to service synchronous IPCs. | 94 // to service synchronous IPCs. |
100 scoped_refptr<NotificationsPrefsCache> prefs_cache_; | 95 scoped_refptr<NotificationsPrefsCache> prefs_cache_; |
101 | 96 |
102 // Non-owned pointer to the notification manager which manages the | 97 // Non-owned pointer to the notification manager which manages the |
103 // UI for desktop toasts. | 98 // UI for desktop toasts. |
104 NotificationUIManager* ui_manager_; | 99 NotificationUIManager* ui_manager_; |
105 | 100 |
106 // Connection to the service providing the other kind of notifications. | |
107 NotificationRegistrar notification_registrar_; | |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); | 101 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); |
110 }; | 102 }; |
111 | 103 |
112 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ | 104 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ |
OLD | NEW |