• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30 
31 #ifndef WebNotification_h
32 #define WebNotification_h
33 
34 #include "WebCommon.h"
35 #include "WebTextDirection.h"
36 
37 #if WEBKIT_IMPLEMENTATION
38 namespace WebCore { class Notification; }
39 namespace WTF { template <typename T> class PassRefPtr; }
40 #endif
41 
42 namespace WebKit {
43 
44 class WebNotificationPrivate;
45 class WebURL;
46 class WebString;
47 
48 // Represents access to a desktop notification.
49 class WebNotification {
50 public:
WebNotification()51     WebNotification() : m_private(0) { }
WebNotification(const WebNotification & other)52     WebNotification(const WebNotification& other) : m_private(0) { assign(other); }
53 
~WebNotification()54     ~WebNotification() { reset(); }
55 
56     WEBKIT_API void reset();
57     WEBKIT_API void assign(const WebNotification&);
58 
59     WebNotification& operator=(const WebNotification& other)
60     {
61         assign(other);
62         return *this;
63     }
64 
65     // Operators required to put WebNotification in an ordered map.
equals(const WebNotification & other)66     bool equals(const WebNotification& other) const { return m_private == other.m_private; }
67     WEBKIT_API bool lessThan(const WebNotification& other) const;
68 
69     // Is the notification HTML vs. icon-title-text?
70     WEBKIT_API bool isHTML() const;
71 
72     // If HTML, the URL which contains the contents of the notification.
73     WEBKIT_API WebURL url() const;
74 
75     WEBKIT_API WebURL iconURL() const;
76     WEBKIT_API WebString title() const;
77     WEBKIT_API WebString body() const;
78     WEBKIT_API WebTextDirection direction() const;
79 
80     WEBKIT_API WebString replaceId() const;
81 
82     // Called if the presenter goes out of scope before the notification does.
83     WEBKIT_API void detachPresenter();
84 
85     // Called to indicate the notification has been displayed.
86     WEBKIT_API void dispatchDisplayEvent();
87 
88     // Called to indicate an error has occurred with this notification.
89     WEBKIT_API void dispatchErrorEvent(const WebString& errorMessage);
90 
91     // Called to indicate the notification has been closed.  If it was
92     // closed by the user (as opposed to automatically by the system),
93     // the byUser parameter will be true.
94     WEBKIT_API void dispatchCloseEvent(bool byUser);
95 
96     // Called to indicate the notification was clicked on.
97     WEBKIT_API void dispatchClickEvent();
98 
99 #if WEBKIT_IMPLEMENTATION
100     WebNotification(const WTF::PassRefPtr<WebCore::Notification>&);
101     WebNotification& operator=(const WTF::PassRefPtr<WebCore::Notification>&);
102     operator WTF::PassRefPtr<WebCore::Notification>() const;
103 #endif
104 
105 private:
106     void assign(WebNotificationPrivate*);
107     WebNotificationPrivate* m_private;
108 };
109 
110 inline bool operator==(const WebNotification& a, const WebNotification& b)
111 {
112     return a.equals(b);
113 }
114 
115 inline bool operator!=(const WebNotification& a, const WebNotification& b)
116 {
117     return !a.equals(b);
118 }
119 
120 inline bool operator<(const WebNotification& a, const WebNotification& b)
121 {
122     return a.lessThan(b);
123 }
124 
125 } // namespace WebKit
126 
127 #endif
128