| 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/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 origin_url, title, message, icon_url, replace_id, delegate, profile); | 269 origin_url, title, message, icon_url, replace_id, delegate, profile); |
| 270 #endif | 270 #endif |
| 271 } | 271 } |
| 272 | 272 |
| 273 // static | 273 // static |
| 274 void DesktopNotificationService::RemoveNotification( | 274 void DesktopNotificationService::RemoveNotification( |
| 275 const std::string& notification_id) { | 275 const std::string& notification_id) { |
| 276 g_browser_process->notification_ui_manager()->CancelById(notification_id); | 276 g_browser_process->notification_ui_manager()->CancelById(notification_id); |
| 277 } | 277 } |
| 278 | 278 |
| 279 DesktopNotificationService::DesktopNotificationService(Profile* profile, | 279 DesktopNotificationService::DesktopNotificationService( |
| 280 Profile* profile, |
| 280 NotificationUIManager* ui_manager) | 281 NotificationUIManager* ui_manager) |
| 281 : profile_(profile), | 282 : profile_(profile), |
| 282 ui_manager_(ui_manager) { | 283 ui_manager_(ui_manager) { |
| 283 StartObserving(); | 284 StartObserving(); |
| 284 } | 285 } |
| 285 | 286 |
| 286 DesktopNotificationService::~DesktopNotificationService() { | 287 DesktopNotificationService::~DesktopNotificationService() { |
| 287 StopObserving(); | 288 StopObserving(); |
| 288 } | 289 } |
| 289 | 290 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 319 ContentSettingsPattern::Wildcard(), | 320 ContentSettingsPattern::Wildcard(), |
| 320 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 321 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 321 NO_RESOURCE_IDENTIFIER, | 322 NO_RESOURCE_IDENTIFIER, |
| 322 CONTENT_SETTING_BLOCK); | 323 CONTENT_SETTING_BLOCK); |
| 323 } | 324 } |
| 324 | 325 |
| 325 void DesktopNotificationService::Observe( | 326 void DesktopNotificationService::Observe( |
| 326 int type, | 327 int type, |
| 327 const content::NotificationSource& source, | 328 const content::NotificationSource& source, |
| 328 const content::NotificationDetails& details) { | 329 const content::NotificationDetails& details) { |
| 330 // This may get called during shutdown, so don't use GetUIManager() here, |
| 331 // and don't do anything if ui_manager_ hasn't already been set. |
| 332 if (!ui_manager_) |
| 333 return; |
| 334 |
| 329 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | 335 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
| 330 // Remove all notifications currently shown or queued by the extension | 336 // Remove all notifications currently shown or queued by the extension |
| 331 // which was unloaded. Don't use GetUIManager() here, because this may | 337 // which was unloaded. |
| 332 // get called during shutdown. | |
| 333 const extensions::Extension* extension = | 338 const extensions::Extension* extension = |
| 334 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; | 339 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; |
| 335 if (extension && | 340 if (extension && |
| 336 g_browser_process && g_browser_process->notification_ui_manager()) { | 341 g_browser_process && g_browser_process->notification_ui_manager()) { |
| 337 g_browser_process->notification_ui_manager()-> | 342 g_browser_process->notification_ui_manager()-> |
| 338 CancelAllBySourceOrigin(extension->url()); | 343 CancelAllBySourceOrigin(extension->url()); |
| 339 } | 344 } |
| 340 } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) { | 345 } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) { |
| 346 if (g_browser_process && g_browser_process->notification_ui_manager()) { |
| 347 g_browser_process->notification_ui_manager()-> |
| 348 CancelAllByProfile(profile_); |
| 349 } |
| 341 StopObserving(); | 350 StopObserving(); |
| 342 } | 351 } |
| 343 } | 352 } |
| 344 | 353 |
| 345 ContentSetting DesktopNotificationService::GetDefaultContentSetting( | 354 ContentSetting DesktopNotificationService::GetDefaultContentSetting( |
| 346 std::string* provider_id) { | 355 std::string* provider_id) { |
| 347 return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( | 356 return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( |
| 348 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, provider_id); | 357 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, provider_id); |
| 349 } | 358 } |
| 350 | 359 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 | 519 |
| 511 if (setting == CONTENT_SETTING_ALLOW) | 520 if (setting == CONTENT_SETTING_ALLOW) |
| 512 return WebKit::WebNotificationPresenter::PermissionAllowed; | 521 return WebKit::WebNotificationPresenter::PermissionAllowed; |
| 513 if (setting == CONTENT_SETTING_BLOCK) | 522 if (setting == CONTENT_SETTING_BLOCK) |
| 514 return WebKit::WebNotificationPresenter::PermissionDenied; | 523 return WebKit::WebNotificationPresenter::PermissionDenied; |
| 515 if (setting == CONTENT_SETTING_ASK) | 524 if (setting == CONTENT_SETTING_ASK) |
| 516 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 525 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 517 NOTREACHED() << "Invalid notifications settings value: " << setting; | 526 NOTREACHED() << "Invalid notifications settings value: " << setting; |
| 518 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 527 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 519 } | 528 } |
| OLD | NEW |