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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
6#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
7#pragma once
8
9#include <string>
10
11#include "base/basictypes.h"
12#include "chrome/browser/notifications/notification_object_proxy.h"
13#include "googleurl/src/gurl.h"
14
15class NotificationDelegate;
16
17// Representation of an notification to be shown to the user.  All
18// notifications at this level are HTML, although they may be
19// data: URLs representing simple text+icon notifications.
20class Notification {
21 public:
22  Notification(const GURL& origin_url,
23               const GURL& content_url,
24               const string16& display_source,
25               const string16& replace_id,
26               NotificationDelegate* delegate);
27  Notification(const Notification& notification);
28  ~Notification();
29  Notification& operator=(const Notification& notification);
30
31  // The URL (may be data:) containing the contents for the notification.
32  const GURL& content_url() const { return content_url_; }
33
34  // The origin URL of the script which requested the notification.
35  const GURL& origin_url() const { return origin_url_; }
36
37  // A display string for the source of the notification.
38  const string16& display_source() const { return display_source_; }
39
40  const string16& replace_id() const { return replace_id_; }
41
42  void Display() const { delegate()->Display(); }
43  void Error() const { delegate()->Error(); }
44  void Click() const { delegate()->Click(); }
45  void Close(bool by_user) const { delegate()->Close(by_user); }
46
47  std::string notification_id() const { return delegate()->id(); }
48
49 private:
50  NotificationDelegate* delegate() const { return delegate_.get(); }
51
52  // The Origin of the page/worker which created this notification.
53  GURL origin_url_;
54
55  // The URL of the HTML content of the toast (may be a data: URL for simple
56  // string-based notifications).
57  GURL content_url_;
58
59  // The display string for the source of the notification.  Could be
60  // the same as origin_url_, or the name of an extension.
61  string16 display_source_;
62
63  // The replace ID for the notification.
64  string16 replace_id_;
65
66  // A proxy object that allows access back to the JavaScript object that
67  // represents the notification, for firing events.
68  scoped_refptr<NotificationDelegate> delegate_;
69};
70
71#endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
72