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

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

Issue 385058: When extensions use notifications, display the name of the extension in UI ra... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 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
===================================================================
--- chrome/browser/notifications/desktop_notification_service.cc (revision 31723)
+++ chrome/browser/notifications/desktop_notification_service.cc (working copy)
@@ -11,6 +11,7 @@
#include "base/thread.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_object_proxy.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
@@ -26,6 +27,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
#include "chrome/common/render_messages.h"
+#include "chrome/common/url_constants.h"
#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -100,11 +102,13 @@
public:
NotificationPermissionInfoBarDelegate(TabContents* contents,
const GURL& origin,
+ const std::wstring& display_name,
int process_id,
int route_id,
int callback_context)
: ConfirmInfoBarDelegate(contents),
origin_(origin),
+ display_name_(display_name),
profile_(contents->profile()),
process_id_(process_id),
route_id_(route_id),
@@ -126,8 +130,7 @@
}
virtual std::wstring GetMessageText() const {
- return l10n_util::GetStringF(IDS_NOTIFICATION_PERMISSIONS,
- UTF8ToWide(origin_.spec()));
+ return l10n_util::GetStringF(IDS_NOTIFICATION_PERMISSIONS, display_name_);
}
virtual SkBitmap* GetIcon() const {
@@ -163,6 +166,10 @@
// The origin we are asking for permissions on.
GURL origin_;
+ // The display name for the origin to be displayed. Will be different from
+ // origin_ for extensions.
+ std::wstring display_name_;
+
// The Profile that we restore sessions from.
Profile* profile_;
@@ -260,8 +267,11 @@
TabContents* tab = browser->GetSelectedTabContents();
if (!tab)
return;
+
+ std::wstring display_name = DisplayNameForOrigin(origin);
+
tab->AddInfoBar(new NotificationPermissionInfoBarDelegate(
- tab, origin, process_id, route_id, callback_context));
+ tab, origin, display_name, process_id, route_id, callback_context));
}
void DesktopNotificationService::ShowNotification(
@@ -274,7 +284,7 @@
scoped_refptr<NotificationObjectProxy> proxy(
new NotificationObjectProxy(process_id, route_id, notification_id,
false));
- Notification notif(GURL(), GURL(), proxy);
+ Notification notif(GURL(), GURL(), L"", proxy);
return ui_manager_->Cancel(notif);
}
@@ -287,7 +297,7 @@
new NotificationObjectProxy(process_id, route_id,
notification_id,
source == WorkerNotification);
- Notification notif(origin, url, proxy);
+ Notification notif(origin, url, DisplayNameForOrigin(origin), proxy);
ShowNotification(notif);
return true;
}
@@ -303,7 +313,22 @@
source == WorkerNotification);
// "upconvert" the string parameters to a data: URL.
string16 data_url = CreateDataUrl(icon, title, text);
- Notification notif(origin, GURL(data_url), proxy);
+ Notification notif(
+ origin, GURL(data_url), DisplayNameForOrigin(origin), proxy);
ShowNotification(notif);
return true;
}
+
+std::wstring DesktopNotificationService::DisplayNameForOrigin(
+ const GURL& origin) {
+ // If the source is an extension, lookup the display name.
+ if (origin.SchemeIs(chrome::kExtensionScheme)) {
+ ExtensionsService* ext_service = profile_->GetExtensionsService();
+ if (ext_service) {
+ Extension* extension = ext_service->GetExtensionByURL(origin);
+ if (extension)
+ return ASCIIToWide(extension->name());
+ }
+ }
+ return UTF8ToWide(origin.spec());
+}

Powered by Google App Engine
This is Rietveld 408576698