summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications
diff options
context:
space:
mode:
authorjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 18:40:37 +0000
committerjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 18:40:37 +0000
commita1ec63a64fbb15d6ed20bc3fb856b48d3a5835e2 (patch)
treeca9ff360285a4d04498480b60e6a7a21850e5670 /chrome/browser/notifications
parent002c9bbb960f20bbb088fc716e3438d673750729 (diff)
downloadchromium_src-a1ec63a64fbb15d6ed20bc3fb856b48d3a5835e2.zip
chromium_src-a1ec63a64fbb15d6ed20bc3fb856b48d3a5835e2.tar.gz
chromium_src-a1ec63a64fbb15d6ed20bc3fb856b48d3a5835e2.tar.bz2
When extensions use notifications, display the name of the extension in UI rather than the "origin".
BUG=26961 TEST=test extension linked in the bug Review URL: http://codereview.chromium.org/385058 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31799 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications')
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc37
-rw-r--r--chrome/browser/notifications/desktop_notification_service.h5
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.cc2
-rw-r--r--chrome/browser/notifications/notification.h12
4 files changed, 50 insertions, 6 deletions
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index 2057f70..6410511 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -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 @@ class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
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 @@ class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
}
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 @@ class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
// 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 @@ void DesktopNotificationService::RequestPermission(
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 @@ bool DesktopNotificationService::CancelDesktopNotification(
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 @@ bool DesktopNotificationService::ShowDesktopNotification(
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 @@ bool DesktopNotificationService::ShowDesktopNotificationText(
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());
+}
diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h
index 86ad6d1..ad075e2 100644
--- a/chrome/browser/notifications/desktop_notification_service.h
+++ b/chrome/browser/notifications/desktop_notification_service.h
@@ -71,6 +71,11 @@ class DesktopNotificationService {
private:
void InitPrefs();
+ // Returns a display name for an origin, to be used in permission infobar
+ // or on the frame of the notification toast. Different from the origin
+ // itself when dealing with extensions.
+ std::wstring DisplayNameForOrigin(const GURL& origin);
+
// The profile which owns this object.
Profile* profile_;
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc
index 819e70f..868cb33 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/notifications/desktop_notifications_unittest.cc
@@ -32,6 +32,7 @@ void MockBalloonCollection::Add(const Notification& notification,
// balloon collection.
Notification test_notification(notification.origin_url(),
notification.content_url(),
+ notification.display_source(),
log_proxy_.get());
BalloonCollectionImpl::Add(test_notification, profile);
}
@@ -39,6 +40,7 @@ void MockBalloonCollection::Add(const Notification& notification,
bool MockBalloonCollection::Remove(const Notification& notification) {
Notification test_notification(notification.origin_url(),
notification.content_url(),
+ notification.display_source(),
log_proxy_.get());
return BalloonCollectionImpl::Remove(test_notification);
}
diff --git a/chrome/browser/notifications/notification.h b/chrome/browser/notifications/notification.h
index e7f46bd..f6472c7 100644
--- a/chrome/browser/notifications/notification.h
+++ b/chrome/browser/notifications/notification.h
@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
+#include <string>
+
#include "base/basictypes.h"
#include "chrome/browser/notifications/notification_object_proxy.h"
#include "googleurl/src/gurl.h"
@@ -15,15 +17,18 @@
class Notification {
public:
Notification(const GURL& origin_url, const GURL& content_url,
+ const std::wstring& display_source,
NotificationObjectProxy* proxy)
: origin_url_(origin_url),
content_url_(content_url),
+ display_source_(display_source),
proxy_(proxy) {
}
Notification(const Notification& notification)
: origin_url_(notification.origin_url()),
content_url_(notification.content_url()),
+ display_source_(notification.display_source()),
proxy_(notification.proxy()) {
}
@@ -33,6 +38,9 @@ class Notification {
// The origin URL of the script which requested the notification.
const GURL& origin_url() const { return origin_url_; }
+ // A display string for the source of the notification.
+ const std::wstring& display_source() const { return display_source_; }
+
void Display() const { proxy()->Display(); }
void Error() const { proxy()->Error(); }
void Close(bool by_user) const { proxy()->Close(by_user); }
@@ -51,6 +59,10 @@ class Notification {
// string-based notifications).
GURL content_url_;
+ // The display string for the source of the notification. Could be
+ // the same as origin_url_, or the name of an extension.
+ std::wstring display_source_;
+
// A proxy object that allows access back to the JavaScript object that
// represents the notification, for firing events.
scoped_refptr<NotificationObjectProxy> proxy_;