1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11 #include "nsIServiceManager.h"
13 #include "nsIConsoleService.h"
14 #include "nsIDOMCanvasRenderingContext2D.h"
15 #include "nsICanvasRenderingContextInternal.h"
16 #include "nsIHTMLCollection.h"
17 #include "mozilla/dom/HTMLCanvasElement.h"
18 #include "nsIPrincipal.h"
20 #include "nsGfxCIID.h"
24 #include "CanvasUtils.h"
25 #include "mozilla/gfx/Matrix.h"
27 using namespace mozilla::gfx
;
30 namespace CanvasUtils
{
33 DoDrawImageSecurityCheck(dom::HTMLCanvasElement
*aCanvasElement
,
34 nsIPrincipal
*aPrincipal
,
38 NS_PRECONDITION(aPrincipal
, "Must have a principal here");
40 // Callers should ensure that mCanvasElement is non-null before calling this
41 if (!aCanvasElement
) {
42 NS_WARNING("DoDrawImageSecurityCheck called without canvas element!");
46 if (aCanvasElement
->IsWriteOnly())
49 // If we explicitly set WriteOnly just do it and get out
51 aCanvasElement
->SetWriteOnly();
55 // No need to do a security check if the image used CORS for the load
59 if (aCanvasElement
->NodePrincipal()->Subsumes(aPrincipal
)) {
60 // This canvas has access to that image anyway
64 aCanvasElement
->SetWriteOnly();
68 CoerceDouble(JS::Value v
, double* d
)
72 } else if (v
.isInt32()) {
73 *d
= double(v
.toInt32());
74 } else if (v
.isUndefined()) {
82 } // namespace CanvasUtils
83 } // namespace mozilla