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

Unified Diff: chrome/browser/notifications/notification_platform_bridge_mac.mm

Issue 2827543003: Display ETLD+1 instead of the full domain in MacOSX native notifications (Closed)
Patch Set: format Created 3 years, 8 months 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
« no previous file with comments | « no previous file | chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/notifications/notification_platform_bridge_mac.mm
diff --git a/chrome/browser/notifications/notification_platform_bridge_mac.mm b/chrome/browser/notifications/notification_platform_bridge_mac.mm
index b3357a6ceb216506db1525ac67c10aba3b35f6dd..b1073fd2428e0c31915433a55603ef6af3527ff5 100644
--- a/chrome/browser/notifications/notification_platform_bridge_mac.mm
+++ b/chrome/browser/notifications/notification_platform_bridge_mac.mm
@@ -36,6 +36,7 @@
#include "chrome/grit/generated_resources.h"
#include "components/crash/content/app/crashpad.h"
#include "components/url_formatter/elide_url.h"
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "third_party/WebKit/public/platform/modules/notifications/WebNotificationConstants.h"
#include "third_party/crashpad/crashpad/client/crashpad_client.h"
#include "ui/base/l10n/l10n_util_mac.h"
@@ -126,6 +127,25 @@ base::string16 CreateNotificationTitle(const Notification& notification) {
return title;
}
+base::string16 CreateNotificationContext(const Notification& notification,
+ bool requires_attribution) {
+ if (!requires_attribution)
+ return notification.context_message();
+
+ base::string16 context =
+ base::UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry(
+ notification.origin_url(),
+ net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
+
+ // localhost, raw IPs etc. are not handled by GetDomainAndRegistry.
+ if (context.empty()) {
+ context = url_formatter::FormatOriginForSecurityDisplay(
+ url::Origin(notification.origin_url()),
+ url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
+ }
+
+ return context;
+}
} // namespace
// A Cocoa class that represents the delegate of NSUserNotificationCenter and
@@ -194,15 +214,9 @@ void NotificationPlatformBridgeMac::Display(
bool requires_attribution =
notification.context_message().empty() &&
notification_type != NotificationCommon::EXTENSION;
+ [builder setSubTitle:base::SysUTF16ToNSString(CreateNotificationContext(
+ notification, requires_attribution))];
- base::string16 subtitle =
- requires_attribution
- ? url_formatter::FormatOriginForSecurityDisplay(
- url::Origin(notification.origin_url()),
- url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS)
- : notification.context_message();
-
- [builder setSubTitle:base::SysUTF16ToNSString(subtitle)];
if (!notification.icon().IsEmpty()) {
[builder setIcon:notification.icon().ToNSImage()];
}
« no previous file with comments | « no previous file | chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698