summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2011-05-31 20:30:28 +0100
committerKristian Monsen <kristianm@google.com>2011-06-14 20:31:41 -0700
commit72a454cd3513ac24fbdd0e0cb9ad70b86a99b801 (patch)
tree382278a54ce7a744d62fa510a9a80688cc12434b /chrome/browser/notifications
parentc4becdd46e31d261b930e4b5a539cbc1d45c23a6 (diff)
downloadexternal_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.zip
external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.gz
external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.bz2
Merge Chromium.org at r11.0.672.0: Initial merge by git.
Change-Id: I8b4aaf611a2a405fe3fe10e8a94ea7658645c192
Diffstat (limited to 'chrome/browser/notifications')
-rw-r--r--chrome/browser/notifications/OWNERS1
-rw-r--r--chrome/browser/notifications/balloon.cc4
-rw-r--r--chrome/browser/notifications/balloon.h6
-rw-r--r--chrome/browser/notifications/balloon_collection.cc342
-rw-r--r--chrome/browser/notifications/balloon_collection.h8
-rw-r--r--chrome/browser/notifications/balloon_collection_impl.cc382
-rw-r--r--chrome/browser/notifications/balloon_collection_impl.h13
-rw-r--r--chrome/browser/notifications/balloon_collection_linux.cc25
-rw-r--r--chrome/browser/notifications/balloon_collection_win.cc21
-rw-r--r--chrome/browser/notifications/balloon_host.cc70
-rw-r--r--chrome/browser/notifications/balloon_host.h36
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc281
-rw-r--r--chrome/browser/notifications/desktop_notification_service.h2
-rw-r--r--chrome/browser/notifications/desktop_notification_service_unittest.cc2
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.cc38
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.h11
-rw-r--r--chrome/browser/notifications/notification_exceptions_table_model.cc6
-rw-r--r--chrome/browser/notifications/notification_exceptions_table_model.h4
-rw-r--r--chrome/browser/notifications/notification_exceptions_table_model_unittest.cc2
-rw-r--r--chrome/browser/notifications/notification_options_menu_model.cc10
-rw-r--r--chrome/browser/notifications/notification_options_menu_model.h20
-rw-r--r--chrome/browser/notifications/notification_test_util.h2
-rw-r--r--chrome/browser/notifications/notification_ui_manager.cc40
-rw-r--r--chrome/browser/notifications/notification_ui_manager.h12
-rw-r--r--chrome/browser/notifications/notifications_interactive_uitest.cc7
-rw-r--r--chrome/browser/notifications/notifications_prefs_cache.cc6
-rw-r--r--chrome/browser/notifications/notifications_prefs_cache_unittest.cc2
27 files changed, 751 insertions, 602 deletions
diff --git a/chrome/browser/notifications/OWNERS b/chrome/browser/notifications/OWNERS
new file mode 100644
index 0000000..967c65c
--- /dev/null
+++ b/chrome/browser/notifications/OWNERS
@@ -0,0 +1 @@
+johnnyg@chromium.org
diff --git a/chrome/browser/notifications/balloon.cc b/chrome/browser/notifications/balloon.cc
index d9f9111..115e1ee 100644
--- a/chrome/browser/notifications/balloon.cc
+++ b/chrome/browser/notifications/balloon.cc
@@ -8,8 +8,8 @@
#include "chrome/browser/notifications/balloon_collection.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/renderer_host/site_instance.h"
-#include "gfx/rect.h"
-#include "gfx/size.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/size.h"
Balloon::Balloon(const Notification& notification, Profile* profile,
BalloonCollection* collection)
diff --git a/chrome/browser/notifications/balloon.h b/chrome/browser/notifications/balloon.h
index 5b86508..48c22e1 100644
--- a/chrome/browser/notifications/balloon.h
+++ b/chrome/browser/notifications/balloon.h
@@ -10,9 +10,9 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
-#include "gfx/point.h"
-#include "gfx/rect.h"
-#include "gfx/size.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/size.h"
class Balloon;
class BalloonCollection;
diff --git a/chrome/browser/notifications/balloon_collection.cc b/chrome/browser/notifications/balloon_collection.cc
index 60c9f2d..48059f5 100644
--- a/chrome/browser/notifications/balloon_collection.cc
+++ b/chrome/browser/notifications/balloon_collection.cc
@@ -1,344 +1,12 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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/notifications/balloon_collection_impl.h"
+#include "chrome/browser/notifications/balloon_collection.h"
-#include "base/logging.h"
-#include "base/stl_util-inl.h"
-#include "chrome/browser/notifications/balloon.h"
-#include "chrome/browser/notifications/balloon_host.h"
-#include "chrome/browser/notifications/notification.h"
-#include "chrome/browser/ui/window_sizer.h"
-#include "gfx/rect.h"
-#include "gfx/size.h"
-
-namespace {
-
-// Portion of the screen allotted for notifications. When notification balloons
-// extend over this, no new notifications are shown until some are closed.
-const double kPercentBalloonFillFactor = 0.7;
-
-// Allow at least this number of balloons on the screen.
-const int kMinAllowedBalloonCount = 2;
-
-// Delay from the mouse leaving the balloon collection before
-// there is a relayout, in milliseconds.
-const int kRepositionDelay = 300;
-
-} // namespace
-
-BalloonCollectionImpl::BalloonCollectionImpl()
-#if USE_OFFSETS
- : ALLOW_THIS_IN_INITIALIZER_LIST(reposition_factory_(this)),
- added_as_message_loop_observer_(false)
-#endif
-{
-
- SetPositionPreference(BalloonCollection::DEFAULT_POSITION);
-}
-
-BalloonCollectionImpl::~BalloonCollectionImpl() {
-}
-
-void BalloonCollectionImpl::Add(const Notification& notification,
- Profile* profile) {
- 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
- // condition. We are only interested in comparing height to maximum.
- new_balloon->set_min_scrollbar_size(gfx::Size(1 + layout_.max_balloon_width(),
- layout_.max_balloon_height()));
- new_balloon->SetPosition(layout_.OffScreenLocation(), false);
- new_balloon->Show();
-#if USE_OFFSETS
- int count = base_.count();
- if (count > 0)
- new_balloon->set_offset(base_.balloons()[count - 1]->offset());
-#endif
- base_.Add(new_balloon);
- PositionBalloons(false);
-
- // There may be no listener in a unit test.
- if (space_change_listener_)
- space_change_listener_->OnBalloonSpaceChanged();
-
- // This is used only for testing.
- if (on_collection_changed_callback_.get())
- on_collection_changed_callback_->Run();
-}
-
-bool BalloonCollectionImpl::RemoveById(const std::string& id) {
- return base_.CloseById(id);
-}
-
-bool BalloonCollectionImpl::RemoveBySourceOrigin(const GURL& origin) {
- return base_.CloseAllBySourceOrigin(origin);
-}
-
-void BalloonCollectionImpl::RemoveAll() {
- base_.CloseAll();
-}
-
-bool BalloonCollectionImpl::HasSpace() const {
- int count = base_.count();
- if (count < kMinAllowedBalloonCount)
- return true;
-
- int max_balloon_size = 0;
- int total_size = 0;
- layout_.GetMaxLinearSize(&max_balloon_size, &total_size);
-
- int current_max_size = max_balloon_size * count;
- int max_allowed_size = static_cast<int>(total_size *
- kPercentBalloonFillFactor);
- return current_max_size < max_allowed_size - max_balloon_size;
-}
-
-void BalloonCollectionImpl::ResizeBalloon(Balloon* balloon,
- const gfx::Size& size) {
- balloon->set_content_size(Layout::ConstrainToSizeLimits(size));
- PositionBalloons(true);
-}
-
-void BalloonCollectionImpl::DisplayChanged() {
- layout_.RefreshSystemMetrics();
- PositionBalloons(true);
+BalloonCollection::BalloonCollection()
+ : space_change_listener_(NULL) {
}
-void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
- // We want to free the balloon when finished.
- const Balloons& balloons = base_.balloons();
- Balloons::const_iterator it = balloons.begin();
-
-#if USE_OFFSETS
- gfx::Point offset;
- bool apply_offset = false;
- while (it != balloons.end()) {
- if (*it == source) {
- ++it;
- if (it != balloons.end()) {
- apply_offset = true;
- offset.set_y((source)->offset().y() - (*it)->offset().y() +
- (*it)->content_size().height() - source->content_size().height());
- }
- } else {
- if (apply_offset)
- (*it)->add_offset(offset);
- ++it;
- }
- }
- // Start listening for UI events so we cancel the offset when the mouse
- // leaves the balloon area.
- if (apply_offset)
- AddMessageLoopObserver();
-#endif
-
- base_.Remove(source);
- PositionBalloons(true);
-
- // There may be no listener in a unit test.
- if (space_change_listener_)
- space_change_listener_->OnBalloonSpaceChanged();
-
- // This is used only for testing.
- if (on_collection_changed_callback_.get())
- on_collection_changed_callback_->Run();
-}
-
-void BalloonCollectionImpl::PositionBalloonsInternal(bool reposition) {
- const Balloons& balloons = base_.balloons();
-
- layout_.RefreshSystemMetrics();
- gfx::Point origin = layout_.GetLayoutOrigin();
- for (Balloons::const_iterator it = balloons.begin();
- it != balloons.end();
- ++it) {
- gfx::Point upper_left = layout_.NextPosition((*it)->GetViewSize(), &origin);
- (*it)->SetPosition(upper_left, reposition);
- }
-}
-
-#if USE_OFFSETS
-void BalloonCollectionImpl::AddMessageLoopObserver() {
- if (!added_as_message_loop_observer_) {
- MessageLoopForUI::current()->AddObserver(this);
- added_as_message_loop_observer_ = true;
- }
-}
-
-void BalloonCollectionImpl::RemoveMessageLoopObserver() {
- if (added_as_message_loop_observer_) {
- MessageLoopForUI::current()->RemoveObserver(this);
- added_as_message_loop_observer_ = false;
- }
-}
-
-void BalloonCollectionImpl::CancelOffsets() {
- reposition_factory_.RevokeAll();
-
- // Unhook from listening to all UI events.
- RemoveMessageLoopObserver();
-
- const Balloons& balloons = base_.balloons();
- for (Balloons::const_iterator it = balloons.begin();
- it != balloons.end();
- ++it)
- (*it)->set_offset(gfx::Point(0, 0));
-
- PositionBalloons(true);
-}
-
-void BalloonCollectionImpl::HandleMouseMoveEvent() {
- if (!IsCursorInBalloonCollection()) {
- // Mouse has left the region. Schedule a reposition after
- // a short delay.
- if (reposition_factory_.empty()) {
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- reposition_factory_.NewRunnableMethod(
- &BalloonCollectionImpl::CancelOffsets),
- kRepositionDelay);
- }
- } else {
- // Mouse moved back into the region. Cancel the reposition.
- reposition_factory_.RevokeAll();
- }
-}
-#endif
-
-BalloonCollectionImpl::Layout::Layout() {
- RefreshSystemMetrics();
-}
-
-void BalloonCollectionImpl::Layout::GetMaxLinearSize(int* max_balloon_size,
- int* total_size) const {
- DCHECK(max_balloon_size && total_size);
-
- // All placement schemes are vertical, so we only care about height.
- *total_size = work_area_.height();
- *max_balloon_size = max_balloon_height();
-}
-
-gfx::Point BalloonCollectionImpl::Layout::GetLayoutOrigin() const {
- int x = 0;
- int y = 0;
- switch (placement_) {
- case VERTICALLY_FROM_TOP_LEFT:
- x = work_area_.x() + HorizontalEdgeMargin();
- y = work_area_.y() + VerticalEdgeMargin();
- break;
- case VERTICALLY_FROM_TOP_RIGHT:
- x = work_area_.right() - HorizontalEdgeMargin();
- y = work_area_.y() + VerticalEdgeMargin();
- break;
- case VERTICALLY_FROM_BOTTOM_LEFT:
- x = work_area_.x() + HorizontalEdgeMargin();
- y = work_area_.bottom() - VerticalEdgeMargin();
- break;
- case VERTICALLY_FROM_BOTTOM_RIGHT:
- x = work_area_.right() - HorizontalEdgeMargin();
- y = work_area_.bottom() - VerticalEdgeMargin();
- break;
- default:
- NOTREACHED();
- break;
- }
- return gfx::Point(x, y);
-}
-
-gfx::Point BalloonCollectionImpl::Layout::NextPosition(
- const gfx::Size& balloon_size,
- gfx::Point* position_iterator) const {
- DCHECK(position_iterator);
-
- int x = 0;
- int y = 0;
- switch (placement_) {
- case VERTICALLY_FROM_TOP_LEFT:
- x = position_iterator->x();
- y = position_iterator->y();
- position_iterator->set_y(position_iterator->y() + balloon_size.height() +
- InterBalloonMargin());
- break;
- case VERTICALLY_FROM_TOP_RIGHT:
- x = position_iterator->x() - balloon_size.width();
- y = position_iterator->y();
- position_iterator->set_y(position_iterator->y() + balloon_size.height() +
- InterBalloonMargin());
- break;
- case VERTICALLY_FROM_BOTTOM_LEFT:
- position_iterator->set_y(position_iterator->y() - balloon_size.height() -
- InterBalloonMargin());
- x = position_iterator->x();
- y = position_iterator->y();
- break;
- case VERTICALLY_FROM_BOTTOM_RIGHT:
- position_iterator->set_y(position_iterator->y() - balloon_size.height() -
- InterBalloonMargin());
- x = position_iterator->x() - balloon_size.width();
- y = position_iterator->y();
- break;
- default:
- NOTREACHED();
- break;
- }
- return gfx::Point(x, y);
-}
-
-gfx::Point BalloonCollectionImpl::Layout::OffScreenLocation() const {
- int x = 0;
- int y = 0;
- switch (placement_) {
- case VERTICALLY_FROM_TOP_LEFT:
- x = work_area_.x() + HorizontalEdgeMargin();
- y = work_area_.y() + kBalloonMaxHeight + VerticalEdgeMargin();
- break;
- case VERTICALLY_FROM_TOP_RIGHT:
- x = work_area_.right() - kBalloonMaxWidth - HorizontalEdgeMargin();
- y = work_area_.y() + kBalloonMaxHeight + VerticalEdgeMargin();
- break;
- case VERTICALLY_FROM_BOTTOM_LEFT:
- x = work_area_.x() + HorizontalEdgeMargin();
- y = work_area_.bottom() + kBalloonMaxHeight + VerticalEdgeMargin();
- break;
- case VERTICALLY_FROM_BOTTOM_RIGHT:
- x = work_area_.right() - kBalloonMaxWidth - HorizontalEdgeMargin();
- y = work_area_.bottom() + kBalloonMaxHeight + VerticalEdgeMargin();
- break;
- default:
- NOTREACHED();
- break;
- }
- return gfx::Point(x, y);
-}
-
-// static
-gfx::Size BalloonCollectionImpl::Layout::ConstrainToSizeLimits(
- const gfx::Size& size) {
- // restrict to the min & max sizes
- return gfx::Size(
- std::max(min_balloon_width(),
- std::min(max_balloon_width(), size.width())),
- std::max(min_balloon_height(),
- std::min(max_balloon_height(), size.height())));
-}
-
-bool BalloonCollectionImpl::Layout::RefreshSystemMetrics() {
- bool changed = false;
-
-#if defined(OS_MACOSX)
- gfx::Rect new_work_area = GetMacWorkArea();
-#else
- scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider(
- WindowSizer::CreateDefaultMonitorInfoProvider());
- gfx::Rect new_work_area = info_provider->GetPrimaryMonitorWorkArea();
-#endif
- if (!work_area_.Equals(new_work_area)) {
- work_area_.SetRect(new_work_area.x(), new_work_area.y(),
- new_work_area.width(), new_work_area.height());
- changed = true;
- }
-
- return changed;
+BalloonCollection::~BalloonCollection() {
}
diff --git a/chrome/browser/notifications/balloon_collection.h b/chrome/browser/notifications/balloon_collection.h
index 6909759..4cae909 100644
--- a/chrome/browser/notifications/balloon_collection.h
+++ b/chrome/browser/notifications/balloon_collection.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -48,11 +48,9 @@ class BalloonCollection {
static BalloonCollection* Create();
- BalloonCollection()
- : space_change_listener_(NULL) {
- }
+ BalloonCollection();
- virtual ~BalloonCollection() {}
+ virtual ~BalloonCollection();
// Adds a new balloon for the specified notification.
virtual void Add(const Notification& notification,
diff --git a/chrome/browser/notifications/balloon_collection_impl.cc b/chrome/browser/notifications/balloon_collection_impl.cc
new file mode 100644
index 0000000..f133de3
--- /dev/null
+++ b/chrome/browser/notifications/balloon_collection_impl.cc
@@ -0,0 +1,382 @@
+// Copyright (c) 2010 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/notifications/balloon_collection_impl.h"
+
+#include "base/logging.h"
+#include "base/stl_util-inl.h"
+#include "chrome/browser/notifications/balloon.h"
+#include "chrome/browser/notifications/balloon_host.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/ui/window_sizer.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/size.h"
+
+namespace {
+
+// Portion of the screen allotted for notifications. When notification balloons
+// extend over this, no new notifications are shown until some are closed.
+const double kPercentBalloonFillFactor = 0.7;
+
+// Allow at least this number of balloons on the screen.
+const int kMinAllowedBalloonCount = 2;
+
+// Delay from the mouse leaving the balloon collection before
+// there is a relayout, in milliseconds.
+const int kRepositionDelay = 300;
+
+} // namespace
+
+BalloonCollectionImpl::BalloonCollectionImpl()
+#if USE_OFFSETS
+ : ALLOW_THIS_IN_INITIALIZER_LIST(reposition_factory_(this)),
+ added_as_message_loop_observer_(false)
+#endif
+{
+
+ SetPositionPreference(BalloonCollection::DEFAULT_POSITION);
+}
+
+BalloonCollectionImpl::~BalloonCollectionImpl() {
+}
+
+void BalloonCollectionImpl::Add(const Notification& notification,
+ Profile* profile) {
+ 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
+ // condition. We are only interested in comparing height to maximum.
+ new_balloon->set_min_scrollbar_size(gfx::Size(1 + layout_.max_balloon_width(),
+ layout_.max_balloon_height()));
+ new_balloon->SetPosition(layout_.OffScreenLocation(), false);
+ new_balloon->Show();
+#if USE_OFFSETS
+ int count = base_.count();
+ if (count > 0 && layout_.RequiresOffsets())
+ new_balloon->set_offset(base_.balloons()[count - 1]->offset());
+#endif
+ base_.Add(new_balloon);
+ PositionBalloons(false);
+
+ // There may be no listener in a unit test.
+ if (space_change_listener_)
+ space_change_listener_->OnBalloonSpaceChanged();
+
+ // This is used only for testing.
+ if (on_collection_changed_callback_.get())
+ on_collection_changed_callback_->Run();
+}
+
+bool BalloonCollectionImpl::RemoveById(const std::string& id) {
+ return base_.CloseById(id);
+}
+
+bool BalloonCollectionImpl::RemoveBySourceOrigin(const GURL& origin) {
+ return base_.CloseAllBySourceOrigin(origin);
+}
+
+void BalloonCollectionImpl::RemoveAll() {
+ base_.CloseAll();
+}
+
+bool BalloonCollectionImpl::HasSpace() const {
+ int count = base_.count();
+ if (count < kMinAllowedBalloonCount)
+ return true;
+
+ int max_balloon_size = 0;
+ int total_size = 0;
+ layout_.GetMaxLinearSize(&max_balloon_size, &total_size);
+
+ int current_max_size = max_balloon_size * count;
+ int max_allowed_size = static_cast<int>(total_size *
+ kPercentBalloonFillFactor);
+ return current_max_size < max_allowed_size - max_balloon_size;
+}
+
+void BalloonCollectionImpl::ResizeBalloon(Balloon* balloon,
+ const gfx::Size& size) {
+ balloon->set_content_size(Layout::ConstrainToSizeLimits(size));
+ PositionBalloons(true);
+}
+
+void BalloonCollectionImpl::DisplayChanged() {
+ layout_.RefreshSystemMetrics();
+ PositionBalloons(true);
+}
+
+void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
+ // We want to free the balloon when finished.
+ const Balloons& balloons = base_.balloons();
+ Balloons::const_iterator it = balloons.begin();
+
+#if USE_OFFSETS
+ if (layout_.RequiresOffsets()) {
+ gfx::Point offset;
+ bool apply_offset = false;
+ while (it != balloons.end()) {
+ if (*it == source) {
+ ++it;
+ if (it != balloons.end()) {
+ apply_offset = true;
+ offset.set_y((source)->offset().y() - (*it)->offset().y() +
+ (*it)->content_size().height() - source->content_size().height());
+ }
+ } else {
+ if (apply_offset)
+ (*it)->add_offset(offset);
+ ++it;
+ }
+ }
+ // Start listening for UI events so we cancel the offset when the mouse
+ // leaves the balloon area.
+ if (apply_offset)
+ AddMessageLoopObserver();
+ }
+#endif
+
+ base_.Remove(source);
+ PositionBalloons(true);
+
+ // There may be no listener in a unit test.
+ if (space_change_listener_)
+ space_change_listener_->OnBalloonSpaceChanged();
+
+ // This is used only for testing.
+ if (on_collection_changed_callback_.get())
+ on_collection_changed_callback_->Run();
+}
+
+const BalloonCollection::Balloons& BalloonCollectionImpl::GetActiveBalloons() {
+ return base_.balloons();
+}
+
+void BalloonCollectionImpl::PositionBalloonsInternal(bool reposition) {
+ const Balloons& balloons = base_.balloons();
+
+ layout_.RefreshSystemMetrics();
+ gfx::Point origin = layout_.GetLayoutOrigin();
+ for (Balloons::const_iterator it = balloons.begin();
+ it != balloons.end();
+ ++it) {
+ gfx::Point upper_left = layout_.NextPosition((*it)->GetViewSize(), &origin);
+ (*it)->SetPosition(upper_left, reposition);
+ }
+}
+
+gfx::Rect BalloonCollectionImpl::GetBalloonsBoundingBox() const {
+ // Start from the layout origin.
+ gfx::Rect bounds = gfx::Rect(layout_.GetLayoutOrigin(), gfx::Size(0, 0));
+
+ // For each balloon, extend the rectangle. This approach is indifferent to
+ // the orientation of the balloons.
+ const Balloons& balloons = base_.balloons();
+ Balloons::const_iterator iter;
+ for (iter = balloons.begin(); iter != balloons.end(); ++iter) {
+ gfx::Rect balloon_box = gfx::Rect((*iter)->GetPosition(),
+ (*iter)->GetViewSize());
+ bounds = bounds.Union(balloon_box);
+ }
+
+ return bounds;
+}
+
+#if USE_OFFSETS
+void BalloonCollectionImpl::AddMessageLoopObserver() {
+ if (!added_as_message_loop_observer_) {
+ MessageLoopForUI::current()->AddObserver(this);
+ added_as_message_loop_observer_ = true;
+ }
+}
+
+void BalloonCollectionImpl::RemoveMessageLoopObserver() {
+ if (added_as_message_loop_observer_) {
+ MessageLoopForUI::current()->RemoveObserver(this);
+ added_as_message_loop_observer_ = false;
+ }
+}
+
+void BalloonCollectionImpl::CancelOffsets() {
+ reposition_factory_.RevokeAll();
+
+ // Unhook from listening to all UI events.
+ RemoveMessageLoopObserver();
+
+ const Balloons& balloons = base_.balloons();
+ for (Balloons::const_iterator it = balloons.begin();
+ it != balloons.end();
+ ++it)
+ (*it)->set_offset(gfx::Point(0, 0));
+
+ PositionBalloons(true);
+}
+
+void BalloonCollectionImpl::HandleMouseMoveEvent() {
+ if (!IsCursorInBalloonCollection()) {
+ // Mouse has left the region. Schedule a reposition after
+ // a short delay.
+ if (reposition_factory_.empty()) {
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ reposition_factory_.NewRunnableMethod(
+ &BalloonCollectionImpl::CancelOffsets),
+ kRepositionDelay);
+ }
+ } else {
+ // Mouse moved back into the region. Cancel the reposition.
+ reposition_factory_.RevokeAll();
+ }
+}
+#endif
+
+BalloonCollectionImpl::Layout::Layout() {
+ RefreshSystemMetrics();
+}
+
+void BalloonCollectionImpl::Layout::GetMaxLinearSize(int* max_balloon_size,
+ int* total_size) const {
+ DCHECK(max_balloon_size && total_size);
+
+ // All placement schemes are vertical, so we only care about height.
+ *total_size = work_area_.height();
+ *max_balloon_size = max_balloon_height();
+}
+
+gfx::Point BalloonCollectionImpl::Layout::GetLayoutOrigin() const {
+ int x = 0;
+ int y = 0;
+ switch (placement_) {
+ case VERTICALLY_FROM_TOP_LEFT:
+ x = work_area_.x() + HorizontalEdgeMargin();
+ y = work_area_.y() + VerticalEdgeMargin();
+ break;
+ case VERTICALLY_FROM_TOP_RIGHT:
+ x = work_area_.right() - HorizontalEdgeMargin();
+ y = work_area_.y() + VerticalEdgeMargin();
+ break;
+ case VERTICALLY_FROM_BOTTOM_LEFT:
+ x = work_area_.x() + HorizontalEdgeMargin();
+ y = work_area_.bottom() - VerticalEdgeMargin();
+ break;
+ case VERTICALLY_FROM_BOTTOM_RIGHT:
+ x = work_area_.right() - HorizontalEdgeMargin();
+ y = work_area_.bottom() - VerticalEdgeMargin();
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ return gfx::Point(x, y);
+}
+
+gfx::Point BalloonCollectionImpl::Layout::NextPosition(
+ const gfx::Size& balloon_size,
+ gfx::Point* position_iterator) const {
+ DCHECK(position_iterator);
+
+ int x = 0;
+ int y = 0;
+ switch (placement_) {
+ case VERTICALLY_FROM_TOP_LEFT:
+ x = position_iterator->x();
+ y = position_iterator->y();
+ position_iterator->set_y(position_iterator->y() + balloon_size.height() +
+ InterBalloonMargin());
+ break;
+ case VERTICALLY_FROM_TOP_RIGHT:
+ x = position_iterator->x() - balloon_size.width();
+ y = position_iterator->y();
+ position_iterator->set_y(position_iterator->y() + balloon_size.height() +
+ InterBalloonMargin());
+ break;
+ case VERTICALLY_FROM_BOTTOM_LEFT:
+ position_iterator->set_y(position_iterator->y() - balloon_size.height() -
+ InterBalloonMargin());
+ x = position_iterator->x();
+ y = position_iterator->y();
+ break;
+ case VERTICALLY_FROM_BOTTOM_RIGHT:
+ position_iterator->set_y(position_iterator->y() - balloon_size.height() -
+ InterBalloonMargin());
+ x = position_iterator->x() - balloon_size.width();
+ y = position_iterator->y();
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ return gfx::Point(x, y);
+}
+
+gfx::Point BalloonCollectionImpl::Layout::OffScreenLocation() const {
+ int x = 0;
+ int y = 0;
+ switch (placement_) {
+ case VERTICALLY_FROM_TOP_LEFT:
+ x = work_area_.x() + HorizontalEdgeMargin();
+ y = work_area_.y() + kBalloonMaxHeight + VerticalEdgeMargin();
+ break;
+ case VERTICALLY_FROM_TOP_RIGHT:
+ x = work_area_.right() - kBalloonMaxWidth - HorizontalEdgeMargin();
+ y = work_area_.y() + kBalloonMaxHeight + VerticalEdgeMargin();
+ break;
+ case VERTICALLY_FROM_BOTTOM_LEFT:
+ x = work_area_.x() + HorizontalEdgeMargin();
+ y = work_area_.bottom() + kBalloonMaxHeight + VerticalEdgeMargin();
+ break;
+ case VERTICALLY_FROM_BOTTOM_RIGHT:
+ x = work_area_.right() - kBalloonMaxWidth - HorizontalEdgeMargin();
+ y = work_area_.bottom() + kBalloonMaxHeight + VerticalEdgeMargin();
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ return gfx::Point(x, y);
+}
+
+bool BalloonCollectionImpl::Layout::RequiresOffsets() const {
+ // Layout schemes that grow up from the bottom require offsets;
+ // schemes that grow down do not require offsets.
+ bool offsets = (placement_ == VERTICALLY_FROM_BOTTOM_LEFT ||
+ placement_ == VERTICALLY_FROM_BOTTOM_RIGHT);
+
+#if defined(OS_MACOSX)
+ // These schemes are in screen-coordinates, and top and bottom
+ // are inverted on Mac.
+ offsets = !offsets;
+#endif
+
+ return offsets;
+}
+
+// static
+gfx::Size BalloonCollectionImpl::Layout::ConstrainToSizeLimits(
+ const gfx::Size& size) {
+ // restrict to the min & max sizes
+ return gfx::Size(
+ std::max(min_balloon_width(),
+ std::min(max_balloon_width(), size.width())),
+ std::max(min_balloon_height(),
+ std::min(max_balloon_height(), size.height())));
+}
+
+bool BalloonCollectionImpl::Layout::RefreshSystemMetrics() {
+ bool changed = false;
+
+#if defined(OS_MACOSX)
+ gfx::Rect new_work_area = GetMacWorkArea();
+#else
+ scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider(
+ WindowSizer::CreateDefaultMonitorInfoProvider());
+ gfx::Rect new_work_area = info_provider->GetPrimaryMonitorWorkArea();
+#endif
+ if (!work_area_.Equals(new_work_area)) {
+ work_area_.SetRect(new_work_area.x(), new_work_area.y(),
+ new_work_area.width(), new_work_area.height());
+ changed = true;
+ }
+
+ return changed;
+}
diff --git a/chrome/browser/notifications/balloon_collection_impl.h b/chrome/browser/notifications/balloon_collection_impl.h
index d123717..fdabcb5 100644
--- a/chrome/browser/notifications/balloon_collection_impl.h
+++ b/chrome/browser/notifications/balloon_collection_impl.h
@@ -14,8 +14,8 @@
#include "base/message_loop.h"
#include "chrome/browser/notifications/balloon_collection.h"
#include "chrome/browser/notifications/balloon_collection_base.h"
-#include "gfx/point.h"
-#include "gfx/rect.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
// Mac balloons grow from the top down and have close buttons on top, so
// offsetting is not necessary for easy multiple-closing. Other platforms grow
@@ -50,7 +50,7 @@ class BalloonCollectionImpl : public BalloonCollection
virtual void SetPositionPreference(PositionPreference position);
virtual void DisplayChanged();
virtual void OnBalloonClosed(Balloon* source);
- virtual const Balloons& GetActiveBalloons() { return base_.balloons(); }
+ virtual const Balloons& GetActiveBalloons();
// MessageLoopForUI::Observer interface.
#if defined(OS_WIN)
@@ -120,6 +120,10 @@ class BalloonCollectionImpl : public BalloonCollection
// to be used as the initial position for an animation into view.
gfx::Point OffScreenLocation() const;
+ // Returns true if the layout requires offsetting for keeping the close
+ // buttons under the cursor during rapid-close interaction.
+ bool RequiresOffsets() const;
+
private:
// Layout parameters
int VerticalEdgeMargin() const;
@@ -142,6 +146,9 @@ class BalloonCollectionImpl : public BalloonCollection
virtual Balloon* MakeBalloon(const Notification& notification,
Profile* profile);
+ // Gets a bounding box for all the current balloons in screen coordinates.
+ gfx::Rect GetBalloonsBoundingBox() const;
+
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_linux.cc b/chrome/browser/notifications/balloon_collection_linux.cc
index 099193c..0255ae8 100644
--- a/chrome/browser/notifications/balloon_collection_linux.cc
+++ b/chrome/browser/notifications/balloon_collection_linux.cc
@@ -1,12 +1,17 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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/notifications/balloon_collection_impl.h"
#include "chrome/browser/notifications/balloon.h"
-#include "chrome/browser/views/notifications/balloon_view.h"
-#include "gfx/size.h"
+#include "ui/gfx/size.h"
+
+#if defined(TOOLKIT_VIEWS)
+#include "chrome/browser/ui/views/notifications/balloon_view.h"
+#else
+#include "chrome/browser/ui/gtk/notifications/balloon_view_gtk.h"
+#endif
Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
Profile* profile) {
@@ -46,25 +51,13 @@ void BalloonCollectionImpl::DidProcessEvent(GdkEvent* event) {
}
bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
- const Balloons& balloons = base_.balloons();
- if (balloons.empty())
- return false;
-
- gfx::Point upper_left = balloons[balloons.size() - 1]->GetPosition();
- gfx::Point lower_right = layout_.GetLayoutOrigin();
-
- gfx::Rect bounds = gfx::Rect(upper_left.x(),
- upper_left.y(),
- lower_right.x() - upper_left.x(),
- lower_right.y() - upper_left.y());
-
GdkScreen* screen = gdk_screen_get_default();
GdkDisplay* display = gdk_screen_get_display(screen);
gint x, y;
gdk_display_get_pointer(display, NULL, &x, &y, NULL);
gfx::Point cursor(x, y);
- return bounds.Contains(cursor);
+ return GetBalloonsBoundingBox().Contains(cursor);
}
void BalloonCollectionImpl::SetPositionPreference(
diff --git a/chrome/browser/notifications/balloon_collection_win.cc b/chrome/browser/notifications/balloon_collection_win.cc
index 742872b..821b5f4 100644
--- a/chrome/browser/notifications/balloon_collection_win.cc
+++ b/chrome/browser/notifications/balloon_collection_win.cc
@@ -1,12 +1,12 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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/notifications/balloon_collection_impl.h"
#include "chrome/browser/notifications/balloon.h"
-#include "chrome/browser/views/notifications/balloon_view.h"
-#include "gfx/rect.h"
+#include "chrome/browser/ui/views/notifications/balloon_view.h"
+#include "ui/gfx/rect.h"
Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
Profile* profile) {
@@ -44,22 +44,9 @@ void BalloonCollectionImpl::DidProcessMessage(const MSG& msg) {
}
bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
- const Balloons& balloons = base_.balloons();
- if (balloons.empty())
- return false;
-
- gfx::Point upper_left = balloons[balloons.size() - 1]->GetPosition();
- gfx::Point lower_right = layout_.GetLayoutOrigin();
-
- gfx::Rect bounds = gfx::Rect(upper_left.x(),
- upper_left.y(),
- lower_right.x() - upper_left.x(),
- lower_right.y() - upper_left.y());
-
DWORD pos = GetMessagePos();
gfx::Point cursor(pos);
-
- return bounds.Contains(cursor);
+ return GetBalloonsBoundingBox().Contains(cursor);
}
void BalloonCollectionImpl::SetPositionPreference(
diff --git a/chrome/browser/notifications/balloon_host.cc b/chrome/browser/notifications/balloon_host.cc
index d24f3d7..6cf4ba1 100644
--- a/chrome/browser/notifications/balloon_host.cc
+++ b/chrome/browser/notifications/balloon_host.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -14,42 +14,20 @@
#include "chrome/browser/renderer_preferences_util.h"
#include "chrome/common/bindings_policy.h"
#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h"
#include "chrome/common/render_messages.h"
+#include "chrome/common/render_messages_params.h"
#include "chrome/common/renderer_preferences.h"
#include "chrome/common/url_constants.h"
#include "webkit/glue/webpreferences.h"
-namespace {
-class BalloonPaintObserver : public RenderWidgetHost::PaintObserver {
- public:
- explicit BalloonPaintObserver(BalloonHost* balloon_host)
- : balloon_host_(balloon_host) {
- }
-
- virtual void RenderWidgetHostWillPaint(RenderWidgetHost* rhw) {}
- virtual void RenderWidgetHostDidPaint(RenderWidgetHost* rwh);
-
- private:
- BalloonHost* balloon_host_;
-
- DISALLOW_COPY_AND_ASSIGN(BalloonPaintObserver);
-};
-
-void BalloonPaintObserver::RenderWidgetHostDidPaint(RenderWidgetHost* rwh) {
- balloon_host_->RenderWidgetHostDidPaint();
- // WARNING: we may have been deleted (if the balloon host cleared the paint
- // observer).
-}
-
-} // namespace
-
BalloonHost::BalloonHost(Balloon* balloon)
: render_view_host_(NULL),
balloon_(balloon),
initialized_(false),
should_notify_on_disconnect_(false),
- enable_dom_ui_(false) {
+ enable_web_ui_(false) {
DCHECK(balloon_);
// If the notification is for an extension URL, make sure to use the extension
@@ -73,7 +51,7 @@ void BalloonHost::Shutdown() {
}
}
-Browser* BalloonHost::GetBrowser() const {
+Browser* BalloonHost::GetBrowser() {
// Notifications aren't associated with a particular browser.
return NULL;
}
@@ -92,7 +70,7 @@ const string16& BalloonHost::GetSource() const {
WebPreferences BalloonHost::GetWebkitPrefs() {
WebPreferences web_prefs =
RenderViewHostDelegateHelper::GetWebkitPrefs(GetProfile(),
- enable_dom_ui_);
+ enable_web_ui_);
web_prefs.allow_scripts_to_close_windows = true;
return web_prefs;
}
@@ -151,7 +129,7 @@ RenderViewHostDelegate::View* BalloonHost::GetViewDelegate() {
return this;
}
-void BalloonHost::ProcessDOMUIMessage(
+void BalloonHost::ProcessWebUIMessage(
const ViewHostMsg_DomMessage_Params& params) {
if (extension_function_dispatcher_.get()) {
extension_function_dispatcher_->HandleRequest(params);
@@ -162,17 +140,16 @@ void BalloonHost::ProcessDOMUIMessage(
// open pages in new tabs.
void BalloonHost::CreateNewWindow(
int route_id,
- WindowContainerType window_container_type,
- const string16& frame_name) {
+ const ViewHostMsg_CreateWindow_Params& params) {
delegate_view_helper_.CreateNewWindow(
route_id,
balloon_->profile(),
site_instance_.get(),
- DOMUIFactory::GetDOMUIType(balloon_->profile(),
+ WebUIFactory::GetWebUIType(balloon_->profile(),
balloon_->notification().content_url()),
this,
- window_container_type,
- frame_name);
+ params.window_container_type,
+ params.frame_name);
}
void BalloonHost::ShowCreatedWindow(int route_id,
@@ -224,8 +201,8 @@ void BalloonHost::Init() {
if (extension_function_dispatcher_.get()) {
rvh->AllowBindings(BindingsPolicy::EXTENSION);
rvh->set_is_extension_process(true);
- } else if (enable_dom_ui_) {
- rvh->AllowBindings(BindingsPolicy::DOM_UI);
+ } else if (enable_web_ui_) {
+ rvh->AllowBindings(BindingsPolicy::WEB_UI);
}
// Do platform-specific initialization.
@@ -236,17 +213,18 @@ void BalloonHost::Init() {
rvh->set_view(render_widget_host_view());
rvh->CreateRenderView(string16());
#if defined(OS_MACOSX)
- rvh->set_paint_observer(new BalloonPaintObserver(this));
+ registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DID_PAINT,
+ Source<RenderWidgetHost>(render_view_host_));
#endif
rvh->NavigateToURL(balloon_->notification().content_url());
initialized_ = true;
}
-void BalloonHost::EnableDOMUI() {
+void BalloonHost::EnableWebUI() {
DCHECK(render_view_host_ == NULL) <<
- "EnableDOMUI has to be called before a renderer is created.";
- enable_dom_ui_ = true;
+ "EnableWebUI has to be called before a renderer is created.";
+ enable_web_ui_ = true;
}
void BalloonHost::UpdateInspectorSetting(const std::string& key,
@@ -259,10 +237,14 @@ void BalloonHost::ClearInspectorSettings() {
RenderViewHostDelegateHelper::ClearInspectorSettings(GetProfile());
}
-void BalloonHost::RenderWidgetHostDidPaint() {
- render_view_host_->set_paint_observer(NULL);
- render_view_host_->EnablePreferredSizeChangedMode(
- kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
+void BalloonHost::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::RENDER_WIDGET_HOST_DID_PAINT) {
+ registrar_.RemoveAll();
+ render_view_host_->EnablePreferredSizeChangedMode(
+ kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
+ }
}
BalloonHost::~BalloonHost() {
diff --git a/chrome/browser/notifications/balloon_host.h b/chrome/browser/notifications/balloon_host.h
index 358cb61..afb3eb1 100644
--- a/chrome/browser/notifications/balloon_host.h
+++ b/chrome/browser/notifications/balloon_host.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -12,6 +12,8 @@
#include "chrome/browser/extensions/extension_function_dispatcher.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
class Balloon;
class Browser;
@@ -22,7 +24,8 @@ struct WebPreferences;
class BalloonHost : public RenderViewHostDelegate,
public RenderViewHostDelegate::View,
- public ExtensionFunctionDispatcher::Delegate {
+ public ExtensionFunctionDispatcher::Delegate,
+ public NotificationObserver {
public:
explicit BalloonHost(Balloon* balloon);
@@ -33,7 +36,7 @@ class BalloonHost : public RenderViewHostDelegate,
void Shutdown();
// ExtensionFunctionDispatcher::Delegate overrides.
- virtual Browser* GetBrowser() const;
+ virtual Browser* GetBrowser();
virtual gfx::NativeView GetNativeViewOfHost();
virtual TabContents* associated_tab_contents() const;
@@ -57,17 +60,21 @@ class BalloonHost : public RenderViewHostDelegate,
virtual int GetBrowserWindowID() const;
virtual ViewType::Type GetRenderViewType() const;
virtual RenderViewHostDelegate::View* GetViewDelegate();
- virtual void ProcessDOMUIMessage(const ViewHostMsg_DomMessage_Params& params);
+ virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params);
+
+ // NotificationObserver override.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
// RenderViewHostDelegate::View methods. Only the ones for opening new
// windows are currently implemented.
virtual void CreateNewWindow(
int route_id,
- WindowContainerType window_container_type,
- const string16& frame_name);
+ const ViewHostMsg_CreateWindow_Params& params);
virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type) {}
- virtual void CreateNewFullscreenWidget(
- int route_id, WebKit::WebPopupType popup_type) {}
+ virtual void CreateNewFullscreenWidget(int route_id) {}
virtual void ShowCreatedWindow(int route_id,
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
@@ -105,16 +112,13 @@ class BalloonHost : public RenderViewHostDelegate,
virtual void UpdatePreferredSize(const gfx::Size& pref_size);
virtual RendererPreferences GetRendererPrefs(Profile* profile) const;
- // Enable DOM UI. This has to be called before renderer is created.
- void EnableDOMUI();
+ // Enable Web UI. This has to be called before renderer is created.
+ void EnableWebUI();
virtual void UpdateInspectorSetting(const std::string& key,
const std::string& value);
virtual void ClearInspectorSettings();
- // Called when the render view has painted.
- void RenderWidgetHostDidPaint();
-
protected:
virtual ~BalloonHost();
// Must override in platform specific implementations.
@@ -150,8 +154,10 @@ class BalloonHost : public RenderViewHostDelegate,
// rendering a page from an extension.
scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_;
- // A flag to enable DOM UI.
- bool enable_dom_ui_;
+ // A flag to enable Web UI.
+ bool enable_web_ui_;
+
+ NotificationRegistrar registrar_;
};
#endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_HOST_H_
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index a1eaeb3..0f837f9 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -1,11 +1,9 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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/notifications/desktop_notification_service.h"
-#include "app/l10n_util.h"
-#include "app/resource_bundle.h"
#include "base/metrics/histogram.h"
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
@@ -36,13 +34,171 @@
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "net/base/escape.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
using WebKit::WebNotificationPresenter;
using WebKit::WebTextDirection;
const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK;
+// NotificationPermissionCallbackTask -----------------------------------------
+
+// A task object which calls the renderer to inform the web page that the
+// permission request has completed.
+class NotificationPermissionCallbackTask : public Task {
+ public:
+ NotificationPermissionCallbackTask(int process_id,
+ int route_id,
+ int request_id);
+ virtual ~NotificationPermissionCallbackTask();
+
+ private:
+ virtual void Run();
+
+ int process_id_;
+ int route_id_;
+ int request_id_;
+};
+
+NotificationPermissionCallbackTask::NotificationPermissionCallbackTask(
+ int process_id,
+ int route_id,
+ int request_id)
+ : process_id_(process_id),
+ route_id_(route_id),
+ request_id_(request_id) {
+}
+
+NotificationPermissionCallbackTask::~NotificationPermissionCallbackTask() {
+}
+
+void NotificationPermissionCallbackTask::Run() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_);
+ if (host)
+ host->Send(new ViewMsg_PermissionRequestDone(route_id_, request_id_));
+}
+
+
+// NotificationPermissionInfoBarDelegate --------------------------------------
+
+// The delegate for the infobar shown when an origin requests notification
+// permissions.
+class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
+ public:
+ NotificationPermissionInfoBarDelegate(TabContents* contents,
+ const GURL& origin,
+ const string16& display_name,
+ int process_id,
+ int route_id,
+ int callback_context);
+
+ private:
+ virtual ~NotificationPermissionInfoBarDelegate();
+
+ // ConfirmInfoBarDelegate:
+ virtual void InfoBarClosed();
+ virtual SkBitmap* GetIcon() const;
+ virtual Type GetInfoBarType() const;
+ virtual string16 GetMessageText() const;
+ virtual string16 GetButtonLabel(InfoBarButton button) const;
+ virtual bool Accept();
+ virtual bool Cancel();
+
+ // 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.
+ string16 display_name_;
+
+ // The Profile that we restore sessions from.
+ Profile* profile_;
+
+ // The callback information that tells us how to respond to javascript via
+ // the correct RenderView.
+ int process_id_;
+ int route_id_;
+ int callback_context_;
+
+ // Whether the user clicked one of the buttons.
+ bool action_taken_;
+
+ DISALLOW_COPY_AND_ASSIGN(NotificationPermissionInfoBarDelegate);
+};
+
+NotificationPermissionInfoBarDelegate::NotificationPermissionInfoBarDelegate(
+ TabContents* contents,
+ const GURL& origin,
+ const string16& 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),
+ callback_context_(callback_context),
+ action_taken_(false) {
+}
+
+NotificationPermissionInfoBarDelegate::
+ ~NotificationPermissionInfoBarDelegate() {
+}
+
+void NotificationPermissionInfoBarDelegate::InfoBarClosed() {
+ if (!action_taken_)
+ UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1);
+
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ new NotificationPermissionCallbackTask(process_id_, route_id_,
+ callback_context_));
+
+ delete this;
+}
+
+SkBitmap* NotificationPermissionInfoBarDelegate::GetIcon() const {
+ return ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ IDR_PRODUCT_ICON_32);
+}
+
+InfoBarDelegate::Type
+ NotificationPermissionInfoBarDelegate::GetInfoBarType() const {
+ return PAGE_ACTION_TYPE;
+}
+
+string16 NotificationPermissionInfoBarDelegate::GetMessageText() const {
+ return l10n_util::GetStringFUTF16(IDS_NOTIFICATION_PERMISSIONS,
+ display_name_);
+}
+
+string16 NotificationPermissionInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
+ return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
+ IDS_NOTIFICATION_PERMISSION_YES : IDS_NOTIFICATION_PERMISSION_NO);
+}
+
+bool NotificationPermissionInfoBarDelegate::Accept() {
+ UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Allowed", 1);
+ profile_->GetDesktopNotificationService()->GrantPermission(origin_);
+ action_taken_ = true;
+ return true;
+}
+
+bool NotificationPermissionInfoBarDelegate::Cancel() {
+ UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Denied", 1);
+ profile_->GetDesktopNotificationService()->DenyPermission(origin_);
+ action_taken_ = true;
+ return true;
+}
+
+
+// DesktopNotificationService -------------------------------------------------
+
// static
string16 DesktopNotificationService::CreateDataUrl(
const GURL& icon_url, const string16& title, const string16& body,
@@ -94,123 +250,6 @@ string16 DesktopNotificationService::CreateDataUrl(
EscapeQueryParamValue(data, false));
}
-// A task object which calls the renderer to inform the web page that the
-// permission request has completed.
-class NotificationPermissionCallbackTask : public Task {
- public:
- NotificationPermissionCallbackTask(int process_id, int route_id,
- int request_id)
- : process_id_(process_id),
- route_id_(route_id),
- request_id_(request_id) {
- }
-
- virtual void Run() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_);
- if (host)
- host->Send(new ViewMsg_PermissionRequestDone(route_id_, request_id_));
- }
-
- private:
- int process_id_;
- int route_id_;
- int request_id_;
-};
-
-// The delegate for the infobar shown when an origin requests notification
-// permissions.
-class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
- public:
- NotificationPermissionInfoBarDelegate(TabContents* contents,
- const GURL& origin,
- const string16& 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),
- callback_context_(callback_context),
- action_taken_(false) {
- }
-
- // Overridden from ConfirmInfoBarDelegate:
- virtual void InfoBarClosed() {
- if (!action_taken_)
- UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1);
-
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- new NotificationPermissionCallbackTask(
- process_id_, route_id_, callback_context_));
-
- delete this;
- }
-
- virtual string16 GetMessageText() const {
- return l10n_util::GetStringFUTF16(IDS_NOTIFICATION_PERMISSIONS,
- display_name_);
- }
-
- virtual SkBitmap* GetIcon() const {
- return ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_PRODUCT_ICON_32);
- }
-
- virtual int GetButtons() const {
- return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
- }
-
- virtual string16 GetButtonLabel(InfoBarButton button) const {
- return button == BUTTON_OK ?
- l10n_util::GetStringUTF16(IDS_NOTIFICATION_PERMISSION_YES) :
- l10n_util::GetStringUTF16(IDS_NOTIFICATION_PERMISSION_NO);
- }
-
- virtual bool Accept() {
- UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Allowed", 1);
- profile_->GetDesktopNotificationService()->GrantPermission(origin_);
- action_taken_ = true;
- return true;
- }
-
- virtual bool Cancel() {
- UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Denied", 1);
- profile_->GetDesktopNotificationService()->DenyPermission(origin_);
- action_taken_ = true;
- return true;
- }
-
- // Overridden from InfoBarDelegate:
- virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; }
-
- private:
- // 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.
- string16 display_name_;
-
- // The Profile that we restore sessions from.
- Profile* profile_;
-
- // The callback information that tells us how to respond to javascript via
- // the correct RenderView.
- int process_id_;
- int route_id_;
- int callback_context_;
-
- // Whether the user clicked one of the buttons.
- bool action_taken_;
-
- DISALLOW_COPY_AND_ASSIGN(NotificationPermissionInfoBarDelegate);
-};
-
DesktopNotificationService::DesktopNotificationService(Profile* profile,
NotificationUIManager* ui_manager)
: profile_(profile),
diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h
index bb6691b..e208be3 100644
--- a/chrome/browser/notifications/desktop_notification_service.h
+++ b/chrome/browser/notifications/desktop_notification_service.h
@@ -17,7 +17,7 @@
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
#include "googleurl/src/gurl.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h"
class Notification;
class NotificationUIManager;
diff --git a/chrome/browser/notifications/desktop_notification_service_unittest.cc b/chrome/browser/notifications/desktop_notification_service_unittest.cc
index 64ad3fc..05a3dd5 100644
--- a/chrome/browser/notifications/desktop_notification_service_unittest.cc
+++ b/chrome/browser/notifications/desktop_notification_service_unittest.cc
@@ -16,7 +16,7 @@
#include "chrome/test/testing_profile.h"
#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h"
namespace {
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc
index 762990f..6effdf1 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/notifications/desktop_notifications_unittest.cc
@@ -7,6 +7,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/render_messages.h"
#include "chrome/common/render_messages_params.h"
#include "chrome/test/testing_pref_service.h"
@@ -16,6 +17,10 @@ const int MockBalloonCollection::kMockBalloonSpace = 5;
// static
std::string DesktopNotificationsTest::log_output_;
+MockBalloonCollection::MockBalloonCollection() {}
+
+MockBalloonCollection::~MockBalloonCollection() {}
+
void MockBalloonCollection::Add(const Notification& notification,
Profile* profile) {
// Swap in a logging proxy for the purpose of logging calls that
@@ -324,6 +329,39 @@ TEST_F(DesktopNotificationsTest, TestUserInputEscaping) {
EXPECT_EQ(std::string::npos, data_url.spec().find("%3ci%3e"));
}
+TEST_F(DesktopNotificationsTest, TestBoundingBox) {
+ // Create some notifications.
+ ViewHostMsg_ShowNotification_Params params = StandardTestNotification();
+ for (int id = 0; id <= 3; ++id) {
+ params.notification_id = id;
+ EXPECT_TRUE(service_->ShowDesktopNotification(
+ params, 0, 0, DesktopNotificationService::PageNotification));
+ }
+
+ gfx::Rect box = balloon_collection_->GetBalloonsBoundingBox();
+
+ // Try this for all positions.
+ BalloonCollection::PositionPreference pref;
+ for (pref = BalloonCollection::UPPER_RIGHT;
+ pref <= BalloonCollection::LOWER_LEFT;
+ pref = static_cast<BalloonCollection::PositionPreference>(pref + 1)) {
+ // Make sure each balloon's 4 corners are inside the box.
+ std::deque<Balloon*>& balloons = balloon_collection_->balloons();
+ std::deque<Balloon*>::iterator iter;
+ for (iter = balloons.begin(); iter != balloons.end(); ++iter) {
+ int min_x = (*iter)->GetPosition().x();
+ int max_x = min_x + (*iter)->GetViewSize().width() - 1;
+ int min_y = (*iter)->GetPosition().y();
+ int max_y = min_y + (*iter)->GetViewSize().height() - 1;
+
+ EXPECT_TRUE(box.Contains(gfx::Point(min_x, min_y)));
+ EXPECT_TRUE(box.Contains(gfx::Point(min_x, max_y)));
+ EXPECT_TRUE(box.Contains(gfx::Point(max_x, min_y)));
+ EXPECT_TRUE(box.Contains(gfx::Point(max_x, max_y)));
+ }
+ }
+}
+
TEST_F(DesktopNotificationsTest, TestPositionPreference) {
// Set position preference to lower right.
profile_->GetPrefs()->SetInteger(prefs::kDesktopNotificationPosition,
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.h b/chrome/browser/notifications/desktop_notifications_unittest.h
index 9f556e4..25e5270 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.h
+++ b/chrome/browser/notifications/desktop_notifications_unittest.h
@@ -17,7 +17,6 @@
#include "chrome/browser/notifications/notification_test_util.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/notifications/notifications_prefs_cache.h"
-#include "chrome/common/render_messages.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -29,7 +28,8 @@ typedef LoggingNotificationDelegate<DesktopNotificationsTest>
// of notifications that are added to it.
class MockBalloonCollection : public BalloonCollectionImpl {
public:
- MockBalloonCollection() {}
+ MockBalloonCollection();
+ virtual ~MockBalloonCollection();
// Our mock collection has an area large enough for a fixed number
// of balloons.
@@ -59,6 +59,11 @@ class MockBalloonCollection : public BalloonCollectionImpl {
int MinHeight() { return Layout::min_balloon_height(); }
int MaxHeight() { return Layout::max_balloon_height(); }
+ // Returns the bounding box.
+ gfx::Rect GetBalloonsBoundingBox() {
+ return BalloonCollectionImpl::GetBalloonsBoundingBox();
+ }
+
private:
std::deque<Balloon*> balloons_;
};
@@ -66,7 +71,7 @@ class MockBalloonCollection : public BalloonCollectionImpl {
class DesktopNotificationsTest : public testing::Test {
public:
DesktopNotificationsTest();
- ~DesktopNotificationsTest();
+ virtual ~DesktopNotificationsTest();
static void log(const std::string& message) {
log_output_.append(message);
diff --git a/chrome/browser/notifications/notification_exceptions_table_model.cc b/chrome/browser/notifications/notification_exceptions_table_model.cc
index e70536c..7a70875 100644
--- a/chrome/browser/notifications/notification_exceptions_table_model.cc
+++ b/chrome/browser/notifications/notification_exceptions_table_model.cc
@@ -4,8 +4,6 @@
#include "chrome/browser/notifications/notification_exceptions_table_model.h"
-#include "app/l10n_util.h"
-#include "app/table_model_observer.h"
#include "base/auto_reset.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_helper.h"
@@ -14,6 +12,8 @@
#include "chrome/common/notification_type.h"
#include "chrome/common/url_constants.h"
#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/models/table_model_observer.h"
struct NotificationExceptionsTableModel::Entry {
Entry(const GURL& origin, ContentSetting setting);
@@ -93,7 +93,7 @@ string16 NotificationExceptionsTableModel::GetText(int row,
}
void NotificationExceptionsTableModel::SetObserver(
- TableModelObserver* observer) {
+ ui::TableModelObserver* observer) {
observer_ = observer;
}
diff --git a/chrome/browser/notifications/notification_exceptions_table_model.h b/chrome/browser/notifications/notification_exceptions_table_model.h
index de19963..c9e2100 100644
--- a/chrome/browser/notifications/notification_exceptions_table_model.h
+++ b/chrome/browser/notifications/notification_exceptions_table_model.h
@@ -28,7 +28,7 @@ class NotificationExceptionsTableModel : public RemoveRowsTableModel,
// Overridden from TableModel:
virtual int RowCount() OVERRIDE;
virtual string16 GetText(int row, int column_id) OVERRIDE;
- virtual void SetObserver(TableModelObserver* observer) OVERRIDE;
+ virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
// Overridden from NotificationObserver:
virtual void Observe(NotificationType type,
@@ -48,7 +48,7 @@ class NotificationExceptionsTableModel : public RemoveRowsTableModel,
// that we ourselves caused.
bool updates_disabled_;
NotificationRegistrar registrar_;
- TableModelObserver* observer_;
+ ui::TableModelObserver* observer_;
DISALLOW_COPY_AND_ASSIGN(NotificationExceptionsTableModel);
};
diff --git a/chrome/browser/notifications/notification_exceptions_table_model_unittest.cc b/chrome/browser/notifications/notification_exceptions_table_model_unittest.cc
index 4fdcb24..693f1ec 100644
--- a/chrome/browser/notifications/notification_exceptions_table_model_unittest.cc
+++ b/chrome/browser/notifications/notification_exceptions_table_model_unittest.cc
@@ -4,13 +4,13 @@
#include "chrome/browser/notifications/notification_exceptions_table_model.h"
-#include "app/l10n_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
#include "chrome/test/testing_profile.h"
#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/l10n/l10n_util.h"
class NotificationExceptionsTableModelTest : public RenderViewHostTestHarness {
public:
diff --git a/chrome/browser/notifications/notification_options_menu_model.cc b/chrome/browser/notifications/notification_options_menu_model.cc
index fb05bda..c524643 100644
--- a/chrome/browser/notifications/notification_options_menu_model.cc
+++ b/chrome/browser/notifications/notification_options_menu_model.cc
@@ -4,7 +4,6 @@
#include "chrome/browser/notifications/notification_options_menu_model.h"
-#include "app/l10n_util.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
@@ -22,6 +21,7 @@
#include "chrome/common/extensions/extension.h"
#include "chrome/common/url_constants.h"
#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
#if defined(OS_WIN)
#include "chrome/browser/ui/views/browser_dialogs.h"
@@ -41,7 +41,7 @@ const int kCornerLowerRight = 14;
const int kCornerDefault = 20;
CornerSelectionMenuModel::CornerSelectionMenuModel(Balloon* balloon)
- : ALLOW_THIS_IN_INITIALIZER_LIST(menus::SimpleMenuModel(this)),
+ : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
balloon_(balloon) {
AddRadioItem(kCornerDefault,
l10n_util::GetStringUTF16(IDS_NOTIFICATION_POSITION_DEFAULT),
@@ -91,7 +91,7 @@ bool CornerSelectionMenuModel::IsCommandIdEnabled(int command_id) const {
}
bool CornerSelectionMenuModel::GetAcceleratorForCommandId(
- int command_id, menus::Accelerator* accelerator) {
+ int command_id, ui::Accelerator* accelerator) {
// Currently no accelerators.
return false;
}
@@ -116,7 +116,7 @@ void CornerSelectionMenuModel::ExecuteCommand(int command_id) {
}
NotificationOptionsMenuModel::NotificationOptionsMenuModel(Balloon* balloon)
- : ALLOW_THIS_IN_INITIALIZER_LIST(menus::SimpleMenuModel(this)),
+ : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
balloon_(balloon) {
const Notification& notification = balloon->notification();
@@ -205,7 +205,7 @@ bool NotificationOptionsMenuModel::IsCommandIdEnabled(int /* command_id */)
}
bool NotificationOptionsMenuModel::GetAcceleratorForCommandId(
- int /* command_id */, menus::Accelerator* /* accelerator */) {
+ int /* command_id */, ui::Accelerator* /* accelerator */) {
// Currently no accelerators.
return false;
}
diff --git a/chrome/browser/notifications/notification_options_menu_model.h b/chrome/browser/notifications/notification_options_menu_model.h
index 022b7e0..033f360 100644
--- a/chrome/browser/notifications/notification_options_menu_model.h
+++ b/chrome/browser/notifications/notification_options_menu_model.h
@@ -6,21 +6,21 @@
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OPTIONS_MENU_MODEL_H_
#pragma once
-#include "app/menus/simple_menu_model.h"
#include "chrome/browser/notifications/balloon.h"
+#include "ui/base/models/simple_menu_model.h"
// Model for the corner-selection submenu.
-class CornerSelectionMenuModel : public menus::SimpleMenuModel,
- public menus::SimpleMenuModel::Delegate {
+class CornerSelectionMenuModel : public ui::SimpleMenuModel,
+ public ui::SimpleMenuModel::Delegate {
public:
explicit CornerSelectionMenuModel(Balloon* balloon);
virtual ~CornerSelectionMenuModel();
- // Overridden from menus::SimpleMenuModel::Delegate:
+ // Overridden from ui::SimpleMenuModel::Delegate:
virtual bool IsCommandIdChecked(int command_id) const;
virtual bool IsCommandIdEnabled(int command_id) const;
virtual bool GetAcceleratorForCommandId(int command_id,
- menus::Accelerator* accelerator);
+ ui::Accelerator* accelerator);
virtual void ExecuteCommand(int command_id);
private:
@@ -31,21 +31,21 @@ class CornerSelectionMenuModel : public menus::SimpleMenuModel,
};
// Model for the notification options menu itself.
-class NotificationOptionsMenuModel : public menus::SimpleMenuModel,
- public menus::SimpleMenuModel::Delegate {
+class NotificationOptionsMenuModel : public ui::SimpleMenuModel,
+ public ui::SimpleMenuModel::Delegate {
public:
explicit NotificationOptionsMenuModel(Balloon* balloon);
virtual ~NotificationOptionsMenuModel();
- // Overridden from menus::SimpleMenuModel:
+ // Overridden from ui::SimpleMenuModel:
virtual bool IsItemForCommandIdDynamic(int command_id) const;
virtual string16 GetLabelForCommandId(int command_id) const;
- // Overridden from menus::SimpleMenuModel::Delegate:
+ // Overridden from ui::SimpleMenuModel::Delegate:
virtual bool IsCommandIdChecked(int command_id) const;
virtual bool IsCommandIdEnabled(int command_id) const;
virtual bool GetAcceleratorForCommandId(int command_id,
- menus::Accelerator* accelerator);
+ ui::Accelerator* accelerator);
virtual void ExecuteCommand(int command_id);
private:
diff --git a/chrome/browser/notifications/notification_test_util.h b/chrome/browser/notifications/notification_test_util.h
index fbaec4e..38863cf 100644
--- a/chrome/browser/notifications/notification_test_util.h
+++ b/chrome/browser/notifications/notification_test_util.h
@@ -10,7 +10,7 @@
#include "chrome/browser/notifications/notification_object_proxy.h"
#include "chrome/browser/notifications/balloon.h"
-#include "gfx/size.h"
+#include "ui/gfx/size.h"
// NotificationDelegate which does nothing, useful for testing when
// the notification events are not important.
diff --git a/chrome/browser/notifications/notification_ui_manager.cc b/chrome/browser/notifications/notification_ui_manager.cc
index 950bd6c..51a2c66 100644
--- a/chrome/browser/notifications/notification_ui_manager.cc
+++ b/chrome/browser/notifications/notification_ui_manager.cc
@@ -8,6 +8,8 @@
#include "base/scoped_ptr.h"
#include "base/stl_util-inl.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/fullscreen.h"
+#include "chrome/browser/idle.h"
#include "chrome/browser/notifications/balloon_collection.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -16,6 +18,10 @@
#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
+namespace {
+const int kUserStatePollingIntervalSeconds = 1;
+}
+
// A class which represents a notification waiting to be shown.
class QueuedNotification {
public:
@@ -42,14 +48,21 @@ class QueuedNotification {
};
NotificationUIManager::NotificationUIManager(PrefService* local_state)
- : balloon_collection_(NULL) {
+ : balloon_collection_(NULL),
+ is_user_active_(true) {
registrar_.Add(this, NotificationType::APP_TERMINATING,
NotificationService::AllSources());
position_pref_.Init(prefs::kDesktopNotificationPosition, local_state, this);
+#if defined(OS_MACOSX)
+ InitFullScreenMonitor();
+#endif
}
NotificationUIManager::~NotificationUIManager() {
STLDeleteElements(&show_queue_);
+#if defined(OS_MACOSX)
+ StopFullScreenMonitor();
+#endif
}
// static
@@ -126,8 +139,29 @@ void NotificationUIManager::CancelAll() {
}
void NotificationUIManager::CheckAndShowNotifications() {
- // TODO(johnnyg): http://crbug.com/25061 - Check for user idle/presentation.
- ShowNotifications();
+ CheckUserState();
+ if (is_user_active_)
+ ShowNotifications();
+}
+
+void NotificationUIManager::CheckUserState() {
+ bool is_user_active_previously = is_user_active_;
+ is_user_active_ = CalculateIdleState(0) != IDLE_STATE_LOCKED &&
+ !IsFullScreenMode();
+ if (is_user_active_ == is_user_active_previously)
+ return;
+
+ if (is_user_active_) {
+ user_state_check_timer_.Stop();
+ // We need to show any postponed nofications when the user becomes active
+ // again.
+ ShowNotifications();
+ } else if (!user_state_check_timer_.IsRunning()) {
+ // Start a timer to detect the moment at which the user becomes active.
+ user_state_check_timer_.Start(
+ base::TimeDelta::FromSeconds(kUserStatePollingIntervalSeconds), this,
+ &NotificationUIManager::CheckUserState);
+ }
}
void NotificationUIManager::ShowNotifications() {
diff --git a/chrome/browser/notifications/notification_ui_manager.h b/chrome/browser/notifications/notification_ui_manager.h
index 3a0125c..7ac63a2 100644
--- a/chrome/browser/notifications/notification_ui_manager.h
+++ b/chrome/browser/notifications/notification_ui_manager.h
@@ -11,6 +11,7 @@
#include "base/id_map.h"
#include "base/scoped_ptr.h"
+#include "base/timer.h"
#include "chrome/browser/notifications/balloon.h"
#include "chrome/browser/notifications/balloon_collection.h"
#include "chrome/browser/prefs/pref_member.h"
@@ -73,12 +74,12 @@ class NotificationUIManager
// be placed on the screen.
void SetPositionPreference(BalloonCollection::PositionPreference preference);
- // NotificationObserver interface (the event signaling kind of notifications)
+ private:
+ // NotificationObserver override.
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
- private:
// Attempts to display notifications from the show_queue if the user
// is active.
void CheckAndShowNotifications();
@@ -93,6 +94,9 @@ class NotificationUIManager
// returns true if the replacement happened.
bool TryReplacement(const Notification& notification);
+ // Checks the user state to decide if we want to show the notification.
+ void CheckUserState();
+
// An owned pointer to the collection of active balloons.
scoped_ptr<BalloonCollection> balloon_collection_;
@@ -106,6 +110,10 @@ class NotificationUIManager
// Prefs listener for the position preference.
IntegerPrefMember position_pref_;
+ // Used by screen-saver and full-screen handling support.
+ bool is_user_active_;
+ base::RepeatingTimer<NotificationUIManager> user_state_check_timer_;
+
DISALLOW_COPY_AND_ASSIGN(NotificationUIManager);
};
diff --git a/chrome/browser/notifications/notifications_interactive_uitest.cc b/chrome/browser/notifications/notifications_interactive_uitest.cc
index 43d905f..d2ace68 100644
--- a/chrome/browser/notifications/notifications_interactive_uitest.cc
+++ b/chrome/browser/notifications/notifications_interactive_uitest.cc
@@ -1,8 +1,7 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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/common/chrome_switches.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/ui/ui_test.h"
@@ -62,7 +61,7 @@ TEST_F(NotificationsPermissionTest, FLAKY_TestNoUserGestureInfobar) {
"files/notifications/notifications_request_inline.html")));
WaitUntilTabCount(1);
- int info_bar_count;
+ size_t info_bar_count;
ASSERT_TRUE(tab->GetInfoBarCount(&info_bar_count));
- EXPECT_EQ(0, info_bar_count);
+ EXPECT_EQ(0U, info_bar_count);
}
diff --git a/chrome/browser/notifications/notifications_prefs_cache.cc b/chrome/browser/notifications/notifications_prefs_cache.cc
index b1dbe2e..b7cd5f5 100644
--- a/chrome/browser/notifications/notifications_prefs_cache.cc
+++ b/chrome/browser/notifications/notifications_prefs_cache.cc
@@ -4,11 +4,13 @@
#include "chrome/browser/notifications/notifications_prefs_cache.h"
+#include <string>
+
#include "base/string_util.h"
+#include "base/values.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_thread.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h"
NotificationsPrefsCache::NotificationsPrefsCache()
: default_content_setting_(CONTENT_SETTING_DEFAULT),
diff --git a/chrome/browser/notifications/notifications_prefs_cache_unittest.cc b/chrome/browser/notifications/notifications_prefs_cache_unittest.cc
index d3bbf7d..a6dcea9 100644
--- a/chrome/browser/notifications/notifications_prefs_cache_unittest.cc
+++ b/chrome/browser/notifications/notifications_prefs_cache_unittest.cc
@@ -7,7 +7,7 @@
#include "base/message_loop.h"
#include "chrome/browser/browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h"
TEST(NotificationsPrefsCacheTest, CanCreate) {
scoped_refptr<NotificationsPrefsCache> cache(new NotificationsPrefsCache());