Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / notifications / notification.cc
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/notifications/notification.h"
6
7 #include "base/strings/string_util.h"
8 #include "chrome/browser/notifications/desktop_notification_service.h"
9 #include "ui/base/webui/web_ui_util.h"
10
11 Notification::Notification(const GURL& origin_url,
12                            const GURL& icon_url,
13                            const base::string16& title,
14                            const base::string16& body,
15                            blink::WebTextDirection dir,
16                            const base::string16& display_source,
17                            const base::string16& replace_id,
18                            NotificationDelegate* delegate)
19     : message_center::Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
20                                    delegate->id(),
21                                    title,
22                                    body,
23                                    gfx::Image(),
24                                    display_source,
25                                    message_center::NotifierId(origin_url),
26                                    message_center::RichNotificationData(),
27                                    delegate),
28       origin_url_(origin_url),
29       icon_url_(icon_url),
30       replace_id_(replace_id),
31       delegate_(delegate) {
32   // "Upconvert" the string parameters to a data: URL.
33   content_url_ = GURL(DesktopNotificationService::CreateDataUrl(
34       icon_url, title, body, dir));
35 }
36
37 Notification::Notification(
38     message_center::NotificationType type,
39     const GURL& origin_url,
40     const base::string16& title,
41     const base::string16& body,
42     const gfx::Image& icon,
43     blink::WebTextDirection dir,
44     const message_center::NotifierId& notifier_id,
45     const base::string16& display_source,
46     const base::string16& replace_id,
47     const message_center::RichNotificationData& rich_notification_data,
48     NotificationDelegate* delegate)
49     : message_center::Notification(type,
50                                    delegate->id(),
51                                    title,
52                                    body,
53                                    icon,
54                                    display_source,
55                                    notifier_id,
56                                    rich_notification_data,
57                                    delegate),
58       origin_url_(origin_url),
59       replace_id_(replace_id),
60       delegate_(delegate) {
61   // It's important to leave |icon_url_| empty with rich notifications enabled,
62   // to prevent "Downloading" the data url and overwriting the existing |icon|.
63 }
64
65 Notification::Notification(const GURL& origin_url,
66                            const gfx::Image& icon,
67                            const base::string16& title,
68                            const base::string16& body,
69                            blink::WebTextDirection dir,
70                            const base::string16& display_source,
71                            const base::string16& replace_id,
72                            NotificationDelegate* delegate)
73     : message_center::Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
74                                    delegate->id(),
75                                    title,
76                                    body,
77                                    icon,
78                                    display_source,
79                                    message_center::NotifierId(origin_url),
80                                    message_center::RichNotificationData(),
81                                    delegate),
82       origin_url_(origin_url),
83       replace_id_(replace_id),
84       delegate_(delegate) {}
85
86 Notification::Notification(const Notification& notification)
87     : message_center::Notification(notification),
88       origin_url_(notification.origin_url()),
89       icon_url_(notification.icon_url()),
90       content_url_(notification.content_url()),
91       button_one_icon_url_(notification.button_one_icon_url()),
92       button_two_icon_url_(notification.button_two_icon_url()),
93       image_url_(notification.image_url()),
94       replace_id_(notification.replace_id()),
95       delegate_(notification.delegate()) {}
96
97 Notification::~Notification() {}
98
99 Notification& Notification::operator=(const Notification& notification) {
100   message_center::Notification::operator=(notification);
101   origin_url_ = notification.origin_url();
102   icon_url_ = notification.icon_url();
103   content_url_ = notification.content_url();
104   button_one_icon_url_ = notification.button_one_icon_url();
105   button_two_icon_url_ = notification.button_two_icon_url();
106   image_url_ = notification.image_url();
107   replace_id_ = notification.replace_id();
108   delegate_ = notification.delegate();
109   return *this;
110 }