2013-01-18 00:45:11 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2012-01-02 20:23:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-10-12 12:43:01 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2015-04-28 18:45:45 +00:00
|
|
|
#include "mozilla/Move.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2016-04-02 18:53:12 +00:00
|
|
|
#include "mozilla/ChaosMode.h"
|
2012-01-02 20:23:41 +00:00
|
|
|
|
2011-07-08 17:55:03 +00:00
|
|
|
#include "ImageLogging.h"
|
2013-09-28 18:28:42 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2001-05-08 04:12:40 +00:00
|
|
|
#include "imgLoader.h"
|
2010-08-14 04:09:48 +00:00
|
|
|
#include "imgRequestProxy.h"
|
2010-05-22 04:10:14 +00:00
|
|
|
|
2001-05-08 04:12:40 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2015-03-24 16:18:48 +00:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2011-07-14 18:47:34 +00:00
|
|
|
#include "nsContentUtils.h"
|
2014-12-30 23:54:59 +00:00
|
|
|
#include "nsCORSListenerProxy.h"
|
2002-09-18 22:08:12 +00:00
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 02:17:00 +00:00
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsIProtocolHandler.h"
|
2013-01-08 21:40:47 +00:00
|
|
|
#include "nsMimeTypes.h"
|
2011-06-24 14:22:33 +00:00
|
|
|
#include "nsStreamUtils.h"
|
2001-05-11 21:05:08 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
2015-11-12 20:09:52 +00:00
|
|
|
#include "nsICacheInfoChannel.h"
|
2009-07-28 16:13:48 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2015-07-07 02:17:00 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2009-07-28 16:13:48 +00:00
|
|
|
#include "nsIProgressEventSink.h"
|
2009-08-13 11:20:41 +00:00
|
|
|
#include "nsIChannelEventSink.h"
|
2010-08-05 02:15:55 +00:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2008-09-04 23:00:42 +00:00
|
|
|
#include "nsIFileURL.h"
|
2015-07-07 02:17:00 +00:00
|
|
|
#include "nsIFile.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
2014-06-03 20:37:46 +00:00
|
|
|
#include "nsINetworkPredictor.h"
|
2015-03-24 16:18:48 +00:00
|
|
|
#include "mozilla/dom/nsMixedContentBlocker.h"
|
2002-03-23 13:21:33 +00:00
|
|
|
|
2009-01-05 05:52:22 +00:00
|
|
|
#include "nsIApplicationCache.h"
|
|
|
|
#include "nsIApplicationCacheContainer.h"
|
|
|
|
|
2010-05-22 04:10:14 +00:00
|
|
|
#include "nsIMemoryReporter.h"
|
2015-07-23 05:39:48 +00:00
|
|
|
#include "DecoderFactory.h"
|
2013-09-07 13:01:08 +00:00
|
|
|
#include "Image.h"
|
2014-09-22 21:30:20 +00:00
|
|
|
#include "gfxPrefs.h"
|
2015-07-07 02:17:00 +00:00
|
|
|
#include "prtime.h"
|
2010-05-22 04:10:14 +00:00
|
|
|
|
2002-09-30 23:18:43 +00:00
|
|
|
// we want to explore making the document own the load group
|
|
|
|
// so we can associate the document URI with the load group.
|
|
|
|
// until this point, we have an evil hack:
|
2013-03-29 20:14:19 +00:00
|
|
|
#include "nsIHttpChannelInternal.h"
|
2012-06-26 04:20:12 +00:00
|
|
|
#include "nsILoadContext.h"
|
2013-04-09 17:38:48 +00:00
|
|
|
#include "nsILoadGroupChild.h"
|
2015-10-27 18:12:46 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
2002-09-30 23:18:43 +00:00
|
|
|
|
2011-06-12 02:30:15 +00:00
|
|
|
using namespace mozilla;
|
2012-01-06 16:02:27 +00:00
|
|
|
using namespace mozilla::image;
|
2014-11-18 13:46:53 +00:00
|
|
|
using namespace mozilla::net;
|
2010-08-14 04:09:49 +00:00
|
|
|
|
2013-12-08 05:38:32 +00:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(ImagesMallocSizeOf)
|
2012-03-02 00:05:32 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class imgMemoryReporter final : public nsIMemoryReporter
|
2010-05-22 04:10:14 +00:00
|
|
|
{
|
2014-11-27 02:00:15 +00:00
|
|
|
~imgMemoryReporter() { }
|
2014-06-23 18:49:08 +00:00
|
|
|
|
2010-05-22 04:10:14 +00:00
|
|
|
public:
|
2013-12-08 05:39:47 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2011-06-06 01:22:45 +00:00
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsISupports* aData, bool aAnonymize) override
|
2010-05-22 04:10:14 +00:00
|
|
|
{
|
2014-05-15 23:11:57 +00:00
|
|
|
nsresult rv;
|
2014-11-27 02:00:15 +00:00
|
|
|
nsTArray<ImageMemoryCounter> chrome;
|
|
|
|
nsTArray<ImageMemoryCounter> content;
|
|
|
|
nsTArray<ImageMemoryCounter> uncached;
|
2012-06-26 04:20:12 +00:00
|
|
|
|
2012-09-06 14:11:28 +00:00
|
|
|
for (uint32_t i = 0; i < mKnownLoaders.Length(); i++) {
|
2015-11-11 07:07:09 +00:00
|
|
|
for (auto iter = mKnownLoaders[i]->mChromeCache.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
imgCacheEntry* entry = iter.UserData();
|
|
|
|
RefPtr<imgRequest> req = entry->GetRequest();
|
|
|
|
RecordCounterForRequest(req, &chrome, !entry->HasNoProxies());
|
|
|
|
}
|
|
|
|
for (auto iter = mKnownLoaders[i]->mCache.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
imgCacheEntry* entry = iter.UserData();
|
|
|
|
RefPtr<imgRequest> req = entry->GetRequest();
|
|
|
|
RecordCounterForRequest(req, &content, !entry->HasNoProxies());
|
|
|
|
}
|
2014-09-05 21:36:11 +00:00
|
|
|
MutexAutoLock lock(mKnownLoaders[i]->mUncachedImagesMutex);
|
2015-07-14 13:37:57 +00:00
|
|
|
for (auto iter = mKnownLoaders[i]->mUncachedImages.Iter();
|
|
|
|
!iter.Done();
|
|
|
|
iter.Next()) {
|
|
|
|
nsPtrHashKey<imgRequest>* entry = iter.Get();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> req = entry->GetKey();
|
2015-07-14 13:37:57 +00:00
|
|
|
RecordCounterForRequest(req, &uncached, req->HasConsumers());
|
|
|
|
}
|
2012-06-26 04:20:12 +00:00
|
|
|
}
|
2012-03-02 00:05:32 +00:00
|
|
|
|
2014-05-21 06:06:54 +00:00
|
|
|
// Note that we only need to anonymize content image URIs.
|
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
rv = ReportCounterArray(aHandleReport, aData, chrome, "images/chrome");
|
2014-05-15 23:11:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-03-02 00:05:32 +00:00
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
rv = ReportCounterArray(aHandleReport, aData, content,
|
|
|
|
"images/content", aAnonymize);
|
2014-05-15 23:11:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-03-02 00:05:32 +00:00
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
// Uncached images may be content or chrome, so anonymize them.
|
|
|
|
rv = ReportCounterArray(aHandleReport, aData, uncached,
|
|
|
|
"images/uncached", aAnonymize);
|
2014-09-05 21:36:11 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-05-22 04:10:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-19 22:52:30 +00:00
|
|
|
static int64_t ImagesContentUsedUncompressedDistinguishedAmount()
|
2010-05-22 04:10:14 +00:00
|
|
|
{
|
2012-03-02 00:05:32 +00:00
|
|
|
size_t n = 0;
|
2015-04-07 21:49:00 +00:00
|
|
|
for (uint32_t i = 0; i < imgLoader::sMemReporter->mKnownLoaders.Length();
|
|
|
|
i++) {
|
2015-11-11 07:07:09 +00:00
|
|
|
for (auto iter = imgLoader::sMemReporter->mKnownLoaders[i]->mCache.Iter();
|
|
|
|
!iter.Done();
|
|
|
|
iter.Next()) {
|
|
|
|
imgCacheEntry* entry = iter.UserData();
|
|
|
|
if (entry->HasNoProxies()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<imgRequest> req = entry->GetRequest();
|
|
|
|
RefPtr<Image> image = req->GetImage();
|
|
|
|
if (!image) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Both this and EntryImageSizes measure images/content/raster/used/decoded
|
|
|
|
// memory. This function's measurement is secondary -- the result doesn't
|
|
|
|
// go in the "explicit" tree -- so we use moz_malloc_size_of instead of
|
|
|
|
// ImagesMallocSizeOf to prevent DMD from seeing it reported twice.
|
|
|
|
ImageMemoryCounter counter(image, moz_malloc_size_of, /* aIsUsed = */ true);
|
|
|
|
|
|
|
|
n += counter.Values().DecodedHeap();
|
|
|
|
n += counter.Values().DecodedNonHeap();
|
|
|
|
}
|
2012-06-26 04:20:12 +00:00
|
|
|
}
|
2012-03-02 00:05:32 +00:00
|
|
|
return n;
|
2010-05-22 04:10:14 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
void RegisterLoader(imgLoader* aLoader)
|
|
|
|
{
|
|
|
|
mKnownLoaders.AppendElement(aLoader);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnregisterLoader(imgLoader* aLoader)
|
|
|
|
{
|
|
|
|
mKnownLoaders.RemoveElement(aLoader);
|
|
|
|
}
|
|
|
|
|
2012-03-02 00:05:32 +00:00
|
|
|
private:
|
2012-06-26 04:20:12 +00:00
|
|
|
nsTArray<imgLoader*> mKnownLoaders;
|
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
struct MemoryTotal
|
2014-05-15 23:11:57 +00:00
|
|
|
{
|
2014-11-27 02:00:15 +00:00
|
|
|
MemoryTotal& operator+=(const ImageMemoryCounter& aImageCounter)
|
|
|
|
{
|
|
|
|
if (aImageCounter.Type() == imgIContainer::TYPE_RASTER) {
|
|
|
|
if (aImageCounter.IsUsed()) {
|
|
|
|
mUsedRasterCounter += aImageCounter.Values();
|
|
|
|
} else {
|
|
|
|
mUnusedRasterCounter += aImageCounter.Values();
|
|
|
|
}
|
|
|
|
} else if (aImageCounter.Type() == imgIContainer::TYPE_VECTOR) {
|
|
|
|
if (aImageCounter.IsUsed()) {
|
|
|
|
mUsedVectorCounter += aImageCounter.Values();
|
|
|
|
} else {
|
|
|
|
mUnusedVectorCounter += aImageCounter.Values();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_CRASH("Unexpected image type");
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MemoryCounter& UsedRaster() const { return mUsedRasterCounter; }
|
|
|
|
const MemoryCounter& UnusedRaster() const { return mUnusedRasterCounter; }
|
|
|
|
const MemoryCounter& UsedVector() const { return mUsedVectorCounter; }
|
|
|
|
const MemoryCounter& UnusedVector() const { return mUnusedVectorCounter; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
MemoryCounter mUsedRasterCounter;
|
|
|
|
MemoryCounter mUnusedRasterCounter;
|
|
|
|
MemoryCounter mUsedVectorCounter;
|
|
|
|
MemoryCounter mUnusedVectorCounter;
|
2010-05-22 04:10:14 +00:00
|
|
|
};
|
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
// Reports all images of a single kind, e.g. all used chrome images.
|
|
|
|
nsresult ReportCounterArray(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
2015-04-28 18:46:17 +00:00
|
|
|
nsTArray<ImageMemoryCounter>& aCounterArray,
|
2014-11-27 02:00:15 +00:00
|
|
|
const char* aPathPrefix,
|
|
|
|
bool aAnonymize = false)
|
2014-05-15 23:11:57 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2014-11-27 02:00:15 +00:00
|
|
|
MemoryTotal summaryTotal;
|
|
|
|
MemoryTotal nonNotableTotal;
|
2014-05-15 23:11:57 +00:00
|
|
|
|
|
|
|
// Report notable images, and compute total and non-notable aggregate sizes.
|
2014-11-27 02:00:15 +00:00
|
|
|
for (uint32_t i = 0; i < aCounterArray.Length(); i++) {
|
2015-04-28 18:46:17 +00:00
|
|
|
ImageMemoryCounter& counter = aCounterArray[i];
|
2014-05-21 06:06:54 +00:00
|
|
|
|
|
|
|
if (aAnonymize) {
|
2014-11-27 02:00:15 +00:00
|
|
|
counter.URI().Truncate();
|
|
|
|
counter.URI().AppendPrintf("<anonymized-%u>", i);
|
2014-05-21 06:06:54 +00:00
|
|
|
} else {
|
2014-11-27 02:00:15 +00:00
|
|
|
// The URI could be an extremely long data: URI. Truncate if needed.
|
2014-05-21 06:06:54 +00:00
|
|
|
static const size_t max = 256;
|
2014-11-27 02:00:15 +00:00
|
|
|
if (counter.URI().Length() > max) {
|
|
|
|
counter.URI().Truncate(max);
|
|
|
|
counter.URI().AppendLiteral(" (truncated)");
|
2014-05-21 06:06:54 +00:00
|
|
|
}
|
2014-11-27 02:00:15 +00:00
|
|
|
counter.URI().ReplaceChar('/', '\\');
|
2014-05-15 23:11:57 +00:00
|
|
|
}
|
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
summaryTotal += counter;
|
2014-05-15 23:11:57 +00:00
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
if (counter.IsNotable()) {
|
2015-04-28 18:46:17 +00:00
|
|
|
rv = ReportImage(aHandleReport, aData, aPathPrefix, counter);
|
2014-11-26 10:56:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-11-27 02:00:15 +00:00
|
|
|
} else {
|
|
|
|
nonNotableTotal += counter;
|
2014-05-15 23:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report non-notable images in aggregate.
|
2014-11-27 02:00:15 +00:00
|
|
|
rv = ReportTotal(aHandleReport, aData, /* aExplicit = */ true,
|
|
|
|
aPathPrefix, "<non-notable images>/", nonNotableTotal);
|
2014-11-26 09:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
// Report a summary in aggregate, outside of the explicit tree.
|
|
|
|
rv = ReportTotal(aHandleReport, aData, /* aExplicit = */ false,
|
|
|
|
aPathPrefix, "", summaryTotal);
|
2014-11-26 09:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-05-22 04:10:14 +00:00
|
|
|
|
2015-04-28 18:46:17 +00:00
|
|
|
static nsresult ReportImage(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
const char* aPathPrefix,
|
|
|
|
const ImageMemoryCounter& aCounter)
|
2014-11-26 09:37:57 +00:00
|
|
|
{
|
2015-05-04 23:08:51 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
nsAutoCString pathPrefix(NS_LITERAL_CSTRING("explicit/"));
|
|
|
|
pathPrefix.Append(aPathPrefix);
|
|
|
|
pathPrefix.Append(aCounter.Type() == imgIContainer::TYPE_RASTER
|
|
|
|
? "/raster/"
|
|
|
|
: "/vector/");
|
|
|
|
pathPrefix.Append(aCounter.IsUsed() ? "used/" : "unused/");
|
|
|
|
pathPrefix.Append("image(");
|
2015-04-28 18:46:17 +00:00
|
|
|
pathPrefix.AppendInt(aCounter.IntrinsicSize().width);
|
|
|
|
pathPrefix.Append("x");
|
|
|
|
pathPrefix.AppendInt(aCounter.IntrinsicSize().height);
|
|
|
|
pathPrefix.Append(", ");
|
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
if (aCounter.URI().IsEmpty()) {
|
|
|
|
pathPrefix.Append("<unknown URI>");
|
|
|
|
} else {
|
|
|
|
pathPrefix.Append(aCounter.URI());
|
|
|
|
}
|
2015-04-28 18:46:17 +00:00
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
pathPrefix.Append(")/");
|
2014-11-26 09:37:57 +00:00
|
|
|
|
2015-05-04 23:08:51 +00:00
|
|
|
rv = ReportSurfaces(aHandleReport, aData, pathPrefix, aCounter);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = ReportSourceValue(aHandleReport, aData, pathPrefix, aCounter.Values());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2015-04-28 18:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult ReportSurfaces(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
const nsACString& aPathPrefix,
|
|
|
|
const ImageMemoryCounter& aCounter)
|
|
|
|
{
|
|
|
|
for (const SurfaceMemoryCounter& counter : aCounter.Surfaces()) {
|
|
|
|
nsAutoCString surfacePathPrefix(aPathPrefix);
|
|
|
|
surfacePathPrefix.Append(counter.IsLocked() ? "locked/" : "unlocked/");
|
|
|
|
surfacePathPrefix.Append("surface(");
|
|
|
|
|
|
|
|
if (counter.SubframeSize() &&
|
|
|
|
*counter.SubframeSize() != counter.Key().Size()) {
|
|
|
|
surfacePathPrefix.AppendInt(counter.SubframeSize()->width);
|
|
|
|
surfacePathPrefix.Append("x");
|
|
|
|
surfacePathPrefix.AppendInt(counter.SubframeSize()->height);
|
|
|
|
surfacePathPrefix.Append(" subframe of ");
|
|
|
|
}
|
|
|
|
|
|
|
|
surfacePathPrefix.AppendInt(counter.Key().Size().width);
|
|
|
|
surfacePathPrefix.Append("x");
|
|
|
|
surfacePathPrefix.AppendInt(counter.Key().Size().height);
|
|
|
|
|
|
|
|
if (counter.Type() == SurfaceMemoryCounterType::NORMAL) {
|
|
|
|
surfacePathPrefix.Append("@");
|
|
|
|
surfacePathPrefix.AppendFloat(counter.Key().AnimationTime());
|
|
|
|
|
2015-08-15 00:56:44 +00:00
|
|
|
if (counter.Key().Flags() != DefaultSurfaceFlags()) {
|
2015-04-28 18:46:17 +00:00
|
|
|
surfacePathPrefix.Append(", flags:");
|
2015-08-15 00:56:44 +00:00
|
|
|
surfacePathPrefix.AppendInt(uint32_t(counter.Key().Flags()),
|
|
|
|
/* aRadix = */ 16);
|
2015-04-28 18:46:17 +00:00
|
|
|
}
|
|
|
|
} else if (counter.Type() == SurfaceMemoryCounterType::COMPOSITING) {
|
|
|
|
surfacePathPrefix.Append(", compositing frame");
|
|
|
|
} else if (counter.Type() == SurfaceMemoryCounterType::COMPOSITING_PREV) {
|
|
|
|
surfacePathPrefix.Append(", compositing prev frame");
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unknown counter type");
|
|
|
|
}
|
|
|
|
|
|
|
|
surfacePathPrefix.Append(")/");
|
|
|
|
|
|
|
|
nsresult rv = ReportValues(aHandleReport, aData, surfacePathPrefix,
|
|
|
|
counter.Values());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2014-11-27 02:00:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult ReportTotal(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
bool aExplicit,
|
|
|
|
const char* aPathPrefix,
|
|
|
|
const char* aPathInfix,
|
|
|
|
const MemoryTotal& aTotal)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsAutoCString pathPrefix;
|
|
|
|
if (aExplicit) {
|
|
|
|
pathPrefix.Append("explicit/");
|
2014-11-26 09:37:57 +00:00
|
|
|
}
|
2014-11-27 02:00:15 +00:00
|
|
|
pathPrefix.Append(aPathPrefix);
|
|
|
|
|
|
|
|
nsAutoCString rasterUsedPrefix(pathPrefix);
|
|
|
|
rasterUsedPrefix.Append("/raster/used/");
|
|
|
|
rasterUsedPrefix.Append(aPathInfix);
|
|
|
|
rv = ReportValues(aHandleReport, aData, rasterUsedPrefix,
|
|
|
|
aTotal.UsedRaster());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoCString rasterUnusedPrefix(pathPrefix);
|
|
|
|
rasterUnusedPrefix.Append("/raster/unused/");
|
|
|
|
rasterUnusedPrefix.Append(aPathInfix);
|
|
|
|
rv = ReportValues(aHandleReport, aData, rasterUnusedPrefix,
|
|
|
|
aTotal.UnusedRaster());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoCString vectorUsedPrefix(pathPrefix);
|
|
|
|
vectorUsedPrefix.Append("/vector/used/");
|
|
|
|
vectorUsedPrefix.Append(aPathInfix);
|
|
|
|
rv = ReportValues(aHandleReport, aData, vectorUsedPrefix,
|
|
|
|
aTotal.UsedVector());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoCString vectorUnusedPrefix(pathPrefix);
|
|
|
|
vectorUnusedPrefix.Append("/vector/unused/");
|
|
|
|
vectorUnusedPrefix.Append(aPathInfix);
|
|
|
|
rv = ReportValues(aHandleReport, aData, vectorUnusedPrefix,
|
|
|
|
aTotal.UnusedVector());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-11-26 09:37:57 +00:00
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
static nsresult ReportValues(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
const nsACString& aPathPrefix,
|
|
|
|
const MemoryCounter& aCounter)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2015-05-04 23:08:51 +00:00
|
|
|
rv = ReportSourceValue(aHandleReport, aData, aPathPrefix, aCounter);
|
2014-11-27 02:00:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = ReportValue(aHandleReport, aData, KIND_HEAP, aPathPrefix,
|
|
|
|
"decoded-heap",
|
|
|
|
"Decoded image data which is stored on the heap.",
|
|
|
|
aCounter.DecodedHeap());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = ReportValue(aHandleReport, aData, KIND_NONHEAP, aPathPrefix,
|
|
|
|
"decoded-nonheap",
|
|
|
|
"Decoded image data which isn't stored on the heap.",
|
|
|
|
aCounter.DecodedNonHeap());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-04 23:08:51 +00:00
|
|
|
static nsresult ReportSourceValue(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
const nsACString& aPathPrefix,
|
|
|
|
const MemoryCounter& aCounter)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = ReportValue(aHandleReport, aData, KIND_HEAP, aPathPrefix,
|
|
|
|
"source",
|
|
|
|
"Raster image source data and vector image documents.",
|
|
|
|
aCounter.Source());
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
static nsresult ReportValue(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
int32_t aKind,
|
|
|
|
const nsACString& aPathPrefix,
|
|
|
|
const char* aPathSuffix,
|
|
|
|
const char* aDescription,
|
|
|
|
size_t aValue)
|
|
|
|
{
|
|
|
|
if (aValue == 0) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString desc(aDescription);
|
|
|
|
nsAutoCString path(aPathPrefix);
|
|
|
|
path.Append(aPathSuffix);
|
|
|
|
|
|
|
|
return aHandleReport->Callback(EmptyCString(), path, aKind, UNITS_BYTES,
|
|
|
|
aValue, desc, aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RecordCounterForRequest(imgRequest* aRequest,
|
|
|
|
nsTArray<ImageMemoryCounter>* aArray,
|
|
|
|
bool aIsUsed)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = aRequest->GetImage();
|
2014-11-27 02:00:15 +00:00
|
|
|
if (!image) {
|
|
|
|
return;
|
2014-09-05 21:36:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 18:46:17 +00:00
|
|
|
ImageMemoryCounter counter(image, ImagesMallocSizeOf, aIsUsed);
|
2014-11-27 02:00:15 +00:00
|
|
|
|
2015-04-28 18:46:17 +00:00
|
|
|
aArray->AppendElement(Move(counter));
|
2014-09-05 21:36:11 +00:00
|
|
|
}
|
2010-05-22 04:10:14 +00:00
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(imgMemoryReporter, nsIMemoryReporter)
|
2013-12-08 05:39:47 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsProgressNotificationProxy,
|
|
|
|
nsIProgressEventSink,
|
|
|
|
nsIChannelEventSink,
|
|
|
|
nsIInterfaceRequestor)
|
2009-07-28 16:13:48 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProgressNotificationProxy::OnProgress(nsIRequest* request,
|
|
|
|
nsISupports* ctxt,
|
2015-01-08 19:48:52 +00:00
|
|
|
int64_t progress,
|
|
|
|
int64_t progressMax)
|
2011-07-01 17:03:30 +00:00
|
|
|
{
|
2009-07-28 16:13:48 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2010-11-21 19:21:57 +00:00
|
|
|
request->GetLoadGroup(getter_AddRefs(loadGroup));
|
2009-07-28 16:13:48 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIProgressEventSink> target;
|
|
|
|
NS_QueryNotificationCallbacks(mOriginalCallbacks,
|
|
|
|
loadGroup,
|
|
|
|
NS_GET_IID(nsIProgressEventSink),
|
|
|
|
getter_AddRefs(target));
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!target) {
|
2009-07-28 16:13:48 +00:00
|
|
|
return NS_OK;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-07-28 16:13:48 +00:00
|
|
|
return target->OnProgress(mImageRequest, ctxt, progress, progressMax);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProgressNotificationProxy::OnStatus(nsIRequest* request,
|
|
|
|
nsISupports* ctxt,
|
|
|
|
nsresult status,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* statusArg)
|
2011-07-01 17:03:30 +00:00
|
|
|
{
|
2009-07-28 16:13:48 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2010-11-21 19:21:57 +00:00
|
|
|
request->GetLoadGroup(getter_AddRefs(loadGroup));
|
2009-07-28 16:13:48 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIProgressEventSink> target;
|
|
|
|
NS_QueryNotificationCallbacks(mOriginalCallbacks,
|
|
|
|
loadGroup,
|
|
|
|
NS_GET_IID(nsIProgressEventSink),
|
|
|
|
getter_AddRefs(target));
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!target) {
|
2009-07-28 16:13:48 +00:00
|
|
|
return NS_OK;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-07-28 16:13:48 +00:00
|
|
|
return target->OnStatus(mImageRequest, ctxt, status, statusArg);
|
|
|
|
}
|
|
|
|
|
2009-08-13 11:20:41 +00:00
|
|
|
NS_IMETHODIMP
|
2015-04-07 21:49:00 +00:00
|
|
|
nsProgressNotificationProxy::
|
|
|
|
AsyncOnChannelRedirect(nsIChannel* oldChannel,
|
|
|
|
nsIChannel* newChannel,
|
|
|
|
uint32_t flags,
|
|
|
|
nsIAsyncVerifyRedirectCallback* cb)
|
2011-07-01 17:03:30 +00:00
|
|
|
{
|
2009-08-13 11:20:41 +00:00
|
|
|
// Tell the original original callbacks about it too
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2010-11-21 19:21:57 +00:00
|
|
|
newChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
2009-08-13 11:20:41 +00:00
|
|
|
nsCOMPtr<nsIChannelEventSink> target;
|
|
|
|
NS_QueryNotificationCallbacks(mOriginalCallbacks,
|
|
|
|
loadGroup,
|
|
|
|
NS_GET_IID(nsIChannelEventSink),
|
|
|
|
getter_AddRefs(target));
|
2010-08-05 02:15:55 +00:00
|
|
|
if (!target) {
|
|
|
|
cb->OnRedirectVerifyCallback(NS_OK);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delegate to |target| if set, reusing |cb|
|
|
|
|
return target->AsyncOnChannelRedirect(oldChannel, newChannel, flags, cb);
|
2009-08-13 11:20:41 +00:00
|
|
|
}
|
|
|
|
|
2009-07-28 16:13:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProgressNotificationProxy::GetInterface(const nsIID& iid,
|
2011-07-01 17:03:30 +00:00
|
|
|
void** result)
|
|
|
|
{
|
2009-07-28 16:13:48 +00:00
|
|
|
if (iid.Equals(NS_GET_IID(nsIProgressEventSink))) {
|
|
|
|
*result = static_cast<nsIProgressEventSink*>(this);
|
2009-07-28 17:46:04 +00:00
|
|
|
NS_ADDREF_THIS();
|
2009-07-28 16:13:48 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-08-13 11:20:41 +00:00
|
|
|
if (iid.Equals(NS_GET_IID(nsIChannelEventSink))) {
|
|
|
|
*result = static_cast<nsIChannelEventSink*>(this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-04-07 21:49:00 +00:00
|
|
|
if (mOriginalCallbacks) {
|
2009-07-28 16:13:48 +00:00
|
|
|
return mOriginalCallbacks->GetInterface(iid, result);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-07-28 16:13:48 +00:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
static void
|
|
|
|
NewRequestAndEntry(bool aForcePrincipalCheckForCacheEntry, imgLoader* aLoader,
|
2015-05-20 17:21:13 +00:00
|
|
|
const ImageCacheKey& aKey,
|
2015-04-07 21:49:00 +00:00
|
|
|
imgRequest** aRequest, imgCacheEntry** aEntry)
|
2008-09-04 16:36:27 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> request = new imgRequest(aLoader, aKey);
|
|
|
|
RefPtr<imgCacheEntry> entry =
|
2015-04-07 21:49:00 +00:00
|
|
|
new imgCacheEntry(aLoader, request, aForcePrincipalCheckForCacheEntry);
|
2014-09-05 21:36:11 +00:00
|
|
|
aLoader->AddToUncachedImages(request);
|
2011-10-01 16:14:40 +00:00
|
|
|
request.forget(aRequest);
|
|
|
|
entry.forget(aEntry);
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
2008-09-04 16:36:27 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
static bool
|
|
|
|
ShouldRevalidateEntry(imgCacheEntry* aEntry,
|
|
|
|
nsLoadFlags aFlags,
|
|
|
|
bool aHasExpired)
|
2002-01-15 05:23:33 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool bValidateEntry = false;
|
2002-09-18 22:08:12 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (aFlags & nsIRequest::LOAD_BYPASS_CACHE) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2002-09-18 22:08:12 +00:00
|
|
|
|
|
|
|
if (aFlags & nsIRequest::VALIDATE_ALWAYS) {
|
2011-10-17 14:59:28 +00:00
|
|
|
bValidateEntry = true;
|
2015-04-07 21:49:00 +00:00
|
|
|
} else if (aEntry->GetMustValidate()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
bValidateEntry = true;
|
2015-04-07 21:49:00 +00:00
|
|
|
} else if (aHasExpired) {
|
|
|
|
// The cache entry has expired... Determine whether the stale cache
|
|
|
|
// entry can be used without validation...
|
2013-03-29 20:14:19 +00:00
|
|
|
if (aFlags & (nsIRequest::VALIDATE_NEVER |
|
2015-04-07 21:49:00 +00:00
|
|
|
nsIRequest::VALIDATE_ONCE_PER_SESSION)) {
|
|
|
|
// VALIDATE_NEVER and VALIDATE_ONCE_PER_SESSION allow stale cache
|
|
|
|
// entries to be used unless they have been explicitly marked to
|
|
|
|
// indicate that revalidation is necessary.
|
2011-10-17 14:59:28 +00:00
|
|
|
bValidateEntry = false;
|
2015-04-07 21:49:00 +00:00
|
|
|
|
|
|
|
} else if (!(aFlags & nsIRequest::LOAD_FROM_CACHE)) {
|
|
|
|
// LOAD_FROM_CACHE allows a stale cache entry to be used... Otherwise,
|
|
|
|
// the entry must be revalidated.
|
2011-10-17 14:59:28 +00:00
|
|
|
bValidateEntry = true;
|
2002-09-18 22:08:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bValidateEntry;
|
|
|
|
}
|
|
|
|
|
2015-03-24 16:18:48 +00:00
|
|
|
/* Call content policies on cached images that went through a redirect */
|
|
|
|
static bool
|
|
|
|
ShouldLoadCachedImage(imgRequest* aImgRequest,
|
|
|
|
nsISupports* aLoadingContext,
|
|
|
|
nsIPrincipal* aLoadingPrincipal)
|
|
|
|
{
|
|
|
|
/* Call content policies on cached images - Bug 1082837
|
|
|
|
* Cached images are keyed off of the first uri in a redirect chain.
|
|
|
|
* Hence content policies don't get a chance to test the intermediate hops
|
|
|
|
* or the final desitnation. Here we test the final destination using
|
|
|
|
* mCurrentURI off of the imgRequest and passing it into content policies.
|
|
|
|
* For Mixed Content Blocker, we do an additional check to determine if any
|
|
|
|
* of the intermediary hops went through an insecure redirect with the
|
|
|
|
* mHadInsecureRedirect flag
|
|
|
|
*/
|
|
|
|
bool insecureRedirect = aImgRequest->HadInsecureRedirect();
|
|
|
|
nsCOMPtr<nsIURI> contentLocation;
|
|
|
|
aImgRequest->GetCurrentURI(getter_AddRefs(contentLocation));
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
int16_t decision = nsIContentPolicy::REJECT_REQUEST;
|
2015-09-20 21:55:59 +00:00
|
|
|
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_INTERNAL_IMAGE,
|
2015-03-24 16:18:48 +00:00
|
|
|
contentLocation,
|
|
|
|
aLoadingPrincipal,
|
|
|
|
aLoadingContext,
|
|
|
|
EmptyCString(), //mime guess
|
|
|
|
nullptr, //aExtra
|
|
|
|
&decision,
|
|
|
|
nsContentUtils::GetContentPolicy(),
|
|
|
|
nsContentUtils::GetSecurityManager());
|
|
|
|
if (NS_FAILED(rv) || !NS_CP_ACCEPTED(decision)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We call all Content Policies above, but we also have to call mcb
|
|
|
|
// individually to check the intermediary redirect hops are secure.
|
|
|
|
if (insecureRedirect) {
|
|
|
|
if (!nsContentUtils::IsSystemPrincipal(aLoadingPrincipal)) {
|
|
|
|
// Set the requestingLocation from the aLoadingPrincipal.
|
|
|
|
nsCOMPtr<nsIURI> requestingLocation;
|
|
|
|
if (aLoadingPrincipal) {
|
|
|
|
rv = aLoadingPrincipal->GetURI(getter_AddRefs(requestingLocation));
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// reset the decision for mixed content blocker check
|
|
|
|
decision = nsIContentPolicy::REJECT_REQUEST;
|
|
|
|
rv = nsMixedContentBlocker::ShouldLoad(insecureRedirect,
|
|
|
|
nsIContentPolicy::TYPE_IMAGE,
|
|
|
|
contentLocation,
|
|
|
|
requestingLocation,
|
|
|
|
aLoadingContext,
|
|
|
|
EmptyCString(), //mime guess
|
|
|
|
nullptr,
|
|
|
|
aLoadingPrincipal,
|
|
|
|
&decision);
|
|
|
|
if (NS_FAILED(rv) || !NS_CP_ACCEPTED(decision)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-14 18:47:34 +00:00
|
|
|
// Returns true if this request is compatible with the given CORS mode on the
|
|
|
|
// given loading principal, and false if the request may not be reused due
|
2014-11-18 13:46:53 +00:00
|
|
|
// to CORS. Also checks the Referrer Policy, since requests with different
|
|
|
|
// referrers/policies may generate different responses.
|
2011-07-14 18:47:34 +00:00
|
|
|
static bool
|
2014-11-18 13:46:53 +00:00
|
|
|
ValidateSecurityInfo(imgRequest* request, bool forcePrincipalCheck,
|
|
|
|
int32_t corsmode, nsIPrincipal* loadingPrincipal,
|
2015-03-24 16:18:48 +00:00
|
|
|
nsISupports* aCX, ReferrerPolicy referrerPolicy)
|
2011-07-14 18:47:34 +00:00
|
|
|
{
|
2014-11-18 13:46:53 +00:00
|
|
|
// If the entry's Referrer Policy doesn't match, we can't use this request.
|
2015-06-05 22:25:24 +00:00
|
|
|
// XXX: this will return false if an image has different referrer attributes,
|
|
|
|
// i.e. we currently don't use the cached image but reload the image with
|
|
|
|
// the new referrer policy bug 1174921
|
2014-11-18 13:46:53 +00:00
|
|
|
if (referrerPolicy != request->GetReferrerPolicy()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-14 18:47:34 +00:00
|
|
|
// If the entry's CORS mode doesn't match, or the CORS mode matches but the
|
|
|
|
// document principal isn't the same, we can't use this request.
|
|
|
|
if (request->GetCORSMode() != corsmode) {
|
|
|
|
return false;
|
2011-09-20 21:00:42 +00:00
|
|
|
} else if (request->GetCORSMode() != imgIRequest::CORS_NONE ||
|
|
|
|
forcePrincipalCheck) {
|
2011-07-14 18:47:34 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> otherprincipal = request->GetLoadingPrincipal();
|
|
|
|
|
|
|
|
// If we previously had a principal, but we don't now, we can't use this
|
|
|
|
// request.
|
|
|
|
if (otherprincipal && !loadingPrincipal) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (otherprincipal && loadingPrincipal) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool equals = false;
|
2011-07-14 18:47:34 +00:00
|
|
|
otherprincipal->Equals(loadingPrincipal, &equals);
|
2015-03-24 16:18:48 +00:00
|
|
|
if (!equals) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-14 18:47:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 16:18:48 +00:00
|
|
|
// Content Policy Check on Cached Images
|
|
|
|
return ShouldLoadCachedImage(request, aCX, loadingPrincipal);
|
2011-07-14 18:47:34 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
static nsresult
|
|
|
|
NewImageChannel(nsIChannel** aResult,
|
|
|
|
// If aForcePrincipalCheckForCacheEntry is true, then we will
|
|
|
|
// force a principal check even when not using CORS before
|
|
|
|
// assuming we have a cache hit on a cache entry that we
|
|
|
|
// create for this channel. This is an out param that should
|
|
|
|
// be set to true if this channel ends up depending on
|
|
|
|
// aLoadingPrincipal and false otherwise.
|
|
|
|
bool* aForcePrincipalCheckForCacheEntry,
|
|
|
|
nsIURI* aURI,
|
|
|
|
nsIURI* aInitialDocumentURI,
|
|
|
|
nsIURI* aReferringURI,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
const nsCString& aAcceptHeader,
|
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
nsContentPolicyType aPolicyType,
|
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
2016-04-13 13:34:36 +00:00
|
|
|
nsISupports* aRequestingContext,
|
|
|
|
bool aRespectPrivacy)
|
2002-09-18 22:08:12 +00:00
|
|
|
{
|
2015-04-19 00:18:49 +00:00
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
2002-09-18 22:08:12 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIHttpChannel> newHttpChannel;
|
2013-03-29 20:14:19 +00:00
|
|
|
|
2002-09-18 22:08:12 +00:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> callbacks;
|
|
|
|
|
|
|
|
if (aLoadGroup) {
|
|
|
|
// Get the notification callbacks from the load group for the new channel.
|
|
|
|
//
|
|
|
|
// XXX: This is not exactly correct, because the network request could be
|
|
|
|
// referenced by multiple windows... However, the new channel needs
|
|
|
|
// something. So, using the 'first' notification callbacks is better
|
|
|
|
// than nothing...
|
|
|
|
//
|
|
|
|
aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
|
|
|
|
}
|
|
|
|
|
2013-08-23 19:51:00 +00:00
|
|
|
// Pass in a nullptr loadgroup because this is the underlying network
|
|
|
|
// request. This request may be referenced by several proxy image requests
|
|
|
|
// (possibly in different documents).
|
2002-09-18 22:08:12 +00:00
|
|
|
// If all of the proxy requests are canceled then this request should be
|
|
|
|
// canceled too.
|
|
|
|
//
|
2014-06-27 20:57:36 +00:00
|
|
|
aLoadFlags |= nsIChannel::LOAD_CLASSIFY_URI;
|
2014-09-21 16:45:34 +00:00
|
|
|
|
2014-11-14 16:56:55 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> triggeringPrincipal = aLoadingPrincipal;
|
2014-07-17 23:07:58 +00:00
|
|
|
bool isSandBoxed = false;
|
|
|
|
// only inherit if we have a principal
|
|
|
|
bool inherit = false;
|
2014-11-14 16:56:55 +00:00
|
|
|
if (triggeringPrincipal) {
|
2015-04-07 21:49:00 +00:00
|
|
|
inherit = nsContentUtils::
|
|
|
|
ChannelShouldInheritPrincipal(triggeringPrincipal,
|
|
|
|
aURI,
|
|
|
|
false, // aInheritForAboutBlank
|
|
|
|
false); // aForceInherit
|
|
|
|
} else {
|
2014-11-14 16:56:55 +00:00
|
|
|
triggeringPrincipal = nsContentUtils::GetSystemPrincipal();
|
2014-09-21 16:45:34 +00:00
|
|
|
}
|
|
|
|
nsCOMPtr<nsINode> requestingNode = do_QueryInterface(aRequestingContext);
|
2014-07-17 23:07:58 +00:00
|
|
|
nsSecurityFlags securityFlags = nsILoadInfo::SEC_NORMAL;
|
|
|
|
if (inherit) {
|
|
|
|
securityFlags |= nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
|
|
|
|
}
|
2014-08-19 21:49:38 +00:00
|
|
|
|
2016-04-13 13:34:36 +00:00
|
|
|
if (aRespectPrivacy) {
|
|
|
|
securityFlags |= nsILoadInfo::SEC_FORCE_PRIVATE_BROWSING;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
// Note we are calling NS_NewChannelWithTriggeringPrincipal() here with a
|
|
|
|
// node and a principal. This is for things like background images that are
|
|
|
|
// specified by user stylesheets, where the document is being styled, but
|
|
|
|
// the principal is that of the user stylesheet.
|
2014-11-14 16:56:55 +00:00
|
|
|
if (requestingNode) {
|
|
|
|
rv = NS_NewChannelWithTriggeringPrincipal(aResult,
|
|
|
|
aURI,
|
|
|
|
requestingNode,
|
|
|
|
triggeringPrincipal,
|
|
|
|
securityFlags,
|
2015-03-25 21:42:18 +00:00
|
|
|
aPolicyType,
|
2014-11-14 16:56:55 +00:00
|
|
|
nullptr, // loadGroup
|
|
|
|
callbacks,
|
|
|
|
aLoadFlags);
|
2015-04-07 21:49:00 +00:00
|
|
|
} else {
|
2014-11-14 16:56:55 +00:00
|
|
|
// either we are loading something inside a document, in which case
|
|
|
|
// we should always have a requestingNode, or we are loading something
|
|
|
|
// outside a document, in which case the triggeringPrincipal
|
|
|
|
// should always be the systemPrincipal.
|
2015-08-02 17:42:22 +00:00
|
|
|
// However, there are two exceptions: one is Notifications and the
|
|
|
|
// other one is Favicons which create a channel in the parent prcoess
|
|
|
|
// in which case we can't get a requestingNode.
|
2014-11-14 16:56:55 +00:00
|
|
|
rv = NS_NewChannel(aResult,
|
|
|
|
aURI,
|
|
|
|
triggeringPrincipal,
|
|
|
|
securityFlags,
|
2015-03-25 21:42:18 +00:00
|
|
|
aPolicyType,
|
2014-11-14 16:56:55 +00:00
|
|
|
nullptr, // loadGroup
|
|
|
|
callbacks,
|
|
|
|
aLoadFlags);
|
|
|
|
}
|
2014-09-21 16:45:34 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2002-09-18 22:08:12 +00:00
|
|
|
return rv;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2002-09-18 22:08:12 +00:00
|
|
|
|
2014-07-17 23:07:58 +00:00
|
|
|
*aForcePrincipalCheckForCacheEntry = inherit && !isSandBoxed;
|
2011-09-20 21:00:42 +00:00
|
|
|
|
2002-09-18 22:08:12 +00:00
|
|
|
// Initialize HTTP-specific attributes
|
|
|
|
newHttpChannel = do_QueryInterface(*aResult);
|
|
|
|
if (newHttpChannel) {
|
2002-09-27 04:22:13 +00:00
|
|
|
newHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
|
2009-07-15 07:22:40 +00:00
|
|
|
aAcceptHeader,
|
2011-10-17 14:59:28 +00:00
|
|
|
false);
|
2002-09-30 23:18:43 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsCOMPtr<nsIHttpChannelInternal> httpChannelInternal =
|
|
|
|
do_QueryInterface(newHttpChannel);
|
2002-09-30 23:18:43 +00:00
|
|
|
NS_ENSURE_TRUE(httpChannelInternal, NS_ERROR_UNEXPECTED);
|
|
|
|
httpChannelInternal->SetDocumentURI(aInitialDocumentURI);
|
2014-11-18 13:46:53 +00:00
|
|
|
newHttpChannel->SetReferrerWithPolicy(aReferringURI, aReferrerPolicy);
|
2002-09-18 22:08:12 +00:00
|
|
|
}
|
|
|
|
|
2005-02-21 20:58:01 +00:00
|
|
|
// Image channels are loaded by default with reduced priority.
|
|
|
|
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(*aResult);
|
|
|
|
if (p) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t priority = nsISupportsPriority::PRIORITY_LOW;
|
2005-02-21 20:58:01 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (aLoadFlags & nsIRequest::LOAD_BACKGROUND) {
|
2005-02-21 20:58:01 +00:00
|
|
|
++priority; // further reduce priority for background loads
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2005-02-21 20:58:01 +00:00
|
|
|
|
2005-02-21 22:21:21 +00:00
|
|
|
p->AdjustPriority(priority);
|
2005-02-21 20:58:01 +00:00
|
|
|
}
|
|
|
|
|
2014-01-30 03:35:40 +00:00
|
|
|
// Create a new loadgroup for this new channel, using the old group as
|
|
|
|
// the parent. The indirection keeps the channel insulated from cancels,
|
|
|
|
// but does allow a way for this revalidation to be associated with at
|
|
|
|
// least one base load group for scheduling/caching purposes.
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = do_CreateInstance(NS_LOADGROUP_CONTRACTID);
|
|
|
|
nsCOMPtr<nsILoadGroupChild> childLoadGroup = do_QueryInterface(loadGroup);
|
|
|
|
if (childLoadGroup) {
|
|
|
|
childLoadGroup->SetParentLoadGroup(aLoadGroup);
|
|
|
|
}
|
|
|
|
(*aResult)->SetLoadGroup(loadGroup);
|
|
|
|
|
2016-04-13 13:34:36 +00:00
|
|
|
// This is a workaround and a real fix in bug 1264231.
|
|
|
|
if (callbacks) {
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(callbacks);
|
|
|
|
if (loadContext) {
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
|
|
|
rv = (*aResult)->GetLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
DocShellOriginAttributes originAttrs;
|
|
|
|
loadContext->GetOriginAttributes(originAttrs);
|
|
|
|
NeckoOriginAttributes neckoOriginAttrs;
|
|
|
|
neckoOriginAttrs.InheritFromDocShellToNecko(originAttrs);
|
|
|
|
loadInfo->SetOriginAttributes(neckoOriginAttrs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-18 22:08:12 +00:00
|
|
|
return NS_OK;
|
2002-01-15 05:23:33 +00:00
|
|
|
}
|
2001-07-17 01:14:40 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
static uint32_t
|
|
|
|
SecondsFromPRTime(PRTime prTime)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
return uint32_t(int64_t(prTime) / int64_t(PR_USEC_PER_SEC));
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
imgCacheEntry::imgCacheEntry(imgLoader* loader, imgRequest* request,
|
|
|
|
bool forcePrincipalCheck)
|
2012-06-26 04:20:12 +00:00
|
|
|
: mLoader(loader),
|
|
|
|
mRequest(request),
|
2008-09-04 23:00:42 +00:00
|
|
|
mDataSize(0),
|
|
|
|
mTouchedTime(SecondsFromPRTime(PR_Now())),
|
2015-10-20 05:15:25 +00:00
|
|
|
mLoadTime(SecondsFromPRTime(PR_Now())),
|
2008-09-04 23:00:42 +00:00
|
|
|
mExpiryTime(0),
|
2011-10-17 14:59:28 +00:00
|
|
|
mMustValidate(false),
|
2011-07-01 17:03:38 +00:00
|
|
|
// We start off as evicted so we don't try to update the cache. PutIntoCache
|
|
|
|
// will set this to false.
|
2011-10-17 14:59:28 +00:00
|
|
|
mEvicted(true),
|
|
|
|
mHasNoProxies(true),
|
2011-09-20 21:00:42 +00:00
|
|
|
mForcePrincipalCheck(forcePrincipalCheck)
|
2015-04-07 21:49:00 +00:00
|
|
|
{ }
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2009-01-31 02:17:47 +00:00
|
|
|
imgCacheEntry::~imgCacheEntry()
|
|
|
|
{
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_FUNC(gImgLog, "imgCacheEntry::~imgCacheEntry()");
|
2009-01-31 02:17:47 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgCacheEntry::Touch(bool updateTime /* = true */)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_SCOPE(gImgLog, "imgCacheEntry::Touch");
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (updateTime) {
|
2008-09-04 23:00:42 +00:00
|
|
|
mTouchedTime = SecondsFromPRTime(PR_Now());
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
UpdateCache();
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgCacheEntry::UpdateCache(int32_t diff /* = 0 */)
|
2009-09-12 22:44:18 +00:00
|
|
|
{
|
2009-01-31 02:17:47 +00:00
|
|
|
// Don't update the cache if we've been removed from it or it doesn't care
|
|
|
|
// about our size or usage.
|
|
|
|
if (!Evicted() && HasNoProxies()) {
|
2015-04-28 18:45:45 +00:00
|
|
|
mLoader->CacheEntriesChanged(mRequest->IsChrome(), diff);
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 05:15:25 +00:00
|
|
|
void imgCacheEntry::UpdateLoadTime()
|
|
|
|
{
|
|
|
|
mLoadTime = SecondsFromPRTime(PR_Now());
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgCacheEntry::SetHasNoProxies(bool hasNoProxies)
|
2009-01-31 02:17:47 +00:00
|
|
|
{
|
2015-11-16 17:21:00 +00:00
|
|
|
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
2015-05-11 20:42:30 +00:00
|
|
|
if (hasNoProxies) {
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog, "imgCacheEntry::SetHasNoProxies true",
|
2015-05-20 17:21:13 +00:00
|
|
|
"uri", mRequest->CacheKey().Spec());
|
2015-05-11 20:42:30 +00:00
|
|
|
} else {
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog, "imgCacheEntry::SetHasNoProxies false",
|
2015-05-20 17:21:13 +00:00
|
|
|
"uri", mRequest->CacheKey().Spec());
|
2015-05-11 20:42:30 +00:00
|
|
|
}
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
|
|
|
|
mHasNoProxies = hasNoProxies;
|
|
|
|
}
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
imgCacheQueue::imgCacheQueue()
|
2011-10-17 14:59:28 +00:00
|
|
|
: mDirty(false),
|
2008-09-04 23:00:42 +00:00
|
|
|
mSize(0)
|
2015-04-07 21:49:00 +00:00
|
|
|
{ }
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgCacheQueue::UpdateSize(int32_t diff)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
mSize += diff;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
uint32_t
|
|
|
|
imgCacheQueue::GetSize() const
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <algorithm>
|
2008-09-11 11:34:17 +00:00
|
|
|
using namespace std;
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgCacheQueue::Remove(imgCacheEntry* entry)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
queueContainer::iterator it = find(mQueue.begin(), mQueue.end(), entry);
|
|
|
|
if (it != mQueue.end()) {
|
|
|
|
mSize -= (*it)->GetDataSize();
|
|
|
|
mQueue.erase(it);
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgCacheQueue::Push(imgCacheEntry* entry)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
mSize += entry->GetDataSize();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheEntry> refptr(entry);
|
2008-09-04 23:00:42 +00:00
|
|
|
mQueue.push_back(refptr);
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
already_AddRefed<imgCacheEntry>
|
|
|
|
imgCacheQueue::Pop()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-04-07 21:49:00 +00:00
|
|
|
if (mQueue.empty()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
|
|
|
if (IsDirty()) {
|
2008-09-04 23:00:42 +00:00
|
|
|
Refresh();
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheEntry> entry = mQueue[0];
|
2008-09-04 23:00:42 +00:00
|
|
|
std::pop_heap(mQueue.begin(), mQueue.end(), imgLoader::CompareCacheEntries);
|
|
|
|
mQueue.pop_back();
|
|
|
|
|
|
|
|
mSize -= entry->GetDataSize();
|
2013-04-22 11:15:59 +00:00
|
|
|
return entry.forget();
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgCacheQueue::Refresh()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
std::make_heap(mQueue.begin(), mQueue.end(), imgLoader::CompareCacheEntries);
|
2011-10-17 14:59:28 +00:00
|
|
|
mDirty = false;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgCacheQueue::MarkDirty()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mDirty = true;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
bool
|
|
|
|
imgCacheQueue::IsDirty()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return mDirty;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
uint32_t
|
|
|
|
imgCacheQueue::GetNumElements() const
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return mQueue.size();
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
imgCacheQueue::iterator
|
|
|
|
imgCacheQueue::begin()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return mQueue.begin();
|
|
|
|
}
|
2015-04-07 21:49:00 +00:00
|
|
|
|
|
|
|
imgCacheQueue::const_iterator
|
|
|
|
imgCacheQueue::begin() const
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return mQueue.begin();
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
imgCacheQueue::iterator
|
|
|
|
imgCacheQueue::end()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return mQueue.end();
|
|
|
|
}
|
2015-04-07 21:49:00 +00:00
|
|
|
|
|
|
|
imgCacheQueue::const_iterator
|
|
|
|
imgCacheQueue::end() const
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return mQueue.end();
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult
|
|
|
|
imgLoader::CreateNewProxyForRequest(imgRequest* aRequest,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
imgRequestProxy** _retval)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::CreateNewProxyForRequest",
|
2015-04-07 21:49:00 +00:00
|
|
|
"imgRequest", aRequest);
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
/* XXX If we move decoding onto separate threads, we should save off the
|
|
|
|
calling thread here and pass it off to |proxyRequest| so that it call
|
|
|
|
proxy calls to |aObserver|.
|
|
|
|
*/
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequestProxy> proxyRequest = new imgRequestProxy();
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
/* It is important to call |SetLoadFlags()| before calling |Init()| because
|
|
|
|
|Init()| adds the request to the loadgroup.
|
|
|
|
*/
|
|
|
|
proxyRequest->SetLoadFlags(aLoadFlags);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ImageURL> uri;
|
2010-05-11 03:27:41 +00:00
|
|
|
aRequest->GetURI(getter_AddRefs(uri));
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
// init adds itself to imgRequest's list of observers
|
2012-12-19 21:28:54 +00:00
|
|
|
nsresult rv = proxyRequest->Init(aRequest, aLoadGroup, uri, aObserver);
|
2015-03-05 06:18:09 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2008-09-04 23:00:42 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-03-05 06:18:09 +00:00
|
|
|
proxyRequest.forget(_retval);
|
2008-09-04 23:00:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class imgCacheExpirationTracker final
|
2012-01-02 20:23:41 +00:00
|
|
|
: public nsExpirationTracker<imgCacheEntry, 3>
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
enum { TIMEOUT_SECONDS = 10 };
|
|
|
|
public:
|
|
|
|
imgCacheExpirationTracker();
|
|
|
|
|
|
|
|
protected:
|
2015-04-07 21:49:00 +00:00
|
|
|
void NotifyExpired(imgCacheEntry* entry);
|
2008-09-04 23:00:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
imgCacheExpirationTracker::imgCacheExpirationTracker()
|
2015-09-10 04:07:07 +00:00
|
|
|
: nsExpirationTracker<imgCacheEntry, 3>(TIMEOUT_SECONDS * 1000,
|
|
|
|
"imgCacheExpirationTracker")
|
2015-04-07 21:49:00 +00:00
|
|
|
{ }
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgCacheExpirationTracker::NotifyExpired(imgCacheEntry* entry)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2009-02-25 19:09:44 +00:00
|
|
|
// Hold on to a reference to this entry, because the expiration tracker
|
|
|
|
// mechanism doesn't.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheEntry> kungFuDeathGrip(entry);
|
2009-02-25 19:09:44 +00:00
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> req = entry->GetRequest();
|
2015-05-11 20:42:30 +00:00
|
|
|
if (req) {
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog,
|
2015-05-11 20:42:30 +00:00
|
|
|
"imgCacheExpirationTracker::NotifyExpired",
|
2015-05-20 17:21:13 +00:00
|
|
|
"entry", req->CacheKey().Spec());
|
2015-05-11 20:42:30 +00:00
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
// We can be called multiple times on the same entry. Don't do work multiple
|
|
|
|
// times.
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!entry->Evicted()) {
|
2012-06-26 04:20:12 +00:00
|
|
|
entry->Loader()->RemoveFromCache(entry);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
entry->Loader()->VerifyCacheSizes();
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// imgLoader
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-09 07:09:42 +00:00
|
|
|
double imgLoader::sCacheTimeWeight;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t imgLoader::sCacheMaxSize;
|
2012-06-26 04:20:12 +00:00
|
|
|
imgMemoryReporter* imgLoader::sMemReporter;
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(imgLoader, imgILoader, nsIContentSniffer, imgICache,
|
|
|
|
nsISupportsWeakReference, nsIObserver)
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2014-04-08 22:51:33 +00:00
|
|
|
static imgLoader* gSingleton = nullptr;
|
|
|
|
static imgLoader* gPBSingleton = nullptr;
|
|
|
|
|
|
|
|
imgLoader*
|
|
|
|
imgLoader::Singleton()
|
|
|
|
{
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!gSingleton) {
|
2016-03-31 23:26:38 +00:00
|
|
|
gSingleton = imgLoader::Create().take();
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2014-04-08 22:51:33 +00:00
|
|
|
return gSingleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
imgLoader*
|
|
|
|
imgLoader::PBSingleton()
|
|
|
|
{
|
|
|
|
if (!gPBSingleton) {
|
2016-03-31 23:26:38 +00:00
|
|
|
gPBSingleton = imgLoader::Create().take();
|
2014-04-08 22:51:33 +00:00
|
|
|
gPBSingleton->RespectPrivacyNotifications();
|
|
|
|
}
|
|
|
|
return gPBSingleton;
|
|
|
|
}
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
imgLoader::imgLoader()
|
2014-09-05 21:36:11 +00:00
|
|
|
: mUncachedImagesMutex("imgLoader::UncachedImages"), mRespectPrivacy(false)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2012-06-26 04:20:12 +00:00
|
|
|
sMemReporter->AddRef();
|
|
|
|
sMemReporter->RegisterLoader(this);
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2012-10-12 12:43:01 +00:00
|
|
|
already_AddRefed<imgLoader>
|
|
|
|
imgLoader::GetInstance()
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
static RefPtr<imgLoader> singleton;
|
2012-10-12 12:43:01 +00:00
|
|
|
if (!singleton) {
|
|
|
|
singleton = imgLoader::Create();
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!singleton) {
|
2012-10-12 12:43:01 +00:00
|
|
|
return nullptr;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2012-10-12 12:43:01 +00:00
|
|
|
ClearOnShutdown(&singleton);
|
|
|
|
}
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgLoader> loader = singleton.get();
|
2012-10-12 12:43:01 +00:00
|
|
|
return loader.forget();
|
|
|
|
}
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
imgLoader::~imgLoader()
|
|
|
|
{
|
2012-06-26 04:20:12 +00:00
|
|
|
ClearChromeImageCache();
|
|
|
|
ClearImageCache();
|
2014-09-05 21:36:11 +00:00
|
|
|
{
|
|
|
|
// If there are any of our imgRequest's left they are in the uncached
|
|
|
|
// images set, so clear their pointer to us.
|
|
|
|
MutexAutoLock lock(mUncachedImagesMutex);
|
2015-07-14 13:37:57 +00:00
|
|
|
for (auto iter = mUncachedImages.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsPtrHashKey<imgRequest>* entry = iter.Get();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> req = entry->GetKey();
|
2015-07-14 13:37:57 +00:00
|
|
|
req->ClearLoader();
|
|
|
|
}
|
2014-09-05 21:36:11 +00:00
|
|
|
}
|
2012-06-26 04:20:12 +00:00
|
|
|
sMemReporter->UnregisterLoader(this);
|
|
|
|
sMemReporter->Release();
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgLoader::VerifyCacheSizes()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2010-04-29 06:27:00 +00:00
|
|
|
#ifdef DEBUG
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!mCacheTracker) {
|
2008-09-04 23:00:42 +00:00
|
|
|
return;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
uint32_t cachesize = mCache.Count() + mChromeCache.Count();
|
2015-04-07 21:49:00 +00:00
|
|
|
uint32_t queuesize =
|
|
|
|
mCacheQueue.GetNumElements() + mChromeCacheQueue.GetNumElements();
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t trackersize = 0;
|
2015-10-17 10:53:28 +00:00
|
|
|
for (nsExpirationTracker<imgCacheEntry, 3>::Iterator it(mCacheTracker.get());
|
2015-04-07 21:49:00 +00:00
|
|
|
it.Next(); ){
|
2008-09-04 23:00:42 +00:00
|
|
|
trackersize++;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(queuesize == trackersize, "Queue and tracker sizes out of sync!");
|
|
|
|
MOZ_ASSERT(queuesize <= cachesize, "Queue has more elements than cache!");
|
2010-04-29 06:27:00 +00:00
|
|
|
#endif
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
imgLoader::imgCacheTable&
|
|
|
|
imgLoader::GetCache(bool aForChrome)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-04-28 18:45:45 +00:00
|
|
|
return aForChrome ? mChromeCache : mCache;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
imgLoader::imgCacheTable&
|
|
|
|
imgLoader::GetCache(const ImageCacheKey& aKey)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-04-28 18:45:45 +00:00
|
|
|
return GetCache(aKey.IsChrome());
|
2013-09-28 18:28:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheQueue&
|
|
|
|
imgLoader::GetCacheQueue(bool aForChrome)
|
2013-09-28 18:28:42 +00:00
|
|
|
{
|
2015-04-28 18:45:45 +00:00
|
|
|
return aForChrome ? mChromeCacheQueue : mCacheQueue;
|
|
|
|
|
2013-09-28 18:28:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheQueue&
|
|
|
|
imgLoader::GetCacheQueue(const ImageCacheKey& aKey)
|
2013-09-28 18:28:42 +00:00
|
|
|
{
|
2015-04-28 18:45:45 +00:00
|
|
|
return GetCacheQueue(aKey.IsChrome());
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
void imgLoader::GlobalInit()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2014-09-22 21:30:20 +00:00
|
|
|
sCacheTimeWeight = gfxPrefs::ImageCacheTimeWeight() / 1000.0;
|
|
|
|
int32_t cachesize = gfxPrefs::ImageCacheSize();
|
|
|
|
sCacheMaxSize = cachesize > 0 ? cachesize : 0;
|
2009-07-15 07:22:40 +00:00
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
sMemReporter = new imgMemoryReporter();
|
2013-11-07 05:35:30 +00:00
|
|
|
RegisterStrongMemoryReporter(sMemReporter);
|
2015-04-07 21:49:00 +00:00
|
|
|
RegisterImagesContentUsedUncompressedDistinguishedAmount(
|
|
|
|
imgMemoryReporter::ImagesContentUsedUncompressedDistinguishedAmount);
|
2012-06-26 04:20:12 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult
|
|
|
|
imgLoader::InitCache()
|
2012-06-26 04:20:12 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!os) {
|
2012-06-26 04:20:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2012-06-26 04:20:12 +00:00
|
|
|
|
|
|
|
os->AddObserver(this, "memory-pressure", false);
|
2014-08-29 00:20:27 +00:00
|
|
|
os->AddObserver(this, "app-theme-changed", false);
|
2012-06-26 04:20:12 +00:00
|
|
|
os->AddObserver(this, "chrome-flush-skin-caches", false);
|
|
|
|
os->AddObserver(this, "chrome-flush-caches", false);
|
|
|
|
os->AddObserver(this, "last-pb-context-exited", false);
|
|
|
|
os->AddObserver(this, "profile-before-change", false);
|
|
|
|
os->AddObserver(this, "xpcom-shutdown", false);
|
|
|
|
|
2015-10-17 10:53:28 +00:00
|
|
|
mCacheTracker = MakeUnique<imgCacheExpirationTracker>();
|
2012-06-26 04:20:12 +00:00
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
return NS_OK;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult
|
|
|
|
imgLoader::Init()
|
2009-07-15 07:22:40 +00:00
|
|
|
{
|
2012-06-26 04:20:12 +00:00
|
|
|
InitCache();
|
|
|
|
|
2011-06-12 02:30:15 +00:00
|
|
|
ReadAcceptHeaderPref();
|
2009-07-15 07:22:40 +00:00
|
|
|
|
2011-06-12 02:30:15 +00:00
|
|
|
Preferences::AddWeakObserver(this, "image.http.accept");
|
2009-07-15 07:22:40 +00:00
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-07-12 01:01:53 +00:00
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgLoader::RespectPrivacyNotifications()
|
|
|
|
{
|
|
|
|
mRespectPrivacy = true;
|
2009-07-15 07:22:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-04-07 21:49:00 +00:00
|
|
|
imgLoader::Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const char16_t* aData)
|
2009-07-15 07:22:40 +00:00
|
|
|
{
|
2010-07-12 01:01:53 +00:00
|
|
|
// We listen for pref change notifications...
|
|
|
|
if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
2014-06-27 08:08:13 +00:00
|
|
|
if (!NS_strcmp(aData, MOZ_UTF16("image.http.accept"))) {
|
2011-06-12 02:30:15 +00:00
|
|
|
ReadAcceptHeaderPref();
|
2010-07-12 01:01:53 +00:00
|
|
|
}
|
2009-07-15 07:22:40 +00:00
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
} else if (strcmp(aTopic, "memory-pressure") == 0) {
|
|
|
|
MinimizeCaches();
|
2014-08-29 00:20:27 +00:00
|
|
|
} else if (strcmp(aTopic, "app-theme-changed") == 0) {
|
|
|
|
ClearImageCache();
|
|
|
|
MinimizeCaches();
|
2012-06-26 04:20:12 +00:00
|
|
|
} else if (strcmp(aTopic, "chrome-flush-skin-caches") == 0 ||
|
|
|
|
strcmp(aTopic, "chrome-flush-caches") == 0) {
|
|
|
|
MinimizeCaches();
|
|
|
|
ClearChromeImageCache();
|
|
|
|
} else if (strcmp(aTopic, "last-pb-context-exited") == 0) {
|
|
|
|
if (mRespectPrivacy) {
|
2010-07-12 01:01:53 +00:00
|
|
|
ClearImageCache();
|
2012-06-26 04:20:12 +00:00
|
|
|
ClearChromeImageCache();
|
|
|
|
}
|
|
|
|
} else if (strcmp(aTopic, "profile-before-change") == 0 ||
|
|
|
|
strcmp(aTopic, "xpcom-shutdown") == 0) {
|
|
|
|
mCacheTracker = nullptr;
|
2010-07-12 01:01:53 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
} else {
|
2010-07-12 01:01:53 +00:00
|
|
|
// (Nothing else should bring us here)
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(0, "Invalid topic received");
|
2010-07-12 01:01:53 +00:00
|
|
|
}
|
|
|
|
|
2009-07-15 07:22:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-12 02:30:15 +00:00
|
|
|
void imgLoader::ReadAcceptHeaderPref()
|
2009-07-15 07:22:40 +00:00
|
|
|
{
|
2011-06-12 02:30:15 +00:00
|
|
|
nsAdoptingCString accept = Preferences::GetCString("image.http.accept");
|
2015-04-07 21:49:00 +00:00
|
|
|
if (accept) {
|
2009-07-15 07:22:40 +00:00
|
|
|
mAcceptHeader = accept;
|
2015-04-07 21:49:00 +00:00
|
|
|
} else {
|
|
|
|
mAcceptHeader =
|
|
|
|
IMAGE_PNG "," IMAGE_WILDCARD ";q=0.8," ANY_WILDCARD ";q=0.5";
|
|
|
|
}
|
2009-07-15 07:22:40 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgLoader::ClearCache(bool chrome)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-04-07 21:49:00 +00:00
|
|
|
if (chrome) {
|
2008-09-04 23:00:42 +00:00
|
|
|
return ClearChromeImageCache();
|
2015-04-07 21:49:00 +00:00
|
|
|
} else {
|
2008-09-04 23:00:42 +00:00
|
|
|
return ClearImageCache();
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
2015-10-26 20:03:26 +00:00
|
|
|
imgLoader::FindEntryProperties(nsIURI* uri,
|
2016-04-11 09:00:03 +00:00
|
|
|
nsIDOMDocument* aDOMDoc,
|
2015-10-26 20:03:26 +00:00
|
|
|
nsIProperties** _retval)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2016-04-11 09:00:03 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDoc);
|
2015-10-27 18:12:46 +00:00
|
|
|
ImageCacheKey key(uri, doc);
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheTable& cache = GetCache(key);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheEntry> entry;
|
2015-04-28 18:45:45 +00:00
|
|
|
if (cache.Get(key, getter_AddRefs(entry)) && entry) {
|
2015-04-07 21:49:00 +00:00
|
|
|
if (mCacheTracker && entry->HasNoProxies()) {
|
2012-06-26 04:20:12 +00:00
|
|
|
mCacheTracker->MarkUsed(entry);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> request = entry->GetRequest();
|
2008-09-04 23:00:42 +00:00
|
|
|
if (request) {
|
2015-03-05 06:18:09 +00:00
|
|
|
nsCOMPtr<nsIProperties> properties = request->Properties();
|
|
|
|
properties.forget(_retval);
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-28 20:01:07 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
imgLoader::ClearCacheForControlledDocument(nsIDocument* aDoc)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDoc);
|
2016-02-02 15:36:30 +00:00
|
|
|
AutoTArray<RefPtr<imgCacheEntry>, 128> entriesToBeRemoved;
|
2015-10-28 20:01:07 +00:00
|
|
|
imgCacheTable& cache = GetCache(false);
|
|
|
|
for (auto iter = cache.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto& key = iter.Key();
|
|
|
|
if (key.ControlledDocument() == aDoc) {
|
|
|
|
entriesToBeRemoved.AppendElement(iter.Data());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto& entry : entriesToBeRemoved) {
|
|
|
|
if (!RemoveFromCache(entry)) {
|
|
|
|
NS_WARNING("Couldn't remove an entry from the cache in ClearCacheForControlledDocument()\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgLoader::Shutdown()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2014-04-08 22:51:33 +00:00
|
|
|
NS_IF_RELEASE(gSingleton);
|
|
|
|
NS_IF_RELEASE(gPBSingleton);
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult
|
|
|
|
imgLoader::ClearChromeImageCache()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2012-06-26 04:20:12 +00:00
|
|
|
return EvictEntries(mChromeCache);
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult
|
|
|
|
imgLoader::ClearImageCache()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2012-06-26 04:20:12 +00:00
|
|
|
return EvictEntries(mCache);
|
2009-05-07 20:55:06 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgLoader::MinimizeCaches()
|
2009-05-07 20:55:06 +00:00
|
|
|
{
|
2012-06-26 04:20:12 +00:00
|
|
|
EvictEntries(mCacheQueue);
|
|
|
|
EvictEntries(mChromeCacheQueue);
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
bool
|
2015-04-28 18:45:45 +00:00
|
|
|
imgLoader::PutIntoCache(const ImageCacheKey& aKey, imgCacheEntry* entry)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheTable& cache = GetCache(aKey);
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-04-28 18:45:45 +00:00
|
|
|
"imgLoader::PutIntoCache", "uri", aKey.Spec());
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-05-01 20:01:51 +00:00
|
|
|
// Check to see if this request already exists in the cache. If so, we'll
|
|
|
|
// replace the old version.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheEntry> tmpCacheEntry;
|
2015-04-28 18:45:45 +00:00
|
|
|
if (cache.Get(aKey, getter_AddRefs(tmpCacheEntry)) && tmpCacheEntry) {
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2015-04-07 21:49:00 +00:00
|
|
|
("[this=%p] imgLoader::PutIntoCache -- Element already in the cache",
|
|
|
|
nullptr));
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> tmpRequest = tmpCacheEntry->GetRequest();
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2008-09-30 21:47:47 +00:00
|
|
|
// If it already exists, and we're putting the same key into the cache, we
|
|
|
|
// should remove the old version.
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2015-04-07 21:49:00 +00:00
|
|
|
("[this=%p] imgLoader::PutIntoCache -- Replacing cached element",
|
|
|
|
nullptr));
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
RemoveFromCache(aKey);
|
2008-09-30 21:47:47 +00:00
|
|
|
} else {
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2015-04-07 21:49:00 +00:00
|
|
|
("[this=%p] imgLoader::PutIntoCache --"
|
|
|
|
" Element NOT already in the cache", nullptr));
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
cache.Put(aKey, entry);
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2009-03-17 21:07:16 +00:00
|
|
|
// We can be called to resurrect an evicted entry.
|
2015-04-07 21:49:00 +00:00
|
|
|
if (entry->Evicted()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
entry->SetEvicted(false);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-03-17 21:07:16 +00:00
|
|
|
|
|
|
|
// If we're resurrecting an entry with no proxies, put it back in the
|
|
|
|
// tracker and queue.
|
|
|
|
if (entry->HasNoProxies()) {
|
|
|
|
nsresult addrv = NS_OK;
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (mCacheTracker) {
|
2012-06-26 04:20:12 +00:00
|
|
|
addrv = mCacheTracker->AddObject(entry);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-03-17 21:07:16 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(addrv)) {
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheQueue& queue = GetCacheQueue(aKey);
|
2009-03-17 21:07:16 +00:00
|
|
|
queue.Push(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> request = entry->GetRequest();
|
2011-10-17 14:59:28 +00:00
|
|
|
request->SetIsInCache(true);
|
2014-09-05 21:36:11 +00:00
|
|
|
RemoveFromUncachedImages(request);
|
2009-03-17 21:07:16 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-01-31 02:17:47 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
bool
|
|
|
|
imgLoader::SetHasNoProxies(imgRequest* aRequest, imgCacheEntry* aEntry)
|
2009-01-31 02:17:47 +00:00
|
|
|
{
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-05-20 17:21:13 +00:00
|
|
|
"imgLoader::SetHasNoProxies", "uri",
|
|
|
|
aRequest->CacheKey().Spec());
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2014-09-11 02:47:00 +00:00
|
|
|
aEntry->SetHasNoProxies(true);
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (aEntry->Evicted()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheQueue& queue = GetCacheQueue(aRequest->IsChrome());
|
2009-01-31 02:17:47 +00:00
|
|
|
|
|
|
|
nsresult addrv = NS_OK;
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (mCacheTracker) {
|
2014-09-11 02:47:00 +00:00
|
|
|
addrv = mCacheTracker->AddObject(aEntry);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(addrv)) {
|
2014-09-11 02:47:00 +00:00
|
|
|
queue.Push(aEntry);
|
2009-01-31 02:17:47 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheTable& cache = GetCache(aRequest->IsChrome());
|
2008-09-04 23:00:42 +00:00
|
|
|
CheckCacheLimits(cache, queue);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
bool
|
|
|
|
imgLoader::SetHasProxies(imgRequest* aRequest)
|
2009-01-31 02:17:47 +00:00
|
|
|
{
|
|
|
|
VerifyCacheSizes();
|
|
|
|
|
2015-05-20 17:21:13 +00:00
|
|
|
const ImageCacheKey& key = aRequest->CacheKey();
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheTable& cache = GetCache(key);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-04-28 18:45:45 +00:00
|
|
|
"imgLoader::SetHasProxies", "uri", key.Spec());
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheEntry> entry;
|
2015-04-28 18:45:45 +00:00
|
|
|
if (cache.Get(key, getter_AddRefs(entry)) && entry) {
|
2014-09-11 02:47:00 +00:00
|
|
|
// Make sure the cache entry is for the right request
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> entryRequest = entry->GetRequest();
|
2014-09-11 02:47:00 +00:00
|
|
|
if (entryRequest == aRequest && entry->HasNoProxies()) {
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheQueue& queue = GetCacheQueue(key);
|
2014-09-11 02:47:00 +00:00
|
|
|
queue.Remove(entry);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (mCacheTracker) {
|
2014-09-11 02:47:00 +00:00
|
|
|
mCacheTracker->RemoveObject(entry);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2014-09-11 02:47:00 +00:00
|
|
|
entry->SetHasNoProxies(false);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2014-09-11 02:47:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-01-31 02:17:47 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
2015-04-28 18:45:45 +00:00
|
|
|
imgLoader::CacheEntriesChanged(bool aForChrome, int32_t aSizeDiff /* = 0 */)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheQueue& queue = GetCacheQueue(aForChrome);
|
2008-09-04 23:00:42 +00:00
|
|
|
queue.MarkDirty();
|
2015-04-28 18:45:45 +00:00
|
|
|
queue.UpdateSize(aSizeDiff);
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgLoader::CheckCacheLimits(imgCacheTable& cache, imgCacheQueue& queue)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-04-07 21:49:00 +00:00
|
|
|
if (queue.GetNumElements() == 0) {
|
2013-03-29 20:14:19 +00:00
|
|
|
NS_ASSERTION(queue.GetSize() == 0,
|
2008-09-04 23:00:42 +00:00
|
|
|
"imgLoader::CheckCacheLimits -- incorrect cache size");
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2014-07-19 01:47:39 +00:00
|
|
|
// Remove entries from the cache until we're back at our desired max size.
|
|
|
|
while (queue.GetSize() > sCacheMaxSize) {
|
2008-09-04 23:00:42 +00:00
|
|
|
// Remove the first entry in the queue.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheEntry> entry(queue.Pop());
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(entry, "imgLoader::CheckCacheLimits -- NULL entry pointer");
|
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> req = entry->GetRequest();
|
2015-05-11 20:42:30 +00:00
|
|
|
if (req) {
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-05-11 20:42:30 +00:00
|
|
|
"imgLoader::CheckCacheLimits",
|
2015-05-20 17:21:13 +00:00
|
|
|
"entry", req->CacheKey().Spec());
|
2015-05-11 20:42:30 +00:00
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (entry) {
|
2008-09-04 23:00:42 +00:00
|
|
|
RemoveFromCache(entry);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
bool
|
|
|
|
imgLoader::ValidateRequestWithNewChannel(imgRequest* request,
|
|
|
|
nsIURI* aURI,
|
|
|
|
nsIURI* aInitialDocumentURI,
|
|
|
|
nsIURI* aReferrerURI,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsISupports* aCX,
|
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
nsContentPolicyType aLoadPolicyType,
|
|
|
|
imgRequestProxy** aProxyRequest,
|
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
|
|
|
int32_t aCORSMode)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
// now we need to insert a new channel request object inbetween the real
|
|
|
|
// request and the proxy that basically delays loading the image until it
|
|
|
|
// gets a 304 or figures out that this needs to be a new request
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2009-01-31 02:17:47 +00:00
|
|
|
// If we're currently in the middle of validating this request, just hand
|
|
|
|
// back a proxy to it; the required work will be done for us.
|
2015-03-24 02:37:45 +00:00
|
|
|
if (request->GetValidator()) {
|
2012-10-12 12:43:01 +00:00
|
|
|
rv = CreateNewProxyForRequest(request, aLoadGroup, aObserver,
|
|
|
|
aLoadFlags, aProxyRequest);
|
2010-05-25 14:34:04 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-05-25 14:34:04 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2010-08-02 19:44:49 +00:00
|
|
|
if (*aProxyRequest) {
|
|
|
|
imgRequestProxy* proxy = static_cast<imgRequestProxy*>(*aProxyRequest);
|
|
|
|
|
|
|
|
// We will send notifications from imgCacheValidator::OnStartRequest().
|
|
|
|
// In the mean time, we must defer notifications because we are added to
|
|
|
|
// the imgRequest's proxy list, and we can get extra notifications
|
2015-10-29 23:37:42 +00:00
|
|
|
// resulting from methods such as StartDecoding(). See bug 579122.
|
2011-10-17 14:59:28 +00:00
|
|
|
proxy->SetNotificationsDeferred(true);
|
2010-08-02 19:44:49 +00:00
|
|
|
|
|
|
|
// Attach the proxy without notifying
|
2015-03-24 02:37:45 +00:00
|
|
|
request->GetValidator()->AddProxy(proxy);
|
2010-08-02 19:44:49 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
return NS_SUCCEEDED(rv);
|
|
|
|
|
|
|
|
} else {
|
2011-07-01 17:03:42 +00:00
|
|
|
// We will rely on Necko to cache this request when it's possible, and to
|
|
|
|
// tell imgCacheValidator::OnStartRequest whether the request came from its
|
|
|
|
// cache.
|
2008-09-04 23:00:42 +00:00
|
|
|
nsCOMPtr<nsIChannel> newChannel;
|
2011-09-20 21:00:42 +00:00
|
|
|
bool forcePrincipalCheck;
|
2008-09-04 23:00:42 +00:00
|
|
|
rv = NewImageChannel(getter_AddRefs(newChannel),
|
2011-09-20 21:00:42 +00:00
|
|
|
&forcePrincipalCheck,
|
2008-09-04 23:00:42 +00:00
|
|
|
aURI,
|
|
|
|
aInitialDocumentURI,
|
|
|
|
aReferrerURI,
|
2014-11-18 13:46:53 +00:00
|
|
|
aReferrerPolicy,
|
2008-09-04 23:00:42 +00:00
|
|
|
aLoadGroup,
|
2009-07-15 07:22:40 +00:00
|
|
|
mAcceptHeader,
|
2010-05-20 20:08:02 +00:00
|
|
|
aLoadFlags,
|
2014-08-19 21:49:38 +00:00
|
|
|
aLoadPolicyType,
|
2014-09-21 16:45:34 +00:00
|
|
|
aLoadingPrincipal,
|
2016-04-13 13:34:36 +00:00
|
|
|
aCX,
|
|
|
|
mRespectPrivacy);
|
2008-09-04 23:00:42 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequestProxy> req;
|
2008-09-04 23:00:42 +00:00
|
|
|
rv = CreateNewProxyForRequest(request, aLoadGroup, aObserver,
|
2012-11-04 03:04:07 +00:00
|
|
|
aLoadFlags, getter_AddRefs(req));
|
2008-09-04 23:00:42 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2009-07-28 16:13:48 +00:00
|
|
|
// Make sure that OnStatus/OnProgress calls have the right request set...
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsProgressNotificationProxy> progressproxy =
|
2011-07-01 17:03:38 +00:00
|
|
|
new nsProgressNotificationProxy(newChannel, req);
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!progressproxy) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-07-28 16:13:48 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheValidator> hvc =
|
2015-04-07 21:49:00 +00:00
|
|
|
new imgCacheValidator(progressproxy, this, request, aCX,
|
|
|
|
forcePrincipalCheck);
|
2011-07-14 18:47:34 +00:00
|
|
|
|
2013-09-28 18:28:42 +00:00
|
|
|
// Casting needed here to get past multiple inheritance.
|
|
|
|
nsCOMPtr<nsIStreamListener> listener =
|
|
|
|
do_QueryInterface(static_cast<nsIThreadRetargetableStreamListener*>(hvc));
|
|
|
|
NS_ENSURE_TRUE(listener, false);
|
2011-07-14 18:47:34 +00:00
|
|
|
|
2012-03-02 05:13:54 +00:00
|
|
|
// We must set the notification callbacks before setting up the
|
|
|
|
// CORS listener, because that's also interested inthe
|
|
|
|
// notification callbacks.
|
|
|
|
newChannel->SetNotificationCallbacks(hvc);
|
|
|
|
|
2011-07-14 18:47:34 +00:00
|
|
|
if (aCORSMode != imgIRequest::CORS_NONE) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool withCredentials = aCORSMode == imgIRequest::CORS_USE_CREDENTIALS;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsCORSListenerProxy> corsproxy =
|
2013-09-28 18:28:42 +00:00
|
|
|
new nsCORSListenerProxy(listener, aLoadingPrincipal, withCredentials);
|
2015-04-23 00:30:10 +00:00
|
|
|
rv = corsproxy->Init(newChannel, DataURIHandling::Allow);
|
2011-07-14 18:47:34 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-07-14 18:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
listener = corsproxy;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
request->SetValidator(hvc);
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2010-08-02 19:44:49 +00:00
|
|
|
// We will send notifications from imgCacheValidator::OnStartRequest().
|
|
|
|
// In the mean time, we must defer notifications because we are added to
|
|
|
|
// the imgRequest's proxy list, and we can get extra notifications
|
2015-10-29 23:37:42 +00:00
|
|
|
// resulting from methods such as StartDecoding(). See bug 579122.
|
2015-03-05 06:18:09 +00:00
|
|
|
req->SetNotificationsDeferred(true);
|
2010-08-02 19:44:49 +00:00
|
|
|
|
|
|
|
// Add the proxy without notifying
|
2015-03-05 06:18:09 +00:00
|
|
|
hvc->AddProxy(req);
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2014-06-03 20:37:46 +00:00
|
|
|
mozilla::net::PredictorLearn(aURI, aInitialDocumentURI,
|
|
|
|
nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE, aLoadGroup);
|
2013-10-25 21:56:58 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
rv = newChannel->AsyncOpen(listener, nullptr);
|
2015-03-05 06:18:09 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-03-05 06:18:09 +00:00
|
|
|
req.forget(aProxyRequest);
|
|
|
|
return true;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
bool
|
|
|
|
imgLoader::ValidateEntry(imgCacheEntry* aEntry,
|
|
|
|
nsIURI* aURI,
|
|
|
|
nsIURI* aInitialDocumentURI,
|
|
|
|
nsIURI* aReferrerURI,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsISupports* aCX,
|
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
nsContentPolicyType aLoadPolicyType,
|
|
|
|
bool aCanMakeNewChannel,
|
|
|
|
imgRequestProxy** aProxyRequest,
|
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
|
|
|
int32_t aCORSMode)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_SCOPE(gImgLog, "imgLoader::ValidateEntry");
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasExpired;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t expirationTime = aEntry->GetExpiryTime();
|
2008-09-04 23:00:42 +00:00
|
|
|
if (expirationTime <= SecondsFromPRTime(PR_Now())) {
|
2011-10-17 14:59:28 +00:00
|
|
|
hasExpired = true;
|
2008-09-04 23:00:42 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
hasExpired = false;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Special treatment for file URLs - aEntry has expired if file has changed
|
|
|
|
nsCOMPtr<nsIFileURL> fileUrl(do_QueryInterface(aURI));
|
|
|
|
if (fileUrl) {
|
2015-10-20 05:15:25 +00:00
|
|
|
uint32_t lastModTime = aEntry->GetLoadTime();
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> theFile;
|
|
|
|
rv = fileUrl->GetFile(getter_AddRefs(theFile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-08-30 07:10:35 +00:00
|
|
|
PRTime fileLastMod;
|
2008-09-04 23:00:42 +00:00
|
|
|
rv = theFile->GetLastModifiedTime(&fileLastMod);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// nsIFile uses millisec, NSPR usec
|
|
|
|
fileLastMod *= 1000;
|
|
|
|
hasExpired = SecondsFromPRTime((PRTime)fileLastMod) > lastModTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> request(aEntry->GetRequest());
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!request) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2014-11-18 13:46:53 +00:00
|
|
|
if (!ValidateSecurityInfo(request, aEntry->ForcePrincipalCheck(),
|
|
|
|
aCORSMode, aLoadingPrincipal,
|
2015-03-24 16:18:48 +00:00
|
|
|
aCX, aReferrerPolicy))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-07-14 18:47:34 +00:00
|
|
|
|
2014-10-22 09:48:36 +00:00
|
|
|
// data URIs are immutable and by their nature can't leak data, so we can
|
|
|
|
// just return true in that case. Doing so would mean that shift-reload
|
|
|
|
// doesn't reload data URI documents/images though (which is handy for
|
|
|
|
// debugging during gecko development) so we make an exception in that case.
|
2012-11-21 00:58:32 +00:00
|
|
|
nsAutoCString scheme;
|
|
|
|
aURI->GetScheme(scheme);
|
2014-10-22 09:48:36 +00:00
|
|
|
if (scheme.EqualsLiteral("data") &&
|
|
|
|
!(aLoadFlags & nsIRequest::LOAD_BYPASS_CACHE)) {
|
2012-11-21 00:58:32 +00:00
|
|
|
return true;
|
2014-10-22 09:48:36 +00:00
|
|
|
}
|
2012-11-21 00:58:32 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool validateRequest = false;
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
// If the request's loadId is the same as the aCX, then it is ok to use
|
|
|
|
// this one because it has already been validated for this context.
|
|
|
|
//
|
2012-07-30 14:20:58 +00:00
|
|
|
// XXX: nullptr seems to be a 'special' key value that indicates that NO
|
2008-09-04 23:00:42 +00:00
|
|
|
// validation is required.
|
|
|
|
//
|
2015-04-07 21:49:00 +00:00
|
|
|
void *key = (void*) aCX;
|
2015-03-24 02:37:45 +00:00
|
|
|
if (request->LoadId() != key) {
|
2009-11-12 23:00:30 +00:00
|
|
|
// If we would need to revalidate this entry, but we're being told to
|
|
|
|
// bypass the cache, we don't allow this entry to be used.
|
2015-04-07 21:49:00 +00:00
|
|
|
if (aLoadFlags & nsIRequest::LOAD_BYPASS_CACHE) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-11-12 23:00:30 +00:00
|
|
|
|
2016-04-02 18:53:12 +00:00
|
|
|
if (MOZ_UNLIKELY(ChaosMode::isActive(ChaosFeature::ImageCache))) {
|
|
|
|
if (ChaosMode::randomUint32LessThan(4) < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
// Determine whether the cache aEntry must be revalidated...
|
|
|
|
validateRequest = ShouldRevalidateEntry(aEntry, aLoadFlags, hasExpired);
|
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2013-03-29 20:14:19 +00:00
|
|
|
("imgLoader::ValidateEntry validating cache entry. "
|
2008-09-04 23:00:42 +00:00
|
|
|
"validateRequest = %d", validateRequest));
|
2015-11-16 17:21:00 +00:00
|
|
|
} else if (!key && MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString spec;
|
2008-09-04 23:00:42 +00:00
|
|
|
aURI->GetSpec(spec);
|
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2013-03-29 20:14:19 +00:00
|
|
|
("imgLoader::ValidateEntry BYPASSING cache validation for %s "
|
2008-09-04 23:00:42 +00:00
|
|
|
"because of NULL LoadID", spec.get()));
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2009-01-05 05:52:22 +00:00
|
|
|
// We can't use a cached request if it comes from a different
|
|
|
|
// application cache than this load is expecting.
|
|
|
|
nsCOMPtr<nsIApplicationCacheContainer> appCacheContainer;
|
|
|
|
nsCOMPtr<nsIApplicationCache> requestAppCache;
|
|
|
|
nsCOMPtr<nsIApplicationCache> groupAppCache;
|
2015-03-24 02:37:45 +00:00
|
|
|
if ((appCacheContainer = do_GetInterface(request->GetRequest()))) {
|
2009-01-05 05:52:22 +00:00
|
|
|
appCacheContainer->GetApplicationCache(getter_AddRefs(requestAppCache));
|
2015-03-24 02:37:45 +00:00
|
|
|
}
|
|
|
|
if ((appCacheContainer = do_QueryInterface(aLoadGroup))) {
|
2009-01-05 05:52:22 +00:00
|
|
|
appCacheContainer->GetApplicationCache(getter_AddRefs(groupAppCache));
|
2015-03-24 02:37:45 +00:00
|
|
|
}
|
2009-01-05 05:52:22 +00:00
|
|
|
|
|
|
|
if (requestAppCache != groupAppCache) {
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2009-01-05 05:52:22 +00:00
|
|
|
("imgLoader::ValidateEntry - Unable to use cached imgRequest "
|
|
|
|
"[request=%p] because of mismatched application caches\n",
|
|
|
|
address_of(request)));
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-01-05 05:52:22 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
if (validateRequest && aCanMakeNewChannel) {
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_SCOPE(gImgLog,
|
2015-04-07 21:49:00 +00:00
|
|
|
"imgLoader::ValidateRequest |cache hit| must validate");
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
return ValidateRequestWithNewChannel(request, aURI, aInitialDocumentURI,
|
2014-11-18 13:46:53 +00:00
|
|
|
aReferrerURI, aReferrerPolicy,
|
|
|
|
aLoadGroup, aObserver,
|
2014-08-19 21:49:38 +00:00
|
|
|
aCX, aLoadFlags, aLoadPolicyType,
|
|
|
|
aProxyRequest, aLoadingPrincipal,
|
|
|
|
aCORSMode);
|
2011-07-14 18:47:34 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
return !validateRequest;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
bool
|
2015-04-28 18:45:45 +00:00
|
|
|
imgLoader::RemoveFromCache(const ImageCacheKey& aKey)
|
2013-09-28 18:28:42 +00:00
|
|
|
{
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-04-28 18:45:45 +00:00
|
|
|
"imgLoader::RemoveFromCache", "uri", aKey.Spec());
|
2013-09-28 18:28:42 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
imgCacheTable& cache = GetCache(aKey);
|
|
|
|
imgCacheQueue& queue = GetCacheQueue(aKey);
|
2013-09-28 18:28:42 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheEntry> entry;
|
2015-04-28 18:45:45 +00:00
|
|
|
if (cache.Get(aKey, getter_AddRefs(entry)) && entry) {
|
|
|
|
cache.Remove(aKey);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(!entry->Evicted(), "Evicting an already-evicted cache entry!");
|
2009-01-31 02:17:47 +00:00
|
|
|
|
|
|
|
// Entries with no proxies are in the tracker.
|
|
|
|
if (entry->HasNoProxies()) {
|
2015-04-07 21:49:00 +00:00
|
|
|
if (mCacheTracker) {
|
2012-06-26 04:20:12 +00:00
|
|
|
mCacheTracker->RemoveObject(entry);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
queue.Remove(entry);
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
entry->SetEvicted(true);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> request = entry->GetRequest();
|
2011-10-17 14:59:28 +00:00
|
|
|
request->SetIsInCache(false);
|
2014-09-05 21:36:11 +00:00
|
|
|
AddToUncachedImages(request);
|
2009-03-17 21:07:16 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2015-04-07 21:49:00 +00:00
|
|
|
|
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
bool
|
|
|
|
imgLoader::RemoveFromCache(imgCacheEntry* entry)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_STATIC_FUNC(gImgLog, "imgLoader::RemoveFromCache entry");
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> request = entry->GetRequest();
|
2008-09-04 23:00:42 +00:00
|
|
|
if (request) {
|
2015-05-20 17:21:13 +00:00
|
|
|
const ImageCacheKey& key = request->CacheKey();
|
|
|
|
imgCacheTable& cache = GetCache(key);
|
|
|
|
imgCacheQueue& queue = GetCacheQueue(key);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-05-20 17:21:13 +00:00
|
|
|
"imgLoader::RemoveFromCache", "entry's uri",
|
|
|
|
key.Spec());
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-05-20 17:21:13 +00:00
|
|
|
cache.Remove(key);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-05-20 17:21:13 +00:00
|
|
|
if (entry->HasNoProxies()) {
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_STATIC_FUNC(gImgLog,
|
2015-05-20 17:21:13 +00:00
|
|
|
"imgLoader::RemoveFromCache removing from tracker");
|
|
|
|
if (mCacheTracker) {
|
|
|
|
mCacheTracker->RemoveObject(entry);
|
2009-01-31 02:17:47 +00:00
|
|
|
}
|
2015-05-20 17:21:13 +00:00
|
|
|
queue.Remove(entry);
|
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-05-20 17:21:13 +00:00
|
|
|
entry->SetEvicted(true);
|
|
|
|
request->SetIsInCache(false);
|
|
|
|
AddToUncachedImages(request);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-05-20 17:21:13 +00:00
|
|
|
return true;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-01-31 02:17:47 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult
|
|
|
|
imgLoader::EvictEntries(imgCacheTable& aCacheToClear)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_STATIC_FUNC(gImgLog, "imgLoader::EvictEntries table");
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
// We have to make a temporary, since RemoveFromCache removes the element
|
|
|
|
// from the queue, invalidating iterators.
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<imgCacheEntry> > entries;
|
2015-11-11 05:30:02 +00:00
|
|
|
for (auto iter = aCacheToClear.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
RefPtr<imgCacheEntry>& data = iter.Data();
|
|
|
|
entries.AppendElement(data);
|
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
for (uint32_t i = 0; i < entries.Length(); ++i) {
|
|
|
|
if (!RemoveFromCache(entries[i])) {
|
2008-09-04 23:00:42 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
MOZ_ASSERT(aCacheToClear.Count() == 0);
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult
|
|
|
|
imgLoader::EvictEntries(imgCacheQueue& aQueueToClear)
|
2009-05-07 20:55:06 +00:00
|
|
|
{
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_STATIC_FUNC(gImgLog, "imgLoader::EvictEntries queue");
|
2009-05-07 20:55:06 +00:00
|
|
|
|
|
|
|
// We have to make a temporary, since RemoveFromCache removes the element
|
|
|
|
// from the queue, invalidating iterators.
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<imgCacheEntry> > entries(aQueueToClear.GetNumElements());
|
2015-04-07 21:49:00 +00:00
|
|
|
for (imgCacheQueue::const_iterator i = aQueueToClear.begin();
|
|
|
|
i != aQueueToClear.end(); ++i) {
|
2009-05-07 20:55:06 +00:00
|
|
|
entries.AppendElement(*i);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-05-07 20:55:06 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
for (uint32_t i = 0; i < entries.Length(); ++i) {
|
|
|
|
if (!RemoveFromCache(entries[i])) {
|
2009-05-07 20:55:06 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-07 20:55:06 +00:00
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
MOZ_ASSERT(aQueueToClear.GetNumElements() == 0);
|
|
|
|
|
2009-05-07 20:55:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgLoader::AddToUncachedImages(imgRequest* aRequest)
|
2014-09-05 21:36:11 +00:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mUncachedImagesMutex);
|
|
|
|
mUncachedImages.PutEntry(aRequest);
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgLoader::RemoveFromUncachedImages(imgRequest* aRequest)
|
2014-09-05 21:36:11 +00:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mUncachedImagesMutex);
|
|
|
|
mUncachedImages.RemoveEntry(aRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
#define LOAD_FLAGS_CACHE_MASK (nsIRequest::LOAD_BYPASS_CACHE | \
|
|
|
|
nsIRequest::LOAD_FROM_CACHE)
|
|
|
|
|
|
|
|
#define LOAD_FLAGS_VALIDATE_MASK (nsIRequest::VALIDATE_ALWAYS | \
|
|
|
|
nsIRequest::VALIDATE_NEVER | \
|
|
|
|
nsIRequest::VALIDATE_ONCE_PER_SESSION)
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgLoader::LoadImageXPCOM(nsIURI* aURI,
|
|
|
|
nsIURI* aInitialDocumentURI,
|
|
|
|
nsIURI* aReferrerURI,
|
|
|
|
const nsAString& aReferrerPolicy,
|
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsISupports* aCX,
|
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
nsISupports* aCacheKey,
|
|
|
|
nsContentPolicyType aContentPolicyType,
|
|
|
|
imgIRequest** _retval)
|
2001-01-22 22:01:03 +00:00
|
|
|
{
|
2014-08-19 21:49:38 +00:00
|
|
|
// Optional parameter, so defaults to 0 (== TYPE_INVALID)
|
|
|
|
if (!aContentPolicyType) {
|
2015-09-20 21:55:59 +00:00
|
|
|
aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE;
|
2014-08-19 21:49:38 +00:00
|
|
|
}
|
2015-04-07 21:49:00 +00:00
|
|
|
imgRequestProxy* proxy;
|
2014-11-18 13:46:53 +00:00
|
|
|
ReferrerPolicy refpol = ReferrerPolicyFromString(aReferrerPolicy);
|
2016-04-11 08:58:03 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aCX);
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aCX);
|
2014-11-18 13:46:53 +00:00
|
|
|
nsresult rv = LoadImage(aURI,
|
|
|
|
aInitialDocumentURI,
|
|
|
|
aReferrerURI,
|
|
|
|
refpol,
|
|
|
|
aLoadingPrincipal,
|
|
|
|
aLoadGroup,
|
|
|
|
aObserver,
|
2016-04-11 08:58:03 +00:00
|
|
|
node,
|
|
|
|
doc,
|
2014-11-18 13:46:53 +00:00
|
|
|
aLoadFlags,
|
|
|
|
aCacheKey,
|
|
|
|
aContentPolicyType,
|
|
|
|
EmptyString(),
|
|
|
|
&proxy);
|
2012-10-12 12:43:01 +00:00
|
|
|
*_retval = proxy;
|
2014-11-18 13:46:53 +00:00
|
|
|
return rv;
|
2012-10-12 12:43:01 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult
|
|
|
|
imgLoader::LoadImage(nsIURI* aURI,
|
|
|
|
nsIURI* aInitialDocumentURI,
|
|
|
|
nsIURI* aReferrerURI,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver,
|
2016-04-11 08:58:03 +00:00
|
|
|
nsINode *aContext,
|
|
|
|
nsIDocument* aLoadingDocument,
|
2015-04-07 21:49:00 +00:00
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
nsISupports* aCacheKey,
|
|
|
|
nsContentPolicyType aContentPolicyType,
|
|
|
|
const nsAString& initiatorType,
|
|
|
|
imgRequestProxy** _retval)
|
2012-10-12 12:43:01 +00:00
|
|
|
{
|
2014-08-19 21:49:38 +00:00
|
|
|
VerifyCacheSizes();
|
2004-05-05 21:17:31 +00:00
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
NS_ASSERTION(aURI, "imgLoader::LoadImage -- NULL URI pointer");
|
2008-09-04 16:36:27 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!aURI) {
|
2001-03-30 01:59:03 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2001-03-30 01:59:03 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString spec;
|
2008-09-04 23:00:42 +00:00
|
|
|
aURI->GetSpec(spec);
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::LoadImage", "aURI", spec.get());
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> request;
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2001-10-17 05:57:29 +00:00
|
|
|
nsresult rv;
|
2002-09-18 22:08:12 +00:00
|
|
|
nsLoadFlags requestFlags = nsIRequest::LOAD_NORMAL;
|
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool isPrivate = false;
|
|
|
|
|
2012-11-04 03:04:07 +00:00
|
|
|
if (aLoadGroup) {
|
2012-06-26 04:20:12 +00:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> callbacks;
|
|
|
|
aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
|
|
|
|
if (callbacks) {
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(callbacks);
|
|
|
|
isPrivate = loadContext && loadContext->UsePrivateBrowsing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(isPrivate == mRespectPrivacy);
|
|
|
|
#endif
|
|
|
|
|
2002-09-18 22:08:12 +00:00
|
|
|
// Get the default load flags from the loadgroup (if possible)...
|
|
|
|
if (aLoadGroup) {
|
|
|
|
aLoadGroup->GetLoadFlags(&requestFlags);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Merge the default load flags with those passed in via aLoadFlags.
|
|
|
|
// Currently, *only* the caching, validation and background load flags
|
|
|
|
// are merged...
|
|
|
|
//
|
2008-09-04 23:00:42 +00:00
|
|
|
// The flags in aLoadFlags take precedence over the default flags!
|
2002-09-18 22:08:12 +00:00
|
|
|
//
|
|
|
|
if (aLoadFlags & LOAD_FLAGS_CACHE_MASK) {
|
|
|
|
// Override the default caching flags...
|
|
|
|
requestFlags = (requestFlags & ~LOAD_FLAGS_CACHE_MASK) |
|
|
|
|
(aLoadFlags & LOAD_FLAGS_CACHE_MASK);
|
|
|
|
}
|
|
|
|
if (aLoadFlags & LOAD_FLAGS_VALIDATE_MASK) {
|
|
|
|
// Override the default validation flags...
|
|
|
|
requestFlags = (requestFlags & ~LOAD_FLAGS_VALIDATE_MASK) |
|
|
|
|
(aLoadFlags & LOAD_FLAGS_VALIDATE_MASK);
|
|
|
|
}
|
|
|
|
if (aLoadFlags & nsIRequest::LOAD_BACKGROUND) {
|
|
|
|
// Propagate background loading...
|
|
|
|
requestFlags |= nsIRequest::LOAD_BACKGROUND;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t corsmode = imgIRequest::CORS_NONE;
|
2011-07-14 18:47:34 +00:00
|
|
|
if (aLoadFlags & imgILoader::LOAD_CORS_ANONYMOUS) {
|
|
|
|
corsmode = imgIRequest::CORS_ANONYMOUS;
|
|
|
|
} else if (aLoadFlags & imgILoader::LOAD_CORS_USE_CREDENTIALS) {
|
|
|
|
corsmode = imgIRequest::CORS_USE_CREDENTIALS;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheEntry> entry;
|
2001-07-17 01:14:40 +00:00
|
|
|
|
2009-11-12 23:00:30 +00:00
|
|
|
// Look in the cache for our URI, and then validate it.
|
|
|
|
// XXX For now ignore aCacheKey. We will need it in the future
|
|
|
|
// for correctly dealing with image load requests that are a result
|
|
|
|
// of post data.
|
2016-04-11 09:00:03 +00:00
|
|
|
ImageCacheKey key(aURI, aLoadingDocument);
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheTable& cache = GetCache(key);
|
2008-12-12 00:47:47 +00:00
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
if (cache.Get(key, getter_AddRefs(entry)) && entry) {
|
2010-05-20 20:08:02 +00:00
|
|
|
if (ValidateEntry(entry, aURI, aInitialDocumentURI, aReferrerURI,
|
2016-04-11 08:58:03 +00:00
|
|
|
aReferrerPolicy, aLoadGroup, aObserver, aLoadingDocument,
|
2014-11-18 13:46:53 +00:00
|
|
|
requestFlags, aContentPolicyType, true, _retval,
|
2014-08-19 21:49:38 +00:00
|
|
|
aLoadingPrincipal, corsmode)) {
|
2013-07-10 09:56:21 +00:00
|
|
|
request = entry->GetRequest();
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
// If this entry has no proxies, its request has no reference to the
|
|
|
|
// entry.
|
2009-11-12 23:00:30 +00:00
|
|
|
if (entry->HasNoProxies()) {
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog,
|
2015-04-28 18:45:45 +00:00
|
|
|
"imgLoader::LoadImage() adding proxyless entry", "uri", key.Spec());
|
2015-04-07 21:49:00 +00:00
|
|
|
MOZ_ASSERT(!request->HasCacheEntry(),
|
|
|
|
"Proxyless entry's request has cache entry!");
|
2009-11-12 23:00:30 +00:00
|
|
|
request->SetCacheEntry(entry);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (mCacheTracker) {
|
2012-06-26 04:20:12 +00:00
|
|
|
mCacheTracker->MarkUsed(entry);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2013-03-29 20:14:19 +00:00
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2009-11-12 23:00:30 +00:00
|
|
|
entry->Touch();
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
#ifdef DEBUG_joe
|
2015-04-07 21:49:00 +00:00
|
|
|
printf("CACHEGET: %d %s %d\n", time(nullptr), spec.get(),
|
|
|
|
entry->SizeOfData());
|
2008-09-04 23:00:42 +00:00
|
|
|
#endif
|
2015-04-07 21:49:00 +00:00
|
|
|
} else {
|
2009-11-12 23:00:30 +00:00
|
|
|
// We can't use this entry. We'll try to load it off the network, and if
|
|
|
|
// successful, overwrite the old entry in the cache with a new one.
|
2012-07-30 14:20:58 +00:00
|
|
|
entry = nullptr;
|
2001-03-06 04:46:20 +00:00
|
|
|
}
|
2001-10-17 05:57:29 +00:00
|
|
|
}
|
|
|
|
|
2009-07-28 16:13:48 +00:00
|
|
|
// Keep the channel in this scope, so we can adjust its notificationCallbacks
|
|
|
|
// later when we create the proxy.
|
|
|
|
nsCOMPtr<nsIChannel> newChannel;
|
2008-09-04 23:00:42 +00:00
|
|
|
// If we didn't get a cache hit, we need to load from the network.
|
|
|
|
if (!request) {
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_SCOPE(gImgLog, "imgLoader::LoadImage |cache miss|");
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2011-09-20 21:00:42 +00:00
|
|
|
bool forcePrincipalCheck;
|
2002-09-18 22:08:12 +00:00
|
|
|
rv = NewImageChannel(getter_AddRefs(newChannel),
|
2011-09-20 21:00:42 +00:00
|
|
|
&forcePrincipalCheck,
|
2002-09-18 22:08:12 +00:00
|
|
|
aURI,
|
|
|
|
aInitialDocumentURI,
|
|
|
|
aReferrerURI,
|
2014-11-18 13:46:53 +00:00
|
|
|
aReferrerPolicy,
|
2002-09-18 22:08:12 +00:00
|
|
|
aLoadGroup,
|
2009-07-15 07:22:40 +00:00
|
|
|
mAcceptHeader,
|
2010-05-20 20:08:02 +00:00
|
|
|
requestFlags,
|
2014-08-19 21:49:38 +00:00
|
|
|
aContentPolicyType,
|
2014-09-21 16:45:34 +00:00
|
|
|
aLoadingPrincipal,
|
2016-04-13 13:34:36 +00:00
|
|
|
aContext,
|
|
|
|
mRespectPrivacy);
|
2015-04-07 21:49:00 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2002-09-18 22:08:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2012-10-03 22:43:26 +00:00
|
|
|
MOZ_ASSERT(NS_UsePrivateBrowsing(newChannel) == mRespectPrivacy);
|
2012-06-26 04:20:12 +00:00
|
|
|
|
2015-05-20 17:21:13 +00:00
|
|
|
NewRequestAndEntry(forcePrincipalCheck, this, key,
|
|
|
|
getter_AddRefs(request),
|
2015-04-07 21:49:00 +00:00
|
|
|
getter_AddRefs(entry));
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2015-04-07 21:49:00 +00:00
|
|
|
("[this=%p] imgLoader::LoadImage -- Created new imgRequest"
|
|
|
|
" [request=%p]\n", this, request.get()));
|
2001-03-19 21:57:39 +00:00
|
|
|
|
2014-01-30 03:35:40 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> channelLoadGroup;
|
|
|
|
newChannel->GetLoadGroup(getter_AddRefs(channelLoadGroup));
|
2014-12-16 01:40:43 +00:00
|
|
|
request->Init(aURI, aURI, /* aHadInsecureRedirect = */ false,
|
2016-04-11 08:58:03 +00:00
|
|
|
channelLoadGroup, newChannel, entry, aLoadingDocument,
|
2014-11-18 13:46:53 +00:00
|
|
|
aLoadingPrincipal, corsmode, aReferrerPolicy);
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2013-10-16 01:35:44 +00:00
|
|
|
// Add the initiator type for this image load
|
|
|
|
nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(newChannel);
|
|
|
|
if (timedChannel) {
|
|
|
|
timedChannel->SetInitiatorType(initiatorType);
|
|
|
|
}
|
|
|
|
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
// create the proxy listener
|
2011-07-14 18:47:34 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> pl = new ProxyListener(request.get());
|
|
|
|
|
|
|
|
// See if we need to insert a CORS proxy between the proxy listener and the
|
|
|
|
// request.
|
|
|
|
nsCOMPtr<nsIStreamListener> listener = pl;
|
|
|
|
if (corsmode != imgIRequest::CORS_NONE) {
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2012-03-03 04:44:55 +00:00
|
|
|
("[this=%p] imgLoader::LoadImage -- Setting up a CORS load",
|
|
|
|
this));
|
2011-09-29 06:19:26 +00:00
|
|
|
bool withCredentials = corsmode == imgIRequest::CORS_USE_CREDENTIALS;
|
2011-07-14 18:47:34 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsCORSListenerProxy> corsproxy =
|
2012-09-19 02:16:23 +00:00
|
|
|
new nsCORSListenerProxy(pl, aLoadingPrincipal, withCredentials);
|
2015-04-23 00:30:10 +00:00
|
|
|
rv = corsproxy->Init(newChannel, DataURIHandling::Allow);
|
2011-07-14 18:47:34 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2012-03-03 04:44:55 +00:00
|
|
|
("[this=%p] imgLoader::LoadImage -- nsCORSListenerProxy "
|
|
|
|
"creation failed: 0x%x\n", this, rv));
|
|
|
|
request->CancelAndAbort(rv);
|
2011-07-14 18:47:34 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
2011-07-14 18:47:34 +00:00
|
|
|
listener = corsproxy;
|
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2015-04-07 21:49:00 +00:00
|
|
|
("[this=%p] imgLoader::LoadImage -- Calling channel->AsyncOpen()\n",
|
|
|
|
this));
|
2002-03-07 01:50:14 +00:00
|
|
|
|
2014-06-03 20:37:46 +00:00
|
|
|
mozilla::net::PredictorLearn(aURI, aInitialDocumentURI,
|
|
|
|
nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE, aLoadGroup);
|
2013-10-25 21:56:58 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
nsresult openRes = newChannel->AsyncOpen(listener, nullptr);
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
2002-09-18 22:08:12 +00:00
|
|
|
if (NS_FAILED(openRes)) {
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2005-02-16 15:26:04 +00:00
|
|
|
("[this=%p] imgLoader::LoadImage -- AsyncOpen() failed: 0x%x\n",
|
|
|
|
this, openRes));
|
2008-12-22 22:20:46 +00:00
|
|
|
request->CancelAndAbort(openRes);
|
2002-09-18 22:08:12 +00:00
|
|
|
return openRes;
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
}
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
// Try to add the new request into the cache.
|
2015-04-28 18:45:45 +00:00
|
|
|
PutIntoCache(key, entry);
|
2001-02-23 08:36:51 +00:00
|
|
|
} else {
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_MSG_WITH_PARAM(gImgLog,
|
2002-09-18 22:08:12 +00:00
|
|
|
"imgLoader::LoadImage |cache hit|", "request", request);
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 23:00:30 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
// If we didn't get a proxy when validating the cache entry, we need to
|
|
|
|
// create one.
|
2008-09-04 23:00:42 +00:00
|
|
|
if (!*_retval) {
|
2009-11-12 23:00:30 +00:00
|
|
|
// ValidateEntry() has three return values: "Is valid," "might be valid --
|
|
|
|
// validating over network", and "not valid." If we don't have a _retval,
|
|
|
|
// we know ValidateEntry is not validating over the network, so it's safe
|
|
|
|
// to SetLoadId here because we know this request is valid for this context.
|
|
|
|
//
|
|
|
|
// Note, however, that this doesn't guarantee the behaviour we want (one
|
|
|
|
// URL maps to the same image on a page) if we load the same image in a
|
|
|
|
// different tab (see bug 528003), because its load id will get re-set, and
|
|
|
|
// that'll cause us to validate over the network.
|
2016-04-11 08:58:03 +00:00
|
|
|
request->SetLoadId(aLoadingDocument);
|
2003-05-14 05:42:06 +00:00
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_MSG(gImgLog, "imgLoader::LoadImage", "creating proxy request.");
|
2008-09-04 23:00:42 +00:00
|
|
|
rv = CreateNewProxyForRequest(request, aLoadGroup, aObserver,
|
2012-11-04 03:04:07 +00:00
|
|
|
requestFlags, _retval);
|
2010-05-25 14:34:04 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
imgRequestProxy* proxy = *_retval;
|
2003-05-14 05:42:06 +00:00
|
|
|
|
2009-07-28 16:13:48 +00:00
|
|
|
// Make sure that OnStatus/OnProgress calls have the right request set, if
|
|
|
|
// we did create a channel here.
|
|
|
|
if (newChannel) {
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> requestor(
|
|
|
|
new nsProgressNotificationProxy(newChannel, proxy));
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!requestor) {
|
2009-07-28 16:13:48 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2009-07-28 16:13:48 +00:00
|
|
|
newChannel->SetNotificationCallbacks(requestor);
|
|
|
|
}
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
// Note that it's OK to add here even if the request is done. If it is,
|
2010-05-11 03:27:41 +00:00
|
|
|
// it'll send a OnStopRequest() to the proxy in imgRequestProxy::Notify and
|
|
|
|
// the proxy will be removed from the loadgroup.
|
2008-09-04 23:00:42 +00:00
|
|
|
proxy->AddToLoadGroup();
|
2008-09-04 15:23:16 +00:00
|
|
|
|
2010-07-28 21:52:14 +00:00
|
|
|
// If we're loading off the network, explicitly don't notify our proxy,
|
|
|
|
// because necko (or things called from necko, such as imgCacheValidator)
|
|
|
|
// are going to call our notifications asynchronously, and we can't make it
|
|
|
|
// further asynchronous because observers might rely on imagelib completing
|
|
|
|
// its work between the channel's OnStartRequest and OnStopRequest.
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!newChannel) {
|
2010-07-28 21:52:14 +00:00
|
|
|
proxy->NotifyListener();
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
return rv;
|
2003-05-14 05:42:06 +00:00
|
|
|
}
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
NS_ASSERTION(*_retval, "imgLoader::LoadImage -- no return value");
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
return NS_OK;
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgLoader::LoadImageWithChannelXPCOM(nsIChannel* channel,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsISupports* aCX,
|
|
|
|
nsIStreamListener** listener,
|
|
|
|
imgIRequest** _retval)
|
2012-10-12 12:43:01 +00:00
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
imgRequestProxy* proxy;
|
|
|
|
result = LoadImageWithChannel(channel,
|
|
|
|
aObserver,
|
|
|
|
aCX,
|
|
|
|
listener,
|
|
|
|
&proxy);
|
|
|
|
*_retval = proxy;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult
|
|
|
|
imgLoader::LoadImageWithChannel(nsIChannel* channel,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsISupports* aCX,
|
|
|
|
nsIStreamListener** listener,
|
|
|
|
imgRequestProxy** _retval)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_ASSERTION(channel,
|
|
|
|
"imgLoader::LoadImageWithChannel -- NULL channel pointer");
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2012-10-03 22:43:26 +00:00
|
|
|
MOZ_ASSERT(NS_UsePrivateBrowsing(channel) == mRespectPrivacy);
|
2012-06-26 04:20:12 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> request;
|
2001-02-20 22:43:56 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2003-03-26 05:29:11 +00:00
|
|
|
channel->GetURI(getter_AddRefs(uri));
|
2016-04-11 09:00:03 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aCX);
|
2015-10-27 18:12:46 +00:00
|
|
|
ImageCacheKey key(uri, doc);
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2002-09-18 22:08:12 +00:00
|
|
|
nsLoadFlags requestFlags = nsIRequest::LOAD_NORMAL;
|
|
|
|
channel->GetLoadFlags(&requestFlags);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheEntry> entry;
|
2002-09-18 22:08:12 +00:00
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
if (requestFlags & nsIRequest::LOAD_BYPASS_CACHE) {
|
2015-04-28 18:45:45 +00:00
|
|
|
RemoveFromCache(key);
|
2008-09-04 23:00:42 +00:00
|
|
|
} else {
|
|
|
|
// Look in the cache for our URI, and then validate it.
|
|
|
|
// XXX For now ignore aCacheKey. We will need it in the future
|
|
|
|
// for correctly dealing with image load requests that are a result
|
|
|
|
// of post data.
|
2015-04-28 18:45:45 +00:00
|
|
|
imgCacheTable& cache = GetCache(key);
|
|
|
|
if (cache.Get(key, getter_AddRefs(entry)) && entry) {
|
2008-09-04 23:00:42 +00:00
|
|
|
// We don't want to kick off another network load. So we ask
|
|
|
|
// ValidateEntry to only do validation without creating a new proxy. If
|
|
|
|
// it says that the entry isn't valid any more, we'll only use the entry
|
|
|
|
// we're getting if the channel is loading from the cache anyways.
|
|
|
|
//
|
|
|
|
// XXX -- should this be changed? it's pretty much verbatim from the old
|
|
|
|
// code, but seems nonsensical.
|
2014-08-19 21:49:38 +00:00
|
|
|
//
|
|
|
|
// Since aCanMakeNewChannel == false, we don't need to pass content policy
|
|
|
|
// type/principal/etc
|
2014-11-18 13:46:53 +00:00
|
|
|
if (ValidateEntry(entry, uri, nullptr, nullptr, RP_Default,
|
|
|
|
nullptr, aObserver, aCX, requestFlags,
|
2014-08-19 21:49:38 +00:00
|
|
|
nsIContentPolicy::TYPE_INVALID, false, nullptr,
|
|
|
|
nullptr, imgIRequest::CORS_NONE)) {
|
2013-07-10 09:56:21 +00:00
|
|
|
request = entry->GetRequest();
|
2003-04-10 01:01:31 +00:00
|
|
|
} else {
|
2015-11-12 20:09:52 +00:00
|
|
|
nsCOMPtr<nsICacheInfoChannel> cacheChan(do_QueryInterface(channel));
|
2011-09-29 06:19:26 +00:00
|
|
|
bool bUseCacheCopy;
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (cacheChan) {
|
2008-09-04 23:00:42 +00:00
|
|
|
cacheChan->IsFromCache(&bUseCacheCopy);
|
2015-04-07 21:49:00 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
bUseCacheCopy = false;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2013-07-10 09:56:21 +00:00
|
|
|
if (!bUseCacheCopy) {
|
2012-07-30 14:20:58 +00:00
|
|
|
entry = nullptr;
|
2013-07-10 09:56:21 +00:00
|
|
|
} else {
|
|
|
|
request = entry->GetRequest();
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
2002-09-18 22:08:12 +00:00
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
|
|
|
|
if (request && entry) {
|
2015-04-07 21:49:00 +00:00
|
|
|
// If this entry has no proxies, its request has no reference to
|
|
|
|
// the entry.
|
2009-01-31 02:17:47 +00:00
|
|
|
if (entry->HasNoProxies()) {
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog,
|
2015-04-07 21:49:00 +00:00
|
|
|
"imgLoader::LoadImageWithChannel() adding proxyless entry",
|
2015-04-28 18:45:45 +00:00
|
|
|
"uri", key.Spec());
|
2015-04-07 21:49:00 +00:00
|
|
|
MOZ_ASSERT(!request->HasCacheEntry(),
|
|
|
|
"Proxyless entry's request has cache entry!");
|
2009-01-31 02:17:47 +00:00
|
|
|
request->SetCacheEntry(entry);
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (mCacheTracker) {
|
2012-06-26 04:20:12 +00:00
|
|
|
mCacheTracker->MarkUsed(entry);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2013-03-29 20:14:19 +00:00
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
}
|
2002-09-18 22:08:12 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-08 04:21:49 +00:00
|
|
|
|
2002-01-15 05:23:33 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
channel->GetLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
|
2011-06-09 19:03:41 +00:00
|
|
|
// Filter out any load flags not from nsIRequest
|
|
|
|
requestFlags &= nsIRequest::LOAD_REQUESTMASK;
|
2010-07-28 21:52:14 +00:00
|
|
|
|
2011-04-08 04:55:25 +00:00
|
|
|
nsresult rv = NS_OK;
|
2001-02-20 23:35:22 +00:00
|
|
|
if (request) {
|
2001-02-20 22:43:56 +00:00
|
|
|
// we have this in our cache already.. cancel the current (document) load
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
// this should fire an OnStopRequest
|
|
|
|
channel->Cancel(NS_ERROR_PARSED_DATA_CACHED);
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*listener = nullptr; // give them back a null nsIStreamListener
|
2010-07-28 21:52:14 +00:00
|
|
|
|
|
|
|
rv = CreateNewProxyForRequest(request, loadGroup, aObserver,
|
2012-11-04 03:04:07 +00:00
|
|
|
requestFlags, _retval);
|
2010-07-28 21:52:14 +00:00
|
|
|
static_cast<imgRequestProxy*>(*_retval)->NotifyListener();
|
2001-02-20 22:43:56 +00:00
|
|
|
} else {
|
2015-05-20 17:21:13 +00:00
|
|
|
// We use originalURI here to fulfil the imgIRequest contract on GetURI.
|
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
channel->GetOriginalURI(getter_AddRefs(originalURI));
|
|
|
|
|
|
|
|
// XXX(seth): We should be able to just use |key| here, except that |key| is
|
|
|
|
// 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.
|
2015-10-27 18:12:46 +00:00
|
|
|
ImageCacheKey originalURIKey(originalURI, doc);
|
2015-05-20 17:21:13 +00:00
|
|
|
|
2011-09-20 21:00:42 +00:00
|
|
|
// Default to doing a principal check because we don't know who
|
|
|
|
// started that load and whether their principal ended up being
|
|
|
|
// inherited on the channel.
|
2015-05-20 17:21:13 +00:00
|
|
|
NewRequestAndEntry(/* aForcePrincipalCheckForCacheEntry = */ true,
|
|
|
|
this, originalURIKey,
|
|
|
|
getter_AddRefs(request),
|
2015-04-07 21:49:00 +00:00
|
|
|
getter_AddRefs(entry));
|
2001-03-16 02:40:04 +00:00
|
|
|
|
2011-07-14 18:47:32 +00:00
|
|
|
// No principal specified here, because we're not passed one.
|
2014-12-16 01:40:43 +00:00
|
|
|
// In LoadImageWithChannel, the redirects that may have been
|
|
|
|
// assoicated with this load would have gone through necko.
|
|
|
|
// We only have the final URI in ImageLib and hence don't know
|
|
|
|
// if the request went through insecure redirects. But if it did,
|
|
|
|
// 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);
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProxyListener> pl =
|
2015-03-05 06:18:09 +00:00
|
|
|
new ProxyListener(static_cast<nsIStreamListener*>(request.get()));
|
|
|
|
pl.forget(listener);
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
// Try to add the new request into the cache.
|
2015-05-20 17:21:13 +00:00
|
|
|
PutIntoCache(originalURIKey, entry);
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2010-07-28 21:52:14 +00:00
|
|
|
rv = CreateNewProxyForRequest(request, loadGroup, aObserver,
|
2012-11-04 03:04:07 +00:00
|
|
|
requestFlags, _retval);
|
2002-09-18 22:08:12 +00:00
|
|
|
|
2010-07-28 21:52:14 +00:00
|
|
|
// Explicitly don't notify our proxy, because we're loading off the
|
|
|
|
// network, and necko (or things called from necko, such as
|
|
|
|
// imgCacheValidator) are going to call our notifications asynchronously,
|
|
|
|
// and we can't make it further asynchronous because observers might rely
|
|
|
|
// on imagelib completing its work between the channel's OnStartRequest and
|
|
|
|
// OnStopRequest.
|
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-12-05 19:33:08 +00:00
|
|
|
bool
|
|
|
|
imgLoader::SupportImageWithMimeType(const char* aMimeType,
|
|
|
|
AcceptedMimeTypes aAccept
|
|
|
|
/* = AcceptedMimeTypes::IMAGES */)
|
2002-03-23 13:21:33 +00:00
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString mimeType(aMimeType);
|
2002-04-01 21:14:07 +00:00
|
|
|
ToLowerCase(mimeType);
|
2014-12-05 19:33:08 +00:00
|
|
|
|
|
|
|
if (aAccept == AcceptedMimeTypes::IMAGES_AND_DOCUMENTS &&
|
|
|
|
mimeType.EqualsLiteral("image/svg+xml")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-23 05:39:48 +00:00
|
|
|
DecoderType type = DecoderFactory::GetDecoderType(mimeType.get());
|
|
|
|
return type != DecoderType::UNKNOWN;
|
2002-03-23 13:21:33 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgLoader::GetMIMETypeFromContent(nsIRequest* aRequest,
|
|
|
|
const uint8_t* aContents,
|
|
|
|
uint32_t aLength,
|
|
|
|
nsACString& aContentType)
|
2002-05-24 20:54:44 +00:00
|
|
|
{
|
2004-07-19 18:53:02 +00:00
|
|
|
return GetMimeTypeFromContent((const char*)aContents, aLength, aContentType);
|
2002-05-24 20:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult
|
|
|
|
imgLoader::GetMimeTypeFromContent(const char* aContents,
|
|
|
|
uint32_t aLength,
|
|
|
|
nsACString& aContentType)
|
2002-03-23 13:21:33 +00:00
|
|
|
{
|
|
|
|
/* Is it a GIF? */
|
2009-04-06 00:30:03 +00:00
|
|
|
if (aLength >= 6 && (!nsCRT::strncmp(aContents, "GIF87a", 6) ||
|
2015-04-07 21:49:00 +00:00
|
|
|
!nsCRT::strncmp(aContents, "GIF89a", 6))) {
|
2013-01-08 21:40:47 +00:00
|
|
|
aContentType.AssignLiteral(IMAGE_GIF);
|
2002-03-23 13:21:33 +00:00
|
|
|
|
|
|
|
/* or a PNG? */
|
2015-04-07 21:49:00 +00:00
|
|
|
} else if (aLength >= 8 && ((unsigned char)aContents[0]==0x89 &&
|
|
|
|
(unsigned char)aContents[1]==0x50 &&
|
|
|
|
(unsigned char)aContents[2]==0x4E &&
|
|
|
|
(unsigned char)aContents[3]==0x47 &&
|
|
|
|
(unsigned char)aContents[4]==0x0D &&
|
|
|
|
(unsigned char)aContents[5]==0x0A &&
|
|
|
|
(unsigned char)aContents[6]==0x1A &&
|
|
|
|
(unsigned char)aContents[7]==0x0A)) {
|
2013-01-08 21:40:47 +00:00
|
|
|
aContentType.AssignLiteral(IMAGE_PNG);
|
2002-03-23 13:21:33 +00:00
|
|
|
|
|
|
|
/* maybe a JPEG (JFIF)? */
|
|
|
|
/* JFIF files start with SOI APP0 but older files can start with SOI DQT
|
|
|
|
* so we test for SOI followed by any marker, i.e. FF D8 FF
|
|
|
|
* this will also work for SPIFF JPEG files if they appear in the future.
|
|
|
|
*
|
|
|
|
* (JFIF is 0XFF 0XD8 0XFF 0XE0 <skip 2> 0X4A 0X46 0X49 0X46 0X00)
|
|
|
|
*/
|
2015-04-07 21:49:00 +00:00
|
|
|
} else if (aLength >= 3 &&
|
|
|
|
((unsigned char)aContents[0])==0xFF &&
|
|
|
|
((unsigned char)aContents[1])==0xD8 &&
|
|
|
|
((unsigned char)aContents[2])==0xFF) {
|
2013-01-08 21:40:47 +00:00
|
|
|
aContentType.AssignLiteral(IMAGE_JPEG);
|
2002-03-23 13:21:33 +00:00
|
|
|
|
|
|
|
/* or how about ART? */
|
|
|
|
/* ART begins with JG (4A 47). Major version offset 2.
|
2013-08-23 19:51:00 +00:00
|
|
|
* Minor version offset 3. Offset 4 must be nullptr.
|
2002-03-23 13:21:33 +00:00
|
|
|
*/
|
2015-04-07 21:49:00 +00:00
|
|
|
} else if (aLength >= 5 &&
|
|
|
|
((unsigned char) aContents[0])==0x4a &&
|
|
|
|
((unsigned char) aContents[1])==0x47 &&
|
|
|
|
((unsigned char) aContents[4])==0x00 ) {
|
2013-01-08 21:40:47 +00:00
|
|
|
aContentType.AssignLiteral(IMAGE_ART);
|
2002-03-23 13:21:33 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
} else if (aLength >= 2 && !nsCRT::strncmp(aContents, "BM", 2)) {
|
2013-01-08 21:40:47 +00:00
|
|
|
aContentType.AssignLiteral(IMAGE_BMP);
|
2002-03-23 13:21:33 +00:00
|
|
|
|
|
|
|
// ICOs always begin with a 2-byte 0 followed by a 2-byte 1.
|
2005-01-12 20:16:07 +00:00
|
|
|
// CURs begin with 2-byte 0 followed by 2-byte 2.
|
2015-04-07 21:49:00 +00:00
|
|
|
} else if (aLength >= 4 && (!memcmp(aContents, "\000\000\001\000", 4) ||
|
|
|
|
!memcmp(aContents, "\000\000\002\000", 4))) {
|
2013-01-08 21:40:47 +00:00
|
|
|
aContentType.AssignLiteral(IMAGE_ICO);
|
2002-03-23 13:21:33 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
} else {
|
2002-06-11 22:40:29 +00:00
|
|
|
/* none of the above? I give up */
|
2004-07-19 18:53:02 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2002-06-04 08:48:12 +00:00
|
|
|
}
|
|
|
|
|
2004-07-19 18:53:02 +00:00
|
|
|
return NS_OK;
|
2002-03-23 13:21:33 +00:00
|
|
|
}
|
|
|
|
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
/**
|
|
|
|
* proxy stream listener class used to handle multipart/x-mixed-replace
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsIRequest.h"
|
|
|
|
#include "nsIStreamConverterService.h"
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(ProxyListener,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIThreadRetargetableStreamListener,
|
|
|
|
nsIRequestObserver)
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
ProxyListener::ProxyListener(nsIStreamListener* dest) :
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
mDestListener(dest)
|
|
|
|
{
|
|
|
|
/* member initializers and constructor code */
|
|
|
|
}
|
|
|
|
|
|
|
|
ProxyListener::~ProxyListener()
|
|
|
|
{
|
|
|
|
/* destructor code */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** nsIRequestObserver methods **/
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ProxyListener::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
{
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!mDestListener) {
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
|
|
|
if (channel) {
|
2014-10-29 15:35:05 +00:00
|
|
|
// We need to set the initiator type for the image load
|
|
|
|
nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(channel);
|
|
|
|
if (timedChannel) {
|
|
|
|
nsAutoString type;
|
|
|
|
timedChannel->GetInitiatorType(type);
|
|
|
|
if (type.IsEmpty()) {
|
|
|
|
timedChannel->SetInitiatorType(NS_LITERAL_STRING("img"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString contentType;
|
2002-03-20 22:50:33 +00:00
|
|
|
nsresult rv = channel->GetContentType(contentType);
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
if (!contentType.IsEmpty()) {
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
/* If multipart/x-mixed-replace content, we'll insert a MIME decoder
|
|
|
|
in the pipeline to handle the content and pass it along to our
|
|
|
|
original listener.
|
|
|
|
*/
|
2002-01-15 05:23:33 +00:00
|
|
|
if (NS_LITERAL_CSTRING("multipart/x-mixed-replace").Equals(contentType)) {
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsCOMPtr<nsIStreamConverterService> convServ(
|
|
|
|
do_GetService("@mozilla.org/streamConverters;1", &rv));
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIStreamListener> toListener(mDestListener);
|
|
|
|
nsCOMPtr<nsIStreamListener> fromListener;
|
|
|
|
|
2004-06-29 16:45:07 +00:00
|
|
|
rv = convServ->AsyncConvertData("multipart/x-mixed-replace",
|
|
|
|
"*/*",
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
toListener,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr,
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
getter_AddRefs(fromListener));
|
2015-04-07 21:49:00 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
mDestListener = fromListener;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mDestListener->OnStartRequest(aRequest, ctxt);
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ProxyListener::OnStopRequest(nsIRequest* aRequest,
|
|
|
|
nsISupports* ctxt,
|
|
|
|
nsresult status)
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
{
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!mDestListener) {
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
|
|
|
return mDestListener->OnStopRequest(aRequest, ctxt, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** nsIStreamListener methods **/
|
|
|
|
|
2012-09-06 02:41:02 +00:00
|
|
|
NS_IMETHODIMP
|
2015-04-07 21:49:00 +00:00
|
|
|
ProxyListener::OnDataAvailable(nsIRequest* aRequest, nsISupports* ctxt,
|
|
|
|
nsIInputStream* inStr, uint64_t sourceOffset,
|
2012-09-06 02:41:02 +00:00
|
|
|
uint32_t count)
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
{
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!mDestListener) {
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
return mDestListener->OnDataAvailable(aRequest, ctxt, inStr,
|
|
|
|
sourceOffset, count);
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
}
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2013-09-28 18:28:42 +00:00
|
|
|
/** nsThreadRetargetableStreamListener methods **/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ProxyListener::CheckListenerChain()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on the main thread!");
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIThreadRetargetableStreamListener> retargetableListener =
|
|
|
|
do_QueryInterface(mDestListener, &rv);
|
|
|
|
if (retargetableListener) {
|
|
|
|
rv = retargetableListener->CheckListenerChain();
|
|
|
|
}
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2013-09-28 18:28:42 +00:00
|
|
|
("ProxyListener::CheckListenerChain %s [this=%p listener=%p rv=%x]",
|
|
|
|
(NS_SUCCEEDED(rv) ? "success" : "failure"),
|
|
|
|
this, (nsIStreamListener*)mDestListener, rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-01-15 05:23:33 +00:00
|
|
|
/**
|
|
|
|
* http validate class. check a channel for a 304
|
|
|
|
*/
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(imgCacheValidator, nsIStreamListener, nsIRequestObserver,
|
|
|
|
nsIThreadRetargetableStreamListener,
|
|
|
|
nsIChannelEventSink, nsIInterfaceRequestor,
|
|
|
|
nsIAsyncVerifyRedirectCallback)
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2011-07-01 17:03:38 +00:00
|
|
|
imgCacheValidator::imgCacheValidator(nsProgressNotificationProxy* progress,
|
2015-04-07 21:49:00 +00:00
|
|
|
imgLoader* loader, imgRequest* request,
|
2015-03-24 02:37:45 +00:00
|
|
|
nsISupports* aContext,
|
|
|
|
bool forcePrincipalCheckForCacheEntry)
|
2011-07-01 17:03:38 +00:00
|
|
|
: mProgressProxy(progress),
|
|
|
|
mRequest(request),
|
2012-06-26 04:20:12 +00:00
|
|
|
mContext(aContext),
|
2014-12-16 01:40:43 +00:00
|
|
|
mImgLoader(loader),
|
|
|
|
mHadInsecureRedirect(false)
|
2011-07-01 17:03:38 +00:00
|
|
|
{
|
2015-04-07 21:49:00 +00:00
|
|
|
NewRequestAndEntry(forcePrincipalCheckForCacheEntry, loader,
|
2015-05-20 17:21:13 +00:00
|
|
|
mRequest->CacheKey(),
|
2015-04-07 21:49:00 +00:00
|
|
|
getter_AddRefs(mNewRequest),
|
2012-06-26 04:20:12 +00:00
|
|
|
getter_AddRefs(mNewEntry));
|
2011-07-01 17:03:38 +00:00
|
|
|
}
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2002-12-24 14:30:12 +00:00
|
|
|
imgCacheValidator::~imgCacheValidator()
|
2002-01-15 05:23:33 +00:00
|
|
|
{
|
2003-04-02 03:19:50 +00:00
|
|
|
if (mRequest) {
|
2015-03-24 02:37:45 +00:00
|
|
|
mRequest->SetValidator(nullptr);
|
2003-04-02 03:19:50 +00:00
|
|
|
}
|
2002-01-15 05:23:33 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void
|
|
|
|
imgCacheValidator::AddProxy(imgRequestProxy* aProxy)
|
2002-01-15 05:23:33 +00:00
|
|
|
{
|
2003-05-14 05:42:06 +00:00
|
|
|
// aProxy needs to be in the loadgroup since we're validating from
|
|
|
|
// the network.
|
|
|
|
aProxy->AddToLoadGroup();
|
|
|
|
|
2005-06-01 18:28:20 +00:00
|
|
|
mProxies.AppendObject(aProxy);
|
2002-01-15 05:23:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** nsIRequestObserver methods **/
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgCacheValidator::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
|
2002-01-15 05:23:33 +00:00
|
|
|
{
|
2015-04-07 17:02:02 +00:00
|
|
|
// We may be holding on to a document, so ensure that it's released.
|
|
|
|
nsCOMPtr<nsISupports> context = mContext.forget();
|
|
|
|
|
2015-03-28 03:07:20 +00:00
|
|
|
// If for some reason we don't still have an existing request (probably
|
|
|
|
// because OnStartRequest got delivered more than once), just bail.
|
|
|
|
if (!mRequest) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("OnStartRequest delivered more than once?");
|
|
|
|
aRequest->Cancel(NS_BINDING_ABORTED);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-07-01 17:03:42 +00:00
|
|
|
// If this request is coming from cache and has the same URI as our
|
|
|
|
// imgRequest, the request all our proxies are pointing at is valid, and all
|
|
|
|
// we have to do is tell them to notify their listeners.
|
2015-11-12 20:09:52 +00:00
|
|
|
nsCOMPtr<nsICacheInfoChannel> cacheChan(do_QueryInterface(aRequest));
|
2011-07-01 17:03:42 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
2012-11-08 18:54:00 +00:00
|
|
|
if (cacheChan && channel && !mRequest->CacheChanged(aRequest)) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isFromCache = false;
|
2011-07-01 17:03:42 +00:00
|
|
|
cacheChan->IsFromCache(&isFromCache);
|
2011-07-01 01:58:34 +00:00
|
|
|
|
2011-07-01 17:03:42 +00:00
|
|
|
nsCOMPtr<nsIURI> channelURI;
|
|
|
|
channel->GetURI(getter_AddRefs(channelURI));
|
2015-03-24 02:37:45 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
|
|
|
mRequest->GetCurrentURI(getter_AddRefs(currentURI));
|
|
|
|
|
|
|
|
bool sameURI = false;
|
|
|
|
if (channelURI && currentURI) {
|
|
|
|
channelURI->Equals(currentURI, &sameURI);
|
|
|
|
}
|
2011-07-01 17:03:42 +00:00
|
|
|
|
|
|
|
if (isFromCache && sameURI) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mProxies.Count();
|
|
|
|
for (int32_t i = count-1; i>=0; i--) {
|
2015-04-07 21:49:00 +00:00
|
|
|
imgRequestProxy* proxy = static_cast<imgRequestProxy*>(mProxies[i]);
|
2010-07-28 21:52:14 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
// Proxies waiting on cache validation should be deferring
|
|
|
|
// notifications. Undefer them.
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(proxy->NotificationsDeferred(),
|
|
|
|
"Proxies waiting on cache validation should be "
|
|
|
|
"deferring notifications!");
|
2011-10-17 14:59:28 +00:00
|
|
|
proxy->SetNotificationsDeferred(false);
|
2010-08-02 19:44:49 +00:00
|
|
|
|
2010-07-28 21:52:14 +00:00
|
|
|
// Notify synchronously, because we're already in OnStartRequest, an
|
|
|
|
// asynchronously-called function.
|
|
|
|
proxy->SyncNotifyListener();
|
2002-01-15 05:23:33 +00:00
|
|
|
}
|
|
|
|
|
2011-07-01 17:03:42 +00:00
|
|
|
// We don't need to load this any more.
|
|
|
|
aRequest->Cancel(NS_BINDING_ABORTED);
|
|
|
|
|
2015-04-07 17:02:02 +00:00
|
|
|
mRequest->SetLoadId(context);
|
2015-03-24 02:37:45 +00:00
|
|
|
mRequest->SetValidator(nullptr);
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mRequest = nullptr;
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mNewRequest = nullptr;
|
|
|
|
mNewEntry = nullptr;
|
2011-07-01 17:03:38 +00:00
|
|
|
|
2002-01-15 05:23:33 +00:00
|
|
|
return NS_OK;
|
2002-12-24 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2009-01-31 02:17:47 +00:00
|
|
|
// We can't load out of cache. We have to create a whole new request for the
|
|
|
|
// data that's coming in off the channel.
|
2002-12-24 14:30:12 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2013-09-28 18:28:42 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ImageURL> imageURL;
|
2013-09-28 18:28:42 +00:00
|
|
|
mRequest->GetURI(getter_AddRefs(imageURL));
|
|
|
|
uri = imageURL->ToIURI();
|
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
2015-05-11 20:42:30 +00:00
|
|
|
nsAutoCString spec;
|
|
|
|
uri->GetSpec(spec);
|
2015-11-16 17:21:00 +00:00
|
|
|
LOG_MSG_WITH_PARAM(gImgLog,
|
2015-05-11 20:42:30 +00:00
|
|
|
"imgCacheValidator::OnStartRequest creating new request",
|
|
|
|
"uri", spec.get());
|
|
|
|
}
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t corsmode = mRequest->GetCORSMode();
|
2014-11-18 13:46:53 +00:00
|
|
|
ReferrerPolicy refpol = mRequest->GetReferrerPolicy();
|
2011-07-14 18:47:32 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> loadingPrincipal = mRequest->GetLoadingPrincipal();
|
|
|
|
|
2002-12-24 14:30:12 +00:00
|
|
|
// Doom the old request's cache entry
|
2003-06-23 22:55:17 +00:00
|
|
|
mRequest->RemoveFromCache();
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
mRequest->SetValidator(nullptr);
|
2012-07-30 14:20:58 +00:00
|
|
|
mRequest = nullptr;
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2008-12-22 22:20:46 +00:00
|
|
|
// We use originalURI here to fulfil the imgIRequest contract on GetURI.
|
2006-03-11 20:32:47 +00:00
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
channel->GetOriginalURI(getter_AddRefs(originalURI));
|
2014-12-16 01:40:43 +00:00
|
|
|
mNewRequest->Init(originalURI, uri, mHadInsecureRedirect, aRequest, channel,
|
2015-04-07 17:02:02 +00:00
|
|
|
mNewEntry, context, loadingPrincipal, corsmode, refpol);
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2011-07-14 18:47:34 +00:00
|
|
|
mDestListener = new ProxyListener(mNewRequest);
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2009-01-31 02:17:47 +00:00
|
|
|
// Try to add the new request into the cache. Note that the entry must be in
|
|
|
|
// the cache before the proxies' ownership changes, because adding a proxy
|
|
|
|
// changes the caching behaviour for imgRequests.
|
2015-05-20 17:21:13 +00:00
|
|
|
mImgLoader->PutIntoCache(mNewRequest->CacheKey(), mNewEntry);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mProxies.Count();
|
|
|
|
for (int32_t i = count-1; i>=0; i--) {
|
2015-04-07 21:49:00 +00:00
|
|
|
imgRequestProxy* proxy = static_cast<imgRequestProxy*>(mProxies[i]);
|
2011-07-01 17:03:38 +00:00
|
|
|
proxy->ChangeOwner(mNewRequest);
|
2010-07-28 21:52:14 +00:00
|
|
|
|
|
|
|
// Notify synchronously, because we're already in OnStartRequest, an
|
|
|
|
// asynchronously-called function.
|
2012-10-22 16:44:53 +00:00
|
|
|
proxy->SetNotificationsDeferred(false);
|
2010-07-28 21:52:14 +00:00
|
|
|
proxy->SyncNotifyListener();
|
2002-01-15 05:23:33 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mNewRequest = nullptr;
|
|
|
|
mNewEntry = nullptr;
|
2002-01-15 05:23:33 +00:00
|
|
|
|
|
|
|
return mDestListener->OnStartRequest(aRequest, ctxt);
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgCacheValidator::OnStopRequest(nsIRequest* aRequest,
|
|
|
|
nsISupports* ctxt,
|
|
|
|
nsresult status)
|
2002-01-15 05:23:33 +00:00
|
|
|
{
|
2015-04-07 17:02:02 +00:00
|
|
|
// Be sure we've released the document that we may have been holding on to.
|
|
|
|
mContext = nullptr;
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!mDestListener) {
|
2002-01-15 05:23:33 +00:00
|
|
|
return NS_OK;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2002-01-15 05:23:33 +00:00
|
|
|
|
|
|
|
return mDestListener->OnStopRequest(aRequest, ctxt, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** nsIStreamListener methods **/
|
|
|
|
|
|
|
|
|
2012-09-06 02:41:02 +00:00
|
|
|
NS_IMETHODIMP
|
2015-04-07 21:49:00 +00:00
|
|
|
imgCacheValidator::OnDataAvailable(nsIRequest* aRequest, nsISupports* ctxt,
|
|
|
|
nsIInputStream* inStr,
|
2012-09-06 02:41:02 +00:00
|
|
|
uint64_t sourceOffset, uint32_t count)
|
2002-01-15 05:23:33 +00:00
|
|
|
{
|
|
|
|
if (!mDestListener) {
|
|
|
|
// XXX see bug 113959
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t _retval;
|
2012-07-30 14:20:58 +00:00
|
|
|
inStr->ReadSegments(NS_DiscardSegment, nullptr, count, &_retval);
|
2002-01-15 05:23:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
return mDestListener->OnDataAvailable(aRequest, ctxt, inStr, sourceOffset,
|
|
|
|
count);
|
2002-01-15 05:23:33 +00:00
|
|
|
}
|
2011-07-01 17:03:38 +00:00
|
|
|
|
2013-09-28 18:28:42 +00:00
|
|
|
/** nsIThreadRetargetableStreamListener methods **/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
imgCacheValidator::CheckListenerChain()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on the main thread!");
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIThreadRetargetableStreamListener> retargetableListener =
|
|
|
|
do_QueryInterface(mDestListener, &rv);
|
|
|
|
if (retargetableListener) {
|
|
|
|
rv = retargetableListener->CheckListenerChain();
|
|
|
|
}
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2013-09-28 18:28:42 +00:00
|
|
|
("[this=%p] imgCacheValidator::CheckListenerChain -- rv %d=%s",
|
|
|
|
this, NS_SUCCEEDED(rv) ? "succeeded" : "failed", rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-07-01 17:03:38 +00:00
|
|
|
/** nsIInterfaceRequestor methods **/
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgCacheValidator::GetInterface(const nsIID& aIID, void** aResult)
|
2011-07-01 17:03:38 +00:00
|
|
|
{
|
2015-04-07 21:49:00 +00:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIChannelEventSink))) {
|
2011-07-01 17:03:38 +00:00
|
|
|
return QueryInterface(aIID, aResult);
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2011-07-01 17:03:38 +00:00
|
|
|
|
|
|
|
return mProgressProxy->GetInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
// These functions are materially the same as the same functions in imgRequest.
|
|
|
|
// We duplicate them because we're verifying whether cache loads are necessary,
|
|
|
|
// not unconditionally loading.
|
|
|
|
|
|
|
|
/** nsIChannelEventSink methods **/
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgCacheValidator::
|
|
|
|
AsyncOnChannelRedirect(nsIChannel* oldChannel,
|
|
|
|
nsIChannel* newChannel,
|
|
|
|
uint32_t flags,
|
|
|
|
nsIAsyncVerifyRedirectCallback* callback)
|
2011-07-01 17:03:38 +00:00
|
|
|
{
|
|
|
|
// Note all cache information we get from the old channel.
|
|
|
|
mNewRequest->SetCacheValidation(mNewEntry, oldChannel);
|
|
|
|
|
2014-12-16 01:40:43 +00:00
|
|
|
// If the previous URI is a non-HTTPS URI, record that fact for later use by
|
|
|
|
// security code, which needs to know whether there is an insecure load at any
|
|
|
|
// point in the redirect chain.
|
|
|
|
nsCOMPtr<nsIURI> oldURI;
|
|
|
|
bool isHttps = false;
|
|
|
|
bool isChrome = false;
|
|
|
|
bool schemeLocal = false;
|
|
|
|
if (NS_FAILED(oldChannel->GetURI(getter_AddRefs(oldURI))) ||
|
|
|
|
NS_FAILED(oldURI->SchemeIs("https", &isHttps)) ||
|
|
|
|
NS_FAILED(oldURI->SchemeIs("chrome", &isChrome)) ||
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_FAILED(NS_URIChainHasFlags(oldURI,
|
|
|
|
nsIProtocolHandler::URI_IS_LOCAL_RESOURCE,
|
|
|
|
&schemeLocal)) ||
|
2014-12-16 01:40:43 +00:00
|
|
|
(!isHttps && !isChrome && !schemeLocal)) {
|
|
|
|
mHadInsecureRedirect = true;
|
|
|
|
}
|
|
|
|
|
2011-07-01 17:03:38 +00:00
|
|
|
// Prepare for callback
|
|
|
|
mRedirectCallback = callback;
|
|
|
|
mRedirectChannel = newChannel;
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
return mProgressProxy->AsyncOnChannelRedirect(oldChannel, newChannel, flags,
|
|
|
|
this);
|
2011-07-01 17:03:38 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgCacheValidator::OnRedirectVerifyCallback(nsresult aResult)
|
2011-07-01 17:03:38 +00:00
|
|
|
{
|
|
|
|
// If we've already been told to abort, just do so.
|
|
|
|
if (NS_FAILED(aResult)) {
|
|
|
|
mRedirectCallback->OnRedirectVerifyCallback(aResult);
|
2012-07-30 14:20:58 +00:00
|
|
|
mRedirectCallback = nullptr;
|
|
|
|
mRedirectChannel = nullptr;
|
2011-07-01 17:03:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure we have a protocol that returns data rather than opens
|
|
|
|
// an external application, e.g. mailto:
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
mRedirectChannel->GetURI(getter_AddRefs(uri));
|
2011-09-29 06:19:26 +00:00
|
|
|
bool doesNotReturnData = false;
|
2011-07-01 17:03:38 +00:00
|
|
|
NS_URIChainHasFlags(uri, nsIProtocolHandler::URI_DOES_NOT_RETURN_DATA,
|
|
|
|
&doesNotReturnData);
|
|
|
|
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
if (doesNotReturnData) {
|
|
|
|
result = NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRedirectCallback->OnRedirectVerifyCallback(result);
|
2012-07-30 14:20:58 +00:00
|
|
|
mRedirectCallback = nullptr;
|
|
|
|
mRedirectChannel = nullptr;
|
2011-07-01 17:03:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|