| 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/status_icons/desktop_notification_balloon.h" | 5 #include "chrome/browser/status_icons/desktop_notification_balloon.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/notifications/desktop_notification_service.h" | 11 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 12 #include "chrome/browser/notifications/notification.h" | 12 #include "chrome/browser/notifications/notification.h" |
| 13 #include "chrome/browser/notifications/notification_delegate.h" | 13 #include "chrome/browser/notifications/notification_delegate.h" |
| 14 #include "chrome/browser/notifications/notification_ui_manager.h" | 14 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/ui/webui/web_ui_util.h" | 16 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 17 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 18 #include "ui/gfx/image/image_skia.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 void CloseBalloon(const std::string& id) { | 22 void CloseBalloon(const std::string& id) { |
| 22 // The browser process may have gone away during shutting down, in this case | 23 // The browser process may have gone away during shutting down, in this case |
| 23 // notification_ui_manager() will close the balloon in its destructor. | 24 // notification_ui_manager() will close the balloon in its destructor. |
| 24 if (!g_browser_process) | 25 if (!g_browser_process) |
| 25 return; | 26 return; |
| 26 | 27 |
| 27 g_browser_process->notification_ui_manager()->CancelById(id); | 28 g_browser_process->notification_ui_manager()->CancelById(id); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 DesktopNotificationBalloon::~DesktopNotificationBalloon() { | 66 DesktopNotificationBalloon::~DesktopNotificationBalloon() { |
| 66 if (notification_.get()) | 67 if (notification_.get()) |
| 67 CloseBalloon(notification_->notification_id()); | 68 CloseBalloon(notification_->notification_id()); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void DesktopNotificationBalloon::DisplayBalloon(const SkBitmap& icon, | 71 void DesktopNotificationBalloon::DisplayBalloon(const SkBitmap& icon, |
| 71 const string16& title, | 72 const string16& title, |
| 72 const string16& contents) { | 73 const string16& contents) { |
| 73 GURL icon_url; | 74 GURL icon_url; |
| 74 if (!icon.empty()) | 75 if (!icon.empty()) |
| 75 icon_url = GURL(web_ui_util::GetImageDataUrl(icon)); | 76 icon_url = GURL(web_ui_util::GetImageDataUrl(gfx::ImageSkia(icon))); |
| 76 | 77 |
| 77 GURL content_url(DesktopNotificationService::CreateDataUrl( | 78 GURL content_url(DesktopNotificationService::CreateDataUrl( |
| 78 icon_url, title, contents, WebKit::WebTextDirectionDefault)); | 79 icon_url, title, contents, WebKit::WebTextDirectionDefault)); |
| 79 | 80 |
| 80 notification_.reset(new Notification( | 81 notification_.reset(new Notification( |
| 81 GURL(), content_url, string16(), string16(), | 82 GURL(), content_url, string16(), string16(), |
| 82 new DummyNotificationDelegate(base::IntToString(id_count_++)))); | 83 new DummyNotificationDelegate(base::IntToString(id_count_++)))); |
| 83 | 84 |
| 84 // Allowing IO access is required here to cover the corner case where | 85 // Allowing IO access is required here to cover the corner case where |
| 85 // there is no last used profile and the default one is loaded. | 86 // there is no last used profile and the default one is loaded. |
| 86 // IO access won't be required for normal uses. | 87 // IO access won't be required for normal uses. |
| 87 base::ThreadRestrictions::ScopedAllowIO allow_io; | 88 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 88 g_browser_process->notification_ui_manager()->Add( | 89 g_browser_process->notification_ui_manager()->Add( |
| 89 *notification_.get(), ProfileManager::GetLastUsedProfile()); | 90 *notification_.get(), ProfileManager::GetLastUsedProfile()); |
| 90 } | 91 } |
| OLD | NEW |