Fix for bug 428229 (Unable to override addEventListener), add nsIDOMNSEventTarget to workers. r=bent.

--HG--
extra : rebase_source : 81ef9a9c3401c7b6b47c2da829903a02d61d51e3
This commit is contained in:
Peter Van der Beken 2010-01-13 14:50:01 +01:00
Родитель 1c3043fb0e
Коммит 2df9829fab
7 изменённых файлов: 160 добавлений и 59 удалений

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

@ -3735,6 +3735,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(Worker, nsIWorker)
DOM_CLASSINFO_MAP_ENTRY(nsIWorker)
DOM_CLASSINFO_MAP_ENTRY(nsIAbstractWorker)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END

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

@ -521,8 +521,9 @@ NS_IMPL_ISUPPORTS_INHERITED3(nsDOMWorkerScope, nsDOMWorkerMessageHandler,
nsIWorkerGlobalScope,
nsIXPCScriptable)
NS_IMPL_CI_INTERFACE_GETTER4(nsDOMWorkerScope, nsIWorkerScope,
NS_IMPL_CI_INTERFACE_GETTER5(nsDOMWorkerScope, nsIWorkerScope,
nsIWorkerGlobalScope,
nsIDOMNSEventTarget,
nsIDOMEventTarget,
nsIXPCScriptable)
@ -837,14 +838,7 @@ nsDOMWorkerScope::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
if (mWorker->IsCanceled()) {
return NS_ERROR_ABORT;
}
return nsDOMWorkerMessageHandler::AddEventListener(aType, aListener,
aUseCapture);
return AddEventListener(aType, aListener, aUseCapture, PR_FALSE, 0);
}
NS_IMETHODIMP
@ -875,6 +869,25 @@ nsDOMWorkerScope::DispatchEvent(nsIDOMEvent* aEvent,
return nsDOMWorkerMessageHandler::DispatchEvent(aEvent, _retval);
}
NS_IMETHODIMP
nsDOMWorkerScope::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture,
PRBool aWantsUntrusted,
PRUint8 optional_argc)
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
if (mWorker->IsCanceled()) {
return NS_ERROR_ABORT;
}
return nsDOMWorkerMessageHandler::AddEventListener(aType, aListener,
aUseCapture,
aWantsUntrusted,
optional_argc);
}
class nsWorkerHoldingRunnable : public nsIRunnable
{
public:
@ -1003,8 +1016,9 @@ public:
NS_IMPL_QUERY_INTERFACE1(nsDOMWorkerClassInfo, nsIClassInfo)
// Keep this list in sync with the list in nsDOMClassInfo.cpp!
NS_IMPL_CI_INTERFACE_GETTER3(nsDOMWorkerClassInfo, nsIWorker,
NS_IMPL_CI_INTERFACE_GETTER4(nsDOMWorkerClassInfo, nsIWorker,
nsIAbstractWorker,
nsIDOMNSEventTarget,
nsIDOMEventTarget)
NS_IMPL_THREADSAFE_DOM_CI(nsDOMWorkerClassInfo)
@ -1081,6 +1095,8 @@ NS_INTERFACE_MAP_BEGIN(nsDOMWorker)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWorker)
NS_INTERFACE_MAP_ENTRY(nsIWorker)
NS_INTERFACE_MAP_ENTRY(nsIAbstractWorker)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMNSEventTarget,
nsDOMWorkerMessageHandler)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventTarget, nsDOMWorkerMessageHandler)
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
@ -1902,13 +1918,7 @@ nsDOMWorker::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
NS_ASSERTION(mWrappedNative, "Called after Finalize!");
if (IsCanceled()) {
return NS_OK;
}
return nsDOMWorkerMessageHandler::AddEventListener(aType, aListener,
aUseCapture);
return AddEventListener(aType, aListener, aUseCapture, PR_FALSE, 0);
}
NS_IMETHODIMP
@ -1935,6 +1945,24 @@ nsDOMWorker::DispatchEvent(nsIDOMEvent* aEvent,
return nsDOMWorkerMessageHandler::DispatchEvent(aEvent, _retval);
}
NS_IMETHODIMP
nsDOMWorker::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture,
PRBool aWantsUntrusted,
PRUint8 optional_argc)
{
NS_ASSERTION(mWrappedNative, "Called after Finalize!");
if (IsCanceled()) {
return NS_OK;
}
return nsDOMWorkerMessageHandler::AddEventListener(aType, aListener,
aUseCapture,
aWantsUntrusted,
optional_argc);
}
/**
* See nsIWorker
*/

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

