Bug 1316661 part 1. Eliminate IsCallerChrome callers in HTMLCanvasElement code. r=smaug

This commit is contained in:
Boris Zbarsky 2016-11-15 00:18:32 -05:00
Родитель 6f654ebcfb
Коммит 4f1a0ffdd3
4 изменённых файлов: 59 добавлений и 80 удалений

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

@ -624,18 +624,21 @@ HTMLCanvasElement::ParseAttribute(int32_t aNamespaceID,
}
// HTMLCanvasElement::toDataURL
NS_IMETHODIMP
HTMLCanvasElement::ToDataURL(const nsAString& aType, JS::Handle<JS::Value> aParams,
JSContext* aCx, nsAString& aDataURL)
void
HTMLCanvasElement::ToDataURL(JSContext* aCx, const nsAString& aType,
JS::Handle<JS::Value> aParams,
nsAString& aDataURL,
CallerType aCallerType,
ErrorResult& aRv)
{
// do a trust check if this is a write-only canvas
if (mWriteOnly && !nsContentUtils::IsCallerChrome()) {
return NS_ERROR_DOM_SECURITY_ERR;
if (mWriteOnly && aCallerType != CallerType::System) {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return;
}
return ToDataURLImpl(aCx, aType, aParams, aDataURL);
aRv = ToDataURLImpl(aCx, aType, aParams, aDataURL);
}
void
@ -809,10 +812,11 @@ HTMLCanvasElement::ToBlob(JSContext* aCx,
BlobCallback& aCallback,
const nsAString& aType,
JS::Handle<JS::Value> aParams,
CallerType aCallerType,
ErrorResult& aRv)
{
// do a trust check if this is a write-only canvas
if (mWriteOnly && !nsContentUtils::IsCallerChrome()) {
if (mWriteOnly && aCallerType != CallerType::System) {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return;
}
@ -863,40 +867,30 @@ HTMLCanvasElement::TransferControlToOffscreen(ErrorResult& aRv)
already_AddRefed<File>
HTMLCanvasElement::MozGetAsFile(const nsAString& aName,
const nsAString& aType,
CallerType aCallerType,
ErrorResult& aRv)
{
nsCOMPtr<nsISupports> file;
aRv = MozGetAsFile(aName, aType, getter_AddRefs(file));
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(file);
RefPtr<Blob> domBlob = static_cast<Blob*>(blob.get());
MOZ_ASSERT(domBlob->IsFile());
return domBlob->ToFile();
}
NS_IMETHODIMP
HTMLCanvasElement::MozGetAsFile(const nsAString& aName,
const nsAString& aType,
nsISupports** aResult)
{
OwnerDoc()->WarnOnceAbout(nsIDocument::eMozGetAsFile);
// do a trust check if this is a write-only canvas
if ((mWriteOnly) &&
!nsContentUtils::IsCallerChrome()) {
return NS_ERROR_DOM_SECURITY_ERR;
if (mWriteOnly && aCallerType != CallerType::System) {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return nullptr;
}
return MozGetAsBlobImpl(aName, aType, aResult);
RefPtr<File> file;
aRv = MozGetAsFileImpl(aName, aType, getter_AddRefs(file));
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
return file.forget();
}
nsresult
HTMLCanvasElement::MozGetAsBlobImpl(const nsAString& aName,
HTMLCanvasElement::MozGetAsFileImpl(const nsAString& aName,
const nsAString& aType,
nsISupports** aResult)
File** aResult)
{
nsCOMPtr<nsIInputStream> stream;
nsAutoString type(aType);
@ -920,7 +914,7 @@ HTMLCanvasElement::MozGetAsBlobImpl(const nsAString& aName,
nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(OwnerDoc()->GetScopeObject());
// The File takes ownership of the buffer
nsCOMPtr<nsIDOMBlob> file =
RefPtr<File> file =
File::CreateMemoryFile(win, imgData, (uint32_t)imgSize, aName, type,
PR_Now());
@ -952,18 +946,18 @@ HTMLCanvasElement::GetContext(JSContext* aCx,
aRv);
}
NS_IMETHODIMP
already_AddRefed<nsISupports>
HTMLCanvasElement::MozGetIPCContext(const nsAString& aContextId,
nsISupports **aContext)
ErrorResult& aRv)
{
if(!nsContentUtils::IsCallerChrome()) {
// XXX ERRMSG we need to report an error to developers here! (bug 329026)
return NS_ERROR_DOM_SECURITY_ERR;
}
// Note that we're a [ChromeOnly] method, so from JS we can only be called by
// system code.
// We only support 2d shmem contexts for now.
if (!aContextId.EqualsLiteral("2d"))
return NS_ERROR_INVALID_ARG;
if (!aContextId.EqualsLiteral("2d")) {
aRv.Throw(NS_ERROR_INVALID_ARG);
return nullptr;
}
CanvasContextType contextType = CanvasContextType::Canvas2D;
@ -973,8 +967,7 @@ HTMLCanvasElement::MozGetIPCContext(const nsAString& aContextId,
RefPtr<nsICanvasRenderingContextInternal> context;
context = CreateContext(contextType);
if (!context) {
*aContext = nullptr;
return NS_OK;
return nullptr;
}
mCurrentContext = context;
@ -983,15 +976,20 @@ HTMLCanvasElement::MozGetIPCContext(const nsAString& aContextId,
ErrorResult dummy;
nsresult rv = UpdateContext(nullptr, JS::NullHandleValue, dummy);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(rv);
return nullptr;
}
} else {
// We already have a context of some type.
if (contextType != mCurrentContextType)
return NS_ERROR_INVALID_ARG;
if (contextType != mCurrentContextType) {
aRv.Throw(NS_ERROR_INVALID_ARG);
return nullptr;
}
}
NS_ADDREF (*aContext = mCurrentContext);
return NS_OK;
nsCOMPtr<nsISupports> context(mCurrentContext);
return context.forget();
}

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

@ -16,6 +16,7 @@
#include "nsSize.h"
#include "nsError.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/CanvasRenderingContextHelper.h"
#include "mozilla/gfx/Rect.h"
#include "mozilla/layers/LayersTypes.h"
@ -176,15 +177,14 @@ public:
void ToDataURL(JSContext* aCx, const nsAString& aType,
JS::Handle<JS::Value> aParams,
nsAString& aDataURL, ErrorResult& aRv)
{
aRv = ToDataURL(aType, aParams, aCx, aDataURL);
}
nsAString& aDataURL, CallerType aCallerType,
ErrorResult& aRv);
void ToBlob(JSContext* aCx,
BlobCallback& aCallback,
const nsAString& aType,
JS::Handle<JS::Value> aParams,
CallerType aCallerType,
ErrorResult& aRv);
OffscreenCanvas* TransferControlToOffscreen(ErrorResult& aRv);
@ -204,14 +204,10 @@ public:
}
already_AddRefed<File> MozGetAsFile(const nsAString& aName,
const nsAString& aType,
CallerType aCallerType,
ErrorResult& aRv);
already_AddRefed<nsISupports> MozGetIPCContext(const nsAString& aContextId,
ErrorResult& aRv)
{
nsCOMPtr<nsISupports> context;
aRv = MozGetIPCContext(aContextId, getter_AddRefs(context));
return context.forget();
}
ErrorResult& aRv);
PrintCallback* GetMozPrintCallback() const;
void SetMozPrintCallback(PrintCallback* aCallback);
@ -371,9 +367,9 @@ protected:
const nsAString& aMimeType,
const JS::Value& aEncoderOptions,
nsAString& aDataURL);
nsresult MozGetAsBlobImpl(const nsAString& aName,
nsresult MozGetAsFileImpl(const nsAString& aName,
const nsAString& aType,
nsISupports** aResult);
File** aResult);
void CallPrintCallback();
AsyncCanvasRenderer* GetAsyncCanvasRenderer();

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

