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.
32
#include "WebNotification.h"
34
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
37
#include "Notification.h"
38
#include "UserGestureIndicator.h"
39
#include "WindowFocusAllowedIndicator.h"
40
#include "WebTextDirection.h"
41
#include <public/WebString.h>
42
#include <public/WebURL.h>
43
#include <wtf/PassRefPtr.h>
45
using namespace WebCore;
49
class WebNotificationPrivate : public Notification {
52
void WebNotification::reset()
57
void WebNotification::assign(const WebNotification& other)
59
WebNotificationPrivate* p = const_cast<WebNotificationPrivate*>(other.m_private);
65
bool WebNotification::lessThan(const WebNotification& other) const
67
return reinterpret_cast<uintptr_t>(m_private) < reinterpret_cast<uintptr_t>(other.m_private);
70
bool WebNotification::isHTML() const
72
return m_private->isHTML();
75
WebURL WebNotification::url() const
78
return m_private->url();
81
WebURL WebNotification::iconURL() const
84
return m_private->iconURL();
87
WebString WebNotification::title() const
90
return m_private->title();
93
WebString WebNotification::body() const
96
return m_private->body();
99
WebTextDirection WebNotification::direction() const
101
return (m_private->direction() == RTL) ?
102
WebTextDirectionRightToLeft :
103
WebTextDirectionLeftToRight;
106
WebString WebNotification::replaceId() const
108
return m_private->tag();
111
void WebNotification::detachPresenter()
113
m_private->detachPresenter();
116
void WebNotification::dispatchDisplayEvent()
118
#if ENABLE(LEGACY_NOTIFICATIONS)
119
dispatchEvent("display");
121
dispatchEvent("show");
124
void WebNotification::dispatchErrorEvent(const WebKit::WebString& /* errorMessage */)
126
// FIXME: errorMessage not supported by WebCore yet
127
dispatchEvent(eventNames().errorEvent);
130
void WebNotification::dispatchCloseEvent(bool /* byUser */)
132
// FIXME: byUser flag not supported by WebCore yet
133
dispatchEvent(eventNames().closeEvent);
136
void WebNotification::dispatchClickEvent()
138
UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
139
WindowFocusAllowedIndicator windowFocusAllowed;
140
dispatchEvent(eventNames().clickEvent);
143
void WebNotification::dispatchEvent(const WTF::AtomicString& type)
145
// Do not dispatch if the context is gone.
146
if (!m_private->scriptExecutionContext())
149
RefPtr<Event> event = Event::create(type, false, true);
150
m_private->dispatchEvent(event.release());
153
WebNotification::WebNotification(const WTF::PassRefPtr<Notification>& notification)
154
: m_private(static_cast<WebNotificationPrivate*>(notification.leakRef()))
158
WebNotification& WebNotification::operator=(const WTF::PassRefPtr<Notification>& notification)
160
assign(static_cast<WebNotificationPrivate*>(notification.leakRef()));
164
WebNotification::operator WTF::PassRefPtr<Notification>() const
166
return WTF::PassRefPtr<Notification>(const_cast<WebNotificationPrivate*>(m_private));
169
void WebNotification::assign(WebNotificationPrivate* p)
171
// p is already ref'd for us by the caller
177
} // namespace WebKit
179
#endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)