@ -79,6 +79,12 @@ class nsDOMWorkerScope : public nsDOMWorkerMessageHandler,
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMEVENTTARGET
// nsIDOMNSEventTarget
NS_IMETHOD AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture,
PRBool aWantsUntrusted,
PRUint8 optional_argc);
NS_DECL_NSIWORKERGLOBALSCOPE
NS_DECL_NSIWORKERSCOPE
NS_DECL_NSIXPCSCRIPTABLE
@ -126,6 +132,12 @@ class nsDOMWorker : public nsDOMWorkerMessageHandler,
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMEVENTTARGET
// nsIDOMNSEventTarget
NS_IMETHOD AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture,
PRBool aWantsUntrusted,
PRUint8 optional_argc);
NS_DECL_NSIABSTRACTWORKER
NS_DECL_NSIWORKER
NS_DECL_NSITIMERCALLBACK

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

@ -89,11 +89,13 @@ nsDOMWorkerWrappedWeakEventListener(nsDOMWorkerWeakEventListener* aInner)
NS_ASSERTION(aInner, "Null pointer!");
}
NS_IMPL_THREADSAFE_ISUPPORTS2(nsDOMWorkerMessageHandler,
NS_IMPL_THREADSAFE_ISUPPORTS3(nsDOMWorkerMessageHandler,
nsIDOMNSEventTarget,
nsIDOMEventTarget,
nsIClassInfo)
NS_IMPL_CI_INTERFACE_GETTER1(nsDOMWorkerMessageHandler,
NS_IMPL_CI_INTERFACE_GETTER2(nsDOMWorkerMessageHandler,
nsIDOMNSEventTarget,
nsIDOMEventTarget)
NS_IMPL_THREADSAFE_DOM_CI(nsDOMWorkerMessageHandler)
@ -252,25 +254,7 @@ nsDOMWorkerMessageHandler::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
ListenerCollection* collection =
const_cast<ListenerCollection*>(GetListenerCollection(aType));
if (!collection) {
collection = mCollections.AppendElement(aType);
NS_ENSURE_TRUE(collection, NS_ERROR_OUT_OF_MEMORY);
}
nsRefPtr<nsDOMWorkerWeakEventListener> weakListener =
new nsDOMWorkerWeakEventListener();
NS_ENSURE_TRUE(weakListener, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = weakListener->Init(aListener);
NS_ENSURE_SUCCESS(rv, rv);
WeakListener* newListener = collection->listeners.AppendElement(weakListener);
NS_ENSURE_TRUE(newListener, NS_ERROR_OUT_OF_MEMORY);
return NS_OK;
return AddEventListener(aType, aListener, aUseCapture, PR_FALSE, 0);
}
/**
@ -351,3 +335,56 @@ nsDOMWorkerMessageHandler::DispatchEvent(nsIDOMEvent* aEvent,
return NS_OK;
}
/**
* See nsIDOMNSEventTarget
*/
NS_IMETHODIMP
nsDOMWorkerMessageHandler::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture,
PRBool aWantsUntrusted,
PRUint8 optional_argc)
{
// We don't support aWantsUntrusted yet.
NS_ENSURE_TRUE(optional_argc == 0, NS_ERROR_NOT_IMPLEMENTED);
ListenerCollection* collection =
const_cast<ListenerCollection*>(GetListenerCollection(aType));
if (!collection) {
collection = mCollections.AppendElement(aType);
NS_ENSURE_TRUE(collection, NS_ERROR_OUT_OF_MEMORY);
}
nsRefPtr<nsDOMWorkerWeakEventListener> weakListener =
new nsDOMWorkerWeakEventListener();
NS_ENSURE_TRUE(weakListener, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = weakListener->Init(aListener);
NS_ENSURE_SUCCESS(rv, rv);
WeakListener* newListener = collection->listeners.AppendElement(weakListener);
NS_ENSURE_TRUE(newListener, NS_ERROR_OUT_OF_MEMORY);
return NS_OK;
}
/**
* See nsIDOMNSEventTarget
*/
NS_IMETHODIMP
nsDOMWorkerMessageHandler::GetScriptTypeID(PRUint32 *aScriptType)
{
*aScriptType = nsIProgrammingLanguage::JAVASCRIPT;
return NS_OK;
}
NS_IMETHODIMP
nsDOMWorkerMessageHandler::SetScriptTypeID(PRUint32 aScriptType)
{
NS_ERROR("Can't change default script type for workers");
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -42,6 +42,7 @@
#include "nsIClassInfo.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMNSEventTarget.h"
#include "nsIDOMWorkers.h"
#include "nsIProgrammingLanguage.h"
@ -105,11 +106,13 @@ private:
};
class nsDOMWorkerMessageHandler : public nsIDOMEventTarget,
public nsIDOMNSEventTarget,
public nsIClassInfo
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMEVENTTARGET
NS_DECL_NSIDOMNSEVENTTARGET
NS_DECL_NSICLASSINFO
virtual nsresult SetOnXListener(const nsAString& aType,

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

@ -246,7 +246,8 @@ nsDOMWorkerXHRUpload::nsDOMWorkerXHRUpload(nsDOMWorkerXHR* aWorkerXHR)
NS_IMPL_ISUPPORTS_INHERITED1(nsDOMWorkerXHRUpload, nsDOMWorkerXHREventTarget,
nsIXMLHttpRequestUpload)
NS_IMPL_CI_INTERFACE_GETTER3(nsDOMWorkerXHRUpload, nsIDOMEventTarget,
NS_IMPL_CI_INTERFACE_GETTER4(nsDOMWorkerXHRUpload, nsIDOMNSEventTarget,
nsIDOMEventTarget,
nsIXMLHttpRequestEventTarget,
nsIXMLHttpRequestUpload)
@ -257,25 +258,7 @@ nsDOMWorkerXHRUpload::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture)
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
NS_ENSURE_ARG_POINTER(aListener);
if (mWorkerXHR->mWorker->IsCanceled()) {
return NS_ERROR_ABORT;
}
nsresult rv = nsDOMWorkerXHREventTarget::AddEventListener(aType, aListener,
aUseCapture);
NS_ENSURE_SUCCESS(rv, rv);
rv = mWorkerXHR->mXHRProxy->UploadEventListenerAdded();
if (NS_FAILED(rv)) {
NS_WARNING("UploadEventListenerAdded failed!");
RemoveEventListener(aType, aListener, aUseCapture);
return rv;
}
return NS_OK;
return AddEventListener(aType, aListener, aUseCapture, PR_FALSE, 0);
}
NS_IMETHODIMP
@ -308,6 +291,36 @@ nsDOMWorkerXHRUpload::DispatchEvent(nsIDOMEvent* aEvent,
return nsDOMWorkerXHREventTarget::DispatchEvent(aEvent, _retval);
}
NS_IMETHODIMP
nsDOMWorkerXHRUpload::AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture,
PRBool aWantsUntrusted,
PRUint8 optional_argc)
{
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
NS_ENSURE_ARG_POINTER(aListener);
if (mWorkerXHR->mWorker->IsCanceled()) {
return NS_ERROR_ABORT;
}
nsresult rv = nsDOMWorkerXHREventTarget::AddEventListener(aType, aListener,
aUseCapture,
aWantsUntrusted,
optional_argc);
NS_ENSURE_SUCCESS(rv, rv);
rv = mWorkerXHR->mXHRProxy->UploadEventListenerAdded();
if (NS_FAILED(rv)) {
NS_WARNING("UploadEventListenerAdded failed!");
RemoveEventListener(aType, aListener, aUseCapture);
return rv;
}
return NS_OK;
}
nsresult
nsDOMWorkerXHRUpload::SetOnXListener(const nsAString& aType,
nsIDOMEventListener* aListener)
@ -364,7 +377,8 @@ NS_IMPL_QUERY_INTERFACE_INHERITED2(nsDOMWorkerXHR, nsDOMWorkerXHREventTarget,
nsIXMLHttpRequest,
nsIXPCScriptable)
NS_IMPL_CI_INTERFACE_GETTER3(nsDOMWorkerXHR, nsIDOMEventTarget,
NS_IMPL_CI_INTERFACE_GETTER4(nsDOMWorkerXHR, nsIDOMNSEventTarget,
nsIDOMEventTarget,
nsIXMLHttpRequestEventTarget,
nsIXMLHttpRequest)

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

@ -71,6 +71,7 @@ class nsDOMWorkerXHREventTarget : public nsDOMWorkerMessageHandler,
public:
NS_DECL_ISUPPORTS_INHERITED
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMWorkerMessageHandler::)
NS_FORWARD_NSIDOMNSEVENTTARGET(nsDOMWorkerMessageHandler::)
NS_DECL_NSIXMLHTTPREQUESTEVENTTARGET
static const char* const sListenerTypes[];
@ -139,6 +140,11 @@ class nsDOMWorkerXHRUpload : public nsDOMWorkerXHREventTarget,
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMEVENTTARGET
NS_IMETHOD AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture,
PRBool aWantsUntrusted,
PRUint8 optional_argc);
NS_FORWARD_NSIXMLHTTPREQUESTEVENTTARGET(nsDOMWorkerXHREventTarget::)
NS_DECL_NSIXMLHTTPREQUESTUPLOAD
NS_FORWARD_NSICLASSINFO_NOGETINTERFACES(nsDOMWorkerXHREventTarget::)