@ -25,23 +25,5 @@ interface nsIDOMHTMLCanvasElement : nsISupports
attribute unsigned long width;
attribute unsigned long height;
attribute boolean mozOpaque;
// Valid calls are:
// toDataURL(); -- defaults to image/png
// toDataURL(type); -- uses given type
// toDataURL(type, params); -- uses given type, and any valid parameters
[implicit_jscontext]
DOMString toDataURL([optional] in DOMString type,
[optional] in jsval params);
// Valid calls are
// mozGetAsFile(name); -- defaults to image/png
// mozGetAsFile(name, type); -- uses given type
// The return value is a File object.
nsISupports mozGetAsFile(in DOMString name, [optional] in DOMString type);
// A Mozilla-only extension to get a canvas context backed by double-buffered
// shared memory. Only privileged callers can call this.
nsISupports MozGetIPCContext(in DOMString contextId);
};

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

@ -22,10 +22,10 @@ interface HTMLCanvasElement : HTMLElement {
[Throws]
nsISupports? getContext(DOMString contextId, optional any contextOptions = null);
[Throws]
[Throws, NeedsCallerType]
DOMString toDataURL(optional DOMString type = "",
optional any encoderOptions);
[Throws]
[Throws, NeedsCallerType]
void toBlob(BlobCallback _callback,
optional DOMString type = "",
optional any encoderOptions);
@ -35,10 +35,13 @@ interface HTMLCanvasElement : HTMLElement {
partial interface HTMLCanvasElement {
[Pure, SetterThrows]
attribute boolean mozOpaque;
[Throws]
[Throws, NeedsCallerType]
File mozGetAsFile(DOMString name, optional DOMString? type = null);
// A Mozilla-only extension to get a canvas context backed by double-buffered
// shared memory. Only privileged callers can call this.
[ChromeOnly, Throws]
nsISupports? MozGetIPCContext(DOMString contextId);
attribute PrintCallback? mozPrintCallback;
[Throws, UnsafeInPrerendering, Pref="canvas.capturestream.enabled"]