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 #include "chrome/browser/notifications/desktop_notification_service.h" | 5 #include "chrome/browser/notifications/desktop_notification_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 replace_id, | 97 replace_id, |
98 message_center::RichNotificationData(), | 98 message_center::RichNotificationData(), |
99 delegate); | 99 delegate); |
100 g_browser_process->notification_ui_manager()->Add(notification, profile); | 100 g_browser_process->notification_ui_manager()->Add(notification, profile); |
101 return notification.delegate_id(); | 101 return notification.delegate_id(); |
102 } | 102 } |
103 | 103 |
104 DesktopNotificationService::DesktopNotificationService(Profile* profile) | 104 DesktopNotificationService::DesktopNotificationService(Profile* profile) |
105 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS), | 105 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS), |
106 profile_(profile), | 106 profile_(profile), |
| 107 #if defined(ENABLE_EXTENSIONS) |
107 extension_registry_observer_(this), | 108 extension_registry_observer_(this), |
| 109 #endif |
108 weak_factory_(this) { | 110 weak_factory_(this) { |
109 OnStringListPrefChanged( | 111 OnStringListPrefChanged( |
110 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_); | 112 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_); |
111 OnStringListPrefChanged( | 113 OnStringListPrefChanged( |
112 prefs::kMessageCenterDisabledSystemComponentIds, | 114 prefs::kMessageCenterDisabledSystemComponentIds, |
113 &disabled_system_component_ids_); | 115 &disabled_system_component_ids_); |
114 disabled_extension_id_pref_.Init( | 116 disabled_extension_id_pref_.Init( |
115 prefs::kMessageCenterDisabledExtensionIds, | 117 prefs::kMessageCenterDisabledExtensionIds, |
116 profile_->GetPrefs(), | 118 profile_->GetPrefs(), |
117 base::Bind( | 119 base::Bind( |
118 &DesktopNotificationService::OnStringListPrefChanged, | 120 &DesktopNotificationService::OnStringListPrefChanged, |
119 base::Unretained(this), | 121 base::Unretained(this), |
120 base::Unretained(prefs::kMessageCenterDisabledExtensionIds), | 122 base::Unretained(prefs::kMessageCenterDisabledExtensionIds), |
121 base::Unretained(&disabled_extension_ids_))); | 123 base::Unretained(&disabled_extension_ids_))); |
122 disabled_system_component_id_pref_.Init( | 124 disabled_system_component_id_pref_.Init( |
123 prefs::kMessageCenterDisabledSystemComponentIds, | 125 prefs::kMessageCenterDisabledSystemComponentIds, |
124 profile_->GetPrefs(), | 126 profile_->GetPrefs(), |
125 base::Bind( | 127 base::Bind( |
126 &DesktopNotificationService::OnStringListPrefChanged, | 128 &DesktopNotificationService::OnStringListPrefChanged, |
127 base::Unretained(this), | 129 base::Unretained(this), |
128 base::Unretained(prefs::kMessageCenterDisabledSystemComponentIds), | 130 base::Unretained(prefs::kMessageCenterDisabledSystemComponentIds), |
129 base::Unretained(&disabled_system_component_ids_))); | 131 base::Unretained(&disabled_system_component_ids_))); |
| 132 #if defined(ENABLE_EXTENSIONS) |
130 extension_registry_observer_.Add( | 133 extension_registry_observer_.Add( |
131 extensions::ExtensionRegistry::Get(profile_)); | 134 extensions::ExtensionRegistry::Get(profile_)); |
| 135 #endif |
132 } | 136 } |
133 | 137 |
134 DesktopNotificationService::~DesktopNotificationService() { | 138 DesktopNotificationService::~DesktopNotificationService() { |
135 } | 139 } |
136 | 140 |
137 void DesktopNotificationService::RequestNotificationPermission( | 141 void DesktopNotificationService::RequestNotificationPermission( |
138 content::WebContents* web_contents, | 142 content::WebContents* web_contents, |
139 const PermissionRequestID& request_id, | 143 const PermissionRequestID& request_id, |
140 const GURL& requesting_frame, | 144 const GURL& requesting_frame, |
141 bool user_gesture, | 145 bool user_gesture, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 const base::ListValue* pref_list = pref_service->GetList(pref_name); | 293 const base::ListValue* pref_list = pref_service->GetList(pref_name); |
290 for (size_t i = 0; i < pref_list->GetSize(); ++i) { | 294 for (size_t i = 0; i < pref_list->GetSize(); ++i) { |
291 std::string element; | 295 std::string element; |
292 if (pref_list->GetString(i, &element) && !element.empty()) | 296 if (pref_list->GetString(i, &element) && !element.empty()) |
293 ids_field->insert(element); | 297 ids_field->insert(element); |
294 else | 298 else |
295 LOG(WARNING) << i << "-th element is not a string for " << pref_name; | 299 LOG(WARNING) << i << "-th element is not a string for " << pref_name; |
296 } | 300 } |
297 } | 301 } |
298 | 302 |
| 303 #if defined(ENABLE_EXTENSIONS) |
299 void DesktopNotificationService::OnExtensionUninstalled( | 304 void DesktopNotificationService::OnExtensionUninstalled( |
300 content::BrowserContext* browser_context, | 305 content::BrowserContext* browser_context, |
301 const extensions::Extension* extension, | 306 const extensions::Extension* extension, |
302 extensions::UninstallReason reason) { | 307 extensions::UninstallReason reason) { |
303 #if defined(ENABLE_EXTENSIONS) | |
304 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); | 308 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); |
305 if (IsNotifierEnabled(notifier_id)) | 309 if (IsNotifierEnabled(notifier_id)) |
306 return; | 310 return; |
307 | 311 |
308 // The settings for ephemeral apps will be persisted across cache evictions. | 312 // The settings for ephemeral apps will be persisted across cache evictions. |
309 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) | 313 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) |
310 return; | 314 return; |
311 | 315 |
312 SetNotifierEnabled(notifier_id, true); | 316 SetNotifierEnabled(notifier_id, true); |
| 317 } |
313 #endif | 318 #endif |
314 } | |
315 | 319 |
316 void DesktopNotificationService::OnNotificationPermissionRequested( | 320 void DesktopNotificationService::OnNotificationPermissionRequested( |
317 const NotificationPermissionCallback& callback, bool allowed) { | 321 const NotificationPermissionCallback& callback, bool allowed) { |
318 blink::WebNotificationPermission permission = allowed ? | 322 blink::WebNotificationPermission permission = allowed ? |
319 blink::WebNotificationPermissionAllowed : | 323 blink::WebNotificationPermissionAllowed : |
320 blink::WebNotificationPermissionDenied; | 324 blink::WebNotificationPermissionDenied; |
321 | 325 |
322 callback.Run(permission); | 326 callback.Run(permission); |
323 } | 327 } |
324 | 328 |
(...skipping 16 matching lines...) Expand all Loading... |
341 // Tell the IO thread that this extension's permission for notifications | 345 // Tell the IO thread that this extension's permission for notifications |
342 // has changed. | 346 // has changed. |
343 extensions::InfoMap* extension_info_map = | 347 extensions::InfoMap* extension_info_map = |
344 extensions::ExtensionSystem::Get(profile_)->info_map(); | 348 extensions::ExtensionSystem::Get(profile_)->info_map(); |
345 BrowserThread::PostTask( | 349 BrowserThread::PostTask( |
346 BrowserThread::IO, FROM_HERE, | 350 BrowserThread::IO, FROM_HERE, |
347 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 351 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
348 extension_info_map, notifier_id.id, !enabled)); | 352 extension_info_map, notifier_id.id, !enabled)); |
349 #endif | 353 #endif |
350 } | 354 } |
OLD | NEW |