summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-17 22:38:22 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-17 22:38:22 +0000
commit1979453de9770526bf4b6f8b7adab57f5e4b2de6 (patch)
tree7184ebd0469112854dd17a682e6e76f65c468b08
parent539ee3e4239962f775f0c7e42bc4816642eae671 (diff)
downloadchromium_src-1979453de9770526bf4b6f8b7adab57f5e4b2de6.zip
chromium_src-1979453de9770526bf4b6f8b7adab57f5e4b2de6.tar.gz
chromium_src-1979453de9770526bf4b6f8b7adab57f5e4b2de6.tar.bz2
Implement chromeos SystemNotification on Aura by introducing BalloonCollectionImplAura.
BUG=98331 TEST=Test system notifications (failed network connect, low battery) on ChromeOS Aura. Review URL: http://codereview.chromium.org/9187043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117984 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/cros_stubs_aura.cc77
-rw-r--r--chrome/browser/chromeos/extensions/file_browser_notifications.cc6
-rw-r--r--chrome/browser/chromeos/extensions/file_browser_notifications.h5
-rw-r--r--chrome/browser/chromeos/notifications/balloon_collection_impl.cc20
-rw-r--r--chrome/browser/chromeos/notifications/balloon_collection_impl.h19
-rw-r--r--chrome/browser/chromeos/notifications/balloon_collection_impl_aura.cc72
-rw-r--r--chrome/browser/chromeos/notifications/balloon_collection_impl_aura.h65
-rw-r--r--chrome/browser/chromeos/notifications/balloon_view_host.h6
-rw-r--r--chrome/browser/chromeos/notifications/desktop_notifications_unittest.cc78
-rw-r--r--chrome/browser/chromeos/notifications/desktop_notifications_unittest.h31
-rw-r--r--chrome/browser/chromeos/notifications/notification_browsertest.cc15
-rw-r--r--chrome/browser/chromeos/notifications/system_notification.cc27
-rw-r--r--chrome/browser/chromeos/notifications/system_notification.h13
-rw-r--r--chrome/browser/chromeos/notifications/system_notification_browsertest.cc154
-rw-r--r--chrome/browser/notifications/balloon_collection_base.cc9
-rw-r--r--chrome/browser/notifications/balloon_collection_base.h4
-rw-r--r--chrome/browser/notifications/balloon_collection_impl.cc12
-rw-r--r--chrome/browser/notifications/balloon_collection_impl.h19
-rw-r--r--chrome/browser/notifications/balloon_collection_views.cc4
-rw-r--r--chrome/browser/notifications/notification_options_menu_model.cc12
-rw-r--r--chrome/browser/ui/views/notifications/balloon_view.cc19
-rw-r--r--chrome/browser/ui/views/notifications/balloon_view.h7
-rw-r--r--chrome/chrome_browser.gypi11
-rw-r--r--chrome/chrome_tests.gypi10
24 files changed, 493 insertions, 202 deletions
diff --git a/chrome/browser/chromeos/cros_stubs_aura.cc b/chrome/browser/chromeos/cros_stubs_aura.cc
deleted file mode 100644
index d4039d6..0000000
--- a/chrome/browser/chromeos/cros_stubs_aura.cc
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/chromeos/notifications/system_notification.h"
-#include "chrome/browser/notifications/balloon_collection.h"
-
-namespace chromeos {
-
-////////////////////////////////////////////////////////////////////////////////
-// SystemNotification
-
-void SystemNotification::Init(int icon_resource_id) {
- NOTIMPLEMENTED();
-}
-
-SystemNotification::SystemNotification(Profile* profile,
- NotificationDelegate* delegate,
- int icon_resource_id,
- const string16& title)
- : profile_(profile),
- collection_(NULL),
- delegate_(delegate),
- title_(title),
- visible_(false),
- urgent_(false) {
- NOTIMPLEMENTED();
-}
-
-SystemNotification::SystemNotification(Profile* profile,
- const std::string& id,
- int icon_resource_id,
- const string16& title)
- : profile_(profile),
- collection_(NULL),
- delegate_(new Delegate(id)),
- title_(title),
- visible_(false),
- urgent_(false) {
- NOTIMPLEMENTED();
-}
-
-SystemNotification::~SystemNotification() {
-}
-
-void SystemNotification::Show(const string16& message,
- bool urgent,
- bool sticky) {
- NOTIMPLEMENTED() << " " << message;
-}
-
-void SystemNotification::Show(const string16& message,
- const string16& link,
- const MessageCallback& callback,
- bool urgent,
- bool sticky) {
- NOTIMPLEMENTED();
-}
-
-void SystemNotification::Hide() {
- NOTIMPLEMENTED();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// SystemNotification::Delegate
-
-SystemNotification::Delegate::Delegate(const std::string& id)
- : id_(id) {
- NOTIMPLEMENTED();
-}
-
-std::string SystemNotification::Delegate::id() const {
- NOTIMPLEMENTED();
- return id_;
-}
-
-} // namespace chromeos
diff --git a/chrome/browser/chromeos/extensions/file_browser_notifications.cc b/chrome/browser/chromeos/extensions/file_browser_notifications.cc
index 1a5ed13..38ea6ad 100644
--- a/chrome/browser/chromeos/extensions/file_browser_notifications.cc
+++ b/chrome/browser/chromeos/extensions/file_browser_notifications.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -307,7 +307,7 @@ const string16& FileBrowserNotifications::GetLinkText() {
return link_text_;
}
-chromeos::MessageCallback FileBrowserNotifications::GetLinkCallback() {
+chromeos::BalloonViewHost::MessageCallback
+FileBrowserNotifications::GetLinkCallback() {
return base::Bind(&FileBrowserNotifications::OnLinkClicked, AsWeakPtr());
}
-
diff --git a/chrome/browser/chromeos/extensions/file_browser_notifications.h b/chrome/browser/chromeos/extensions/file_browser_notifications.h
index 889c437..96d943e 100644
--- a/chrome/browser/chromeos/extensions/file_browser_notifications.h
+++ b/chrome/browser/chromeos/extensions/file_browser_notifications.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -110,7 +110,7 @@ class FileBrowserNotifications
void OnLinkClicked(const base::ListValue* arg);
bool HasMoreInfoLink(NotificationType type);
const string16& GetLinkText();
- chromeos::MessageCallback GetLinkCallback();
+ chromeos::BalloonViewHost::MessageCallback GetLinkCallback();
string16 link_text_;
NotificationMap notifications_;
@@ -121,4 +121,3 @@ class FileBrowserNotifications
};
#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_NOTIFICATIONS_H_
-
diff --git a/chrome/browser/chromeos/notifications/balloon_collection_impl.cc b/chrome/browser/chromeos/notifications/balloon_collection_impl.cc
index eb8d8aa..deba6fa 100644
--- a/chrome/browser/chromeos/notifications/balloon_collection_impl.cc
+++ b/chrome/browser/chromeos/notifications/balloon_collection_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -40,7 +40,7 @@ BalloonCollectionImpl::~BalloonCollectionImpl() {
void BalloonCollectionImpl::Add(const Notification& notification,
Profile* profile) {
Balloon* new_balloon = MakeBalloon(notification, profile);
- base_.Add(new_balloon);
+ base_.Add(new_balloon, false);
new_balloon->Show();
notification_ui_->Add(new_balloon);
@@ -56,7 +56,7 @@ void BalloonCollectionImpl::Add(const Notification& notification,
bool BalloonCollectionImpl::AddWebUIMessageCallback(
const Notification& notification,
const std::string& message,
- const MessageCallback& callback) {
+ const BalloonViewHost::MessageCallback& callback) {
Balloon* balloon = FindBalloon(notification);
if (!balloon)
return false;
@@ -66,16 +66,16 @@ bool BalloonCollectionImpl::AddWebUIMessageCallback(
return host->AddWebUIMessageCallback(message, callback);
}
+// Called from SystemNotification::Show for system notifications.
void BalloonCollectionImpl::AddSystemNotification(
const Notification& notification,
Profile* profile,
- bool sticky,
- bool control) {
-
+ bool sticky) {
Balloon* new_balloon = new Balloon(notification, profile, this);
new_balloon->set_view(
- new chromeos::BalloonViewImpl(sticky, control, true));
- base_.Add(new_balloon);
+ new chromeos::BalloonViewImpl(
+ sticky, false /*no controls*/, true /*enable webui*/));
+ base_.Add(new_balloon, false);
new_balloon->Show();
notification_ui_->Add(new_balloon);
@@ -167,10 +167,12 @@ void BalloonCollectionImpl::Shutdown() {
notification_ui_.reset();
}
+// Called from BalloonCollectionImpl::Add for non system notifications.
Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
Profile* profile) {
Balloon* new_balloon = new Balloon(notification, profile, this);
- new_balloon->set_view(new chromeos::BalloonViewImpl(false, true, false));
+ new_balloon->set_view(new chromeos::BalloonViewImpl(
+ false /*not sticky*/, true /*has controls*/, false /*no web ui*/));
return new_balloon;
}
diff --git a/chrome/browser/chromeos/notifications/balloon_collection_impl.h b/chrome/browser/chromeos/notifications/balloon_collection_impl.h
index 94e8c2c..aacc238 100644
--- a/chrome/browser/chromeos/notifications/balloon_collection_impl.h
+++ b/chrome/browser/chromeos/notifications/balloon_collection_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -81,16 +81,17 @@ class BalloonCollectionImpl : public BalloonCollection,
// there is no notification that matches NotificationDelegate::id(),
// or a callback for given message already exists. The callback
// object is owned and deleted by callee.
- bool AddWebUIMessageCallback(const Notification& notification,
- const std::string& message,
- const MessageCallback& callback);
+ bool AddWebUIMessageCallback(
+ const Notification& notification,
+ const std::string& message,
+ const BalloonViewHost::MessageCallback& callback);
// Adds new system notification.
// |sticky| is used to indicate that the notification
- // is sticky and cannot be dismissed by a user. |controls| turns on/off
- // info label and option/dismiss buttons.
+ // is sticky and cannot be dismissed by a user.
void AddSystemNotification(const Notification& notification,
- Profile* profile, bool sticky, bool controls);
+ Profile* profile,
+ bool sticky);
// Updates the notification's content. It uses
// NotificationDelegate::id() to check the equality of notifications.
@@ -104,6 +105,10 @@ class BalloonCollectionImpl : public BalloonCollection,
// the updated notification is visible.
bool UpdateAndShowNotification(const Notification& notification);
+ // base_ is embedded, so this is a simple accessor for the number of
+ // balloons in the collection.
+ int count() const { return base_.count(); }
+
// Injects notification ui. Used to inject a mock implementation in tests.
void set_notification_ui(NotificationUI* ui) {
notification_ui_.reset(ui);
diff --git a/chrome/browser/chromeos/notifications/balloon_collection_impl_aura.cc b/chrome/browser/chromeos/notifications/balloon_collection_impl_aura.cc
new file mode 100644
index 0000000..b4a402c
--- /dev/null
+++ b/chrome/browser/chromeos/notifications/balloon_collection_impl_aura.cc
@@ -0,0 +1,72 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/notifications/balloon_collection_impl_aura.h"
+
+#include "chrome/browser/notifications/balloon.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/ui/views/notifications/balloon_view.h"
+#include "chrome/browser/ui/views/notifications/balloon_view_host.h"
+
+namespace chromeos {
+
+bool BalloonCollectionImplAura::AddWebUIMessageCallback(
+ const Notification& notification,
+ const std::string& message,
+ const BalloonViewHost::MessageCallback& callback) {
+ Balloon* balloon = base().FindBalloon(notification);
+ if (!balloon)
+ return false;
+
+ BalloonViewHost* host =
+ static_cast<chromeos::BalloonViewHost*>(balloon->view()->GetHost());
+ return host->AddWebUIMessageCallback(message, callback);
+}
+
+void BalloonCollectionImplAura::AddSystemNotification(
+ const Notification& notification,
+ Profile* profile,
+ bool sticky) {
+ system_notifications_.insert(notification.notification_id());
+
+ // Add balloons to the front of the stack. This ensures that system
+ // notifications will always be displayed. NOTE: This has the side effect
+ // that system notifications are displayed in inverse order, with the most
+ // recent notification always at the front of the list.
+ AddImpl(notification, profile, true /* add to front*/);
+}
+
+bool BalloonCollectionImplAura::UpdateNotification(
+ const Notification& notification) {
+ Balloon* balloon = base().FindBalloon(notification);
+ if (!balloon)
+ return false;
+ balloon->Update(notification);
+ return true;
+}
+
+bool BalloonCollectionImplAura::UpdateAndShowNotification(
+ const Notification& notification) {
+ return UpdateNotification(notification);
+}
+
+Balloon* BalloonCollectionImplAura::MakeBalloon(
+ const Notification& notification, Profile* profile) {
+ Balloon* balloon = new Balloon(notification, profile, this);
+ ::BalloonViewImpl* balloon_view = new ::BalloonViewImpl(this);
+ if (system_notifications_.find(notification.notification_id()) !=
+ system_notifications_.end())
+ balloon_view->set_enable_web_ui(true);
+ balloon->set_view(balloon_view);
+ gfx::Size size(layout().min_balloon_width(), layout().min_balloon_height());
+ balloon->set_content_size(size);
+ return balloon;
+}
+
+} // namespace chromeos
+
+// static
+BalloonCollection* BalloonCollection::Create() {
+ return new chromeos::BalloonCollectionImplAura();
+}
diff --git a/chrome/browser/chromeos/notifications/balloon_collection_impl_aura.h b/chrome/browser/chromeos/notifications/balloon_collection_impl_aura.h
new file mode 100644
index 0000000..65d76a1
--- /dev/null
+++ b/chrome/browser/chromeos/notifications/balloon_collection_impl_aura.h
@@ -0,0 +1,65 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_AURA_H_
+#define CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_AURA_H_
+#pragma once
+
+#include <set>
+
+#include "chrome/browser/chromeos/notifications/balloon_view_host.h" // MessageCallback
+#include "chrome/browser/notifications/balloon_collection_impl.h"
+
+namespace chromeos {
+
+// Wrapper on top of ::BalloonCollectionImpl to provide an interface for
+// chromeos::SystemNotification.
+class BalloonCollectionImplAura : public ::BalloonCollectionImpl {
+ public:
+ BalloonCollectionImplAura() {}
+
+ // Adds a callback for WebUI message. Returns true if the callback
+ // is succssfully registered, or false otherwise. It fails to add if
+ // there is no notification that matches NotificationDelegate::id(),
+ // or a callback for given message already exists. The callback
+ // object is owned and deleted by callee.
+ bool AddWebUIMessageCallback(
+ const Notification& notification,
+ const std::string& message,
+ const BalloonViewHost::MessageCallback& callback);
+
+ // Adds a new system notification.
+ // |sticky| is ignored in the Aura implementation; desktop notifications
+ // are always sticky (i.e. they need to be dismissed explicitly).
+ void AddSystemNotification(const Notification& notification,
+ Profile* profile,
+ bool sticky);
+
+ // Updates the notification's content. It uses
+ // NotificationDelegate::id() to check the equality of notifications.
+ // Returns true if the notification has been updated. False if
+ // no corresponding notification is found. This will not change the
+ // visibility of the notification.
+ bool UpdateNotification(const Notification& notification);
+
+ // On Aura this behaves the same as UpdateNotification.
+ bool UpdateAndShowNotification(const Notification& notification);
+
+ protected:
+ // Creates a new balloon. Overridable by unit tests. The caller is
+ // responsible for freeing the pointer returned.
+ virtual Balloon* MakeBalloon(const Notification& notification,
+ Profile* profile);
+
+ private:
+ // Set of unique ids associated with system notifications, used by
+ // MakeBalloon to determine whether or not to enable Web UI.
+ std::set<std::string> system_notifications_;
+
+ DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImplAura);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_AURA_H_
diff --git a/chrome/browser/chromeos/notifications/balloon_view_host.h b/chrome/browser/chromeos/notifications/balloon_view_host.h
index 19fca89..3571df6 100644
--- a/chrome/browser/chromeos/notifications/balloon_view_host.h
+++ b/chrome/browser/chromeos/notifications/balloon_view_host.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -23,10 +23,10 @@ class ListValue;
namespace chromeos {
-typedef base::Callback<void(const base::ListValue*)> MessageCallback;
-
class BalloonViewHost : public ::BalloonViewHost {
public:
+ typedef base::Callback<void(const base::ListValue*)> MessageCallback;
+
explicit BalloonViewHost(Balloon* balloon);
virtual ~BalloonViewHost();
diff --git a/chrome/browser/chromeos/notifications/desktop_notifications_unittest.cc b/chrome/browser/chromeos/notifications/desktop_notifications_unittest.cc
index 90625bb..bd2e9e6 100644
--- a/chrome/browser/chromeos/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/chromeos/notifications/desktop_notifications_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,6 +10,19 @@
#include "chrome/browser/prefs/pref_service.h"
#include "content/public/common/show_desktop_notification_params.h"
+#if defined(USE_AURA)
+#include "chrome/browser/chromeos/notifications/balloon_collection_impl_aura.h"
+#include "ui/aura/root_window.h"
+#else
+#include "chrome/browser/chromeos/notifications/balloon_collection_impl.h"
+#endif
+
+#if defined(USE_AURA)
+typedef class chromeos::BalloonCollectionImplAura BalloonCollectionImplType;
+#else
+typedef class chromeos::BalloonCollectionImpl BalloonCollectionImplType;
+#endif
+
using content::BrowserThread;
namespace chromeos {
@@ -17,7 +30,10 @@ namespace chromeos {
// static
std::string DesktopNotificationsTest::log_output_;
-class MockNotificationUI : public BalloonCollectionImpl::NotificationUI {
+class BalloonViewImpl;
+
+#if !defined(USE_AURA)
+class MockNotificationUI : public BalloonCollectionImplType::NotificationUI {
public:
virtual void Add(Balloon* balloon) {}
virtual bool Update(Balloon* balloon) { return false; }
@@ -27,31 +43,54 @@ class MockNotificationUI : public BalloonCollectionImpl::NotificationUI {
const gfx::Size& size) {}
virtual void SetActiveView(BalloonViewImpl* view) {}
};
+#endif
-MockBalloonCollection::MockBalloonCollection() {
- set_notification_ui(new MockNotificationUI());
-}
+// Test version of the balloon collection which counts the number
+// of notifications that are added to it.
+class MockBalloonCollection : public BalloonCollectionImplType {
+ public:
+ MockBalloonCollection() {
+#if !defined(USE_AURA)
+ set_notification_ui(new MockNotificationUI());
+#endif
+ }
+ virtual ~MockBalloonCollection() {};
-MockBalloonCollection::~MockBalloonCollection() {}
+ // BalloonCollectionImplType overrides
+ virtual void Add(const Notification& notification, Profile* profile) OVERRIDE;
+ virtual Balloon* MakeBalloon(const Notification& notification,
+ Profile* profile) OVERRIDE;
+ virtual void OnBalloonClosed(Balloon* source) OVERRIDE;
+
+ // Number of balloons being shown.
+ std::set<Balloon*>& balloons() { return balloons_; }
+ int count() const { return balloons_.size(); }
+
+ private:
+ std::set<Balloon*> balloons_;
+};
void MockBalloonCollection::Add(const Notification& notification,
Profile* profile) {
// Swap in a logging proxy for the purpose of logging calls that
// would be made into javascript, then pass this down to the
// balloon collection.
+ typedef LoggingNotificationDelegate<DesktopNotificationsTest>
+ LoggingNotificationProxy;
Notification test_notification(
notification.origin_url(),
notification.content_url(),
notification.display_source(),
notification.replace_id(),
new LoggingNotificationProxy(notification.notification_id()));
- BalloonCollectionImpl::Add(test_notification, profile);
+ BalloonCollectionImplType::Add(test_notification, profile);
}
Balloon* MockBalloonCollection::MakeBalloon(const Notification& notification,
Profile* profile) {
// Start with a normal balloon but mock out the view.
- Balloon* balloon = BalloonCollectionImpl::MakeBalloon(notification, profile);
+ Balloon* balloon =
+ BalloonCollectionImplType::MakeBalloon(notification, profile);
balloon->set_view(new MockBalloonView(balloon));
balloons_.insert(balloon);
return balloon;
@@ -59,19 +98,10 @@ Balloon* MockBalloonCollection::MakeBalloon(const Notification& notification,
void MockBalloonCollection::OnBalloonClosed(Balloon* source) {
balloons_.erase(source);
- BalloonCollectionImpl::OnBalloonClosed(source);
+ BalloonCollectionImplType::OnBalloonClosed(source);
}
-int MockBalloonCollection::UppermostVerticalPosition() {
- int min = 0;
- std::set<Balloon*>::iterator iter;
- for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) {
- int pos = (*iter)->GetPosition().y();
- if (iter == balloons_.begin() || pos < min)
- min = pos;
- }
- return min;
-}
+// DesktopNotificationsTest
DesktopNotificationsTest::DesktopNotificationsTest()
: ui_thread_(BrowserThread::UI, &message_loop_) {
@@ -81,6 +111,10 @@ DesktopNotificationsTest::~DesktopNotificationsTest() {
}
void DesktopNotificationsTest::SetUp() {
+#if defined(USE_AURA)
+ // Make sure a root window has been instantiated.
+ aura::RootWindow::GetInstance();
+#endif
browser::RegisterLocalState(&local_state_);
profile_.reset(new TestingProfile());
balloon_collection_ = new MockBalloonCollection();
@@ -195,7 +229,13 @@ TEST_F(DesktopNotificationsTest, TestManyNotifications) {
int route_id = 0;
// Request lots of identical notifications.
+#if defined(USE_AURA)
+ // Aura is using the non-chromeos notification system which has a limit
+ // of 4 visible toasts.
+ const int kLotsOfToasts = 4;
+#else
const int kLotsOfToasts = 20;
+#endif
for (int id = 1; id <= kLotsOfToasts; ++id) {
SCOPED_TRACE(base::StringPrintf("Creation loop: id=%d", id));
content::ShowDesktopNotificationHostMsgParams params =
diff --git a/chrome/browser/chromeos/notifications/desktop_notifications_unittest.h b/chrome/browser/chromeos/notifications/desktop_notifications_unittest.h
index 69c4464..e63d408 100644
--- a/chrome/browser/chromeos/notifications/desktop_notifications_unittest.h
+++ b/chrome/browser/chromeos/notifications/desktop_notifications_unittest.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,7 +13,6 @@
#include "base/message_loop.h"
#include "base/string_util.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
-#include "chrome/browser/chromeos/notifications/balloon_collection_impl.h"
#include "chrome/browser/notifications/balloon.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/notifications/notification.h"
@@ -32,33 +31,7 @@ struct ShowDesktopNotificationHostMsgParams;
namespace chromeos {
class DesktopNotificationsTest;
-typedef LoggingNotificationDelegate<DesktopNotificationsTest>
- LoggingNotificationProxy;
-
-// Test version of the balloon collection which counts the number
-// of notifications that are added to it.
-class MockBalloonCollection : public BalloonCollectionImpl {
- public:
- MockBalloonCollection();
- virtual ~MockBalloonCollection();
-
- // BalloonCollectionImpl overrides
- virtual void Add(const Notification& notification,
- Profile* profile) OVERRIDE;
- virtual Balloon* MakeBalloon(const Notification& notification,
- Profile* profile) OVERRIDE;
- virtual void OnBalloonClosed(Balloon* source) OVERRIDE;
-
- // Number of balloons being shown.
- std::set<Balloon*>& balloons() { return balloons_; }
- int count() const { return balloons_.size(); }
-
- // Returns the highest y-coordinate of all the balloons in the collection.
- int UppermostVerticalPosition();
-
- private:
- std::set<Balloon*> balloons_;
-};
+class MockBalloonCollection;
class DesktopNotificationsTest : public testing::Test {
public:
diff --git a/chrome/browser/chromeos/notifications/notification_browsertest.cc b/chrome/browser/chromeos/notifications/notification_browsertest.cc
index 08124ee..1d2a417 100644
--- a/chrome/browser/chromeos/notifications/notification_browsertest.cc
+++ b/chrome/browser/chromeos/notifications/notification_browsertest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -226,7 +226,7 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, TestSystemNotification) {
NotificationPanelTester* tester = panel->GetTester();
Notification notify = NewMockNotification(delegate.get());
- collection->AddSystemNotification(notify, browser()->profile(), true, false);
+ collection->AddSystemNotification(notify, browser()->profile(), true);
EXPECT_EQ(1, tester->GetNewNotificationCount());
EXPECT_EQ(1, tester->GetStickyNotificationCount());
@@ -331,7 +331,7 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition2) {
// The panel must be expanded again when a new system notification is added.
collection->AddSystemNotification(
- NewMockNotification("3"), browser()->profile(), true, false);
+ NewMockNotification("3"), browser()->profile(), true);
EXPECT_EQ(3, tester->GetNotificationCount());
EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
WaitForPanelState(tester, PanelController::EXPANDED);
@@ -433,7 +433,7 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, DISABLED_TestScrollBalloonToVisible) {
SCOPED_TRACE(base::StringPrintf("new system %d", i));
std::string id = base::StringPrintf("s%d", i);
collection->AddSystemNotification(
- NewMockNotification(id), browser()->profile(), true, false);
+ NewMockNotification(id), browser()->profile(), true);
BalloonViewImpl* view =
tester->GetBalloonView(collection, NewMockNotification(id));
WaitForVisible(view);
@@ -493,7 +493,7 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, FLAKY_TestActivateDeactivate) {
collection->Add(NewMockNotification("1"), profile);
collection->AddSystemNotification(
- NewMockNotification("2"), profile, true, false);
+ NewMockNotification("2"), profile, true);
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
BalloonViewImpl* view1 =
@@ -526,7 +526,7 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, TestCloseDismissAllNonSticky) {
collection->Add(NewMockNotification("1"), profile);
collection->AddSystemNotification(
- NewMockNotification("2"), profile, true, false);
+ NewMockNotification("2"), profile, true);
collection->Add(NewMockNotification("3"), profile);
ui_test_utils::RunAllPendingInMessageLoop();
@@ -546,7 +546,7 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, TestAddWebUIMessageCallback) {
Profile* profile = browser()->profile();
collection->AddSystemNotification(
- NewMockNotification("1"), profile, false, false);
+ NewMockNotification("1"), profile, false);
EXPECT_TRUE(collection->AddWebUIMessageCallback(
NewMockNotification("1"),
@@ -582,7 +582,6 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, TestWebUIMessageCallback) {
Notification(GURL(), content_url, string16(), string16(),
new MockNotificationDelegate("1")),
profile,
- false,
false);
EXPECT_TRUE(collection->AddWebUIMessageCallback(
NewMockNotification("1"),
diff --git a/chrome/browser/chromeos/notifications/system_notification.cc b/chrome/browser/chromeos/notifications/system_notification.cc
index 5196fa8..8127402 100644
--- a/chrome/browser/chromeos/notifications/system_notification.cc
+++ b/chrome/browser/chromeos/notifications/system_notification.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,17 +6,22 @@
#include "base/callback.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chromeos/notifications/balloon_collection_impl.h"
#include "chrome/browser/chromeos/notifications/system_notification_factory.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/ui/webui/web_ui_util.h"
+#if defined(USE_AURA)
+#include "chrome/browser/chromeos/notifications/balloon_collection_impl_aura.h"
+#else
+#include "chrome/browser/chromeos/notifications/balloon_collection_impl.h"
+#endif
+
namespace chromeos {
void SystemNotification::Init(int icon_resource_id) {
- collection_ = static_cast<BalloonCollectionImpl*>(
- g_browser_process->notification_ui_manager()->balloon_collection());
+ collection_ = static_cast<BalloonCollectionImplType*>(
+ g_browser_process->notification_ui_manager()->balloon_collection());
std::string url = web_ui_util::GetImageDataUrlFromResource(icon_resource_id);
DCHECK(!url.empty());
GURL tmp_gurl(url);
@@ -55,12 +60,12 @@ SystemNotification::~SystemNotification() {
void SystemNotification::Show(const string16& message,
bool urgent,
bool sticky) {
- Show(message, string16(), MessageCallback(), urgent, sticky);
+ Show(message, string16(), BalloonViewHost::MessageCallback(), urgent, sticky);
}
void SystemNotification::Show(const string16& message,
const string16& link,
- const MessageCallback& callback,
+ const BalloonViewHost::MessageCallback& callback,
bool urgent,
bool sticky) {
Notification notify = SystemNotificationFactory::Create(icon_,
@@ -68,14 +73,14 @@ void SystemNotification::Show(const string16& message,
if (visible_) {
// Force showing a user hidden notification on an urgent transition.
if (urgent && !urgent_) {
- collection_->UpdateAndShowNotification(notify);
+ if (!collection_->UpdateAndShowNotification(notify))
+ visible_ = false; // re-show
} else {
collection_->UpdateNotification(notify);
}
- } else {
- collection_->AddSystemNotification(notify, profile_,
- sticky,
- false /* no controls */);
+ }
+ if (!visible_) {
+ collection_->AddSystemNotification(notify, profile_, sticky);
collection_->AddWebUIMessageCallback(notify, "link", callback);
}
visible_ = true;
diff --git a/chrome/browser/chromeos/notifications/system_notification.h b/chrome/browser/chromeos/notifications/system_notification.h
index d7e0811..ad23750 100644
--- a/chrome/browser/chromeos/notifications/system_notification.h
+++ b/chrome/browser/chromeos/notifications/system_notification.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -19,7 +19,13 @@ class Profile;
namespace chromeos {
+#if defined(USE_AURA)
+class BalloonCollectionImplAura;
+typedef class BalloonCollectionImplAura BalloonCollectionImplType;
+#else
class BalloonCollectionImpl;
+typedef class BalloonCollectionImpl BalloonCollectionImplType;
+#endif
// The system notification object handles the display of a system notification
@@ -51,7 +57,8 @@ class SystemNotification {
// Same as Show() above with a footer link at the bottom and a callback
// for when the link is clicked.
void Show(const string16& message, const string16& link_text,
- const MessageCallback& callback, bool urgent, bool sticky);
+ const BalloonViewHost::MessageCallback& callback,
+ bool urgent, bool sticky);
// Hide will dismiss the notification, if the notification is already
// hidden it does nothing
@@ -82,7 +89,7 @@ class SystemNotification {
void Init(int icon_resource_id);
Profile* profile_;
- BalloonCollectionImpl* collection_;
+ BalloonCollectionImplType* collection_;
scoped_refptr<NotificationDelegate> delegate_;
GURL icon_;
string16 title_;
diff --git a/chrome/browser/chromeos/notifications/system_notification_browsertest.cc b/chrome/browser/chromeos/notifications/system_notification_browsertest.cc
new file mode 100644
index 0000000..ab51112
--- /dev/null
+++ b/chrome/browser/chromeos/notifications/system_notification_browsertest.cc
@@ -0,0 +1,154 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "base/string16.h"
+#include "base/string_util.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/notifications/system_notification_factory.h"
+#include "chrome/browser/notifications/notification_test_util.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/notification_service.h"
+#include "ui/base/x/x11_util.h"
+
+#if defined(USE_AURA)
+#include "chrome/browser/chromeos/notifications/balloon_collection_impl_aura.h"
+#include "ui/aura/root_window.h"
+#else
+#include "chrome/browser/chromeos/notifications/balloon_collection_impl.h"
+#endif
+
+#if defined(USE_AURA)
+typedef class chromeos::BalloonCollectionImplAura BalloonCollectionImplType;
+#else
+typedef class chromeos::BalloonCollectionImpl BalloonCollectionImplType;
+#endif
+
+namespace chromeos {
+
+class SystemNotificationTest : public InProcessBrowserTest {
+ public:
+ SystemNotificationTest() {}
+
+ void HandleWebUIMessage(const ListValue* value) {
+ MessageLoop::current()->Quit();
+ }
+
+ protected:
+ virtual void SetUp() {
+ InProcessBrowserTest::SetUp();
+ }
+
+ BalloonCollectionImplType* GetBalloonCollectionImpl() {
+ return static_cast<BalloonCollectionImplType*>(
+ g_browser_process->notification_ui_manager()->balloon_collection());
+ }
+
+ Notification NewMockNotification(const std::string& id) {
+ return NewMockNotification(new MockNotificationDelegate(id));
+ }
+
+ Notification NewMockNotification(NotificationDelegate* delegate) {
+ std::string text = delegate->id();
+ return SystemNotificationFactory::Create(
+ GURL(), ASCIIToUTF16(text.c_str()), ASCIIToUTF16(text.c_str()),
+ delegate);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SystemNotificationTest);
+};
+
+IN_PROC_BROWSER_TEST_F(SystemNotificationTest, TestSystemNotification) {
+ BalloonCollectionImplType* collection = GetBalloonCollectionImpl();
+ scoped_refptr<MockNotificationDelegate> delegate(
+ new MockNotificationDelegate("power"));
+
+ EXPECT_EQ(0, collection->count());
+
+ Notification notify = NewMockNotification(delegate.get());
+ collection->AddSystemNotification(notify, browser()->profile(), true);
+
+ EXPECT_EQ(1, collection->count());
+
+ Notification update = SystemNotificationFactory::Create(
+ GURL(), ASCIIToUTF16("Title"), ASCIIToUTF16("updated"), delegate.get());
+ collection->UpdateNotification(update);
+
+ EXPECT_EQ(1, collection->count());
+
+ Notification update_and_show = SystemNotificationFactory::Create(
+ GURL(), ASCIIToUTF16("Title"), ASCIIToUTF16("updated and shown"),
+ delegate.get());
+ collection->UpdateAndShowNotification(update_and_show);
+
+ EXPECT_EQ(1, collection->count());
+
+ // Dismiss the notification.
+ collection->RemoveById(delegate->id());
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ EXPECT_EQ(0, collection->count());
+}
+
+IN_PROC_BROWSER_TEST_F(SystemNotificationTest, TestAddWebUIMessageCallback) {
+ BalloonCollectionImplType* collection = GetBalloonCollectionImpl();
+ Profile* profile = browser()->profile();
+
+ collection->AddSystemNotification(
+ NewMockNotification("1"), profile, false);
+
+ EXPECT_TRUE(collection->AddWebUIMessageCallback(
+ NewMockNotification("1"),
+ "test",
+ base::Bind(&SystemNotificationTest::HandleWebUIMessage,
+ base::Unretained(static_cast<SystemNotificationTest*>(this)))));
+
+ // Adding callback for the same message twice should fail.
+ EXPECT_FALSE(collection->AddWebUIMessageCallback(
+ NewMockNotification("1"),
+ "test",
+ base::Bind(&SystemNotificationTest::HandleWebUIMessage,
+ base::Unretained(static_cast<SystemNotificationTest*>(this)))));
+
+ // Adding callback to nonexistent notification should fail.
+ EXPECT_FALSE(collection->AddWebUIMessageCallback(
+ NewMockNotification("2"),
+ "test1",
+ base::Bind(&SystemNotificationTest::HandleWebUIMessage,
+ base::Unretained(static_cast<SystemNotificationTest*>(this)))));
+}
+
+// Occasional crash: http://crbug.com/96461
+IN_PROC_BROWSER_TEST_F(SystemNotificationTest, TestWebUIMessageCallback) {
+ BalloonCollectionImplType* collection = GetBalloonCollectionImpl();
+ Profile* profile = browser()->profile();
+ // A notification that sends 'test' WebUI message back to chrome.
+ const GURL content_url(
+ "data:text/html;charset=utf-8,"
+ "<html><script>function send() { chrome.send('test', ['']); }</script>"
+ "<body onload='send()'></body></html>");
+ collection->AddSystemNotification(
+ Notification(GURL(), content_url, string16(), string16(),
+ new MockNotificationDelegate("1")),
+ profile,
+ false);
+ EXPECT_TRUE(collection->AddWebUIMessageCallback(
+ NewMockNotification("1"),
+ "test",
+ base::Bind(&SystemNotificationTest::HandleWebUIMessage,
+ base::Unretained(static_cast<SystemNotificationTest*>(this)))));
+ MessageLoop::current()->Run();
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/notifications/balloon_collection_base.cc b/chrome/browser/notifications/balloon_collection_base.cc
index 4e9ab50f..278f4a9 100644
--- a/chrome/browser/notifications/balloon_collection_base.cc
+++ b/chrome/browser/notifications/balloon_collection_base.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,8 +16,11 @@ BalloonCollectionBase::~BalloonCollectionBase() {
STLDeleteElements(&balloons_);
}
-void BalloonCollectionBase::Add(Balloon* balloon) {
- balloons_.push_back(balloon);
+void BalloonCollectionBase::Add(Balloon* balloon, bool add_to_front) {
+ if (add_to_front)
+ balloons_.push_front(balloon);
+ else
+ balloons_.push_back(balloon);
}
void BalloonCollectionBase::Remove(Balloon* balloon) {
diff --git a/chrome/browser/notifications/balloon_collection_base.h b/chrome/browser/notifications/balloon_collection_base.h
index c388ac9..578c76e 100644
--- a/chrome/browser/notifications/balloon_collection_base.h
+++ b/chrome/browser/notifications/balloon_collection_base.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -27,7 +27,7 @@ class BalloonCollectionBase {
typedef std::deque<Balloon*> Balloons;
// Adds a balloon to the collection. Takes ownership of pointer.
- virtual void Add(Balloon* balloon);
+ virtual void Add(Balloon* balloon, bool add_to_front);
// Removes a balloon from the collection (if present). Frees
// the pointer after removal.
diff --git a/chrome/browser/notifications/balloon_collection_impl.cc b/chrome/browser/notifications/balloon_collection_impl.cc
index 26e1363..b12548f 100644
--- a/chrome/browser/notifications/balloon_collection_impl.cc
+++ b/chrome/browser/notifications/balloon_collection_impl.cc
@@ -58,8 +58,9 @@ BalloonCollectionImpl::BalloonCollectionImpl()
BalloonCollectionImpl::~BalloonCollectionImpl() {
}
-void BalloonCollectionImpl::Add(const Notification& notification,
- Profile* profile) {
+void BalloonCollectionImpl::AddImpl(const Notification& notification,
+ Profile* profile,
+ bool add_to_front) {
Balloon* new_balloon = MakeBalloon(notification, profile);
// The +1 on width is necessary because width is fixed on notifications,
// so since we always have the max size, we would always hit the scrollbar
@@ -73,7 +74,7 @@ void BalloonCollectionImpl::Add(const Notification& notification,
if (count > 0 && layout_.RequiresOffsets())
new_balloon->set_offset(base_.balloons()[count - 1]->offset());
#endif
- base_.Add(new_balloon);
+ base_.Add(new_balloon, add_to_front);
PositionBalloons(false);
// There may be no listener in a unit test.
@@ -85,6 +86,11 @@ void BalloonCollectionImpl::Add(const Notification& notification,
on_collection_changed_callback_.Run();
}
+void BalloonCollectionImpl::Add(const Notification& notification,
+ Profile* profile) {
+ AddImpl(notification, profile, false);
+}
+
bool BalloonCollectionImpl::RemoveById(const std::string& id) {
return base_.CloseById(id);
}
diff --git a/chrome/browser/notifications/balloon_collection_impl.h b/chrome/browser/notifications/balloon_collection_impl.h
index 032fabb..749c9e0 100644
--- a/chrome/browser/notifications/balloon_collection_impl.h
+++ b/chrome/browser/notifications/balloon_collection_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -72,6 +72,10 @@ class BalloonCollectionImpl : public BalloonCollection,
virtual void DidProcessEvent(GdkEvent* event) OVERRIDE;
#endif
+ // base_ is embedded, so this is a simple accessor for the number of
+ // balloons in the collection.
+ int count() const { return base_.count(); }
+
protected:
// Calculates layout values for the balloons including
// the scaling, the max/min sizes, and the upper left corner of each.
@@ -165,14 +169,23 @@ class BalloonCollectionImpl : public BalloonCollection,
DISALLOW_COPY_AND_ASSIGN(Layout);
};
- // Creates a new balloon. Overridable by unit tests. The caller is
- // responsible for freeing the pointer returned.
+ // Creates a new balloon. Overridable by derived classes and unit tests.
+ // The caller is responsible for freeing the pointer returned.
virtual Balloon* MakeBalloon(const Notification& notification,
Profile* profile);
+ // Protected implementation of Add with additional add_to_front parameter
+ // for use by derived classes.
+ void AddImpl(const Notification& notification,
+ Profile* profile,
+ bool add_to_front);
+
// Gets a bounding box for all the current balloons in screen coordinates.
gfx::Rect GetBalloonsBoundingBox() const;
+ BalloonCollectionBase& base() { return base_; }
+ Layout& layout() { return layout_; }
+
private:
// Adjusts the positions of the balloons (e.g., when one is closed).
// Implemented by each platform for specific UI requirements.
diff --git a/chrome/browser/notifications/balloon_collection_views.cc b/chrome/browser/notifications/balloon_collection_views.cc
index f5ac0e4..763fba1 100644
--- a/chrome/browser/notifications/balloon_collection_views.cc
+++ b/chrome/browser/notifications/balloon_collection_views.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -108,7 +108,9 @@ void BalloonCollectionImpl::SetPositionPreference(
PositionBalloons(true);
}
+#if !defined(USE_AURA)
// static
BalloonCollection* BalloonCollection::Create() {
return new BalloonCollectionImpl();
}
+#endif
diff --git a/chrome/browser/notifications/notification_options_menu_model.cc b/chrome/browser/notifications/notification_options_menu_model.cc
index 2578c3f..c486742 100644
--- a/chrome/browser/notifications/notification_options_menu_model.cc
+++ b/chrome/browser/notifications/notification_options_menu_model.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -129,16 +129,18 @@ NotificationOptionsMenuModel::NotificationOptionsMenuModel(Balloon* balloon)
IDS_EXTENSIONS_DISABLE);
AddItem(kToggleExtensionCommand, disable_label);
}
- } else {
+ } else if (!notification.display_source().empty()) {
const string16 disable_label = l10n_util::GetStringFUTF16(
IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE,
notification.display_source());
AddItem(kTogglePermissionCommand, disable_label);
}
- const string16 settings_label = l10n_util::GetStringUTF16(
- IDS_NOTIFICATIONS_SETTINGS_BUTTON);
- AddItem(kOpenContentSettingsCommand, settings_label);
+ if (!notification.display_source().empty()) {
+ const string16 settings_label = l10n_util::GetStringUTF16(
+ IDS_NOTIFICATIONS_SETTINGS_BUTTON);
+ AddItem(kOpenContentSettingsCommand, settings_label);
+ }
corner_menu_model_.reset(new CornerSelectionMenuModel(balloon));
AddSubMenu(kCornerSelectionSubMenu,
diff --git a/chrome/browser/ui/views/notifications/balloon_view.cc b/chrome/browser/ui/views/notifications/balloon_view.cc
index 717746e..d58481d 100644
--- a/chrome/browser/ui/views/notifications/balloon_view.cc
+++ b/chrome/browser/ui/views/notifications/balloon_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -15,7 +15,6 @@
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_options_menu_model.h"
-#include "chrome/browser/ui/views/notifications/balloon_view_host.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/render_widget_host_view.h"
@@ -43,6 +42,12 @@
#include "ui/views/painter.h"
#include "ui/views/widget/widget.h"
+#if defined(OS_CHROMEOS) && defined(USE_AURA)
+#include "chrome/browser/chromeos/notifications/balloon_view_host.h"
+#else
+#include "chrome/browser/ui/views/notifications/balloon_view_host.h"
+#endif
+
using views::Widget;
namespace {
@@ -103,7 +108,8 @@ BalloonViewImpl::BalloonViewImpl(BalloonCollection* collection)
close_button_(NULL),
animation_(NULL),
options_menu_model_(NULL),
- options_menu_button_(NULL) {
+ options_menu_button_(NULL),
+ enable_web_ui_(false) {
// This object is not to be deleted by the views hierarchy,
// as it is owned by the balloon.
set_parent_owned(false);
@@ -333,8 +339,15 @@ void BalloonViewImpl::Show(Balloon* balloon) {
// We don't let the OS manage the RTL layout of these widgets, because
// this code is already taking care of correctly reversing the layout.
gfx::Rect contents_rect = GetContentsRectangle();
+#if defined(OS_CHROMEOS) && defined(USE_AURA)
+ html_contents_.reset(new chromeos::BalloonViewHost(balloon));
+#else
html_contents_.reset(new BalloonViewHost(balloon));
+#endif
html_contents_->SetPreferredSize(gfx::Size(10000, 10000));
+ if (enable_web_ui_)
+ html_contents_->EnableWebUI();
+
html_container_ = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
params.bounds = contents_rect;
diff --git a/chrome/browser/ui/views/notifications/balloon_view.h b/chrome/browser/ui/views/notifications/balloon_view.h
index 76ef55c..8db76de 100644
--- a/chrome/browser/ui/views/notifications/balloon_view.h
+++ b/chrome/browser/ui/views/notifications/balloon_view.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -58,6 +58,8 @@ class BalloonViewImpl : public BalloonView,
virtual gfx::Size GetSize() const OVERRIDE;
virtual BalloonHost* GetHost() const OVERRIDE;
+ void set_enable_web_ui(bool enable) { enable_web_ui_ = enable; }
+
private:
// views::View interface.
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
@@ -157,6 +159,9 @@ class BalloonViewImpl : public BalloonView,
content::NotificationRegistrar notification_registrar_;
+ // Set to true if this is browser generate web UI.
+ bool enable_web_ui_;
+
DISALLOW_COPY_AND_ASSIGN(BalloonViewImpl);
};
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index ec33793..5079ba6 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -445,7 +445,6 @@
'browser/chromeos/cros_settings_names.h',
'browser/chromeos/cros_settings_provider.cc',
'browser/chromeos/cros_settings_provider.h',
- 'browser/chromeos/cros_stubs_aura.cc',
'browser/chromeos/customization_document.cc',
'browser/chromeos/customization_document.h',
'browser/chromeos/dbus/bluetooth_adapter_client.cc',
@@ -704,6 +703,8 @@
'browser/chromeos/network_message_observer.h',
'browser/chromeos/notifications/balloon_collection_impl.cc',
'browser/chromeos/notifications/balloon_collection_impl.h',
+ 'browser/chromeos/notifications/balloon_collection_impl_aura.cc',
+ 'browser/chromeos/notifications/balloon_collection_impl_aura.h',
'browser/chromeos/notifications/balloon_view.cc',
'browser/chromeos/notifications/balloon_view.h',
'browser/chromeos/notifications/balloon_view_host.cc',
@@ -5350,6 +5351,14 @@
['exclude', '^browser/chromeos/login/views_login_display_host.cc'],
['exclude', '^browser/chromeos/login/wizard_in_process_browser_test.cc'],
['exclude', '^browser/chromeos/notifications/'],
+ ['include', '^browser/chromeos/notifications/balloon_collection_impl_aura.cc'],
+ ['include', '^browser/chromeos/notifications/balloon_collection_impl_aura.h'],
+ ['include', '^browser/chromeos/notifications/balloon_view_host.cc'],
+ ['include', '^browser/chromeos/notifications/balloon_view_host.h'],
+ ['include', '^browser/chromeos/notifications/system_notification.cc'],
+ ['include', '^browser/chromeos/notifications/system_notification.h'],
+ ['include', '^browser/chromeos/notifications/system_notification_factory.cc'],
+ ['include', '^browser/chromeos/notifications/system_notification_factory.h'],
],
}],
['enable_plugin_installation==0', {
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 7e80c94..54eae34 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -2173,13 +2173,6 @@
['exclude', '^browser/plugin_download_helper_unittest.cc'],
['exclude', '^browser/safe_browsing/download_protection_service_unittest.cc' ],
],
- 'conditions': [
- ['use_aura==1', {
- 'sources!': [
- 'browser/chromeos/notifications/desktop_notifications_unittest.cc',
- ],
- }],
- ],
}, { # else: chromeos == 0
'sources/': [
['exclude', '^browser/chromeos/'],
@@ -2532,6 +2525,7 @@
'browser/chromeos/login/wizard_in_process_browser_test.h',
'browser/chromeos/media/media_player_browsertest.cc',
'browser/chromeos/notifications/notification_browsertest.cc',
+ 'browser/chromeos/notifications/system_notification_browsertest.cc',
'browser/chromeos/panels/panel_browsertest.cc',
'browser/chromeos/process_proxy/process_proxy_browsertest.cc',
'browser/chromeos/status/accessibility_menu_button_browsertest.cc',
@@ -2889,7 +2883,7 @@
'conditions': [
['use_aura==1', {
'sources/': [
- ['exclude', '^browser/chromeos/notifications/'],
+ ['exclude', '^browser/chromeos/notifications/notification_browsertest.cc'],
['exclude', '^browser/chromeos/panels/panel_browsertest.cc'],
['exclude', '^browser/ui/views/status_icons/status_tray_chromeos_browsertest.cc'],
],