Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/ash/balloon_collection_impl_ash.h" | 5 #include "chrome/browser/ui/views/ash/balloon_collection_impl_ash.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | |
| 8 #include "ash/shell.h" | |
| 9 #include "ash/system/status_area_widget.h" | |
| 10 #include "base/command_line.h" | |
| 11 #include "chrome/browser/extensions/extension_service.h" | |
| 7 #include "chrome/browser/notifications/balloon.h" | 12 #include "chrome/browser/notifications/balloon.h" |
| 13 #include "chrome/browser/notifications/desktop_notification_service.h" | |
| 14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | |
| 8 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" | |
| 17 #include "chrome/browser/ui/browser_finder.h" | |
| 18 #include "chrome/browser/ui/views/ash/balloon_view_ash.h" | |
| 19 #include "chrome/browser/ui/views/notifications/balloon_view_host.h" | |
| 9 #include "chrome/browser/ui/views/notifications/balloon_view_views.h" | 20 #include "chrome/browser/ui/views/notifications/balloon_view_views.h" |
| 10 #include "chrome/browser/ui/views/notifications/balloon_view_host.h" | |
| 11 | 21 |
| 12 BalloonCollectionImplAsh::BalloonCollectionImplAsh() { | 22 BalloonCollectionImplAsh::BalloonCollectionImplAsh() { |
| 23 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 24 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.
| |
| 25 ash::Shell::GetInstance()->status_area_widget()-> | |
| 26 web_notification_tray()->SetDelegate(this); | |
| 27 } | |
| 13 } | 28 } |
| 14 | 29 |
| 15 BalloonCollectionImplAsh::~BalloonCollectionImplAsh() { | 30 BalloonCollectionImplAsh::~BalloonCollectionImplAsh() { |
| 16 } | 31 } |
| 17 | 32 |
| 33 bool BalloonCollectionImplAsh::HasSpace() const { | |
| 34 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 35 ash::switches::kAshNotify)) { | |
| 36 return BalloonCollectionImpl::HasSpace(); | |
| 37 } | |
| 38 return true; // Overflow is handled by ash::WebNotificationTray. | |
| 39 } | |
| 40 | |
| 41 void BalloonCollectionImplAsh::Add(const Notification& notification, | |
| 42 Profile* profile) { | |
| 43 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 44 ash::switches::kAshNotify)) { | |
| 45 if (notification.is_html()) | |
| 46 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
| |
| 47 if (notification.title().empty() && notification.body().empty()) | |
| 48 return; // Empty notification, don't show. | |
| 49 } | |
| 50 return BalloonCollectionImpl::Add(notification, profile); | |
| 51 } | |
| 52 | |
| 53 void BalloonCollectionImplAsh::DisableExtension( | |
| 54 const std::string& notifcation_id) { | |
| 55 Balloon* balloon = base().FindBalloonById(notifcation_id); | |
| 56 if (!balloon) | |
| 57 return; | |
| 58 ExtensionService* extension_service = | |
| 59 balloon->profile()->GetExtensionService(); | |
| 60 const GURL& origin = balloon->notification().origin_url(); | |
| 61 const extensions::Extension* extension = | |
| 62 extension_service->extensions()->GetExtensionOrAppByURL( | |
| 63 ExtensionURLInfo(origin)); | |
| 64 if (!extension) | |
| 65 return; | |
| 66 extension_service->DisableExtension( | |
| 67 extension->id(), extensions::Extension::DISABLE_USER_ACTION); | |
| 68 } | |
| 69 | |
| 70 void BalloonCollectionImplAsh::DisableNotificationsFromSource( | |
| 71 const std::string& notifcation_id) { | |
| 72 Balloon* balloon = base().FindBalloonById(notifcation_id); | |
| 73 if (!balloon) | |
| 74 return; | |
| 75 DesktopNotificationService* service = | |
| 76 DesktopNotificationServiceFactory::GetForProfile(balloon->profile()); | |
| 77 service->DenyPermission(balloon->notification().origin_url()); | |
| 78 } | |
| 79 | |
| 80 void BalloonCollectionImplAsh::NotificationRemoved( | |
| 81 const std::string& notifcation_id) { | |
| 82 RemoveById(notifcation_id); | |
| 83 } | |
| 84 | |
| 85 void BalloonCollectionImplAsh::ShowSettings(const std::string& notifcation_id) { | |
| 86 Balloon* balloon = base().FindBalloonById(notifcation_id); | |
| 87 Profile* profile = | |
| 88 balloon ? balloon->profile() : ProfileManager::GetDefaultProfile(); | |
| 89 Browser* browser = browser::FindOrCreateTabbedBrowser(profile); | |
| 90 browser->ShowContentSettingsPage(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
| 91 } | |
| 92 | |
| 93 void BalloonCollectionImplAsh::OnClicked(const std::string& notifcation_id) { | |
| 94 Balloon* balloon = base().FindBalloonById(notifcation_id); | |
| 95 if (!balloon) | |
| 96 return; | |
| 97 balloon->OnClick(); | |
| 98 } | |
| 99 | |
| 18 bool BalloonCollectionImplAsh::AddWebUIMessageCallback( | 100 bool BalloonCollectionImplAsh::AddWebUIMessageCallback( |
| 19 const Notification& notification, | 101 const Notification& notification, |
| 20 const std::string& message, | 102 const std::string& message, |
| 21 const chromeos::BalloonViewHost::MessageCallback& callback) { | 103 const chromeos::BalloonViewHost::MessageCallback& callback) { |
| 22 #if defined(OS_CHROMEOS) | 104 #if defined(OS_CHROMEOS) |
| 23 Balloon* balloon = base().FindBalloon(notification); | 105 Balloon* balloon = base().FindBalloon(notification); |
| 24 if (!balloon) | 106 if (!balloon) |
| 25 return false; | 107 return false; |
| 26 | 108 |
| 27 BalloonHost* balloon_host = balloon->balloon_view()->GetHost(); | 109 BalloonHost* balloon_host = balloon->balloon_view()->GetHost(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 58 } | 140 } |
| 59 | 141 |
| 60 bool BalloonCollectionImplAsh::UpdateAndShowNotification( | 142 bool BalloonCollectionImplAsh::UpdateAndShowNotification( |
| 61 const Notification& notification) { | 143 const Notification& notification) { |
| 62 return UpdateNotification(notification); | 144 return UpdateNotification(notification); |
| 63 } | 145 } |
| 64 | 146 |
| 65 Balloon* BalloonCollectionImplAsh::MakeBalloon( | 147 Balloon* BalloonCollectionImplAsh::MakeBalloon( |
| 66 const Notification& notification, Profile* profile) { | 148 const Notification& notification, Profile* profile) { |
| 67 Balloon* balloon = new Balloon(notification, profile, this); | 149 Balloon* balloon = new Balloon(notification, profile, this); |
| 68 ::BalloonViewImpl* balloon_view = new ::BalloonViewImpl(this); | 150 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 69 if (system_notifications_.find(notification.notification_id()) != | 151 ash::switches::kAshNotify)) { |
| 70 system_notifications_.end()) | 152 ::BalloonViewImpl* balloon_view = new ::BalloonViewImpl(this); |
| 71 balloon_view->set_enable_web_ui(true); | 153 if (system_notifications_.find(notification.notification_id()) != |
| 72 balloon->set_view(balloon_view); | 154 system_notifications_.end()) |
| 73 gfx::Size size(layout().min_balloon_width(), layout().min_balloon_height()); | 155 balloon_view->set_enable_web_ui(true); |
| 74 balloon->set_content_size(size); | 156 balloon->set_view(balloon_view); |
| 157 gfx::Size size(layout().min_balloon_width(), layout().min_balloon_height()); | |
| 158 balloon->set_content_size(size); | |
| 159 } else { | |
| 160 BalloonViewAsh* balloon_view = new BalloonViewAsh(this); | |
| 161 balloon->set_view(balloon_view); | |
| 162 } | |
| 75 return balloon; | 163 return balloon; |
| 76 } | 164 } |
| 77 | 165 |
| 78 // For now, only use BalloonCollectionImplAsh on ChromeOS, until | 166 // For now, only use BalloonCollectionImplAsh on ChromeOS, until |
| 79 // system_notifications_ is replaced with status area notifications. | 167 // system_notifications_ is replaced with status area notifications. |
| 80 #if defined(OS_CHROMEOS) | 168 #if defined(OS_CHROMEOS) |
| 81 // static | 169 // static |
| 82 BalloonCollection* BalloonCollection::Create() { | 170 BalloonCollection* BalloonCollection::Create() { |
| 83 return new BalloonCollectionImplAsh(); | 171 return new BalloonCollectionImplAsh(); |
| 84 } | 172 } |
| 85 #endif | 173 #endif |
| OLD | NEW |