Chromium Code Reviews| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 Notification notification(origin_url, icon, title, message, | 91 Notification notification(origin_url, icon, title, message, |
| 92 blink::WebTextDirectionDefault, | 92 blink::WebTextDirectionDefault, |
| 93 base::string16(), replace_id, delegate); | 93 base::string16(), replace_id, delegate); |
| 94 g_browser_process->notification_ui_manager()->Add(notification, profile); | 94 g_browser_process->notification_ui_manager()->Add(notification, profile); |
| 95 return notification.delegate_id(); | 95 return notification.delegate_id(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 DesktopNotificationService::DesktopNotificationService(Profile* profile) | 98 DesktopNotificationService::DesktopNotificationService(Profile* profile) |
| 99 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS), | 99 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS), |
| 100 profile_(profile), | 100 profile_(profile), |
| 101 #if defined(ENABLE_EXTENSION) | |
|
dewittj
2014/09/19 17:33:05
this should be ENABLE_EXTENSIONS
Jitu( very slow this week)
2014/09/22 05:49:44
Done.
| |
| 101 extension_registry_observer_(this), | 102 extension_registry_observer_(this), |
| 103 #endif | |
| 102 weak_factory_(this) { | 104 weak_factory_(this) { |
| 103 OnStringListPrefChanged( | 105 OnStringListPrefChanged( |
| 104 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_); | 106 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_); |
| 105 OnStringListPrefChanged( | 107 OnStringListPrefChanged( |
| 106 prefs::kMessageCenterDisabledSystemComponentIds, | 108 prefs::kMessageCenterDisabledSystemComponentIds, |
| 107 &disabled_system_component_ids_); | 109 &disabled_system_component_ids_); |
| 108 disabled_extension_id_pref_.Init( | 110 disabled_extension_id_pref_.Init( |
| 109 prefs::kMessageCenterDisabledExtensionIds, | 111 prefs::kMessageCenterDisabledExtensionIds, |
| 110 profile_->GetPrefs(), | 112 profile_->GetPrefs(), |
| 111 base::Bind( | 113 base::Bind( |
| 112 &DesktopNotificationService::OnStringListPrefChanged, | 114 &DesktopNotificationService::OnStringListPrefChanged, |
| 113 base::Unretained(this), | 115 base::Unretained(this), |
| 114 base::Unretained(prefs::kMessageCenterDisabledExtensionIds), | 116 base::Unretained(prefs::kMessageCenterDisabledExtensionIds), |
| 115 base::Unretained(&disabled_extension_ids_))); | 117 base::Unretained(&disabled_extension_ids_))); |
| 116 disabled_system_component_id_pref_.Init( | 118 disabled_system_component_id_pref_.Init( |
| 117 prefs::kMessageCenterDisabledSystemComponentIds, | 119 prefs::kMessageCenterDisabledSystemComponentIds, |
| 118 profile_->GetPrefs(), | 120 profile_->GetPrefs(), |
| 119 base::Bind( | 121 base::Bind( |
| 120 &DesktopNotificationService::OnStringListPrefChanged, | 122 &DesktopNotificationService::OnStringListPrefChanged, |
| 121 base::Unretained(this), | 123 base::Unretained(this), |
| 122 base::Unretained(prefs::kMessageCenterDisabledSystemComponentIds), | 124 base::Unretained(prefs::kMessageCenterDisabledSystemComponentIds), |
| 123 base::Unretained(&disabled_system_component_ids_))); | 125 base::Unretained(&disabled_system_component_ids_))); |
| 126 #if defined(ENABLE_EXTENSION) | |
|
dewittj
2014/09/19 17:33:05
Same.
Jitu( very slow this week)
2014/09/22 05:49:44
Done.
| |
| 124 extension_registry_observer_.Add( | 127 extension_registry_observer_.Add( |
| 125 extensions::ExtensionRegistry::Get(profile_)); | 128 extensions::ExtensionRegistry::Get(profile_)); |
| 129 #endif | |
| 126 } | 130 } |
| 127 | 131 |
| 128 DesktopNotificationService::~DesktopNotificationService() { | 132 DesktopNotificationService::~DesktopNotificationService() { |
| 129 } | 133 } |
| 130 | 134 |
| 131 void DesktopNotificationService::RequestNotificationPermission( | 135 void DesktopNotificationService::RequestNotificationPermission( |
| 132 content::WebContents* web_contents, | 136 content::WebContents* web_contents, |
| 133 const PermissionRequestID& request_id, | 137 const PermissionRequestID& request_id, |
| 134 const GURL& requesting_frame, | 138 const GURL& requesting_frame, |
| 135 bool user_gesture, | 139 bool user_gesture, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 const base::ListValue* pref_list = pref_service->GetList(pref_name); | 287 const base::ListValue* pref_list = pref_service->GetList(pref_name); |
| 284 for (size_t i = 0; i < pref_list->GetSize(); ++i) { | 288 for (size_t i = 0; i < pref_list->GetSize(); ++i) { |
| 285 std::string element; | 289 std::string element; |
| 286 if (pref_list->GetString(i, &element) && !element.empty()) | 290 if (pref_list->GetString(i, &element) && !element.empty()) |
| 287 ids_field->insert(element); | 291 ids_field->insert(element); |
| 288 else | 292 else |
| 289 LOG(WARNING) << i << "-th element is not a string for " << pref_name; | 293 LOG(WARNING) << i << "-th element is not a string for " << pref_name; |
| 290 } | 294 } |
| 291 } | 295 } |
| 292 | 296 |
| 297 #if defined(ENABLE_EXTENSIONS) | |
| 293 void DesktopNotificationService::OnExtensionUninstalled( | 298 void DesktopNotificationService::OnExtensionUninstalled( |
| 294 content::BrowserContext* browser_context, | 299 content::BrowserContext* browser_context, |
| 295 const extensions::Extension* extension, | 300 const extensions::Extension* extension, |
| 296 extensions::UninstallReason reason) { | 301 extensions::UninstallReason reason) { |
| 297 #if defined(ENABLE_EXTENSIONS) | |
| 298 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); | 302 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); |
| 299 if (IsNotifierEnabled(notifier_id)) | 303 if (IsNotifierEnabled(notifier_id)) |
| 300 return; | 304 return; |
| 301 | 305 |
| 302 // The settings for ephemeral apps will be persisted across cache evictions. | 306 // The settings for ephemeral apps will be persisted across cache evictions. |
| 303 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) | 307 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) |
| 304 return; | 308 return; |
| 305 | 309 |
| 306 SetNotifierEnabled(notifier_id, true); | 310 SetNotifierEnabled(notifier_id, true); |
| 311 } | |
| 307 #endif | 312 #endif |
| 308 } | |
| 309 | 313 |
| 310 void DesktopNotificationService::OnNotificationPermissionRequested( | 314 void DesktopNotificationService::OnNotificationPermissionRequested( |
| 311 const NotificationPermissionCallback& callback, bool allowed) { | 315 const NotificationPermissionCallback& callback, bool allowed) { |
| 312 blink::WebNotificationPermission permission = allowed ? | 316 blink::WebNotificationPermission permission = allowed ? |
| 313 blink::WebNotificationPermissionAllowed : | 317 blink::WebNotificationPermissionAllowed : |
| 314 blink::WebNotificationPermissionDenied; | 318 blink::WebNotificationPermissionDenied; |
| 315 | 319 |
| 316 callback.Run(permission); | 320 callback.Run(permission); |
| 317 } | 321 } |
| 318 | 322 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 335 // Tell the IO thread that this extension's permission for notifications | 339 // Tell the IO thread that this extension's permission for notifications |
| 336 // has changed. | 340 // has changed. |
| 337 extensions::InfoMap* extension_info_map = | 341 extensions::InfoMap* extension_info_map = |
| 338 extensions::ExtensionSystem::Get(profile_)->info_map(); | 342 extensions::ExtensionSystem::Get(profile_)->info_map(); |
| 339 BrowserThread::PostTask( | 343 BrowserThread::PostTask( |
| 340 BrowserThread::IO, FROM_HERE, | 344 BrowserThread::IO, FROM_HERE, |
| 341 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 345 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
| 342 extension_info_map, notifier_id.id, !enabled)); | 346 extension_info_map, notifier_id.id, !enabled)); |
| 343 #endif | 347 #endif |
| 344 } | 348 } |
| OLD | NEW |