mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-23 23:57:31 +09:00
Improve origin-clean algorithm
This commit is contained in:
parent
21eef2bff9
commit
85e68b684f
5 changed files with 41 additions and 39 deletions
|
|
@ -2406,7 +2406,11 @@ CanvasRenderingContext2D::SetStyleFromUnion(const StringOrCanvasGradientOrCanvas
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aValue.IsCanvasPattern()) {
|
if (aValue.IsCanvasPattern()) {
|
||||||
SetStyleFromPattern(aValue.GetAsCanvasPattern(), aWhichStyle);
|
CanvasPattern& pattern = aValue.GetAsCanvasPattern();
|
||||||
|
SetStyleFromPattern(pattern, aWhichStyle);
|
||||||
|
if (pattern.mForceWriteOnly) {
|
||||||
|
SetWriteOnly();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2581,11 +2585,12 @@ CanvasRenderingContext2D::CreatePattern(const CanvasImageSource& aSource,
|
||||||
nsLayoutUtils::SurfaceFromElement(element,
|
nsLayoutUtils::SurfaceFromElement(element,
|
||||||
nsLayoutUtils::SFE_WANT_FIRST_FRAME, mTarget);
|
nsLayoutUtils::SFE_WANT_FIRST_FRAME, mTarget);
|
||||||
|
|
||||||
if (!res.GetSourceSurface()) {
|
RefPtr<SourceSurface> surface = res.GetSourceSurface();
|
||||||
|
if (!surface) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<CanvasPattern> pat = new CanvasPattern(this, res.GetSourceSurface(), repeatMode,
|
RefPtr<CanvasPattern> pat = new CanvasPattern(this, surface, repeatMode,
|
||||||
res.mPrincipal, res.mIsWriteOnly,
|
res.mPrincipal, res.mIsWriteOnly,
|
||||||
res.mCORSUsed);
|
res.mCORSUsed);
|
||||||
return pat.forget();
|
return pat.forget();
|
||||||
|
|
@ -4895,8 +4900,8 @@ CanvasRenderingContext2D::CachedSurfaceFromElement(Element* aElement)
|
||||||
|
|
||||||
res.mSize = res.mSourceSurface->GetSize();
|
res.mSize = res.mSourceSurface->GetSize();
|
||||||
res.mPrincipal = principal.forget();
|
res.mPrincipal = principal.forget();
|
||||||
res.mIsWriteOnly = false;
|
|
||||||
res.mImageRequest = imgRequest.forget();
|
res.mImageRequest = imgRequest.forget();
|
||||||
|
res.mIsWriteOnly = CheckWriteOnlySecurity(res.mCORSUsed, res.mPrincipal);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,5 +126,25 @@ CoerceDouble(const JS::Value& v, double* d)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CheckWriteOnlySecurity(bool aCORSUsed, nsIPrincipal* aPrincipal) {
|
||||||
|
if (!aPrincipal) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!aCORSUsed) {
|
||||||
|
nsIGlobalObject* incumbentSettingsObject = dom::GetIncumbentGlobal();
|
||||||
|
if (NS_WARN_IF(!incumbentSettingsObject)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIPrincipal* principal = incumbentSettingsObject->PrincipalOrNull();
|
||||||
|
if (NS_WARN_IF(!principal) || !(principal->Subsumes(aPrincipal))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CanvasUtils
|
} // namespace CanvasUtils
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include "mozilla/dom/ToJSValue.h"
|
#include "mozilla/dom/ToJSValue.h"
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
#include "mozilla/FloatingPoint.h"
|
#include "mozilla/FloatingPoint.h"
|
||||||
|
#include "nsLayoutUtils.h"
|
||||||
|
|
||||||
class nsIPrincipal;
|
class nsIPrincipal;
|
||||||
|
|
||||||
|
|
@ -156,6 +157,10 @@ DashArrayToJSVal(nsTArray<T>& dashes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns true if write-only mode must used for this principal based on
|
||||||
|
// the incumbent global.
|
||||||
|
bool CheckWriteOnlySecurity(bool aCORSUsed, nsIPrincipal* aPrincipal);
|
||||||
|
|
||||||
} // namespace CanvasUtils
|
} // namespace CanvasUtils
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -315,36 +315,6 @@ private:
|
||||||
const Maybe<IntRect>& mCropRect;
|
const Maybe<IntRect>& mCropRect;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool
|
|
||||||
CheckSecurityForHTMLElements(bool aIsWriteOnly, bool aCORSUsed, nsIPrincipal* aPrincipal)
|
|
||||||
{
|
|
||||||
MOZ_ASSERT(aPrincipal);
|
|
||||||
|
|
||||||
if (aIsWriteOnly) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!aCORSUsed) {
|
|
||||||
nsIGlobalObject* incumbentSettingsObject = GetIncumbentGlobal();
|
|
||||||
if (NS_WARN_IF(!incumbentSettingsObject)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsIPrincipal* principal = incumbentSettingsObject->PrincipalOrNull();
|
|
||||||
if (NS_WARN_IF(!principal) || !(principal->Subsumes(aPrincipal))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
CheckSecurityForHTMLElements(const nsLayoutUtils::SurfaceFromElementResult& aRes)
|
|
||||||
{
|
|
||||||
return CheckSecurityForHTMLElements(aRes.mIsWriteOnly, aRes.mCORSUsed, aRes.mPrincipal);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A wrapper to the nsLayoutUtils::SurfaceFromElement() function followed by the
|
* A wrapper to the nsLayoutUtils::SurfaceFromElement() function followed by the
|
||||||
* security checking.
|
* security checking.
|
||||||
|
|
@ -365,7 +335,7 @@ GetSurfaceFromElement(nsIGlobalObject* aGlobal, HTMLElementType& aElement,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check origin-clean and pass back
|
// Check origin-clean and pass back
|
||||||
*aWriteOnly = !CheckSecurityForHTMLElements(res);
|
*aWriteOnly = res.mIsWriteOnly;
|
||||||
|
|
||||||
return surface.forget();
|
return surface.forget();
|
||||||
}
|
}
|
||||||
|
|
@ -818,7 +788,7 @@ ImageBitmap::CreateInternal(nsIGlobalObject* aGlobal, HTMLVideoElement& aVideoEl
|
||||||
nsCOMPtr<nsIPrincipal> principal = aVideoEl.GetCurrentVideoPrincipal();
|
nsCOMPtr<nsIPrincipal> principal = aVideoEl.GetCurrentVideoPrincipal();
|
||||||
bool CORSUsed = aVideoEl.GetCORSMode() != CORS_NONE;
|
bool CORSUsed = aVideoEl.GetCORSMode() != CORS_NONE;
|
||||||
|
|
||||||
writeOnly = !CheckSecurityForHTMLElements(false, CORSUsed, principal);
|
writeOnly = CheckWriteOnlySecurity(CORSUsed, principal);
|
||||||
|
|
||||||
// Create ImageBitmap.
|
// Create ImageBitmap.
|
||||||
ImageContainer *container = aVideoEl.GetImageContainer();
|
ImageContainer *container = aVideoEl.GetImageContainer();
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "mozilla/ArrayUtils.h"
|
#include "mozilla/ArrayUtils.h"
|
||||||
#include "mozilla/BasicEvents.h"
|
#include "mozilla/BasicEvents.h"
|
||||||
|
#include "mozilla/dom/CanvasUtils.h"
|
||||||
#include "mozilla/ClearOnShutdown.h"
|
#include "mozilla/ClearOnShutdown.h"
|
||||||
#include "mozilla/EffectCompositor.h"
|
#include "mozilla/EffectCompositor.h"
|
||||||
#include "mozilla/EffectSet.h"
|
#include "mozilla/EffectSet.h"
|
||||||
|
|
@ -7285,10 +7286,10 @@ nsLayoutUtils::SurfaceFromElement(nsIImageLoadingContent* aElement,
|
||||||
}
|
}
|
||||||
|
|
||||||
result.mPrincipal = principal.forget();
|
result.mPrincipal = principal.forget();
|
||||||
// no images, including SVG images, can load content from another domain.
|
|
||||||
result.mIsWriteOnly = false;
|
|
||||||
result.mImageRequest = imgRequest.forget();
|
result.mImageRequest = imgRequest.forget();
|
||||||
return result;
|
return result;
|
||||||
|
result.mIsWriteOnly =
|
||||||
|
CanvasUtils::CheckWriteOnlySecurity(result.mCORSUsed, result.mPrincipal);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsLayoutUtils::SurfaceFromElementResult
|
nsLayoutUtils::SurfaceFromElementResult
|
||||||
|
|
@ -7400,7 +7401,8 @@ nsLayoutUtils::SurfaceFromElement(HTMLVideoElement* aElement,
|
||||||
result.mHasSize = true;
|
result.mHasSize = true;
|
||||||
result.mSize = result.mLayersImage->GetSize();
|
result.mSize = result.mLayersImage->GetSize();
|
||||||
result.mPrincipal = principal.forget();
|
result.mPrincipal = principal.forget();
|
||||||
result.mIsWriteOnly = false;
|
result.mIsWriteOnly =
|
||||||
|
CanvasUtils::CheckWriteOnlySecurity(result.mCORSUsed, result.mPrincipal);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue