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/notifications/message_center_notification_manager.h" | 5 #include "chrome/browser/notifications/message_center_notification_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return false; | 157 return false; |
158 } | 158 } |
159 | 159 |
160 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
161 // MessageCenter::Delegate | 161 // MessageCenter::Delegate |
162 | 162 |
163 void MessageCenterNotificationManager::DisableExtension( | 163 void MessageCenterNotificationManager::DisableExtension( |
164 const std::string& notification_id) { | 164 const std::string& notification_id) { |
165 ProfileNotification* profile_notification = | 165 ProfileNotification* profile_notification = |
166 FindProfileNotification(notification_id); | 166 FindProfileNotification(notification_id); |
| 167 if (!profile_notification) |
| 168 return; |
| 169 |
167 std::string extension_id = profile_notification->GetExtensionId(); | 170 std::string extension_id = profile_notification->GetExtensionId(); |
168 DCHECK(!extension_id.empty()); // or UI should not have enabled the command. | 171 DCHECK(!extension_id.empty()); // or UI should not have enabled the command. |
169 DesktopNotificationService* service = | 172 DesktopNotificationService* service = |
170 DesktopNotificationServiceFactory::GetForProfile( | 173 DesktopNotificationServiceFactory::GetForProfile( |
171 profile_notification->profile()); | 174 profile_notification->profile()); |
172 service->SetExtensionEnabled(extension_id, false); | 175 service->SetExtensionEnabled(extension_id, false); |
173 } | 176 } |
174 | 177 |
175 void MessageCenterNotificationManager::DisableNotificationsFromSource( | 178 void MessageCenterNotificationManager::DisableNotificationsFromSource( |
176 const std::string& notification_id) { | 179 const std::string& notification_id) { |
177 ProfileNotification* profile_notification = | 180 ProfileNotification* profile_notification = |
178 FindProfileNotification(notification_id); | 181 FindProfileNotification(notification_id); |
| 182 if (!profile_notification) |
| 183 return; |
| 184 |
179 // UI should not have enabled the command if there is no valid source. | 185 // UI should not have enabled the command if there is no valid source. |
180 DCHECK(profile_notification->notification().origin_url().is_valid()); | 186 DCHECK(profile_notification->notification().origin_url().is_valid()); |
181 DesktopNotificationService* service = | 187 DesktopNotificationService* service = |
182 DesktopNotificationServiceFactory::GetForProfile( | 188 DesktopNotificationServiceFactory::GetForProfile( |
183 profile_notification->profile()); | 189 profile_notification->profile()); |
184 service->DenyPermission(profile_notification->notification().origin_url()); | 190 service->DenyPermission(profile_notification->notification().origin_url()); |
185 } | 191 } |
186 | 192 |
187 void MessageCenterNotificationManager::ShowSettings( | 193 void MessageCenterNotificationManager::ShowSettings( |
188 const std::string& notification_id) { | 194 const std::string& notification_id) { |
189 // The per-message-center Settings button passes an empty string. | 195 // The per-message-center Settings button passes an empty string. |
190 if (notification_id.empty()) { | 196 if (notification_id.empty()) { |
191 NOTIMPLEMENTED(); | 197 NOTIMPLEMENTED(); |
192 return; | 198 return; |
193 } | 199 } |
194 | 200 |
195 ProfileNotification* profile_notification = | 201 ProfileNotification* profile_notification = |
196 FindProfileNotification(notification_id); | 202 FindProfileNotification(notification_id); |
| 203 if (!profile_notification) |
| 204 return; |
| 205 |
197 Browser* browser = | 206 Browser* browser = |
198 chrome::FindOrCreateTabbedBrowser(profile_notification->profile(), | 207 chrome::FindOrCreateTabbedBrowser(profile_notification->profile(), |
199 chrome::HOST_DESKTOP_TYPE_NATIVE); | 208 chrome::HOST_DESKTOP_TYPE_NATIVE); |
200 if (profile_notification->GetExtensionId().empty()) | 209 if (profile_notification->GetExtensionId().empty()) |
201 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 210 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
202 else | 211 else |
203 chrome::ShowExtensions(browser, std::string()); | 212 chrome::ShowExtensions(browser, std::string()); |
204 } | 213 } |
205 | 214 |
206 void MessageCenterNotificationManager::ShowSettingsDialog( | 215 void MessageCenterNotificationManager::ShowSettingsDialog( |
(...skipping 10 matching lines...) Expand all Loading... |
217 // directly to MessageCenter, but this method will be called for the removals | 226 // directly to MessageCenter, but this method will be called for the removals |
218 // of such notifications. | 227 // of such notifications. |
219 NotificationMap::const_iterator iter = | 228 NotificationMap::const_iterator iter = |
220 profile_notifications_.find(notification_id); | 229 profile_notifications_.find(notification_id); |
221 if (iter != profile_notifications_.end()) | 230 if (iter != profile_notifications_.end()) |
222 RemoveProfileNotification(iter->second, by_user); | 231 RemoveProfileNotification(iter->second, by_user); |
223 } | 232 } |
224 | 233 |
225 void MessageCenterNotificationManager::OnNotificationClicked( | 234 void MessageCenterNotificationManager::OnNotificationClicked( |
226 const std::string& notification_id) { | 235 const std::string& notification_id) { |
227 FindProfileNotification(notification_id)->notification().Click(); | 236 ProfileNotification* profile_notification = |
| 237 FindProfileNotification(notification_id); |
| 238 if (!profile_notification) |
| 239 return; |
| 240 profile_notification->notification().Click(); |
228 } | 241 } |
229 void MessageCenterNotificationManager::OnNotificationButtonClicked( | 242 void MessageCenterNotificationManager::OnNotificationButtonClicked( |
230 const std::string& notification_id, | 243 const std::string& notification_id, |
231 int button_index) { | 244 int button_index) { |
232 FindProfileNotification(notification_id)->notification().ButtonClick( | 245 ProfileNotification* profile_notification = |
233 button_index); | 246 FindProfileNotification(notification_id); |
| 247 if (!profile_notification) |
| 248 return; |
| 249 profile_notification->notification().ButtonClick(button_index); |
234 } | 250 } |
235 | 251 |
236 | 252 |
237 //////////////////////////////////////////////////////////////////////////////// | 253 //////////////////////////////////////////////////////////////////////////////// |
238 // ImageDownloads | 254 // ImageDownloads |
239 | 255 |
240 MessageCenterNotificationManager::ImageDownloads::ImageDownloads( | 256 MessageCenterNotificationManager::ImageDownloads::ImageDownloads( |
241 message_center::MessageCenter* message_center) | 257 message_center::MessageCenter* message_center) |
242 : message_center_(message_center) { | 258 : message_center_(message_center) { |
243 } | 259 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 profile_notification->notification().Close(by_user); | 418 profile_notification->notification().Close(by_user); |
403 std::string id = profile_notification->notification().notification_id(); | 419 std::string id = profile_notification->notification().notification_id(); |
404 profile_notifications_.erase(id); | 420 profile_notifications_.erase(id); |
405 delete profile_notification; | 421 delete profile_notification; |
406 } | 422 } |
407 | 423 |
408 MessageCenterNotificationManager::ProfileNotification* | 424 MessageCenterNotificationManager::ProfileNotification* |
409 MessageCenterNotificationManager::FindProfileNotification( | 425 MessageCenterNotificationManager::FindProfileNotification( |
410 const std::string& id) const { | 426 const std::string& id) const { |
411 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 427 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
412 // If the notification is shown in UI, it must be in the map. | 428 if (iter == profile_notifications_.end()) |
413 DCHECK(iter != profile_notifications_.end()); | 429 return NULL; |
414 DCHECK((*iter).second); | 430 |
415 return (*iter).second; | 431 return (*iter).second; |
416 } | 432 } |
OLD | NEW |