summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/notification.h
blob: f80a65fcbceb67f7c0fb3ce3938b72fa08d9ae48 (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
// Copyright (c) 2009 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.

#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_

#include <string>

#include "base/basictypes.h"
#include "chrome/browser/notifications/notification_object_proxy.h"
#include "googleurl/src/gurl.h"

// Representation of an notification to be shown to the user.  All
// notifications at this level are HTML, although they may be
// data: URLs representing simple text+icon notifications.
class Notification {
 public:
  Notification(const GURL& origin_url, const GURL& content_url,
               const std::wstring& display_source,
               NotificationObjectProxy* proxy,
               bool sticky)
      : origin_url_(origin_url),
        content_url_(content_url),
        display_source_(display_source),
        proxy_(proxy),
        sticky_(sticky) {
  }

  Notification(const Notification& notification)
      : origin_url_(notification.origin_url()),
        content_url_(notification.content_url()),
        display_source_(notification.display_source()),
        proxy_(notification.proxy()),
        sticky_(notification.sticky()) {
  }

  // The URL (may be data:) containing the contents for the notification.
  const GURL& content_url() const { return content_url_; }

  // The origin URL of the script which requested the notification.
  const GURL& origin_url() const { return origin_url_; }

  // A display string for the source of the notification.
  const std::wstring& display_source() const { return display_source_; }

  void Display() const { proxy()->Display(); }
  void Error() const { proxy()->Error(); }
  void Close(bool by_user) const { proxy()->Close(by_user); }

  bool sticky() const {
    return sticky_;
  }

  bool IsSame(const Notification& other) const {
    return (*proxy_).IsSame(*(other.proxy()));
  }

 private:
  NotificationObjectProxy* proxy() const { return proxy_.get(); }

  // The Origin of the page/worker which created this notification.
  GURL origin_url_;

  // The URL of the HTML content of the toast (may be a data: URL for simple
  // string-based notifications).
  GURL content_url_;

  // The display string for the source of the notification.  Could be
  // the same as origin_url_, or the name of an extension.
  std::wstring display_source_;

  // A proxy object that allows access back to the JavaScript object that
  // represents the notification, for firing events.
  scoped_refptr<NotificationObjectProxy> proxy_;

  // A sticky flag. A sticky notification cannot be dismissed by a
  // user.
  bool sticky_;

  // Disallow assign.  Copy constructor written above.
  void operator=(const Notification&);
};

#endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_