2011-07-17 12:09:13 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-03-30 21:42:20 -07: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 12:09:13 -07:00
|
|
|
|
|
|
|
#include "EventTarget.h"
|
|
|
|
|
|
|
|
USING_WORKERS_NAMESPACE
|
2012-05-05 18:15:11 -07:00
|
|
|
using mozilla::ErrorResult;
|
2012-11-10 07:45:52 -08:00
|
|
|
using namespace mozilla::dom;
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
2012-04-26 13:57:33 -07:00
|
|
|
EventTarget::_trace(JSTracer* aTrc)
|
2012-01-18 10:05:38 -08:00
|
|
|
{
|
2012-04-26 13:57:33 -07:00
|
|
|
mListenerManager._trace(aTrc);
|
|
|
|
DOMBindingBase::_trace(aTrc);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
2012-04-26 13:57:33 -07:00
|
|
|
EventTarget::_finalize(JSFreeOp* aFop)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
2012-04-26 13:57:33 -07:00
|
|
|
mListenerManager._finalize(aFop);
|
|
|
|
DOMBindingBase::_finalize(aFop);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
JSObject*
|
2012-05-05 18:15:11 -07:00
|
|
|
EventTarget::GetEventListener(const nsAString& aType, ErrorResult& aRv) const
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
JSContext* cx = GetJSContext();
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
JSString* type =
|
|
|
|
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
|
|
|
if (!type || !(type = JS_InternJSString(cx, type))) {
|
2012-05-05 18:15:11 -07:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2012-03-30 21:42:20 -07:00
|
|
|
return NULL;
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
return mListenerManager.GetEventListener(INTERNED_STRING_TO_JSID(cx, type));
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
2013-05-17 18:48:25 -07:00
|
|
|
EventTarget::SetEventListener(const nsAString& aType,
|
|
|
|
JS::Handle<JSObject*> aListener,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& aRv)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
JSContext* cx = GetJSContext();
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
JSString* type =
|
|
|
|
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
|
|
|
if (!type || !(type = JS_InternJSString(cx, type))) {
|
2012-05-05 18:15:11 -07:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2012-03-30 21:42:20 -07:00
|
|
|
return;
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
mListenerManager.SetEventListener(cx, INTERNED_STRING_TO_JSID(cx, type),
|
|
|
|
aListener, aRv);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
2013-05-17 18:48:25 -07:00
|
|
|
EventTarget::AddEventListener(const nsAString& aType,
|
|
|
|
JS::Handle<JSObject*> aListener,
|
2012-03-30 21:42:20 -07:00
|
|
|
bool aCapturing, Nullable<bool> aWantsUntrusted,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& aRv)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
2013-05-17 18:48:25 -07:00
|
|
|
if (!aListener) {
|
2012-03-30 21:42:20 -07:00
|
|
|
return;
|
2012-01-18 10:05:38 -08:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
JSContext* cx = GetJSContext();
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
JSString* type =
|
|
|
|
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
|
|
|
if (!type || !(type = JS_InternJSString(cx, type))) {
|
2012-05-05 18:15:11 -07:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2012-03-30 21:42:20 -07:00
|
|
|
return;
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
bool wantsUntrusted = !aWantsUntrusted.IsNull() && aWantsUntrusted.Value();
|
|
|
|
mListenerManager.AddEventListener(cx, INTERNED_STRING_TO_JSID(cx, type),
|
|
|
|
aListener, aCapturing, wantsUntrusted,
|
|
|
|
aRv);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
2013-05-17 18:48:25 -07:00
|
|
|
EventTarget::RemoveEventListener(const nsAString& aType,
|
|
|
|
JS::Handle<JSObject*> aListener,
|
2012-05-05 18:15:11 -07:00
|
|
|
bool aCapturing, ErrorResult& aRv)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
2013-05-17 18:48:25 -07:00
|
|
|
if (!aListener) {
|
2012-03-30 21:42:20 -07:00
|
|
|
return;
|
2011-12-01 13:30:28 -08:00
|
|
|
}
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
JSContext* cx = GetJSContext();
|
2012-01-18 10:05:38 -08:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
JSString* type =
|
|
|
|
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
|
|
|
if (!type || !(type = JS_InternJSString(cx, type))) {
|
2012-05-05 18:15:11 -07:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2012-03-30 21:42:20 -07:00
|
|
|
return;
|
2011-10-06 16:09:43 -07:00
|
|
|
}
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
mListenerManager.RemoveEventListener(cx, INTERNED_STRING_TO_JSID(cx, type),
|
|
|
|
aListener, aCapturing);
|
2012-03-19 07:34:55 -07:00
|
|
|
}
|