1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file.
4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once
8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
9201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch#include <string>
10201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch
11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/basictypes.h"
12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/notifications/notification_object_proxy.h"
13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "googleurl/src/gurl.h"
14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass NotificationDelegate;
16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Representation of an notification to be shown to the user.  All
18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// notifications at this level are HTML, although they may be
19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// data: URLs representing simple text+icon notifications.
20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass Notification {
21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
22731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  Notification(const GURL& origin_url,
23731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick               const GURL& content_url,
243345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick               const string16& display_source,
25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch               const string16& replace_id,
26731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick               NotificationDelegate* delegate);
27731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  Notification(const Notification& notification);
28731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ~Notification();
29731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  Notification& operator=(const Notification& notification);
30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The URL (may be data:) containing the contents for the notification.
32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const GURL& content_url() const { return content_url_; }
33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The origin URL of the script which requested the notification.
35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const GURL& origin_url() const { return origin_url_; }
36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // A display string for the source of the notification.
383345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  const string16& display_source() const { return display_source_; }
39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const string16& replace_id() const { return replace_id_; }
41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void Display() const { delegate()->Display(); }
43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void Error() const { delegate()->Error(); }
443345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void Click() const { delegate()->Click(); }
45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void Close(bool by_user) const { delegate()->Close(by_user); }
46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
47201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  std::string notification_id() const { return delegate()->id(); }
48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  NotificationDelegate* delegate() const { return delegate_.get(); }
51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
52c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The Origin of the page/worker which created this notification.
53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  GURL origin_url_;
54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The URL of the HTML content of the toast (may be a data: URL for simple
56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // string-based notifications).
57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  GURL content_url_;
58c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The display string for the source of the notification.  Could be
60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // the same as origin_url_, or the name of an extension.
613345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  string16 display_source_;
62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The replace ID for the notification.
64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  string16 replace_id_;
65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // A proxy object that allows access back to the JavaScript object that
67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // represents the notification, for firing events.
68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_refptr<NotificationDelegate> delegate_;
69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
72