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

Unified Diff: chrome/browser/notifications/notification.cc

Issue 14631005: Enable users of NotificationUIManager to specify binary images. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase for relanding. Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/notification.cc
diff --git a/chrome/browser/notifications/notification.cc b/chrome/browser/notifications/notification.cc
index 3e24b23e2d353f65a2e006e74c50e750bacd42ec..592ca43ec26047f435c558981d540f24e6f23411 100644
--- a/chrome/browser/notifications/notification.cc
+++ b/chrome/browser/notifications/notification.cc
@@ -4,18 +4,28 @@
#include "chrome/browser/notifications/notification.h"
+#include "base/string_util.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "ui/message_center/message_center_util.h"
+#include "ui/webui/web_ui_util.h"
Notification::Notification(const GURL& origin_url,
const GURL& content_url,
const string16& display_source,
const string16& replace_id,
NotificationDelegate* delegate)
- : type_(message_center::NOTIFICATION_TYPE_SIMPLE),
+ : message_center::Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
+ delegate->id(),
+ EmptyString16(),
+ EmptyString16(),
+ gfx::Image(),
+ display_source,
+ origin_url.spec(),
+ NULL,
+ delegate),
origin_url_(origin_url),
is_html_(true),
content_url_(content_url),
- display_source_(display_source),
replace_id_(replace_id),
delegate_(delegate) {}
@@ -27,13 +37,18 @@ Notification::Notification(const GURL& origin_url,
const string16& display_source,
const string16& replace_id,
NotificationDelegate* delegate)
- : type_(message_center::NOTIFICATION_TYPE_SIMPLE),
+ : message_center::Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
+ delegate->id(),
+ title,
+ body,
+ gfx::Image(),
+ display_source,
+ origin_url.spec(),
+ NULL,
+ delegate),
origin_url_(origin_url),
icon_url_(icon_url),
is_html_(false),
- title_(title),
- body_(body),
- display_source_(display_source),
replace_id_(replace_id),
delegate_(delegate) {
// "Upconvert" the string parameters to a data: URL.
@@ -51,24 +66,63 @@ Notification::Notification(message_center::NotificationType type,
const string16& replace_id,
const DictionaryValue* optional_fields,
NotificationDelegate* delegate)
- : type_(type),
+ : message_center::Notification(type,
+ delegate->id(),
+ title,
+ body,
+ gfx::Image(),
+ display_source,
+ origin_url.spec(),
+ optional_fields,
+ delegate),
origin_url_(origin_url),
icon_url_(icon_url),
is_html_(false),
- title_(title),
- body_(body),
- display_source_(display_source),
replace_id_(replace_id),
- optional_fields_(NULL),
delegate_(delegate) {
if (optional_fields)
- optional_fields_.reset(optional_fields->DeepCopy());
+ ApplyOptionalFields(optional_fields);
// "Upconvert" the string parameters to a data: URL. Some balloon views
// require content URL to render anything, so this serves as a backup.
content_url_ = GURL(DesktopNotificationService::CreateDataUrl(
icon_url, title, body, dir));
}
+Notification::Notification(
+ message_center::NotificationType type,
+ const GURL& origin_url,
+ const string16& title,
+ const string16& body,
+ const gfx::Image& icon,
+ WebKit::WebTextDirection dir,
+ const string16& display_source,
+ const string16& replace_id,
+ const message_center::RichNotificationData& rich_notification_data,
+ NotificationDelegate* delegate)
+ : message_center::Notification(type,
+ delegate->id(),
+ title,
+ body,
+ icon,
+ display_source,
+ origin_url.spec(),
+ rich_notification_data,
+ delegate),
+ origin_url_(origin_url),
+ is_html_(false),
+ replace_id_(replace_id),
+ delegate_(delegate) {
+ if (!message_center::IsRichNotificationEnabled()) {
+ // "Upconvert" the string parameters to a data: URL. Some balloon views
+ // require content URL to render anything, so this serves as a backup.
+ GURL icon_url;
+ if (!icon.IsEmpty())
+ icon_url_ = GURL(webui::GetBitmapDataUrl(*icon.ToSkBitmap()));
+ content_url_ = GURL(
+ DesktopNotificationService::CreateDataUrl(icon_url, title, body, dir));
+ }
+}
+
Notification::Notification(const GURL& origin_url,
const gfx::Image& icon,
const string16& title,
@@ -77,55 +131,60 @@ Notification::Notification(const GURL& origin_url,
const string16& display_source,
const string16& replace_id,
NotificationDelegate* delegate)
- : type_(message_center::NOTIFICATION_TYPE_SIMPLE),
+ : message_center::Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
+ delegate->id(),
+ title,
+ body,
+ icon,
+ display_source,
+ origin_url.spec(),
+ NULL,
+ delegate),
origin_url_(origin_url),
- icon_(icon),
is_html_(false),
- title_(title),
- body_(body),
- display_source_(display_source),
replace_id_(replace_id),
delegate_(delegate) {}
Notification::Notification(const Notification& notification)
- : type_(notification.type()),
+ : message_center::Notification(notification),
origin_url_(notification.origin_url()),
- icon_(notification.icon()),
icon_url_(notification.icon_url()),
is_html_(notification.is_html()),
content_url_(notification.content_url()),
- title_(notification.title()),
- body_(notification.body()),
- display_source_(notification.display_source()),
+ button_one_icon_url_(notification.button_one_icon_url()),
+ button_two_icon_url_(notification.button_two_icon_url()),
+ image_url_(notification.image_url()),
replace_id_(notification.replace_id()),
- delegate_(notification.delegate()) {
- if (notification.optional_fields())
- optional_fields_.reset(notification.optional_fields()->DeepCopy());
-}
+ delegate_(notification.delegate()) {}
Notification::~Notification() {}
Notification& Notification::operator=(const Notification& notification) {
- type_ = notification.type();
+ message_center::Notification::operator=(notification);
origin_url_ = notification.origin_url();
- icon_ = notification.icon_;
icon_url_ = notification.icon_url();
is_html_ = notification.is_html();
content_url_ = notification.content_url();
- title_ = notification.title();
- body_ = notification.body();
- display_source_ = notification.display_source();
+ button_one_icon_url_ = notification.button_one_icon_url();
+ button_two_icon_url_ = notification.button_two_icon_url();
+ image_url_ = notification.image_url();
replace_id_ = notification.replace_id();
- if (notification.optional_fields())
- optional_fields_.reset(notification.optional_fields()->DeepCopy());
- else
- optional_fields_.reset();
delegate_ = notification.delegate();
return *this;
}
-void Notification::DisableTimeout() {
- if (!optional_fields_.get())
- optional_fields_.reset(new base::DictionaryValue());
- optional_fields_->SetBoolean(message_center::kPrivateNeverTimeoutKey, true);
+void Notification::ApplyOptionalFields(const DictionaryValue* optional_fields) {
+ if (!optional_fields)
+ return;
+
+ string16 url;
+ if (optional_fields->GetString(message_center::kButtonOneIconUrlKey, &url)) {
+ button_one_icon_url_ = GURL(url);
+ }
+ if (optional_fields->GetString(message_center::kButtonTwoIconUrlKey, &url)) {
+ button_two_icon_url_ = GURL(url);
+ }
+ if (optional_fields->GetString(message_center::kImageUrlKey, &url)) {
+ image_url_ = GURL(url);
+ }
}
« no previous file with comments | « chrome/browser/notifications/notification.h ('k') | chrome/browser/notifications/notification_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698