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;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
|
|
|
EventTarget::_Trace(JSTracer* aTrc)
|
2012-01-18 22:05:38 +04:00
|
|
|
{
|
2012-03-31 08:42:20 +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-03-19 18:34:55 +04:00
|
|
|
EventTarget::_Finalize(JSFreeOp* aFop)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2012-03-19 18:34:55 +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
|
|
|
|
EventTarget::SetEventListener(const nsAString& aType, 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
|
|
|
|
EventTarget::AddEventListener(const nsAString& aType, JSObject* aListener,
|
|
|
|
bool aCapturing, Nullable<bool> aWantsUntrusted,
|
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
|
|
|
if (!aListener) {
|
|
|
|
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
|
|
|
|
EventTarget::RemoveEventListener(const nsAString& aType, JSObject* aListener,
|
2012-05-06 05:15:11 +04:00
|
|
|
bool aCapturing, ErrorResult& aRv)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2012-03-31 08:42:20 +04:00
|
|
|
if (!aListener) {
|
|
|
|
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
|
|
|
}
|