mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 759726 - Move mCanvasElement to nsICanvasRenderingContextInternal and make SetCanvasElement return void; f=bz r=bjacob
This commit is contained in:
parent
c334a5d8c5
commit
e9e1333685
@ -6,7 +6,6 @@
|
||||
#define mozilla_dom_DocumentRendererChild
|
||||
|
||||
#include "mozilla/ipc/PDocumentRendererChild.h"
|
||||
#include "nsICanvasRenderingContextInternal.h"
|
||||
#include "nsString.h"
|
||||
#include "gfxContext.h"
|
||||
|
||||
|
@ -6,11 +6,12 @@
|
||||
#define mozilla_dom_DocumentRendererParent
|
||||
|
||||
#include "mozilla/ipc/PDocumentRendererParent.h"
|
||||
#include "nsICanvasRenderingContextInternal.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "gfxContext.h"
|
||||
|
||||
class nsICanvasRenderingContextInternal;
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
|
@ -9,14 +9,14 @@
|
||||
#include "nsISupports.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsHTMLCanvasElement.h"
|
||||
#include "gfxPattern.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
#define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \
|
||||
{ 0xffb42d3c, 0x8281, 0x44c8, \
|
||||
{ 0xac, 0xba, 0x73, 0x15, 0x31, 0xaa, 0xe5, 0x07 } }
|
||||
{ 0x8b8da863, 0xd151, 0x4014, \
|
||||
{ 0x8b, 0xdc, 0x62, 0xb5, 0x0d, 0xc0, 0x2b, 0x62 } }
|
||||
|
||||
class nsHTMLCanvasElement;
|
||||
class gfxContext;
|
||||
class gfxASurface;
|
||||
class nsIPropertyBag;
|
||||
@ -46,9 +46,10 @@ public:
|
||||
RenderFlagPremultAlpha = 0x1
|
||||
};
|
||||
|
||||
// This method should NOT hold a ref to aParentCanvas; it will be called
|
||||
// with nsnull when the element is going away.
|
||||
NS_IMETHOD SetCanvasElement(nsHTMLCanvasElement* aParentCanvas) = 0;
|
||||
void SetCanvasElement(nsHTMLCanvasElement* aParentCanvas)
|
||||
{
|
||||
mCanvasElement = aParentCanvas;
|
||||
}
|
||||
|
||||
// Sets the dimensions of the canvas, in pixels. Called
|
||||
// whenever the size of the element changes.
|
||||
@ -119,6 +120,9 @@ public:
|
||||
// anything into this canvas before changing the shmem state, it will be
|
||||
// lost.
|
||||
NS_IMETHOD SetIsIPC(bool isIPC) = 0;
|
||||
|
||||
protected:
|
||||
nsRefPtr<nsHTMLCanvasElement> mCanvasElement;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasRenderingContextInternal,
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocShellTreeNode.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIDocument.h"
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "mozilla/ipc/DocumentRendererParent.h"
|
||||
#include "gfxImageSurface.h"
|
||||
#include "gfxPattern.h"
|
||||
#include "nsICanvasRenderingContextInternal.h"
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
|
||||
|
@ -73,8 +73,7 @@ NS_NewCanvasRenderingContextWebGL(nsIDOMWebGLRenderingContext** aResult)
|
||||
}
|
||||
|
||||
WebGLContext::WebGLContext()
|
||||
: mCanvasElement(nsnull),
|
||||
gl(nsnull)
|
||||
: gl(nsnull)
|
||||
{
|
||||
SetIsDOMBinding();
|
||||
mEnabledExtensions.SetLength(WebGLExtensionID_Max);
|
||||
@ -243,10 +242,10 @@ WebGLContext::Invalidate()
|
||||
if (!mCanvasElement)
|
||||
return;
|
||||
|
||||
nsSVGEffects::InvalidateDirectRenderingObservers(HTMLCanvasElement());
|
||||
nsSVGEffects::InvalidateDirectRenderingObservers(mCanvasElement);
|
||||
|
||||
mInvalidated = true;
|
||||
HTMLCanvasElement()->InvalidateCanvasContent(nsnull);
|
||||
mCanvasElement->InvalidateCanvasContent(nsnull);
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMHTMLCanvasElement canvas; */
|
||||
@ -262,14 +261,6 @@ WebGLContext::GetCanvas(nsIDOMHTMLCanvasElement **canvas)
|
||||
// nsICanvasRenderingContextInternal
|
||||
//
|
||||
|
||||
NS_IMETHODIMP
|
||||
WebGLContext::SetCanvasElement(nsHTMLCanvasElement* aParentCanvas)
|
||||
{
|
||||
mCanvasElement = aParentCanvas;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static bool
|
||||
GetBoolFromPropertyBag(nsIPropertyBag *bag, const char *propName, bool *boolResult)
|
||||
{
|
||||
@ -332,7 +323,7 @@ WebGLContext::SetDimensions(PRInt32 width, PRInt32 height)
|
||||
/*** early success return cases ***/
|
||||
|
||||
if (mCanvasElement) {
|
||||
HTMLCanvasElement()->InvalidateCanvas();
|
||||
mCanvasElement->InvalidateCanvas();
|
||||
}
|
||||
|
||||
if (gl && mWidth == width && mHeight == height)
|
||||
@ -727,7 +718,7 @@ WebGLContext::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
||||
// releasing the reference to the element.
|
||||
// The userData will receive DidTransactionCallbacks, which flush the
|
||||
// the invalidation state to indicate that the canvas is up to date.
|
||||
userData = new WebGLContextUserData(HTMLCanvasElement());
|
||||
userData = new WebGLContextUserData(mCanvasElement);
|
||||
canvasLayer->SetDidTransactionCallback(
|
||||
WebGLContextUserData::DidTransactionCallback, userData);
|
||||
}
|
||||
@ -1066,7 +1057,7 @@ WebGLContext::Notify(nsITimer* timer)
|
||||
{
|
||||
TerminateContextLossTimer();
|
||||
|
||||
if (!HTMLCanvasElement()) {
|
||||
if (!mCanvasElement) {
|
||||
// the canvas is gone. That happens when the page was closed before we got
|
||||
// this timer event. In this case, there's nothing to do here, just don't crash.
|
||||
return NS_OK;
|
||||
@ -1076,8 +1067,8 @@ WebGLContext::Notify(nsITimer* timer)
|
||||
// that now.
|
||||
if (mContextStatus == ContextLostAwaitingEvent) {
|
||||
bool defaultAction;
|
||||
nsContentUtils::DispatchTrustedEvent(HTMLCanvasElement()->OwnerDoc(),
|
||||
(nsIDOMHTMLCanvasElement*) HTMLCanvasElement(),
|
||||
nsContentUtils::DispatchTrustedEvent(mCanvasElement->OwnerDoc(),
|
||||
static_cast<nsIDOMHTMLCanvasElement*>(mCanvasElement),
|
||||
NS_LITERAL_STRING("webglcontextlost"),
|
||||
true,
|
||||
true,
|
||||
@ -1105,8 +1096,8 @@ WebGLContext::Notify(nsITimer* timer)
|
||||
return NS_OK;
|
||||
}
|
||||
mContextStatus = ContextStable;
|
||||
nsContentUtils::DispatchTrustedEvent(HTMLCanvasElement()->OwnerDoc(),
|
||||
(nsIDOMHTMLCanvasElement*) HTMLCanvasElement(),
|
||||
nsContentUtils::DispatchTrustedEvent(mCanvasElement->OwnerDoc(),
|
||||
static_cast<nsIDOMHTMLCanvasElement*>(mCanvasElement),
|
||||
NS_LITERAL_STRING("webglcontextrestored"),
|
||||
true,
|
||||
true);
|
||||
@ -1215,7 +1206,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WebGLContext)
|
||||
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_NSCOMPTR_AMBIGUOUS(mCanvasElement, nsINode)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_OF_NSCOMPTR(mEnabledExtensions)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
@ -483,7 +483,7 @@ public:
|
||||
nsIDOMWebGLRenderingContext)
|
||||
|
||||
nsINode* GetParentObject() {
|
||||
return HTMLCanvasElement();
|
||||
return mCanvasElement;
|
||||
}
|
||||
|
||||
virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
|
||||
@ -494,11 +494,6 @@ public:
|
||||
NS_DECL_NSITIMERCALLBACK
|
||||
|
||||
// nsICanvasRenderingContextInternal
|
||||
NS_IMETHOD SetCanvasElement(nsHTMLCanvasElement* aParentCanvas);
|
||||
nsHTMLCanvasElement* HTMLCanvasElement() const {
|
||||
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; }
|
||||
@ -619,7 +614,7 @@ public:
|
||||
|
||||
// WebIDL WebGLRenderingContext API
|
||||
nsHTMLCanvasElement* GetCanvas() const {
|
||||
return HTMLCanvasElement();
|
||||
return mCanvasElement;
|
||||
}
|
||||
WebGLsizei GetDrawingBufferWidth() const {
|
||||
if (!IsContextStable())
|
||||
@ -1107,8 +1102,6 @@ protected:
|
||||
return ((x + y - 1) / y) * y;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLCanvasElement> mCanvasElement;
|
||||
|
||||
nsRefPtr<gl::GLContext> gl;
|
||||
|
||||
CheckedUint32 mGeneration;
|
||||
|
@ -3841,7 +3841,7 @@ WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width,
|
||||
return;
|
||||
}
|
||||
|
||||
if (HTMLCanvasElement()->IsWriteOnly() && !nsContentUtils::IsCallerTrustedForRead()) {
|
||||
if (mCanvasElement->IsWriteOnly() && !nsContentUtils::IsCallerTrustedForRead()) {
|
||||
GenerateWarning("readPixels: Not allowed");
|
||||
return rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
||||
}
|
||||
@ -4343,7 +4343,7 @@ WebGLContext::SurfaceFromElementResultToImageSurface(nsLayoutUtils::SurfaceFromE
|
||||
// validated for cross-domain use.
|
||||
if (!res.mCORSUsed) {
|
||||
bool subsumes;
|
||||
nsresult rv = HTMLCanvasElement()->NodePrincipal()->Subsumes(res.mPrincipal, &subsumes);
|
||||
nsresult rv = mCanvasElement->NodePrincipal()->Subsumes(res.mPrincipal, &subsumes);
|
||||
if (NS_FAILED(rv) || !subsumes) {
|
||||
GenerateWarning("It is forbidden to load a WebGL texture from a cross-domain element that has not been validated with CORS. "
|
||||
"See https://developer.mozilla.org/en/WebGL/Cross-Domain_Textures");
|
||||
|
@ -317,7 +317,6 @@ public:
|
||||
nsresult Redraw();
|
||||
|
||||
// nsICanvasRenderingContextInternal
|
||||
NS_IMETHOD SetCanvasElement(nsHTMLCanvasElement* aParentCanvas);
|
||||
NS_IMETHOD SetDimensions(PRInt32 width, PRInt32 height);
|
||||
void Initialize(nsIDocShell *shell, PRInt32 width, PRInt32 height);
|
||||
NS_IMETHOD InitializeWithSurface(nsIDocShell *shell, gfxASurface *surface, PRInt32 width, PRInt32 height);
|
||||
@ -445,12 +444,6 @@ protected:
|
||||
bool mResetLayer;
|
||||
bool mIPC;
|
||||
|
||||
// the canvas element we're a context of
|
||||
nsCOMPtr<nsIDOMHTMLCanvasElement> mCanvasElement;
|
||||
nsHTMLCanvasElement *HTMLCanvasElement() {
|
||||
return static_cast<nsHTMLCanvasElement*>(mCanvasElement.get());
|
||||
}
|
||||
|
||||
// Initialize the Thebes rendering context
|
||||
void CreateThebes();
|
||||
|
||||
@ -771,7 +764,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCanvasRenderingContext2D)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCanvasElement)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCanvasRenderingContext2D)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCanvasElement)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mCanvasElement, nsINode)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
DOMCI_DATA(CanvasRenderingContext2D, nsCanvasRenderingContext2D)
|
||||
@ -807,7 +800,6 @@ NS_NewCanvasRenderingContext2DThebes(nsIDOMCanvasRenderingContext2D** aResult)
|
||||
nsCanvasRenderingContext2D::nsCanvasRenderingContext2D()
|
||||
: mValid(false), mZero(false), mOpaque(false), mResetLayer(true)
|
||||
, mIPC(false)
|
||||
, mCanvasElement(nsnull)
|
||||
, mSaveCount(0), mIsEntireFrameInvalid(false)
|
||||
, mPredictManyRedrawCalls(false), mHasPath(false), mInvalidateCount(0)
|
||||
, mLastStyle(STYLE_MAX), mStyleStack(20)
|
||||
@ -831,9 +823,9 @@ bool
|
||||
nsCanvasRenderingContext2D::ParseColor(const nsAString& aString,
|
||||
nscolor* aColor)
|
||||
{
|
||||
nsIDocument* document = HTMLCanvasElement()
|
||||
? HTMLCanvasElement()->OwnerDoc()
|
||||
: nsnull;
|
||||
nsIDocument* document = mCanvasElement
|
||||
? mCanvasElement->OwnerDoc()
|
||||
: nsnull;
|
||||
|
||||
// Pass the CSS Loader object to the parser, to allow parser error
|
||||
// reports to include the outer window ID.
|
||||
@ -845,10 +837,10 @@ nsCanvasRenderingContext2D::ParseColor(const nsAString& aString,
|
||||
|
||||
nsIPresShell* presShell = GetPresShell();
|
||||
nsRefPtr<nsStyleContext> parentContext;
|
||||
if (HTMLCanvasElement() && HTMLCanvasElement()->IsInDoc()) {
|
||||
if (mCanvasElement && mCanvasElement->IsInDoc()) {
|
||||
// Inherit from the canvas element.
|
||||
parentContext = nsComputedDOMStyle::GetStyleContextForElement(
|
||||
HTMLCanvasElement(), nsnull, presShell);
|
||||
mCanvasElement, nsnull, presShell);
|
||||
}
|
||||
|
||||
unused << nsRuleNode::ComputeColor(
|
||||
@ -861,7 +853,7 @@ nsresult
|
||||
nsCanvasRenderingContext2D::Reset()
|
||||
{
|
||||
if (mCanvasElement) {
|
||||
HTMLCanvasElement()->InvalidateCanvas();
|
||||
mCanvasElement->InvalidateCanvas();
|
||||
}
|
||||
|
||||
// only do this for non-docshell created contexts,
|
||||
@ -913,7 +905,7 @@ nsCanvasRenderingContext2D::SetStyleFromStringOrInterface(const nsAString& aStr,
|
||||
nsContentUtils::ReportToConsole(
|
||||
nsIScriptError::warningFlag,
|
||||
"Canvas",
|
||||
mCanvasElement ? HTMLCanvasElement()->OwnerDoc() : nsnull,
|
||||
mCanvasElement ? mCanvasElement->OwnerDoc() : nsnull,
|
||||
nsContentUtils::eDOM_PROPERTIES,
|
||||
"UnexpectedCanvasVariantStyle");
|
||||
|
||||
@ -997,7 +989,7 @@ nsCanvasRenderingContext2D::ApplyStyle(Style aWhichStyle,
|
||||
nsCanvasPattern* pattern = CurrentState().patternStyles[aWhichStyle];
|
||||
if (pattern) {
|
||||
if (mCanvasElement)
|
||||
CanvasUtils::DoDrawImageSecurityCheck(HTMLCanvasElement(),
|
||||
CanvasUtils::DoDrawImageSecurityCheck(mCanvasElement,
|
||||
pattern->Principal(),
|
||||
pattern->GetForceWriteOnly(),
|
||||
pattern->GetCORSUsed());
|
||||
@ -1038,9 +1030,9 @@ nsCanvasRenderingContext2D::Redraw()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsSVGEffects::InvalidateDirectRenderingObservers(HTMLCanvasElement());
|
||||
nsSVGEffects::InvalidateDirectRenderingObservers(mCanvasElement);
|
||||
|
||||
HTMLCanvasElement()->InvalidateCanvasContent(nsnull);
|
||||
mCanvasElement->InvalidateCanvasContent(nsnull);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1063,9 +1055,9 @@ nsCanvasRenderingContext2D::Redraw(const gfxRect& r)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsSVGEffects::InvalidateDirectRenderingObservers(HTMLCanvasElement());
|
||||
nsSVGEffects::InvalidateDirectRenderingObservers(mCanvasElement);
|
||||
|
||||
HTMLCanvasElement()->InvalidateCanvasContent(&r);
|
||||
mCanvasElement->InvalidateCanvasContent(&r);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1377,14 +1369,6 @@ nsCanvasRenderingContext2D::GetImageFormat() const
|
||||
// nsCanvasRenderingContext2D impl
|
||||
//
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::SetCanvasElement(nsHTMLCanvasElement* aCanvasElement)
|
||||
{
|
||||
mCanvasElement = aCanvasElement;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2D::GetCanvas(nsIDOMHTMLCanvasElement **canvas)
|
||||
{
|
||||
@ -2472,9 +2456,8 @@ nsCanvasRenderingContext2D::SetFont(const nsAString& font)
|
||||
* string is equal to the old one.
|
||||
*/
|
||||
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(mCanvasElement);
|
||||
if (!content && !mDocShell) {
|
||||
NS_WARNING("Canvas element must be an nsIContent and non-null or a docshell must be provided");
|
||||
if (!mCanvasElement && !mDocShell) {
|
||||
NS_WARNING("Canvas element must be non-null or a docshell must be provided");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -2514,10 +2497,10 @@ nsCanvasRenderingContext2D::SetFont(const nsAString& font)
|
||||
// values (2em, bolder, etc.)
|
||||
nsRefPtr<nsStyleContext> parentContext;
|
||||
|
||||
if (content && content->IsInDoc()) {
|
||||
if (mCanvasElement && mCanvasElement->IsInDoc()) {
|
||||
// inherit from the canvas element
|
||||
parentContext = nsComputedDOMStyle::GetStyleContextForElement(
|
||||
content->AsElement(),
|
||||
mCanvasElement,
|
||||
nsnull,
|
||||
presShell);
|
||||
} else {
|
||||
@ -2852,9 +2835,8 @@ nsCanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText,
|
||||
if (aMaxWidth < 0)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(mCanvasElement);
|
||||
if (!content && !mDocShell) {
|
||||
NS_WARNING("Canvas element must be an nsIContent and non-null or a docshell must be provided");
|
||||
if (!mCanvasElement && !mDocShell) {
|
||||
NS_WARNING("Canvas element must be non-null or a docshell must be provided");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -2871,10 +2853,10 @@ nsCanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText,
|
||||
// for now, default to ltr if not in doc
|
||||
bool isRTL = false;
|
||||
|
||||
if (content && content->IsInDoc()) {
|
||||
if (mCanvasElement && mCanvasElement->IsInDoc()) {
|
||||
// try to find the closest context
|
||||
nsRefPtr<nsStyleContext> canvasStyle =
|
||||
nsComputedDOMStyle::GetStyleContextForElement(content->AsElement(),
|
||||
nsComputedDOMStyle::GetStyleContextForElement(mCanvasElement,
|
||||
nsnull,
|
||||
presShell);
|
||||
if (!canvasStyle)
|
||||
@ -3397,7 +3379,7 @@ nsCanvasRenderingContext2D::DrawImage(nsIDOMElement *imgElt, float a1,
|
||||
nsRefPtr<gfxPattern> pattern;
|
||||
gfxIntSize imgSize;
|
||||
nsRefPtr<gfxASurface> imgsurf =
|
||||
CanvasImageCache::Lookup(imgElt, HTMLCanvasElement(), &imgSize);
|
||||
CanvasImageCache::Lookup(imgElt, mCanvasElement, &imgSize);
|
||||
|
||||
if (!imgsurf) {
|
||||
// The canvas spec says that drawImage should draw the first frame
|
||||
@ -3424,14 +3406,14 @@ nsCanvasRenderingContext2D::DrawImage(nsIDOMElement *imgElt, float a1,
|
||||
imgSize = res.mSize;
|
||||
|
||||
if (mCanvasElement) {
|
||||
CanvasUtils::DoDrawImageSecurityCheck(HTMLCanvasElement(),
|
||||
CanvasUtils::DoDrawImageSecurityCheck(mCanvasElement,
|
||||
res.mPrincipal,
|
||||
res.mIsWriteOnly,
|
||||
res.mCORSUsed);
|
||||
}
|
||||
|
||||
if (res.mImageRequest) {
|
||||
CanvasImageCache::NotifyDrawImage(imgElt, HTMLCanvasElement(),
|
||||
CanvasImageCache::NotifyDrawImage(imgElt, mCanvasElement,
|
||||
res.mImageRequest, imgsurf, imgSize);
|
||||
}
|
||||
}
|
||||
@ -3834,8 +3816,7 @@ nsCanvasRenderingContext2D::GetImageData(double aSx, double aSy,
|
||||
|
||||
// Check only if we have a canvas element; if we were created with a docshell,
|
||||
// then it's special internal use.
|
||||
if (mCanvasElement &&
|
||||
HTMLCanvasElement()->IsWriteOnly() &&
|
||||
if (mCanvasElement && mCanvasElement->IsWriteOnly() &&
|
||||
!nsContentUtils::IsCallerTrustedForRead()) {
|
||||
// XXX ERRMSG we need to report an error to developers here! (bug 329026)
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
@ -4217,7 +4198,7 @@ nsCanvasRenderingContext2D::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
||||
// releasing the reference to the element.
|
||||
// The userData will receive DidTransactionCallbacks, which flush the
|
||||
// the invalidation state to indicate that the canvas is up to date.
|
||||
userData = new CanvasRenderingContext2DUserData(HTMLCanvasElement());
|
||||
userData = new CanvasRenderingContext2DUserData(mCanvasElement);
|
||||
canvasLayer->SetDidTransactionCallback(
|
||||
CanvasRenderingContext2DUserData::DidTransactionCallback, userData);
|
||||
}
|
||||
|
@ -373,7 +373,6 @@ public:
|
||||
nsresult Redraw();
|
||||
|
||||
// nsICanvasRenderingContextInternal
|
||||
NS_IMETHOD SetCanvasElement(nsHTMLCanvasElement* aParentCanvas);
|
||||
NS_IMETHOD SetDimensions(PRInt32 width, PRInt32 height);
|
||||
NS_IMETHOD InitializeWithSurface(nsIDocShell *shell, gfxASurface *surface, PRInt32 width, PRInt32 height)
|
||||
{ return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
@ -482,10 +481,6 @@ protected:
|
||||
*/
|
||||
SurfaceFormat GetSurfaceFormat() const;
|
||||
|
||||
nsHTMLCanvasElement *HTMLCanvasElement() {
|
||||
return static_cast<nsHTMLCanvasElement*>(mCanvasElement.get());
|
||||
}
|
||||
|
||||
// Member vars
|
||||
PRInt32 mWidth, mHeight;
|
||||
|
||||
@ -505,9 +500,6 @@ protected:
|
||||
// This is needed for drawing in drawAsyncXULElement
|
||||
bool mIPC;
|
||||
|
||||
// the canvas element we're a context of
|
||||
nsCOMPtr<nsIDOMHTMLCanvasElement> mCanvasElement;
|
||||
|
||||
// If mCanvasElement is not provided, then a docshell is
|
||||
nsCOMPtr<nsIDocShell> mDocShell;
|
||||
|
||||
@ -784,7 +776,7 @@ protected:
|
||||
gradient->mRadius2, gradient->GetGradientStopsForTarget(aRT));
|
||||
} else if (state.patternStyles[aStyle]) {
|
||||
if (aCtx->mCanvasElement) {
|
||||
CanvasUtils::DoDrawImageSecurityCheck(aCtx->HTMLCanvasElement(),
|
||||
CanvasUtils::DoDrawImageSecurityCheck(aCtx->mCanvasElement,
|
||||
state.patternStyles[aStyle]->mPrincipal,
|
||||
state.patternStyles[aStyle]->mForceWriteOnly,
|
||||
state.patternStyles[aStyle]->mCORSUsed);
|
||||
@ -948,7 +940,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCanvasRenderingContext2DAzure)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCanvasElement)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCanvasRenderingContext2DAzure)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCanvasElement)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mCanvasElement, nsINode)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
// XXX
|
||||
@ -996,7 +988,6 @@ NS_NewCanvasRenderingContext2DAzure(nsIDOMCanvasRenderingContext2D** aResult)
|
||||
nsCanvasRenderingContext2DAzure::nsCanvasRenderingContext2DAzure()
|
||||
: mValid(false), mZero(false), mOpaque(false), mResetLayer(true)
|
||||
, mIPC(false)
|
||||
, mCanvasElement(nsnull)
|
||||
, mIsEntireFrameInvalid(false)
|
||||
, mPredictManyRedrawCalls(false), mPathTransformWillUpdate(false)
|
||||
, mInvalidateCount(0)
|
||||
@ -1020,9 +1011,9 @@ bool
|
||||
nsCanvasRenderingContext2DAzure::ParseColor(const nsAString& aString,
|
||||
nscolor* aColor)
|
||||
{
|
||||
nsIDocument* document = HTMLCanvasElement()
|
||||
? HTMLCanvasElement()->OwnerDoc()
|
||||
: nsnull;
|
||||
nsIDocument* document = mCanvasElement
|
||||
? mCanvasElement->OwnerDoc()
|
||||
: nsnull;
|
||||
|
||||
// Pass the CSS Loader object to the parser, to allow parser error
|
||||
// reports to include the outer window ID.
|
||||
@ -1034,10 +1025,10 @@ nsCanvasRenderingContext2DAzure::ParseColor(const nsAString& aString,
|
||||
|
||||
nsIPresShell* presShell = GetPresShell();
|
||||
nsRefPtr<nsStyleContext> parentContext;
|
||||
if (HTMLCanvasElement() && HTMLCanvasElement()->IsInDoc()) {
|
||||
if (mCanvasElement && mCanvasElement->IsInDoc()) {
|
||||
// Inherit from the canvas element.
|
||||
parentContext = nsComputedDOMStyle::GetStyleContextForElement(
|
||||
HTMLCanvasElement(), nsnull, presShell);
|
||||
mCanvasElement, nsnull, presShell);
|
||||
}
|
||||
|
||||
unused << nsRuleNode::ComputeColor(
|
||||
@ -1050,7 +1041,7 @@ nsresult
|
||||
nsCanvasRenderingContext2DAzure::Reset()
|
||||
{
|
||||
if (mCanvasElement) {
|
||||
HTMLCanvasElement()->InvalidateCanvas();
|
||||
mCanvasElement->InvalidateCanvas();
|
||||
}
|
||||
|
||||
// only do this for non-docshell created contexts,
|
||||
@ -1103,7 +1094,7 @@ nsCanvasRenderingContext2DAzure::SetStyleFromStringOrInterface(const nsAString&
|
||||
nsContentUtils::ReportToConsole(
|
||||
nsIScriptError::warningFlag,
|
||||
"Canvas",
|
||||
mCanvasElement ? HTMLCanvasElement()->OwnerDoc() : nsnull,
|
||||
mCanvasElement ? mCanvasElement->OwnerDoc() : nsnull,
|
||||
nsContentUtils::eDOM_PROPERTIES,
|
||||
"UnexpectedCanvasVariantStyle");
|
||||
|
||||
@ -1176,9 +1167,9 @@ nsCanvasRenderingContext2DAzure::Redraw()
|
||||
gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(mTarget);
|
||||
mThebesSurface->MarkDirty();
|
||||
|
||||
nsSVGEffects::InvalidateDirectRenderingObservers(HTMLCanvasElement());
|
||||
nsSVGEffects::InvalidateDirectRenderingObservers(mCanvasElement);
|
||||
|
||||
HTMLCanvasElement()->InvalidateCanvasContent(nsnull);
|
||||
mCanvasElement->InvalidateCanvasContent(nsnull);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1208,10 +1199,10 @@ nsCanvasRenderingContext2DAzure::Redraw(const mgfx::Rect &r)
|
||||
gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(mTarget);
|
||||
mThebesSurface->MarkDirty();
|
||||
|
||||
nsSVGEffects::InvalidateDirectRenderingObservers(HTMLCanvasElement());
|
||||
nsSVGEffects::InvalidateDirectRenderingObservers(mCanvasElement);
|
||||
|
||||
gfxRect tmpR = ThebesRect(r);
|
||||
HTMLCanvasElement()->InvalidateCanvasContent(&tmpR);
|
||||
mCanvasElement->InvalidateCanvasContent(&tmpR);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -1497,14 +1488,6 @@ nsCanvasRenderingContext2DAzure::GetSurfaceFormat() const
|
||||
// nsCanvasRenderingContext2DAzure impl
|
||||
//
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2DAzure::SetCanvasElement(nsHTMLCanvasElement* aCanvasElement)
|
||||
{
|
||||
mCanvasElement = aCanvasElement;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCanvasRenderingContext2DAzure::GetCanvas(nsIDOMHTMLCanvasElement **canvas)
|
||||
{
|
||||
@ -2680,9 +2663,8 @@ nsCanvasRenderingContext2DAzure::SetFont(const nsAString& font)
|
||||
* string is equal to the old one.
|
||||
*/
|
||||
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(mCanvasElement);
|
||||
if (!content && !mDocShell) {
|
||||
NS_WARNING("Canvas element must be an nsIContent and non-null or a docshell must be provided");
|
||||
if (!mCanvasElement && !mDocShell) {
|
||||
NS_WARNING("Canvas element must be non-null or a docshell must be provided");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -2725,10 +2707,10 @@ nsCanvasRenderingContext2DAzure::SetFont(const nsAString& font)
|
||||
// values (2em, bolder, etc.)
|
||||
nsRefPtr<nsStyleContext> parentContext;
|
||||
|
||||
if (content && content->IsInDoc()) {
|
||||
if (mCanvasElement && mCanvasElement->IsInDoc()) {
|
||||
// inherit from the canvas element
|
||||
parentContext = nsComputedDOMStyle::GetStyleContextForElement(
|
||||
content->AsElement(),
|
||||
mCanvasElement,
|
||||
nsnull,
|
||||
presShell);
|
||||
} else {
|
||||
@ -3168,9 +3150,8 @@ nsCanvasRenderingContext2DAzure::DrawOrMeasureText(const nsAString& aRawText,
|
||||
if (aMaxWidth < 0)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(mCanvasElement);
|
||||
if (!content && !mDocShell) {
|
||||
NS_WARNING("Canvas element must be an nsIContent and non-null or a docshell must be provided");
|
||||
if (!mCanvasElement && !mDocShell) {
|
||||
NS_WARNING("Canvas element must be non-null or a docshell must be provided");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -3187,10 +3168,10 @@ nsCanvasRenderingContext2DAzure::DrawOrMeasureText(const nsAString& aRawText,
|
||||
// for now, default to ltr if not in doc
|
||||
bool isRTL = false;
|
||||
|
||||
if (content && content->IsInDoc()) {
|
||||
if (mCanvasElement && mCanvasElement->IsInDoc()) {
|
||||
// try to find the closest context
|
||||
nsRefPtr<nsStyleContext> canvasStyle =
|
||||
nsComputedDOMStyle::GetStyleContextForElement(content->AsElement(),
|
||||
nsComputedDOMStyle::GetStyleContextForElement(mCanvasElement,
|
||||
nsnull,
|
||||
presShell);
|
||||
if (!canvasStyle) {
|
||||
@ -3629,7 +3610,7 @@ nsCanvasRenderingContext2DAzure::DrawImage(nsIDOMElement *imgElt, float a1,
|
||||
|
||||
if (srcSurf && mCanvasElement) {
|
||||
// Do security check here.
|
||||
CanvasUtils::DoDrawImageSecurityCheck(HTMLCanvasElement(),
|
||||
CanvasUtils::DoDrawImageSecurityCheck(mCanvasElement,
|
||||
content->NodePrincipal(), canvas->IsWriteOnly(),
|
||||
false);
|
||||
imgSize = gfxIntSize(srcSurf->GetSize().width, srcSurf->GetSize().height);
|
||||
@ -3637,7 +3618,7 @@ nsCanvasRenderingContext2DAzure::DrawImage(nsIDOMElement *imgElt, float a1,
|
||||
}
|
||||
} else {
|
||||
gfxASurface* imgsurf =
|
||||
CanvasImageCache::Lookup(imgElt, HTMLCanvasElement(), &imgSize);
|
||||
CanvasImageCache::Lookup(imgElt, mCanvasElement, &imgSize);
|
||||
if (imgsurf) {
|
||||
srcSurf = gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(mTarget, imgsurf);
|
||||
}
|
||||
@ -3663,13 +3644,13 @@ nsCanvasRenderingContext2DAzure::DrawImage(nsIDOMElement *imgElt, float a1,
|
||||
imgSize = res.mSize;
|
||||
|
||||
if (mCanvasElement) {
|
||||
CanvasUtils::DoDrawImageSecurityCheck(HTMLCanvasElement(),
|
||||
CanvasUtils::DoDrawImageSecurityCheck(mCanvasElement,
|
||||
res.mPrincipal, res.mIsWriteOnly,
|
||||
res.mCORSUsed);
|
||||
}
|
||||
|
||||
if (res.mImageRequest) {
|
||||
CanvasImageCache::NotifyDrawImage(imgElt, HTMLCanvasElement(),
|
||||
CanvasImageCache::NotifyDrawImage(imgElt, mCanvasElement,
|
||||
res.mImageRequest, res.mSurface, imgSize);
|
||||
}
|
||||
|
||||
@ -4009,8 +3990,7 @@ nsCanvasRenderingContext2DAzure::GetImageData(double aSx, double aSy,
|
||||
|
||||
// Check only if we have a canvas element; if we were created with a docshell,
|
||||
// then it's special internal use.
|
||||
if (mCanvasElement &&
|
||||
HTMLCanvasElement()->IsWriteOnly() &&
|
||||
if (mCanvasElement && mCanvasElement->IsWriteOnly() &&
|
||||
!nsContentUtils::IsCallerTrustedForRead())
|
||||
{
|
||||
// XXX ERRMSG we need to report an error to developers here! (bug 329026)
|
||||
@ -4407,7 +4387,7 @@ nsCanvasRenderingContext2DAzure::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
||||
// releasing the reference to the element.
|
||||
// The userData will receive DidTransactionCallbacks, which flush the
|
||||
// the invalidation state to indicate that the canvas is up to date.
|
||||
userData = new CanvasRenderingContext2DUserData(HTMLCanvasElement());
|
||||
userData = new CanvasRenderingContext2DUserData(mCanvasElement);
|
||||
canvasLayer->SetDidTransactionCallback(
|
||||
CanvasRenderingContext2DUserData::DidTransactionCallback, userData);
|
||||
}
|
||||
|
@ -16,14 +16,14 @@
|
||||
#include "nsDOMError.h"
|
||||
#include "nsNodeInfoManager.h"
|
||||
|
||||
#include "nsICanvasRenderingContextInternal.h"
|
||||
#include "nsICanvasElementExternal.h"
|
||||
#include "nsIDOMCanvasRenderingContext2D.h"
|
||||
#include "nsLayoutUtils.h"
|
||||
|
||||
#include "Layers.h"
|
||||
|
||||
class nsICanvasRenderingContextInternal;
|
||||
class nsIDOMFile;
|
||||
class nsIPropertyBag;
|
||||
|
||||
class nsHTMLCanvasElement : public nsGenericHTMLElement,
|
||||
public nsICanvasElementExternal,
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include "prmem.h"
|
||||
#include "nsDOMFile.h"
|
||||
|
||||
#include "nsICanvasRenderingContextInternal.h"
|
||||
#include "nsIDOMCanvasRenderingContext2D.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "jsapi.h"
|
||||
@ -453,15 +455,9 @@ nsHTMLCanvasElement::GetContextHelper(const nsAString& aContextId,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
rv = ctx->SetCanvasElement(this);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aContext = nsnull;
|
||||
return rv;
|
||||
}
|
||||
|
||||
ctx->SetCanvasElement(this);
|
||||
ctx.forget(aContext);
|
||||
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
Loading…
Reference in New Issue
Block a user