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

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

Issue 432005: Make notifications permission available in the extension manifest and hook up... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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) 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"
13 #include "chrome/common/notification_service.h"
12 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
13 15
14 class NotificationUIManager; 16 class NotificationUIManager;
15 class NotificationsPrefsCache; 17 class NotificationsPrefsCache;
16 class PrefService; 18 class PrefService;
17 class Profile; 19 class Profile;
18 class Task; 20 class Task;
19 21
20 // The DesktopNotificationService is an object, owned by the Profile, 22 // The DesktopNotificationService is an object, owned by the Profile,
21 // 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.
22 class DesktopNotificationService { 24 class DesktopNotificationService : public NotificationObserver {
23 public: 25 public:
24 enum NotificationSource { 26 enum DesktopNotificationSource {
25 PageNotification, 27 PageNotification,
26 WorkerNotification 28 WorkerNotification
27 }; 29 };
28 30
29 DesktopNotificationService(Profile* profile, 31 DesktopNotificationService(Profile* profile,
30 NotificationUIManager* ui_manager); 32 NotificationUIManager* ui_manager);
31 ~DesktopNotificationService(); 33 virtual ~DesktopNotificationService();
32 34
33 // Requests permission (using an info-bar) for a given origin. 35 // Requests permission (using an info-bar) for a given origin.
34 // |callback_context| contains an opaque value to pass back to the 36 // |callback_context| contains an opaque value to pass back to the
35 // requesting process when the info-bar finishes. 37 // requesting process when the info-bar finishes.
36 void RequestPermission(const GURL& origin, 38 void RequestPermission(const GURL& origin,
37 int process_id, 39 int process_id,
38 int route_id, 40 int route_id,
39 int callback_context); 41 int callback_context);
40 42
41 // Takes a notification object and shows it in the UI. 43 // Takes a notification object and shows it in the UI.
42 void ShowNotification(const Notification& notification); 44 void ShowNotification(const Notification& notification);
43 45
44 // Two ShowNotification methods: getting content either from remote 46 // Two ShowNotification methods: getting content either from remote
45 // URL or as local parameters. These are called on the UI thread 47 // URL or as local parameters. These are called on the UI thread
46 // in response to IPCs from a child process running script. |origin| 48 // in response to IPCs from a child process running script. |origin|
47 // is the origin of the script. |source| indicates whether the 49 // is the origin of the script. |source| indicates whether the
48 // script is in a worker or page. |notification_id| is an opaque 50 // script is in a worker or page. |notification_id| is an opaque
49 // value to be passed back to the process when events occur on 51 // value to be passed back to the process when events occur on
50 // this notification. 52 // this notification.
51 bool ShowDesktopNotification(const GURL& origin, const GURL& url, 53 bool ShowDesktopNotification(const GURL& origin, const GURL& url,
52 int process_id, int route_id, NotificationSource source, 54 int process_id, int route_id, DesktopNotificationSource source,
53 int notification_id); 55 int notification_id);
54 bool ShowDesktopNotificationText(const GURL& origin, const GURL& icon, 56 bool ShowDesktopNotificationText(const GURL& origin, const GURL& icon,
55 const string16& title, const string16& text, int process_id, 57 const string16& title, const string16& text, int process_id,
56 int route_id, NotificationSource source, int notification_id); 58 int route_id, DesktopNotificationSource source, int notification_id);
57 59
58 // Cancels a notification. If it has already been shown, it will be 60 // Cancels a notification. If it has already been shown, it will be
59 // removed from the screen. If it hasn't been shown yet, it won't be 61 // removed from the screen. If it hasn't been shown yet, it won't be
60 // shown. 62 // shown.
61 bool CancelDesktopNotification(int process_id, 63 bool CancelDesktopNotification(int process_id,
62 int route_id, 64 int route_id,
63 int notification_id); 65 int notification_id);
64 66
65 // Methods to setup and modify permission preferences. 67 // Methods to setup and modify permission preferences.
66 void GrantPermission(const GURL& origin); 68 void GrantPermission(const GURL& origin);
67 void DenyPermission(const GURL& origin); 69 void DenyPermission(const GURL& origin);
68 70
69 NotificationsPrefsCache* prefs_cache() { return prefs_cache_; } 71 NotificationsPrefsCache* prefs_cache() { return prefs_cache_; }
70 72
73 // NotificationObserver interface.
74 virtual void Observe(NotificationType type,
75 const NotificationSource& source,
76 const NotificationDetails& details);
77
71 private: 78 private:
72 void InitPrefs(); 79 void InitPrefs();
73 80
74 // Returns a display name for an origin, to be used in permission infobar 81 // Returns a display name for an origin, to be used in permission infobar
75 // or on the frame of the notification toast. Different from the origin 82 // or on the frame of the notification toast. Different from the origin
76 // itself when dealing with extensions. 83 // itself when dealing with extensions.
77 std::wstring DisplayNameForOrigin(const GURL& origin); 84 std::wstring DisplayNameForOrigin(const GURL& origin);
78 85
79 // The profile which owns this object. 86 // The profile which owns this object.
80 Profile* profile_; 87 Profile* profile_;
81 88
82 // A cache of preferences which is accessible only on the IO thread 89 // A cache of preferences which is accessible only on the IO thread
83 // to service synchronous IPCs. 90 // to service synchronous IPCs.
84 scoped_refptr<NotificationsPrefsCache> prefs_cache_; 91 scoped_refptr<NotificationsPrefsCache> prefs_cache_;
85 92
86 // Non-owned pointer to the notification manager which manages the 93 // Non-owned pointer to the notification manager which manages the
87 // UI for desktop toasts. 94 // UI for desktop toasts.
88 NotificationUIManager* ui_manager_; 95 NotificationUIManager* ui_manager_;
89 96
97 // Connection to the service providing the other kind of notifications.
98 NotificationRegistrar notification_registrar_;
99
90 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); 100 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService);
91 }; 101 };
92 102
93 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ 103 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698