| 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/balloon_collection_impl_win.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/system/web_notification/web_notification_tray.h" | |
| 9 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/notifications/balloon.h" | 8 #include "chrome/browser/notifications/balloon.h" |
| 11 #include "chrome/browser/notifications/desktop_notification_service.h" | 9 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 12 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 10 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 13 #include "chrome/browser/notifications/notification.h" | 11 #include "chrome/browser/notifications/notification.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 16 #include "chrome/browser/ui/chrome_pages.h" | 14 #include "chrome/browser/ui/chrome_pages.h" |
| 17 #include "chrome/browser/ui/views/ash/balloon_view_ash.h" | 15 #include "chrome/browser/ui/views/balloon_view_win.h" |
| 16 #include "chrome/browser/ui/views/message_center/message_center_tray_host_win.h" |
| 18 #include "chrome/browser/ui/views/notifications/balloon_view_host.h" | 17 #include "chrome/browser/ui/views/notifications/balloon_view_host.h" |
| 19 #include "chrome/browser/ui/views/notifications/balloon_view_views.h" | 18 #include "chrome/browser/ui/views/notifications/balloon_view_views.h" |
| 19 #include "ui/message_center/message_center_tray.h" |
| 20 #include "ui/message_center/message_center_tray_host.h" |
| 20 | 21 |
| 21 BalloonCollectionImplAsh::BalloonCollectionImplAsh() { | 22 BalloonCollectionImplWin::BalloonCollectionImplWin() { |
| 22 ash::Shell::GetInstance()->GetWebNotificationTray()->message_center()-> | 23 ui::MessageCenterTrayHost* host = ui::MessageCenterTrayHostWin::GetInstance(); |
| 23 SetDelegate(this); | 24 host->message_center()->SetDelegate(this); |
| 24 } | 25 } |
| 25 | 26 |
| 26 BalloonCollectionImplAsh::~BalloonCollectionImplAsh() { | 27 BalloonCollectionImplWin::~BalloonCollectionImplWin() { |
| 27 } | 28 } |
| 28 | 29 |
| 29 bool BalloonCollectionImplAsh::HasSpace() const { | 30 bool BalloonCollectionImplWin::HasSpace() const { |
| 30 return true; // Overflow is handled by ash::WebNotificationTray. | 31 return true; // Overflow is handled by messagecentertray |
| 31 } | 32 } |
| 32 | 33 |
| 33 void BalloonCollectionImplAsh::Add(const Notification& notification, | 34 void BalloonCollectionImplWin::Add(const Notification& notification, |
| 34 Profile* profile) { | 35 Profile* profile) { |
| 35 if (notification.is_html()) | 36 if (notification.is_html()) |
| 36 return; // HTML notifications are not supported in Ash. | 37 return; // HTML notifications are not supported in Win. |
| 37 if (notification.title().empty() && notification.body().empty()) | 38 if (notification.title().empty() && notification.body().empty()) |
| 38 return; // Empty notification, don't show. | 39 return; // Empty notification, don't show. |
| 39 return BalloonCollectionImpl::Add(notification, profile); | 40 return BalloonCollectionImpl::Add(notification, profile); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void BalloonCollectionImplAsh::DisableExtension( | 43 void BalloonCollectionImplWin::DisableExtension( |
| 43 const std::string& notification_id) { | 44 const std::string& notification_id) { |
| 44 Balloon* balloon = base().FindBalloonById(notification_id); | 45 Balloon* balloon = base().FindBalloonById(notification_id); |
| 45 const extensions::Extension* extension = GetBalloonExtension(balloon); | 46 const extensions::Extension* extension = GetBalloonExtension(balloon); |
| 46 if (!extension) | 47 if (!extension) |
| 47 return; | 48 return; |
| 48 balloon->profile()->GetExtensionService()->DisableExtension( | 49 balloon->profile()->GetExtensionService()->DisableExtension( |
| 49 extension->id(), extensions::Extension::DISABLE_USER_ACTION); | 50 extension->id(), extensions::Extension::DISABLE_USER_ACTION); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void BalloonCollectionImplAsh::DisableNotificationsFromSource( | 53 void BalloonCollectionImplWin::DisableNotificationsFromSource( |
| 53 const std::string& notification_id) { | 54 const std::string& notification_id) { |
| 54 Balloon* balloon = base().FindBalloonById(notification_id); | 55 Balloon* balloon = base().FindBalloonById(notification_id); |
| 55 if (!balloon) | 56 if (!balloon) |
| 56 return; | 57 return; |
| 57 DesktopNotificationService* service = | 58 DesktopNotificationService* service = |
| 58 DesktopNotificationServiceFactory::GetForProfile(balloon->profile()); | 59 DesktopNotificationServiceFactory::GetForProfile(balloon->profile()); |
| 59 service->DenyPermission(balloon->notification().origin_url()); | 60 service->DenyPermission(balloon->notification().origin_url()); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void BalloonCollectionImplAsh::NotificationRemoved( | 63 void BalloonCollectionImplWin::NotificationRemoved( |
| 63 const std::string& notification_id) { | 64 const std::string& notification_id) { |
| 64 RemoveById(notification_id); | 65 RemoveById(notification_id); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void BalloonCollectionImplAsh::ShowSettings( | 68 void BalloonCollectionImplWin::ShowSettings( |
| 68 const std::string& notification_id) { | 69 const std::string& notification_id) { |
| 69 Balloon* balloon = base().FindBalloonById(notification_id); | 70 Balloon* balloon = base().FindBalloonById(notification_id); |
| 70 Profile* profile = | 71 Profile* profile = |
| 71 balloon ? balloon->profile() : ProfileManager::GetDefaultProfile(); | 72 balloon ? balloon->profile() : ProfileManager::GetDefaultProfile(); |
| 72 Browser* browser = | 73 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 73 chrome::FindOrCreateTabbedBrowser(profile, | 74 profile, |
| 74 chrome::HOST_DESKTOP_TYPE_ASH); | 75 chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 75 if (GetBalloonExtension(balloon)) | 76 if (GetBalloonExtension(balloon)) |
| 76 chrome::ShowExtensions(browser); | 77 chrome::ShowExtensions(browser); |
| 77 else | 78 else |
| 78 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 79 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 79 } | 80 } |
| 80 | 81 |
| 81 void BalloonCollectionImplAsh::OnClicked(const std::string& notification_id) { | 82 void BalloonCollectionImplWin::OnClicked(const std::string& notification_id) { |
| 82 Balloon* balloon = base().FindBalloonById(notification_id); | 83 Balloon* balloon = base().FindBalloonById(notification_id); |
| 83 if (!balloon) | 84 if (!balloon) |
| 84 return; | 85 return; |
| 85 balloon->OnClick(); | 86 balloon->OnClick(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void BalloonCollectionImplAsh::OnButtonClicked( | 89 void BalloonCollectionImplWin::OnButtonClicked( |
| 89 const std::string& notification_id, int button_index) { | 90 const std::string& notification_id, int button_index) { |
| 90 Balloon* balloon = base().FindBalloonById(notification_id); | 91 Balloon* balloon = base().FindBalloonById(notification_id); |
| 91 if (balloon) | 92 if (balloon) |
| 92 balloon->OnButtonClick(button_index); | 93 balloon->OnButtonClick(button_index); |
| 93 } | 94 } |
| 94 | 95 |
| 95 bool BalloonCollectionImplAsh::AddWebUIMessageCallback( | 96 bool BalloonCollectionImplWin::UpdateNotification( |
| 96 const Notification& notification, | |
| 97 const std::string& message, | |
| 98 const chromeos::BalloonViewHost::MessageCallback& callback) { | |
| 99 #if defined(OS_CHROMEOS) | |
| 100 Balloon* balloon = base().FindBalloon(notification); | |
| 101 if (!balloon) | |
| 102 return false; | |
| 103 | |
| 104 BalloonHost* balloon_host = balloon->balloon_view()->GetHost(); | |
| 105 if (!balloon_host) | |
| 106 return false; | |
| 107 chromeos::BalloonViewHost* balloon_view_host = | |
| 108 static_cast<chromeos::BalloonViewHost*>(balloon_host); | |
| 109 return balloon_view_host->AddWebUIMessageCallback(message, callback); | |
| 110 #else | |
| 111 return false; | |
| 112 #endif | |
| 113 } | |
| 114 | |
| 115 bool BalloonCollectionImplAsh::UpdateNotification( | |
| 116 const Notification& notification) { | 97 const Notification& notification) { |
| 117 Balloon* balloon = base().FindBalloon(notification); | 98 Balloon* balloon = base().FindBalloon(notification); |
| 118 if (!balloon) | 99 if (!balloon) |
| 119 return false; | 100 return false; |
| 120 balloon->Update(notification); | 101 balloon->Update(notification); |
| 121 return true; | 102 return true; |
| 122 } | 103 } |
| 123 | 104 |
| 124 bool BalloonCollectionImplAsh::UpdateAndShowNotification( | 105 bool BalloonCollectionImplWin::UpdateAndShowNotification( |
| 125 const Notification& notification) { | 106 const Notification& notification) { |
| 126 return UpdateNotification(notification); | 107 return UpdateNotification(notification); |
| 127 } | 108 } |
| 128 | 109 |
| 129 Balloon* BalloonCollectionImplAsh::MakeBalloon( | 110 Balloon* BalloonCollectionImplWin::MakeBalloon( |
| 130 const Notification& notification, Profile* profile) { | 111 const Notification& notification, Profile* profile) { |
| 131 Balloon* balloon = new Balloon(notification, profile, this); | 112 Balloon* balloon = new Balloon(notification, profile, this); |
| 132 BalloonViewAsh* balloon_view = new BalloonViewAsh(this); | 113 BalloonViewWin* balloon_view = new BalloonViewWin(this); |
| 133 balloon->set_view(balloon_view); | 114 balloon->set_view(balloon_view); |
| 134 return balloon; | 115 return balloon; |
| 135 } | 116 } |
| 136 | 117 |
| 137 const extensions::Extension* BalloonCollectionImplAsh::GetBalloonExtension( | 118 const extensions::Extension* BalloonCollectionImplWin::GetBalloonExtension( |
| 138 Balloon* balloon) { | 119 Balloon* balloon) { |
| 139 if (!balloon) | 120 if (!balloon) |
| 140 return NULL; | 121 return NULL; |
| 141 ExtensionService* extension_service = | 122 ExtensionService* extension_service = |
| 142 balloon->profile()->GetExtensionService(); | 123 balloon->profile()->GetExtensionService(); |
| 143 const GURL& origin = balloon->notification().origin_url(); | 124 const GURL& origin = balloon->notification().origin_url(); |
| 144 return extension_service->extensions()->GetExtensionOrAppByURL( | 125 return extension_service->extensions()->GetExtensionOrAppByURL( |
| 145 ExtensionURLInfo(origin)); | 126 ExtensionURLInfo(origin)); |
| 146 } | 127 } |
| 147 | 128 |
| 148 #if defined(OS_CHROMEOS) | 129 #if defined(OS_WIN) |
| 149 // static | 130 // static |
| 150 BalloonCollection* BalloonCollection::Create() { | 131 BalloonCollection* BalloonCollection::Create() { |
| 151 return new BalloonCollectionImplAsh(); | 132 return new BalloonCollectionImplWin(); |
| 152 } | 133 } |
| 153 #endif | 134 #endif |
| OLD | NEW |