Index: chrome/browser/notifications/desktop_notification_service.cc |
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc |
index 01bacf5b0ed5475fbc4331db316833a55611334c..0c4915acc2cfe2e15e0b0f9c5f7f27c1f12bcd53 100644 |
--- a/chrome/browser/notifications/desktop_notification_service.cc |
+++ b/chrome/browser/notifications/desktop_notification_service.cc |
@@ -31,6 +31,7 @@ |
#include "content/public/browser/render_view_host.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/show_desktop_notification_params.h" |
+#include "net/base/net_util.h" |
#include "ui/base/webui/web_ui_util.h" |
#include "ui/message_center/notifier_settings.h" |
@@ -162,12 +163,20 @@ void DesktopNotificationService::ShowDesktopNotification( |
NotificationObjectProxy* proxy = |
new NotificationObjectProxy(render_frame_host, delegate.Pass()); |
- base::string16 display_source = DisplayNameForOriginInProcessId( |
- origin, render_frame_host->GetProcess()->GetID()); |
+ int process_id = render_frame_host->GetProcess()->GetID(); |
+ |
+ // TODO(dewittj): The origin of file:// URLs always appears to be the empty |
+ // URL. We need a better way to display this than returning an empty string. |
+ base::string16 display_source = |
+ DisplayNameForOriginInProcessId(origin, process_id); |
+ |
Notification notification(origin, params.icon_url, params.title, |
params.body, params.direction, display_source, params.replace_id, |
proxy); |
+ // Web notifications should display their origin |
+ notification.set_context_message(display_source); |
+ |
// The webkit notification doesn't timeout. |
notification.set_never_timeout(true); |
@@ -182,34 +191,76 @@ void DesktopNotificationService::ShowDesktopNotification( |
} |
base::string16 DesktopNotificationService::DisplayNameForOriginInProcessId( |
- const GURL& origin, int process_id) { |
+ 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); |
- for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); |
- iter != extensions.end(); ++iter) { |
- NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id()); |
- if (IsNotifierEnabled(notifier_id)) |
- return base::UTF8ToUTF16((*iter)->name()); |
- } |
+ base::string16 extension_display_name; |
+ if (ExtensionDisplayName(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 DesktopNotificationService::ExtensionDisplayName( |
+ 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(); |
+ if (extension_info_map) { |
+ extensions::ExtensionSet extensions; |
+ extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( |
+ origin, |
+ process_id, |
+ extensions::APIPermission::kNotifications, |
+ &extensions); |
+ for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); |
Peter Beverloo
2014/10/18 09:31:02
nit: since you're moving this, might as well use C
dewittj
2014/10/29 16:21:25
Done.
|
+ iter != extensions.end(); |
+ ++iter) { |
+ NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id()); |
+ if (IsNotifierEnabled(notifier_id)) { |
+ *out = base::UTF8ToUTF16((*iter)->name()); |
+ return true; |
+ } |
+ } |
+ } |
+ return false; |
+} |
+#endif // defined(ENABLE_EXTENSIONS) |
+ |
+// static |
+base::string16 DesktopNotificationService::OriginDisplayName( |
+ const GURL& origin, |
+ 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); |
} |
bool DesktopNotificationService::IsNotifierEnabled( |
- const NotifierId& notifier_id) { |
+ const NotifierId& notifier_id) const { |
switch (notifier_id.type) { |
case NotifierId::APPLICATION: |
return disabled_extension_ids_.find(notifier_id.id) == |