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/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/prefs/pref_member.h" | 17 #include "base/prefs/pref_member.h" |
18 #include "base/scoped_observer.h" | 18 #include "base/scoped_observer.h" |
19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
20 #include "chrome/browser/content_settings/permission_context_base.h" | 20 #include "chrome/browser/content_settings/permission_context_base.h" |
21 #include "components/content_settings/core/common/content_settings.h" | 21 #include "components/content_settings/core/common/content_settings.h" |
22 #include "components/keyed_service/core/keyed_service.h" | 22 #include "components/keyed_service/core/keyed_service.h" |
23 #include "third_party/WebKit/public/platform/WebNotificationPermission.h" | |
24 #include "third_party/WebKit/public/web/WebTextDirection.h" | |
25 #include "ui/message_center/notifier_settings.h" | 23 #include "ui/message_center/notifier_settings.h" |
26 #include "url/gurl.h" | 24 #include "url/gurl.h" |
27 | 25 |
28 #if defined(ENABLE_EXTENSIONS) | 26 #if defined(ENABLE_EXTENSIONS) |
29 #include "extensions/browser/extension_registry_observer.h" | 27 #include "extensions/browser/extension_registry_observer.h" |
30 #endif | 28 #endif |
31 | 29 |
32 class Notification; | |
33 class NotificationDelegate; | |
34 class NotificationUIManager; | |
35 class Profile; | 30 class Profile; |
36 | 31 |
37 namespace content { | |
38 class DesktopNotificationDelegate; | |
39 struct ShowDesktopNotificationHostMsgParams; | |
40 } | |
41 | |
42 #if defined(ENABLE_EXTENSIONS) | 32 #if defined(ENABLE_EXTENSIONS) |
43 namespace extensions { | 33 namespace extensions { |
44 class ExtensionRegistry; | 34 class ExtensionRegistry; |
45 } | 35 } |
46 #endif | 36 #endif |
47 | 37 |
48 namespace gfx { | |
49 class Image; | |
50 } | |
51 | |
52 namespace user_prefs { | 38 namespace user_prefs { |
53 class PrefRegistrySyncable; | 39 class PrefRegistrySyncable; |
54 } | 40 } |
55 | 41 |
56 // The DesktopNotificationService is an object, owned by the Profile, | 42 // The DesktopNotificationService is an object, owned by the Profile, |
57 // which provides the creation of desktop "toasts" to web pages and workers. | 43 // which provides the creation of desktop "toasts" to web pages and workers. |
58 class DesktopNotificationService : public PermissionContextBase | 44 class DesktopNotificationService : public PermissionContextBase |
59 #if defined(ENABLE_EXTENSIONS) | 45 #if defined(ENABLE_EXTENSIONS) |
60 , | 46 , |
61 public extensions::ExtensionRegistryObserver | 47 public extensions::ExtensionRegistryObserver |
62 #endif | 48 #endif |
63 { | 49 { |
64 public: | 50 public: |
65 // Register profile-specific prefs of notifications. | 51 // Register profile-specific prefs of notifications. |
66 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); | 52 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); |
67 | 53 |
68 explicit DesktopNotificationService(Profile* profile); | 54 explicit DesktopNotificationService(Profile* profile); |
69 ~DesktopNotificationService() override; | 55 ~DesktopNotificationService() override; |
70 | 56 |
71 // Requests Web Notification permission for |requesting_frame|. The |callback| | 57 // Requests Web Notification permission for |requesting_frame|. The |callback| |
72 // will be invoked after the user has made a decision. | 58 // will be invoked after the user has made a decision. |
73 void RequestNotificationPermission( | 59 void RequestNotificationPermission( |
74 content::WebContents* web_contents, | 60 content::WebContents* web_contents, |
75 const PermissionRequestID& request_id, | 61 const PermissionRequestID& request_id, |
76 const GURL& requesting_origin, | 62 const GURL& requesting_origin, |
77 bool user_gesture, | 63 bool user_gesture, |
78 const base::Callback<void(bool)>& result_callback); | 64 const base::Callback<void(bool)>& result_callback); |
79 | 65 |
80 // Show a desktop notification. If |cancel_callback| is non-null, it's set to | |
81 // a callback which can be used to cancel the notification. | |
82 void ShowDesktopNotification( | |
83 const content::ShowDesktopNotificationHostMsgParams& params, | |
84 int render_process_id, | |
85 scoped_ptr<content::DesktopNotificationDelegate> delegate, | |
86 base::Closure* cancel_callback); | |
87 | |
88 // Returns true if the notifier with |notifier_id| is allowed to send | 66 // Returns true if the notifier with |notifier_id| is allowed to send |
89 // notifications. | 67 // notifications. |
90 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id); | 68 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id); |
91 | 69 |
92 // Updates the availability of the notifier. | 70 // Updates the availability of the notifier. |
93 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, | 71 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, |
94 bool enabled); | 72 bool enabled); |
95 | 73 |
96 private: | 74 private: |
97 // Returns a display name for an origin in the process id, to be used in | |
98 // permission infobar or on the frame of the notification toast. Different | |
99 // from the origin itself when dealing with extensions. | |
100 base::string16 DisplayNameForOriginInProcessId(const GURL& origin, | |
101 int process_id); | |
102 | |
103 // Called when the string list pref has been changed. | 75 // Called when the string list pref has been changed. |
104 void OnStringListPrefChanged( | 76 void OnStringListPrefChanged( |
105 const char* pref_name, std::set<std::string>* ids_field); | 77 const char* pref_name, std::set<std::string>* ids_field); |
106 | 78 |
107 // Called when the disabled_extension_id pref has been changed. | 79 // Called when the disabled_extension_id pref has been changed. |
108 void OnDisabledExtensionIdsChanged(); | 80 void OnDisabledExtensionIdsChanged(); |
109 | 81 |
110 void FirePermissionLevelChangedEvent( | 82 void FirePermissionLevelChangedEvent( |
111 const message_center::NotifierId& notifier_id, | 83 const message_center::NotifierId& notifier_id, |
112 bool enabled); | 84 bool enabled); |
(...skipping 29 matching lines...) Expand all Loading... |
142 // An observer to listen when extension is uninstalled. | 114 // An observer to listen when extension is uninstalled. |
143 ScopedObserver<extensions::ExtensionRegistry, | 115 ScopedObserver<extensions::ExtensionRegistry, |
144 extensions::ExtensionRegistryObserver> | 116 extensions::ExtensionRegistryObserver> |
145 extension_registry_observer_; | 117 extension_registry_observer_; |
146 #endif | 118 #endif |
147 | 119 |
148 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); | 120 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); |
149 }; | 121 }; |
150 | 122 |
151 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ | 123 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ |
OLD | NEW |