Chromium Code Reviews| 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/chromeos/notifications/system_notification.h" | 5 #include "chrome/browser/chromeos/notifications/system_notification.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/notifications/balloon_collection_impl_aura.h" | 9 #include "chrome/browser/chromeos/notifications/balloon_collection_impl_aura.h" |
| 10 #include "chrome/browser/chromeos/notifications/system_notification_factory.h" | 10 #include "chrome/browser/chromeos/notifications/system_notification_factory.h" |
| 11 #include "chrome/browser/notifications/notification.h" | 11 #include "chrome/browser/notifications/notification.h" |
| 12 #include "chrome/browser/notifications/notification_ui_manager.h" | 12 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 13 #include "chrome/browser/ui/webui/web_ui_util.h" | 13 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 14 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 14 | 15 |
| 15 namespace chromeos { | 16 namespace chromeos { |
| 16 | 17 |
| 17 void SystemNotification::Init(int icon_resource_id) { | 18 void SystemNotification::Init(int icon_resource_id) { |
| 19 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | |
| 18 collection_ = static_cast<BalloonCollectionImplType*>( | 20 collection_ = static_cast<BalloonCollectionImplType*>( |
| 19 g_browser_process->notification_ui_manager()->balloon_collection()); | 21 g_browser_process->notification_ui_manager()->balloon_collection()); |
| 20 std::string url = web_ui_util::GetImageDataUrlFromResource(icon_resource_id); | 22 std::string url = web_ui_util::GetImageDataUrlFromResource(icon_resource_id); |
| 21 DCHECK(!url.empty()); | 23 DCHECK(!url.empty()); |
| 22 GURL tmp_gurl(url); | 24 GURL tmp_gurl(url); |
| 23 icon_.Swap(&tmp_gurl); | 25 icon_.Swap(&tmp_gurl); |
| 24 } | 26 } |
| 25 | 27 |
| 26 SystemNotification::SystemNotification(Profile* profile, | 28 SystemNotification::SystemNotification(Profile* profile, |
| 27 NotificationDelegate* delegate, | 29 NotificationDelegate* delegate, |
| 28 int icon_resource_id, | 30 int icon_resource_id, |
| 29 const string16& title) | 31 const string16& title) |
| 30 : profile_(profile), | 32 : profile_(profile), |
| 31 collection_(NULL), | 33 collection_(NULL), |
| 32 delegate_(delegate), | 34 delegate_(delegate), |
| 33 title_(title), | 35 title_(title), |
| 34 visible_(false), | 36 visible_(false), |
| 35 urgent_(false) { | 37 sticky_(false), |
| 38 urgent_(false), | |
| 39 show_on_unlock_(false) { | |
| 36 Init(icon_resource_id); | 40 Init(icon_resource_id); |
| 37 } | 41 } |
| 38 | 42 |
| 39 SystemNotification::SystemNotification(Profile* profile, | 43 SystemNotification::SystemNotification(Profile* profile, |
| 40 const std::string& id, | 44 const std::string& id, |
| 41 int icon_resource_id, | 45 int icon_resource_id, |
| 42 const string16& title) | 46 const string16& title) |
| 43 : profile_(profile), | 47 : profile_(profile), |
| 44 collection_(NULL), | 48 collection_(NULL), |
| 45 delegate_(new Delegate(id)), | 49 delegate_(new Delegate(id)), |
| 46 title_(title), | 50 title_(title), |
| 47 visible_(false), | 51 visible_(false), |
| 48 urgent_(false) { | 52 sticky_(false), |
| 53 urgent_(false), | |
| 54 show_on_unlock_(false) { | |
| 49 Init(icon_resource_id); | 55 Init(icon_resource_id); |
| 50 } | 56 } |
| 51 | 57 |
| 52 SystemNotification::~SystemNotification() { | 58 SystemNotification::~SystemNotification() { |
| 59 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | |
| 60 } | |
| 61 | |
| 62 void SystemNotification::UnlockScreen() { | |
| 63 if (show_on_unlock_) { | |
| 64 DCHECK(!visible_); | |
| 65 Notification notify = SystemNotificationFactory::Create( | |
| 66 icon_, title_, message_, link_, delegate_.get()); | |
| 67 ShowNotification(notify); | |
| 68 } | |
| 53 } | 69 } |
| 54 | 70 |
| 55 void SystemNotification::Show(const string16& message, | 71 void SystemNotification::Show(const string16& message, |
| 56 bool urgent, | 72 bool urgent, |
| 57 bool sticky) { | 73 bool sticky) { |
| 58 Show(message, string16(), BalloonViewHost::MessageCallback(), urgent, sticky); | 74 Show(message, string16(), BalloonViewHost::MessageCallback(), urgent, sticky); |
| 59 } | 75 } |
| 60 | 76 |
| 61 void SystemNotification::Show(const string16& message, | 77 void SystemNotification::Show(const string16& message, |
| 62 const string16& link, | 78 const string16& link, |
| 63 const BalloonViewHost::MessageCallback& callback, | 79 const BalloonViewHost::MessageCallback& callback, |
| 64 bool urgent, | 80 bool urgent, |
| 65 bool sticky) { | 81 bool sticky) { |
| 66 Notification notify = SystemNotificationFactory::Create(icon_, | 82 message_ = message; |
| 67 title_, message, link, delegate_.get()); | 83 link_ = link; |
| 84 callback_ = callback; | |
| 85 sticky_ = sticky; | |
| 86 | |
| 87 if (DBusThreadManager::Get()->GetPowerManagerClient()->GetIsScreenLocked()) { | |
|
oshima
2012/05/11 19:40:07
can you use ScreenLocker::default_screen_locker()-
| |
| 88 if (visible_ && urgent && !urgent_) { | |
| 89 // Hide the notification so that we show/update it on unlock. | |
| 90 Hide(); | |
| 91 urgent_ = true; | |
| 92 } | |
| 93 if (!visible_) | |
| 94 show_on_unlock_ = true; | |
| 95 return; | |
| 96 } | |
| 97 | |
| 98 Notification notify = SystemNotificationFactory::Create( | |
| 99 icon_, title_, message_, link_, delegate_.get()); | |
| 68 if (visible_) { | 100 if (visible_) { |
| 69 // Force showing a user hidden notification on an urgent transition. | 101 // Force showing a user hidden notification on an urgent transition. |
| 70 if (urgent && !urgent_) { | 102 if (urgent && !urgent_) { |
| 71 if (!collection_->UpdateAndShowNotification(notify)) | 103 if (!collection_->UpdateAndShowNotification(notify)) |
| 72 visible_ = false; // re-show | 104 visible_ = false; // re-show |
| 73 } else { | 105 } else { |
| 74 collection_->UpdateNotification(notify); | 106 collection_->UpdateNotification(notify); |
| 75 } | 107 } |
| 76 } | 108 } |
| 77 if (!visible_) { | 109 if (!visible_) |
| 78 collection_->AddSystemNotification(notify, profile_, sticky); | 110 ShowNotification(notify); |
| 79 collection_->AddWebUIMessageCallback(notify, "link", callback); | 111 urgent_ = urgent; |
| 80 } | 112 } |
| 113 | |
| 114 void SystemNotification::ShowNotification(const Notification& notify) { | |
| 115 collection_->AddSystemNotification(notify, profile_, sticky_); | |
| 116 collection_->AddWebUIMessageCallback(notify, "link", callback_); | |
| 81 visible_ = true; | 117 visible_ = true; |
| 82 urgent_ = urgent; | |
| 83 } | 118 } |
| 84 | 119 |
| 85 void SystemNotification::Hide() { | 120 void SystemNotification::Hide() { |
| 86 if (visible_) { | 121 if (visible_) { |
| 87 collection_->RemoveById(delegate_->id()); | 122 collection_->RemoveById(delegate_->id()); |
| 88 visible_ = false; | 123 visible_ = false; |
| 89 urgent_ = false; | 124 urgent_ = false; |
| 90 } | 125 } |
| 91 } | 126 } |
| 92 | 127 |
| 93 //////////////////////////////////////////////////////////////////////////////// | 128 //////////////////////////////////////////////////////////////////////////////// |
| 94 // SystemNotification::Delegate | 129 // SystemNotification::Delegate |
| 95 | 130 |
| 96 SystemNotification::Delegate::Delegate(const std::string& id) | 131 SystemNotification::Delegate::Delegate(const std::string& id) |
| 97 : id_(id) { | 132 : id_(id) { |
| 98 } | 133 } |
| 99 | 134 |
| 100 std::string SystemNotification::Delegate::id() const { | 135 std::string SystemNotification::Delegate::id() const { |
| 101 return id_; | 136 return id_; |
| 102 } | 137 } |
| 103 | 138 |
| 104 } // namespace chromeos | 139 } // namespace chromeos |
| OLD | NEW |