forked from mirrors/gecko-dev
Bug 1771867 - Early Hints Phase 2 - Part 7: Pass early hint preload to image preloader r=necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D161177
This commit is contained in:
parent
01bc307305
commit
17df5816aa
9 changed files with 41 additions and 23 deletions
|
|
@ -12212,7 +12212,7 @@ already_AddRefed<nsIURI> Document::ResolvePreloadImage(
|
|||
|
||||
void Document::PreLoadImage(nsIURI* aUri, const nsAString& aCrossOriginAttr,
|
||||
ReferrerPolicyEnum aReferrerPolicy, bool aIsImgSet,
|
||||
bool aLinkPreload) {
|
||||
bool aLinkPreload, uint64_t aEarlyHintPreloaderId) {
|
||||
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL |
|
||||
nsIRequest::LOAD_RECORD_START_REQUEST_DELAY |
|
||||
nsContentUtils::CORSModeToLoadImageFlags(
|
||||
|
|
@ -12226,11 +12226,15 @@ void Document::PreLoadImage(nsIURI* aUri, const nsAString& aCrossOriginAttr,
|
|||
ReferrerInfo::CreateFromDocumentAndPolicyOverride(this, aReferrerPolicy);
|
||||
|
||||
RefPtr<imgRequestProxy> request;
|
||||
|
||||
nsLiteralString initiator = aEarlyHintPreloaderId
|
||||
? u"early-hints"_ns
|
||||
: (aLinkPreload ? u"link"_ns : u"img"_ns);
|
||||
|
||||
nsresult rv = nsContentUtils::LoadImage(
|
||||
aUri, static_cast<nsINode*>(this), this, NodePrincipal(), 0, referrerInfo,
|
||||
nullptr /* no observer */, loadFlags,
|
||||
aLinkPreload ? u"link"_ns : u"img"_ns, getter_AddRefs(request),
|
||||
policyType, false /* urgent */, aLinkPreload);
|
||||
nullptr /* no observer */, loadFlags, initiator, getter_AddRefs(request),
|
||||
policyType, false /* urgent */, aLinkPreload, aEarlyHintPreloaderId);
|
||||
|
||||
// Pin image-reference to avoid evicting it from the img-cache before
|
||||
// the "real" load occurs. Unpinned in DispatchContentLoadedEvents and
|
||||
|
|
@ -12253,7 +12257,7 @@ void Document::MaybePreLoadImage(nsIURI* aUri,
|
|||
dom::Element::StringToCORSMode(aCrossOriginAttr));
|
||||
if (!mPreloadService.PreloadExists(key)) {
|
||||
PreLoadImage(aUri, aCrossOriginAttr, aReferrerPolicy, aIsImgSet,
|
||||
aLinkPreload);
|
||||
aLinkPreload, 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -12273,8 +12277,8 @@ void Document::MaybePreLoadImage(nsIURI* aUri,
|
|||
#endif
|
||||
|
||||
// Image not in cache - trigger preload
|
||||
PreLoadImage(aUri, aCrossOriginAttr, aReferrerPolicy, aIsImgSet,
|
||||
aLinkPreload);
|
||||
PreLoadImage(aUri, aCrossOriginAttr, aReferrerPolicy, aIsImgSet, aLinkPreload,
|
||||
0);
|
||||
}
|
||||
|
||||
void Document::MaybePreconnect(nsIURI* aOrigURI, mozilla::CORSMode aCORSMode) {
|
||||
|
|
|
|||
|
|
@ -3014,7 +3014,7 @@ class Document : public nsINode,
|
|||
bool aLinkPreload, const TimeStamp& aInitTimestamp);
|
||||
void PreLoadImage(nsIURI* uri, const nsAString& aCrossOriginAttr,
|
||||
ReferrerPolicyEnum aReferrerPolicy, bool aIsImgSet,
|
||||
bool aLinkPreload);
|
||||
bool aLinkPreload, uint64_t aEarlyHintPreloaderId);
|
||||
|
||||
/**
|
||||
* Called by images to forget an image preload when they start doing
|
||||
|
|
|
|||
|
|
@ -3815,7 +3815,8 @@ nsresult nsContentUtils::LoadImage(
|
|||
nsIReferrerInfo* aReferrerInfo, imgINotificationObserver* aObserver,
|
||||
int32_t aLoadFlags, const nsAString& initiatorType,
|
||||
imgRequestProxy** aRequest, nsContentPolicyType aContentPolicyType,
|
||||
bool aUseUrgentStartForChannel, bool aLinkPreload) {
|
||||
bool aUseUrgentStartForChannel, bool aLinkPreload,
|
||||
uint64_t aEarlyHintPreloaderId) {
|
||||
MOZ_ASSERT(aURI, "Must have a URI");
|
||||
MOZ_ASSERT(aContext, "Must have a context");
|
||||
MOZ_ASSERT(aLoadingDocument, "Must have a document");
|
||||
|
|
@ -3852,7 +3853,7 @@ nsresult nsContentUtils::LoadImage(
|
|||
initiatorType, /* the load initiator */
|
||||
aUseUrgentStartForChannel, /* urgent-start flag */
|
||||
aLinkPreload, /* <link preload> initiator */
|
||||
aRequest);
|
||||
aEarlyHintPreloaderId, aRequest);
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
|||
|
|
@ -1016,7 +1016,8 @@ class nsContentUtils {
|
|||
imgRequestProxy** aRequest,
|
||||
nsContentPolicyType aContentPolicyType =
|
||||
nsIContentPolicy::TYPE_INTERNAL_IMAGE,
|
||||
bool aUseUrgentStartForChannel = false, bool aLinkPreload = false);
|
||||
bool aUseUrgentStartForChannel = false, bool aLinkPreload = false,
|
||||
uint64_t aEarlyHintPreloaderId = 0);
|
||||
|
||||
/**
|
||||
* Obtain an image loader that respects the given document/channel's privacy
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
// Undefine windows version of LoadImage because our code uses that name.
|
||||
#include "mozilla/ScopeExit.h"
|
||||
#include "nsIChildChannel.h"
|
||||
#undef LoadImage
|
||||
|
||||
#include "imgLoader.h"
|
||||
|
|
@ -2235,11 +2236,12 @@ imgLoader::LoadImageXPCOM(
|
|||
aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE;
|
||||
}
|
||||
imgRequestProxy* proxy;
|
||||
nsresult rv = LoadImage(
|
||||
aURI, aInitialDocumentURI, aReferrerInfo, aTriggeringPrincipal, 0,
|
||||
aLoadGroup, aObserver, aLoadingDocument, aLoadingDocument, aLoadFlags,
|
||||
aCacheKey, aContentPolicyType, u""_ns,
|
||||
/* aUseUrgentStartForChannel */ false, /* aListPreload */ false, &proxy);
|
||||
nsresult rv =
|
||||
LoadImage(aURI, aInitialDocumentURI, aReferrerInfo, aTriggeringPrincipal,
|
||||
0, aLoadGroup, aObserver, aLoadingDocument, aLoadingDocument,
|
||||
aLoadFlags, aCacheKey, aContentPolicyType, u""_ns,
|
||||
/* aUseUrgentStartForChannel */ false, /* aListPreload */ false,
|
||||
0, &proxy);
|
||||
*_retval = proxy;
|
||||
return rv;
|
||||
}
|
||||
|
|
@ -2290,7 +2292,8 @@ nsresult imgLoader::LoadImage(
|
|||
nsINode* aContext, Document* aLoadingDocument, nsLoadFlags aLoadFlags,
|
||||
nsISupports* aCacheKey, nsContentPolicyType aContentPolicyType,
|
||||
const nsAString& initiatorType, bool aUseUrgentStartForChannel,
|
||||
bool aLinkPreload, imgRequestProxy** _retval) {
|
||||
bool aLinkPreload, uint64_t aEarlyHintPreloaderId,
|
||||
imgRequestProxy** _retval) {
|
||||
VerifyCacheSizes();
|
||||
|
||||
NS_ASSERTION(aURI, "imgLoader::LoadImage -- NULL URI pointer");
|
||||
|
|
@ -2551,7 +2554,16 @@ nsresult imgLoader::LoadImage(
|
|||
nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE,
|
||||
aLoadGroup);
|
||||
|
||||
nsresult openRes = newChannel->AsyncOpen(listener);
|
||||
nsresult openRes;
|
||||
if (aEarlyHintPreloaderId) {
|
||||
nsCOMPtr<nsIHttpChannelInternal> channelInternal =
|
||||
do_QueryInterface(newChannel);
|
||||
NS_ENSURE_TRUE(channelInternal != nullptr, NS_ERROR_FAILURE);
|
||||
|
||||
rv = channelInternal->SetEarlyHintPreloaderId(aEarlyHintPreloaderId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
openRes = newChannel->AsyncOpen(listener);
|
||||
|
||||
if (NS_FAILED(openRes)) {
|
||||
MOZ_LOG(
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ class imgLoader final : public imgILoader,
|
|||
nsLoadFlags aLoadFlags, nsISupports* aCacheKey,
|
||||
nsContentPolicyType aContentPolicyType, const nsAString& initiatorType,
|
||||
bool aUseUrgentStartForChannel, bool aLinkPreload,
|
||||
imgRequestProxy** _retval);
|
||||
uint64_t aEarlyHintPreloaderId, imgRequestProxy** _retval);
|
||||
|
||||
[[nodiscard]] nsresult LoadImageWithChannel(
|
||||
nsIChannel* channel, imgINotificationObserver* aObserver,
|
||||
|
|
|
|||
|
|
@ -2692,7 +2692,7 @@ nsresult nsImageFrame::LoadIcon(const nsAString& aSpec,
|
|||
loadFlags, nullptr, contentPolicyType, u""_ns,
|
||||
false, /* aUseUrgentStartForChannel */
|
||||
false, /* aLinkPreload */
|
||||
aRequest);
|
||||
0, aRequest);
|
||||
}
|
||||
|
||||
void nsImageFrame::GetDocumentCharacterSet(nsACString& aCharset) const {
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ void PreloadService::PreloadImage(nsIURI* aURI, const nsAString& aCrossOrigin,
|
|||
uint64_t aEarlyHintPreloaderId) {
|
||||
mDocument->PreLoadImage(aURI, aCrossOrigin,
|
||||
PreloadReferrerPolicy(aImageReferrerPolicy),
|
||||
aIsImgSet, true);
|
||||
aIsImgSet, true, aEarlyHintPreloaderId);
|
||||
}
|
||||
|
||||
void PreloadService::PreloadFont(nsIURI* aURI, const nsAString& aCrossOrigin,
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ nsresult IconLoader::LoadIcon(nsIURI* aIconURI, nsINode* aNode,
|
|||
aIconURI, nullptr, nullptr, nullptr, 0, loadGroup, this, nullptr,
|
||||
nullptr, nsIRequest::LOAD_NORMAL, nullptr,
|
||||
nsIContentPolicy::TYPE_INTERNAL_IMAGE, u""_ns,
|
||||
/* aUseUrgentStartForChannel */ false, /* aLinkPreload */ false,
|
||||
/* aUseUrgentStartForChannel */ false, /* aLinkPreload */ false, 0,
|
||||
getter_AddRefs(mIconRequest));
|
||||
} else {
|
||||
// TODO: nsIContentPolicy::TYPE_INTERNAL_IMAGE may not be the correct
|
||||
|
|
@ -72,7 +72,7 @@ nsresult IconLoader::LoadIcon(nsIURI* aIconURI, nsINode* aNode,
|
|||
aNode, document, nsIRequest::LOAD_NORMAL, nullptr,
|
||||
nsIContentPolicy::TYPE_INTERNAL_IMAGE, u""_ns,
|
||||
/* aUseUrgentStartForChannel */ false,
|
||||
/* aLinkPreload */ false, getter_AddRefs(mIconRequest));
|
||||
/* aLinkPreload */ false, 0, getter_AddRefs(mIconRequest));
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
|
|
|
|||
Loading…
Reference in a new issue