Chromium Code Reviews| Index: chrome/browser/notifications/platform_notification_service_impl.cc |
| diff --git a/chrome/browser/notifications/platform_notification_service_impl.cc b/chrome/browser/notifications/platform_notification_service_impl.cc |
| index 75719bd4e70dceea9c592b28e4c8c6b7b495bbf1..d78afbe34468934106f32c4d3b3de0c83fb73c95 100644 |
| --- a/chrome/browser/notifications/platform_notification_service_impl.cc |
| +++ b/chrome/browser/notifications/platform_notification_service_impl.cc |
| @@ -4,6 +4,7 @@ |
| #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| +#include "base/prefs/pref_service.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/notifications/notification_object_proxy.h" |
| @@ -11,17 +12,20 @@ |
| #include "chrome/browser/notifications/persistent_notification_delegate.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_io_data.h" |
| +#include "chrome/common/pref_names.h" |
| #include "components/content_settings/core/browser/host_content_settings_map.h" |
| #include "components/content_settings/core/common/content_settings.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/desktop_notification_delegate.h" |
| #include "content/public/browser/notification_event_dispatcher.h" |
| #include "content/public/common/platform_notification_data.h" |
| +#include "net/base/net_util.h" |
| #include "ui/message_center/notifier_settings.h" |
| #if defined(ENABLE_EXTENSIONS) |
| #include "chrome/browser/notifications/desktop_notification_service.h" |
| #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| +#include "extensions/browser/extension_registry.h" |
| #include "extensions/browser/extension_system.h" |
| #include "extensions/browser/info_map.h" |
| #include "extensions/common/constants.h" |
| @@ -120,7 +124,6 @@ void PlatformNotificationServiceImpl::DisplayNotification( |
| const SkBitmap& icon, |
| const content::PlatformNotificationData& notification_data, |
| scoped_ptr<content::DesktopNotificationDelegate> delegate, |
| - int render_process_id, |
| base::Closure* cancel_callback) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| @@ -129,7 +132,7 @@ void PlatformNotificationServiceImpl::DisplayNotification( |
| NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass()); |
| Notification notification = CreateNotificationFromData( |
| - profile, origin, icon, notification_data, proxy, render_process_id); |
| + profile, origin, icon, notification_data, proxy); |
| GetNotificationUIManager()->Add(notification, profile); |
| if (cancel_callback) |
| @@ -147,8 +150,7 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
| int64 service_worker_registration_id, |
| const GURL& origin, |
| const SkBitmap& icon, |
| - const content::PlatformNotificationData& notification_data, |
| - int render_process_id) { |
| + const content::PlatformNotificationData& notification_data) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| Profile* profile = Profile::FromBrowserContext(browser_context); |
| @@ -161,7 +163,7 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
| notification_data); |
| Notification notification = CreateNotificationFromData( |
| - profile, origin, icon, notification_data, delegate, render_process_id); |
| + profile, origin, icon, notification_data, delegate); |
| GetNotificationUIManager()->Add(notification, profile); |
| @@ -186,10 +188,8 @@ Notification PlatformNotificationServiceImpl::CreateNotificationFromData( |
| const GURL& origin, |
| const SkBitmap& icon, |
| const content::PlatformNotificationData& notification_data, |
| - NotificationDelegate* delegate, |
| - int render_process_id) const { |
| - base::string16 display_source = DisplayNameForOriginInProcessId( |
| - profile, origin, render_process_id); |
| + NotificationDelegate* delegate) const { |
| + base::string16 display_source = DisplayNameForOrigin(profile, origin); |
| // TODO(peter): Icons for Web Notifications are currently always requested for |
| // 1x scale, whereas the displays on which they can be displayed can have a |
| @@ -199,6 +199,8 @@ Notification PlatformNotificationServiceImpl::CreateNotificationFromData( |
| notification_data.body, gfx::Image::CreateFrom1xBitmap(icon), |
| display_source, notification_data.tag, delegate); |
| + notification.set_context_message(display_source); |
| + |
| // Web Notifications do not timeout. |
| notification.set_never_timeout(true); |
| @@ -218,32 +220,42 @@ void PlatformNotificationServiceImpl::SetNotificationUIManagerForTesting( |
| notification_ui_manager_for_tests_ = manager; |
| } |
| -base::string16 PlatformNotificationServiceImpl::DisplayNameForOriginInProcessId( |
| - Profile* profile, const GURL& origin, int process_id) const { |
| +base::string16 PlatformNotificationServiceImpl::DisplayNameForOrigin( |
| + Profile* profile, |
| + const GURL& origin) const { |
| #if defined(ENABLE_EXTENSIONS) |
| // If the source is an extension, lookup the display name. |
| if (origin.SchemeIs(extensions::kExtensionScheme)) { |
| - extensions::InfoMap* extension_info_map = |
| - extensions::ExtensionSystem::Get(profile)->info_map(); |
| - if (extension_info_map) { |
| - extensions::ExtensionSet extensions; |
| - extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( |
| - origin, |
| - process_id, |
| - extensions::APIPermission::kNotifications, |
| - &extensions); |
| - DesktopNotificationService* desktop_notification_service = |
| - DesktopNotificationServiceFactory::GetForProfile(profile); |
| - DCHECK(desktop_notification_service); |
| - |
| - for (const auto& extension : extensions) { |
| - NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); |
| - if (desktop_notification_service->IsNotifierEnabled(notifier_id)) |
| - return base::UTF8ToUTF16(extension->name()); |
| - } |
| - } |
| + const extensions::Extension* extension = |
| + extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| + origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
| + DCHECK(extension); |
| + |
| + return base::UTF8ToUTF16(extension->name()); |
| } |
| #endif |
| - return base::UTF8ToUTF16(origin.host()); |
| + std::string languages = |
| + profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| + |
| + return WebOriginDisplayName(origin, languages); |
| +} |
| + |
| +// static |
| +base::string16 PlatformNotificationServiceImpl::WebOriginDisplayName( |
| + const GURL& origin, |
| + const std::string& languages) { |
| + if (origin.SchemeIsHTTPOrHTTPS()) { |
| + base::string16 formatted_origin = |
| + net::IDNToUnicode(origin.host(), languages); |
| + if (origin.has_port()) { |
| + formatted_origin.push_back(':'); |
| + formatted_origin.append(base::UTF8ToUTF16(origin.port())); |
| + } |
| + return formatted_origin; |
| + } |
|
felt
2015/01/29 20:22:44
I'm fine with dropping https:// because that is me
dewittj
2015/02/02 19:42:57
Done.
|
| + |
| + // TODO(dewittj): Once file:// URLs are passed in to the origin |
| + // GURL here, begin returning the path as the display name. |
| + return net::FormatUrl(origin, languages); |
| } |