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> | |
11 | 10 |
12 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
13 #include "base/callback_forward.h" | |
14 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | |
17 #include "base/prefs/pref_member.h" | 14 #include "base/prefs/pref_member.h" |
18 #include "base/scoped_observer.h" | 15 #include "base/scoped_observer.h" |
19 #include "base/strings/string16.h" | |
20 #include "chrome/browser/content_settings/permission_context_base.h" | |
21 #include "components/content_settings/core/common/content_settings.h" | |
22 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
23 #include "ui/message_center/notifier_settings.h" | 17 #include "ui/message_center/notifier_settings.h" |
24 #include "url/gurl.h" | |
25 | 18 |
26 #if defined(ENABLE_EXTENSIONS) | 19 #if defined(ENABLE_EXTENSIONS) |
27 #include "extensions/browser/extension_registry_observer.h" | 20 #include "extensions/browser/extension_registry_observer.h" |
28 #endif | 21 #endif |
29 | 22 |
30 class Profile; | 23 class Profile; |
31 | 24 |
32 #if defined(ENABLE_EXTENSIONS) | 25 #if defined(ENABLE_EXTENSIONS) |
33 namespace extensions { | 26 namespace extensions { |
34 class ExtensionRegistry; | 27 class ExtensionRegistry; |
35 } | 28 } |
36 #endif | 29 #endif |
37 | 30 |
38 namespace user_prefs { | 31 namespace user_prefs { |
39 class PrefRegistrySyncable; | 32 class PrefRegistrySyncable; |
40 } | 33 } |
41 | 34 |
42 // The DesktopNotificationService is an object, owned by the Profile, | 35 // The DesktopNotificationService is an object, owned by the Profile, |
43 // which provides the creation of desktop "toasts" to web pages and workers. | 36 // which provides the creation of desktop "toasts" to web pages and workers. |
44 class DesktopNotificationService : public PermissionContextBase | 37 class DesktopNotificationService : public KeyedService |
45 #if defined(ENABLE_EXTENSIONS) | 38 #if defined(ENABLE_EXTENSIONS) |
46 , | 39 , public extensions::ExtensionRegistryObserver |
47 public extensions::ExtensionRegistryObserver | |
48 #endif | 40 #endif |
49 { | 41 { |
50 public: | 42 public: |
51 // Register profile-specific prefs of notifications. | 43 // Register profile-specific prefs of notifications. |
52 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); | 44 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); |
53 | 45 |
54 explicit DesktopNotificationService(Profile* profile); | 46 explicit DesktopNotificationService(Profile* profile); |
55 ~DesktopNotificationService() override; | 47 ~DesktopNotificationService() override; |
56 | 48 |
57 // Requests Web Notification permission for |requesting_frame|. The |callback| | |
58 // will be invoked after the user has made a decision. | |
59 void RequestNotificationPermission( | |
60 content::WebContents* web_contents, | |
61 const PermissionRequestID& request_id, | |
62 const GURL& requesting_origin, | |
63 bool user_gesture, | |
64 const BrowserPermissionCallback& result_callback); | |
65 | |
66 // Returns true if the notifier with |notifier_id| is allowed to send | 49 // Returns true if the notifier with |notifier_id| is allowed to send |
67 // notifications. | 50 // notifications. |
68 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id) const; | 51 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id) const; |
69 | 52 |
70 // Updates the availability of the notifier. | 53 // Updates the availability of the notifier. |
71 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, | 54 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, |
72 bool enabled); | 55 bool enabled); |
73 | 56 |
74 private: | 57 private: |
75 // Called when the string list pref has been changed. | 58 // Called when the string list pref has been changed. |
76 void OnStringListPrefChanged( | 59 void OnStringListPrefChanged( |
77 const char* pref_name, std::set<std::string>* ids_field); | 60 const char* pref_name, std::set<std::string>* ids_field); |
78 | 61 |
79 // Called when the disabled_extension_id pref has been changed. | 62 // Called when the disabled_extension_id pref has been changed. |
80 void OnDisabledExtensionIdsChanged(); | 63 void OnDisabledExtensionIdsChanged(); |
81 | 64 |
82 void FirePermissionLevelChangedEvent( | 65 void FirePermissionLevelChangedEvent( |
83 const message_center::NotifierId& notifier_id, | 66 const message_center::NotifierId& notifier_id, |
84 bool enabled); | 67 bool enabled); |
85 | 68 |
86 #if defined(ENABLE_EXTENSIONS) | 69 #if defined(ENABLE_EXTENSIONS) |
87 // extensions::ExtensionRegistryObserver: | 70 // extensions::ExtensionRegistryObserver: |
88 void OnExtensionUninstalled(content::BrowserContext* browser_context, | 71 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
89 const extensions::Extension* extension, | 72 const extensions::Extension* extension, |
90 extensions::UninstallReason reason) override; | 73 extensions::UninstallReason reason) override; |
91 #endif | 74 #endif |
92 | 75 |
93 // PermissionContextBase: | |
94 void UpdateContentSetting(const GURL& requesting_origin, | |
95 const GURL& embedder_origin, | |
96 ContentSetting content_setting) override; | |
97 bool IsRestrictedToSecureOrigins() const override; | |
98 | |
99 // The profile which owns this object. | 76 // The profile which owns this object. |
100 Profile* profile_; | 77 Profile* profile_; |
101 | 78 |
102 // Prefs listener for disabled_extension_id. | 79 // Prefs listener for disabled_extension_id. |
103 StringListPrefMember disabled_extension_id_pref_; | 80 StringListPrefMember disabled_extension_id_pref_; |
104 | 81 |
105 // Prefs listener for disabled_system_component_id. | 82 // Prefs listener for disabled_system_component_id. |
106 StringListPrefMember disabled_system_component_id_pref_; | 83 StringListPrefMember disabled_system_component_id_pref_; |
107 | 84 |
108 // On-memory data for the availability of extensions. | 85 // On-memory data for the availability of extensions. |
109 std::set<std::string> disabled_extension_ids_; | 86 std::set<std::string> disabled_extension_ids_; |
110 | 87 |
111 // On-memory data for the availability of system_component. | 88 // On-memory data for the availability of system_component. |
112 std::set<std::string> disabled_system_component_ids_; | 89 std::set<std::string> disabled_system_component_ids_; |
113 | 90 |
114 #if defined(ENABLE_EXTENSIONS) | 91 #if defined(ENABLE_EXTENSIONS) |
115 // An observer to listen when extension is uninstalled. | 92 // An observer to listen when extension is uninstalled. |
116 ScopedObserver<extensions::ExtensionRegistry, | 93 ScopedObserver<extensions::ExtensionRegistry, |
117 extensions::ExtensionRegistryObserver> | 94 extensions::ExtensionRegistryObserver> |
118 extension_registry_observer_; | 95 extension_registry_observer_; |
119 #endif | 96 #endif |
120 | 97 |
121 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); | 98 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); |
122 }; | 99 }; |
123 | 100 |
124 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ | 101 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ |
OLD | NEW |