~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit/chromium/src/WebNotification.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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) || ENABLE(LEGACY_NOTIFICATIONS)
 
35
 
 
36
#include "Event.h"
 
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>
 
44
 
 
45
using namespace WebCore;
 
46
 
 
47
namespace WebKit {
 
48
 
 
49
class WebNotificationPrivate : public Notification {
 
50
};
 
51
 
 
52
void WebNotification::reset()
 
53
{
 
54
    assign(0);
 
55
}
 
56
 
 
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
 
 
65
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
 
 
70
bool WebNotification::isHTML() const
 
71
{
 
72
    return m_private->isHTML();
 
73
}
 
74
 
 
75
WebURL WebNotification::url() const
 
76
{
 
77
    ASSERT(isHTML());
 
78
    return m_private->url();
 
79
}
 
80
 
 
81
WebURL WebNotification::iconURL() const
 
82
{
 
83
    ASSERT(!isHTML());
 
84
    return m_private->iconURL();
 
85
}
 
86
 
 
87
WebString WebNotification::title() const
 
88
{
 
89
    ASSERT(!isHTML());
 
90
    return m_private->title();
 
91
}
 
92
 
 
93
WebString WebNotification::body() const
 
94
{
 
95
    ASSERT(!isHTML());
 
96
    return m_private->body();
 
97
}
 
98
 
 
99
WebTextDirection WebNotification::direction() const
 
100
{
 
101
    return (m_private->direction() == RTL) ?
 
102
        WebTextDirectionRightToLeft :
 
103
        WebTextDirectionLeftToRight;
 
104
}
 
105
 
 
106
WebString WebNotification::replaceId() const
 
107
{
 
108
    return m_private->tag();
 
109
}
 
110
 
 
111
void WebNotification::detachPresenter()
 
112
{
 
113
    m_private->detachPresenter();
 
114
}
 
115
 
 
116
void WebNotification::dispatchDisplayEvent()
 
117
{
 
118
#if ENABLE(LEGACY_NOTIFICATIONS)
 
119
    dispatchEvent("display");
 
120
#endif
 
121
    dispatchEvent("show");
 
122
}
 
123
 
 
124
void WebNotification::dispatchErrorEvent(const WebKit::WebString& /* errorMessage */)
 
125
{
 
126
    // FIXME: errorMessage not supported by WebCore yet
 
127
    dispatchEvent(eventNames().errorEvent);
 
128
}
 
129
 
 
130
void WebNotification::dispatchCloseEvent(bool /* byUser */)
 
131
{
 
132
    // FIXME: byUser flag not supported by WebCore yet
 
133
    dispatchEvent(eventNames().closeEvent);
 
134
}
 
135
 
 
136
void WebNotification::dispatchClickEvent()
 
137
{
 
138
    UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
 
139
    WindowFocusAllowedIndicator windowFocusAllowed;
 
140
    dispatchEvent(eventNames().clickEvent);
 
141
}
 
142
 
 
143
void WebNotification::dispatchEvent(const WTF::AtomicString& type)
 
144
{
 
145
    // Do not dispatch if the context is gone.
 
146
    if (!m_private->scriptExecutionContext())
 
147
        return;
 
148
 
 
149
    RefPtr<Event> event = Event::create(type, false, true);
 
150
    m_private->dispatchEvent(event.release());
 
151
}
 
152
 
 
153
WebNotification::WebNotification(const WTF::PassRefPtr<Notification>& notification)
 
154
    : m_private(static_cast<WebNotificationPrivate*>(notification.leakRef()))
 
155
{
 
156
}
 
157
 
 
158
WebNotification& WebNotification::operator=(const WTF::PassRefPtr<Notification>& notification)
 
159
{
 
160
    assign(static_cast<WebNotificationPrivate*>(notification.leakRef()));
 
161
    return *this;
 
162
}
 
163
 
 
164
WebNotification::operator WTF::PassRefPtr<Notification>() const
 
165
{
 
166
    return WTF::PassRefPtr<Notification>(const_cast<WebNotificationPrivate*>(m_private));
 
167
}
 
168
 
 
169
void WebNotification::assign(WebNotificationPrivate* p)
 
170
{
 
171
    // p is already ref'd for us by the caller
 
172
    if (m_private)
 
173
        m_private->deref();
 
174
    m_private = p;
 
175
}
 
176
 
 
177
} // namespace WebKit
 
178
 
 
179
#endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)