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..d6d6e280603f5107c5b46610892d246b30688a60 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,12 +12,14 @@ |
#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) |
@@ -199,6 +202,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); |
@@ -219,31 +224,76 @@ void PlatformNotificationServiceImpl::SetNotificationUIManagerForTesting( |
} |
base::string16 PlatformNotificationServiceImpl::DisplayNameForOriginInProcessId( |
- Profile* profile, const GURL& origin, int process_id) const { |
+ Profile* profile, |
+ const GURL& origin, |
+ int process_id) 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()); |
- } |
+ base::string16 extension_display_name; |
+ if (ExtensionDisplayName(profile, origin, process_id, |
+ &extension_display_name)) { |
+ return extension_display_name; |
} |
} |
#endif |
- return base::UTF8ToUTF16(origin.host()); |
+ std::string languages = |
+ profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
+ |
+ return OriginDisplayName(origin, languages); |
+} |
+ |
+#if defined(ENABLE_EXTENSIONS) |
+bool PlatformNotificationServiceImpl::ExtensionDisplayName( |
+ Profile* profile, |
+ const GURL& origin, |
+ int process_id, |
+ base::string16* out) const { |
+ DCHECK(origin.SchemeIs(extensions::kExtensionScheme)); |
+ DCHECK(out); |
+ |
+ extensions::InfoMap* extension_info_map = |
+ extensions::ExtensionSystem::Get(profile)->info_map(); |
Peter Beverloo
2015/01/10 00:03:33
This is the code that's violating threading constr
dewittj
2015/01/13 22:18:01
Yes, I know this is the threading problem; just mo
Peter Beverloo
2015/01/14 19:18:14
That seems good to me. If this does ever happen in
|
+ 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 (auto& extension : extensions) { |
+ NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); |
+ if (desktop_notification_service->IsNotifierEnabled(notifier_id)) { |
+ *out = base::UTF8ToUTF16(extension->name()); |
+ return true; |
+ } |
+ } |
+ } |
+ return false; |
+} |
+#endif // defined(ENABLE_EXTENSIONS) |
+ |
+// static |
+base::string16 PlatformNotificationServiceImpl::OriginDisplayName( |
+ 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; |
+ } |
+ |
+ // 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); |
} |
+ |
+ |