| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/resource_bundle.h" |
| 8 #include "base/base64.h" |
| 7 #include "base/move.h" | 9 #include "base/move.h" |
| 8 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/notifications/system_notification_factory.h" | 11 #include "chrome/browser/chromeos/notifications/system_notification_factory.h" |
| 10 #include "chrome/browser/notifications/notification.h" | 12 #include "chrome/browser/notifications/notification.h" |
| 11 #include "chrome/browser/notifications/notification_ui_manager.h" | 13 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 12 | 14 |
| 13 namespace chromeos { | 15 namespace chromeos { |
| 14 | 16 |
| 15 SystemNotification::SystemNotification(Profile* profile, std::string id, | 17 SystemNotification::SystemNotification(Profile* profile, std::string id, |
| 16 string16 title) | 18 int icon_resource_id, string16 title) |
| 17 : profile_(profile), | 19 : profile_(profile), |
| 18 collection_(static_cast<BalloonCollectionImpl*>( | 20 collection_(static_cast<BalloonCollectionImpl*>( |
| 19 g_browser_process->notification_ui_manager()->balloon_collection())), | 21 g_browser_process->notification_ui_manager()->balloon_collection())), |
| 20 delegate_(new Delegate(base::move(id))), | 22 delegate_(new Delegate(base::move(id))), |
| 21 title_(move(title)), | 23 title_(move(title)), |
| 22 visible_(false) {} | 24 visible_(false), |
| 25 urgent_(false) { |
| 26 // Load resource icon and covert to base64 encoded data url |
| 27 scoped_refptr<RefCountedMemory> raw_icon(ResourceBundle::GetSharedInstance(). |
| 28 LoadDataResourceBytes(icon_resource_id)); |
| 29 std::string str_gurl; |
| 30 std::copy(raw_icon->front(), raw_icon->front() + raw_icon->size(), |
| 31 std::back_inserter(str_gurl)); |
| 32 base::Base64Encode(str_gurl, &str_gurl); |
| 33 str_gurl.insert(0, "data:image/png;base64,"); |
| 34 GURL tmp_gurl(str_gurl); |
| 35 icon_.Swap(&tmp_gurl); |
| 36 } |
| 23 | 37 |
| 24 SystemNotification::~SystemNotification() { | 38 SystemNotification::~SystemNotification() { |
| 25 Hide(); | 39 Hide(); |
| 26 } | 40 } |
| 27 | 41 |
| 28 void SystemNotification::Show(const string16& message) { | 42 void SystemNotification::Show(const string16& message, bool urgent) { |
| 29 Notification notify = SystemNotificationFactory::Create(GURL(), | 43 Notification notify = SystemNotificationFactory::Create(icon_, |
| 30 title_, message, delegate_.get()); | 44 title_, message, delegate_.get()); |
| 31 if (visible_) { | 45 if (visible_) { |
| 32 collection_->UpdateNotification(notify); | 46 // Force showing a user hidden notification on an urgent transition. |
| 47 if (urgent && !urgent_) { |
| 48 collection_->UpdateAndShowNotification(notify); |
| 49 } else { |
| 50 collection_->UpdateNotification(notify); |
| 51 } |
| 33 } else { | 52 } else { |
| 34 collection_->AddSystemNotification(notify, profile_, true /* sticky */, | 53 collection_->AddSystemNotification(notify, profile_, true /* sticky */, |
| 35 false /* no controls */); | 54 false /* no controls */); |
| 36 visible_ = true; | |
| 37 } | 55 } |
| 56 visible_ = true; |
| 57 urgent_ = urgent; |
| 38 } | 58 } |
| 39 | 59 |
| 40 void SystemNotification::Hide() { | 60 void SystemNotification::Hide() { |
| 41 if (visible_) { | 61 if (visible_) { |
| 42 collection_->Remove(Notification(GURL(), GURL(), std::wstring(), | 62 collection_->Remove(Notification(GURL(), GURL(), std::wstring(), |
| 43 delegate_.get())); | 63 delegate_.get())); |
| 44 | 64 |
| 45 visible_ = false; | 65 visible_ = false; |
| 66 urgent_ = false; |
| 46 } | 67 } |
| 47 } | 68 } |
| 48 | 69 |
| 49 } // namespace chromeos | 70 } // namespace chromeos |
| 50 | 71 |
| OLD | NEW |