Convert dom/base/nsImageLoadingContent.cpp to use AsyncOpen2...
parent
1da7e39a56
commit
3103cfd8b0
|
@ -22,6 +22,7 @@
|
||||||
#include "nsIDOMWindow.h"
|
#include "nsIDOMWindow.h"
|
||||||
#include "nsITabChild.h"
|
#include "nsITabChild.h"
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
|
#include "nsIImageLoadingContent.h"
|
||||||
#include "nsILoadContext.h"
|
#include "nsILoadContext.h"
|
||||||
#include "nsCOMArray.h"
|
#include "nsCOMArray.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
|
@ -145,6 +146,16 @@ nsContentPolicy::CheckPolicy(CPMethod policyMethod,
|
||||||
decision);
|
decision);
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && NS_CP_REJECTED(*decision)) {
|
if (NS_SUCCEEDED(rv) && NS_CP_REJECTED(*decision)) {
|
||||||
|
// If we are blocking an image, we have to let the
|
||||||
|
// ImageLoadingContent know that we blocked the load.
|
||||||
|
if (externalType == nsIContentPolicy::TYPE_IMAGE ||
|
||||||
|
externalType == nsIContentPolicy::TYPE_IMAGESET) {
|
||||||
|
nsCOMPtr<nsIImageLoadingContent> img =
|
||||||
|
do_QueryInterface(requestingContext);
|
||||||
|
if (img) {
|
||||||
|
img->SetBlockedRequest(*decision);
|
||||||
|
}
|
||||||
|
}
|
||||||
/* policy says no, no point continuing to check */
|
/* policy says no, no point continuing to check */
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -193,6 +204,16 @@ nsContentPolicy::CheckPolicy(CPMethod policyMethod,
|
||||||
decision);
|
decision);
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && NS_CP_REJECTED(*decision)) {
|
if (NS_SUCCEEDED(rv) && NS_CP_REJECTED(*decision)) {
|
||||||
|
// If we are blocking an image, we have to let the
|
||||||
|
// ImageLoadingContent know that we blocked the load.
|
||||||
|
if (externalType == nsIContentPolicy::TYPE_IMAGE ||
|
||||||
|
externalType == nsIContentPolicy::TYPE_IMAGESET) {
|
||||||
|
nsCOMPtr<nsIImageLoadingContent> img =
|
||||||
|
do_QueryInterface(requestingContext);
|
||||||
|
if (img) {
|
||||||
|
img->SetBlockedRequest(*decision);
|
||||||
|
}
|
||||||
|
}
|
||||||
/* policy says no, no point continuing to check */
|
/* policy says no, no point continuing to check */
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8478,12 +8478,9 @@ nsContentUtils::InternalContentPolicyTypeToExternalOrWorker(nsContentPolicyType
|
||||||
bool
|
bool
|
||||||
nsContentUtils::IsPreloadType(nsContentPolicyType aType)
|
nsContentUtils::IsPreloadType(nsContentPolicyType aType)
|
||||||
{
|
{
|
||||||
if (aType == nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD ||
|
return (aType == nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD ||
|
||||||
aType == nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD ||
|
aType == nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD ||
|
||||||
aType == nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD) {
|
aType == nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
|
|
@ -9222,19 +9222,23 @@ already_AddRefed<nsIURI>
|
||||||
nsDocument::ResolvePreloadImage(nsIURI *aBaseURI,
|
nsDocument::ResolvePreloadImage(nsIURI *aBaseURI,
|
||||||
const nsAString& aSrcAttr,
|
const nsAString& aSrcAttr,
|
||||||
const nsAString& aSrcsetAttr,
|
const nsAString& aSrcsetAttr,
|
||||||
const nsAString& aSizesAttr)
|
const nsAString& aSizesAttr,
|
||||||
|
bool *aIsImgSet)
|
||||||
{
|
{
|
||||||
nsString sourceURL;
|
nsString sourceURL;
|
||||||
|
bool isImgSet;
|
||||||
if (mPreloadPictureDepth == 1 && !mPreloadPictureFoundSource.IsVoid()) {
|
if (mPreloadPictureDepth == 1 && !mPreloadPictureFoundSource.IsVoid()) {
|
||||||
// We're in a <picture> element and found a URI from a source previous to
|
// We're in a <picture> element and found a URI from a source previous to
|
||||||
// this image, use it.
|
// this image, use it.
|
||||||
sourceURL = mPreloadPictureFoundSource;
|
sourceURL = mPreloadPictureFoundSource;
|
||||||
|
isImgSet = true;
|
||||||
} else {
|
} else {
|
||||||
// Otherwise try to use this <img> as a source
|
// Otherwise try to use this <img> as a source
|
||||||
HTMLImageElement::SelectSourceForTagWithAttrs(this, false, aSrcAttr,
|
HTMLImageElement::SelectSourceForTagWithAttrs(this, false, aSrcAttr,
|
||||||
aSrcsetAttr, aSizesAttr,
|
aSrcsetAttr, aSizesAttr,
|
||||||
NullString(), NullString(),
|
NullString(), NullString(),
|
||||||
sourceURL);
|
sourceURL);
|
||||||
|
isImgSet = !aSrcsetAttr.IsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty sources are not loaded by <img> (i.e. not resolved to the baseURI)
|
// Empty sources are not loaded by <img> (i.e. not resolved to the baseURI)
|
||||||
|
@ -9252,6 +9256,8 @@ nsDocument::ResolvePreloadImage(nsIURI *aBaseURI,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*aIsImgSet = isImgSet;
|
||||||
|
|
||||||
// We don't clear mPreloadPictureFoundSource because subsequent <img> tags in
|
// We don't clear mPreloadPictureFoundSource because subsequent <img> tags in
|
||||||
// this this <picture> share the same <sources> (though this is not valid per
|
// this this <picture> share the same <sources> (though this is not valid per
|
||||||
// spec)
|
// spec)
|
||||||
|
@ -9260,16 +9266,12 @@ nsDocument::ResolvePreloadImage(nsIURI *aBaseURI,
|
||||||
|
|
||||||
void
|
void
|
||||||
nsDocument::MaybePreLoadImage(nsIURI* uri, const nsAString &aCrossOriginAttr,
|
nsDocument::MaybePreLoadImage(nsIURI* uri, const nsAString &aCrossOriginAttr,
|
||||||
ReferrerPolicy aReferrerPolicy)
|
ReferrerPolicy aReferrerPolicy, bool aIsImgSet)
|
||||||
{
|
{
|
||||||
// Early exit if the img is already present in the img-cache
|
// Early exit if the img is already present in the img-cache
|
||||||
// which indicates that the "real" load has already started and
|
// which indicates that the "real" load has already started and
|
||||||
// that we shouldn't preload it.
|
// that we shouldn't preload it.
|
||||||
int16_t blockingStatus;
|
if (nsContentUtils::IsImageInCache(uri, static_cast<nsIDocument *>(this))) {
|
||||||
if (nsContentUtils::IsImageInCache(uri, static_cast<nsIDocument *>(this)) ||
|
|
||||||
!nsContentUtils::CanLoadImage(uri, static_cast<nsIDocument *>(this),
|
|
||||||
this, NodePrincipal(), &blockingStatus,
|
|
||||||
nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9288,6 +9290,10 @@ nsDocument::MaybePreLoadImage(nsIURI* uri, const nsAString &aCrossOriginAttr,
|
||||||
MOZ_CRASH("Unknown CORS mode!");
|
MOZ_CRASH("Unknown CORS mode!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsContentPolicyType policyType =
|
||||||
|
aIsImgSet ? nsIContentPolicy::TYPE_IMAGESET :
|
||||||
|
nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD;
|
||||||
|
|
||||||
// Image not in cache - trigger preload
|
// Image not in cache - trigger preload
|
||||||
RefPtr<imgRequestProxy> request;
|
RefPtr<imgRequestProxy> request;
|
||||||
nsresult rv =
|
nsresult rv =
|
||||||
|
@ -9301,7 +9307,7 @@ nsDocument::MaybePreLoadImage(nsIURI* uri, const nsAString &aCrossOriginAttr,
|
||||||
loadFlags,
|
loadFlags,
|
||||||
NS_LITERAL_STRING("img"),
|
NS_LITERAL_STRING("img"),
|
||||||
getter_AddRefs(request),
|
getter_AddRefs(request),
|
||||||
nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD);
|
policyType);
|
||||||
|
|
||||||
// Pin image-reference to avoid evicting it from the img-cache before
|
// Pin image-reference to avoid evicting it from the img-cache before
|
||||||
// the "real" load occurs. Unpinned in DispatchContentLoadedEvents and
|
// the "real" load occurs. Unpinned in DispatchContentLoadedEvents and
|
||||||
|
|
|
@ -948,11 +948,13 @@ public:
|
||||||
ResolvePreloadImage(nsIURI *aBaseURI,
|
ResolvePreloadImage(nsIURI *aBaseURI,
|
||||||
const nsAString& aSrcAttr,
|
const nsAString& aSrcAttr,
|
||||||
const nsAString& aSrcsetAttr,
|
const nsAString& aSrcsetAttr,
|
||||||
const nsAString& aSizesAttr) override;
|
const nsAString& aSizesAttr,
|
||||||
|
bool *aIsImgSet) override;
|
||||||
|
|
||||||
virtual void MaybePreLoadImage(nsIURI* uri,
|
virtual void MaybePreLoadImage(nsIURI* uri,
|
||||||
const nsAString &aCrossOriginAttr,
|
const nsAString &aCrossOriginAttr,
|
||||||
ReferrerPolicy aReferrerPolicy) override;
|
ReferrerPolicy aReferrerPolicy,
|
||||||
|
bool aIsImgSet) override;
|
||||||
virtual void ForgetImagePreload(nsIURI* aURI) override;
|
virtual void ForgetImagePreload(nsIURI* aURI) override;
|
||||||
|
|
||||||
virtual void MaybePreconnect(nsIURI* uri,
|
virtual void MaybePreconnect(nsIURI* uri,
|
||||||
|
|
|
@ -2260,21 +2260,27 @@ public:
|
||||||
* nesting and possible sources, which are used to inform URL selection
|
* nesting and possible sources, which are used to inform URL selection
|
||||||
* responsive <picture> or <img srcset> images. Unset attributes are expected
|
* responsive <picture> or <img srcset> images. Unset attributes are expected
|
||||||
* to be marked void.
|
* to be marked void.
|
||||||
|
* If this image is for <picture> or <img srcset>, aIsImgSet will be set to
|
||||||
|
* true, false otherwise.
|
||||||
*/
|
*/
|
||||||
virtual already_AddRefed<nsIURI>
|
virtual already_AddRefed<nsIURI>
|
||||||
ResolvePreloadImage(nsIURI *aBaseURI,
|
ResolvePreloadImage(nsIURI *aBaseURI,
|
||||||
const nsAString& aSrcAttr,
|
const nsAString& aSrcAttr,
|
||||||
const nsAString& aSrcsetAttr,
|
const nsAString& aSrcsetAttr,
|
||||||
const nsAString& aSizesAttr) = 0;
|
const nsAString& aSizesAttr,
|
||||||
|
bool *aIsImgSet) = 0;
|
||||||
/**
|
/**
|
||||||
* Called by nsParser to preload images. Can be removed and code moved
|
* Called by nsParser to preload images. Can be removed and code moved
|
||||||
* to nsPreloadURIs::PreloadURIs() in file nsParser.cpp whenever the
|
* to nsPreloadURIs::PreloadURIs() in file nsParser.cpp whenever the
|
||||||
* parser-module is linked with gklayout-module. aCrossOriginAttr should
|
* parser-module is linked with gklayout-module. aCrossOriginAttr should
|
||||||
* be a void string if the attr is not present.
|
* be a void string if the attr is not present.
|
||||||
|
* aIsImgSet is the value got from calling ResolvePreloadImage, it is true
|
||||||
|
* when this image is for loading <picture> or <img srcset> images.
|
||||||
*/
|
*/
|
||||||
virtual void MaybePreLoadImage(nsIURI* uri,
|
virtual void MaybePreLoadImage(nsIURI* uri,
|
||||||
const nsAString& aCrossOriginAttr,
|
const nsAString& aCrossOriginAttr,
|
||||||
ReferrerPolicyEnum aReferrerPolicy) = 0;
|
ReferrerPolicyEnum aReferrerPolicy,
|
||||||
|
bool aIsImgSet) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by images to forget an image preload when they start doing
|
* Called by images to forget an image preload when they start doing
|
||||||
|
|
|
@ -103,6 +103,15 @@ interface nsIImageLoadingContent : imgINotificationObserver
|
||||||
*/
|
*/
|
||||||
imgIRequest getRequest(in long aRequestType);
|
imgIRequest getRequest(in long aRequestType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call this function when the request was blocked by any of the
|
||||||
|
* security policies enforced.
|
||||||
|
*
|
||||||
|
* @param aContentDecision the decision returned from nsIContentPolicy
|
||||||
|
* (any of the types REJECT_*)
|
||||||
|
*/
|
||||||
|
void setBlockedRequest(in int16_t aContentDecision);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the current request's size is available.
|
* @return true if the current request's size is available.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
|
|
||||||
#include "mozAutoDocUpdate.h"
|
#include "mozAutoDocUpdate.h"
|
||||||
#include "mozilla/AsyncEventDispatcher.h"
|
#include "mozilla/AsyncEventDispatcher.h"
|
||||||
|
#include "mozilla/AutoRestore.h"
|
||||||
#include "mozilla/EventStates.h"
|
#include "mozilla/EventStates.h"
|
||||||
#include "mozilla/dom/Element.h"
|
#include "mozilla/dom/Element.h"
|
||||||
#include "mozilla/dom/ImageTracker.h"
|
#include "mozilla/dom/ImageTracker.h"
|
||||||
|
@ -94,7 +95,8 @@ nsImageLoadingContent::nsImageLoadingContent()
|
||||||
mNewRequestsWillNeedAnimationReset(false),
|
mNewRequestsWillNeedAnimationReset(false),
|
||||||
mStateChangerDepth(0),
|
mStateChangerDepth(0),
|
||||||
mCurrentRequestRegistered(false),
|
mCurrentRequestRegistered(false),
|
||||||
mPendingRequestRegistered(false)
|
mPendingRequestRegistered(false),
|
||||||
|
mIsStartingImageLoad(false)
|
||||||
{
|
{
|
||||||
if (!nsContentUtils::GetImgLoaderForChannel(nullptr, nullptr)) {
|
if (!nsContentUtils::GetImgLoaderForChannel(nullptr, nullptr)) {
|
||||||
mLoadingEnabled = false;
|
mLoadingEnabled = false;
|
||||||
|
@ -785,6 +787,11 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI,
|
||||||
nsIDocument* aDocument,
|
nsIDocument* aDocument,
|
||||||
nsLoadFlags aLoadFlags)
|
nsLoadFlags aLoadFlags)
|
||||||
{
|
{
|
||||||
|
MOZ_ASSERT(!mIsStartingImageLoad, "some evil code is reentering LoadImage.");
|
||||||
|
if (mIsStartingImageLoad) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
// Pending load/error events need to be canceled in some situations. This
|
// Pending load/error events need to be canceled in some situations. This
|
||||||
// is not documented in the spec, but can cause site compat problems if not
|
// is not documented in the spec, but can cause site compat problems if not
|
||||||
// done. See bug 1309461 and https://github.com/whatwg/html/issues/1872.
|
// done. See bug 1309461 and https://github.com/whatwg/html/issues/1872.
|
||||||
|
@ -814,6 +821,21 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AutoRestore<bool> guard(mIsStartingImageLoad);
|
||||||
|
mIsStartingImageLoad = true;
|
||||||
|
|
||||||
|
// Data documents, or documents from DOMParser shouldn't perform image loading.
|
||||||
|
if (aDocument->IsLoadedAsData()) {
|
||||||
|
// This is the only codepath on which we can reach SetBlockedRequest while
|
||||||
|
// our pending request exists. Just clear it out here if we do have one.
|
||||||
|
ClearPendingRequest(NS_BINDING_ABORTED,
|
||||||
|
Some(OnNonvisible::DISCARD_IMAGES));
|
||||||
|
SetBlockedRequest(nsIContentPolicy::REJECT_REQUEST);
|
||||||
|
FireEvent(NS_LITERAL_STRING("error"));
|
||||||
|
FireEvent(NS_LITERAL_STRING("loadend"));
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
// URI equality check.
|
// URI equality check.
|
||||||
//
|
//
|
||||||
// We skip the equality check if our current image was blocked, since in that
|
// We skip the equality check if our current image was blocked, since in that
|
||||||
|
@ -844,23 +866,8 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI,
|
||||||
"Principal mismatch?");
|
"Principal mismatch?");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Are we blocked?
|
|
||||||
int16_t cpDecision = nsIContentPolicy::REJECT_REQUEST;
|
|
||||||
nsContentPolicyType policyType = PolicyTypeForLoad(aImageLoadType);
|
nsContentPolicyType policyType = PolicyTypeForLoad(aImageLoadType);
|
||||||
|
|
||||||
nsContentUtils::CanLoadImage(aNewURI,
|
|
||||||
static_cast<nsIImageLoadingContent*>(this),
|
|
||||||
aDocument,
|
|
||||||
aDocument->NodePrincipal(),
|
|
||||||
&cpDecision,
|
|
||||||
policyType);
|
|
||||||
if (!NS_CP_ACCEPTED(cpDecision)) {
|
|
||||||
FireEvent(NS_LITERAL_STRING("error"));
|
|
||||||
FireEvent(NS_LITERAL_STRING("loadend"));
|
|
||||||
SetBlockedRequest(aNewURI, cpDecision);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsLoadFlags loadFlags = aLoadFlags;
|
nsLoadFlags loadFlags = aLoadFlags;
|
||||||
int32_t corsmode = GetCORSMode();
|
int32_t corsmode = GetCORSMode();
|
||||||
if (corsmode == CORS_ANONYMOUS) {
|
if (corsmode == CORS_ANONYMOUS) {
|
||||||
|
@ -878,7 +885,6 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI,
|
||||||
referrerPolicy = imgReferrerPolicy;
|
referrerPolicy = imgReferrerPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not blocked. Do the load.
|
|
||||||
RefPtr<imgRequestProxy>& req = PrepareNextRequest(aImageLoadType);
|
RefPtr<imgRequestProxy>& req = PrepareNextRequest(aImageLoadType);
|
||||||
nsCOMPtr<nsIContent> content =
|
nsCOMPtr<nsIContent> content =
|
||||||
do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
||||||
|
@ -932,7 +938,6 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI,
|
||||||
|
|
||||||
FireEvent(NS_LITERAL_STRING("error"));
|
FireEvent(NS_LITERAL_STRING("error"));
|
||||||
FireEvent(NS_LITERAL_STRING("loadend"));
|
FireEvent(NS_LITERAL_STRING("loadend"));
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -1212,46 +1217,42 @@ nsImageLoadingContent::PrepareNextRequest(ImageLoadType aImageLoadType)
|
||||||
mMostRecentRequestChange = now;
|
mMostRecentRequestChange = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't have a usable current request, get rid of any half-baked
|
|
||||||
// request that might be sitting there and make this one current.
|
|
||||||
if (!HaveSize(mCurrentRequest))
|
|
||||||
return PrepareCurrentRequest(aImageLoadType);
|
|
||||||
|
|
||||||
// Otherwise, make it pending.
|
// We only want to cancel the existing current request if size is not
|
||||||
return PreparePendingRequest(aImageLoadType);
|
// available. bz says the web depends on this behavior.
|
||||||
|
// Otherwise, we get rid of any half-baked request that might be sitting there
|
||||||
|
// and make this one current.
|
||||||
|
// TODO: Bug 583491
|
||||||
|
// Investigate/Cleanup NS_ERROR_IMAGE_SRC_CHANGED use in nsImageFrame.cpp
|
||||||
|
return HaveSize(mCurrentRequest) ?
|
||||||
|
PreparePendingRequest(aImageLoadType) :
|
||||||
|
PrepareCurrentRequest(aImageLoadType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
nsresult
|
||||||
nsImageLoadingContent::SetBlockedRequest(nsIURI* aURI, int16_t aContentDecision)
|
nsImageLoadingContent::SetBlockedRequest(int16_t aContentDecision)
|
||||||
{
|
{
|
||||||
|
// If this is not calling from LoadImage, for example, from ServiceWorker,
|
||||||
|
// bail out.
|
||||||
|
if (!mIsStartingImageLoad) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
// Sanity
|
// Sanity
|
||||||
MOZ_ASSERT(!NS_CP_ACCEPTED(aContentDecision), "Blocked but not?");
|
MOZ_ASSERT(!NS_CP_ACCEPTED(aContentDecision), "Blocked but not?");
|
||||||
|
|
||||||
// We do some slightly illogical stuff here to maintain consistency with
|
// We should never have a pending request after we got blocked.
|
||||||
// old behavior that people probably depend on. Even in the case where the
|
MOZ_ASSERT(!mPendingRequest, "mPendingRequest should be null.");
|
||||||
// new image is blocked, the old one should really be canceled with the
|
|
||||||
// reason "image source changed". However, apparently there's some abuse
|
|
||||||
// over in nsImageFrame where the displaying of the "broken" icon for the
|
|
||||||
// next image depends on the cancel reason of the previous image. ugh.
|
|
||||||
// XXX(seth): So shouldn't we fix nsImageFrame?!
|
|
||||||
ClearPendingRequest(NS_ERROR_IMAGE_BLOCKED,
|
|
||||||
Some(OnNonvisible::DISCARD_IMAGES));
|
|
||||||
|
|
||||||
// For the blocked case, we only want to cancel the existing current request
|
|
||||||
// if size is not available. bz says the web depends on this behavior.
|
|
||||||
if (!HaveSize(mCurrentRequest)) {
|
|
||||||
|
|
||||||
|
if (HaveSize(mCurrentRequest)) {
|
||||||
|
// PreparePendingRequest set mPendingRequestFlags, now since we've decided
|
||||||
|
// to block it, we reset it back to 0.
|
||||||
|
mPendingRequestFlags = 0;
|
||||||
|
} else {
|
||||||
mImageBlockingStatus = aContentDecision;
|
mImageBlockingStatus = aContentDecision;
|
||||||
uint32_t keepFlags = mCurrentRequestFlags & REQUEST_IS_IMAGESET;
|
|
||||||
ClearCurrentRequest(NS_ERROR_IMAGE_BLOCKED,
|
|
||||||
Some(OnNonvisible::DISCARD_IMAGES));
|
|
||||||
|
|
||||||
// We still want to remember what URI we were and if it was an imageset,
|
|
||||||
// despite not having an actual request. These are both cleared as part of
|
|
||||||
// ClearCurrentRequest() before a new request is started.
|
|
||||||
mCurrentURI = aURI;
|
|
||||||
mCurrentRequestFlags = keepFlags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<imgRequestProxy>&
|
RefPtr<imgRequestProxy>&
|
||||||
|
@ -1262,7 +1263,7 @@ nsImageLoadingContent::PrepareCurrentRequest(ImageLoadType aImageLoadType)
|
||||||
mImageBlockingStatus = nsIContentPolicy::ACCEPT;
|
mImageBlockingStatus = nsIContentPolicy::ACCEPT;
|
||||||
|
|
||||||
// Get rid of anything that was there previously.
|
// Get rid of anything that was there previously.
|
||||||
ClearCurrentRequest(NS_ERROR_IMAGE_SRC_CHANGED,
|
ClearCurrentRequest(NS_BINDING_ABORTED,
|
||||||
Some(OnNonvisible::DISCARD_IMAGES));
|
Some(OnNonvisible::DISCARD_IMAGES));
|
||||||
|
|
||||||
if (mNewRequestsWillNeedAnimationReset) {
|
if (mNewRequestsWillNeedAnimationReset) {
|
||||||
|
@ -1281,7 +1282,7 @@ RefPtr<imgRequestProxy>&
|
||||||
nsImageLoadingContent::PreparePendingRequest(ImageLoadType aImageLoadType)
|
nsImageLoadingContent::PreparePendingRequest(ImageLoadType aImageLoadType)
|
||||||
{
|
{
|
||||||
// Get rid of anything that was there previously.
|
// Get rid of anything that was there previously.
|
||||||
ClearPendingRequest(NS_ERROR_IMAGE_SRC_CHANGED,
|
ClearPendingRequest(NS_BINDING_ABORTED,
|
||||||
Some(OnNonvisible::DISCARD_IMAGES));
|
Some(OnNonvisible::DISCARD_IMAGES));
|
||||||
|
|
||||||
if (mNewRequestsWillNeedAnimationReset) {
|
if (mNewRequestsWillNeedAnimationReset) {
|
||||||
|
|
|
@ -302,18 +302,11 @@ protected:
|
||||||
*/
|
*/
|
||||||
RefPtr<imgRequestProxy>& PrepareNextRequest(ImageLoadType aImageLoadType);
|
RefPtr<imgRequestProxy>& PrepareNextRequest(ImageLoadType aImageLoadType);
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when we would normally call PrepareNextRequest(), but the request was
|
|
||||||
* blocked.
|
|
||||||
*/
|
|
||||||
void SetBlockedRequest(nsIURI* aURI, int16_t aContentDecision);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a COMPtr reference to the current/pending image requests, cleaning
|
* Returns a COMPtr reference to the current/pending image requests, cleaning
|
||||||
* up and canceling anything that was there before. Note that if you just want
|
* up and canceling anything that was there before. Note that if you just want
|
||||||
* to get rid of one of the requests, you should call
|
* to get rid of one of the requests, you should call
|
||||||
* Clear*Request(NS_BINDING_ABORTED) instead, since it passes a more appropriate
|
* Clear*Request(NS_BINDING_ABORTED) instead.
|
||||||
* aReason than Prepare*Request() does (NS_ERROR_IMAGE_SRC_CHANGED).
|
|
||||||
*
|
*
|
||||||
* @param aImageLoadType The ImageLoadType for this request
|
* @param aImageLoadType The ImageLoadType for this request
|
||||||
*/
|
*/
|
||||||
|
@ -459,6 +452,14 @@ private:
|
||||||
// registered with the refresh driver.
|
// registered with the refresh driver.
|
||||||
bool mCurrentRequestRegistered;
|
bool mCurrentRequestRegistered;
|
||||||
bool mPendingRequestRegistered;
|
bool mPendingRequestRegistered;
|
||||||
|
|
||||||
|
// This member is used in SetBlockedRequest, if it's true, then this call is
|
||||||
|
// triggered from LoadImage.
|
||||||
|
// If this is false, it means this call is from other places like
|
||||||
|
// ServiceWorker, then we will ignore call to SetBlockedRequest for now.
|
||||||
|
//
|
||||||
|
// Also we use this variable to check if some evil code is reentering LoadImage.
|
||||||
|
bool mIsStartingImageLoad;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // nsImageLoadingContent_h__
|
#endif // nsImageLoadingContent_h__
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "nsIStreamListener.h"
|
#include "nsIStreamListener.h"
|
||||||
#include "nsCDefaultURIFixup.h"
|
#include "nsCDefaultURIFixup.h"
|
||||||
#include "nsIURIFixup.h"
|
#include "nsIURIFixup.h"
|
||||||
|
#include "nsIImageLoadingContent.h"
|
||||||
|
|
||||||
#include "mozilla/dom/Element.h"
|
#include "mozilla/dom/Element.h"
|
||||||
#include "mozilla/dom/TabChild.h"
|
#include "mozilla/dom/TabChild.h"
|
||||||
|
@ -801,6 +802,8 @@ nsContentSecurityManager::CheckChannel(nsIChannel* aChannel)
|
||||||
// within nsCorsListenerProxy
|
// within nsCorsListenerProxy
|
||||||
rv = DoCheckLoadURIChecks(uri, loadInfo);
|
rv = DoCheckLoadURIChecks(uri, loadInfo);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
// TODO: Bug 1371237
|
||||||
|
// consider calling SetBlockedRequest in nsContentSecurityManager::CheckChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
@ -1684,6 +1684,7 @@ imgLoader::ValidateRequestWithNewChannel(imgRequest* request,
|
||||||
|
|
||||||
rv = newChannel->AsyncOpen2(listener);
|
rv = newChannel->AsyncOpen2(listener);
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
req->CancelAndForgetObserver(rv);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -907,6 +907,9 @@ nsCORSListenerProxy::UpdateChannel(nsIChannel* aChannel,
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Bug 1353683
|
||||||
|
// consider calling SetBlockedRequest in nsCORSListenerProxy::UpdateChannel
|
||||||
|
//
|
||||||
// Check that the uri is ok to load
|
// Check that the uri is ok to load
|
||||||
rv = nsContentUtils::GetSecurityManager()->
|
rv = nsContentUtils::GetSecurityManager()->
|
||||||
CheckLoadURIWithPrincipal(mRequestingPrincipal, uri,
|
CheckLoadURIWithPrincipal(mRequestingPrincipal, uri,
|
||||||
|
|
|
@ -954,8 +954,9 @@ nsHtml5TreeOpExecutor::PreloadImage(const nsAString& aURL,
|
||||||
const nsAString& aImageReferrerPolicy)
|
const nsAString& aImageReferrerPolicy)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIURI> baseURI = BaseURIForPreload();
|
nsCOMPtr<nsIURI> baseURI = BaseURIForPreload();
|
||||||
|
bool isImgSet = false;
|
||||||
nsCOMPtr<nsIURI> uri = mDocument->ResolvePreloadImage(baseURI, aURL, aSrcset,
|
nsCOMPtr<nsIURI> uri = mDocument->ResolvePreloadImage(baseURI, aURL, aSrcset,
|
||||||
aSizes);
|
aSizes, &isImgSet);
|
||||||
if (uri && ShouldPreloadURI(uri)) {
|
if (uri && ShouldPreloadURI(uri)) {
|
||||||
// use document wide referrer policy
|
// use document wide referrer policy
|
||||||
mozilla::net::ReferrerPolicy referrerPolicy = mSpeculationReferrerPolicy;
|
mozilla::net::ReferrerPolicy referrerPolicy = mSpeculationReferrerPolicy;
|
||||||
|
@ -969,7 +970,7 @@ nsHtml5TreeOpExecutor::PreloadImage(const nsAString& aURL,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mDocument->MaybePreLoadImage(uri, aCrossOrigin, referrerPolicy);
|
mDocument->MaybePreLoadImage(uri, aCrossOrigin, referrerPolicy, isImgSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue