diff --git a/dom/Makefile.in b/dom/Makefile.in index 8b9f73976eae..2798eb318404 100644 --- a/dom/Makefile.in +++ b/dom/Makefile.in @@ -62,7 +62,6 @@ DIRS = \ interfaces/json \ interfaces/offline \ interfaces/geolocation \ - interfaces/threads \ interfaces/notification \ interfaces/svg \ $(NULL) @@ -81,6 +80,7 @@ DIRS += \ indexedDB \ system \ ipc \ + workers \ $(NULL) ifdef ENABLE_TESTS diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 54d4ad6aa7f6..10b2d2b7835a 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -460,7 +460,7 @@ #include "nsIDOMGeoPositionError.h" // Workers -#include "nsDOMWorker.h" +#include "mozilla/dom/workers/Workers.h" #include "nsDOMFile.h" #include "nsDOMFileReader.h" @@ -599,9 +599,6 @@ DOMCI_DATA(ContentFrameMessageManager, void) DOMCI_DATA(DOMPrototype, void) DOMCI_DATA(DOMConstructor, void) -DOMCI_DATA(Worker, void) -DOMCI_DATA(ChromeWorker, void) - #define NS_DEFINE_CLASSINFO_DATA_WITH_NAME(_class, _name, _helper, \ _flags) \ { #_name, \ @@ -1431,11 +1428,6 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA_WITH_NAME(MathMLElement, Element, nsElementSH, ELEMENT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(Worker, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ChromeWorker, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(WebGLRenderingContext, nsWebGLViewportHandlerSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(WebGLBuffer, nsDOMGenericSH, @@ -1572,8 +1564,6 @@ struct nsConstructorFuncMapData static const nsConstructorFuncMapData kConstructorFuncMap[] = { - NS_DEFINE_CONSTRUCTOR_FUNC_DATA(Worker, nsDOMWorker::NewWorker) - NS_DEFINE_CONSTRUCTOR_FUNC_DATA(ChromeWorker, nsDOMWorker::NewChromeWorker) NS_DEFINE_CONSTRUCTOR_FUNC_DATA(File, nsDOMFileFile::NewFile) NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MozBlobBuilder, NS_NewBlobBuilder) }; @@ -4144,18 +4134,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMNodeSelector) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(Worker, nsIWorker) - DOM_CLASSINFO_MAP_ENTRY(nsIWorker) - DOM_CLASSINFO_MAP_ENTRY(nsIAbstractWorker) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) - DOM_CLASSINFO_MAP_END - - DOM_CLASSINFO_MAP_BEGIN(ChromeWorker, nsIWorker) - DOM_CLASSINFO_MAP_ENTRY(nsIWorker) - DOM_CLASSINFO_MAP_ENTRY(nsIAbstractWorker) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(WebGLRenderingContext, nsIDOMWebGLRenderingContext) DOM_CLASSINFO_MAP_ENTRY(nsIDOMWebGLRenderingContext) DOM_CLASSINFO_MAP_END @@ -6066,10 +6044,32 @@ nsDOMConstructor::HasInstance(nsIXPConnectWrappedNative *wrapper, const nsGlobalNameStruct *name_struct; rv = GetNameStruct(NS_ConvertASCIItoUTF16(dom_class->name), &name_struct); - if (!name_struct) { + if (NS_FAILED(rv)) { return rv; } + if (!name_struct) { + // This isn't a normal DOM object, see if this constructor lives on its + // prototype chain. + jsval val; + if (!JS_GetProperty(cx, obj, "prototype", &val)) { + return NS_ERROR_UNEXPECTED; + } + + JS_ASSERT(!JSVAL_IS_PRIMITIVE(val)); + JSObject *dot_prototype = JSVAL_TO_OBJECT(val); + + JSObject *proto = JS_GetPrototype(cx, dom_obj); + for ( ; proto; proto = JS_GetPrototype(cx, proto)) { + if (proto == dot_prototype) { + *bp = PR_TRUE; + break; + } + } + + return NS_OK; + } + if (name_struct->mType != nsGlobalNameStruct::eTypeClassConstructor && name_struct->mType != nsGlobalNameStruct::eTypeExternalClassInfo && name_struct->mType != nsGlobalNameStruct::eTypeExternalConstructorAlias) { @@ -6702,6 +6702,10 @@ ContentWindowGetter(JSContext *cx, uintN argc, jsval *vp) return ::JS_GetProperty(cx, obj, "content", vp); } +static JSNewResolveOp sOtherResolveFuncs[] = { + mozilla::dom::workers::ResolveWorkerClasses +}; + NS_IMETHODIMP nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsid id, PRUint32 flags, @@ -6928,6 +6932,16 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, if (!(flags & JSRESOLVE_ASSIGNING)) { JSAutoRequest ar(cx); + // Resolve special classes. + for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(sOtherResolveFuncs); i++) { + if (!sOtherResolveFuncs[i](cx, obj, id, flags, objp)) { + return NS_ERROR_FAILURE; + } + if (*objp) { + return NS_OK; + } + } + // Call GlobalResolve() after we call FindChildWithName() so // that named child frames will override external properties // which have been registered with the script namespace manager. diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index 3e0513ff9eb2..77822a21566d 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -462,9 +462,6 @@ DOMCI_CLASS(MozTouchEvent) DOMCI_CLASS(MathMLElement) -DOMCI_CLASS(Worker) -DOMCI_CLASS(ChromeWorker) - // WebGL DOMCI_CLASS(WebGLRenderingContext) DOMCI_CLASS(WebGLBuffer) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index f580c5b44e44..b58781f4b5be 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -91,9 +91,9 @@ #include "nsLayoutStatics.h" #include "nsCycleCollector.h" #include "nsCCUncollectableMarker.h" -#include "nsDOMThreadService.h" #include "nsAutoJSValHolder.h" #include "nsDOMMediaQueryList.h" +#include "mozilla/dom/workers/Workers.h" // Interfaces Needed #include "nsIFrame.h" @@ -1244,18 +1244,11 @@ nsGlobalWindow::FreeInnerObjects(PRBool aClearScope) NS_ASSERTION(IsInnerWindow(), "Don't free inner objects on an outer window"); // Kill all of the workers for this window. - nsDOMThreadService* dts = nsDOMThreadService::get(); - if (dts) { - nsIScriptContext *scx = GetContextInternal(); - - JSContext *cx = scx ? (JSContext *)scx->GetNativeContext() : nsnull; - - // Have to suspend this request here because CancelWorkersForGlobal will - // lock until the worker has died and that could cause a deadlock. - JSAutoSuspendRequest asr(cx); - - dts->CancelWorkersForGlobal(static_cast(this)); - } + nsIScriptContext *scx = GetContextInternal(); + JSContext *cx = scx ? + static_cast(scx->GetNativeContext()) : + nsnull; + mozilla::dom::workers::CancelWorkersForWindow(cx, this); // Close all IndexedDB databases for this window. indexedDB::IndexedDatabaseManager* idbManager = @@ -9928,11 +9921,13 @@ nsGlobalWindow::SuspendTimeouts(PRUint32 aIncrease, if (!suspended) { DisableDeviceMotionUpdates(); - nsDOMThreadService* dts = nsDOMThreadService::get(); - if (dts) { - dts->SuspendWorkersForGlobal(static_cast(this)); - } - + // Suspend all of the workers for this window. + nsIScriptContext *scx = GetContextInternal(); + JSContext *cx = scx ? + static_cast(scx->GetNativeContext()) : + nsnull; + mozilla::dom::workers::SuspendWorkersForWindow(cx, this); + TimeStamp now = TimeStamp::Now(); for (nsTimeout *t = FirstTimeout(); IsTimeout(t); t = t->Next()) { // Set mTimeRemaining to be the time remaining for this timer. @@ -10004,10 +9999,12 @@ nsGlobalWindow::ResumeTimeouts(PRBool aThawChildren) if (shouldResume) { EnableDeviceMotionUpdates(); - nsDOMThreadService* dts = nsDOMThreadService::get(); - if (dts) { - dts->ResumeWorkersForGlobal(static_cast(this)); - } + // Resume all of the workers for this window. + nsIScriptContext *scx = GetContextInternal(); + JSContext *cx = scx ? + static_cast(scx->GetNativeContext()) : + nsnull; + mozilla::dom::workers::ResumeWorkersForWindow(cx, this); // Restore all of the timeouts, using the stored time remaining // (stored in timeout->mTimeRemaining). diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index ee5d55f136f7..5e8b87cc3335 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -3690,32 +3690,32 @@ ObjectPrincipalFinder(JSContext *cx, JSObject *obj) return jsPrincipals; } -static JSObject* -DOMReadStructuredClone(JSContext* cx, - JSStructuredCloneReader* reader, - uint32 tag, - uint32 data, - void* closure) +JSObject* +NS_DOMReadStructuredClone(JSContext* cx, + JSStructuredCloneReader* reader, + uint32 tag, + uint32 data, + void* closure) { // We don't currently support any extensions to structured cloning. nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_DOM_DATA_CLONE_ERR); return nsnull; } -static JSBool -DOMWriteStructuredClone(JSContext* cx, - JSStructuredCloneWriter* writer, - JSObject* obj, - void *closure) +JSBool +NS_DOMWriteStructuredClone(JSContext* cx, + JSStructuredCloneWriter* writer, + JSObject* obj, + void *closure) { // We don't currently support any extensions to structured cloning. nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_DOM_DATA_CLONE_ERR); return JS_FALSE; } -static void -DOMStructuredCloneError(JSContext* cx, - uint32 errorid) +void +NS_DOMStructuredCloneError(JSContext* cx, + uint32 errorid) { // We don't currently support any extensions to structured cloning. nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_DOM_DATA_CLONE_ERR); @@ -3759,9 +3759,9 @@ nsJSRuntime::Init() // Set up the structured clone callbacks. static JSStructuredCloneCallbacks cloneCallbacks = { - DOMReadStructuredClone, - DOMWriteStructuredClone, - DOMStructuredCloneError + NS_DOMReadStructuredClone, + NS_DOMWriteStructuredClone, + NS_DOMStructuredCloneError }; JS_SetStructuredCloneCallbacks(sRuntime, &cloneCallbacks); diff --git a/dom/base/nsJSEnvironment.h b/dom/base/nsJSEnvironment.h index c1cedbec23c3..a0e1835dcd4f 100644 --- a/dom/base/nsJSEnvironment.h +++ b/dom/base/nsJSEnvironment.h @@ -363,4 +363,14 @@ nsresult NS_CreateJSRuntime(nsIScriptRuntime **aRuntime); /* prototypes */ void NS_ScriptErrorReporter(JSContext *cx, const char *message, JSErrorReport *report); +JSObject* NS_DOMReadStructuredClone(JSContext* cx, + JSStructuredCloneReader* reader, uint32 tag, + uint32 data, void* closure); + +JSBool NS_DOMWriteStructuredClone(JSContext* cx, + JSStructuredCloneWriter* writer, + JSObject* obj, void *closure); + +void NS_DOMStructuredCloneError(JSContext* cx, uint32 errorid); + #endif /* nsJSEnvironment_h___ */ diff --git a/dom/dom-config.mk b/dom/dom-config.mk index 34e5c6d9ed52..8d13a462c42e 100644 --- a/dom/dom-config.mk +++ b/dom/dom-config.mk @@ -7,7 +7,7 @@ DOM_SRCDIRS = \ dom/src/offline \ dom/src/geolocation \ dom/src/notification \ - dom/src/threads \ + dom/workers \ content/xbl/src \ content/xul/document/src \ content/events/src \ diff --git a/dom/interfaces/threads/nsIDOMWorkers.idl b/dom/interfaces/threads/nsIDOMWorkers.idl deleted file mode 100644 index a30f0a24b879..000000000000 --- a/dom/interfaces/threads/nsIDOMWorkers.idl +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Web Workers. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Ben Turner (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * From http://www.whatwg.org/specs/web-workers/current-work - */ - -#include "nsIDOMEvent.idl" -#include "nsIDOMEventTarget.idl" - -interface nsIDOMEventListener; - -[scriptable, uuid(ab3725b8-3fca-40cc-a42c-92fb154ef01d)] -interface nsIWorkerMessagePort : nsISupports -{ - void postMessage(/* in JSObject aMessage */); -}; - -[scriptable, uuid(508f2d49-e9a0-4fe8-bd33-321820173b4a)] -interface nsIWorkerMessageEvent : nsIDOMEvent -{ - readonly attribute DOMString data; - readonly attribute DOMString origin; - - readonly attribute nsISupports source; - - void initMessageEvent(in DOMString aTypeArg, - in boolean aCanBubbleArg, - in boolean aCancelableArg, - in DOMString aDataArg, - in DOMString aOriginArg, - in nsISupports aSourceArg); -}; - -[scriptable, uuid(73d82c1d-05de-49c9-a23b-7121ff09a67a)] -interface nsIWorkerErrorEvent : nsIDOMEvent -{ - readonly attribute DOMString message; - readonly attribute DOMString filename; - - readonly attribute unsigned long lineno; - - void initErrorEvent(in DOMString aTypeArg, - in boolean aCanBubbleArg, - in boolean aCancelableArg, - in DOMString aMessageArg, - in DOMString aFilenameArg, - in unsigned long aLinenoArg); -}; - -[scriptable, uuid(17a005c3-4f2f-4bb6-b169-c181fa6873de)] -interface nsIWorkerLocation : nsISupports -{ - readonly attribute AUTF8String href; - readonly attribute AUTF8String protocol; - readonly attribute AUTF8String host; - readonly attribute AUTF8String hostname; - readonly attribute AUTF8String port; - readonly attribute AUTF8String pathname; - readonly attribute AUTF8String search; - readonly attribute AUTF8String hash; - - AUTF8String toString(); -}; - -[scriptable, uuid(74fb665a-e477-4ce2-b3c6-c58b1b28b6c3)] -interface nsIWorkerNavigator : nsISupports -{ - readonly attribute DOMString appName; - readonly attribute DOMString appVersion; - readonly attribute DOMString platform; - readonly attribute DOMString userAgent; -}; - -[scriptable, uuid(c111e7d3-8044-4458-aa7b-637696ffb841)] -interface nsIWorkerGlobalScope : nsISupports -{ - readonly attribute nsIWorkerGlobalScope self; - readonly attribute nsIWorkerNavigator navigator; - readonly attribute nsIWorkerLocation location; - - attribute nsIDOMEventListener onerror; -}; - -[scriptable, uuid(5c55ea4b-e4ac-4ceb-bfeb-46bd5e521b8a)] -interface nsIWorkerScope : nsIWorkerGlobalScope -{ - void postMessage(/* in JSObject aMessage */); - - void close(); - - attribute nsIDOMEventListener onmessage; - attribute nsIDOMEventListener onclose; -}; - -[scriptable, builtinclass, uuid(b90b7561-b5e2-4545-84b0-280dbaaa94ea)] -interface nsIAbstractWorker : nsIDOMEventTarget -{ - attribute nsIDOMEventListener onerror; -}; - -[scriptable, builtinclass, uuid(daf945c3-8d29-4724-8939-dd383f7d27a7)] -interface nsIWorker : nsIAbstractWorker -{ - void postMessage(/* in JSObject aMessage */); - - attribute nsIDOMEventListener onmessage; - - void terminate(); -}; - -[scriptable, uuid(cfc4bb32-ca83-4d58-9b6f-66f8054a333a)] -interface nsIWorkerFactory : nsISupports -{ - nsIWorker newChromeWorker(/* in DOMString aScriptURL */); -}; - -%{ C++ -#define NS_WORKERFACTORY_CONTRACTID \ -"@mozilla.org/threads/workerfactory;1" -%} diff --git a/dom/src/Makefile.in b/dom/src/Makefile.in index 757b6714bfb2..955d50e7bcd8 100644 --- a/dom/src/Makefile.in +++ b/dom/src/Makefile.in @@ -42,6 +42,6 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS = jsurl events storage offline json geolocation threads notification +DIRS = jsurl events storage offline json geolocation notification foo include $(topsrcdir)/config/rules.mk diff --git a/dom/interfaces/threads/Makefile.in b/dom/src/foo/Makefile.in similarity index 73% rename from dom/interfaces/threads/Makefile.in rename to dom/src/foo/Makefile.in index 40d9107ffedd..759adbf6132f 100644 --- a/dom/interfaces/threads/Makefile.in +++ b/dom/src/foo/Makefile.in @@ -1,4 +1,3 @@ -# # ***** BEGIN LICENSE BLOCK ***** # Version: MPL 1.1/GPL 2.0/LGPL 2.1 # @@ -12,10 +11,11 @@ # for the specific language governing rights and limitations under the # License. # -# The Original Code is mozilla.org code. +# The Original Code is worker threads. # -# The Initial Developer of the Original Code is Mozilla Foundation. -# Portions created by the Initial Developer are Copyright (C) 2007 +# The Initial Developer of the Original Code is +# Mozilla Corporation +# Portions created by the Initial Developer are Copyright (C) 2008 # the Initial Developer. All Rights Reserved. # # Contributor(s): @@ -23,8 +23,8 @@ # Ben Turner # # Alternatively, the contents of this file may be used under the terms of -# either of the GNU General Public License Version 2 or later (the "GPL"), -# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), # in which case the provisions of the GPL or the LGPL are applicable instead # of those above. If you wish to allow use of your version of this file only # under the terms of either the GPL or the LGPL, and not to allow others to @@ -36,17 +36,20 @@ # # ***** END LICENSE BLOCK ***** -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +relativesrcdir = dom/src/foo include $(DEPTH)/config/autoconf.mk -MODULE = dom -XPIDL_MODULE = dom_threads -GRE_MODULE = 1 - -XPIDLSRCS = nsIDOMWorkers.idl - include $(topsrcdir)/config/rules.mk + +_TEST_FILES = \ + test_foo.html \ + $(NULL) + +libs:: $(_TEST_FILES) + $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir) diff --git a/dom/src/threads/test/test_functionHandlers.html b/dom/src/foo/test_foo.html similarity index 54% rename from dom/src/threads/test/test_functionHandlers.html rename to dom/src/foo/test_foo.html index 633393204e46..bd0aa8346a14 100644 --- a/dom/src/threads/test/test_functionHandlers.html +++ b/dom/src/foo/test_foo.html @@ -1,15 +1,16 @@ - Test for DOM Worker Threads Recursion + Test for DOM Worker Threads XHR (Bug 450452 ) +DOM Worker Threads XHR (Bug 450452)