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