Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/balloon_collection_impl_win.h" | |
| 6 | |
| 7 #include "chrome/browser/extensions/extension_service.h" | |
| 8 #include "chrome/browser/notifications/balloon.h" | |
| 9 #include "chrome/browser/notifications/desktop_notification_service.h" | |
| 10 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | |
| 11 #include "chrome/browser/notifications/notification.h" | |
| 12 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 13 #include "chrome/browser/profiles/profile_manager.h" | |
| 14 #include "chrome/browser/ui/browser_finder.h" | |
| 15 #include "chrome/browser/ui/chrome_pages.h" | |
| 16 #include "chrome/browser/ui/views/balloon_view_win.h" | |
| 17 #include "chrome/browser/ui/views/message_center/web_notification_tray_win.h" | |
| 18 #include "chrome/browser/ui/views/notifications/balloon_view_host.h" | |
| 19 #include "chrome/browser/ui/views/notifications/balloon_view_views.h" | |
| 20 #include "ui/message_center/message_center_tray.h" | |
| 21 | |
| 22 BalloonCollectionImplWin::BalloonCollectionImplWin() { | |
| 23 ui::WebNotificationTrayWin* host = | |
| 24 ui::WebNotificationTrayWin::GetInstance(); | |
| 25 host->message_center()->SetDelegate(this); | |
|
sky
2013/01/18 21:30:56
You never unset this.
dewittj
2013/01/20 19:02:06
File gone.
| |
| 26 } | |
| 27 | |
| 28 BalloonCollectionImplWin::~BalloonCollectionImplWin() { | |
| 29 } | |
| 30 | |
| 31 bool BalloonCollectionImplWin::HasSpace() const { | |
| 32 return true; // Overflow is handled by messagecentertray | |
|
sky
2013/01/18 21:30:56
end with period.
dewittj
2013/01/20 19:02:06
File gone.
Pete Williamson
2013/01/23 19:52:16
nit: also camel case it: MessageCenterTray.
dewittj
2013/01/23 22:07:51
File gone.
| |
| 33 } | |
| 34 | |
| 35 void BalloonCollectionImplWin::Add(const Notification& notification, | |
| 36 Profile* profile) { | |
| 37 if (notification.is_html()) | |
| 38 return; // HTML notifications are not supported in Win. | |
|
Pete Williamson
2013/01/23 19:52:16
nit - they aren't supported anywhere afaik, so we
dewittj
2013/01/23 22:07:51
File gone.
| |
| 39 if (notification.title().empty() && notification.body().empty()) | |
| 40 return; // Empty notification, don't show. | |
| 41 return BalloonCollectionImpl::Add(notification, profile); | |
| 42 } | |
| 43 | |
| 44 void BalloonCollectionImplWin::DisableExtension( | |
| 45 const std::string& notification_id) { | |
| 46 Balloon* balloon = base().FindBalloonById(notification_id); | |
| 47 const extensions::Extension* extension = GetBalloonExtension(balloon); | |
| 48 if (!extension) | |
| 49 return; | |
| 50 balloon->profile()->GetExtensionService()->DisableExtension( | |
| 51 extension->id(), extensions::Extension::DISABLE_USER_ACTION); | |
| 52 } | |
| 53 | |
| 54 void BalloonCollectionImplWin::DisableNotificationsFromSource( | |
| 55 const std::string& notification_id) { | |
| 56 Balloon* balloon = base().FindBalloonById(notification_id); | |
| 57 if (!balloon) | |
| 58 return; | |
| 59 DesktopNotificationService* service = | |
| 60 DesktopNotificationServiceFactory::GetForProfile(balloon->profile()); | |
| 61 service->DenyPermission(balloon->notification().origin_url()); | |
| 62 } | |
| 63 | |
|
Pete Williamson
2013/01/23 19:52:16
Overall comment - there is a lot of similarity bet
dewittj
2013/01/23 22:07:51
File gone.
| |
| 64 void BalloonCollectionImplWin::NotificationRemoved( | |
| 65 const std::string& notification_id) { | |
| 66 RemoveById(notification_id); | |
| 67 } | |
| 68 | |
| 69 void BalloonCollectionImplWin::ShowSettings( | |
| 70 const std::string& notification_id) { | |
| 71 Balloon* balloon = base().FindBalloonById(notification_id); | |
| 72 Profile* profile = | |
| 73 balloon ? balloon->profile() : ProfileManager::GetDefaultProfile(); | |
| 74 Browser* browser = chrome::FindOrCreateTabbedBrowser( | |
| 75 profile, | |
| 76 chrome::HOST_DESKTOP_TYPE_NATIVE); | |
| 77 if (GetBalloonExtension(balloon)) | |
| 78 chrome::ShowExtensions(browser); | |
| 79 else | |
| 80 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
| 81 } | |
| 82 | |
| 83 void BalloonCollectionImplWin::OnClicked(const std::string& notification_id) { | |
| 84 Balloon* balloon = base().FindBalloonById(notification_id); | |
| 85 if (!balloon) | |
| 86 return; | |
| 87 balloon->OnClick(); | |
| 88 } | |
| 89 | |
| 90 void BalloonCollectionImplWin::OnButtonClicked( | |
| 91 const std::string& notification_id, int button_index) { | |
| 92 Balloon* balloon = base().FindBalloonById(notification_id); | |
| 93 if (balloon) | |
| 94 balloon->OnButtonClick(button_index); | |
| 95 } | |
| 96 | |
| 97 bool BalloonCollectionImplWin::UpdateNotification( | |
| 98 const Notification& notification) { | |
| 99 Balloon* balloon = base().FindBalloon(notification); | |
| 100 if (!balloon) | |
| 101 return false; | |
| 102 balloon->Update(notification); | |
| 103 return true; | |
| 104 } | |
| 105 | |
| 106 bool BalloonCollectionImplWin::UpdateAndShowNotification( | |
| 107 const Notification& notification) { | |
| 108 return UpdateNotification(notification); | |
| 109 } | |
| 110 | |
| 111 Balloon* BalloonCollectionImplWin::MakeBalloon( | |
| 112 const Notification& notification, Profile* profile) { | |
| 113 Balloon* balloon = new Balloon(notification, profile, this); | |
| 114 BalloonViewWin* balloon_view = new BalloonViewWin(this); | |
| 115 balloon->set_view(balloon_view); | |
| 116 return balloon; | |
| 117 } | |
| 118 | |
| 119 const extensions::Extension* BalloonCollectionImplWin::GetBalloonExtension( | |
| 120 Balloon* balloon) { | |
| 121 if (!balloon) | |
| 122 return NULL; | |
| 123 ExtensionService* extension_service = | |
| 124 balloon->profile()->GetExtensionService(); | |
| 125 const GURL& origin = balloon->notification().origin_url(); | |
| 126 return extension_service->extensions()->GetExtensionOrAppByURL( | |
| 127 ExtensionURLInfo(origin)); | |
| 128 } | |
| 129 | |
| 130 #if defined(OS_WIN) | |
|
Pete Williamson
2013/01/23 19:52:16
Why do we need this #define? I would have expecte
dewittj
2013/01/23 22:07:51
File gone.
| |
| 131 // static | |
| 132 BalloonCollection* BalloonCollection::Create() { | |
| 133 if (NotificationUIManager::DelegatesToMessageCenter()) | |
| 134 return new BalloonCollectionImplWin(); | |
| 135 return new BalloonCollectionImpl(); | |
| 136 } | |
| 137 #endif | |
| OLD | NEW |