| 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> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 // The DesktopNotificationService is an object, owned by the Profile, | 59 // The DesktopNotificationService is an object, owned by the Profile, |
| 60 // which provides the creation of desktop "toasts" to web pages and workers. | 60 // which provides the creation of desktop "toasts" to web pages and workers. |
| 61 class DesktopNotificationService | 61 class DesktopNotificationService |
| 62 : public PermissionContextBase, | 62 : public PermissionContextBase, |
| 63 public extensions::ExtensionRegistryObserver { | 63 public extensions::ExtensionRegistryObserver { |
| 64 public: | 64 public: |
| 65 // Register profile-specific prefs of notifications. | 65 // Register profile-specific prefs of notifications. |
| 66 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); | 66 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); |
| 67 | 67 |
| 68 DesktopNotificationService(Profile* profile, | 68 // Add a desktop notification. |
| 69 NotificationUIManager* ui_manager); | 69 static std::string AddIconNotification(const GURL& origin_url, |
| 70 const base::string16& title, |
| 71 const base::string16& message, |
| 72 const gfx::Image& icon, |
| 73 const base::string16& replace_id, |
| 74 NotificationDelegate* delegate, |
| 75 Profile* profile); |
| 76 |
| 77 explicit DesktopNotificationService(Profile* profile); |
| 70 virtual ~DesktopNotificationService(); | 78 virtual ~DesktopNotificationService(); |
| 71 | 79 |
| 72 // Requests Web Notification permission for |requesting_frame|. The |callback| | 80 // Requests Web Notification permission for |requesting_frame|. The |callback| |
| 73 // will be invoked after the user has made a decision. | 81 // will be invoked after the user has made a decision. |
| 74 void RequestNotificationPermission( | 82 void RequestNotificationPermission( |
| 75 content::WebContents* web_contents, | 83 content::WebContents* web_contents, |
| 76 const PermissionRequestID& request_id, | 84 const PermissionRequestID& request_id, |
| 77 const GURL& requesting_frame, | 85 const GURL& requesting_frame, |
| 78 bool user_gesture, | 86 bool user_gesture, |
| 79 const NotificationPermissionCallback& callback); | 87 const NotificationPermissionCallback& callback); |
| 80 | 88 |
| 81 // Show a desktop notification. If |cancel_callback| is non-null, it's set to | 89 // Show a desktop notification. If |cancel_callback| is non-null, it's set to |
| 82 // a callback which can be used to cancel the notification. | 90 // a callback which can be used to cancel the notification. |
| 83 void ShowDesktopNotification( | 91 void ShowDesktopNotification( |
| 84 const content::ShowDesktopNotificationHostMsgParams& params, | 92 const content::ShowDesktopNotificationHostMsgParams& params, |
| 85 content::RenderFrameHost* render_frame_host, | 93 content::RenderFrameHost* render_frame_host, |
| 86 scoped_ptr<content::DesktopNotificationDelegate> delegate, | 94 scoped_ptr<content::DesktopNotificationDelegate> delegate, |
| 87 base::Closure* cancel_callback); | 95 base::Closure* cancel_callback); |
| 88 | 96 |
| 89 // Creates a data:xxxx URL which contains the full HTML for a notification | |
| 90 // using supplied icon, title, and text, run through a template which contains | |
| 91 // the standard formatting for notifications. | |
| 92 static base::string16 CreateDataUrl(const GURL& icon_url, | |
| 93 const base::string16& title, | |
| 94 const base::string16& body, | |
| 95 blink::WebTextDirection dir); | |
| 96 | |
| 97 // Creates a data:xxxx URL which contains the full HTML for a notification | |
| 98 // using resource template which contains the standard formatting for | |
| 99 // notifications. | |
| 100 static base::string16 CreateDataUrl(int resource, | |
| 101 const std::vector<std::string>& subst); | |
| 102 | |
| 103 // Add a desktop notification. | |
| 104 static std::string AddIconNotification(const GURL& origin_url, | |
| 105 const base::string16& title, | |
| 106 const base::string16& message, | |
| 107 const gfx::Image& icon, | |
| 108 const base::string16& replace_id, | |
| 109 NotificationDelegate* delegate, | |
| 110 Profile* profile); | |
| 111 | |
| 112 // Returns true if the notifier with |notifier_id| is allowed to send | 97 // Returns true if the notifier with |notifier_id| is allowed to send |
| 113 // notifications. | 98 // notifications. |
| 114 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id); | 99 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id); |
| 115 | 100 |
| 116 // Updates the availability of the notifier. | 101 // Updates the availability of the notifier. |
| 117 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, | 102 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, |
| 118 bool enabled); | 103 bool enabled); |
| 119 | 104 |
| 120 // Adds in a the welcome notification if required for components built | 105 // Adds in a the welcome notification if required for components built |
| 121 // into Chrome that show notifications like Chrome Now. | 106 // into Chrome that show notifications like Chrome Now. |
| 122 void ShowWelcomeNotificationIfNecessary(const Notification& notification); | 107 void ShowWelcomeNotificationIfNecessary(const Notification& notification); |
| 123 | 108 |
| 124 private: | 109 private: |
| 125 // Returns a display name for an origin in the process id, to be used in | 110 // Returns a display name for an origin in the process id, to be used in |
| 126 // permission infobar or on the frame of the notification toast. Different | 111 // permission infobar or on the frame of the notification toast. Different |
| 127 // from the origin itself when dealing with extensions. | 112 // from the origin itself when dealing with extensions. |
| 128 base::string16 DisplayNameForOriginInProcessId(const GURL& origin, | 113 base::string16 DisplayNameForOriginInProcessId(const GURL& origin, |
| 129 int process_id); | 114 int process_id); |
| 130 NotificationUIManager* GetUIManager(); | |
| 131 | 115 |
| 132 // Called when the string list pref has been changed. | 116 // Called when the string list pref has been changed. |
| 133 void OnStringListPrefChanged( | 117 void OnStringListPrefChanged( |
| 134 const char* pref_name, std::set<std::string>* ids_field); | 118 const char* pref_name, std::set<std::string>* ids_field); |
| 135 | 119 |
| 136 // Called when the disabled_extension_id pref has been changed. | 120 // Called when the disabled_extension_id pref has been changed. |
| 137 void OnDisabledExtensionIdsChanged(); | 121 void OnDisabledExtensionIdsChanged(); |
| 138 | 122 |
| 139 // Used as a callback once a permission has been decided to convert |allowed| | 123 // Used as a callback once a permission has been decided to convert |allowed| |
| 140 // to one of the blink::WebNotificationPermission values. | 124 // to one of the blink::WebNotificationPermission values. |
| 141 void OnNotificationPermissionRequested( | 125 void OnNotificationPermissionRequested( |
| 142 const base::Callback<void(blink::WebNotificationPermission)>& callback, | 126 const base::Callback<void(blink::WebNotificationPermission)>& callback, |
| 143 bool allowed); | 127 bool allowed); |
| 144 | 128 |
| 145 void FirePermissionLevelChangedEvent( | 129 void FirePermissionLevelChangedEvent( |
| 146 const message_center::NotifierId& notifier_id, | 130 const message_center::NotifierId& notifier_id, |
| 147 bool enabled); | 131 bool enabled); |
| 148 | 132 |
| 149 // extensions::ExtensionRegistryObserver: | 133 // extensions::ExtensionRegistryObserver: |
| 150 virtual void OnExtensionUninstalled( | 134 virtual void OnExtensionUninstalled( |
| 151 content::BrowserContext* browser_context, | 135 content::BrowserContext* browser_context, |
| 152 const extensions::Extension* extension, | 136 const extensions::Extension* extension, |
| 153 extensions::UninstallReason reason) OVERRIDE; | 137 extensions::UninstallReason reason) OVERRIDE; |
| 154 | 138 |
| 155 // The profile which owns this object. | 139 // The profile which owns this object. |
| 156 Profile* profile_; | 140 Profile* profile_; |
| 157 | 141 |
| 158 // Non-owned pointer to the notification manager which manages the | |
| 159 // UI for desktop toasts. | |
| 160 NotificationUIManager* ui_manager_; | |
| 161 | |
| 162 // Prefs listener for disabled_extension_id. | 142 // Prefs listener for disabled_extension_id. |
| 163 StringListPrefMember disabled_extension_id_pref_; | 143 StringListPrefMember disabled_extension_id_pref_; |
| 164 | 144 |
| 165 // Prefs listener for disabled_system_component_id. | 145 // Prefs listener for disabled_system_component_id. |
| 166 StringListPrefMember disabled_system_component_id_pref_; | 146 StringListPrefMember disabled_system_component_id_pref_; |
| 167 | 147 |
| 168 // On-memory data for the availability of extensions. | 148 // On-memory data for the availability of extensions. |
| 169 std::set<std::string> disabled_extension_ids_; | 149 std::set<std::string> disabled_extension_ids_; |
| 170 | 150 |
| 171 // On-memory data for the availability of system_component. | 151 // On-memory data for the availability of system_component. |
| 172 std::set<std::string> disabled_system_component_ids_; | 152 std::set<std::string> disabled_system_component_ids_; |
| 173 | 153 |
| 174 // An observer to listen when extension is uninstalled. | 154 // An observer to listen when extension is uninstalled. |
| 175 ScopedObserver<extensions::ExtensionRegistry, | 155 ScopedObserver<extensions::ExtensionRegistry, |
| 176 extensions::ExtensionRegistryObserver> | 156 extensions::ExtensionRegistryObserver> |
| 177 extension_registry_observer_; | 157 extension_registry_observer_; |
| 178 | 158 |
| 179 // Welcome Notification | 159 // Welcome Notification |
| 180 scoped_ptr<ExtensionWelcomeNotification> chrome_now_welcome_notification_; | 160 scoped_ptr<ExtensionWelcomeNotification> chrome_now_welcome_notification_; |
| 181 | 161 |
| 182 base::WeakPtrFactory<DesktopNotificationService> weak_factory_; | 162 base::WeakPtrFactory<DesktopNotificationService> weak_factory_; |
| 183 | 163 |
| 184 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); | 164 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); |
| 185 }; | 165 }; |
| 186 | 166 |
| 187 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ | 167 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ |
| OLD | NEW |