2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef WebNotification_h
32 #define WebNotification_h
34 #include "WebTextDirection.h"
35 #include "platform/WebCommon.h"
37 #if WEBKIT_IMPLEMENTATION
38 namespace WebCore { class Notification; }
39 namespace WTF { template <typename T> class PassRefPtr; }
48 class WebNotificationPrivate;
52 // Represents access to a desktop notification.
53 class WebNotification {
55 WebNotification() : m_private(0) { }
56 WebNotification(const WebNotification& other) : m_private(0) { assign(other); }
58 ~WebNotification() { reset(); }
60 WEBKIT_EXPORT void reset();
61 WEBKIT_EXPORT void assign(const WebNotification&);
63 WebNotification& operator=(const WebNotification& other)
69 // Operators required to put WebNotification in an ordered map.
70 bool equals(const WebNotification& other) const { return m_private == other.m_private; }
71 WEBKIT_EXPORT bool lessThan(const WebNotification& other) const;
73 // Is the notification HTML vs. icon-title-text?
74 WEBKIT_EXPORT bool isHTML() const;
76 // If HTML, the URL which contains the contents of the notification.
77 WEBKIT_EXPORT WebURL url() const;
79 WEBKIT_EXPORT WebURL iconURL() const;
80 WEBKIT_EXPORT WebString title() const;
81 WEBKIT_EXPORT WebString body() const;
82 WEBKIT_EXPORT WebTextDirection direction() const;
84 WEBKIT_EXPORT WebString replaceId() const;
86 // Called if the presenter goes out of scope before the notification does.
87 WEBKIT_EXPORT void detachPresenter();
89 // Called to indicate the notification has been displayed.
90 WEBKIT_EXPORT void dispatchDisplayEvent();
92 // Called to indicate an error has occurred with this notification.
93 WEBKIT_EXPORT void dispatchErrorEvent(const WebString& errorMessage);
95 // Called to indicate the notification has been closed. If it was
96 // closed by the user (as opposed to automatically by the system),
97 // the byUser parameter will be true.
98 WEBKIT_EXPORT void dispatchCloseEvent(bool byUser);
100 // Called to indicate the notification was clicked on.
101 WEBKIT_EXPORT void dispatchClickEvent();
103 #if WEBKIT_IMPLEMENTATION
104 WebNotification(const WTF::PassRefPtr<WebCore::Notification>&);
105 WebNotification& operator=(const WTF::PassRefPtr<WebCore::Notification>&);
106 operator WTF::PassRefPtr<WebCore::Notification>() const;
110 void assign(WebNotificationPrivate*);
111 void dispatchEvent(const WTF::AtomicString& type);
112 WebNotificationPrivate* m_private;
115 inline bool operator==(const WebNotification& a, const WebNotification& b)
120 inline bool operator!=(const WebNotification& a, const WebNotification& b)
125 inline bool operator<(const WebNotification& a, const WebNotification& b)
127 return a.lessThan(b);
130 } // namespace WebKit