|
Line 0
WebCore/bindings/v8/custom/V8NotificationsCustom.cpp_sec1
|
|
|
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 |
|
| 33 |
#if ENABLE(NOTIFICATIONS) |
| 34 |
|
| 35 |
#include "v8_binding.h" |
| 36 |
#include "v8_custom.h" |
| 37 |
#include "V8Proxy.h" |
| 38 |
|
| 39 |
#include "NotImplemented.h" |
| 40 |
#include "Notification.h" |
| 41 |
#include "Notifications.h" |
| 42 |
#include "WorkerContext.h" |
| 43 |
#include "WorkerContextExecutionProxy.h" |
| 44 |
#include "V8Binding.h" |
| 45 |
#include "V8CustomEventListener.h" |
| 46 |
#include "V8Utilities.h" |
| 47 |
|
| 48 |
namespace WebCore { |
| 49 |
|
| 50 |
ACCESSOR_GETTER(NotificationOndisplay) |
| 51 |
{ |
| 52 |
INC_STATS(L"DOM.Notification.ondisplay._get"); |
| 53 |
Notification* notif = V8Proxy::ToNativeObject<Notification>(V8ClassIndex::NOTIFICATION, info.Holder()); |
| 54 |
if (notif->ondisplay()) { |
| 55 |
V8EventListener* listener = static_cast<V8EventListener*>(notif->ondisplay()); |
| 56 |
v8::Local<v8::Object> v8Listener = listener->getListenerObject(); |
| 57 |
return v8Listener; |
| 58 |
} |
| 59 |
return v8::Undefined(); |
| 60 |
} |
| 61 |
|
| 62 |
ACCESSOR_SETTER(NotificationOndisplay) |
| 63 |
{ |
| 64 |
INC_STATS(L"DOM.Notification.ondisplay._set"); |
| 65 |
Notification* notif = V8Proxy::ToNativeObject<Notification>(V8ClassIndex::NOTIFICATION, info.Holder()); |
| 66 |
V8EventListener* oldListener = static_cast<V8EventListener*>(notif->ondisplay()); |
| 67 |
if (value->IsNull()) { |
| 68 |
if (oldListener) { |
| 69 |
v8::Local<v8::Object> oldV8Listener = oldListener->getListenerObject(); |
| 70 |
removeHiddenDependency(info.Holder(), oldV8Listener, V8Custom::kNotificationRequestCacheIndex); |
| 71 |
} |
| 72 |
|
| 73 |
// Clear the listener |
| 74 |
notif->setOndisplay(0); |
| 75 |
} else { |
| 76 |
RefPtr<EventListener> listener; |
| 77 |
ScriptExecutionContext* context = notif->scriptExecutionContext(); |
| 78 |
if (context->isWorkerContext()) |
| 79 |
listener = static_cast<WorkerContext*>(context)->script()->proxy()->findOrCreateEventListener(v8::Local<v8::Object>::Cast(value), false, false); |
| 80 |
else |
| 81 |
listener = V8Proxy::retrieve(context)->FindOrCreateV8EventListener(v8::Local<v8::Object>::Cast(value), false); |
| 82 |
|
| 83 |
if (listener) { |
| 84 |
if (oldListener) { |
| 85 |
v8::Local<v8::Object> oldV8Listener = oldListener->getListenerObject(); |
| 86 |
removeHiddenDependency(info.Holder(), oldV8Listener, V8Custom::kNotificationRequestCacheIndex); |
| 87 |
} |
| 88 |
|
| 89 |
notif->setOndisplay(listener); |
| 90 |
createHiddenDependency(info.Holder(), value, V8Custom::kNotificationRequestCacheIndex); |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
ACCESSOR_GETTER(NotificationOnerror) |
| 96 |
{ |
| 97 |
INC_STATS(L"DOM.Notification.onerror._get"); |
| 98 |
Notification* notif = V8Proxy::ToNativeObject<Notification>(V8ClassIndex::NOTIFICATION, info.Holder()); |
| 99 |
if (notif->onerror()) { |
| 100 |
V8EventListener* listener = static_cast<V8EventListener*>(notif->onerror()); |
| 101 |
v8::Local<v8::Object> v8Listener = listener->getListenerObject(); |
| 102 |
return v8Listener; |
| 103 |
} |
| 104 |
return v8::Undefined(); |
| 105 |
} |
| 106 |
|
| 107 |
ACCESSOR_SETTER(NotificationOnerror) |
| 108 |
{ |
| 109 |
INC_STATS(L"DOM.Notification.onerror._set"); |
| 110 |
Notification* notif = V8Proxy::ToNativeObject<Notification>(V8ClassIndex::NOTIFICATION, info.Holder()); |
| 111 |
V8EventListener* oldListener = static_cast<V8EventListener*>(notif->onerror()); |
| 112 |
if (value->IsNull()) { |
| 113 |
if (oldListener) { |
| 114 |
v8::Local<v8::Object> oldV8Listener = oldListener->getListenerObject(); |
| 115 |
removeHiddenDependency(info.Holder(), oldV8Listener, V8Custom::kNotificationRequestCacheIndex); |
| 116 |
} |
| 117 |
|
| 118 |
// Clear the listener |
| 119 |
notif->setOnerror(0); |
| 120 |
} else { |
| 121 |
RefPtr<EventListener> listener; |
| 122 |
ScriptExecutionContext* context = notif->scriptExecutionContext(); |
| 123 |
if (context->isWorkerContext()) |
| 124 |
listener = static_cast<WorkerContext*>(context)->script()->proxy()->findOrCreateEventListener(v8::Local<v8::Object>::Cast(value), false, false); |
| 125 |
else |
| 126 |
listener = V8Proxy::retrieve(context)->FindOrCreateV8EventListener(v8::Local<v8::Object>::Cast(value), false); |
| 127 |
if (listener) { |
| 128 |
if (oldListener) { |
| 129 |
v8::Local<v8::Object> oldV8Listener = |
| 130 |
oldListener->getListenerObject(); |
| 131 |
removeHiddenDependency(info.Holder(), oldV8Listener, V8Custom::kNotificationRequestCacheIndex); |
| 132 |
} |
| 133 |
|
| 134 |
notif->setOnerror(listener); |
| 135 |
createHiddenDependency(info.Holder(), value, V8Custom::kNotificationRequestCacheIndex); |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
ACCESSOR_GETTER(NotificationOnclose) |
| 141 |
{ |
| 142 |
INC_STATS(L"DOM.Notification.onclose._get"); |
| 143 |
Notification* notif = V8Proxy::ToNativeObject<Notification>(V8ClassIndex::NOTIFICATION, info.Holder()); |
| 144 |
if (notif->onclose()) { |
| 145 |
V8EventListener* listener = static_cast<V8EventListener*>(notif->onclose()); |
| 146 |
v8::Local<v8::Object> v8Listener = listener->getListenerObject(); |
| 147 |
return v8Listener; |
| 148 |
} |
| 149 |
return v8::Undefined(); |
| 150 |
} |
| 151 |
|
| 152 |
ACCESSOR_SETTER(NotificationOnclose) |
| 153 |
{ |
| 154 |
INC_STATS(L"DOM.Notification.onerror._set"); |
| 155 |
Notification* notif = V8Proxy::ToNativeObject<Notification>(V8ClassIndex::NOTIFICATION, info.Holder()); |
| 156 |
V8EventListener* oldListener = static_cast<V8EventListener*>(notif->onclose()); |
| 157 |
if (value->IsNull()) { |
| 158 |
if (oldListener) { |
| 159 |
v8::Local<v8::Object> oldV8Listener = oldListener->getListenerObject(); |
| 160 |
removeHiddenDependency(info.Holder(), oldV8Listener, V8Custom::kNotificationRequestCacheIndex); |
| 161 |
} |
| 162 |
|
| 163 |
// Clear the listener |
| 164 |
notif->setOnclose(0); |
| 165 |
} else { |
| 166 |
RefPtr<EventListener> listener; |
| 167 |
ScriptExecutionContext* context = notif->scriptExecutionContext(); |
| 168 |
if (context->isWorkerContext()) |
| 169 |
listener = static_cast<WorkerContext*>(context)->script()->proxy()->findOrCreateEventListener(v8::Local<v8::Object>::Cast(value), false, false); |
| 170 |
else |
| 171 |
listener = V8Proxy::retrieve(context)->FindOrCreateV8EventListener(v8::Local<v8::Object>::Cast(value), false); |
| 172 |
if (listener) { |
| 173 |
if (oldListener) { |
| 174 |
v8::Local<v8::Object> oldV8Listener = |
| 175 |
oldListener->getListenerObject(); |
| 176 |
removeHiddenDependency(info.Holder(), oldV8Listener, V8Custom::kNotificationRequestCacheIndex); |
| 177 |
} |
| 178 |
|
| 179 |
notif->setOnclose(listener); |
| 180 |
createHiddenDependency(info.Holder(), value, V8Custom::kNotificationRequestCacheIndex); |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
CALLBACK_FUNC_DECL(NotificationsCreateHTMLNotification) |
| 186 |
{ |
| 187 |
INC_STATS(L"DOM.Notifications.CreateHTMLNotification()"); |
| 188 |
Notifications* notifInterface = V8Proxy::ToNativeObject<Notifications>(V8ClassIndex::NOTIFICATIONS, args.Holder()); |
| 189 |
|
| 190 |
ExceptionCode ec = 0; |
| 191 |
String url = toWebCoreString(args[0]); |
| 192 |
RefPtr<Notification> notif = Notification::create(url, notifInterface->context(), ec, notifInterface->provider()); |
| 193 |
|
| 194 |
if (ec) { |
| 195 |
return throwError(ec); |
| 196 |
} |
| 197 |
|
| 198 |
return WorkerContextExecutionProxy::ToV8Object(V8ClassIndex::NOTIFICATION, notif.get()); |
| 199 |
} |
| 200 |
|
| 201 |
CALLBACK_FUNC_DECL(NotificationsCreateNotification) |
| 202 |
{ |
| 203 |
INC_STATS(L"DOM.Notifications.CreateNotification()"); |
| 204 |
Notifications* notifInterface = V8Proxy::ToNativeObject<Notifications>(V8ClassIndex::NOTIFICATIONS, args.Holder()); |
| 205 |
|
| 206 |
NotificationParameters parameters(toWebCoreString(args[0]), toWebCoreString(args[1]), toWebCoreString(args[2])); |
| 207 |
|
| 208 |
ExceptionCode ec = 0; |
| 209 |
RefPtr<Notification> notif = Notification::create(parameters, notifInterface->context(), ec, notifInterface->provider()); |
| 210 |
|
| 211 |
if (ec) { |
| 212 |
return throwError(ec); |
| 213 |
} |
| 214 |
|
| 215 |
return WorkerContextExecutionProxy::ToV8Object(V8ClassIndex::NOTIFICATION, notif.get()); |
| 216 |
} |
| 217 |
|
| 218 |
CALLBACK_FUNC_DECL(NotificationShow) |
| 219 |
{ |
| 220 |
INC_STATS(L"DOM.Notification.Show()"); |
| 221 |
Notification* notif = V8Proxy::ToNativeObject<Notification>(V8ClassIndex::NOTIFICATION, args.Holder()); |
| 222 |
notif->show(); |
| 223 |
|
| 224 |
return v8::Undefined(); |
| 225 |
} |
| 226 |
|
| 227 |
CALLBACK_FUNC_DECL(NotificationCancel) |
| 228 |
{ |
| 229 |
INC_STATS(L"DOM.Notification.Cancel()"); |
| 230 |
Notification* notif = V8Proxy::ToNativeObject<Notification>(V8ClassIndex::NOTIFICATION, args.Holder()); |
| 231 |
notif->cancel(); |
| 232 |
|
| 233 |
return v8::Undefined(); |
| 234 |
} |
| 235 |
|
| 236 |
} // namespace WebCore |
| 237 |
|
| 238 |
#endif // ENABLE(NOTIFICATIONS) |