Bug 1048048 - add preload content policy types for images (r=seth)

This commit is contained in:
Christoph Kerschbaumer 2015-09-20 14:55:59 -07:00
parent dad4927d12
commit ad12815962
22 changed files with 31 additions and 29 deletions

View File

@ -164,7 +164,7 @@ this.ContentLinkHandler = {
}
// Security says okay, now ask content policy
if (contentPolicy.shouldLoad(Ci.nsIContentPolicy.TYPE_IMAGE,
if (contentPolicy.shouldLoad(Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE,
uri, targetDoc.documentURIObject,
aLink, aLink.type, null)
!= Ci.nsIContentPolicy.ACCEPT)

View File

@ -79,7 +79,7 @@ function _imageFromURI(doc, uri, privateMode, callback) {
null, // aLoadingPrincipal
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE);
Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE);
try {
channel.QueryInterface(Ci.nsIPrivateBrowsingChannel);
channel.setPrivate(privateMode);

View File

@ -624,7 +624,7 @@ public:
* @param aContext the context the image is loaded in (eg an element)
* @param aLoadingDocument the document we belong to
* @param aLoadingPrincipal the principal doing the load
* @param [aContentPolicyType=nsIContentPolicy::TYPE_IMAGE] (Optional)
* @param [aContentPolicyType=nsIContentPolicy::TYPE_INTERNAL_IMAGE] (Optional)
* The CP content type to use
* @param aImageBlockingStatus the nsIContentPolicy blocking status for this
* image. This will be set even if a security check fails for the
@ -640,7 +640,7 @@ public:
nsIDocument* aLoadingDocument,
nsIPrincipal* aLoadingPrincipal,
int16_t* aImageBlockingStatus = nullptr,
uint32_t aContentPolicyType = nsIContentPolicy::TYPE_IMAGE);
uint32_t aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE);
/**
* Returns true if objects in aDocument shouldn't initiate image loads.
@ -660,7 +660,7 @@ public:
* creation
* @param aObserver the observer for the image load
* @param aLoadFlags the load flags to use. See nsIRequest
* @param [aContentPolicyType=nsIContentPolicy::TYPE_IMAGE] (Optional)
* @param [aContentPolicyType=nsIContentPolicy::TYPE_INTERNAL_IMAGE] (Optional)
* The CP content type to use
* @return the imgIRequest for the image load
*/
@ -673,7 +673,7 @@ public:
int32_t aLoadFlags,
const nsAString& initiatorType,
imgRequestProxy** aRequest,
uint32_t aContentPolicyType = nsIContentPolicy::TYPE_IMAGE);
uint32_t aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE);
/**
* Obtain an image loader that respects the given document/channel's privacy status.

View File

@ -9739,7 +9739,8 @@ nsDocument::MaybePreLoadImage(nsIURI* uri, const nsAString &aCrossOriginAttr,
int16_t blockingStatus;
if (nsContentUtils::IsImageInCache(uri, static_cast<nsIDocument *>(this)) ||
!nsContentUtils::CanLoadImage(uri, static_cast<nsIDocument *>(this),
this, NodePrincipal(), &blockingStatus)) {
this, NodePrincipal(), &blockingStatus,
nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD)) {
return;
}
@ -9769,7 +9770,8 @@ nsDocument::MaybePreLoadImage(nsIURI* uri, const nsAString &aCrossOriginAttr,
nullptr, // no observer
loadFlags,
NS_LITERAL_STRING("img"),
getter_AddRefs(request));
getter_AddRefs(request),
nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD);
// Pin image-reference to avoid evicting it from the img-cache before
// the "real" load occurs. Unpinned in DispatchContentLoadedEvents and

View File

@ -589,7 +589,7 @@ nsImageLoadingContent::PolicyTypeForLoad(ImageLoadType aImageLoadType)
MOZ_ASSERT(aImageLoadType == eImageLoadType_Normal,
"Unknown ImageLoadType type in PolicyTypeForLoad");
return nsIContentPolicy::TYPE_IMAGE;
return nsIContentPolicy::TYPE_INTERNAL_IMAGE;
}
int32_t

View File

@ -1530,7 +1530,7 @@ nsObjectLoadingContent::CheckProcessPolicy(int16_t *aContentPolicy)
int32_t objectType;
switch (mType) {
case eType_Image:
objectType = nsIContentPolicy::TYPE_IMAGE;
objectType = nsIContentPolicy::TYPE_INTERNAL_IMAGE;
break;
case eType_Document:
objectType = nsIContentPolicy::TYPE_DOCUMENT;

View File

@ -99,7 +99,7 @@ ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
}
int16_t decision = nsIContentPolicy::ACCEPT;
nsresult rv = NS_CheckContentProcessPolicy(nsIContentPolicy::TYPE_IMAGE,
nsresult rv = NS_CheckContentProcessPolicy(nsIContentPolicy::TYPE_INTERNAL_IMAGE,
channelURI,
channelPrincipal,
domWindow->GetFrameElementInternal(),

View File

@ -294,7 +294,7 @@ nsContextMenuInfo::GetBackgroundImageRequestInternal(nsIDOMNode* aDOMNode,
return il->LoadImage(bgUri, nullptr, nullptr,
doc->GetReferrerPolicy(), principal, nullptr,
nullptr, nullptr, nsIRequest::LOAD_NORMAL,
nullptr, nsIContentPolicy::TYPE_IMAGE,
nullptr, nsIContentPolicy::TYPE_INTERNAL_IMAGE,
EmptyString(), aRequest);
}
}

View File

@ -618,7 +618,7 @@ ShouldLoadCachedImage(imgRequest* aImgRequest,
nsresult rv;
int16_t decision = nsIContentPolicy::REJECT_REQUEST;
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_IMAGE,
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_INTERNAL_IMAGE,
contentLocation,
aLoadingPrincipal,
aLoadingContext,
@ -1981,7 +1981,7 @@ imgLoader::LoadImageXPCOM(nsIURI* aURI,
{
// Optional parameter, so defaults to 0 (== TYPE_INVALID)
if (!aContentPolicyType) {
aContentPolicyType = nsIContentPolicy::TYPE_IMAGE;
aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE;
}
imgRequestProxy* proxy;
ReferrerPolicy refpol = ReferrerPolicyFromString(aReferrerPolicy);

View File

@ -2204,7 +2204,7 @@ nsImageFrame::LoadIcon(const nsAString& aSpec,
// For icon loads, we don't need to merge with the loadgroup flags
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
nsContentPolicyType contentPolicyType = nsIContentPolicy::TYPE_IMAGE;
nsContentPolicyType contentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE;
return il->LoadImage(realURI, /* icon URI */
nullptr, /* initial document URI; this is only

View File

@ -532,7 +532,7 @@ AsyncFetchAndSetIconFromNetwork::Run()
iconURI,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_IMAGE);
nsIContentPolicy::TYPE_INTERNAL_IMAGE);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInterfaceRequestor> listenerRequestor =

View File

@ -53,7 +53,7 @@ GetDefaultIcon(nsIChannel **aChannel)
defaultIconURI,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_IMAGE);
nsIContentPolicy::TYPE_INTERNAL_IMAGE);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -330,7 +330,7 @@ nsFaviconService::ReplaceFaviconDataFromDataURL(nsIURI* aFaviconURI,
nullptr, // aTriggeringPrincipal
nullptr, // aLoadingNode
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_IMAGE);
nsIContentPolicy::TYPE_INTERNAL_IMAGE);
nsCOMPtr<nsIChannel> channel;
rv = protocolHandler->NewChannel2(dataURI, loadInfo, getter_AddRefs(channel));

View File

@ -33,7 +33,7 @@ function test() {
NetUtil.asyncFetch({
uri: favIconLocation,
loadUsingSystemPrincipal: true,
contentPolicyType: Ci.nsIContentPolicy.TYPE_IMAGE
contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE
}, function(inputStream, status) {
if (!Components.isSuccessCode(status)) {
ok(false, "Could not get the icon file");

View File

@ -63,7 +63,7 @@ function run_test()
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE);
Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE);
channel.asyncOpen(new streamListener("image/png"), null);
do_test_pending();
@ -76,7 +76,7 @@ function run_test()
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE);
Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE);
channel.asyncOpen(new streamListener("image/png"), null);
do_test_pending();
@ -94,7 +94,7 @@ function run_test()
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE);
Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE);
channel.asyncOpen(new streamListener("image/png"), null);
do_test_pending();
}

View File

@ -2081,7 +2081,7 @@ Engine.prototype = {
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE);
Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE);
let iconLoadCallback = function (aByteArray, aEngine) {
// This callback may run after we've already set a preferred icon,

View File

@ -357,7 +357,7 @@ function saveToClipboard(context, reply) {
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE);
Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE);
const input = channel.open();
const imgTools = Cc["@mozilla.org/image/tools;1"]
.getService(Ci.imgITools);

View File

@ -119,7 +119,7 @@ var ImageFile = {
this._netUtil.asyncFetch({
uri: aURI,
loadUsingSystemPrincipal: true,
contentPolicyType: Ci.nsIContentPolicy.TYPE_IMAGE
contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE
}, function read_asyncFetch(aInputStream, aStatus, aRequest) {
if (Components.isSuccessCode(aStatus) && aRequest instanceof Ci.nsIChannel) {
let channel = aRequest.QueryInterface(Ci.nsIChannel);

View File

@ -464,7 +464,7 @@ function downloadIcon(aIconURI) {
let channel = NetUtil.newChannel({
uri: aIconURI,
loadingPrincipal: principal,
contentPolicyType: Ci.nsIContentPolicy.TYPE_IMAGE});
contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE});
let { BadCertHandler } = Cu.import("resource://gre/modules/CertUtils.jsm", {});
// Pass true to avoid optional redirect-cert-checking behavior.
channel.notificationCallbacks = new BadCertHandler(true);

View File

@ -250,7 +250,7 @@ OSXNotificationCenter::ShowAlertNotification(const nsAString & aImageUrl, const
this, nullptr,
aInPrivateBrowsing ? nsIRequest::LOAD_ANONYMOUS :
nsIRequest::LOAD_NORMAL,
nullptr, nsIContentPolicy::TYPE_IMAGE,
nullptr, nsIContentPolicy::TYPE_INTERNAL_IMAGE,
EmptyString(),
getter_AddRefs(osxni->mIconRequest));
if (NS_SUCCEEDED(rv)) {

View File

@ -310,7 +310,7 @@ nsMenuItemIconX::LoadIcon(nsIURI* aIconURI)
mozilla::net::RP_Default,
nullptr, loadGroup, this,
nullptr, nsIRequest::LOAD_NORMAL, nullptr,
nsIContentPolicy::TYPE_IMAGE, EmptyString(),
nsIContentPolicy::TYPE_INTERNAL_IMAGE, EmptyString(),
getter_AddRefs(mIconRequest));
if (NS_FAILED(rv)) return rv;

View File

@ -1108,7 +1108,7 @@ nsresult AsyncFaviconDataReady::OnFaviconDataNotAvailable(void)
mozIconURI,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_IMAGE);
nsIContentPolicy::TYPE_INTERNAL_IMAGE);
NS_ENSURE_SUCCESS(rv, rv);