summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-26 18:56:17 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-26 18:56:17 +0000
commit9e9fff083f6742c63ba154f11d458866e99c6ed9 (patch)
tree844b3fe98800552e320c8775fbbf5d01e6dfb137 /chrome
parente2027b09db15ed5ecf0a481a006655ecd5fd097a (diff)
downloadchromium_src-9e9fff083f6742c63ba154f11d458866e99c6ed9.zip
chromium_src-9e9fff083f6742c63ba154f11d458866e99c6ed9.tar.gz
chromium_src-9e9fff083f6742c63ba154f11d458866e99c6ed9.tar.bz2
Adding sticky field to Notification
BUG=33306 TEST=modified and added new test (TestSticky) to DesktopNotificationsTest Review URL: http://codereview.chromium.org/661155 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40139 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc12
-rw-r--r--chrome/browser/notifications/desktop_notification_service.h9
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.cc49
-rw-r--r--chrome/browser/notifications/notification.h17
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc4
5 files changed, 66 insertions, 25 deletions
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index 3f1237b..8096379 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -332,20 +332,21 @@ bool DesktopNotificationService::CancelDesktopNotification(
scoped_refptr<NotificationObjectProxy> proxy(
new NotificationObjectProxy(process_id, route_id, notification_id,
false));
- Notification notif(GURL(), GURL(), L"", proxy);
+ Notification notif(GURL(), GURL(), L"", proxy, false);
return ui_manager_->Cancel(notif);
}
bool DesktopNotificationService::ShowDesktopNotification(
const GURL& origin, const GURL& url, int process_id, int route_id,
- DesktopNotificationSource source, int notification_id) {
+ DesktopNotificationSource source, int notification_id,
+ bool sticky) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
NotificationObjectProxy* proxy =
new NotificationObjectProxy(process_id, route_id,
notification_id,
source == WorkerNotification);
- Notification notif(origin, url, DisplayNameForOrigin(origin), proxy);
+ Notification notif(origin, url, DisplayNameForOrigin(origin), proxy, sticky);
ShowNotification(notif);
return true;
}
@@ -353,7 +354,8 @@ bool DesktopNotificationService::ShowDesktopNotification(
bool DesktopNotificationService::ShowDesktopNotificationText(
const GURL& origin, const GURL& icon, const string16& title,
const string16& text, int process_id, int route_id,
- DesktopNotificationSource source, int notification_id) {
+ DesktopNotificationSource source, int notification_id,
+ bool sticky) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
NotificationObjectProxy* proxy =
new NotificationObjectProxy(process_id, route_id,
@@ -362,7 +364,7 @@ bool DesktopNotificationService::ShowDesktopNotificationText(
// "upconvert" the string parameters to a data: URL.
string16 data_url = CreateDataUrl(icon, title, text);
Notification notif(
- origin, GURL(data_url), DisplayNameForOrigin(origin), proxy);
+ origin, GURL(data_url), DisplayNameForOrigin(origin), proxy, sticky);
ShowNotification(notif);
return true;
}
diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h
index b384a79..b1050c9 100644
--- a/chrome/browser/notifications/desktop_notification_service.h
+++ b/chrome/browser/notifications/desktop_notification_service.h
@@ -49,13 +49,16 @@ class DesktopNotificationService : public NotificationObserver {
// is the origin of the script. |source| indicates whether the
// script is in a worker or page. |notification_id| is an opaque
// value to be passed back to the process when events occur on
- // this notification.
+ // this notification. |sticky| is used to indicate that the notification
+ // is sticky and cannot be dismissed by a user.
bool ShowDesktopNotification(const GURL& origin, const GURL& url,
int process_id, int route_id, DesktopNotificationSource source,
- int notification_id);
+ int notification_id,
+ bool sticky);
bool ShowDesktopNotificationText(const GURL& origin, const GURL& icon,
const string16& title, const string16& text, int process_id,
- int route_id, DesktopNotificationSource source, int notification_id);
+ int route_id, DesktopNotificationSource source, int notification_id,
+ bool sticky);
// Cancels a notification. If it has already been shown, it will be
// removed from the screen. If it hasn't been shown yet, it won't be
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc
index 186dd5f..04b0931 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/notifications/desktop_notifications_unittest.cc
@@ -33,7 +33,8 @@ void MockBalloonCollection::Add(const Notification& notification,
Notification test_notification(notification.origin_url(),
notification.content_url(),
notification.display_source(),
- log_proxy_.get());
+ log_proxy_.get(),
+ notification.sticky());
BalloonCollectionImpl::Add(test_notification, profile);
}
@@ -41,7 +42,8 @@ bool MockBalloonCollection::Remove(const Notification& notification) {
Notification test_notification(notification.origin_url(),
notification.content_url(),
notification.display_source(),
- log_proxy_.get());
+ log_proxy_.get(),
+ notification.sticky());
return BalloonCollectionImpl::Remove(test_notification);
}
@@ -97,20 +99,25 @@ TEST_F(DesktopNotificationsTest, TestShow) {
EXPECT_TRUE(service_->ShowDesktopNotificationText(
GURL("http://www.google.com"),
GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"),
- 0, 0, DesktopNotificationService::PageNotification, 1));
+ 0, 0, DesktopNotificationService::PageNotification, 1, false));
MessageLoopForUI::current()->RunAllPending();
EXPECT_EQ(1, balloon_collection_->count());
EXPECT_TRUE(service_->ShowDesktopNotification(
GURL("http://www.google.com"),
GURL("http://www.google.com/notification.html"),
- 0, 0, DesktopNotificationService::PageNotification, 2));
+ 0, 0, DesktopNotificationService::PageNotification, 2, false));
MessageLoopForUI::current()->RunAllPending();
EXPECT_EQ(2, balloon_collection_->count());
EXPECT_EQ("notification displayed\n"
"notification displayed\n",
log_output_);
+
+ std::set<Balloon*>::iterator iter = balloon_collection_->balloons().begin();
+ EXPECT_FALSE((*iter)->notification().sticky());
+ iter++;
+ EXPECT_FALSE((*iter)->notification().sticky());
}
TEST_F(DesktopNotificationsTest, TestClose) {
@@ -118,7 +125,7 @@ TEST_F(DesktopNotificationsTest, TestClose) {
EXPECT_TRUE(service_->ShowDesktopNotificationText(
GURL("http://www.google.com"),
GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"),
- 0, 0, DesktopNotificationService::PageNotification, 1));
+ 0, 0, DesktopNotificationService::PageNotification, 1, false));
MessageLoopForUI::current()->RunAllPending();
EXPECT_EQ(1, balloon_collection_->count());
@@ -146,7 +153,7 @@ TEST_F(DesktopNotificationsTest, TestCancel) {
GURL("http://www.google.com"),
GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"),
process_id, route_id, DesktopNotificationService::PageNotification,
- notification_id));
+ notification_id, false));
MessageLoopForUI::current()->RunAllPending();
EXPECT_EQ(1, balloon_collection_->count());
@@ -173,7 +180,7 @@ TEST_F(DesktopNotificationsTest, TestPositioning) {
EXPECT_TRUE(service_->ShowDesktopNotificationText(
GURL("http://www.google.com"),
GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"),
- 0, 0, DesktopNotificationService::PageNotification, id));
+ 0, 0, DesktopNotificationService::PageNotification, id, false));
expected_log.append("notification displayed\n");
int top = balloon_collection_->UppermostVerticalPosition();
if (id > 0)
@@ -194,12 +201,12 @@ TEST_F(DesktopNotificationsTest, TestVariableSize) {
"Really Really Really Really Really Really "
"Really Really Really Really Really Really Really Long Title"),
ASCIIToUTF16("Text"),
- 0, 0, DesktopNotificationService::PageNotification, 0));
+ 0, 0, DesktopNotificationService::PageNotification, 0, false));
expected_log.append("notification displayed\n");
EXPECT_TRUE(service_->ShowDesktopNotificationText(
GURL("http://short.google.com"), GURL("/icon.png"),
ASCIIToUTF16("Short title"), ASCIIToUTF16("Text"),
- 0, 0, DesktopNotificationService::PageNotification, 1));
+ 0, 0, DesktopNotificationService::PageNotification, 1, false));
expected_log.append("notification displayed\n");
std::set<Balloon*>& balloons = balloon_collection_->balloons();
@@ -230,7 +237,7 @@ TEST_F(DesktopNotificationsTest, TestQueueing) {
GURL("http://www.google.com"),
GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"),
process_id, route_id,
- DesktopNotificationService::PageNotification, id));
+ DesktopNotificationService::PageNotification, id, false));
}
MessageLoopForUI::current()->RunAllPending();
@@ -280,7 +287,7 @@ TEST_F(DesktopNotificationsTest, TestEarlyDestruction) {
EXPECT_TRUE(service_->ShowDesktopNotificationText(
GURL("http://www.google.com"),
GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"),
- 0, 0, DesktopNotificationService::PageNotification, id));
+ 0, 0, DesktopNotificationService::PageNotification, id, false));
}
service_.reset(NULL);
}
@@ -293,7 +300,7 @@ TEST_F(DesktopNotificationsTest, TestUserInputEscaping) {
GURL("/icon.png"),
ASCIIToUTF16("<script>window.alert('uh oh');</script>"),
ASCIIToUTF16("<i>this text is in italics</i>"),
- 0, 0, DesktopNotificationService::PageNotification, 1));
+ 0, 0, DesktopNotificationService::PageNotification, 1, false));
MessageLoopForUI::current()->RunAllPending();
EXPECT_EQ(1, balloon_collection_->count());
@@ -302,3 +309,21 @@ TEST_F(DesktopNotificationsTest, TestUserInputEscaping) {
EXPECT_EQ(std::string::npos, data_url.spec().find("<script>"));
EXPECT_EQ(std::string::npos, data_url.spec().find("<i>"));
}
+
+TEST_F(DesktopNotificationsTest, TestSticky) {
+ EXPECT_TRUE(service_->ShowDesktopNotificationText(
+ GURL("http://www.google.com"),
+ GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"),
+ 0, 0, DesktopNotificationService::PageNotification, 1, true));
+ MessageLoopForUI::current()->RunAllPending();
+ EXPECT_TRUE(service_->ShowDesktopNotification(
+ GURL("http://www.google.com"),
+ GURL("http://www.google.com/notification.html"),
+ 0, 0, DesktopNotificationService::PageNotification, 2, true));
+ MessageLoopForUI::current()->RunAllPending();
+
+ std::set<Balloon*>::iterator iter = balloon_collection_->balloons().begin();
+ EXPECT_TRUE((*iter)->notification().sticky());
+ iter++;
+ EXPECT_TRUE((*iter)->notification().sticky());
+}
diff --git a/chrome/browser/notifications/notification.h b/chrome/browser/notifications/notification.h
index f6472c7..f80a65f 100644
--- a/chrome/browser/notifications/notification.h
+++ b/chrome/browser/notifications/notification.h
@@ -18,18 +18,21 @@ class Notification {
public:
Notification(const GURL& origin_url, const GURL& content_url,
const std::wstring& display_source,
- NotificationObjectProxy* proxy)
+ NotificationObjectProxy* proxy,
+ bool sticky)
: origin_url_(origin_url),
content_url_(content_url),
display_source_(display_source),
- proxy_(proxy) {
+ proxy_(proxy),
+ sticky_(sticky) {
}
Notification(const Notification& notification)
: origin_url_(notification.origin_url()),
content_url_(notification.content_url()),
display_source_(notification.display_source()),
- proxy_(notification.proxy()) {
+ proxy_(notification.proxy()),
+ sticky_(notification.sticky()) {
}
// The URL (may be data:) containing the contents for the notification.
@@ -45,6 +48,10 @@ class Notification {
void Error() const { proxy()->Error(); }
void Close(bool by_user) const { proxy()->Close(by_user); }
+ bool sticky() const {
+ return sticky_;
+ }
+
bool IsSame(const Notification& other) const {
return (*proxy_).IsSame(*(other.proxy()));
}
@@ -67,6 +74,10 @@ class Notification {
// represents the notification, for firing events.
scoped_refptr<NotificationObjectProxy> proxy_;
+ // A sticky flag. A sticky notification cannot be dismissed by a
+ // user.
+ bool sticky_;
+
// Disallow assign. Copy constructor written above.
void operator=(const Notification&);
};
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 939bdce..c6f673a 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -1710,7 +1710,7 @@ void RenderViewHost::OnShowDesktopNotification(const GURL& source_origin,
process()->profile()->GetDesktopNotificationService();
service->ShowDesktopNotification(source_origin, url, process()->id(),
routing_id(), DesktopNotificationService::PageNotification,
- notification_id);
+ notification_id, false);
}
void RenderViewHost::OnShowDesktopNotificationText(const GURL& source_origin,
@@ -1720,7 +1720,7 @@ void RenderViewHost::OnShowDesktopNotificationText(const GURL& source_origin,
process()->profile()->GetDesktopNotificationService();
service->ShowDesktopNotificationText(source_origin, icon, title, text,
process()->id(), routing_id(),
- DesktopNotificationService::PageNotification, notification_id);
+ DesktopNotificationService::PageNotification, notification_id, false);
}
void RenderViewHost::OnCancelDesktopNotification(int notification_id) {