Bug 730554 - Part c: Unwrap to nsGenericElement in TexImage2DImageDataOrElement; r=bz

This commit is contained in:
Ms2ger 2012-03-11 09:54:24 +01:00
parent 2e73ca2611
commit 217ef2755d
4 changed files with 25 additions and 35 deletions

View File

@ -413,7 +413,7 @@ public:
return self->TexImage2D_imageData(target, level, internalformat, width,
height, 0, format, type, pixels);
}
nsresult DoCallForElement(nsIDOMElement* elt)
nsresult DoCallForElement(mozilla::dom::Element* elt)
{
return self->TexImage2D_dom(target, level, internalformat, format, type,
elt);
@ -456,7 +456,7 @@ public:
width, height, format, type,
pixels);
}
nsresult DoCallForElement(nsIDOMElement* elt)
nsresult DoCallForElement(mozilla::dom::Element* elt)
{
return self->TexSubImage2D_dom(target, level, xoffset, yoffset, format,
type, elt);
@ -469,24 +469,12 @@ TexImage2DImageDataOrElement(JSContext* cx, T& self, JS::Value* object)
{
MOZ_ASSERT(object && object->isObject());
nsIDOMElement* elt;
nsGenericElement* elt;
xpc_qsSelfRef eltRef;
nsresult rv =
xpc_qsUnwrapArg<nsIDOMElement>(cx, *object, &elt, &eltRef.ptr, object);
if (NS_FAILED(rv)) {
return false;
}
rv = self.DoCallForElement(elt);
// NS_ERROR_DOM_SECURITY_ERR indicates we tried to load a cross-domain
// element, so bail out immediately, don't try to interpret as ImageData.
if (rv == NS_ERROR_DOM_SECURITY_ERR) {
return xpc_qsThrow(cx, rv);
}
if (NS_SUCCEEDED(rv)) {
return true;
if (NS_SUCCEEDED(xpc_qsUnwrapArg<nsGenericElement>(
cx, *object, &elt, &eltRef.ptr, object))) {
nsresult rv = self.DoCallForElement(elt);
return NS_SUCCEEDED(rv) || xpc_qsThrow(cx, rv);
}
// Failed to interpret object as an Element, now try to interpret it as
@ -517,7 +505,7 @@ TexImage2DImageDataOrElement(JSContext* cx, T& self, JS::Value* object)
return xpc_qsThrow(cx, NS_ERROR_FAILURE);
}
rv = self.DoCallForImageData(int_width, int_height, obj_data);
nsresult rv = self.DoCallForImageData(int_width, int_height, obj_data);
return NS_SUCCEEDED(rv) || xpc_qsThrow(cx, rv);
}

View File

@ -815,7 +815,7 @@ protected:
int dstFormat, bool dstPremultiplied,
size_t dstTexelSize);
nsresult DOMElementToImageSurface(nsIDOMElement *imageOrCanvas,
nsresult DOMElementToImageSurface(dom::Element* imageOrCanvas,
gfxImageSurface **imageOut,
int *format);

View File

@ -70,6 +70,7 @@
#endif
using namespace mozilla;
using namespace mozilla::dom;
static bool BaseTypeAndSizeFromUniformType(WebGLenum uType, WebGLenum *baseType, WebGLint *unitSize);
static WebGLenum InternalFormatForFormatAndType(WebGLenum format, WebGLenum type, bool isGLES2);
@ -3966,11 +3967,10 @@ WebGLContext::ConvertImage(size_t width, size_t height, size_t srcStride, size_t
}
nsresult
WebGLContext::DOMElementToImageSurface(nsIDOMElement *imageOrCanvas,
WebGLContext::DOMElementToImageSurface(Element* imageOrCanvas,
gfxImageSurface **imageOut, int *format)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(imageOrCanvas);
if (!content) {
if (!imageOrCanvas) {
return NS_ERROR_FAILURE;
}
@ -3984,7 +3984,7 @@ WebGLContext::DOMElementToImageSurface(nsIDOMElement *imageOrCanvas,
flags |= nsLayoutUtils::SFE_NO_PREMULTIPLY_ALPHA;
nsLayoutUtils::SurfaceFromElementResult res =
nsLayoutUtils::SurfaceFromElement(content->AsElement(), flags);
nsLayoutUtils::SurfaceFromElement(imageOrCanvas, flags);
if (!res.mSurface)
return NS_ERROR_FAILURE;
if (res.mSurface->GetType() != gfxASurface::SurfaceTypeImage) {
@ -4016,7 +4016,7 @@ WebGLContext::DOMElementToImageSurface(nsIDOMElement *imageOrCanvas,
// part 2: if the DOM element is a canvas, check that it's not write-only.
// That would indicate a tainted canvas, i.e. a canvas that could contain
// cross-domain image data.
if (nsHTMLCanvasElement* canvas = nsHTMLCanvasElement::FromContent(content)) {
if (nsHTMLCanvasElement* canvas = nsHTMLCanvasElement::FromContent(imageOrCanvas)) {
if (canvas->IsWriteOnly()) {
LogMessageIfVerbose("The canvas used as source for texImage2D here is tainted (write-only). It is forbidden "
"to load a WebGL texture from a tainted canvas. A Canvas becomes tainted for example "
@ -5082,7 +5082,7 @@ WebGLContext::TexImage2D_imageData(WebGLenum target, WebGLint level, WebGLenum i
NS_IMETHODIMP
WebGLContext::TexImage2D_dom(WebGLenum target, WebGLint level, WebGLenum internalformat,
WebGLenum format, GLenum type, nsIDOMElement *elt)
WebGLenum format, GLenum type, Element* elt)
{
if (!IsContextStable())
return NS_OK;
@ -5272,7 +5272,7 @@ NS_IMETHODIMP
WebGLContext::TexSubImage2D_dom(WebGLenum target, WebGLint level,
WebGLint xoffset, WebGLint yoffset,
WebGLenum format, WebGLenum type,
nsIDOMElement *elt)
Element *elt)
{
if (!IsContextStable())
return NS_OK;

View File

@ -59,16 +59,18 @@ typedef float WebGLclampf;
// for jsval
#include "jsapi.h"
namespace js {
struct ArrayBuffer;
struct TypedArray;
}
namespace mozilla {
namespace dom {
class Element;
} // namespace dom
} // namespace mozilla
/* Avoid conflict with WinAPI */
#undef NO_ERROR
%}
[ptr] native WebGLJSObjectPtr (JSObject);
[ptr] native Element (mozilla::dom::Element);
//
// OpenGL object wrappers
@ -175,7 +177,7 @@ interface nsIWebGLExtensionTextureFilterAnisotropic : nsIWebGLExtension
const WebGLenum MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF;
};
[scriptable, builtinclass, uuid(f000afac-11b3-4c06-a35f-8db411f1cf54)]
[scriptable, builtinclass, uuid(020474b1-2d3f-403b-b85d-11d9082ccd92)]
interface nsIDOMWebGLRenderingContext : nsISupports
{
//
@ -786,7 +788,7 @@ interface nsIDOMWebGLRenderingContext : nsISupports
// HTMLImageElement, HTMLCanvasElement, HTMLVideoElement
[noscript] void texImage2D_dom(in WebGLenum target, in WebGLint level, in WebGLenum internalformat,
in WebGLenum format, in WebGLenum type, in nsIDOMElement element);
in WebGLenum format, in WebGLenum type, in Element element);
void texSubImage2D([optional] in long dummy);
[noscript] void texSubImage2D_array(in WebGLenum target, in WebGLint level,
@ -798,7 +800,7 @@ interface nsIDOMWebGLRenderingContext : nsISupports
// HTMLImageElement, HTMLCanvasElement, HTMLVideoElement
[noscript] void texSubImage2D_dom(in WebGLenum target, in WebGLint level,
in WebGLint xoffset, in WebGLint yoffset, in WebGLenum format, in WebGLenum type,
in nsIDOMElement element);
in Element element);
// Modified: This replaces glTexParameterf, glTexParameterfv, glTexParameteri and glTexParameteriv
void texParameterf(in WebGLenum target, in WebGLenum pname, in WebGLfloat param);