| 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 "ash/system/web_notification/web_notification_tray.h" | 5 #include "ash/system/web_notification/web_notification_tray.h" |
| 6 | 6 |
| 7 #include "ash/system/status_area_widget.h" | 7 #include "ash/system/status_area_widget.h" |
| 8 #include "ash/system/tray/system_tray.h" | 8 #include "ash/system/tray/system_tray.h" |
| 9 #include "ash/system/tray/tray_bubble_view.h" | 9 #include "ash/system/tray/tray_bubble_view.h" |
| 10 #include "ash/system/tray/tray_constants.h" | 10 #include "ash/system/tray/tray_constants.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 if (iter == notifications_.end()) | 155 if (iter == notifications_.end()) |
| 156 return false; | 156 return false; |
| 157 EraseNotification(iter); | 157 EraseNotification(iter); |
| 158 return true; | 158 return true; |
| 159 } | 159 } |
| 160 | 160 |
| 161 void RemoveAllNotifications() { | 161 void RemoveAllNotifications() { |
| 162 notifications_.clear(); | 162 notifications_.clear(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void RemoveNotificationsBySource(const std::string& id) { | 165 void SendRemoveNotificationsBySource(WebNotificationTray* tray, |
| 166 const std::string& id) { |
| 166 Notifications::iterator source_iter = GetNotification(id); | 167 Notifications::iterator source_iter = GetNotification(id); |
| 167 if (source_iter == notifications_.end()) | 168 if (source_iter == notifications_.end()) |
| 168 return; | 169 return; |
| 169 string16 display_source = source_iter->display_source; | 170 string16 display_source = source_iter->display_source; |
| 170 for (Notifications::iterator loopiter = notifications_.begin(); | 171 for (Notifications::iterator loopiter = notifications_.begin(); |
| 171 loopiter != notifications_.end(); ) { | 172 loopiter != notifications_.end(); ) { |
| 172 Notifications::iterator curiter = loopiter++; | 173 Notifications::iterator curiter = loopiter++; |
| 173 if (curiter->display_source == display_source) | 174 if (curiter->display_source == display_source) |
| 174 EraseNotification(curiter); | 175 tray->SendRemoveNotification(curiter->id); |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 | 178 |
| 178 void RemoveNotificationsByExtension(const std::string& id) { | 179 void SendRemoveNotificationsByExtension(WebNotificationTray* tray, |
| 180 const std::string& id) { |
| 179 Notifications::iterator source_iter = GetNotification(id); | 181 Notifications::iterator source_iter = GetNotification(id); |
| 180 if (source_iter == notifications_.end()) | 182 if (source_iter == notifications_.end()) |
| 181 return; | 183 return; |
| 182 std::string extension_id = source_iter->extension_id; | 184 std::string extension_id = source_iter->extension_id; |
| 183 for (Notifications::iterator loopiter = notifications_.begin(); | 185 for (Notifications::iterator loopiter = notifications_.begin(); |
| 184 loopiter != notifications_.end(); ) { | 186 loopiter != notifications_.end(); ) { |
| 185 Notifications::iterator curiter = loopiter++; | 187 Notifications::iterator curiter = loopiter++; |
| 186 if (curiter->extension_id == extension_id) | 188 if (curiter->extension_id == extension_id) |
| 187 EraseNotification(curiter); | 189 tray->SendRemoveNotification(curiter->id); |
| 188 } | 190 } |
| 189 } | 191 } |
| 190 | 192 |
| 191 bool SetNotificationImage(const std::string& id, | 193 bool SetNotificationImage(const std::string& id, |
| 192 const gfx::ImageSkia& image) { | 194 const gfx::ImageSkia& image) { |
| 193 Notifications::iterator iter = GetNotification(id); | 195 Notifications::iterator iter = GetNotification(id); |
| 194 if (iter == notifications_.end()) | 196 if (iter == notifications_.end()) |
| 195 return false; | 197 return false; |
| 196 iter->image = image; | 198 iter->image = image; |
| 197 return true; | 199 return true; |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 std::string notification_id = curiter->id; | 990 std::string notification_id = curiter->id; |
| 989 // May call RemoveNotification and erase curiter. | 991 // May call RemoveNotification and erase curiter. |
| 990 delegate_->NotificationRemoved(notification_id); | 992 delegate_->NotificationRemoved(notification_id); |
| 991 } | 993 } |
| 992 } | 994 } |
| 993 } | 995 } |
| 994 | 996 |
| 995 // When we disable notifications, we remove any existing matching | 997 // When we disable notifications, we remove any existing matching |
| 996 // notifications to avoid adding complicated UI to re-enable the source. | 998 // notifications to avoid adding complicated UI to re-enable the source. |
| 997 void WebNotificationTray::DisableByExtension(const std::string& id) { | 999 void WebNotificationTray::DisableByExtension(const std::string& id) { |
| 998 // Will call SendRemoveNotification for each matching notification. | |
| 999 notification_list_->RemoveNotificationsByExtension(id); | |
| 1000 if (delegate_) | 1000 if (delegate_) |
| 1001 delegate_->DisableExtension(id); | 1001 delegate_->DisableExtension(id); |
| 1002 // Will call SendRemoveNotification for each matching notification. |
| 1003 notification_list_->SendRemoveNotificationsByExtension(this, id); |
| 1002 } | 1004 } |
| 1003 | 1005 |
| 1004 void WebNotificationTray::DisableByUrl(const std::string& id) { | 1006 void WebNotificationTray::DisableByUrl(const std::string& id) { |
| 1005 // Will call SendRemoveNotification for each matching notification. | |
| 1006 notification_list_->RemoveNotificationsBySource(id); | |
| 1007 if (delegate_) | 1007 if (delegate_) |
| 1008 delegate_->DisableNotificationsFromSource(id); | 1008 delegate_->DisableNotificationsFromSource(id); |
| 1009 // Will call SendRemoveNotification for each matching notification. |
| 1010 notification_list_->SendRemoveNotificationsBySource(this, id); |
| 1009 } | 1011 } |
| 1010 | 1012 |
| 1011 bool WebNotificationTray::PerformAction(const ui::Event& event) { | 1013 bool WebNotificationTray::PerformAction(const ui::Event& event) { |
| 1012 if (message_center_bubble()) | 1014 if (message_center_bubble()) |
| 1013 HideMessageCenterBubble(); | 1015 HideMessageCenterBubble(); |
| 1014 else | 1016 else |
| 1015 ShowMessageCenterBubble(); | 1017 ShowMessageCenterBubble(); |
| 1016 return true; | 1018 return true; |
| 1017 } | 1019 } |
| 1018 | 1020 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 } else if (bubble == notification_bubble()) { | 1066 } else if (bubble == notification_bubble()) { |
| 1065 HideNotificationBubble(); | 1067 HideNotificationBubble(); |
| 1066 } | 1068 } |
| 1067 } | 1069 } |
| 1068 | 1070 |
| 1069 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const { | 1071 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const { |
| 1070 return notification_list_->HasNotification(id); | 1072 return notification_list_->HasNotification(id); |
| 1071 } | 1073 } |
| 1072 | 1074 |
| 1073 } // namespace ash | 1075 } // namespace ash |
| OLD | NEW |