Loading dom/base/CORSMode.h +3 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ enum CORSMode : uint8_t { CORS_USE_CREDENTIALS }; constexpr auto kFirstCORSMode = CORS_NONE; constexpr auto kLastCORSMode = CORS_USE_CREDENTIALS; } // namespace mozilla #endif /* CORSMode_h_ */ dom/base/Document.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -12379,12 +12379,12 @@ void Document::MaybePreLoadImage(nsIURI* aUri, ReferrerPolicyEnum aReferrerPolicy, bool aIsImgSet, bool aLinkPreload, const TimeStamp& aInitTimestamp) { const CORSMode corsMode = dom::Element::StringToCORSMode(aCrossOriginAttr); if (aLinkPreload) { // Check if the image was already preloaded in this document to avoid // duplicate preloading. PreloadHashKey key = PreloadHashKey::CreateAsImage( aUri, NodePrincipal(), dom::Element::StringToCORSMode(aCrossOriginAttr)); PreloadHashKey key = PreloadHashKey::CreateAsImage(aUri, NodePrincipal(), corsMode); if (!mPreloadService.PreloadExists(key)) { PreLoadImage(aUri, aCrossOriginAttr, aReferrerPolicy, aIsImgSet, aLinkPreload, 0); Loading @@ -12395,7 +12395,7 @@ void Document::MaybePreLoadImage(nsIURI* aUri, // Early exit if the img is already present in the img-cache // which indicates that the "real" load has already started and // that we shouldn't preload it. if (nsContentUtils::IsImageInCache(aUri, this)) { if (nsContentUtils::IsImageAvailable(aUri, NodePrincipal(), corsMode, this)) { return; } Loading dom/base/nsContentUtils.cpp +9 −15 Original line number Diff line number Diff line Loading @@ -3844,19 +3844,6 @@ imgLoader* nsContentUtils::GetImgLoaderForChannel(nsIChannel* aChannel, : imgLoader::NormalLoader(); } // static bool nsContentUtils::IsImageInCache(nsIURI* aURI, Document* aDocument) { imgILoader* loader = GetImgLoaderForDocument(aDocument); nsCOMPtr<imgICache> cache = do_QueryInterface(loader); // If something unexpected happened we return false, otherwise if props // is set, the image is cached and we return true nsCOMPtr<nsIProperties> props; nsresult rv = cache->FindEntryProperties(aURI, aDocument, getter_AddRefs(props)); return (NS_SUCCEEDED(rv) && props); } // static int32_t nsContentUtils::CORSModeToLoadImageFlags(mozilla::CORSMode aMode) { switch (aMode) { Loading Loading @@ -10026,8 +10013,15 @@ bool nsContentUtils::IsImageAvailable(nsIContent* aLoadingNode, nsIURI* aURI, MOZ_ASSERT(triggeringPrincipal); Document* doc = aLoadingNode->OwnerDoc(); imgLoader* imgLoader = GetImgLoaderForDocument(doc); return imgLoader->IsImageAvailable(aURI, triggeringPrincipal, aCORSMode, doc); return IsImageAvailable(aURI, triggeringPrincipal, aCORSMode, doc); } bool nsContentUtils::IsImageAvailable(nsIURI* aURI, nsIPrincipal* aTriggeringPrincipal, CORSMode aCORSMode, Document* aDoc) { imgLoader* imgLoader = GetImgLoaderForDocument(aDoc); return imgLoader->IsImageAvailable(aURI, aTriggeringPrincipal, aCORSMode, aDoc); } /* static */ Loading dom/base/nsContentUtils.h +2 −5 Original line number Diff line number Diff line Loading @@ -1051,11 +1051,6 @@ class nsContentUtils { static imgLoader* GetImgLoaderForChannel(nsIChannel* aChannel, Document* aContext); /** * Returns whether the given URI is in the image cache. */ static bool IsImageInCache(nsIURI* aURI, Document* aDocument); /** * Method to get an imgIContainer from an image loading content * Loading Loading @@ -3099,6 +3094,8 @@ class nsContentUtils { static bool IsImageAvailable(nsIContent*, nsIURI*, nsIPrincipal* aDefaultTriggeringPrincipal, mozilla::CORSMode); static bool IsImageAvailable(nsIURI*, nsIPrincipal* aTriggeringPrincipal, mozilla::CORSMode, Document*); /** * Returns the content policy type that should be used for loading images Loading image/ImageCacheKey.cpp +12 −4 Original line number Diff line number Diff line Loading @@ -29,26 +29,30 @@ using namespace dom; namespace image { ImageCacheKey::ImageCacheKey(nsIURI* aURI, const OriginAttributes& aAttrs, ImageCacheKey::ImageCacheKey(nsIURI* aURI, CORSMode aCORSMode, const OriginAttributes& aAttrs, Document* aDocument) : mURI(aURI), mOriginAttributes(aAttrs), mControlledDocument(GetSpecialCaseDocumentToken(aDocument)), mIsolationKey(GetIsolationKey(aDocument, aURI)) {} mIsolationKey(GetIsolationKey(aDocument, aURI)), mCORSMode(aCORSMode) {} ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther) : mURI(aOther.mURI), mOriginAttributes(aOther.mOriginAttributes), mControlledDocument(aOther.mControlledDocument), mIsolationKey(aOther.mIsolationKey), mHash(aOther.mHash) {} mHash(aOther.mHash), mCORSMode(aOther.mCORSMode) {} ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther) : mURI(std::move(aOther.mURI)), mOriginAttributes(aOther.mOriginAttributes), mControlledDocument(aOther.mControlledDocument), mIsolationKey(aOther.mIsolationKey), mHash(aOther.mHash) {} mHash(aOther.mHash), mCORSMode(aOther.mCORSMode) {} bool ImageCacheKey::operator==(const ImageCacheKey& aOther) const { // Don't share the image cache between a controlled document and anything Loading @@ -67,6 +71,10 @@ bool ImageCacheKey::operator==(const ImageCacheKey& aOther) const { return false; } if (mCORSMode != aOther.mCORSMode) { return false; } // For non-blob URIs, compare the URIs. bool equals = false; nsresult rv = mURI->Equals(aOther.mURI, &equals); Loading Loading
dom/base/CORSMode.h +3 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ enum CORSMode : uint8_t { CORS_USE_CREDENTIALS }; constexpr auto kFirstCORSMode = CORS_NONE; constexpr auto kLastCORSMode = CORS_USE_CREDENTIALS; } // namespace mozilla #endif /* CORSMode_h_ */
dom/base/Document.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -12379,12 +12379,12 @@ void Document::MaybePreLoadImage(nsIURI* aUri, ReferrerPolicyEnum aReferrerPolicy, bool aIsImgSet, bool aLinkPreload, const TimeStamp& aInitTimestamp) { const CORSMode corsMode = dom::Element::StringToCORSMode(aCrossOriginAttr); if (aLinkPreload) { // Check if the image was already preloaded in this document to avoid // duplicate preloading. PreloadHashKey key = PreloadHashKey::CreateAsImage( aUri, NodePrincipal(), dom::Element::StringToCORSMode(aCrossOriginAttr)); PreloadHashKey key = PreloadHashKey::CreateAsImage(aUri, NodePrincipal(), corsMode); if (!mPreloadService.PreloadExists(key)) { PreLoadImage(aUri, aCrossOriginAttr, aReferrerPolicy, aIsImgSet, aLinkPreload, 0); Loading @@ -12395,7 +12395,7 @@ void Document::MaybePreLoadImage(nsIURI* aUri, // Early exit if the img is already present in the img-cache // which indicates that the "real" load has already started and // that we shouldn't preload it. if (nsContentUtils::IsImageInCache(aUri, this)) { if (nsContentUtils::IsImageAvailable(aUri, NodePrincipal(), corsMode, this)) { return; } Loading
dom/base/nsContentUtils.cpp +9 −15 Original line number Diff line number Diff line Loading @@ -3844,19 +3844,6 @@ imgLoader* nsContentUtils::GetImgLoaderForChannel(nsIChannel* aChannel, : imgLoader::NormalLoader(); } // static bool nsContentUtils::IsImageInCache(nsIURI* aURI, Document* aDocument) { imgILoader* loader = GetImgLoaderForDocument(aDocument); nsCOMPtr<imgICache> cache = do_QueryInterface(loader); // If something unexpected happened we return false, otherwise if props // is set, the image is cached and we return true nsCOMPtr<nsIProperties> props; nsresult rv = cache->FindEntryProperties(aURI, aDocument, getter_AddRefs(props)); return (NS_SUCCEEDED(rv) && props); } // static int32_t nsContentUtils::CORSModeToLoadImageFlags(mozilla::CORSMode aMode) { switch (aMode) { Loading Loading @@ -10026,8 +10013,15 @@ bool nsContentUtils::IsImageAvailable(nsIContent* aLoadingNode, nsIURI* aURI, MOZ_ASSERT(triggeringPrincipal); Document* doc = aLoadingNode->OwnerDoc(); imgLoader* imgLoader = GetImgLoaderForDocument(doc); return imgLoader->IsImageAvailable(aURI, triggeringPrincipal, aCORSMode, doc); return IsImageAvailable(aURI, triggeringPrincipal, aCORSMode, doc); } bool nsContentUtils::IsImageAvailable(nsIURI* aURI, nsIPrincipal* aTriggeringPrincipal, CORSMode aCORSMode, Document* aDoc) { imgLoader* imgLoader = GetImgLoaderForDocument(aDoc); return imgLoader->IsImageAvailable(aURI, aTriggeringPrincipal, aCORSMode, aDoc); } /* static */ Loading
dom/base/nsContentUtils.h +2 −5 Original line number Diff line number Diff line Loading @@ -1051,11 +1051,6 @@ class nsContentUtils { static imgLoader* GetImgLoaderForChannel(nsIChannel* aChannel, Document* aContext); /** * Returns whether the given URI is in the image cache. */ static bool IsImageInCache(nsIURI* aURI, Document* aDocument); /** * Method to get an imgIContainer from an image loading content * Loading Loading @@ -3099,6 +3094,8 @@ class nsContentUtils { static bool IsImageAvailable(nsIContent*, nsIURI*, nsIPrincipal* aDefaultTriggeringPrincipal, mozilla::CORSMode); static bool IsImageAvailable(nsIURI*, nsIPrincipal* aTriggeringPrincipal, mozilla::CORSMode, Document*); /** * Returns the content policy type that should be used for loading images Loading
image/ImageCacheKey.cpp +12 −4 Original line number Diff line number Diff line Loading @@ -29,26 +29,30 @@ using namespace dom; namespace image { ImageCacheKey::ImageCacheKey(nsIURI* aURI, const OriginAttributes& aAttrs, ImageCacheKey::ImageCacheKey(nsIURI* aURI, CORSMode aCORSMode, const OriginAttributes& aAttrs, Document* aDocument) : mURI(aURI), mOriginAttributes(aAttrs), mControlledDocument(GetSpecialCaseDocumentToken(aDocument)), mIsolationKey(GetIsolationKey(aDocument, aURI)) {} mIsolationKey(GetIsolationKey(aDocument, aURI)), mCORSMode(aCORSMode) {} ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther) : mURI(aOther.mURI), mOriginAttributes(aOther.mOriginAttributes), mControlledDocument(aOther.mControlledDocument), mIsolationKey(aOther.mIsolationKey), mHash(aOther.mHash) {} mHash(aOther.mHash), mCORSMode(aOther.mCORSMode) {} ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther) : mURI(std::move(aOther.mURI)), mOriginAttributes(aOther.mOriginAttributes), mControlledDocument(aOther.mControlledDocument), mIsolationKey(aOther.mIsolationKey), mHash(aOther.mHash) {} mHash(aOther.mHash), mCORSMode(aOther.mCORSMode) {} bool ImageCacheKey::operator==(const ImageCacheKey& aOther) const { // Don't share the image cache between a controlled document and anything Loading @@ -67,6 +71,10 @@ bool ImageCacheKey::operator==(const ImageCacheKey& aOther) const { return false; } if (mCORSMode != aOther.mCORSMode) { return false; } // For non-blob URIs, compare the URIs. bool equals = false; nsresult rv = mURI->Equals(aOther.mURI, &equals); Loading