|
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 #include "config.h" |
|
32 #include "WebNotification.h" |
|
33 |
|
34 #if ENABLE(NOTIFICATIONS) |
|
35 |
|
36 #include "Notification.h" |
|
37 |
|
38 #include "WebString.h" |
|
39 #include "WebTextDirection.h" |
|
40 #include "WebURL.h" |
|
41 |
|
42 #include <wtf/PassRefPtr.h> |
|
43 |
|
44 using namespace WebCore; |
|
45 |
|
46 namespace WebKit { |
|
47 |
|
48 class WebNotificationPrivate : public Notification { |
|
49 }; |
|
50 |
|
51 void WebNotification::reset() |
|
52 { |
|
53 assign(0); |
|
54 } |
|
55 |
|
56 void WebNotification::assign(const WebNotification& other) |
|
57 { |
|
58 WebNotificationPrivate* p = const_cast<WebNotificationPrivate*>(other.m_private); |
|
59 if (p) |
|
60 p->ref(); |
|
61 assign(p); |
|
62 } |
|
63 |
|
64 bool WebNotification::lessThan(const WebNotification& other) const |
|
65 { |
|
66 return reinterpret_cast<uintptr_t>(m_private) < reinterpret_cast<uintptr_t>(other.m_private); |
|
67 } |
|
68 |
|
69 bool WebNotification::isHTML() const |
|
70 { |
|
71 return m_private->isHTML(); |
|
72 } |
|
73 |
|
74 WebURL WebNotification::url() const |
|
75 { |
|
76 ASSERT(isHTML()); |
|
77 return m_private->url(); |
|
78 } |
|
79 |
|
80 WebURL WebNotification::iconURL() const |
|
81 { |
|
82 ASSERT(!isHTML()); |
|
83 return m_private->iconURL(); |
|
84 } |
|
85 |
|
86 WebString WebNotification::title() const |
|
87 { |
|
88 ASSERT(!isHTML()); |
|
89 return m_private->contents().title(); |
|
90 } |
|
91 |
|
92 WebString WebNotification::body() const |
|
93 { |
|
94 ASSERT(!isHTML()); |
|
95 return m_private->contents().body(); |
|
96 } |
|
97 |
|
98 // FIXME: remove dir() when unreferenced. Being replaced by direction(). |
|
99 WebString WebNotification::dir() const |
|
100 { |
|
101 return m_private->dir(); |
|
102 } |
|
103 |
|
104 WebTextDirection WebNotification::direction() const |
|
105 { |
|
106 return (m_private->direction() == RTL) ? |
|
107 WebTextDirectionRightToLeft : |
|
108 WebTextDirectionLeftToRight; |
|
109 } |
|
110 |
|
111 WebString WebNotification::replaceId() const |
|
112 { |
|
113 return m_private->replaceId(); |
|
114 } |
|
115 |
|
116 void WebNotification::dispatchDisplayEvent() |
|
117 { |
|
118 RefPtr<Event> event = Event::create("display", false, true); |
|
119 m_private->dispatchEvent(event.release()); |
|
120 } |
|
121 |
|
122 void WebNotification::dispatchErrorEvent(const WebKit::WebString& /* errorMessage */) |
|
123 { |
|
124 // FIXME: errorMessage not supported by WebCore yet |
|
125 RefPtr<Event> event = Event::create(eventNames().errorEvent, false, true); |
|
126 m_private->dispatchEvent(event.release()); |
|
127 } |
|
128 |
|
129 void WebNotification::dispatchCloseEvent(bool /* byUser */) |
|
130 { |
|
131 // FIXME: byUser flag not supported by WebCore yet |
|
132 RefPtr<Event> event = Event::create(eventNames().closeEvent, false, true); |
|
133 m_private->dispatchEvent(event.release()); |
|
134 } |
|
135 |
|
136 WebNotification::WebNotification(const WTF::PassRefPtr<Notification>& notification) |
|
137 : m_private(static_cast<WebNotificationPrivate*>(notification.releaseRef())) |
|
138 { |
|
139 } |
|
140 |
|
141 WebNotification& WebNotification::operator=(const WTF::PassRefPtr<Notification>& notification) |
|
142 { |
|
143 assign(static_cast<WebNotificationPrivate*>(notification.releaseRef())); |
|
144 return *this; |
|
145 } |
|
146 |
|
147 WebNotification::operator WTF::PassRefPtr<Notification>() const |
|
148 { |
|
149 return WTF::PassRefPtr<Notification>(const_cast<WebNotificationPrivate*>(m_private)); |
|
150 } |
|
151 |
|
152 void WebNotification::assign(WebNotificationPrivate* p) |
|
153 { |
|
154 // p is already ref'd for us by the caller |
|
155 if (m_private) |
|
156 m_private->deref(); |
|
157 m_private = p; |
|
158 } |
|
159 |
|
160 } // namespace WebKit |
|
161 |
|
162 #endif // ENABLE(NOTIFICATIONS) |