Bug 1418930 Part 1: Define and use a method nsContentUtils::CORSModeToLoadImageFlags to standardize conversion of CORS modes to load image flags. r=bz

MozReview-Commit-ID: AqsEUhFYxH6

--HG--
extra : rebase_source : 94ab4f3b1e5729cce8a2572c949b174fc74fd878
This commit is contained in:
Brad Werth 2018-01-31 11:10:01 -05:00
Родитель 812a7d1f8c
Коммит 9805f317cb
4 изменённых файлов: 29 добавлений и 21 удалений

Просмотреть файл

@ -3701,6 +3701,20 @@ nsContentUtils::IsImageInCache(nsIURI* aURI, nsIDocument* aDocument)
return (NS_SUCCEEDED(rv) && props);
}
// static
int32_t
nsContentUtils::CORSModeToLoadImageFlags(mozilla::CORSMode aMode)
{
switch (aMode) {
case CORS_ANONYMOUS:
return imgILoader::LOAD_CORS_ANONYMOUS;
case CORS_USE_CREDENTIALS:
return imgILoader::LOAD_CORS_USE_CREDENTIALS;
default:
return 0;
}
}
// static
nsresult
nsContentUtils::LoadImage(nsIURI* aURI, nsINode* aContext,

Просмотреть файл

@ -22,6 +22,7 @@
#include "js/RootingAPI.h"
#include "mozilla/dom/FromParser.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/CORSMode.h"
#include "mozilla/EventForwards.h"
#include "mozilla/GuardObjects.h"
#include "mozilla/TaskCategory.h"
@ -825,6 +826,14 @@ public:
*/
static bool DocumentInactiveForImageLoads(nsIDocument* aDocument);
/**
* Convert a CORSMode into the corresponding imgILoader flags for
* passing to LoadImage.
* @param aMode CORS mode to convert
* @return a bitfield suitable to bitwise OR with other nsIRequest flags
*/
static int32_t CORSModeToLoadImageFlags(mozilla::CORSMode aMode);
/**
* Method to start an image load. This does not do any security checks.
* This method will attempt to make aURI immutable; a caller that wants to

Просмотреть файл

@ -9254,20 +9254,9 @@ nsDocument::MaybePreLoadImage(nsIURI* uri, const nsAString &aCrossOriginAttr,
return;
}
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
switch (Element::StringToCORSMode(aCrossOriginAttr)) {
case CORS_NONE:
// Nothing to do
break;
case CORS_ANONYMOUS:
loadFlags |= imgILoader::LOAD_CORS_ANONYMOUS;
break;
case CORS_USE_CREDENTIALS:
loadFlags |= imgILoader::LOAD_CORS_USE_CREDENTIALS;
break;
default:
MOZ_CRASH("Unknown CORS mode!");
}
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL |
nsContentUtils::CORSModeToLoadImageFlags(
Element::StringToCORSMode(aCrossOriginAttr));
nsContentPolicyType policyType =
aIsImgSet ? nsIContentPolicy::TYPE_IMAGESET :

Просмотреть файл

@ -963,13 +963,9 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI,
"Principal mismatch?");
#endif
nsLoadFlags loadFlags = aLoadFlags;
int32_t corsmode = GetCORSMode();
if (corsmode == CORS_ANONYMOUS) {
loadFlags |= imgILoader::LOAD_CORS_ANONYMOUS;
} else if (corsmode == CORS_USE_CREDENTIALS) {
loadFlags |= imgILoader::LOAD_CORS_USE_CREDENTIALS;
}
nsLoadFlags loadFlags = aLoadFlags |
nsContentUtils::CORSModeToLoadImageFlags(
GetCORSMode());
// get document wide referrer policy
// if referrer attributes are enabled in preferences, load img referrer attribute