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 screen_locked_ = | |
20 DBusThreadManager::Get()->GetPowerManagerClient()->GetIsScreenLocked(); | |
Daniel Erat
2012/05/11 14:12:38
i don't see this method at git.chromium.org/gitweb
stevenjb
2012/05/11 16:35:29
Doh! Forgot to add those files...
| |
21 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | |
18 collection_ = static_cast<BalloonCollectionImplType*>( | 22 collection_ = static_cast<BalloonCollectionImplType*>( |
19 g_browser_process->notification_ui_manager()->balloon_collection()); | 23 g_browser_process->notification_ui_manager()->balloon_collection()); |
20 std::string url = web_ui_util::GetImageDataUrlFromResource(icon_resource_id); | 24 std::string url = web_ui_util::GetImageDataUrlFromResource(icon_resource_id); |
21 DCHECK(!url.empty()); | 25 DCHECK(!url.empty()); |
22 GURL tmp_gurl(url); | 26 GURL tmp_gurl(url); |
23 icon_.Swap(&tmp_gurl); | 27 icon_.Swap(&tmp_gurl); |
24 } | 28 } |
25 | 29 |
26 SystemNotification::SystemNotification(Profile* profile, | 30 SystemNotification::SystemNotification(Profile* profile, |
27 NotificationDelegate* delegate, | 31 NotificationDelegate* delegate, |
28 int icon_resource_id, | 32 int icon_resource_id, |
29 const string16& title) | 33 const string16& title) |
30 : profile_(profile), | 34 : profile_(profile), |
31 collection_(NULL), | 35 collection_(NULL), |
32 delegate_(delegate), | 36 delegate_(delegate), |
33 title_(title), | 37 title_(title), |
34 visible_(false), | 38 visible_(false), |
35 urgent_(false) { | 39 sticky_(false), |
40 urgent_(false), | |
41 screen_locked_(false) { | |
36 Init(icon_resource_id); | 42 Init(icon_resource_id); |
37 } | 43 } |
38 | 44 |
39 SystemNotification::SystemNotification(Profile* profile, | 45 SystemNotification::SystemNotification(Profile* profile, |
40 const std::string& id, | 46 const std::string& id, |
41 int icon_resource_id, | 47 int icon_resource_id, |
42 const string16& title) | 48 const string16& title) |
43 : profile_(profile), | 49 : profile_(profile), |
44 collection_(NULL), | 50 collection_(NULL), |
45 delegate_(new Delegate(id)), | 51 delegate_(new Delegate(id)), |
46 title_(title), | 52 title_(title), |
47 visible_(false), | 53 visible_(false), |
48 urgent_(false) { | 54 sticky_(false), |
55 urgent_(false), | |
56 screen_locked_(false) { | |
49 Init(icon_resource_id); | 57 Init(icon_resource_id); |
50 } | 58 } |
51 | 59 |
52 SystemNotification::~SystemNotification() { | 60 SystemNotification::~SystemNotification() { |
61 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | |
62 } | |
63 | |
64 void SystemNotification::LockScreen() { | |
65 screen_locked_ = true; | |
66 bool was_visible = visible_; | |
67 Hide(); | |
68 visible_ = was_visible; // Show on unlock. | |
69 } | |
70 | |
71 void SystemNotification::UnlockScreen() { | |
72 screen_locked_ = false; | |
73 if (visible_) { | |
74 visible_ = false; // Not actually visible yet | |
75 Notification notify = SystemNotificationFactory::Create( | |
76 icon_, title_, message_, link_, delegate_.get()); | |
77 ShowNotification(notify); | |
78 } | |
53 } | 79 } |
54 | 80 |
55 void SystemNotification::Show(const string16& message, | 81 void SystemNotification::Show(const string16& message, |
56 bool urgent, | 82 bool urgent, |
57 bool sticky) { | 83 bool sticky) { |
58 Show(message, string16(), BalloonViewHost::MessageCallback(), urgent, sticky); | 84 Show(message, string16(), BalloonViewHost::MessageCallback(), urgent, sticky); |
59 } | 85 } |
60 | 86 |
61 void SystemNotification::Show(const string16& message, | 87 void SystemNotification::Show(const string16& message, |
62 const string16& link, | 88 const string16& link, |
63 const BalloonViewHost::MessageCallback& callback, | 89 const BalloonViewHost::MessageCallback& callback, |
64 bool urgent, | 90 bool urgent, |
65 bool sticky) { | 91 bool sticky) { |
66 Notification notify = SystemNotificationFactory::Create(icon_, | 92 message_ = message; |
67 title_, message, link, delegate_.get()); | 93 link_ = link; |
94 callback_ = callback; | |
95 sticky_ = sticky; | |
96 if (screen_locked_) { | |
97 visible_ = true; // Show on unlock | |
98 return; | |
99 } | |
100 Notification notify = SystemNotificationFactory::Create( | |
101 icon_, title_, message_, link_, delegate_.get()); | |
68 if (visible_) { | 102 if (visible_) { |
69 // Force showing a user hidden notification on an urgent transition. | 103 // Force showing a user hidden notification on an urgent transition. |
70 if (urgent && !urgent_) { | 104 if (urgent && !urgent_) { |
71 if (!collection_->UpdateAndShowNotification(notify)) | 105 if (!collection_->UpdateAndShowNotification(notify)) |
72 visible_ = false; // re-show | 106 visible_ = false; // re-show |
73 } else { | 107 } else { |
74 collection_->UpdateNotification(notify); | 108 collection_->UpdateNotification(notify); |
75 } | 109 } |
76 } | 110 } |
111 urgent_ = urgent; | |
112 ShowNotification(notify); | |
113 } | |
114 | |
115 void SystemNotification::ShowNotification(const Notification& notify) { | |
77 if (!visible_) { | 116 if (!visible_) { |
78 collection_->AddSystemNotification(notify, profile_, sticky); | 117 collection_->AddSystemNotification(notify, profile_, sticky_); |
79 collection_->AddWebUIMessageCallback(notify, "link", callback); | 118 collection_->AddWebUIMessageCallback(notify, "link", callback_); |
80 } | 119 } |
81 visible_ = true; | 120 visible_ = true; |
82 urgent_ = urgent; | |
83 } | 121 } |
84 | 122 |
85 void SystemNotification::Hide() { | 123 void SystemNotification::Hide() { |
86 if (visible_) { | 124 if (visible_) { |
87 collection_->RemoveById(delegate_->id()); | 125 collection_->RemoveById(delegate_->id()); |
88 visible_ = false; | 126 visible_ = false; |
89 urgent_ = false; | 127 urgent_ = false; |
90 } | 128 } |
91 } | 129 } |
92 | 130 |
93 //////////////////////////////////////////////////////////////////////////////// | 131 //////////////////////////////////////////////////////////////////////////////// |
94 // SystemNotification::Delegate | 132 // SystemNotification::Delegate |
95 | 133 |
96 SystemNotification::Delegate::Delegate(const std::string& id) | 134 SystemNotification::Delegate::Delegate(const std::string& id) |
97 : id_(id) { | 135 : id_(id) { |
98 } | 136 } |
99 | 137 |
100 std::string SystemNotification::Delegate::id() const { | 138 std::string SystemNotification::Delegate::id() const { |
101 return id_; | 139 return id_; |
102 } | 140 } |
103 | 141 |
104 } // namespace chromeos | 142 } // namespace chromeos |
OLD | NEW |