| 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/prefs/pref_member.h" | 16 #include "base/prefs/pref_member.h" |
| 17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 18 #include "chrome/browser/content_settings/content_settings_provider.h" | 18 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 19 #include "chrome/browser/content_settings/permission_context_base.h" |
| 19 #include "chrome/browser/notifications/extension_welcome_notification.h" | 20 #include "chrome/browser/notifications/extension_welcome_notification.h" |
| 20 #include "chrome/common/content_settings.h" | 21 #include "chrome/common/content_settings.h" |
| 21 #include "components/keyed_service/core/keyed_service.h" | |
| 22 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 24 #include "third_party/WebKit/public/web/WebNotificationPresenter.h" | 24 #include "third_party/WebKit/public/web/WebNotificationPresenter.h" |
| 25 #include "third_party/WebKit/public/web/WebTextDirection.h" | 25 #include "third_party/WebKit/public/web/WebTextDirection.h" |
| 26 #include "ui/message_center/notifier_settings.h" | 26 #include "ui/message_center/notifier_settings.h" |
| 27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 28 | 28 |
| 29 class ContentSettingsPattern; | 29 class ContentSettingsPattern; |
| 30 class Notification; | 30 class Notification; |
| 31 class NotificationDelegate; | 31 class NotificationDelegate; |
| 32 class NotificationUIManager; | 32 class NotificationUIManager; |
| 33 class Profile; | 33 class Profile; |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 class DesktopNotificationDelegate; | 36 class DesktopNotificationDelegate; |
| 37 class RenderFrameHost; | 37 class RenderFrameHost; |
| 38 struct ShowDesktopNotificationHostMsgParams; | 38 struct ShowDesktopNotificationHostMsgParams; |
| 39 } | 39 } |
| 40 | 40 |
| 41 namespace gfx { | 41 namespace gfx { |
| 42 class Image; | 42 class Image; |
| 43 } | 43 } |
| 44 | 44 |
| 45 namespace user_prefs { | 45 namespace user_prefs { |
| 46 class PrefRegistrySyncable; | 46 class PrefRegistrySyncable; |
| 47 } | 47 } |
| 48 | 48 |
| 49 // The DesktopNotificationService is an object, owned by the Profile, | 49 // The DesktopNotificationService is an object, owned by the Profile, |
| 50 // which provides the creation of desktop "toasts" to web pages and workers. | 50 // which provides the creation of desktop "toasts" to web pages and workers. |
| 51 class DesktopNotificationService : public KeyedService, | 51 class DesktopNotificationService : public PermissionContextBase, |
| 52 public content::NotificationObserver { | 52 public content::NotificationObserver { |
| 53 public: | 53 public: |
| 54 // Register profile-specific prefs of notifications. | 54 // Register profile-specific prefs of notifications. |
| 55 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); | 55 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); |
| 56 | 56 |
| 57 DesktopNotificationService(Profile* profile, | 57 DesktopNotificationService(Profile* profile, |
| 58 NotificationUIManager* ui_manager); | 58 NotificationUIManager* ui_manager); |
| 59 virtual ~DesktopNotificationService(); | 59 virtual ~DesktopNotificationService(); |
| 60 | 60 |
| 61 // Requests permission for a given origin. |callback| is run when the UI | |
| 62 // finishes. | |
| 63 void RequestPermission(const GURL& origin, | |
| 64 content::RenderFrameHost* render_frame_host, | |
| 65 const base::Closure& callback); | |
| 66 | |
| 67 // Show a desktop notification. If |cancel_callback| is non-null, it's set to | 61 // Show a desktop notification. If |cancel_callback| is non-null, it's set to |
| 68 // a callback which can be used to cancel the notification. | 62 // a callback which can be used to cancel the notification. |
| 69 void ShowDesktopNotification( | 63 void ShowDesktopNotification( |
| 70 const content::ShowDesktopNotificationHostMsgParams& params, | 64 const content::ShowDesktopNotificationHostMsgParams& params, |
| 71 content::RenderFrameHost* render_frame_host, | 65 content::RenderFrameHost* render_frame_host, |
| 72 content::DesktopNotificationDelegate* delegate, | 66 content::DesktopNotificationDelegate* delegate, |
| 73 base::Closure* cancel_callback); | 67 base::Closure* cancel_callback); |
| 74 | 68 |
| 75 // Methods to setup and modify permission preferences. | |
| 76 void GrantPermission(const GURL& origin); | |
| 77 void DenyPermission(const GURL& origin); | |
| 78 | |
| 79 // Creates a data:xxxx URL which contains the full HTML for a notification | 69 // Creates a data:xxxx URL which contains the full HTML for a notification |
| 80 // using supplied icon, title, and text, run through a template which contains | 70 // using supplied icon, title, and text, run through a template which contains |
| 81 // the standard formatting for notifications. | 71 // the standard formatting for notifications. |
| 82 static base::string16 CreateDataUrl(const GURL& icon_url, | 72 static base::string16 CreateDataUrl(const GURL& icon_url, |
| 83 const base::string16& title, | 73 const base::string16& title, |
| 84 const base::string16& body, | 74 const base::string16& body, |
| 85 blink::WebTextDirection dir); | 75 blink::WebTextDirection dir); |
| 86 | 76 |
| 87 // Creates a data:xxxx URL which contains the full HTML for a notification | 77 // Creates a data:xxxx URL which contains the full HTML for a notification |
| 88 // using resource template which contains the standard formatting for | 78 // using resource template which contains the standard formatting for |
| 89 // notifications. | 79 // notifications. |
| 90 static base::string16 CreateDataUrl(int resource, | 80 static base::string16 CreateDataUrl(int resource, |
| 91 const std::vector<std::string>& subst); | 81 const std::vector<std::string>& subst); |
| 92 | 82 |
| 93 // Add a desktop notification. | 83 // Add a desktop notification. |
| 94 static std::string AddIconNotification(const GURL& origin_url, | 84 static std::string AddIconNotification(const GURL& origin_url, |
| 95 const base::string16& title, | 85 const base::string16& title, |
| 96 const base::string16& message, | 86 const base::string16& message, |
| 97 const gfx::Image& icon, | 87 const gfx::Image& icon, |
| 98 const base::string16& replace_id, | 88 const base::string16& replace_id, |
| 99 NotificationDelegate* delegate, | 89 NotificationDelegate* delegate, |
| 100 Profile* profile); | 90 Profile* profile); |
| 101 | 91 |
| 102 // The default content setting determines how to handle origins that haven't | |
| 103 // been allowed or denied yet. If |provider_id| is not NULL, the id of the | |
| 104 // provider which provided the default setting is assigned to it. | |
| 105 ContentSetting GetDefaultContentSetting(std::string* provider_id); | |
| 106 void SetDefaultContentSetting(ContentSetting setting); | |
| 107 | |
| 108 // NOTE: This should only be called on the UI thread. | |
| 109 void ResetToDefaultContentSetting(); | |
| 110 | |
| 111 // Returns all notifications settings. |settings| is cleared before | |
| 112 // notifications setting are passed to it. | |
| 113 void GetNotificationsSettings(ContentSettingsForOneType* settings); | |
| 114 | |
| 115 // Clears the notifications setting for the given pattern. | |
| 116 void ClearSetting(const ContentSettingsPattern& pattern); | |
| 117 | |
| 118 // Clears the sets of explicitly allowed and denied origins. | |
| 119 void ResetAllOrigins(); | |
| 120 | |
| 121 ContentSetting GetContentSetting(const GURL& origin); | |
| 122 | |
| 123 // Returns true if the notifier with |notifier_id| is allowed to send | 92 // Returns true if the notifier with |notifier_id| is allowed to send |
| 124 // notifications. | 93 // notifications. |
| 125 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id); | 94 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id); |
| 126 | 95 |
| 127 // Updates the availability of the notifier. | 96 // Updates the availability of the notifier. |
| 128 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, | 97 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, |
| 129 bool enabled); | 98 bool enabled); |
| 130 | 99 |
| 131 // Adds in a the welcome notification if required for components built | 100 // Adds in a the welcome notification if required for components built |
| 132 // into Chrome that show notifications like Chrome Now. | 101 // into Chrome that show notifications like Chrome Now. |
| 133 void ShowWelcomeNotificationIfNecessary(const Notification& notification); | 102 void ShowWelcomeNotificationIfNecessary(const Notification& notification); |
| 134 | 103 |
| 135 private: | 104 private: |
| 136 // Returns a display name for an origin in the process id, to be used in | 105 // Returns a display name for an origin in the process id, to be used in |
| 137 // permission infobar or on the frame of the notification toast. Different | 106 // permission infobar or on the frame of the notification toast. Different |
| 138 // from the origin itself when dealing with extensions. | 107 // from the origin itself when dealing with extensions. |
| 139 base::string16 DisplayNameForOriginInProcessId(const GURL& origin, | 108 base::string16 DisplayNameForOriginInProcessId(const GURL& origin, |
| 140 int process_id); | 109 int process_id); |
| 141 | 110 |
| 142 // Notifies the observers when permissions settings change. | |
| 143 void NotifySettingsChange(); | |
| 144 | |
| 145 NotificationUIManager* GetUIManager(); | 111 NotificationUIManager* GetUIManager(); |
| 146 | 112 |
| 147 // Called when the string list pref has been changed. | 113 // Called when the string list pref has been changed. |
| 148 void OnStringListPrefChanged( | 114 void OnStringListPrefChanged( |
| 149 const char* pref_name, std::set<std::string>* ids_field); | 115 const char* pref_name, std::set<std::string>* ids_field); |
| 150 | 116 |
| 151 // Called when the disabled_extension_id pref has been changed. | 117 // Called when the disabled_extension_id pref has been changed. |
| 152 void OnDisabledExtensionIdsChanged(); | 118 void OnDisabledExtensionIdsChanged(); |
| 153 | 119 |
| 154 // Called when the disabled_system_component_id pref has been changed. | 120 // Called when the disabled_system_component_id pref has been changed. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 185 // Registrar for the other kind of notifications (event signaling). | 151 // Registrar for the other kind of notifications (event signaling). |
| 186 content::NotificationRegistrar registrar_; | 152 content::NotificationRegistrar registrar_; |
| 187 | 153 |
| 188 // Welcome Notification | 154 // Welcome Notification |
| 189 scoped_ptr<ExtensionWelcomeNotification> chrome_now_welcome_notification_; | 155 scoped_ptr<ExtensionWelcomeNotification> chrome_now_welcome_notification_; |
| 190 | 156 |
| 191 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); | 157 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService); |
| 192 }; | 158 }; |
| 193 | 159 |
| 194 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ | 160 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_ |
| OLD | NEW |