Bug 728029 - Preserve added JS properties on the JS object returned by webgl.getExtension - r=peterv

This commit is contained in:
Benoit Jacob 2012-03-26 14:59:04 -04:00
Родитель 5b36b1e0f9
Коммит 6e6cb1c555
9 изменённых файлов: 148 добавлений и 57 удалений

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

@ -52,6 +52,7 @@ EXPORTS = \
CustomQS_Canvas.h \
CustomQS_Canvas2D.h \
CustomQS_WebGL.h \
WebGLContext.h \
$(NULL)
EXPORTS_NAMESPACES = mozilla/dom

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

@ -94,6 +94,8 @@ WebGLContext::WebGLContext()
: mCanvasElement(nsnull),
gl(nsnull)
{
mEnabledExtensions.SetLength(WebGLExtensionID_Max);
mGeneration = 0;
mInvalidated = false;
mResetLayer = true;
@ -1168,9 +1170,11 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLContext)
NS_IMPL_CYCLE_COLLECTION_CLASS(WebGLContext)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WebGLContext)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCanvasElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mEnabledExtensions)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(WebGLContext)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCanvasElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_OF_NSCOMPTR(mEnabledExtensions)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
DOMCI_DATA(WebGLRenderingContext, WebGLContext)
@ -1296,44 +1300,34 @@ NAME_NOT_SUPPORTED(WebGLShader)
NAME_NOT_SUPPORTED(WebGLFramebuffer)
NAME_NOT_SUPPORTED(WebGLRenderbuffer)
NS_IMPL_ADDREF(WebGLExtension)
NS_IMPL_RELEASE(WebGLExtension)
// WebGLExtension
NS_IMPL_CYCLE_COLLECTION_CLASS(WebGLExtension)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(WebGLExtension)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(WebGLExtension)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WebGLExtension)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebGLExtension)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIWebGLExtension)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebGLExtension)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(WebGLExtension)
NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLExtension)
DOMCI_DATA(WebGLExtension, WebGLExtension)
NS_INTERFACE_MAP_BEGIN(WebGLExtension)
NS_INTERFACE_MAP_ENTRY(nsIWebGLExtension)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebGLExtension)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(WebGLExtensionStandardDerivatives)
NS_IMPL_RELEASE(WebGLExtensionStandardDerivatives)
DOMCI_DATA(WebGLExtensionStandardDerivatives, WebGLExtensionStandardDerivatives)
NS_INTERFACE_MAP_BEGIN(WebGLExtensionStandardDerivatives)
NS_INTERFACE_MAP_ENTRY(nsIWebGLExtensionStandardDerivatives)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, WebGLExtension)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebGLExtensionStandardDerivatives)
NS_INTERFACE_MAP_END_INHERITING(WebGLExtension)
NS_IMPL_ADDREF(WebGLExtensionTextureFilterAnisotropic)
NS_IMPL_RELEASE(WebGLExtensionTextureFilterAnisotropic)
DOMCI_DATA(WebGLExtensionTextureFilterAnisotropic, WebGLExtensionTextureFilterAnisotropic)
NS_IMPL_ADDREF(WebGLExtensionLoseContext)
NS_IMPL_RELEASE(WebGLExtensionLoseContext)
DOMCI_DATA(WebGLExtensionLoseContext, WebGLExtensionLoseContext)
NS_INTERFACE_MAP_BEGIN(WebGLExtensionLoseContext)
NS_INTERFACE_MAP_ENTRY(nsIWebGLExtensionLoseContext)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, WebGLExtension)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebGLExtensionLoseContext)
NS_INTERFACE_MAP_END_INHERITING(WebGLExtension)
/* readonly attribute WebGLsizei drawingBufferWidth; */
NS_IMETHODIMP
WebGLContext::GetDrawingBufferWidth(WebGLsizei *aWidth)

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

