Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome/browser/notifications/message_center_notification_manager.cc

Issue 11896085: Adding implementation for MessageCenter::Delegate on MessageCeneterNotificationManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: disable on win7_aura Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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.
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 // UI should not have enabled the command if there is no valid source.
156 DCHECK(profile_notification->notification().origin_url().is_valid());
157 DesktopNotificationService* service =
158 DesktopNotificationServiceFactory::GetForProfile(
159 profile_notification->profile());
160 service->DenyPermission(profile_notification->notification().origin_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 RemoveProfileNotification(FindProfileNotification(notification_id));
149 } 166 }
150 167
151 void MessageCenterNotificationManager::ShowSettings( 168 void MessageCenterNotificationManager::ShowSettings(
152 const std::string& notification_id) { 169 const std::string& notification_id) {
153 NOTIMPLEMENTED(); 170 ProfileNotification* profile_notification =
171 FindProfileNotification(notification_id);
172 Browser* browser =
173 chrome::FindOrCreateTabbedBrowser(profile_notification->profile(),
174 chrome::HOST_DESKTOP_TYPE_NATIVE);
175 if (profile_notification->GetExtensionId().empty())
176 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
177 else
178 chrome::ShowExtensions(browser);
154 } 179 }
155 180
156 void MessageCenterNotificationManager::ShowSettingsDialog( 181 void MessageCenterNotificationManager::ShowSettingsDialog(
157 gfx::NativeView context) { 182 gfx::NativeView context) {
158 NOTIMPLEMENTED(); 183 NOTIMPLEMENTED();
159 } 184 }
160 185
161 void MessageCenterNotificationManager::OnClicked( 186 void MessageCenterNotificationManager::OnClicked(
162 const std::string& notification_id) { 187 const std::string& notification_id) {
163 NOTIMPLEMENTED(); 188 FindProfileNotification(notification_id)->notification().Click();
164 } 189 }
165 190
166 void MessageCenterNotificationManager::OnButtonClicked( 191 void MessageCenterNotificationManager::OnButtonClicked(
167 const std::string& notification_id, int button_index) { 192 const std::string& notification_id, int button_index) {
168 NOTIMPLEMENTED(); 193 FindProfileNotification(notification_id)->notification().ButtonClick(
194 button_index);
169 } 195 }
170 196
171 //////////////////////////////////////////////////////////////////////////////// 197 ////////////////////////////////////////////////////////////////////////////////
172 // ProfileNotification 198 // ProfileNotification
173 199
174 MessageCenterNotificationManager::ProfileNotification::ProfileNotification( 200 MessageCenterNotificationManager::ProfileNotification::ProfileNotification(
175 Profile* profile, const Notification& notification) 201 Profile* profile, const Notification& notification)
176 : profile_(profile), 202 : profile_(profile),
177 notification_(notification) { 203 notification_(notification) {
178 DCHECK(profile); 204 DCHECK(profile);
(...skipping 30 matching lines...) Expand all
209 } 235 }
210 236
211 void MessageCenterNotificationManager::RemoveProfileNotification( 237 void MessageCenterNotificationManager::RemoveProfileNotification(
212 ProfileNotification* profile_notification) { 238 ProfileNotification* profile_notification) {
213 profile_notification->notification().Close(false); // Not by user. 239 profile_notification->notification().Close(false); // Not by user.
214 std::string id = profile_notification->notification().notification_id(); 240 std::string id = profile_notification->notification().notification_id();
215 message_center_->RemoveNotification(id); 241 message_center_->RemoveNotification(id);
216 profile_notifications_.erase(id); 242 profile_notifications_.erase(id);
217 delete profile_notification; 243 delete profile_notification;
218 } 244 }
245
246 MessageCenterNotificationManager::ProfileNotification*
247 MessageCenterNotificationManager::FindProfileNotification(
248 const std::string& id) const {
249 NotificationMap::const_iterator iter = profile_notifications_.find(id);
250 // If the notification is shown in UI, it must be in the map.
251 DCHECK(iter != profile_notifications_.end());
252 DCHECK((*iter).second);
253 return (*iter).second;
254 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698