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

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

Issue 231723006: Remove balloon notification code. The last user was the Linux GTK port but that's deleted now. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync past sadrul's r262988 which removed mac/views Created 6 years, 8 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/prefs/scoped_user_pref_update.h" 8 #include "base/prefs/scoped_user_pref_update.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 NOTREACHED() << "unable to load template. ID: " << resource; 377 NOTREACHED() << "unable to load template. ID: " << resource;
378 return base::string16(); 378 return base::string16();
379 } 379 }
380 380
381 std::string data = ReplaceStringPlaceholders(template_html, subst, NULL); 381 std::string data = ReplaceStringPlaceholders(template_html, subst, NULL);
382 return base::UTF8ToUTF16("data:text/html;charset=utf-8," + 382 return base::UTF8ToUTF16("data:text/html;charset=utf-8," +
383 net::EscapeQueryParamValue(data, false)); 383 net::EscapeQueryParamValue(data, false));
384 } 384 }
385 385
386 // static 386 // static
387 std::string DesktopNotificationService::AddNotification(
388 const GURL& origin_url,
389 const base::string16& title,
390 const base::string16& message,
391 const GURL& icon_url,
392 const base::string16& replace_id,
393 NotificationDelegate* delegate,
394 Profile* profile) {
395 if (message_center::IsRichNotificationEnabled()) {
396 // For message center create a non-HTML notification with |icon_url|.
397 Notification notification(origin_url, icon_url, title, message,
398 blink::WebTextDirectionDefault,
399 base::string16(), replace_id, delegate);
400 g_browser_process->notification_ui_manager()->Add(notification, profile);
401 return notification.notification_id();
402 }
403
404 // Generate a data URL embedding the icon URL, title, and message.
405 GURL content_url(CreateDataUrl(
406 icon_url, title, message, blink::WebTextDirectionDefault));
407 Notification notification(
408 GURL(), content_url, base::string16(), replace_id, delegate);
409 g_browser_process->notification_ui_manager()->Add(notification, profile);
410 return notification.notification_id();
411 }
412
413 // static
414 std::string DesktopNotificationService::AddIconNotification( 387 std::string DesktopNotificationService::AddIconNotification(
415 const GURL& origin_url, 388 const GURL& origin_url,
416 const base::string16& title, 389 const base::string16& title,
417 const base::string16& message, 390 const base::string16& message,
418 const gfx::Image& icon, 391 const gfx::Image& icon,
419 const base::string16& replace_id, 392 const base::string16& replace_id,
420 NotificationDelegate* delegate, 393 NotificationDelegate* delegate,
421 Profile* profile) { 394 Profile* profile) {
422 if (message_center::IsRichNotificationEnabled()) { 395 Notification notification(origin_url, icon, title, message,
423 // For message center create a non-HTML notification with |icon|. 396 blink::WebTextDirectionDefault,
424 Notification notification(origin_url, icon, title, message, 397 base::string16(), replace_id, delegate);
425 blink::WebTextDirectionDefault, 398 g_browser_process->notification_ui_manager()->Add(notification, profile);
426 base::string16(), replace_id, delegate); 399 return notification.notification_id();
stevenjb 2014/04/10 17:32:03 It looks like we only call this twice, we could ju
jam 2014/04/10 20:10:00 yeah i'd prefer to keep it as simple as possible :
427 g_browser_process->notification_ui_manager()->Add(notification, profile);
428 return notification.notification_id();
429 }
430
431 GURL icon_url;
432 if (!icon.IsEmpty())
433 icon_url = GURL(webui::GetBitmapDataUrl(*icon.ToSkBitmap()));
434 return AddNotification(
435 origin_url, title, message, icon_url, replace_id, delegate, profile);
436 }
437
438 // static
439 void DesktopNotificationService::RemoveNotification(
440 const std::string& notification_id) {
441 g_browser_process->notification_ui_manager()->CancelById(notification_id);
442 } 400 }
443 401
444 DesktopNotificationService::DesktopNotificationService( 402 DesktopNotificationService::DesktopNotificationService(
445 Profile* profile, 403 Profile* profile,
446 NotificationUIManager* ui_manager) 404 NotificationUIManager* ui_manager)
447 : profile_(profile), 405 : profile_(profile),
448 ui_manager_(ui_manager) { 406 ui_manager_(ui_manager) {
449 OnStringListPrefChanged( 407 OnStringListPrefChanged(
450 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_); 408 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_);
451 OnStringListPrefChanged( 409 OnStringListPrefChanged(
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 // The webkit notification doesn't timeout. 586 // The webkit notification doesn't timeout.
629 notification.set_never_timeout(true); 587 notification.set_never_timeout(true);
630 588
631 ShowNotification(notification); 589 ShowNotification(notification);
632 return true; 590 return true;
633 } 591 }
634 592
635 base::string16 DesktopNotificationService::DisplayNameForOriginInProcessId( 593 base::string16 DesktopNotificationService::DisplayNameForOriginInProcessId(
636 const GURL& origin, int process_id) { 594 const GURL& origin, int process_id) {
637 // If the source is an extension, lookup the display name. 595 // If the source is an extension, lookup the display name.
638 // Message center prefers to use extension name if the notification 596 if (origin.SchemeIs(extensions::kExtensionScheme)) {
639 // is allowed by an extension.
640 if (NotificationUIManager::DelegatesToMessageCenter() ||
641 origin.SchemeIs(extensions::kExtensionScheme)) {
642 extensions::InfoMap* extension_info_map = 597 extensions::InfoMap* extension_info_map =
643 extensions::ExtensionSystem::Get(profile_)->info_map(); 598 extensions::ExtensionSystem::Get(profile_)->info_map();
644 if (extension_info_map) { 599 if (extension_info_map) {
645 extensions::ExtensionSet extensions; 600 extensions::ExtensionSet extensions;
646 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( 601 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
647 origin, process_id, extensions::APIPermission::kNotification, 602 origin, process_id, extensions::APIPermission::kNotification,
648 &extensions); 603 &extensions);
649 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); 604 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
650 iter != extensions.end(); ++iter) { 605 iter != extensions.end(); ++iter) {
651 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id()); 606 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 // AppendIfNotPresent will delete |adding_value| when the same value 694 // AppendIfNotPresent will delete |adding_value| when the same value
740 // already exists. 695 // already exists.
741 list->AppendIfNotPresent(id.release()); 696 list->AppendIfNotPresent(id.release());
742 } else { 697 } else {
743 list->Remove(*id, NULL); 698 list->Remove(*id, NULL);
744 } 699 }
745 } 700 }
746 701
747 void DesktopNotificationService::ShowWelcomeNotificationIfNecessary( 702 void DesktopNotificationService::ShowWelcomeNotificationIfNecessary(
748 const Notification& notification) { 703 const Notification& notification) {
749 if (!chrome_now_welcome_notification_ && 704 if (!chrome_now_welcome_notification_) {
750 message_center::IsRichNotificationEnabled()) {
751 chrome_now_welcome_notification_ = 705 chrome_now_welcome_notification_ =
752 ExtensionWelcomeNotification::Create(kChromeNowExtensionID, profile_); 706 ExtensionWelcomeNotification::Create(kChromeNowExtensionID, profile_);
753 } 707 }
754 708
755 if (chrome_now_welcome_notification_) { 709 if (chrome_now_welcome_notification_) {
756 chrome_now_welcome_notification_->ShowWelcomeNotificationIfNecessary( 710 chrome_now_welcome_notification_->ShowWelcomeNotificationIfNecessary(
757 notification); 711 notification);
758 } 712 }
759 } 713 }
760 714
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 // Tell the IO thread that this extension's permission for notifications 765 // Tell the IO thread that this extension's permission for notifications
812 // has changed. 766 // has changed.
813 extensions::InfoMap* extension_info_map = 767 extensions::InfoMap* extension_info_map =
814 extensions::ExtensionSystem::Get(profile_)->info_map(); 768 extensions::ExtensionSystem::Get(profile_)->info_map();
815 BrowserThread::PostTask( 769 BrowserThread::PostTask(
816 BrowserThread::IO, FROM_HERE, 770 BrowserThread::IO, FROM_HERE,
817 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, 771 base::Bind(&extensions::InfoMap::SetNotificationsDisabled,
818 extension_info_map, notifier_id.id, !enabled)); 772 extension_info_map, notifier_id.id, !enabled));
819 773
820 } 774 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698