| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/platform_notification_service_impl.h" | 5 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | |
| 11 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/metrics/user_metrics_action.h" | 11 #include "base/metrics/user_metrics_action.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 14 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 15 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 17 #include "chrome/browser/notifications/notification_display_service_factory.h" | 16 #include "chrome/browser/notifications/notification_display_service_factory.h" |
| 18 #include "chrome/browser/notifications/notification_object_proxy.h" | 17 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 19 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 18 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
| 20 #include "chrome/browser/permissions/permission_manager.h" | 19 #include "chrome/browser/permissions/permission_manager.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_attributes_storage.h" | 21 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 23 #include "chrome/browser/profiles/profile_io_data.h" | 22 #include "chrome/browser/profiles/profile_io_data.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/common/chrome_switches.h" | |
| 27 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
| 29 #include "components/content_settings/core/browser/host_content_settings_map.h" | 27 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 30 #include "components/content_settings/core/common/content_settings.h" | 28 #include "components/content_settings/core/common/content_settings.h" |
| 31 #include "components/content_settings/core/common/content_settings_types.h" | 29 #include "components/content_settings/core/common/content_settings_types.h" |
| 32 #include "components/prefs/pref_service.h" | 30 #include "components/prefs/pref_service.h" |
| 33 #include "components/url_formatter/url_formatter.h" | |
| 34 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/desktop_notification_delegate.h" | 32 #include "content/public/browser/desktop_notification_delegate.h" |
| 36 #include "content/public/browser/notification_event_dispatcher.h" | 33 #include "content/public/browser/notification_event_dispatcher.h" |
| 37 #include "content/public/browser/permission_type.h" | 34 #include "content/public/browser/permission_type.h" |
| 38 #include "content/public/browser/storage_partition.h" | |
| 39 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
| 40 #include "content/public/common/notification_resources.h" | 36 #include "content/public/common/notification_resources.h" |
| 41 #include "content/public/common/platform_notification_data.h" | 37 #include "content/public/common/platform_notification_data.h" |
| 42 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 43 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
| 44 #include "ui/message_center/notification.h" | 40 #include "ui/message_center/notification.h" |
| 45 #include "ui/message_center/notification_types.h" | 41 #include "ui/message_center/notification_types.h" |
| 46 #include "ui/message_center/notifier_settings.h" | 42 #include "ui/message_center/notifier_settings.h" |
| 47 #include "url/url_constants.h" | 43 #include "url/url_constants.h" |
| 48 | 44 |
| 45 #if BUILDFLAG(ENABLE_BACKGROUND) |
| 46 #include "chrome/browser/lifetime/keep_alive_types.h" |
| 47 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
| 48 #endif |
| 49 |
| 49 #if defined(ENABLE_EXTENSIONS) | 50 #if defined(ENABLE_EXTENSIONS) |
| 50 #include "chrome/browser/notifications/notifier_state_tracker.h" | 51 #include "chrome/browser/notifications/notifier_state_tracker.h" |
| 51 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | 52 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
| 52 #include "extensions/browser/extension_registry.h" | 53 #include "extensions/browser/extension_registry.h" |
| 53 #include "extensions/browser/info_map.h" | 54 #include "extensions/browser/info_map.h" |
| 54 #include "extensions/common/constants.h" | 55 #include "extensions/common/constants.h" |
| 55 #include "extensions/common/permissions/api_permission.h" | 56 #include "extensions/common/permissions/api_permission.h" |
| 56 #include "extensions/common/permissions/permissions_data.h" | 57 #include "extensions/common/permissions/permissions_data.h" |
| 57 #endif | 58 #endif |
| 58 | 59 |
| 59 #if BUILDFLAG(ENABLE_BACKGROUND) | |
| 60 #include "chrome/browser/lifetime/keep_alive_types.h" | |
| 61 #include "chrome/browser/lifetime/scoped_keep_alive.h" | |
| 62 #endif | |
| 63 | |
| 64 using content::BrowserContext; | 60 using content::BrowserContext; |
| 65 using content::BrowserThread; | 61 using content::BrowserThread; |
| 66 using message_center::NotifierId; | 62 using message_center::NotifierId; |
| 67 | 63 |
| 68 class ProfileAttributesEntry; | |
| 69 | |
| 70 namespace { | 64 namespace { |
| 71 | 65 |
| 72 // Invalid id for a renderer process. Used in cases where we need to check for | 66 // Invalid id for a renderer process. Used in cases where we need to check for |
| 73 // permission without having an associated renderer process yet. | 67 // permission without having an associated renderer process yet. |
| 74 const int kInvalidRenderProcessId = -1; | 68 const int kInvalidRenderProcessId = -1; |
| 75 | 69 |
| 76 void OnCloseNonPersistentNotificationProfileLoaded( | 70 void OnCloseNonPersistentNotificationProfileLoaded( |
| 77 const std::string& notification_id, | 71 const std::string& notification_id, |
| 78 Profile* profile) { | 72 Profile* profile) { |
| 79 NotificationDisplayServiceFactory::GetForProfile(profile)->Close( | 73 NotificationDisplayServiceFactory::GetForProfile(profile)->Close( |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 // platform that makes good use of them in the status bar. | 432 // platform that makes good use of them in the status bar. |
| 439 #if defined(OS_ANDROID) | 433 #if defined(OS_ANDROID) |
| 440 // TODO(peter): Handle different screen densities instead of always using the | 434 // TODO(peter): Handle different screen densities instead of always using the |
| 441 // 1x bitmap - crbug.com/585815. | 435 // 1x bitmap - crbug.com/585815. |
| 442 notification.set_small_image( | 436 notification.set_small_image( |
| 443 gfx::Image::CreateFrom1xBitmap(notification_resources.badge)); | 437 gfx::Image::CreateFrom1xBitmap(notification_resources.badge)); |
| 444 #endif // defined(OS_ANDROID) | 438 #endif // defined(OS_ANDROID) |
| 445 | 439 |
| 446 // Developer supplied action buttons. | 440 // Developer supplied action buttons. |
| 447 std::vector<message_center::ButtonInfo> buttons; | 441 std::vector<message_center::ButtonInfo> buttons; |
| 448 for (size_t i = 0; i < notification_data.actions.size(); i++) { | 442 for (size_t i = 0; i < notification_data.actions.size(); ++i) { |
| 449 content::PlatformNotificationAction const& action = | 443 const content::PlatformNotificationAction& action = |
| 450 notification_data.actions[i]; | 444 notification_data.actions[i]; |
| 451 message_center::ButtonInfo button(action.title); | 445 message_center::ButtonInfo button(action.title); |
| 452 // TODO(peter): Handle different screen densities instead of always using | 446 // TODO(peter): Handle different screen densities instead of always using |
| 453 // the 1x bitmap - crbug.com/585815. | 447 // the 1x bitmap - crbug.com/585815. |
| 454 button.icon = | 448 button.icon = |
| 455 gfx::Image::CreateFrom1xBitmap(notification_resources.action_icons[i]); | 449 gfx::Image::CreateFrom1xBitmap(notification_resources.action_icons[i]); |
| 456 button.placeholder = | 450 button.placeholder = |
| 457 action.placeholder.is_null() | 451 action.placeholder.is_null() |
| 458 ? l10n_util::GetStringUTF16(IDS_NOTIFICATION_REPLY_PLACEHOLDER) | 452 ? l10n_util::GetStringUTF16(IDS_NOTIFICATION_REPLY_PLACEHOLDER) |
| 459 : action.placeholder.string(); | 453 : action.placeholder.string(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 474 // On mobile, this is ignored (notifications are minimized at all times). | 468 // On mobile, this is ignored (notifications are minimized at all times). |
| 475 if (notification_data.require_interaction) | 469 if (notification_data.require_interaction) |
| 476 notification.set_never_timeout(true); | 470 notification.set_never_timeout(true); |
| 477 | 471 |
| 478 return notification; | 472 return notification; |
| 479 } | 473 } |
| 480 | 474 |
| 481 NotificationDisplayService* | 475 NotificationDisplayService* |
| 482 PlatformNotificationServiceImpl::GetNotificationDisplayService( | 476 PlatformNotificationServiceImpl::GetNotificationDisplayService( |
| 483 Profile* profile) { | 477 Profile* profile) { |
| 484 if (test_display_service_ != nullptr) | 478 return test_display_service_ |
| 485 return test_display_service_; | 479 ? test_display_service_ |
| 486 return NotificationDisplayServiceFactory::GetForProfile(profile); | 480 : NotificationDisplayServiceFactory::GetForProfile(profile); |
| 487 } | 481 } |
| 488 | 482 |
| 489 base::string16 PlatformNotificationServiceImpl::DisplayNameForContextMessage( | 483 base::string16 PlatformNotificationServiceImpl::DisplayNameForContextMessage( |
| 490 Profile* profile, | 484 Profile* profile, |
| 491 const GURL& origin) const { | 485 const GURL& origin) const { |
| 492 #if defined(ENABLE_EXTENSIONS) | 486 #if defined(ENABLE_EXTENSIONS) |
| 493 // If the source is an extension, lookup the display name. | 487 // If the source is an extension, lookup the display name. |
| 494 if (origin.SchemeIs(extensions::kExtensionScheme)) { | 488 if (origin.SchemeIs(extensions::kExtensionScheme)) { |
| 495 const extensions::Extension* extension = | 489 const extensions::Extension* extension = |
| 496 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 490 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 497 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 491 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
| 498 DCHECK(extension); | 492 DCHECK(extension); |
| 499 | 493 |
| 500 return base::UTF8ToUTF16(extension->name()); | 494 return base::UTF8ToUTF16(extension->name()); |
| 501 } | 495 } |
| 502 #endif | 496 #endif |
| 503 | 497 |
| 504 return base::string16(); | 498 return base::string16(); |
| 505 } | 499 } |
| 506 | 500 |
| 507 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( | 501 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( |
| 508 NotificationDisplayService* display_service) { | 502 NotificationDisplayService* display_service) { |
| 509 test_display_service_ = display_service; | 503 test_display_service_ = display_service; |
| 510 } | 504 } |
| OLD | NEW |