summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/notification.cc
blob: 376ec0f08dc1e665de26eb6885414caefe6f409a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/notifications/notification.h"

#include "chrome/browser/notifications/desktop_notification_service.h"

Notification::Notification(const GURL& origin_url,
                           const GURL& content_url,
                           const string16& display_source,
                           const string16& replace_id,
                           NotificationDelegate* delegate)
 : type_(ui::notifications::NOTIFICATION_TYPE_SIMPLE),
    origin_url_(origin_url),
    is_html_(true),
    content_url_(content_url),
    display_source_(display_source),
    replace_id_(replace_id),
    delegate_(delegate) {
}

Notification::Notification(const GURL& origin_url,
                           const GURL& icon_url,
                           const string16& title,
                           const string16& body,
                           WebKit::WebTextDirection dir,
                           const string16& display_source,
                           const string16& replace_id,
                           NotificationDelegate* delegate)
    : type_(ui::notifications::NOTIFICATION_TYPE_SIMPLE),
      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.
  content_url_ = GURL(DesktopNotificationService::CreateDataUrl(
      icon_url, title, body, dir));
}

Notification::Notification(ui::notifications::NotificationType type,
                           const GURL& origin_url,
                           const GURL& icon_url,
                           const string16& title,
                           const string16& body,
                           WebKit::WebTextDirection dir,
                           const string16& display_source,
                           const string16& replace_id,
                           const DictionaryValue* optional_fields,
                           NotificationDelegate* delegate)
    : type_(type),
      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());
  // "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(const GURL& origin_url,
                           const gfx::ImageSkia& icon,
                           const string16& title,
                           const string16& body,
                           WebKit::WebTextDirection dir,
                           const string16& display_source,
                           const string16& replace_id,
                           NotificationDelegate* delegate)
    : type_(ui::notifications::NOTIFICATION_TYPE_SIMPLE),
      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()),
      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()),
      replace_id_(notification.replace_id()),
      delegate_(notification.delegate()) {
  if (notification.optional_fields())
    optional_fields_.reset(notification.optional_fields()->DeepCopy());
}

Notification::~Notification() {}

Notification& Notification::operator=(const Notification& notification) {
  type_ = notification.type();
  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();
  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;
}