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