@ -58,6 +58,7 @@
#include "nsIMemoryReporter.h"
#include "nsIJSNativeInitializer.h"
#include "nsContentUtils.h"
#include "nsWrapperCache.h"
#include "GLContextProvider.h"
#include "Layers.h"
@ -537,6 +538,10 @@ public:
// nsICanvasRenderingContextInternal
NS_IMETHOD SetCanvasElement(nsHTMLCanvasElement* aParentCanvas);
nsHTMLCanvasElement* HTMLCanvasElement() {
return static_cast<nsHTMLCanvasElement*>(mCanvasElement.get());
}
NS_IMETHOD SetDimensions(PRInt32 width, PRInt32 height);
NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, PRInt32 width, PRInt32 height)
{ return NS_ERROR_NOT_IMPLEMENTED; }
@ -698,9 +703,6 @@ protected:
nsresult BufferSubData_array(WebGLenum target, PRInt32 offset, JSObject* data);
nsCOMPtr<nsIDOMHTMLCanvasElement> mCanvasElement;
nsHTMLCanvasElement *HTMLCanvasElement() {
return static_cast<nsHTMLCanvasElement*>(mCanvasElement.get());
}
nsRefPtr<gl::GLContext> gl;
@ -763,7 +765,7 @@ protected:
WebGL_MOZ_WEBGL_lose_context,
WebGLExtensionID_Max
};
nsRefPtr<WebGLExtension> mEnabledExtensions[WebGLExtensionID_Max];
nsTArray<nsRefPtr<WebGLExtension> > mEnabledExtensions;
bool IsExtensionEnabled(WebGLExtensionID ext) const {
NS_ABORT_IF_FALSE(ext >= 0 && ext < WebGLExtensionID_Max, "bogus index!");
return mEnabledExtensions[ext] != nsnull;
@ -997,6 +999,8 @@ public:
mContextGeneration == other->Generation();
}
WebGLContext *Context() const { return mContext; }
protected:
WebGLContext *mContext;
PRUint32 mContextGeneration;
@ -2541,14 +2545,17 @@ protected:
class WebGLExtension
: public nsIWebGLExtension
, public WebGLContextBoundObject
, public nsWrapperCache
{
public:
WebGLExtension(WebGLContext *baseContext)
: WebGLContextBoundObject(baseContext)
{}
NS_DECL_ISUPPORTS
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WebGLExtension)
NS_DECL_NSIWEBGLEXTENSION
virtual ~WebGLExtension() {}
};

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

@ -74,3 +74,14 @@ WebGLExtensionLoseContext::RestoreContext()
return NS_OK;
}
NS_IMPL_ADDREF_INHERITED(WebGLExtensionLoseContext, WebGLExtension)
NS_IMPL_RELEASE_INHERITED(WebGLExtensionLoseContext, WebGLExtension)
DOMCI_DATA(WebGLExtensionLoseContext, WebGLExtensionLoseContext)
NS_INTERFACE_MAP_BEGIN(WebGLExtensionLoseContext)
NS_INTERFACE_MAP_ENTRY(nsIWebGLExtensionLoseContext)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, WebGLExtension)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebGLExtensionLoseContext)
NS_INTERFACE_MAP_END_INHERITING(WebGLExtension)

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

@ -56,3 +56,14 @@ WebGLExtensionStandardDerivatives::~WebGLExtensionStandardDerivatives()
{
}
NS_IMPL_ADDREF_INHERITED(WebGLExtensionStandardDerivatives, WebGLExtension)
NS_IMPL_RELEASE_INHERITED(WebGLExtensionStandardDerivatives, WebGLExtension)
DOMCI_DATA(WebGLExtensionStandardDerivatives, WebGLExtensionStandardDerivatives)
NS_INTERFACE_MAP_BEGIN(WebGLExtensionStandardDerivatives)
NS_INTERFACE_MAP_ENTRY(nsIWebGLExtensionStandardDerivatives)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, WebGLExtension)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebGLExtensionStandardDerivatives)
NS_INTERFACE_MAP_END_INHERITING(WebGLExtension)

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

