Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2685)

Unified Diff: chrome/browser/notifications/desktop_notification_service.cc

Issue 661643002: Adds a context message of the security origin for web notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 585ac4ac701b35a8d1803d509a98833b47abdb65..59940473986c1748785a9befc34657ce6db6feae 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -21,6 +21,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/desktop_notification_delegate.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"
@@ -177,6 +178,8 @@ void DesktopNotificationService::ShowDesktopNotification(
const GURL& origin = params.origin;
NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass());
+ // 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.
felt 2014/11/04 00:50:16 Could you have content/renderer/notification_provi
dewittj 2015/01/09 21:59:40 This appears to be a broader issue than just notif
felt 2015/01/17 01:40:15 Can you write a test to verify that it's impossibl
base::string16 display_source = DisplayNameForOriginInProcessId(
origin, render_process_id);
@@ -188,6 +191,9 @@ void DesktopNotificationService::ShowDesktopNotification(
gfx::Image::CreateFrom1xBitmap(params.icon),
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);
@@ -202,34 +208,74 @@ 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 (auto& extension : extensions) {
+ NotifierId notifier_id(NotifierId::APPLICATION, extension->id());
+ if (IsNotifierEnabled(notifier_id)) {
+ *out = base::UTF8ToUTF16(extension->name());
+ return true;
+ }
+ }
+ }
+ return false;
+}
+#endif // defined(ENABLE_EXTENSIONS)
+
+// static
+base::string16 DesktopNotificationService::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);
}
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) ==

Powered by Google App Engine
This is Rietveld 408576698