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 "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/notifications/desktop_notification_service.h" | |
11 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | |
10 #include "chrome/browser/notifications/notification.h" | 12 #include "chrome/browser/notifications/notification.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser_finder.h" | |
16 #include "chrome/browser/ui/chrome_pages.h" | |
17 #include "chrome/browser/ui/host_desktop.h" | |
13 #include "chrome/common/extensions/extension_set.h" | 18 #include "chrome/common/extensions/extension_set.h" |
14 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
15 | 20 |
16 MessageCenterNotificationManager::MessageCenterNotificationManager( | 21 MessageCenterNotificationManager::MessageCenterNotificationManager( |
17 message_center::MessageCenter* message_center) | 22 message_center::MessageCenter* message_center) |
18 : message_center_(message_center) { | 23 : message_center_(message_center) { |
19 message_center_->SetDelegate(this); | 24 message_center_->SetDelegate(this); |
20 } | 25 } |
21 | 26 |
22 MessageCenterNotificationManager::~MessageCenterNotificationManager() { | 27 MessageCenterNotificationManager::~MessageCenterNotificationManager() { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 } | 133 } |
129 } | 134 } |
130 return false; | 135 return false; |
131 } | 136 } |
132 | 137 |
133 //////////////////////////////////////////////////////////////////////////////// | 138 //////////////////////////////////////////////////////////////////////////////// |
134 // MessageCenter::Delegate | 139 // MessageCenter::Delegate |
135 | 140 |
136 void MessageCenterNotificationManager::DisableExtension( | 141 void MessageCenterNotificationManager::DisableExtension( |
137 const std::string& notification_id) { | 142 const std::string& notification_id) { |
138 NOTIMPLEMENTED(); | 143 ProfileNotification* profile_notification = |
144 FindProfileNotification(notification_id); | |
145 std::string extension_id = profile_notification->GetExtensionId(); | |
146 DCHECK(!extension_id.empty()); // or UI should not have enabled the command. | |
stevenjb
2013/01/24 23:59:54
two spaces before //
Dmitry Titov
2013/01/25 00:47:45
Done.
| |
147 profile_notification->profile()->GetExtensionService()->DisableExtension( | |
148 extension_id, extensions::Extension::DISABLE_USER_ACTION); | |
139 } | 149 } |
140 | 150 |
141 void MessageCenterNotificationManager::DisableNotificationsFromSource( | 151 void MessageCenterNotificationManager::DisableNotificationsFromSource( |
142 const std::string& notification_id) { | 152 const std::string& notification_id) { |
143 NOTIMPLEMENTED(); | 153 ProfileNotification* profile_notification = |
154 FindProfileNotification(notification_id); | |
155 const GURL& source_url = profile_notification->notification().origin_url(); | |
156 DCHECK(source_url.is_valid()); // or UI should not have enabled the command. | |
stevenjb
2013/01/24 23:59:54
; //
Dmitry Titov
2013/01/25 00:47:45
Done.
| |
157 DesktopNotificationService* service = | |
158 DesktopNotificationServiceFactory::GetForProfile( | |
159 profile_notification->profile()); | |
stevenjb
2013/01/24 23:59:54
nit: Don't need local variable 'source'
Dmitry Titov
2013/01/25 00:47:45
Done.
| |
160 service->DenyPermission(source_url); | |
144 } | 161 } |
145 | 162 |
146 void MessageCenterNotificationManager::NotificationRemoved( | 163 void MessageCenterNotificationManager::NotificationRemoved( |
147 const std::string& notification_id) { | 164 const std::string& notification_id) { |
148 NOTIMPLEMENTED(); | 165 ProfileNotification* profile_notification = |
166 FindProfileNotification(notification_id); | |
stevenjb
2013/01/24 23:59:54
nit: Don't need local variable
Dmitry Titov
2013/01/25 00:47:45
Done.
| |
167 RemoveProfileNotification(profile_notification); | |
149 } | 168 } |
150 | 169 |
151 void MessageCenterNotificationManager::ShowSettings( | 170 void MessageCenterNotificationManager::ShowSettings( |
152 const std::string& notification_id) { | 171 const std::string& notification_id) { |
153 NOTIMPLEMENTED(); | 172 ProfileNotification* profile_notification = |
173 FindProfileNotification(notification_id); | |
174 Profile* profile = profile_notification->profile(); | |
stevenjb
2013/01/24 23:59:54
nit: Don't need local variables
Dmitry Titov
2013/01/25 00:47:45
Removed 'profile', left those used twice...
| |
175 Browser* browser = | |
176 chrome::FindOrCreateTabbedBrowser(profile, | |
177 chrome::HOST_DESKTOP_TYPE_NATIVE); | |
178 if (profile_notification->GetExtensionId().empty()) | |
179 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
180 else | |
181 chrome::ShowExtensions(browser); | |
154 } | 182 } |
155 | 183 |
156 void MessageCenterNotificationManager::OnClicked( | 184 void MessageCenterNotificationManager::OnClicked( |
157 const std::string& notification_id) { | 185 const std::string& notification_id) { |
158 NOTIMPLEMENTED(); | 186 ProfileNotification* profile_notification = |
187 FindProfileNotification(notification_id); | |
stevenjb
2013/01/24 23:59:54
nit: Don't need local variable
Dmitry Titov
2013/01/25 00:47:45
Done.
| |
188 profile_notification->notification().Click(); | |
159 } | 189 } |
160 | 190 |
161 void MessageCenterNotificationManager::OnButtonClicked( | 191 void MessageCenterNotificationManager::OnButtonClicked( |
162 const std::string& notification_id, int button_index) { | 192 const std::string& notification_id, int button_index) { |
163 NOTIMPLEMENTED(); | 193 ProfileNotification* profile_notification = |
194 FindProfileNotification(notification_id); | |
stevenjb
2013/01/24 23:59:54
nit: Don't need local variable
Dmitry Titov
2013/01/25 00:47:45
Done.
| |
195 profile_notification->notification().ButtonClick(button_index); | |
164 } | 196 } |
165 | 197 |
166 //////////////////////////////////////////////////////////////////////////////// | 198 //////////////////////////////////////////////////////////////////////////////// |
167 // ProfileNotification | 199 // ProfileNotification |
168 | 200 |
169 MessageCenterNotificationManager::ProfileNotification::ProfileNotification( | 201 MessageCenterNotificationManager::ProfileNotification::ProfileNotification( |
170 Profile* profile, const Notification& notification) | 202 Profile* profile, const Notification& notification) |
171 : profile_(profile), | 203 : profile_(profile), |
172 notification_(notification) { | 204 notification_(notification) { |
173 DCHECK(profile); | 205 DCHECK(profile); |
(...skipping 30 matching lines...) Expand all Loading... | |
204 } | 236 } |
205 | 237 |
206 void MessageCenterNotificationManager::RemoveProfileNotification( | 238 void MessageCenterNotificationManager::RemoveProfileNotification( |
207 ProfileNotification* profile_notification) { | 239 ProfileNotification* profile_notification) { |
208 profile_notification->notification().Close(false); // Not by user. | 240 profile_notification->notification().Close(false); // Not by user. |
209 std::string id = profile_notification->notification().notification_id(); | 241 std::string id = profile_notification->notification().notification_id(); |
210 message_center_->RemoveNotification(id); | 242 message_center_->RemoveNotification(id); |
211 profile_notifications_.erase(id); | 243 profile_notifications_.erase(id); |
212 delete profile_notification; | 244 delete profile_notification; |
213 } | 245 } |
246 | |
247 MessageCenterNotificationManager::ProfileNotification* | |
248 MessageCenterNotificationManager::FindProfileNotification( | |
249 const std::string& id) const { | |
250 NotificationMap::const_iterator iter = profile_notifications_.find(id); | |
251 if (iter == profile_notifications_.end()) { | |
252 NOTREACHED(); // If the notification is shown in UI, it must be in the map. | |
stevenjb
2013/01/24 23:59:54
; //
Dmitry Titov
2013/01/25 00:47:45
Done.
| |
253 return NULL; | |
254 } | |
stevenjb
2013/01/24 23:59:54
This should be DCHECK(iter != profile_notification
Dmitry Titov
2013/01/25 00:47:45
Done.
| |
255 DCHECK((*iter).second); | |
256 return (*iter).second; | |
257 } | |
OLD | NEW |