• 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 #include "config.h"
32 #include "WebNotification.h"
33 
34 #if ENABLE(NOTIFICATIONS)
35 
36 #include "Notification.h"
37 #include "UserGestureIndicator.h"
38 
39 #include "WebString.h"
40 #include "WebTextDirection.h"
41 #include "WebURL.h"
42 
43 #include <wtf/PassRefPtr.h>
44 
45 using namespace WebCore;
46 
47 namespace WebKit {
48 
49 class WebNotificationPrivate : public Notification {
50 };
51 
reset()52 void WebNotification::reset()
53 {
54     assign(0);
55 }
56 
assign(const WebNotification & other)57 void WebNotification::assign(const WebNotification& other)
58 {
59     WebNotificationPrivate* p = const_cast<WebNotificationPrivate*>(other.m_private);
60     if (p)
61         p->ref();
62     assign(p);
63 }
64 
lessThan(const WebNotification & other) const65 bool WebNotification::lessThan(const WebNotification& other) const
66 {
67     return reinterpret_cast<uintptr_t>(m_private) < reinterpret_cast<uintptr_t>(other.m_private);
68 }
69 
isHTML() const70 bool WebNotification::isHTML() const
71 {
72     return m_private->isHTML();
73 }
74 
url() const75 WebURL WebNotification::url() const
76 {
77     ASSERT(isHTML());
78     return m_private->url();
79 }
80 
iconURL() const81 WebURL WebNotification::iconURL() const
82 {
83     ASSERT(!isHTML());
84     return m_private->iconURL();
85 }
86 
title() const87 WebString WebNotification::title() const
88 {
89     ASSERT(!isHTML());
90     return m_private->contents().title();
91 }
92 
body() const93 WebString WebNotification::body() const
94 {
95     ASSERT(!isHTML());
96     return m_private->contents().body();
97 }
98 
direction() const99 WebTextDirection WebNotification::direction() const
100 {
101     return (m_private->direction() == RTL) ?
102         WebTextDirectionRightToLeft :
103         WebTextDirectionLeftToRight;
104 }
105 
replaceId() const106 WebString WebNotification::replaceId() const
107 {
108     return m_private->replaceId();
109 }
110 
detachPresenter()111 void WebNotification::detachPresenter()
112 {
113     m_private->detachPresenter();
114 }
115 
dispatchDisplayEvent()116 void WebNotification::dispatchDisplayEvent()
117 {
118     RefPtr<Event> event = Event::create("display", false, true);
119     m_private->dispatchEvent(event.release());
120 }
121 
dispatchErrorEvent(const WebKit::WebString &)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 
dispatchCloseEvent(bool)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 
dispatchClickEvent()136 void WebNotification::dispatchClickEvent()
137 {
138     // Make sure clicks on notifications are treated as user gestures.
139     UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
140     RefPtr<Event> event = Event::create(eventNames().clickEvent, false, true);
141     m_private->dispatchEvent(event.release());
142 }
143 
WebNotification(const WTF::PassRefPtr<Notification> & notification)144 WebNotification::WebNotification(const WTF::PassRefPtr<Notification>& notification)
145     : m_private(static_cast<WebNotificationPrivate*>(notification.releaseRef()))
146 {
147 }
148 
operator =(const WTF::PassRefPtr<Notification> & notification)149 WebNotification& WebNotification::operator=(const WTF::PassRefPtr<Notification>& notification)
150 {
151     assign(static_cast<WebNotificationPrivate*>(notification.releaseRef()));
152     return *this;
153 }
154 
operator WTF::PassRefPtr<Notification>() const155 WebNotification::operator WTF::PassRefPtr<Notification>() const
156 {
157     return WTF::PassRefPtr<Notification>(const_cast<WebNotificationPrivate*>(m_private));
158 }
159 
assign(WebNotificationPrivate * p)160 void WebNotification::assign(WebNotificationPrivate* p)
161 {
162     // p is already ref'd for us by the caller
163     if (m_private)
164         m_private->deref();
165     m_private = p;
166 }
167 
168 } // namespace WebKit
169 
170 #endif // ENABLE(NOTIFICATIONS)
171