Fix for bug 428229 (Unable to override addEventListener), remove custom addEventListener code. r=bz.

--HG--
extra : rebase_source : 4e679da2100075a1e3c4ad557b92a3c86a5cf7be
This commit is contained in:
Peter Van der Beken 2010-01-13 14:50:01 +01:00
Родитель 3d4cb5a32c
Коммит a5b6707a12
11 изменённых файлов: 95 добавлений и 183 удалений

Просмотреть файл

@ -291,7 +291,7 @@ nsresult nsRootAccessible::AddEventListeners()
* const* e_end = docEvents + NS_ARRAY_LENGTH(docEvents);
e < e_end; ++e) {
nsresult rv = nstarget->AddEventListener(NS_ConvertASCIItoUTF16(*e),
this, PR_TRUE, PR_TRUE);
this, PR_TRUE, PR_TRUE, 1);
NS_ENSURE_SUCCESS(rv, rv);
}
}

Просмотреть файл

@ -6294,8 +6294,7 @@ nsDocument::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
return AddEventListener(aType, aListener, aUseCapture,
!nsContentUtils::IsChromeDoc(this));
return AddEventListener(aType, aListener, aUseCapture, PR_FALSE, 0);
}
nsresult
@ -6366,14 +6365,21 @@ nsDocument::IsRegisteredHere(const nsAString & type, PRBool *_retval)
NS_IMETHODIMP
nsDocument::AddEventListener(const nsAString& aType,
nsIDOMEventListener *aListener,
PRBool aUseCapture, PRBool aWantsUntrusted)
PRBool aUseCapture, PRBool aWantsUntrusted,
PRUint8 optional_argc)
{
NS_ASSERTION(!aWantsUntrusted || optional_argc > 0,
"Won't check if this is chrome, you want to set "
"aWantsUntrusted to PR_FALSE or make the aWantsUntrusted "
"explicit by making optional_argc non-zero.");
nsIEventListenerManager* manager = GetListenerManager(PR_TRUE);
NS_ENSURE_STATE(manager);
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
if (aWantsUntrusted) {
if (aWantsUntrusted ||
(optional_argc == 0 && !nsContentUtils::IsChromeDoc(this))) {
flags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED;
}

Просмотреть файл

@ -1598,9 +1598,7 @@ nsDOMEventRTTearoff::AddEventListener(const nsAString& aType,
nsIDOMEventListener *aListener,
PRBool useCapture)
{
return
AddEventListener(aType, aListener, useCapture,
!nsContentUtils::IsChromeDoc(mNode->GetOwnerDoc()));
return AddEventListener(aType, aListener, useCapture, PR_FALSE, 0);
}
NS_IMETHODIMP
@ -1666,15 +1664,23 @@ NS_IMETHODIMP
nsDOMEventRTTearoff::AddEventListener(const nsAString& aType,
nsIDOMEventListener *aListener,
PRBool aUseCapture,
PRBool aWantsUntrusted)
PRBool aWantsUntrusted,
PRUint8 optional_argc)
{
NS_ASSERTION(!aWantsUntrusted || optional_argc > 0,
"Won't check if this is chrome, you want to set "
"aWantsUntrusted to PR_FALSE or make the aWantsUntrusted "
"explicit by making optional_argc non-zero.");
nsIEventListenerManager* listener_manager =
mNode->GetListenerManager(PR_TRUE);
NS_ENSURE_STATE(listener_manager);
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
if (aWantsUntrusted) {
if (aWantsUntrusted ||
(optional_argc == 0 &&
!nsContentUtils::IsChromeDoc(mNode->GetOwnerDoc()))) {
flags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED;
}

Просмотреть файл

@ -97,13 +97,7 @@ nsDOMEventTargetHelper::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
nsresult rv;
nsIScriptContext* context =
GetContextForEventHandlers(&rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocument> doc = nsContentUtils::GetDocumentFromScriptContext(context);
PRBool wantsUntrusted = doc && !nsContentUtils::IsChromeDoc(doc);
return AddEventListener(aType, aListener, aUseCapture, wantsUntrusted);
return AddEventListener(aType, aListener, aUseCapture, PR_FALSE, 0);
}
NS_IMETHODIMP
@ -124,14 +118,31 @@ NS_IMETHODIMP
nsDOMEventTargetHelper::AddEventListener(const nsAString& aType,
nsIDOMEventListener *aListener,
PRBool aUseCapture,
PRBool aWantsUntrusted)
PRBool aWantsUntrusted,
PRUint8 optional_argc)
{
NS_ASSERTION(!aWantsUntrusted || optional_argc > 0,
"Won't check if this is chrome, you want to set "
"aWantsUntrusted to PR_FALSE or make the aWantsUntrusted "
"explicit by making optional_argc non-zero.");
nsIEventListenerManager* elm = GetListenerManager(PR_TRUE);
NS_ENSURE_STATE(elm);
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
if (optional_argc == 0) {
nsresult rv;
nsIScriptContext* context = GetContextForEventHandlers(&rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocument> doc =
nsContentUtils::GetDocumentFromScriptContext(context);
aWantsUntrusted = doc && !nsContentUtils::IsChromeDoc(doc);
}
if (aWantsUntrusted) {
flags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED;
}
return elm->AddEventListenerByType(aListener, aType, flags, nsnull);
}

Просмотреть файл

@ -35,6 +35,7 @@ function HTML_TAG(aTagName, aImplClass) {
[ "nsIDOM3Node",
"nsIDOMNSElement",
"nsIDOMEventTarget",
"nsIDOMNSEventTarget",
"nsIDOMNSHTMLElement",
"nsIDOMElementCSSInlineStyle",
"nsIDOMNodeSelector" ];
@ -44,7 +45,7 @@ function HTML_TAG(aTagName, aImplClass) {
interfacesNonClassinfo[aTagName] =
[ "nsIDOMNode",
"nsIDOMElement",
"nsIDOM3EventTarget", "nsIDOMNSEventTarget",
"nsIDOM3EventTarget",
"nsISupportsWeakReference" ];
var interfaceName = "nsIDOM" + getClassName(aTagName);

Просмотреть файл

@ -1998,6 +1998,7 @@ nsDOMClassInfo::WrapNativeParent(JSContext *cx, JSObject *scope,
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentRange) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentTraversal) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentXBL) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Document) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node) \
@ -2008,6 +2009,7 @@ nsDOMClassInfo::WrapNativeParent(JSContext *cx, JSObject *scope,
#define DOM_CLASSINFO_GENERIC_HTML_MAP_ENTRIES \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLElement) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMElementCSSInlineStyle) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSElement) \
@ -2067,6 +2069,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMJSWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindowInternal)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMViewCSS)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMAbstractView)
@ -2132,6 +2135,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(DocumentType, nsIDOMDocumentType)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentType)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
DOM_CLASSINFO_MAP_END
@ -2153,12 +2157,14 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentFragment)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNodeSelector)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(Element, nsIDOMElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNodeSelector)
@ -2168,11 +2174,13 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMAttr)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Attr)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(Text, nsIDOMText)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMText)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Text)
@ -2180,12 +2188,14 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(Comment, nsIDOMComment)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMComment)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(CDATASection, nsIDOMCDATASection)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCDATASection)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Text)
@ -2193,6 +2203,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(ProcessingInstruction, nsIDOMProcessingInstruction)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMProcessingInstruction)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
DOM_CLASSINFO_MAP_END
@ -2708,6 +2719,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(XULElement, nsIDOMXULElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSElement)
@ -2750,6 +2762,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XMLStylesheetProcessingInstruction, nsIDOMProcessingInstruction)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMProcessingInstruction)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMLinkStyle)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
DOM_CLASSINFO_MAP_END
@ -2759,6 +2772,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMJSWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindowInternal)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMChromeWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorageWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMViewCSS)
@ -2828,6 +2842,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNodeSelector)
#define DOM_CLASSINFO_SVG_GRAPHIC_ELEMENT_MAP_ENTRIES \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGLocatable) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGTransformable) \
@ -3176,6 +3191,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(SVGSVGElement, nsIDOMSVGSVGElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGSVGElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFitToViewBox)
@ -3191,6 +3207,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(SVGSymbolElement, nsIDOMSVGSymbolElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGSymbolElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFitToViewBox)
@ -3207,6 +3224,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(SVGTextPathElement, nsIDOMSVGTextPathElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGTextContentElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGURIReference)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGStylable)
DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES
@ -3221,6 +3239,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(SVGTSpanElement, nsIDOMSVGTSpanElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGTextPositioningElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGTextContentElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGStylable)
DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES
@ -3537,6 +3556,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIXMLHttpRequest)
DOM_CLASSINFO_MAP_ENTRY(nsIJSXMLHttpRequest)
DOM_CLASSINFO_MAP_ENTRY(nsIXMLHttpRequestEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIInterfaceRequestor)
DOM_CLASSINFO_MAP_END
@ -3566,6 +3586,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(OfflineResourceList, nsIDOMOfflineResourceList)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMOfflineResourceList)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
@ -3601,6 +3622,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(FileReader, nsIDOMFileReader)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMFileReader)
DOM_CLASSINFO_MAP_ENTRY(nsIXMLHttpRequestEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIInterfaceRequestor)
DOM_CLASSINFO_MAP_END
@ -3609,6 +3631,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMJSWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindowInternal)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMViewCSS)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMAbstractView)
@ -3677,6 +3700,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(XMLHttpRequestUpload, nsIXMLHttpRequestUpload)
DOM_CLASSINFO_MAP_ENTRY(nsIXMLHttpRequestEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIXMLHttpRequestUpload)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
@ -3701,6 +3725,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(MathMLElement, nsIDOMElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNodeSelector)
@ -7412,117 +7437,6 @@ nsEventReceiverSH::ReallyIsEventName(jsval id, jschar aFirstChar)
return PR_FALSE;
}
// static
JSBool
nsEventReceiverSH::AddEventListenerHelper(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *rval)
{
if (argc < 3 || argc > 4) {
ThrowJSException(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS);
return JS_FALSE;
}
nsresult rv = sXPConnect->GetJSObjectOfWrapper(cx, obj, &obj);
if (NS_FAILED(rv)) {
nsDOMClassInfo::ThrowJSException(cx, rv);
return JS_FALSE;
}
OBJ_TO_INNER_OBJECT(cx, obj);
if (!obj) {
return JS_FALSE;
}
// Check that the caller has permission to call obj's addEventListener.
if (NS_FAILED(sSecMan->CheckPropertyAccess(cx, obj,
JS_GET_CLASS(cx, obj)->name,
sAddEventListener_id,
nsIXPCSecurityManager::ACCESS_GET_PROPERTY)) ||
NS_FAILED(sSecMan->CheckPropertyAccess(cx, obj,
JS_GET_CLASS(cx, obj)->name,
sAddEventListener_id,
nsIXPCSecurityManager::ACCESS_CALL_METHOD))) {
// The caller doesn't have access to get or call the callee
// object's addEventListener method. The security manager already
// threw an exception for us, so simply return false.
return JS_FALSE;
}
if (JSVAL_IS_PRIMITIVE(argv[1])) {
// The second argument must be a function, or a
// nsIDOMEventListener. Throw an error.
ThrowJSException(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
return JS_FALSE;
}
JSString* jsstr = JS_ValueToString(cx, argv[0]);
if (!jsstr) {
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_OUT_OF_MEMORY);
return JS_FALSE;
}
nsDependentJSString type(jsstr);
nsCOMPtr<nsIDOMEventListener> listener;
{
nsCOMPtr<nsISupports> tmp;
sXPConnect->WrapJS(cx, JSVAL_TO_OBJECT(argv[1]),
NS_GET_IID(nsIDOMEventListener), getter_AddRefs(tmp));
listener = do_QueryInterface(tmp, &rv);
if (NS_FAILED(rv)) {
ThrowJSException(cx, rv);
return JS_FALSE;
}
}
JSBool useCapture;
JS_ValueToBoolean(cx, argv[2], &useCapture);
if (argc == 4) {
JSBool wantsUntrusted;
JS_ValueToBoolean(cx, argv[3], &wantsUntrusted);
nsCOMPtr<nsIDOMNSEventTarget> eventTarget = do_QueryWrapper(cx, obj, &rv);
if (NS_FAILED(rv)) {
ThrowJSException(cx, rv);
return JS_FALSE;
}
rv = eventTarget->AddEventListener(type, listener, useCapture,
wantsUntrusted);
if (NS_FAILED(rv)) {
ThrowJSException(cx, rv);
return JS_FALSE;
}
} else {
nsCOMPtr<nsIDOMEventTarget> eventTarget = do_QueryWrapper(cx, obj, &rv);
if (NS_FAILED(rv)) {
ThrowJSException(cx, rv);
return JS_FALSE;
}
rv = eventTarget->AddEventListener(type, listener, useCapture);
if (NS_FAILED(rv)) {
ThrowJSException(cx, rv);
return JS_FALSE;
}
}
return JS_TRUE;
}
nsresult
nsEventReceiverSH::RegisterCompileHandler(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj,
@ -7576,21 +7490,6 @@ nsEventReceiverSH::RegisterCompileHandler(nsIXPConnectWrappedNative *wrapper,
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
}
nsresult
nsEventReceiverSH::DefineAddEventListener(JSContext *cx, JSObject *obj,
jsval id, JSObject **objp)
{
NS_ASSERTION(id == sAddEventListener_id, "Wrong call?!?");
JSString *str = JSVAL_TO_STRING(id);
// addEventListener always takes at least 3 arguments.
JSFunction *fnc =
::JS_DefineFunction(cx, obj, ::JS_GetStringBytes(str),
nsEventReceiverSH::AddEventListenerHelper, 3,
JSPROP_ENUMERATE);
*objp = obj;
return fnc ? NS_OK : NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
nsEventReceiverSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj, jsval id,
@ -7636,7 +7535,7 @@ nsEventReceiverSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
}
if (id == sAddEventListener_id) {
return nsEventReceiverSH::DefineAddEventListener(cx, obj, id, objp);
return NS_OK;
}
PRBool did_define = PR_FALSE;
@ -7694,21 +7593,6 @@ nsEventTargetSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
return NS_OK;
}
NS_IMETHODIMP
nsEventTargetSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj, jsval id,
PRUint32 flags, JSObject **objp, PRBool *_retval)
{
if ((flags & JSRESOLVE_ASSIGNING) || !JSVAL_IS_STRING(id)) {
return NS_OK;
}
if (id == sAddEventListener_id) {
return nsEventReceiverSH::DefineAddEventListener(cx, obj, id, objp);
}
return nsDOMGenericSH::NewResolve(wrapper, cx, obj, id, flags, objp,
_retval);
}
NS_IMETHODIMP
nsEventTargetSH::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsval id, jsval *vp, PRBool *_retval)