@ -46,12 +46,6 @@
using namespace mozilla;
NS_INTERFACE_MAP_BEGIN(WebGLExtensionTextureFilterAnisotropic)
NS_INTERFACE_MAP_ENTRY(nsIWebGLExtensionTextureFilterAnisotropic)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, WebGLExtension)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebGLExtensionTextureFilterAnisotropic)
NS_INTERFACE_MAP_END_INHERITING(WebGLExtension)
WebGLExtensionTextureFilterAnisotropic::WebGLExtensionTextureFilterAnisotropic(WebGLContext* context) :
WebGLExtension(context)
{
@ -62,3 +56,14 @@ WebGLExtensionTextureFilterAnisotropic::~WebGLExtensionTextureFilterAnisotropic(
{
}
NS_IMPL_ADDREF_INHERITED(WebGLExtensionTextureFilterAnisotropic, WebGLExtension)
NS_IMPL_RELEASE_INHERITED(WebGLExtensionTextureFilterAnisotropic, WebGLExtension)
DOMCI_DATA(WebGLExtensionTextureFilterAnisotropic, WebGLExtensionTextureFilterAnisotropic)
NS_INTERFACE_MAP_BEGIN(WebGLExtensionTextureFilterAnisotropic)
NS_INTERFACE_MAP_ENTRY(nsIWebGLExtensionTextureFilterAnisotropic)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, WebGLExtension)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebGLExtensionTextureFilterAnisotropic)
NS_INTERFACE_MAP_END_INHERITING(WebGLExtension)

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

@ -49,7 +49,7 @@ public:
WebGLExtensionLoseContext(WebGLContext*);
virtual ~WebGLExtensionLoseContext();
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIWEBGLEXTENSIONLOSECONTEXT
};
@ -61,7 +61,7 @@ public:
WebGLExtensionStandardDerivatives(WebGLContext* context);
virtual ~WebGLExtensionStandardDerivatives();
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIWEBGLEXTENSION
};
@ -73,7 +73,7 @@ public:
WebGLExtensionTextureFilterAnisotropic(WebGLContext* context);
virtual ~WebGLExtensionTextureFilterAnisotropic();
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIWEBGLEXTENSION
};

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

@ -532,6 +532,9 @@ using mozilla::dom::indexedDB::IDBWrapperCache;
#include "DOMError.h"
#include "DOMRequest.h"
#undef None // something included above defines this preprocessor symbol, maybe Xlib headers
#include "WebGLContext.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -1525,14 +1528,18 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WebGLActiveInfo, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WebGLExtension, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WebGLExtensionStandardDerivatives, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WebGLExtensionTextureFilterAnisotropic, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WebGLExtensionLoseContext, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WebGLExtension, WebGLExtensionSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_ADDPROPERTY)
NS_DEFINE_CLASSINFO_DATA(WebGLExtensionStandardDerivatives, WebGLExtensionSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_ADDPROPERTY)
NS_DEFINE_CLASSINFO_DATA(WebGLExtensionTextureFilterAnisotropic, WebGLExtensionSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_ADDPROPERTY)
NS_DEFINE_CLASSINFO_DATA(WebGLExtensionLoseContext, WebGLExtensionSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_ADDPROPERTY)
NS_DEFINE_CLASSINFO_DATA(PaintRequest, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -10841,4 +10848,33 @@ nsSVGStringListSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
return rv;
}
NS_IMETHODIMP
WebGLExtensionSH::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, bool *_retval)
{
WebGLExtensionSH::PreserveWrapper(GetNative(wrapper, obj));
return NS_OK;
}
void
WebGLExtensionSH::PreserveWrapper(nsISupports *aNative)
{
WebGLExtension* ext = static_cast<WebGLExtension*>(aNative);
nsContentUtils::PreserveWrapper(aNative, ext);
}
nsresult
WebGLExtensionSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj)
{
*parentObj = globalObj;
nsCOMPtr<nsIWebGLExtension> iwebglext(do_QueryInterface(nativeObj));
WebGLExtension *webglext = static_cast<WebGLExtension*>(iwebglext.get());
WebGLContext *webgl = webglext->Context();
nsHTMLCanvasElement *canvas = webgl->HTMLCanvasElement();
nsINode *node = static_cast<nsINode*>(canvas);
return WrapNativeParent(cx, globalObj, node, node, parentObj);
}

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

@ -495,6 +495,32 @@ public:
}
};
// WebGLExtension scriptable helper
class WebGLExtensionSH : public nsDOMGenericSH
{
protected:
WebGLExtensionSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData)
{
}
virtual ~WebGLExtensionSH()
{
}
public:
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj);
NS_IMETHOD AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, bool *_retval);
virtual void PreserveWrapper(nsISupports *aNative);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new WebGLExtensionSH(aData);
}
};
// DOM Node helper, this class deals with setting the parent for the
// wrappers