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

Unified Diff: chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc

Issue 10537158: Add support for Ash to Notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc
diff --git a/chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc b/chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc
index 646af7d136d9bd501743a84c3a8685745e6e99e7..bac4bfa7a01a15273ed37bf334a20fdbdba65c21 100644
--- a/chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc
+++ b/chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc
@@ -4,17 +4,99 @@
#include "chrome/browser/ui/views/ash/balloon_collection_impl_ash.h"
+#include "ash/ash_switches.h"
+#include "ash/shell.h"
+#include "ash/system/status_area_widget.h"
+#include "base/command_line.h"
+#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/notifications/balloon.h"
+#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "chrome/browser/notifications/desktop_notification_service_factory.h"
#include "chrome/browser/notifications/notification.h"
-#include "chrome/browser/ui/views/notifications/balloon_view_views.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/views/ash/balloon_view_ash.h"
#include "chrome/browser/ui/views/notifications/balloon_view_host.h"
+#include "chrome/browser/ui/views/notifications/balloon_view_views.h"
BalloonCollectionImplAsh::BalloonCollectionImplAsh() {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ ash::switches::kAshNotify)) {
oshima 2012/06/13 23:58:02 how about defining a utility function like IsAshNo
stevenjb 2012/06/14 04:27:35 Good suggestion. Done.
+ ash::Shell::GetInstance()->status_area_widget()->
+ web_notification_tray()->SetDelegate(this);
+ }
}
BalloonCollectionImplAsh::~BalloonCollectionImplAsh() {
}
+bool BalloonCollectionImplAsh::HasSpace() const {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ ash::switches::kAshNotify)) {
+ return BalloonCollectionImpl::HasSpace();
+ }
+ return true; // Overflow is handled by ash::WebNotificationTray.
+}
+
+void BalloonCollectionImplAsh::Add(const Notification& notification,
+ Profile* profile) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ ash::switches::kAshNotify)) {
+ if (notification.is_html())
+ return; // HTML notifications are not supported in Ash.
oshima 2012/06/13 23:58:02 oh, what will happen to gmail/calendar notificatio
stevenjb 2012/06/14 04:27:35 gmail/cal/talk all use title+text+icon based notif
+ if (notification.title().empty() && notification.body().empty())
+ return; // Empty notification, don't show.
+ }
+ return BalloonCollectionImpl::Add(notification, profile);
+}
+
+void BalloonCollectionImplAsh::DisableExtension(
+ const std::string& notifcation_id) {
+ Balloon* balloon = base().FindBalloonById(notifcation_id);
+ if (!balloon)
+ return;
+ ExtensionService* extension_service =
+ balloon->profile()->GetExtensionService();
+ const GURL& origin = balloon->notification().origin_url();
+ const extensions::Extension* extension =
+ extension_service->extensions()->GetExtensionOrAppByURL(
+ ExtensionURLInfo(origin));
+ if (!extension)
+ return;
+ extension_service->DisableExtension(
+ extension->id(), extensions::Extension::DISABLE_USER_ACTION);
+}
+
+void BalloonCollectionImplAsh::DisableNotificationsFromSource(
+ const std::string& notifcation_id) {
+ Balloon* balloon = base().FindBalloonById(notifcation_id);
+ if (!balloon)
+ return;
+ DesktopNotificationService* service =
+ DesktopNotificationServiceFactory::GetForProfile(balloon->profile());
+ service->DenyPermission(balloon->notification().origin_url());
+}
+
+void BalloonCollectionImplAsh::NotificationRemoved(
+ const std::string& notifcation_id) {
+ RemoveById(notifcation_id);
+}
+
+void BalloonCollectionImplAsh::ShowSettings(const std::string& notifcation_id) {
+ Balloon* balloon = base().FindBalloonById(notifcation_id);
+ Profile* profile =
+ balloon ? balloon->profile() : ProfileManager::GetDefaultProfile();
+ Browser* browser = browser::FindOrCreateTabbedBrowser(profile);
+ browser->ShowContentSettingsPage(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+}
+
+void BalloonCollectionImplAsh::OnClicked(const std::string& notifcation_id) {
+ Balloon* balloon = base().FindBalloonById(notifcation_id);
+ if (!balloon)
+ return;
+ balloon->OnClick();
+}
+
bool BalloonCollectionImplAsh::AddWebUIMessageCallback(
const Notification& notification,
const std::string& message,
@@ -65,13 +147,19 @@ bool BalloonCollectionImplAsh::UpdateAndShowNotification(
Balloon* BalloonCollectionImplAsh::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);
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ ash::switches::kAshNotify)) {
+ ::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);
+ } else {
+ BalloonViewAsh* balloon_view = new BalloonViewAsh(this);
+ balloon->set_view(balloon_view);
+ }
return balloon;
}

Powered by Google App Engine
This is Rietveld 408576698