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

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

Issue 10824265: Correctly remove file browser notifications from Ash notification tray. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 4 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/desktop_notification_service.h" 5 #include "chrome/browser/notifications/desktop_notification_service.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return UTF8ToUTF16("data:text/html;charset=utf-8," + 231 return UTF8ToUTF16("data:text/html;charset=utf-8," +
232 net::EscapeQueryParamValue(data, false)); 232 net::EscapeQueryParamValue(data, false));
233 } 233 }
234 234
235 // static 235 // static
236 std::string DesktopNotificationService::AddNotification( 236 std::string DesktopNotificationService::AddNotification(
237 const GURL& origin_url, 237 const GURL& origin_url,
238 const string16& title, 238 const string16& title,
239 const string16& message, 239 const string16& message,
240 const GURL& icon_url, 240 const GURL& icon_url,
241 const string16& replace_id,
241 NotificationDelegate* delegate, 242 NotificationDelegate* delegate,
242 Profile* profile) { 243 Profile* profile) {
243 #if defined(USE_ASH) 244 #if defined(USE_ASH)
244 if (IsAshNotifyEnabled()) { 245 if (IsAshNotifyEnabled()) {
245 // For Ash create a non-HTML notification with |icon_url|. 246 // For Ash create a non-HTML notification with |icon_url|.
246 Notification notification(GURL(), icon_url, title, message, 247 Notification notification(GURL(), icon_url, title, message,
247 WebKit::WebTextDirectionDefault, 248 WebKit::WebTextDirectionDefault,
248 string16(), string16(), delegate); 249 string16(), replace_id, delegate);
249 g_browser_process->notification_ui_manager()->Add(notification, profile); 250 g_browser_process->notification_ui_manager()->Add(notification, profile);
250 return notification.notification_id(); 251 return notification.notification_id();
251 } 252 }
252 #endif 253 #endif
253 // Generate a data URL embedding the icon URL, title, and message. 254 // Generate a data URL embedding the icon URL, title, and message.
254 GURL content_url(CreateDataUrl( 255 GURL content_url(CreateDataUrl(
255 icon_url, title, message, WebKit::WebTextDirectionDefault)); 256 icon_url, title, message, WebKit::WebTextDirectionDefault));
256 Notification notification( 257 Notification notification(
257 GURL(), content_url, string16(), string16(), delegate); 258 GURL(), content_url, string16(), replace_id, delegate);
258 g_browser_process->notification_ui_manager()->Add(notification, profile); 259 g_browser_process->notification_ui_manager()->Add(notification, profile);
259 return notification.notification_id(); 260 return notification.notification_id();
260 } 261 }
261 262
262 // static 263 // static
263 std::string DesktopNotificationService::AddIconNotification( 264 std::string DesktopNotificationService::AddIconNotification(
264 const GURL& origin_url, 265 const GURL& origin_url,
265 const string16& title, 266 const string16& title,
266 const string16& message, 267 const string16& message,
267 const gfx::ImageSkia& icon, 268 const gfx::ImageSkia& icon,
269 const string16& replace_id,
268 NotificationDelegate* delegate, 270 NotificationDelegate* delegate,
269 Profile* profile) { 271 Profile* profile) {
270 #if defined(USE_ASH) 272 #if defined(USE_ASH)
271 if (IsAshNotifyEnabled()) { 273 if (IsAshNotifyEnabled()) {
272 // For Ash create a non-HTML notification with |icon|. 274 // For Ash create a non-HTML notification with |icon|.
273 Notification notification(GURL(), icon, title, message, 275 Notification notification(GURL(), icon, title, message,
274 WebKit::WebTextDirectionDefault, 276 WebKit::WebTextDirectionDefault,
275 string16(), string16(), delegate); 277 string16(), replace_id, delegate);
276 g_browser_process->notification_ui_manager()->Add(notification, profile); 278 g_browser_process->notification_ui_manager()->Add(notification, profile);
277 return notification.notification_id(); 279 return notification.notification_id();
278 } 280 }
279 #endif 281 #endif
280 GURL icon_url; 282 GURL icon_url;
281 if (!icon.empty()) 283 if (!icon.empty())
282 icon_url = GURL(web_ui_util::GetImageDataUrl(icon)); 284 icon_url = GURL(web_ui_util::GetImageDataUrl(icon));
283 return AddNotification( 285 return AddNotification(
284 origin_url, title, message, icon_url, delegate, profile); 286 origin_url, title, message, icon_url, replace_id, delegate, profile);
287 }
288
289 // static
290 void DesktopNotificationService::RemoveNotification(
291 const std::string& notification_id) {
292 g_browser_process->notification_ui_manager()->CancelById(notification_id);
285 } 293 }
286 294
287 DesktopNotificationService::DesktopNotificationService(Profile* profile, 295 DesktopNotificationService::DesktopNotificationService(Profile* profile,
288 NotificationUIManager* ui_manager) 296 NotificationUIManager* ui_manager)
289 : profile_(profile), 297 : profile_(profile),
290 ui_manager_(ui_manager) { 298 ui_manager_(ui_manager) {
291 StartObserving(); 299 StartObserving();
292 } 300 }
293 301
294 DesktopNotificationService::~DesktopNotificationService() { 302 DesktopNotificationService::~DesktopNotificationService() {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 526
519 if (setting == CONTENT_SETTING_ALLOW) 527 if (setting == CONTENT_SETTING_ALLOW)
520 return WebKit::WebNotificationPresenter::PermissionAllowed; 528 return WebKit::WebNotificationPresenter::PermissionAllowed;
521 if (setting == CONTENT_SETTING_BLOCK) 529 if (setting == CONTENT_SETTING_BLOCK)
522 return WebKit::WebNotificationPresenter::PermissionDenied; 530 return WebKit::WebNotificationPresenter::PermissionDenied;
523 if (setting == CONTENT_SETTING_ASK) 531 if (setting == CONTENT_SETTING_ASK)
524 return WebKit::WebNotificationPresenter::PermissionNotAllowed; 532 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
525 NOTREACHED() << "Invalid notifications settings value: " << setting; 533 NOTREACHED() << "Invalid notifications settings value: " << setting;
526 return WebKit::WebNotificationPresenter::PermissionNotAllowed; 534 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
527 } 535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698