2011-07-17 23:09:13 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-03-31 08:42:20 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
#include "EventTarget.h"
|
|
|
|
|
|
|
|
USING_WORKERS_NAMESPACE
|
2012-05-06 05:15:11 +04:00
|
|
|
using mozilla::ErrorResult;
|
2012-11-10 19:45:52 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2012-04-27 00:57:33 +04:00
|
|
|
EventTarget::_trace(JSTracer* aTrc)
|
2012-01-18 22:05:38 +04:00
|
|
|
{
|
2012-04-27 00:57:33 +04:00
|
|
|
mListenerManager._trace(aTrc);
|
|
|
|
DOMBindingBase::_trace(aTrc);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2012-04-27 00:57:33 +04:00
|
|
|
EventTarget::_finalize(JSFreeOp* aFop)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2012-04-27 00:57:33 +04:00
|
|
|
mListenerManager._finalize(aFop);
|
|
|
|
DOMBindingBase::_finalize(aFop);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
JSObject*
|
2012-05-06 05:15:11 +04:00
|
|
|
EventTarget::GetEventListener(const nsAString& aType, ErrorResult& aRv) const
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2012-03-31 08:42:20 +04:00
|
|
|
JSContext* cx = GetJSContext();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
JSString* type =
|
|
|
|
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
|
|
|
if (!type || !(type = JS_InternJSString(cx, type))) {
|
2012-05-06 05:15:11 +04:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2012-03-31 08:42:20 +04:00
|
|
|
return NULL;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
return mListenerManager.GetEventListener(INTERNED_STRING_TO_JSID(cx, type));
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2013-05-18 05:48:25 +04:00
|
|
|
EventTarget::SetEventListener(const nsAString& aType,
|
|
|
|
JS::Handle<JSObject*> aListener,
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult& aRv)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2012-03-31 08:42:20 +04:00
|
|
|
JSContext* cx = GetJSContext();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
JSString* type =
|
|
|
|
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
|
|
|
if (!type || !(type = JS_InternJSString(cx, type))) {
|
2012-05-06 05:15:11 +04:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2012-03-31 08:42:20 +04:00
|
|
|
return;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
mListenerManager.SetEventListener(cx, INTERNED_STRING_TO_JSID(cx, type),
|
|
|
|
aListener, aRv);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2013-05-18 05:48:25 +04:00
|
|
|
EventTarget::AddEventListener(const nsAString& aType,
|
|
|
|
JS::Handle<JSObject*> aListener,
|
2012-03-31 08:42:20 +04:00
|
|
|
bool aCapturing, Nullable<bool> aWantsUntrusted,
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult& aRv)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-05-18 05:48:25 +04:00
|
|
|
if (!aListener) {
|
2012-03-31 08:42:20 +04:00
|
|
|
return;
|
2012-01-18 22:05:38 +04:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
JSContext* cx = GetJSContext();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
JSString* type =
|
|
|
|
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
|
|
|
if (!type || !(type = JS_InternJSString(cx, type))) {
|
2012-05-06 05:15:11 +04:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2012-03-31 08:42:20 +04:00
|
|
|
return;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
bool wantsUntrusted = !aWantsUntrusted.IsNull() && aWantsUntrusted.Value();
|
|
|
|
mListenerManager.AddEventListener(cx, INTERNED_STRING_TO_JSID(cx, type),
|
|
|
|
aListener, aCapturing, wantsUntrusted,
|
|
|
|
aRv);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2013-05-18 05:48:25 +04:00
|
|
|
EventTarget::RemoveEventListener(const nsAString& aType,
|
|
|
|
JS::Handle<JSObject*> aListener,
|
2012-05-06 05:15:11 +04:00
|
|
|
bool aCapturing, ErrorResult& aRv)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-05-18 05:48:25 +04:00
|
|
|
if (!aListener) {
|
2012-03-31 08:42:20 +04:00
|
|
|
return;
|
2011-12-02 01:30:28 +04:00
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
JSContext* cx = GetJSContext();
|
2012-01-18 22:05:38 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
JSString* type =
|
|
|
|
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
|
|
|
if (!type || !(type = JS_InternJSString(cx, type))) {
|
2012-05-06 05:15:11 +04:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2012-03-31 08:42:20 +04:00
|
|
|
return;
|
2011-10-07 03:09:43 +04:00
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
mListenerManager.RemoveEventListener(cx, INTERNED_STRING_TO_JSID(cx, type),
|
|
|
|
aListener, aCapturing);
|
2012-03-19 18:34:55 +04:00
|
|
|
}
|