| 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 "chrome/browser/notifications/extension_welcome_notification.h" | 21 #include "chrome/browser/notifications/extension_welcome_notification.h" |
| 22 #include "components/content_settings/core/common/content_settings.h" | 22 #include "components/content_settings/core/common/content_settings.h" |
| 23 #include "components/keyed_service/core/keyed_service.h" | 23 #include "components/keyed_service/core/keyed_service.h" |
| 24 #include "extensions/browser/extension_registry_observer.h" | |
| 25 #include "third_party/WebKit/public/platform/WebNotificationPermission.h" | 24 #include "third_party/WebKit/public/platform/WebNotificationPermission.h" |
| 26 #include "third_party/WebKit/public/web/WebTextDirection.h" | 25 #include "third_party/WebKit/public/web/WebTextDirection.h" |
| 27 #include "ui/message_center/notifier_settings.h" | 26 #include "ui/message_center/notifier_settings.h" |
| 28 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 29 | 28 |
| 29 #if defined(ENABLE_EXTENSIONS) |
| 30 #include "extensions/browser/extension_registry_observer.h" |
| 31 #endif |
| 32 |
| 30 class Notification; | 33 class Notification; |
| 31 class NotificationDelegate; | 34 class NotificationDelegate; |
| 32 class NotificationUIManager; | 35 class NotificationUIManager; |
| 33 class Profile; | 36 class Profile; |
| 34 | 37 |
| 35 namespace content { | 38 namespace content { |
| 36 class DesktopNotificationDelegate; | 39 class DesktopNotificationDelegate; |
| 37 class RenderFrameHost; | 40 class RenderFrameHost; |
| 38 struct ShowDesktopNotificationHostMsgParams; | 41 struct ShowDesktopNotificationHostMsgParams; |
| 39 } | 42 } |
| 40 | 43 |
| 44 #if defined(ENABLE_EXTENSIONS) |
| 41 namespace extensions { | 45 namespace extensions { |
| 42 class ExtensionRegistry; | 46 class ExtensionRegistry; |
| 43 } | 47 } |
| 48 #endif |
| 44 | 49 |
| 45 namespace gfx { | 50 namespace gfx { |
| 46 class Image; | 51 class Image; |
| 47 } | 52 } |
| 48 | 53 |
| 49 namespace user_prefs { | 54 namespace user_prefs { |
| 50 class PrefRegistrySyncable; | 55 class PrefRegistrySyncable; |
| 51 } | 56 } |
| 52 | 57 |
| 53 // Callback to be invoked when the result of a permission request is known. | 58 // Callback to be invoked when the result of a permission request is known. |
| 54 typedef base::Callback<void(blink::WebNotificationPermission)> | 59 typedef base::Callback<void(blink::WebNotificationPermission)> |
| 55 NotificationPermissionCallback; | 60 NotificationPermissionCallback; |
| 56 | 61 |
| 57 // The DesktopNotificationService is an object, owned by the Profile, | 62 // The DesktopNotificationService is an object, owned by the Profile, |
| 58 // which provides the creation of desktop "toasts" to web pages and workers. | 63 // which provides the creation of desktop "toasts" to web pages and workers. |
| 59 class DesktopNotificationService | 64 class DesktopNotificationService : public PermissionContextBase |
| 60 : public PermissionContextBase, | 65 #if defined(ENABLE_EXTENSIONS) |
| 61 public extensions::ExtensionRegistryObserver { | 66 , |
| 67 public extensions::ExtensionRegistryObserver |
| 68 #endif |
| 69 { |
| 62 public: | 70 public: |
| 63 // Register profile-specific prefs of notifications. | 71 // Register profile-specific prefs of notifications. |
| 64 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); | 72 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); |
| 65 | 73 |
| 66 // Add a desktop notification. | 74 // Add a desktop notification. |
| 67 static std::string AddIconNotification(const GURL& origin_url, | 75 static std::string AddIconNotification(const GURL& origin_url, |
| 68 const base::string16& title, | 76 const base::string16& title, |
| 69 const base::string16& message, | 77 const base::string16& message, |
| 70 const gfx::Image& icon, | 78 const gfx::Image& icon, |
| 71 const base::string16& replace_id, | 79 const base::string16& replace_id, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Used as a callback once a permission has been decided to convert |allowed| | 129 // Used as a callback once a permission has been decided to convert |allowed| |
| 122 // to one of the blink::WebNotificationPermission values. | 130 // to one of the blink::WebNotificationPermission values. |
| 123 void OnNotificationPermissionRequested( | 131 void OnNotificationPermissionRequested( |
| 124 const base::Callback<void(blink::WebNotificationPermission)>& callback, | 132 const base::Callback<void(blink::WebNotificationPermission)>& callback, |
| 125 bool allowed); | 133 bool allowed); |
| 126 | 134 |
| 127 void FirePermissionLevelChangedEvent( | 135 void FirePermissionLevelChangedEvent( |
| 128 const message_center::NotifierId& notifier_id, | 136 const message_center::NotifierId& notifier_id, |
| 129 bool enabled); | 137 bool enabled); |
| 130 | 138 |
| 139 #if defined(ENABLE_EXTENSIONS) |
| 131 // extensions::ExtensionRegistryObserver: | 140 // extensions::ExtensionRegistryObserver: |
| 132 virtual void OnExtensionUninstalled( | 141 virtual void OnExtensionUninstalled( |
| 133 content::BrowserContext* browser_context, | 142 content::BrowserContext* browser_context, |
| 134 const extensions::Extension* extension, | 143 const extensions::Extension* extension, |
| 135 extensions::UninstallReason reason) OVERRIDE; | 144 extensions::UninstallReason reason) OVERRIDE; |
| 145 #endif |
| 136 | 146 |
| 137 // The profile which owns this object. | 147 // The profile which owns this object. |
| 138 Profile* profile_; | 148 Profile* profile_; |
| 139 | 149 |
| 140 // Prefs listener for disabled_extension_id. | 150 // Prefs listener for disabled_extension_id. |
| 141 StringListPrefMember disabled_extension_id_pref_; | 151 StringListPrefMember disabled_extension_id_pref_; |
| 142 | 152 |
| 143 // Prefs listener for disabled_system_component_id. | 153 // Prefs listener for disabled_system_component_id. |
| 144 StringListPrefMember disabled_system_component_id_pref_; | 154 StringListPrefMember disabled_system_component_id_pref_; |
| 145 | 155 |
| 146 // On-memory data for the availability of extensions. | 156 // On-memory data for the availability of extensions. |
| 147 std::set<std::string> disabled_extension_ids_; | 157 std::set<std::string> disabled_extension_ids_; |
| 148 | 158 |
| 149 // On-memory data for the availability of system_component. | 159 // On-memory data for the availability of system_component. |
| 150 std::set<std::string> disabled_system_component_ids_; | 160 std::set<std::string> disabled_system_component_ids_; |
| 151 | 161 |
| 162 #if defined(ENABLE_EXTENSIONS) |
| 152 // An observer to listen when extension is uninstalled. | 163 // An observer to listen when extension is uninstalled. |
| 153 ScopedObserver<extensions::ExtensionRegistry, | 164 ScopedObserver<extensions::ExtensionRegistry, |
| 154 extensions::ExtensionRegistryObserver> | 165 extensions::ExtensionRegistryObserver> |
| 155 extension_registry_observer_; | 166 extension_registry_observer_; |
| 167 #endif |
| 156 | 168 |
| 157 // Welcome Notification | 169 // Welcome Notification |
| 158 scoped_ptr<ExtensionWelcomeNotification> chrome_now_welcome_notification_; | 170 scoped_ptr<ExtensionWelcomeNotification> chrome_now_welcome_notification_; |
| 159 | 171 |
| 160 base::WeakPtrFactory<DesktopNotificationService> weak_factory_; | 172 base::WeakPtrFactory<DesktopNotificationService> weak_factory_; |
| 161 | 173 |
| 162 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); | 174 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); |
| 163 }; | 175 }; |
| 164 | 176 |
| 165 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ | 177 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ |
| OLD | NEW |