mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-10 01:08:21 +00:00
Bug 1297300 - Add missing checks to GetSpec() calls in image/. r=tnikkel.
This commit is contained in:
parent
b597f8fec1
commit
3ac8aee67f
@ -47,12 +47,15 @@ BlobSerial(ImageURL* aURI)
|
||||
|
||||
ImageCacheKey::ImageCacheKey(nsIURI* aURI,
|
||||
const PrincipalOriginAttributes& aAttrs,
|
||||
nsIDocument* aDocument)
|
||||
: mURI(new ImageURL(aURI))
|
||||
nsIDocument* aDocument,
|
||||
nsresult& aRv)
|
||||
: mURI(new ImageURL(aURI, aRv))
|
||||
, mOriginAttributes(aAttrs)
|
||||
, mControlledDocument(GetControlledDocumentToken(aDocument))
|
||||
, mIsChrome(URISchemeIs(mURI, "chrome"))
|
||||
{
|
||||
NS_ENSURE_SUCCESS_VOID(aRv);
|
||||
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (URISchemeIs(mURI, "blob")) {
|
||||
|
@ -34,7 +34,7 @@ class ImageCacheKey final
|
||||
{
|
||||
public:
|
||||
ImageCacheKey(nsIURI* aURI, const PrincipalOriginAttributes& aAttrs,
|
||||
nsIDocument* aDocument);
|
||||
nsIDocument* aDocument, nsresult& aRv);
|
||||
ImageCacheKey(ImageURL* aURI, const PrincipalOriginAttributes& aAttrs,
|
||||
nsIDocument* aDocument);
|
||||
|
||||
|
@ -28,12 +28,18 @@ namespace image {
|
||||
class ImageURL
|
||||
{
|
||||
public:
|
||||
explicit ImageURL(nsIURI* aURI)
|
||||
explicit ImageURL(nsIURI* aURI, nsresult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Cannot use nsIURI off main thread!");
|
||||
aURI->GetSpec(mSpec);
|
||||
aURI->GetScheme(mScheme);
|
||||
aURI->GetRef(mRef);
|
||||
|
||||
aRv = aURI->GetSpec(mSpec);
|
||||
NS_ENSURE_SUCCESS_VOID(aRv);
|
||||
|
||||
aRv = aURI->GetScheme(mScheme);
|
||||
NS_ENSURE_SUCCESS_VOID(aRv);
|
||||
|
||||
aRv = aURI->GetRef(mRef);
|
||||
NS_ENSURE_SUCCESS_VOID(aRv);
|
||||
}
|
||||
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageURL)
|
||||
|
@ -387,14 +387,18 @@ nsMozIconURI::SetRef(const nsACString& aRef)
|
||||
NS_IMETHODIMP
|
||||
nsMozIconURI::Equals(nsIURI* other, bool* result)
|
||||
{
|
||||
*result = false;
|
||||
NS_ENSURE_ARG_POINTER(other);
|
||||
NS_PRECONDITION(result, "null pointer");
|
||||
|
||||
nsAutoCString spec1;
|
||||
nsAutoCString spec2;
|
||||
|
||||
other->GetSpec(spec2);
|
||||
GetSpec(spec1);
|
||||
nsresult rv = GetSpec(spec1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = other->GetSpec(spec2);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!PL_strcasecmp(spec1.get(), spec2.get())) {
|
||||
*result = true;
|
||||
} else {
|
||||
|
@ -45,7 +45,9 @@ interface imgICache : nsISupports
|
||||
* @param doc Optional pointer to the document that the cache entry belongs to.
|
||||
* @returns NULL if the URL was not found in the cache
|
||||
*/
|
||||
nsIProperties findEntryProperties(in nsIURI uri, [optional] in nsIDOMDocument doc);
|
||||
[must_use]
|
||||
nsIProperties findEntryProperties(in nsIURI uri,
|
||||
[optional] in nsIDOMDocument doc);
|
||||
|
||||
/**
|
||||
* Make this cache instance respect private browsing notifications. This
|
||||
|
@ -1313,7 +1313,9 @@ imgLoader::FindEntryProperties(nsIURI* uri,
|
||||
}
|
||||
}
|
||||
|
||||
ImageCacheKey key(uri, attrs, doc);
|
||||
nsresult rv;
|
||||
ImageCacheKey key(uri, attrs, doc, rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
imgCacheTable& cache = GetCache(key);
|
||||
|
||||
RefPtr<imgCacheEntry> entry;
|
||||
@ -2071,7 +2073,8 @@ imgLoader::LoadImage(nsIURI* aURI,
|
||||
if (aLoadingPrincipal) {
|
||||
attrs = BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef();
|
||||
}
|
||||
ImageCacheKey key(aURI, attrs, aLoadingDocument);
|
||||
ImageCacheKey key(aURI, attrs, aLoadingDocument, rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
imgCacheTable& cache = GetCache(key);
|
||||
|
||||
if (cache.Get(key, getter_AddRefs(entry)) && entry) {
|
||||
@ -2142,9 +2145,12 @@ imgLoader::LoadImage(nsIURI* aURI,
|
||||
|
||||
nsCOMPtr<nsILoadGroup> channelLoadGroup;
|
||||
newChannel->GetLoadGroup(getter_AddRefs(channelLoadGroup));
|
||||
request->Init(aURI, aURI, /* aHadInsecureRedirect = */ false,
|
||||
channelLoadGroup, newChannel, entry, aLoadingDocument,
|
||||
aLoadingPrincipal, corsmode, aReferrerPolicy);
|
||||
rv = request->Init(aURI, aURI, /* aHadInsecureRedirect = */ false,
|
||||
channelLoadGroup, newChannel, entry, aLoadingDocument,
|
||||
aLoadingPrincipal, corsmode, aReferrerPolicy);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Add the initiator type for this image load
|
||||
nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(newChannel);
|
||||
@ -2280,7 +2286,9 @@ imgLoader::LoadImageWithChannel(nsIChannel* channel,
|
||||
attrs.InheritFromNecko(loadInfo->GetOriginAttributes());
|
||||
}
|
||||
|
||||
ImageCacheKey key(uri, attrs, doc);
|
||||
nsresult rv;
|
||||
ImageCacheKey key(uri, attrs, doc, rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsLoadFlags requestFlags = nsIRequest::LOAD_NORMAL;
|
||||
channel->GetLoadFlags(&requestFlags);
|
||||
@ -2361,7 +2369,7 @@ imgLoader::LoadImageWithChannel(nsIChannel* channel,
|
||||
// Filter out any load flags not from nsIRequest
|
||||
requestFlags &= nsIRequest::LOAD_REQUESTMASK;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
rv = NS_OK;
|
||||
if (request) {
|
||||
// we have this in our cache already.. cancel the current (document) load
|
||||
|
||||
@ -2382,7 +2390,8 @@ imgLoader::LoadImageWithChannel(nsIChannel* channel,
|
||||
// constructed above with the *current URI* and not the *original URI*. I'm
|
||||
// pretty sure this is a bug, and it's preventing us from ever getting a
|
||||
// cache hit in LoadImageWithChannel when redirects are involved.
|
||||
ImageCacheKey originalURIKey(originalURI, attrs, doc);
|
||||
ImageCacheKey originalURIKey(originalURI, attrs, doc, rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Default to doing a principal check because we don't know who
|
||||
// started that load and whether their principal ended up being
|
||||
@ -2400,9 +2409,10 @@ imgLoader::LoadImageWithChannel(nsIChannel* channel,
|
||||
// the necko cache should have handled that (since all necko cache hits
|
||||
// including the redirects will go through content policy). Hence, we
|
||||
// can set aHadInsecureRedirect to false here.
|
||||
request->Init(originalURI, uri, /* aHadInsecureRedirect = */ false,
|
||||
channel, channel, entry, aCX, nullptr,
|
||||
imgIRequest::CORS_NONE, RP_Default);
|
||||
rv = request->Init(originalURI, uri, /* aHadInsecureRedirect = */ false,
|
||||
channel, channel, entry, aCX, nullptr,
|
||||
imgIRequest::CORS_NONE, RP_Default);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
RefPtr<ProxyListener> pl =
|
||||
new ProxyListener(static_cast<nsIStreamListener*>(request.get()));
|
||||
@ -2773,8 +2783,12 @@ imgCacheValidator::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
|
||||
// We use originalURI here to fulfil the imgIRequest contract on GetURI.
|
||||
nsCOMPtr<nsIURI> originalURI;
|
||||
channel->GetOriginalURI(getter_AddRefs(originalURI));
|
||||
mNewRequest->Init(originalURI, uri, mHadInsecureRedirect, aRequest, channel,
|
||||
mNewEntry, context, loadingPrincipal, corsmode, refpol);
|
||||
nsresult rv =
|
||||
mNewRequest->Init(originalURI, uri, mHadInsecureRedirect, aRequest, channel,
|
||||
mNewEntry, context, loadingPrincipal, corsmode, refpol);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
mDestListener = new ProxyListener(mNewRequest);
|
||||
|
||||
|
@ -290,26 +290,27 @@ public:
|
||||
imgLoader();
|
||||
nsresult Init();
|
||||
|
||||
nsresult LoadImage(nsIURI* aURI,
|
||||
nsIURI* aInitialDocumentURI,
|
||||
nsIURI* aReferrerURI,
|
||||
ReferrerPolicy aReferrerPolicy,
|
||||
nsIPrincipal* aLoadingPrincipal,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
imgINotificationObserver* aObserver,
|
||||
nsINode* aContext,
|
||||
nsIDocument* aLoadingDocument,
|
||||
nsLoadFlags aLoadFlags,
|
||||
nsISupports* aCacheKey,
|
||||
nsContentPolicyType aContentPolicyType,
|
||||
const nsAString& initiatorType,
|
||||
imgRequestProxy** _retval);
|
||||
MOZ_MUST_USE nsresult LoadImage(nsIURI* aURI,
|
||||
nsIURI* aInitialDocumentURI,
|
||||
nsIURI* aReferrerURI,
|
||||
ReferrerPolicy aReferrerPolicy,
|
||||
nsIPrincipal* aLoadingPrincipal,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
imgINotificationObserver* aObserver,
|
||||
nsINode* aContext,
|
||||
nsIDocument* aLoadingDocument,
|
||||
nsLoadFlags aLoadFlags,
|
||||
nsISupports* aCacheKey,
|
||||
nsContentPolicyType aContentPolicyType,
|
||||
const nsAString& initiatorType,
|
||||
imgRequestProxy** _retval);
|
||||
|
||||
nsresult LoadImageWithChannel(nsIChannel* channel,
|
||||
imgINotificationObserver* aObserver,
|
||||
nsISupports* aCX,
|
||||
nsIStreamListener** listener,
|
||||
imgRequestProxy** _retval);
|
||||
MOZ_MUST_USE nsresult
|
||||
LoadImageWithChannel(nsIChannel* channel,
|
||||
imgINotificationObserver* aObserver,
|
||||
nsISupports* aCX,
|
||||
nsIStreamListener** listener,
|
||||
imgRequestProxy** _retval);
|
||||
|
||||
static nsresult GetMimeTypeFromContent(const char* aContents,
|
||||
uint32_t aLength,
|
||||
|
@ -108,7 +108,10 @@ imgRequest::Init(nsIURI *aURI,
|
||||
mProperties = do_CreateInstance("@mozilla.org/properties;1");
|
||||
|
||||
// Use ImageURL to ensure access to URI data off main thread.
|
||||
mURI = new ImageURL(aURI);
|
||||
nsresult rv;
|
||||
mURI = new ImageURL(aURI, rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mCurrentURI = aCurrentURI;
|
||||
mRequest = aRequest;
|
||||
mChannel = aChannel;
|
||||
|
@ -65,16 +65,16 @@ public:
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
|
||||
|
||||
nsresult Init(nsIURI* aURI,
|
||||
nsIURI* aCurrentURI,
|
||||
bool aHadInsecureRedirect,
|
||||
nsIRequest* aRequest,
|
||||
nsIChannel* aChannel,
|
||||
imgCacheEntry* aCacheEntry,
|
||||
nsISupports* aCX,
|
||||
nsIPrincipal* aLoadingPrincipal,
|
||||
int32_t aCORSMode,
|
||||
ReferrerPolicy aReferrerPolicy);
|
||||
MOZ_MUST_USE nsresult Init(nsIURI* aURI,
|
||||
nsIURI* aCurrentURI,
|
||||
bool aHadInsecureRedirect,
|
||||
nsIRequest* aRequest,
|
||||
nsIChannel* aChannel,
|
||||
imgCacheEntry* aCacheEntry,
|
||||
nsISupports* aCX,
|
||||
nsIPrincipal* aLoadingPrincipal,
|
||||
int32_t aCORSMode,
|
||||
ReferrerPolicy aReferrerPolicy);
|
||||
|
||||
void ClearLoader();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user