Просмотреть файл

@ -442,9 +442,6 @@ protected:
return PR_FALSE;
}
static JSBool AddEventListenerHelper(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *rval);
nsresult RegisterCompileHandler(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj, jsval id,
PRBool compile, PRBool remove,
@ -459,13 +456,10 @@ public:
PRBool *_retval);
NS_IMETHOD AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsval id, jsval *vp, PRBool *_retval);
static nsresult DefineAddEventListener(JSContext *cx, JSObject *obj,
jsval id, JSObject **objp);
};
// Adds support for 4th parameter of addEventListener.
// Simpler than nsEventReceiverSH
// Makes also sure that the wrapper is preserved if new properties are added.
// Makes sure that the wrapper is preserved if new properties are added.
class nsEventTargetSH : public nsDOMGenericSH
{
protected:
@ -479,9 +473,6 @@ protected:
public:
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj);
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsval id, PRUint32 flags,
JSObject **objp, PRBool *_retval);
NS_IMETHOD AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsval id, jsval *vp, PRBool *_retval);

Просмотреть файл

@ -6466,8 +6466,7 @@ nsGlobalWindow::AddEventListener(const nsAString& aType,
FORWARD_TO_INNER_CREATE(AddEventListener, (aType, aListener, aUseCapture),
NS_ERROR_NOT_AVAILABLE);
return AddEventListener(aType, aListener, aUseCapture,
!nsContentUtils::IsChromeDoc(mDoc));
return AddEventListener(aType, aListener, aUseCapture, PR_FALSE, 0);
}
NS_IMETHODIMP
@ -6559,14 +6558,21 @@ nsGlobalWindow::IsRegisteredHere(const nsAString & type, PRBool *_retval)
NS_IMETHODIMP
nsGlobalWindow::AddEventListener(const nsAString& aType,
nsIDOMEventListener *aListener,
PRBool aUseCapture, PRBool aWantsUntrusted)
PRBool aUseCapture, PRBool aWantsUntrusted,
PRUint8 optional_argc)
{
NS_ASSERTION(!aWantsUntrusted || optional_argc > 0,
"Won't check if this is chrome, you want to set "
"aWantsUntrusted to PR_FALSE or make the aWantsUntrusted "
"explicit by making optional_argc non-zero.");
nsIEventListenerManager* manager = GetListenerManager(PR_TRUE);
NS_ENSURE_STATE(manager);
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
if (aWantsUntrusted) {
if (aWantsUntrusted ||
(optional_argc == 0 && !nsContentUtils::IsChromeDoc(mDoc))) {
flags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED;
}

Просмотреть файл

@ -92,7 +92,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsWindowRoot, nsIDOMEventTarget)
NS_IMETHODIMP
nsWindowRoot::AddEventListener(const nsAString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture)
{
return AddGroupedEventListener(aType, aListener, aUseCapture, nsnull);
return AddEventListener(aType, aListener, aUseCapture, PR_FALSE, 0);
}
NS_IMETHODIMP
@ -159,8 +159,14 @@ nsWindowRoot::IsRegisteredHere(const nsAString & type, PRBool *_retval)
NS_IMETHODIMP
nsWindowRoot::AddEventListener(const nsAString& aType,
nsIDOMEventListener *aListener,
PRBool aUseCapture, PRBool aWantsUntrusted)
PRBool aUseCapture, PRBool aWantsUntrusted,
PRUint8 optional_argc)
{
NS_ASSERTION(!aWantsUntrusted || optional_argc > 0,
"Won't check if this is chrome, you want to set "
"aWantsUntrusted to PR_FALSE or make the aWantsUntrusted "
"explicit by making optional_argc non-zero.");
nsIEventListenerManager* manager = GetListenerManager(PR_TRUE);
NS_ENSURE_STATE(manager);

Просмотреть файл

@ -44,7 +44,7 @@
* the Document Object Model.
*/
[scriptable, uuid(37CA0054-C715-42df-83C7-35C69E24A632)]
[scriptable, uuid(c8b658d5-d583-472a-a7ec-cbc2e79f75dd)]
interface nsIDOMNSEventTarget : nsISupports
{
/**
@ -64,10 +64,10 @@ interface nsIDOMNSEventTarget : nsISupports
* listener will receive events whether or not
* they're trusted
*/
void addEventListener(in DOMString type,
in nsIDOMEventListener listener,
in boolean useCapture,
in boolean wantsUntrusted);
[optional_argc] void addEventListener(in DOMString type,
in nsIDOMEventListener listener,
in boolean useCapture,
[optional] in boolean wantsUntrusted);
/**
* The default script type (language) for events firing on this target.
@ -79,5 +79,5 @@ interface nsIDOMNSEventTarget : nsISupports
* script targets must support changing it - ie, some targets may only
* support event handlers written in their default language.
*/
attribute PRUint32 scriptTypeID;
[noscript] attribute PRUint32 scriptTypeID;
};

Просмотреть файл

@ -110,6 +110,7 @@ _TEST_FILES = \
test_bug534362.html \
iframe_bug534362.html \
test_bug531542.html \
test_bug456151.html \
$(NULL)
libs:: $(_TEST_FILES)