2013-01-18 04:45:11 +04: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 15:12:37 +04: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-23 01:01:03 +03:00
|
|
|
|
2016-06-30 20:27:03 +03:00
|
|
|
#include "ImageLogging.h"
|
|
|
|
#include "imgLoader.h"
|
|
|
|
|
2012-01-03 00:23:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-10-12 16:43:01 +04:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2015-04-28 21:45:45 +03:00
|
|
|
#include "mozilla/Move.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2016-06-07 01:23:43 +03:00
|
|
|
#include "mozilla/ChaosMode.h"
|
2012-01-03 00:23:41 +04:00
|
|
|
|
2016-05-19 15:31:15 +03:00
|
|
|
#include "nsImageModule.h"
|
2010-08-14 08:09:48 +04:00
|
|
|
#include "imgRequestProxy.h"
|
2010-05-22 08:10:14 +04:00
|
|
|
|
2001-05-08 08:12:40 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2015-03-24 19:18:48 +03:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2011-07-14 22:47:34 +04:00
|
|
|
#include "nsContentUtils.h"
|
2002-09-19 02:08:12 +04:00
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsIProtocolHandler.h"
|
2013-01-09 01:40:47 +04:00
|
|
|
#include "nsMimeTypes.h"
|
2011-06-24 18:22:33 +04:00
|
|
|
#include "nsStreamUtils.h"
|
2001-05-12 01:05:08 +04:00
|
|
|
#include "nsIHttpChannel.h"
|
2015-11-12 23:09:52 +03:00
|
|
|
#include "nsICacheInfoChannel.h"
|
2009-07-28 20:13:48 +04:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2009-07-28 20:13:48 +04:00
|
|
|
#include "nsIProgressEventSink.h"
|
2009-08-13 15:20:41 +04:00
|
|
|
#include "nsIChannelEventSink.h"
|
2010-08-05 06:15:55 +04:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2008-09-05 03:00:42 +04:00
|
|
|
#include "nsIFileURL.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsIFile.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2014-06-04 00:37:46 +04:00
|
|
|
#include "nsINetworkPredictor.h"
|
2016-06-07 01:23:43 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2015-03-24 19:18:48 +03:00
|
|
|
#include "mozilla/dom/nsMixedContentBlocker.h"
|
2002-03-23 16:21:33 +03:00
|
|
|
|
2009-01-05 08:52:22 +03:00
|
|
|
#include "nsIApplicationCache.h"
|
|
|
|
#include "nsIApplicationCacheContainer.h"
|
|
|
|
|
2010-05-22 08:10:14 +04:00
|
|
|
#include "nsIMemoryReporter.h"
|
2015-07-23 08:39:48 +03:00
|
|
|
#include "DecoderFactory.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
#include "Image.h"
|
2014-09-23 01:30:20 +04:00
|
|
|
#include "gfxPrefs.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "prtime.h"
|
2010-05-22 08:10:14 +04:00
|
|
|
|
2002-10-01 03:18:43 +04: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-30 00:14:19 +04:00
|
|
|
#include "nsIHttpChannelInternal.h"
|
2012-06-26 08:20:12 +04:00
|
|
|
#include "nsILoadContext.h"
|
2013-04-09 21:38:48 +04:00
|
|
|
#include "nsILoadGroupChild.h"
|
2015-10-27 21:12:46 +03:00
|
|
|
#include "nsIDOMDocument.h"
|
2002-10-01 03:18:43 +04:00
|
|
|
|
2011-06-12 06:30:15 +04:00
|
|
|
using namespace mozilla;
|
2016-06-07 01:23:43 +03:00
|
|
|
using namespace mozilla::dom;
|
2012-01-06 20:02:27 +04:00
|
|
|
using namespace mozilla::image;
|
2014-11-18 16:46:53 +03:00
|
|
|
using namespace mozilla::net;
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2013-12-08 09:38:32 +04:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(ImagesMallocSizeOf)
|
2012-03-02 04:05:32 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class imgMemoryReporter final : public nsIMemoryReporter
|
2010-05-22 08:10:14 +04:00
|
|
|
{
|
2014-11-27 05:00:15 +03:00
|
|
|
~imgMemoryReporter() { }
|
2014-06-23 22:49:08 +04:00
|
|
|
|
2010-05-22 08:10:14 +04:00
|
|
|
public:
|
2013-12-08 09:39:47 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2011-06-06 05:22:45 +04:00
|
|
|
|
2014-11-27 05:00:15 +03:00
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsISupports* aData, bool aAnonymize) override
|
2010-05-22 08:10:14 +04:00
|
|
|
{
|
2014-11-27 05:00:15 +03:00
|
|
|
nsTArray<ImageMemoryCounter> chrome;
|
|
|
|
nsTArray<ImageMemoryCounter> content;
|
|
|
|
nsTArray<ImageMemoryCounter> uncached;
|
2012-06-26 08:20:12 +04:00
|
|
|
|
2012-09-06 18:11:28 +04:00
|
|
|
for (uint32_t i = 0; i < mKnownLoaders.Length(); i++) {
|
2015-11-11 10:07:09 +03: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-06 01:36:11 +04:00
|
|
|
MutexAutoLock lock(mKnownLoaders[i]->mUncachedImagesMutex);
|
2015-07-14 16:37:57 +03:00
|
|
|
for (auto iter = mKnownLoaders[i]->mUncachedImages.Iter();
|
|
|
|
!iter.Done();
|
|
|
|
iter.Next()) {
|
|
|
|
nsPtrHashKey<imgRequest>* entry = iter.Get();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> req = entry->GetKey();
|
2015-07-14 16:37:57 +03:00
|
|
|
RecordCounterForRequest(req, &uncached, req->HasConsumers());
|
|
|
|
}
|
2012-06-26 08:20:12 +04:00
|
|
|
}
|
2012-03-02 04:05:32 +04:00
|
|
|
|
2014-05-21 10:06:54 +04:00
|
|
|
// Note that we only need to anonymize content image URIs.
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportCounterArray(aHandleReport, aData, chrome, "images/chrome");
|
2012-03-02 04:05:32 +04:00
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportCounterArray(aHandleReport, aData, content, "images/content",
|
|
|
|
aAnonymize);
|
2012-03-02 04:05:32 +04:00
|
|
|
|
2014-11-27 05:00:15 +03:00
|
|
|
// Uncached images may be content or chrome, so anonymize them.
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportCounterArray(aHandleReport, aData, uncached, "images/uncached",
|
|
|
|
aAnonymize);
|
2014-09-06 01:36:11 +04:00
|
|
|
|
2010-05-22 08:10:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-20 02:52:30 +04:00
|
|
|
static int64_t ImagesContentUsedUncompressedDistinguishedAmount()
|
2010-05-22 08:10:14 +04:00
|
|
|
{
|
2012-03-02 04:05:32 +04:00
|
|
|
size_t n = 0;
|
2015-04-08 00:49:00 +03:00
|
|
|
for (uint32_t i = 0; i < imgLoader::sMemReporter->mKnownLoaders.Length();
|
|
|
|
i++) {
|
2015-11-11 10:07:09 +03: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 08:20:12 +04:00
|
|
|
}
|
2012-03-02 04:05:32 +04:00
|
|
|
return n;
|
2010-05-22 08:10:14 +04:00
|
|
|
}
|
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
void RegisterLoader(imgLoader* aLoader)
|
|
|
|
{
|
|
|
|
mKnownLoaders.AppendElement(aLoader);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnregisterLoader(imgLoader* aLoader)
|
|
|
|
{
|
|
|
|
mKnownLoaders.RemoveElement(aLoader);
|
|
|
|
}
|
|
|
|
|
2012-03-02 04:05:32 +04:00
|
|
|
private:
|
2012-06-26 08:20:12 +04:00
|
|
|
nsTArray<imgLoader*> mKnownLoaders;
|
|
|
|
|
2014-11-27 05:00:15 +03:00
|
|
|
struct MemoryTotal
|
2014-05-16 03:11:57 +04:00
|
|
|
{
|
2014-11-27 05:00:15 +03: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 08:10:14 +04:00
|
|
|
};
|
|
|
|
|
2014-11-27 05:00:15 +03:00
|
|
|
// Reports all images of a single kind, e.g. all used chrome images.
|
2016-08-24 08:23:45 +03:00
|
|
|
void ReportCounterArray(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
nsTArray<ImageMemoryCounter>& aCounterArray,
|
|
|
|
const char* aPathPrefix,
|
|
|
|
bool aAnonymize = false)
|
2014-05-16 03:11:57 +04:00
|
|
|
{
|
2014-11-27 05:00:15 +03:00
|
|
|
MemoryTotal summaryTotal;
|
|
|
|
MemoryTotal nonNotableTotal;
|
2014-05-16 03:11:57 +04:00
|
|
|
|
|
|
|
// Report notable images, and compute total and non-notable aggregate sizes.
|
2014-11-27 05:00:15 +03:00
|
|
|
for (uint32_t i = 0; i < aCounterArray.Length(); i++) {
|
2015-04-28 21:46:17 +03:00
|
|
|
ImageMemoryCounter& counter = aCounterArray[i];
|
2014-05-21 10:06:54 +04:00
|
|
|
|
|
|
|
if (aAnonymize) {
|
2014-11-27 05:00:15 +03:00
|
|
|
counter.URI().Truncate();
|
|
|
|
counter.URI().AppendPrintf("<anonymized-%u>", i);
|
2014-05-21 10:06:54 +04:00
|
|
|
} else {
|
2014-11-27 05:00:15 +03:00
|
|
|
// The URI could be an extremely long data: URI. Truncate if needed.
|
2014-05-21 10:06:54 +04:00
|
|
|
static const size_t max = 256;
|
2014-11-27 05:00:15 +03:00
|
|
|
if (counter.URI().Length() > max) {
|
|
|
|
counter.URI().Truncate(max);
|
|
|
|
counter.URI().AppendLiteral(" (truncated)");
|
2014-05-21 10:06:54 +04:00
|
|
|
}
|
2014-11-27 05:00:15 +03:00
|
|
|
counter.URI().ReplaceChar('/', '\\');
|
2014-05-16 03:11:57 +04:00
|
|
|
}
|
|
|
|
|
2014-11-27 05:00:15 +03:00
|
|
|
summaryTotal += counter;
|
2014-05-16 03:11:57 +04:00
|
|
|
|
2014-11-27 05:00:15 +03:00
|
|
|
if (counter.IsNotable()) {
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportImage(aHandleReport, aData, aPathPrefix, counter);
|
2014-11-27 05:00:15 +03:00
|
|
|
} else {
|
|
|
|
nonNotableTotal += counter;
|
2014-05-16 03:11:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report non-notable images in aggregate.
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportTotal(aHandleReport, aData, /* aExplicit = */ true,
|
|
|
|
aPathPrefix, "<non-notable images>/", nonNotableTotal);
|
2014-11-26 12:37:57 +03:00
|
|
|
|
2014-11-27 05:00:15 +03:00
|
|
|
// Report a summary in aggregate, outside of the explicit tree.
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportTotal(aHandleReport, aData, /* aExplicit = */ false,
|
|
|
|
aPathPrefix, "", summaryTotal);
|
2014-11-26 12:37:57 +03:00
|
|
|
}
|
2010-05-22 08:10:14 +04:00
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
static void ReportImage(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
const char* aPathPrefix,
|
|
|
|
const ImageMemoryCounter& aCounter)
|
2014-11-26 12:37:57 +03:00
|
|
|
{
|
2014-11-27 05:00:15 +03: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 21:46:17 +03:00
|
|
|
pathPrefix.AppendInt(aCounter.IntrinsicSize().width);
|
|
|
|
pathPrefix.Append("x");
|
|
|
|
pathPrefix.AppendInt(aCounter.IntrinsicSize().height);
|
|
|
|
pathPrefix.Append(", ");
|
|
|
|
|
2014-11-27 05:00:15 +03:00
|
|
|
if (aCounter.URI().IsEmpty()) {
|
|
|
|
pathPrefix.Append("<unknown URI>");
|
|
|
|
} else {
|
|
|
|
pathPrefix.Append(aCounter.URI());
|
|
|
|
}
|
2015-04-28 21:46:17 +03:00
|
|
|
|
2014-11-27 05:00:15 +03:00
|
|
|
pathPrefix.Append(")/");
|
2014-11-26 12:37:57 +03:00
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportSurfaces(aHandleReport, aData, pathPrefix, aCounter);
|
2015-05-05 02:08:51 +03:00
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportSourceValue(aHandleReport, aData, pathPrefix, aCounter.Values());
|
2015-04-28 21:46:17 +03:00
|
|
|
}
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
static void ReportSurfaces(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
const nsACString& aPathPrefix,
|
|
|
|
const ImageMemoryCounter& aCounter)
|
2015-04-28 21:46:17 +03:00
|
|
|
{
|
|
|
|
for (const SurfaceMemoryCounter& counter : aCounter.Surfaces()) {
|
|
|
|
nsAutoCString surfacePathPrefix(aPathPrefix);
|
|
|
|
surfacePathPrefix.Append(counter.IsLocked() ? "locked/" : "unlocked/");
|
|
|
|
surfacePathPrefix.Append("surface(");
|
|
|
|
surfacePathPrefix.AppendInt(counter.Key().Size().width);
|
|
|
|
surfacePathPrefix.Append("x");
|
|
|
|
surfacePathPrefix.AppendInt(counter.Key().Size().height);
|
|
|
|
|
|
|
|
if (counter.Type() == SurfaceMemoryCounterType::NORMAL) {
|
2016-08-18 10:06:41 +03:00
|
|
|
PlaybackType playback = counter.Key().Playback();
|
|
|
|
surfacePathPrefix.Append(playback == PlaybackType::eAnimated
|
|
|
|
? " (animation)"
|
|
|
|
: "");
|
2015-04-28 21:46:17 +03:00
|
|
|
|
2015-08-15 03:56:44 +03:00
|
|
|
if (counter.Key().Flags() != DefaultSurfaceFlags()) {
|
2015-04-28 21:46:17 +03:00
|
|
|
surfacePathPrefix.Append(", flags:");
|
2015-08-15 03:56:44 +03:00
|
|
|
surfacePathPrefix.AppendInt(uint32_t(counter.Key().Flags()),
|
|
|
|
/* aRadix = */ 16);
|
2015-04-28 21:46:17 +03: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(")/");
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportValues(aHandleReport, aData, surfacePathPrefix, counter.Values());
|
2015-04-28 21:46:17 +03:00
|
|
|
}
|
2014-11-27 05:00:15 +03:00
|
|
|
}
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
static void ReportTotal(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
bool aExplicit,
|
|
|
|
const char* aPathPrefix,
|
|
|
|
const char* aPathInfix,
|
|
|
|
const MemoryTotal& aTotal)
|
2014-11-27 05:00:15 +03:00
|
|
|
{
|
|
|
|
nsAutoCString pathPrefix;
|
|
|
|
if (aExplicit) {
|
|
|
|
pathPrefix.Append("explicit/");
|
2014-11-26 12:37:57 +03:00
|
|
|
}
|
2014-11-27 05:00:15 +03:00
|
|
|
pathPrefix.Append(aPathPrefix);
|
|
|
|
|
|
|
|
nsAutoCString rasterUsedPrefix(pathPrefix);
|
|
|
|
rasterUsedPrefix.Append("/raster/used/");
|
|
|
|
rasterUsedPrefix.Append(aPathInfix);
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportValues(aHandleReport, aData, rasterUsedPrefix, aTotal.UsedRaster());
|
2014-11-27 05:00:15 +03:00
|
|
|
|
|
|
|
nsAutoCString rasterUnusedPrefix(pathPrefix);
|
|
|
|
rasterUnusedPrefix.Append("/raster/unused/");
|
|
|
|
rasterUnusedPrefix.Append(aPathInfix);
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportValues(aHandleReport, aData, rasterUnusedPrefix,
|
|
|
|
aTotal.UnusedRaster());
|
2014-11-27 05:00:15 +03:00
|
|
|
|
|
|
|
nsAutoCString vectorUsedPrefix(pathPrefix);
|
|
|
|
vectorUsedPrefix.Append("/vector/used/");
|
|
|
|
vectorUsedPrefix.Append(aPathInfix);
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportValues(aHandleReport, aData, vectorUsedPrefix, aTotal.UsedVector());
|
2014-11-27 05:00:15 +03:00
|
|
|
|
|
|
|
nsAutoCString vectorUnusedPrefix(pathPrefix);
|
|
|
|
vectorUnusedPrefix.Append("/vector/unused/");
|
|
|
|
vectorUnusedPrefix.Append(aPathInfix);
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportValues(aHandleReport, aData, vectorUnusedPrefix,
|
|
|
|
aTotal.UnusedVector());
|
2014-11-27 05:00:15 +03:00
|
|
|
}
|
2014-11-26 12:37:57 +03:00
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
static void ReportValues(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
const nsACString& aPathPrefix,
|
|
|
|
const MemoryCounter& aCounter)
|
2014-11-27 05:00:15 +03:00
|
|
|
{
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportSourceValue(aHandleReport, aData, aPathPrefix, aCounter);
|
2014-11-27 05:00:15 +03:00
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportValue(aHandleReport, aData, KIND_HEAP, aPathPrefix,
|
|
|
|
"decoded-heap",
|
|
|
|
"Decoded image data which is stored on the heap.",
|
|
|
|
aCounter.DecodedHeap());
|
2014-11-27 05:00:15 +03:00
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportValue(aHandleReport, aData, KIND_NONHEAP, aPathPrefix,
|
|
|
|
"decoded-nonheap",
|
|
|
|
"Decoded image data which isn't stored on the heap.",
|
|
|
|
aCounter.DecodedNonHeap());
|
2014-11-27 05:00:15 +03:00
|
|
|
}
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
static void ReportSourceValue(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
const nsACString& aPathPrefix,
|
|
|
|
const MemoryCounter& aCounter)
|
2015-05-05 02:08:51 +03:00
|
|
|
{
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportValue(aHandleReport, aData, KIND_HEAP, aPathPrefix,
|
|
|
|
"source",
|
|
|
|
"Raster image source data and vector image documents.",
|
|
|
|
aCounter.Source());
|
2015-05-05 02:08:51 +03:00
|
|
|
}
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
static void ReportValue(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData,
|
|
|
|
int32_t aKind,
|
|
|
|
const nsACString& aPathPrefix,
|
|
|
|
const char* aPathSuffix,
|
|
|
|
const char* aDescription,
|
|
|
|
size_t aValue)
|
2014-11-27 05:00:15 +03:00
|
|
|
{
|
|
|
|
if (aValue == 0) {
|
2016-08-24 08:23:45 +03:00
|
|
|
return;
|
2014-11-27 05:00:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString desc(aDescription);
|
|
|
|
nsAutoCString path(aPathPrefix);
|
|
|
|
path.Append(aPathSuffix);
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
aHandleReport->Callback(EmptyCString(), path, aKind, UNITS_BYTES,
|
|
|
|
aValue, desc, aData);
|
2014-11-27 05:00:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void RecordCounterForRequest(imgRequest* aRequest,
|
|
|
|
nsTArray<ImageMemoryCounter>* aArray,
|
|
|
|
bool aIsUsed)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = aRequest->GetImage();
|
2014-11-27 05:00:15 +03:00
|
|
|
if (!image) {
|
|
|
|
return;
|
2014-09-06 01:36:11 +04:00
|
|
|
}
|
|
|
|
|
2015-04-28 21:46:17 +03:00
|
|
|
ImageMemoryCounter counter(image, ImagesMallocSizeOf, aIsUsed);
|
2014-11-27 05:00:15 +03:00
|
|
|
|
2015-04-28 21:46:17 +03:00
|
|
|
aArray->AppendElement(Move(counter));
|
2014-09-06 01:36:11 +04:00
|
|
|
}
|
2010-05-22 08:10:14 +04:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(imgMemoryReporter, nsIMemoryReporter)
|
2013-12-08 09:39:47 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsProgressNotificationProxy,
|
|
|
|
nsIProgressEventSink,
|
|
|
|
nsIChannelEventSink,
|
|
|
|
nsIInterfaceRequestor)
|
2009-07-28 20:13:48 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProgressNotificationProxy::OnProgress(nsIRequest* request,
|
|
|
|
nsISupports* ctxt,
|
2015-01-08 22:48:52 +03:00
|
|
|
int64_t progress,
|
|
|
|
int64_t progressMax)
|
2011-07-01 21:03:30 +04:00
|
|
|
{
|
2009-07-28 20:13:48 +04:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2010-11-21 22:21:57 +03:00
|
|
|
request->GetLoadGroup(getter_AddRefs(loadGroup));
|
2009-07-28 20:13:48 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIProgressEventSink> target;
|
|
|
|
NS_QueryNotificationCallbacks(mOriginalCallbacks,
|
|
|
|
loadGroup,
|
|
|
|
NS_GET_IID(nsIProgressEventSink),
|
|
|
|
getter_AddRefs(target));
|
2015-04-08 00:49:00 +03:00
|
|
|
if (!target) {
|
2009-07-28 20:13:48 +04:00
|
|
|
return NS_OK;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-07-28 20:13:48 +04:00
|
|
|
return target->OnProgress(mImageRequest, ctxt, progress, progressMax);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProgressNotificationProxy::OnStatus(nsIRequest* request,
|
|
|
|
nsISupports* ctxt,
|
|
|
|
nsresult status,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* statusArg)
|
2011-07-01 21:03:30 +04:00
|
|
|
{
|
2009-07-28 20:13:48 +04:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2010-11-21 22:21:57 +03:00
|
|
|
request->GetLoadGroup(getter_AddRefs(loadGroup));
|
2009-07-28 20:13:48 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIProgressEventSink> target;
|
|
|
|
NS_QueryNotificationCallbacks(mOriginalCallbacks,
|
|
|
|
loadGroup,
|
|
|
|
NS_GET_IID(nsIProgressEventSink),
|
|
|
|
getter_AddRefs(target));
|
2015-04-08 00:49:00 +03:00
|
|
|
if (!target) {
|
2009-07-28 20:13:48 +04:00
|
|
|
return NS_OK;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-07-28 20:13:48 +04:00
|
|
|
return target->OnStatus(mImageRequest, ctxt, status, statusArg);
|
|
|
|
}
|
|
|
|
|
2009-08-13 15:20:41 +04:00
|
|
|
NS_IMETHODIMP
|
2015-04-08 00:49:00 +03:00
|
|
|
nsProgressNotificationProxy::
|
|
|
|
AsyncOnChannelRedirect(nsIChannel* oldChannel,
|
|
|
|
nsIChannel* newChannel,
|
|
|
|
uint32_t flags,
|
|
|
|
nsIAsyncVerifyRedirectCallback* cb)
|
2011-07-01 21:03:30 +04:00
|
|
|
{
|
2009-08-13 15:20:41 +04:00
|
|
|
// Tell the original original callbacks about it too
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2010-11-21 22:21:57 +03:00
|
|
|
newChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
2009-08-13 15:20:41 +04:00
|
|
|
nsCOMPtr<nsIChannelEventSink> target;
|
|
|
|
NS_QueryNotificationCallbacks(mOriginalCallbacks,
|
|
|
|
loadGroup,
|
|
|
|
NS_GET_IID(nsIChannelEventSink),
|
|
|
|
getter_AddRefs(target));
|
2010-08-05 06:15:55 +04: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 15:20:41 +04:00
|
|
|
}
|
|
|
|
|
2009-07-28 20:13:48 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProgressNotificationProxy::GetInterface(const nsIID& iid,
|
2011-07-01 21:03:30 +04:00
|
|
|
void** result)
|
|
|
|
{
|
2009-07-28 20:13:48 +04:00
|
|
|
if (iid.Equals(NS_GET_IID(nsIProgressEventSink))) {
|
|
|
|
*result = static_cast<nsIProgressEventSink*>(this);
|
2009-07-28 21:46:04 +04:00
|
|
|
NS_ADDREF_THIS();
|
2009-07-28 20:13:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-08-13 15:20:41 +04:00
|
|
|
if (iid.Equals(NS_GET_IID(nsIChannelEventSink))) {
|
|
|
|
*result = static_cast<nsIChannelEventSink*>(this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-04-08 00:49:00 +03:00
|
|
|
if (mOriginalCallbacks) {
|
2009-07-28 20:13:48 +04:00
|
|
|
return mOriginalCallbacks->GetInterface(iid, result);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-07-28 20:13:48 +04:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
static void
|
|
|
|
NewRequestAndEntry(bool aForcePrincipalCheckForCacheEntry, imgLoader* aLoader,
|
2015-05-20 20:21:13 +03:00
|
|
|
const ImageCacheKey& aKey,
|
2015-04-08 00:49:00 +03:00
|
|
|
imgRequest** aRequest, imgCacheEntry** aEntry)
|
2008-09-04 20:36:27 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> request = new imgRequest(aLoader, aKey);
|
|
|
|
RefPtr<imgCacheEntry> entry =
|
2015-04-08 00:49:00 +03:00
|
|
|
new imgCacheEntry(aLoader, request, aForcePrincipalCheckForCacheEntry);
|
2014-09-06 01:36:11 +04:00
|
|
|
aLoader->AddToUncachedImages(request);
|
2011-10-01 20:14:40 +04:00
|
|
|
request.forget(aRequest);
|
|
|
|
entry.forget(aEntry);
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
2008-09-04 20:36:27 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
static bool
|
|
|
|
ShouldRevalidateEntry(imgCacheEntry* aEntry,
|
|
|
|
nsLoadFlags aFlags,
|
|
|
|
bool aHasExpired)
|
2002-01-15 08:23:33 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool bValidateEntry = false;
|
2002-09-19 02:08:12 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (aFlags & nsIRequest::LOAD_BYPASS_CACHE) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2002-09-19 02:08:12 +04:00
|
|
|
|
|
|
|
if (aFlags & nsIRequest::VALIDATE_ALWAYS) {
|
2011-10-17 18:59:28 +04:00
|
|
|
bValidateEntry = true;
|
2015-04-08 00:49:00 +03:00
|
|
|
} else if (aEntry->GetMustValidate()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
bValidateEntry = true;
|
2015-04-08 00:49:00 +03:00
|
|
|
} else if (aHasExpired) {
|
|
|
|
// The cache entry has expired... Determine whether the stale cache
|
|
|
|
// entry can be used without validation...
|
2013-03-30 00:14:19 +04:00
|
|
|
if (aFlags & (nsIRequest::VALIDATE_NEVER |
|
2015-04-08 00:49:00 +03: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 18:59:28 +04:00
|
|
|
bValidateEntry = false;
|
2015-04-08 00:49:00 +03: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 18:59:28 +04:00
|
|
|
bValidateEntry = true;
|
2002-09-19 02:08:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bValidateEntry;
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:18:48 +03:00
|
|
|
/* Call content policies on cached images that went through a redirect */
|
|
|
|
static bool
|
|
|
|
ShouldLoadCachedImage(imgRequest* aImgRequest,
|
|
|
|
nsISupports* aLoadingContext,
|
2016-04-27 20:40:56 +03:00
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
|
|
|
nsContentPolicyType aPolicyType)
|
2015-03-24 19:18:48 +03:00
|
|
|
{
|
|
|
|
/* 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;
|
2016-04-27 20:40:56 +03:00
|
|
|
rv = NS_CheckContentLoadPolicy(aPolicyType,
|
2015-03-24 19:18:48 +03: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,
|
2016-04-27 20:40:56 +03:00
|
|
|
aPolicyType,
|
2015-03-24 19:18:48 +03:00
|
|
|
contentLocation,
|
|
|
|
requestingLocation,
|
|
|
|
aLoadingContext,
|
|
|
|
EmptyCString(), //mime guess
|
|
|
|
nullptr,
|
|
|
|
aLoadingPrincipal,
|
|
|
|
&decision);
|
|
|
|
if (NS_FAILED(rv) || !NS_CP_ACCEPTED(decision)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1246540 - HSTS Priming Proof of Concept. r=ckerschb, r=mayhemer, r=jld, r=smaug, r=dkeeler, r=jmaher, p=ally
HSTS priming changes the order of mixed-content blocking and HSTS
upgrades, and adds a priming request to check if a mixed-content load is
accesible over HTTPS and the server supports upgrading via the
Strict-Transport-Security header.
Every call site that uses AsyncOpen2 passes through the mixed-content
blocker, and has a LoadInfo. If the mixed-content blocker marks the load as
needing HSTS priming, nsHttpChannel will build and send an HSTS priming
request on the same URI with the scheme upgraded to HTTPS. If the server
allows the upgrade, then channel performs an internal redirect to the HTTPS URI,
otherwise use the result of mixed-content blocker to allow or block the
load.
nsISiteSecurityService adds an optional boolean out parameter to
determine if the HSTS state is already cached for negative assertions.
If the host has been probed within the previous 24 hours, no HSTS
priming check will be sent.
MozReview-Commit-ID: ES1JruCtDdX
--HG--
extra : rebase_source : 2ac6c93c49f2862fc0b9e595eb0598cd1ea4bedf
2016-09-27 18:27:00 +03:00
|
|
|
bool sendPriming = false;
|
|
|
|
bool mixedContentWouldBlock = false;
|
|
|
|
rv = nsMixedContentBlocker::GetHSTSPrimingFromRequestingContext(contentLocation,
|
|
|
|
aLoadingContext, &sendPriming, &mixedContentWouldBlock);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (sendPriming && mixedContentWouldBlock) {
|
|
|
|
// if either of the securty checks above would cause a priming request, we
|
|
|
|
// can't load this image from the cache, so go ahead and return false here
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:18:48 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-14 22:47:34 +04: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 16:46:53 +03:00
|
|
|
// to CORS. Also checks the Referrer Policy, since requests with different
|
|
|
|
// referrers/policies may generate different responses.
|
2011-07-14 22:47:34 +04:00
|
|
|
static bool
|
2014-11-18 16:46:53 +03:00
|
|
|
ValidateSecurityInfo(imgRequest* request, bool forcePrincipalCheck,
|
|
|
|
int32_t corsmode, nsIPrincipal* loadingPrincipal,
|
2016-04-27 20:40:56 +03:00
|
|
|
nsISupports* aCX, nsContentPolicyType aPolicyType,
|
|
|
|
ReferrerPolicy referrerPolicy)
|
2011-07-14 22:47:34 +04:00
|
|
|
{
|
2014-11-18 16:46:53 +03:00
|
|
|
// If the entry's Referrer Policy doesn't match, we can't use this request.
|
2015-06-06 01:25:24 +03: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 16:46:53 +03:00
|
|
|
if (referrerPolicy != request->GetReferrerPolicy()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-14 22:47:34 +04: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-21 01:00:42 +04:00
|
|
|
} else if (request->GetCORSMode() != imgIRequest::CORS_NONE ||
|
|
|
|
forcePrincipalCheck) {
|
2011-07-14 22:47:34 +04: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 10:19:26 +04:00
|
|
|
bool equals = false;
|
2011-07-14 22:47:34 +04:00
|
|
|
otherprincipal->Equals(loadingPrincipal, &equals);
|
2015-03-24 19:18:48 +03:00
|
|
|
if (!equals) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-14 22:47:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:18:48 +03:00
|
|
|
// Content Policy Check on Cached Images
|
2016-04-27 20:40:56 +03:00
|
|
|
return ShouldLoadCachedImage(request, aCX, loadingPrincipal, aPolicyType);
|
2011-07-14 22:47:34 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03: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,
|
2016-04-27 20:40:56 +03:00
|
|
|
int32_t aCORSMode,
|
2015-04-08 00:49:00 +03:00
|
|
|
nsIURI* aReferringURI,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
const nsCString& aAcceptHeader,
|
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
nsContentPolicyType aPolicyType,
|
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
2016-04-13 16:34:36 +03:00
|
|
|
nsISupports* aRequestingContext,
|
|
|
|
bool aRespectPrivacy)
|
2002-09-19 02:08:12 +04:00
|
|
|
{
|
2015-04-19 03:18:49 +03:00
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
2002-09-19 02:08:12 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIHttpChannel> newHttpChannel;
|
2013-03-30 00:14:19 +04:00
|
|
|
|
2002-09-19 02:08:12 +04: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 23:51:00 +04: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-19 02:08:12 +04:00
|
|
|
// If all of the proxy requests are canceled then this request should be
|
|
|
|
// canceled too.
|
|
|
|
//
|
2014-06-28 00:57:36 +04:00
|
|
|
aLoadFlags |= nsIChannel::LOAD_CLASSIFY_URI;
|
2014-09-21 20:45:34 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsINode> requestingNode = do_QueryInterface(aRequestingContext);
|
2016-04-27 20:40:56 +03:00
|
|
|
|
|
|
|
nsSecurityFlags securityFlags =
|
|
|
|
aCORSMode == imgIRequest::CORS_NONE
|
|
|
|
? nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS
|
|
|
|
: nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS;
|
|
|
|
if (aCORSMode == imgIRequest::CORS_ANONYMOUS) {
|
|
|
|
securityFlags |= nsILoadInfo::SEC_COOKIES_SAME_ORIGIN;
|
|
|
|
} else if (aCORSMode == imgIRequest::CORS_USE_CREDENTIALS) {
|
|
|
|
securityFlags |= nsILoadInfo::SEC_COOKIES_INCLUDE;
|
2014-07-18 03:07:58 +04:00
|
|
|
}
|
2016-04-27 20:40:56 +03:00
|
|
|
securityFlags |= nsILoadInfo::SEC_ALLOW_CHROME;
|
2014-08-20 01:49:38 +04:00
|
|
|
|
2015-04-08 00:49:00 +03: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.
|
2016-04-27 20:40:56 +03:00
|
|
|
if (requestingNode && aLoadingPrincipal) {
|
2014-11-14 19:56:55 +03:00
|
|
|
rv = NS_NewChannelWithTriggeringPrincipal(aResult,
|
|
|
|
aURI,
|
|
|
|
requestingNode,
|
2016-04-27 20:40:56 +03:00
|
|
|
aLoadingPrincipal,
|
2014-11-14 19:56:55 +03:00
|
|
|
securityFlags,
|
2015-03-26 00:42:18 +03:00
|
|
|
aPolicyType,
|
2014-11-14 19:56:55 +03:00
|
|
|
nullptr, // loadGroup
|
|
|
|
callbacks,
|
|
|
|
aLoadFlags);
|
2016-10-13 10:43:57 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPolicyType == nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON) {
|
|
|
|
// If this is a favicon loading, we will use the originAttributes from the
|
|
|
|
// loadingPrincipal as the channel's originAttributes. This allows the favicon
|
|
|
|
// loading from XUL will use the correct originAttributes.
|
|
|
|
NeckoOriginAttributes neckoAttrs;
|
|
|
|
neckoAttrs.InheritFromDocToNecko(BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef());
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->GetLoadInfo();
|
|
|
|
rv = loadInfo->SetOriginAttributes(neckoAttrs);
|
|
|
|
}
|
2015-04-08 00:49:00 +03:00
|
|
|
} else {
|
2014-11-14 19:56:55 +03:00
|
|
|
// either we are loading something inside a document, in which case
|
|
|
|
// we should always have a requestingNode, or we are loading something
|
2016-04-27 20:40:56 +03:00
|
|
|
// outside a document, in which case the loadingPrincipal and
|
|
|
|
// triggeringPrincipal should always be the systemPrincipal.
|
2016-10-13 10:43:57 +03:00
|
|
|
// However, there are exceptions: one is Notifications which create a
|
|
|
|
// channel in the parent prcoess in which case we can't get a requestingNode.
|
2014-11-14 19:56:55 +03:00
|
|
|
rv = NS_NewChannel(aResult,
|
|
|
|
aURI,
|
2016-04-27 20:40:56 +03:00
|
|
|
nsContentUtils::GetSystemPrincipal(),
|
2014-11-14 19:56:55 +03:00
|
|
|
securityFlags,
|
2015-03-26 00:42:18 +03:00
|
|
|
aPolicyType,
|
2014-11-14 19:56:55 +03:00
|
|
|
nullptr, // loadGroup
|
|
|
|
callbacks,
|
|
|
|
aLoadFlags);
|
2016-08-31 00:54:58 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the OriginAttributes from the loading principal, if one is available,
|
|
|
|
// and adjust the private browsing ID based on what kind of load the caller
|
|
|
|
// has asked us to perform.
|
|
|
|
NeckoOriginAttributes neckoAttrs;
|
|
|
|
if (aLoadingPrincipal) {
|
|
|
|
neckoAttrs.InheritFromDocToNecko(BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef());
|
|
|
|
}
|
|
|
|
neckoAttrs.mPrivateBrowsingId = aRespectPrivacy ? 1 : 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->GetLoadInfo();
|
|
|
|
rv = loadInfo->SetOriginAttributes(neckoAttrs);
|
2014-11-14 19:56:55 +03:00
|
|
|
}
|
2014-09-21 20:45:34 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2002-09-19 02:08:12 +04:00
|
|
|
return rv;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2002-09-19 02:08:12 +04:00
|
|
|
|
2016-04-27 20:40:56 +03:00
|
|
|
// only inherit if we have a principal
|
|
|
|
*aForcePrincipalCheckForCacheEntry =
|
|
|
|
aLoadingPrincipal &&
|
|
|
|
nsContentUtils::ChannelShouldInheritPrincipal(
|
|
|
|
aLoadingPrincipal,
|
|
|
|
aURI,
|
|
|
|
/* aInheritForAboutBlank */ false,
|
|
|
|
/* aForceInherit */ false);
|
2011-09-21 01:00:42 +04:00
|
|
|
|
2002-09-19 02:08:12 +04:00
|
|
|
// Initialize HTTP-specific attributes
|
|
|
|
newHttpChannel = do_QueryInterface(*aResult);
|
|
|
|
if (newHttpChannel) {
|
2002-09-27 08:22:13 +04:00
|
|
|
newHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
|
2009-07-15 11:22:40 +04:00
|
|
|
aAcceptHeader,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2002-10-01 03:18:43 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsCOMPtr<nsIHttpChannelInternal> httpChannelInternal =
|
|
|
|
do_QueryInterface(newHttpChannel);
|
2002-10-01 03:18:43 +04:00
|
|
|
NS_ENSURE_TRUE(httpChannelInternal, NS_ERROR_UNEXPECTED);
|
|
|
|
httpChannelInternal->SetDocumentURI(aInitialDocumentURI);
|
2014-11-18 16:46:53 +03:00
|
|
|
newHttpChannel->SetReferrerWithPolicy(aReferringURI, aReferrerPolicy);
|
2002-09-19 02:08:12 +04:00
|
|
|
}
|
|
|
|
|
2005-02-21 23:58:01 +03:00
|
|
|
// Image channels are loaded by default with reduced priority.
|
|
|
|
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(*aResult);
|
|
|
|
if (p) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t priority = nsISupportsPriority::PRIORITY_LOW;
|
2005-02-21 23:58:01 +03:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (aLoadFlags & nsIRequest::LOAD_BACKGROUND) {
|
2005-02-21 23:58:01 +03:00
|
|
|
++priority; // further reduce priority for background loads
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2005-02-21 23:58:01 +03:00
|
|
|
|
2005-02-22 01:21:21 +03:00
|
|
|
p->AdjustPriority(priority);
|
2005-02-21 23:58:01 +03:00
|
|
|
}
|
|
|
|
|
2014-01-30 07:35:40 +04: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);
|
|
|
|
|
2002-09-19 02:08:12 +04:00
|
|
|
return NS_OK;
|
2002-01-15 08:23:33 +03:00
|
|
|
}
|
2001-07-17 05:14:40 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
static uint32_t
|
|
|
|
SecondsFromPRTime(PRTime prTime)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
return uint32_t(int64_t(prTime) / int64_t(PR_USEC_PER_SEC));
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
imgCacheEntry::imgCacheEntry(imgLoader* loader, imgRequest* request,
|
|
|
|
bool forcePrincipalCheck)
|
2012-06-26 08:20:12 +04:00
|
|
|
: mLoader(loader),
|
|
|
|
mRequest(request),
|
2008-09-05 03:00:42 +04:00
|
|
|
mDataSize(0),
|
|
|
|
mTouchedTime(SecondsFromPRTime(PR_Now())),
|
2015-10-20 08:15:25 +03:00
|
|
|
mLoadTime(SecondsFromPRTime(PR_Now())),
|
2008-09-05 03:00:42 +04:00
|
|
|
mExpiryTime(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mMustValidate(false),
|
2011-07-01 21:03:38 +04:00
|
|
|
// We start off as evicted so we don't try to update the cache. PutIntoCache
|
|
|
|
// will set this to false.
|
2011-10-17 18:59:28 +04:00
|
|
|
mEvicted(true),
|
|
|
|
mHasNoProxies(true),
|
2011-09-21 01:00:42 +04:00
|
|
|
mForcePrincipalCheck(forcePrincipalCheck)
|
2015-04-08 00:49:00 +03:00
|
|
|
{ }
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2009-01-31 05:17:47 +03:00
|
|
|
imgCacheEntry::~imgCacheEntry()
|
|
|
|
{
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_FUNC(gImgLog, "imgCacheEntry::~imgCacheEntry()");
|
2009-01-31 05:17:47 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgCacheEntry::Touch(bool updateTime /* = true */)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE(gImgLog, "imgCacheEntry::Touch");
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (updateTime) {
|
2008-09-05 03:00:42 +04:00
|
|
|
mTouchedTime = SecondsFromPRTime(PR_Now());
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
UpdateCache();
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgCacheEntry::UpdateCache(int32_t diff /* = 0 */)
|
2009-09-13 02:44:18 +04:00
|
|
|
{
|
2009-01-31 05:17:47 +03: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 21:45:45 +03:00
|
|
|
mLoader->CacheEntriesChanged(mRequest->IsChrome(), diff);
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 08:15:25 +03:00
|
|
|
void imgCacheEntry::UpdateLoadTime()
|
|
|
|
{
|
|
|
|
mLoadTime = SecondsFromPRTime(PR_Now());
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgCacheEntry::SetHasNoProxies(bool hasNoProxies)
|
2009-01-31 05:17:47 +03:00
|
|
|
{
|
2015-11-16 20:21:00 +03:00
|
|
|
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
2015-05-11 23:42:30 +03:00
|
|
|
if (hasNoProxies) {
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog, "imgCacheEntry::SetHasNoProxies true",
|
2015-05-20 20:21:13 +03:00
|
|
|
"uri", mRequest->CacheKey().Spec());
|
2015-05-11 23:42:30 +03:00
|
|
|
} else {
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog, "imgCacheEntry::SetHasNoProxies false",
|
2015-05-20 20:21:13 +03:00
|
|
|
"uri", mRequest->CacheKey().Spec());
|
2015-05-11 23:42:30 +03:00
|
|
|
}
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
|
|
|
|
mHasNoProxies = hasNoProxies;
|
|
|
|
}
|
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
imgCacheQueue::imgCacheQueue()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mDirty(false),
|
2008-09-05 03:00:42 +04:00
|
|
|
mSize(0)
|
2015-04-08 00:49:00 +03:00
|
|
|
{ }
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgCacheQueue::UpdateSize(int32_t diff)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
mSize += diff;
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
uint32_t
|
|
|
|
imgCacheQueue::GetSize() const
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <algorithm>
|
2008-09-11 15:34:17 +04:00
|
|
|
using namespace std;
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgCacheQueue::Remove(imgCacheEntry* entry)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
queueContainer::iterator it = find(mQueue.begin(), mQueue.end(), entry);
|
|
|
|
if (it != mQueue.end()) {
|
|
|
|
mSize -= (*it)->GetDataSize();
|
|
|
|
mQueue.erase(it);
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgCacheQueue::Push(imgCacheEntry* entry)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
mSize += entry->GetDataSize();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgCacheEntry> refptr(entry);
|
2008-09-05 03:00:42 +04:00
|
|
|
mQueue.push_back(refptr);
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
already_AddRefed<imgCacheEntry>
|
|
|
|
imgCacheQueue::Pop()
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2015-04-08 00:49:00 +03:00
|
|
|
if (mQueue.empty()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
|
|
|
if (IsDirty()) {
|
2008-09-05 03:00:42 +04:00
|
|
|
Refresh();
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgCacheEntry> entry = mQueue[0];
|
2008-09-05 03:00:42 +04:00
|
|
|
std::pop_heap(mQueue.begin(), mQueue.end(), imgLoader::CompareCacheEntries);
|
|
|
|
mQueue.pop_back();
|
|
|
|
|
|
|
|
mSize -= entry->GetDataSize();
|
2013-04-22 15:15:59 +04:00
|
|
|
return entry.forget();
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgCacheQueue::Refresh()
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
std::make_heap(mQueue.begin(), mQueue.end(), imgLoader::CompareCacheEntries);
|
2011-10-17 18:59:28 +04:00
|
|
|
mDirty = false;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgCacheQueue::MarkDirty()
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mDirty = true;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
bool
|
|
|
|
imgCacheQueue::IsDirty()
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
return mDirty;
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
uint32_t
|
|
|
|
imgCacheQueue::GetNumElements() const
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
return mQueue.size();
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
imgCacheQueue::iterator
|
|
|
|
imgCacheQueue::begin()
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
return mQueue.begin();
|
|
|
|
}
|
2015-04-08 00:49:00 +03:00
|
|
|
|
|
|
|
imgCacheQueue::const_iterator
|
|
|
|
imgCacheQueue::begin() const
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
return mQueue.begin();
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
imgCacheQueue::iterator
|
|
|
|
imgCacheQueue::end()
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
return mQueue.end();
|
|
|
|
}
|
2015-04-08 00:49:00 +03:00
|
|
|
|
|
|
|
imgCacheQueue::const_iterator
|
|
|
|
imgCacheQueue::end() const
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
return mQueue.end();
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsresult
|
|
|
|
imgLoader::CreateNewProxyForRequest(imgRequest* aRequest,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
imgRequestProxy** _retval)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::CreateNewProxyForRequest",
|
2015-04-08 00:49:00 +03:00
|
|
|
"imgRequest", aRequest);
|
2008-09-05 03:00:42 +04: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 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy> proxyRequest = new imgRequestProxy();
|
2008-09-05 03:00:42 +04:00
|
|
|
|
|
|
|
/* It is important to call |SetLoadFlags()| before calling |Init()| because
|
|
|
|
|Init()| adds the request to the loadgroup.
|
|
|
|
*/
|
|
|
|
proxyRequest->SetLoadFlags(aLoadFlags);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageURL> uri;
|
2010-05-11 07:27:41 +04:00
|
|
|
aRequest->GetURI(getter_AddRefs(uri));
|
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
// init adds itself to imgRequest's list of observers
|
2012-12-20 01:28:54 +04:00
|
|
|
nsresult rv = proxyRequest->Init(aRequest, aLoadGroup, uri, aObserver);
|
2015-03-05 09:18:09 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2008-09-05 03:00:42 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-03-05 09:18:09 +03:00
|
|
|
proxyRequest.forget(_retval);
|
2008-09-05 03:00:42 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class imgCacheExpirationTracker final
|
2012-01-03 00:23:41 +04:00
|
|
|
: public nsExpirationTracker<imgCacheEntry, 3>
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
|
|
|
enum { TIMEOUT_SECONDS = 10 };
|
|
|
|
public:
|
|
|
|
imgCacheExpirationTracker();
|
|
|
|
|
|
|
|
protected:
|
2015-04-08 00:49:00 +03:00
|
|
|
void NotifyExpired(imgCacheEntry* entry);
|
2008-09-05 03:00:42 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
imgCacheExpirationTracker::imgCacheExpirationTracker()
|
2015-09-10 07:07:07 +03:00
|
|
|
: nsExpirationTracker<imgCacheEntry, 3>(TIMEOUT_SECONDS * 1000,
|
|
|
|
"imgCacheExpirationTracker")
|
2015-04-08 00:49:00 +03:00
|
|
|
{ }
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgCacheExpirationTracker::NotifyExpired(imgCacheEntry* entry)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2009-02-25 22:09:44 +03:00
|
|
|
// Hold on to a reference to this entry, because the expiration tracker
|
|
|
|
// mechanism doesn't.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgCacheEntry> kungFuDeathGrip(entry);
|
2009-02-25 22:09:44 +03:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> req = entry->GetRequest();
|
2015-05-11 23:42:30 +03:00
|
|
|
if (req) {
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog,
|
2015-05-11 23:42:30 +03:00
|
|
|
"imgCacheExpirationTracker::NotifyExpired",
|
2015-05-20 20:21:13 +03:00
|
|
|
"entry", req->CacheKey().Spec());
|
2015-05-11 23:42:30 +03:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
}
|
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
// We can be called multiple times on the same entry. Don't do work multiple
|
|
|
|
// times.
|
2015-04-08 00:49:00 +03:00
|
|
|
if (!entry->Evicted()) {
|
2012-06-26 08:20:12 +04:00
|
|
|
entry->Loader()->RemoveFromCache(entry);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
entry->Loader()->VerifyCacheSizes();
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// imgLoader
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-09 11:09:42 +04:00
|
|
|
double imgLoader::sCacheTimeWeight;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t imgLoader::sCacheMaxSize;
|
2012-06-26 08:20:12 +04:00
|
|
|
imgMemoryReporter* imgLoader::sMemReporter;
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
NS_IMPL_ISUPPORTS(imgLoader, imgILoader, nsIContentSniffer, imgICache,
|
|
|
|
nsISupportsWeakReference, nsIObserver)
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2016-05-19 15:31:15 +03:00
|
|
|
static imgLoader* gNormalLoader = nullptr;
|
|
|
|
static imgLoader* gPrivateBrowsingLoader = nullptr;
|
2014-04-09 02:51:33 +04:00
|
|
|
|
2016-05-19 15:31:15 +03:00
|
|
|
/* static */ already_AddRefed<imgLoader>
|
|
|
|
imgLoader::CreateImageLoader()
|
|
|
|
{
|
|
|
|
// In some cases, such as xpctests, XPCOM modules are not automatically
|
|
|
|
// initialized. We need to make sure that our module is initialized before
|
|
|
|
// we hand out imgLoader instances and code starts using them.
|
|
|
|
mozilla::image::EnsureModuleInitialized();
|
|
|
|
|
|
|
|
RefPtr<imgLoader> loader = new imgLoader();
|
|
|
|
loader->Init();
|
|
|
|
|
|
|
|
return loader.forget();
|
|
|
|
}
|
|
|
|
|
2014-04-09 02:51:33 +04:00
|
|
|
imgLoader*
|
2016-05-19 15:31:15 +03:00
|
|
|
imgLoader::NormalLoader()
|
2014-04-09 02:51:33 +04:00
|
|
|
{
|
2016-05-19 15:31:15 +03:00
|
|
|
if (!gNormalLoader) {
|
|
|
|
gNormalLoader = CreateImageLoader().take();
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2016-05-19 15:31:15 +03:00
|
|
|
return gNormalLoader;
|
2014-04-09 02:51:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
imgLoader*
|
2016-05-19 15:31:15 +03:00
|
|
|
imgLoader::PrivateBrowsingLoader()
|
2014-04-09 02:51:33 +04:00
|
|
|
{
|
2016-05-19 15:31:15 +03:00
|
|
|
if (!gPrivateBrowsingLoader) {
|
|
|
|
gPrivateBrowsingLoader = CreateImageLoader().take();
|
|
|
|
gPrivateBrowsingLoader->RespectPrivacyNotifications();
|
2014-04-09 02:51:33 +04:00
|
|
|
}
|
2016-05-19 15:31:15 +03:00
|
|
|
return gPrivateBrowsingLoader;
|
2014-04-09 02:51:33 +04:00
|
|
|
}
|
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
imgLoader::imgLoader()
|
2014-09-06 01:36:11 +04:00
|
|
|
: mUncachedImagesMutex("imgLoader::UncachedImages"), mRespectPrivacy(false)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2012-06-26 08:20:12 +04:00
|
|
|
sMemReporter->AddRef();
|
|
|
|
sMemReporter->RegisterLoader(this);
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
imgLoader::~imgLoader()
|
|
|
|
{
|
2012-06-26 08:20:12 +04:00
|
|
|
ClearChromeImageCache();
|
|
|
|
ClearImageCache();
|
2014-09-06 01:36:11 +04: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 16:37:57 +03:00
|
|
|
for (auto iter = mUncachedImages.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsPtrHashKey<imgRequest>* entry = iter.Get();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> req = entry->GetKey();
|
2015-07-14 16:37:57 +03:00
|
|
|
req->ClearLoader();
|
|
|
|
}
|
2014-09-06 01:36:11 +04:00
|
|
|
}
|
2012-06-26 08:20:12 +04:00
|
|
|
sMemReporter->UnregisterLoader(this);
|
|
|
|
sMemReporter->Release();
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgLoader::VerifyCacheSizes()
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2010-04-29 10:27:00 +04:00
|
|
|
#ifdef DEBUG
|
2015-04-08 00:49:00 +03:00
|
|
|
if (!mCacheTracker) {
|
2008-09-05 03:00:42 +04:00
|
|
|
return;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
uint32_t cachesize = mCache.Count() + mChromeCache.Count();
|
2015-04-08 00:49:00 +03:00
|
|
|
uint32_t queuesize =
|
|
|
|
mCacheQueue.GetNumElements() + mChromeCacheQueue.GetNumElements();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t trackersize = 0;
|
2015-10-17 13:53:28 +03:00
|
|
|
for (nsExpirationTracker<imgCacheEntry, 3>::Iterator it(mCacheTracker.get());
|
2015-04-08 00:49:00 +03:00
|
|
|
it.Next(); ){
|
2008-09-05 03:00:42 +04:00
|
|
|
trackersize++;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2015-02-10 01:34:50 +03: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 10:27:00 +04:00
|
|
|
#endif
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
imgLoader::imgCacheTable&
|
|
|
|
imgLoader::GetCache(bool aForChrome)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2015-04-28 21:45:45 +03:00
|
|
|
return aForChrome ? mChromeCache : mCache;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
imgLoader::imgCacheTable&
|
|
|
|
imgLoader::GetCache(const ImageCacheKey& aKey)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2015-04-28 21:45:45 +03:00
|
|
|
return GetCache(aKey.IsChrome());
|
2013-09-28 22:28:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheQueue&
|
|
|
|
imgLoader::GetCacheQueue(bool aForChrome)
|
2013-09-28 22:28:42 +04:00
|
|
|
{
|
2015-04-28 21:45:45 +03:00
|
|
|
return aForChrome ? mChromeCacheQueue : mCacheQueue;
|
|
|
|
|
2013-09-28 22:28:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheQueue&
|
|
|
|
imgLoader::GetCacheQueue(const ImageCacheKey& aKey)
|
2013-09-28 22:28:42 +04:00
|
|
|
{
|
2015-04-28 21:45:45 +03:00
|
|
|
return GetCacheQueue(aKey.IsChrome());
|
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
void imgLoader::GlobalInit()
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2014-09-23 01:30:20 +04:00
|
|
|
sCacheTimeWeight = gfxPrefs::ImageCacheTimeWeight() / 1000.0;
|
|
|
|
int32_t cachesize = gfxPrefs::ImageCacheSize();
|
|
|
|
sCacheMaxSize = cachesize > 0 ? cachesize : 0;
|
2009-07-15 11:22:40 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
sMemReporter = new imgMemoryReporter();
|
2013-11-07 09:35:30 +04:00
|
|
|
RegisterStrongMemoryReporter(sMemReporter);
|
2015-04-08 00:49:00 +03:00
|
|
|
RegisterImagesContentUsedUncompressedDistinguishedAmount(
|
|
|
|
imgMemoryReporter::ImagesContentUsedUncompressedDistinguishedAmount);
|
2012-06-26 08:20:12 +04:00
|
|
|
}
|
|
|
|
|
2016-09-19 20:29:59 +03:00
|
|
|
void imgLoader::ShutdownMemoryReporter()
|
|
|
|
{
|
|
|
|
UnregisterImagesContentUsedUncompressedDistinguishedAmount();
|
|
|
|
UnregisterStrongMemoryReporter(sMemReporter);
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsresult
|
|
|
|
imgLoader::InitCache()
|
2012-06-26 08:20:12 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
2015-04-08 00:49:00 +03:00
|
|
|
if (!os) {
|
2012-06-26 08:20:12 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2012-06-26 08:20:12 +04:00
|
|
|
|
|
|
|
os->AddObserver(this, "memory-pressure", false);
|
|
|
|
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 13:53:28 +03:00
|
|
|
mCacheTracker = MakeUnique<imgCacheExpirationTracker>();
|
2012-06-26 08:20:12 +04:00
|
|
|
|
2013-09-02 12:41:57 +04:00
|
|
|
return NS_OK;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsresult
|
|
|
|
imgLoader::Init()
|
2009-07-15 11:22:40 +04:00
|
|
|
{
|
2012-06-26 08:20:12 +04:00
|
|
|
InitCache();
|
|
|
|
|
2011-06-12 06:30:15 +04:00
|
|
|
ReadAcceptHeaderPref();
|
2009-07-15 11:22:40 +04:00
|
|
|
|
2011-06-12 06:30:15 +04:00
|
|
|
Preferences::AddWeakObserver(this, "image.http.accept");
|
2009-07-15 11:22:40 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-07-12 05:01:53 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgLoader::RespectPrivacyNotifications()
|
|
|
|
{
|
|
|
|
mRespectPrivacy = true;
|
2009-07-15 11:22:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-04-08 00:49:00 +03:00
|
|
|
imgLoader::Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const char16_t* aData)
|
2009-07-15 11:22:40 +04:00
|
|
|
{
|
2010-07-12 05:01:53 +04:00
|
|
|
// We listen for pref change notifications...
|
|
|
|
if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
2016-07-21 08:03:25 +03:00
|
|
|
if (!NS_strcmp(aData, u"image.http.accept")) {
|
2011-06-12 06:30:15 +04:00
|
|
|
ReadAcceptHeaderPref();
|
2010-07-12 05:01:53 +04:00
|
|
|
}
|
2009-07-15 11:22:40 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
} else if (strcmp(aTopic, "memory-pressure") == 0) {
|
|
|
|
MinimizeCaches();
|
|
|
|
} 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 05:01:53 +04:00
|
|
|
ClearImageCache();
|
2012-06-26 08:20:12 +04:00
|
|
|
ClearChromeImageCache();
|
|
|
|
}
|
2016-09-19 20:29:59 +03:00
|
|
|
} else if (strcmp(aTopic, "profile-before-change") == 0) {
|
|
|
|
mCacheTracker = nullptr;
|
|
|
|
} else if (strcmp(aTopic, "xpcom-shutdown") == 0) {
|
2012-06-26 08:20:12 +04:00
|
|
|
mCacheTracker = nullptr;
|
2016-09-19 20:29:59 +03:00
|
|
|
ShutdownMemoryReporter();
|
2010-07-12 05:01:53 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
} else {
|
2010-07-12 05:01:53 +04:00
|
|
|
// (Nothing else should bring us here)
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(0, "Invalid topic received");
|
2010-07-12 05:01:53 +04:00
|
|
|
}
|
|
|
|
|
2009-07-15 11:22:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-12 06:30:15 +04:00
|
|
|
void imgLoader::ReadAcceptHeaderPref()
|
2009-07-15 11:22:40 +04:00
|
|
|
{
|
2011-06-12 06:30:15 +04:00
|
|
|
nsAdoptingCString accept = Preferences::GetCString("image.http.accept");
|
2015-04-08 00:49:00 +03:00
|
|
|
if (accept) {
|
2009-07-15 11:22:40 +04:00
|
|
|
mAcceptHeader = accept;
|
2015-04-08 00:49:00 +03:00
|
|
|
} else {
|
|
|
|
mAcceptHeader =
|
|
|
|
IMAGE_PNG "," IMAGE_WILDCARD ";q=0.8," ANY_WILDCARD ";q=0.5";
|
|
|
|
}
|
2009-07-15 11:22:40 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgLoader::ClearCache(bool chrome)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2016-06-07 01:23:43 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
bool privateLoader = this == gPrivateBrowsingLoader;
|
|
|
|
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
|
|
|
Unused << cp->SendClearImageCache(privateLoader, chrome);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (chrome) {
|
2008-09-05 03:00:42 +04:00
|
|
|
return ClearChromeImageCache();
|
2015-04-08 00:49:00 +03:00
|
|
|
} else {
|
2008-09-05 03:00:42 +04:00
|
|
|
return ClearImageCache();
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
2015-10-26 23:03:26 +03:00
|
|
|
imgLoader::FindEntryProperties(nsIURI* uri,
|
2016-04-11 12:00:03 +03:00
|
|
|
nsIDOMDocument* aDOMDoc,
|
2015-10-26 23:03:26 +03:00
|
|
|
nsIProperties** _retval)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2016-04-11 12:00:03 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDoc);
|
2016-08-04 21:22:00 +03:00
|
|
|
|
|
|
|
PrincipalOriginAttributes attrs;
|
|
|
|
if (doc) {
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
|
|
|
|
if (principal) {
|
|
|
|
attrs = BasePrincipal::Cast(principal)->OriginAttributesRef();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 08:34:32 +03:00
|
|
|
nsresult rv;
|
|
|
|
ImageCacheKey key(uri, attrs, doc, rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheTable& cache = GetCache(key);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgCacheEntry> entry;
|
2015-04-28 21:45:45 +03:00
|
|
|
if (cache.Get(key, getter_AddRefs(entry)) && entry) {
|
2015-04-08 00:49:00 +03:00
|
|
|
if (mCacheTracker && entry->HasNoProxies()) {
|
2012-06-26 08:20:12 +04:00
|
|
|
mCacheTracker->MarkUsed(entry);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> request = entry->GetRequest();
|
2008-09-05 03:00:42 +04:00
|
|
|
if (request) {
|
2015-03-05 09:18:09 +03:00
|
|
|
nsCOMPtr<nsIProperties> properties = request->Properties();
|
|
|
|
properties.forget(_retval);
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-28 23:01:07 +03:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
imgLoader::ClearCacheForControlledDocument(nsIDocument* aDoc)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDoc);
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<RefPtr<imgCacheEntry>, 128> entriesToBeRemoved;
|
2015-10-28 23:01:07 +03: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-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgLoader::Shutdown()
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2016-05-19 15:31:15 +03:00
|
|
|
NS_IF_RELEASE(gNormalLoader);
|
|
|
|
gNormalLoader = nullptr;
|
|
|
|
NS_IF_RELEASE(gPrivateBrowsingLoader);
|
|
|
|
gPrivateBrowsingLoader = nullptr;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsresult
|
|
|
|
imgLoader::ClearChromeImageCache()
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2012-06-26 08:20:12 +04:00
|
|
|
return EvictEntries(mChromeCache);
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsresult
|
|
|
|
imgLoader::ClearImageCache()
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2012-06-26 08:20:12 +04:00
|
|
|
return EvictEntries(mCache);
|
2009-05-08 00:55:06 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgLoader::MinimizeCaches()
|
2009-05-08 00:55:06 +04:00
|
|
|
{
|
2012-06-26 08:20:12 +04:00
|
|
|
EvictEntries(mCacheQueue);
|
|
|
|
EvictEntries(mChromeCacheQueue);
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
bool
|
2015-04-28 21:45:45 +03:00
|
|
|
imgLoader::PutIntoCache(const ImageCacheKey& aKey, imgCacheEntry* entry)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheTable& cache = GetCache(aKey);
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-04-28 21:45:45 +03:00
|
|
|
"imgLoader::PutIntoCache", "uri", aKey.Spec());
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-05-01 23:01:51 +03:00
|
|
|
// Check to see if this request already exists in the cache. If so, we'll
|
|
|
|
// replace the old version.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgCacheEntry> tmpCacheEntry;
|
2015-04-28 21:45:45 +03:00
|
|
|
if (cache.Get(aKey, getter_AddRefs(tmpCacheEntry)) && tmpCacheEntry) {
|
2015-11-16 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2015-04-08 00:49:00 +03:00
|
|
|
("[this=%p] imgLoader::PutIntoCache -- Element already in the cache",
|
|
|
|
nullptr));
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> tmpRequest = tmpCacheEntry->GetRequest();
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2008-10-01 01:47:47 +04:00
|
|
|
// If it already exists, and we're putting the same key into the cache, we
|
|
|
|
// should remove the old version.
|
2015-11-16 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2015-04-08 00:49:00 +03:00
|
|
|
("[this=%p] imgLoader::PutIntoCache -- Replacing cached element",
|
|
|
|
nullptr));
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
RemoveFromCache(aKey);
|
2008-10-01 01:47:47 +04:00
|
|
|
} else {
|
2015-11-16 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2015-04-08 00:49:00 +03:00
|
|
|
("[this=%p] imgLoader::PutIntoCache --"
|
|
|
|
" Element NOT already in the cache", nullptr));
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
cache.Put(aKey, entry);
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2009-03-18 00:07:16 +03:00
|
|
|
// We can be called to resurrect an evicted entry.
|
2015-04-08 00:49:00 +03:00
|
|
|
if (entry->Evicted()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
entry->SetEvicted(false);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-03-18 00:07:16 +03: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-08 00:49:00 +03:00
|
|
|
if (mCacheTracker) {
|
2012-06-26 08:20:12 +04:00
|
|
|
addrv = mCacheTracker->AddObject(entry);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-03-18 00:07:16 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(addrv)) {
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheQueue& queue = GetCacheQueue(aKey);
|
2009-03-18 00:07:16 +03:00
|
|
|
queue.Push(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> request = entry->GetRequest();
|
2011-10-17 18:59:28 +04:00
|
|
|
request->SetIsInCache(true);
|
2014-09-06 01:36:11 +04:00
|
|
|
RemoveFromUncachedImages(request);
|
2009-03-18 00:07:16 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-01-31 05:17:47 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
bool
|
|
|
|
imgLoader::SetHasNoProxies(imgRequest* aRequest, imgCacheEntry* aEntry)
|
2009-01-31 05:17:47 +03:00
|
|
|
{
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-05-20 20:21:13 +03:00
|
|
|
"imgLoader::SetHasNoProxies", "uri",
|
|
|
|
aRequest->CacheKey().Spec());
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2014-09-11 06:47:00 +04:00
|
|
|
aEntry->SetHasNoProxies(true);
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (aEntry->Evicted()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheQueue& queue = GetCacheQueue(aRequest->IsChrome());
|
2009-01-31 05:17:47 +03:00
|
|
|
|
|
|
|
nsresult addrv = NS_OK;
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (mCacheTracker) {
|
2014-09-11 06:47:00 +04:00
|
|
|
addrv = mCacheTracker->AddObject(aEntry);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(addrv)) {
|
2014-09-11 06:47:00 +04:00
|
|
|
queue.Push(aEntry);
|
2009-01-31 05:17:47 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheTable& cache = GetCache(aRequest->IsChrome());
|
2008-09-05 03:00:42 +04:00
|
|
|
CheckCacheLimits(cache, queue);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
bool
|
|
|
|
imgLoader::SetHasProxies(imgRequest* aRequest)
|
2009-01-31 05:17:47 +03:00
|
|
|
{
|
|
|
|
VerifyCacheSizes();
|
|
|
|
|
2015-05-20 20:21:13 +03:00
|
|
|
const ImageCacheKey& key = aRequest->CacheKey();
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheTable& cache = GetCache(key);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-04-28 21:45:45 +03:00
|
|
|
"imgLoader::SetHasProxies", "uri", key.Spec());
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgCacheEntry> entry;
|
2015-04-28 21:45:45 +03:00
|
|
|
if (cache.Get(key, getter_AddRefs(entry)) && entry) {
|
2014-09-11 06:47:00 +04:00
|
|
|
// Make sure the cache entry is for the right request
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> entryRequest = entry->GetRequest();
|
2014-09-11 06:47:00 +04:00
|
|
|
if (entryRequest == aRequest && entry->HasNoProxies()) {
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheQueue& queue = GetCacheQueue(key);
|
2014-09-11 06:47:00 +04:00
|
|
|
queue.Remove(entry);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (mCacheTracker) {
|
2014-09-11 06:47:00 +04:00
|
|
|
mCacheTracker->RemoveObject(entry);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2014-09-11 06:47:00 +04:00
|
|
|
entry->SetHasNoProxies(false);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2014-09-11 06:47:00 +04:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-31 05:17:47 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
2015-04-28 21:45:45 +03:00
|
|
|
imgLoader::CacheEntriesChanged(bool aForChrome, int32_t aSizeDiff /* = 0 */)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheQueue& queue = GetCacheQueue(aForChrome);
|
2008-09-05 03:00:42 +04:00
|
|
|
queue.MarkDirty();
|
2015-04-28 21:45:45 +03:00
|
|
|
queue.UpdateSize(aSizeDiff);
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgLoader::CheckCacheLimits(imgCacheTable& cache, imgCacheQueue& queue)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2015-04-08 00:49:00 +03:00
|
|
|
if (queue.GetNumElements() == 0) {
|
2013-03-30 00:14:19 +04:00
|
|
|
NS_ASSERTION(queue.GetSize() == 0,
|
2008-09-05 03:00:42 +04:00
|
|
|
"imgLoader::CheckCacheLimits -- incorrect cache size");
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2014-07-19 05:47:39 +04:00
|
|
|
// Remove entries from the cache until we're back at our desired max size.
|
|
|
|
while (queue.GetSize() > sCacheMaxSize) {
|
2008-09-05 03:00:42 +04:00
|
|
|
// Remove the first entry in the queue.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgCacheEntry> entry(queue.Pop());
|
2008-09-05 03:00:42 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(entry, "imgLoader::CheckCacheLimits -- NULL entry pointer");
|
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> req = entry->GetRequest();
|
2015-05-11 23:42:30 +03:00
|
|
|
if (req) {
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-05-11 23:42:30 +03:00
|
|
|
"imgLoader::CheckCacheLimits",
|
2015-05-20 20:21:13 +03:00
|
|
|
"entry", req->CacheKey().Spec());
|
2015-05-11 23:42:30 +03:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (entry) {
|
2008-09-05 03:00:42 +04:00
|
|
|
RemoveFromCache(entry);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03: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-05 03:00:42 +04: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 05:17:47 +03: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 05:37:45 +03:00
|
|
|
if (request->GetValidator()) {
|
2012-10-12 16:43:01 +04:00
|
|
|
rv = CreateNewProxyForRequest(request, aLoadGroup, aObserver,
|
|
|
|
aLoadFlags, aProxyRequest);
|
2010-05-25 18:34:04 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-05-25 18:34:04 +04:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2010-08-02 23:44:49 +04: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-30 02:37:42 +03:00
|
|
|
// resulting from methods such as StartDecoding(). See bug 579122.
|
2011-10-17 18:59:28 +04:00
|
|
|
proxy->SetNotificationsDeferred(true);
|
2010-08-02 23:44:49 +04:00
|
|
|
|
|
|
|
// Attach the proxy without notifying
|
2015-03-24 05:37:45 +03:00
|
|
|
request->GetValidator()->AddProxy(proxy);
|
2010-08-02 23:44:49 +04:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
|
|
|
return NS_SUCCEEDED(rv);
|
|
|
|
|
|
|
|
} else {
|
2011-07-01 21:03:42 +04: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-05 03:00:42 +04:00
|
|
|
nsCOMPtr<nsIChannel> newChannel;
|
2011-09-21 01:00:42 +04:00
|
|
|
bool forcePrincipalCheck;
|
2008-09-05 03:00:42 +04:00
|
|
|
rv = NewImageChannel(getter_AddRefs(newChannel),
|
2011-09-21 01:00:42 +04:00
|
|
|
&forcePrincipalCheck,
|
2008-09-05 03:00:42 +04:00
|
|
|
aURI,
|
|
|
|
aInitialDocumentURI,
|
2016-04-27 20:40:56 +03:00
|
|
|
aCORSMode,
|
2008-09-05 03:00:42 +04:00
|
|
|
aReferrerURI,
|
2014-11-18 16:46:53 +03:00
|
|
|
aReferrerPolicy,
|
2008-09-05 03:00:42 +04:00
|
|
|
aLoadGroup,
|
2009-07-15 11:22:40 +04:00
|
|
|
mAcceptHeader,
|
2010-05-21 00:08:02 +04:00
|
|
|
aLoadFlags,
|
2014-08-20 01:49:38 +04:00
|
|
|
aLoadPolicyType,
|
2014-09-21 20:45:34 +04:00
|
|
|
aLoadingPrincipal,
|
2016-04-13 16:34:36 +03:00
|
|
|
aCX,
|
|
|
|
mRespectPrivacy);
|
2008-09-05 03:00:42 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy> req;
|
2008-09-05 03:00:42 +04:00
|
|
|
rv = CreateNewProxyForRequest(request, aLoadGroup, aObserver,
|
2012-11-04 07:04:07 +04:00
|
|
|
aLoadFlags, getter_AddRefs(req));
|
2008-09-05 03:00:42 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2009-07-28 20:13:48 +04:00
|
|
|
// Make sure that OnStatus/OnProgress calls have the right request set...
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsProgressNotificationProxy> progressproxy =
|
2011-07-01 21:03:38 +04:00
|
|
|
new nsProgressNotificationProxy(newChannel, req);
|
2015-04-08 00:49:00 +03:00
|
|
|
if (!progressproxy) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-07-28 20:13:48 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgCacheValidator> hvc =
|
2015-04-08 00:49:00 +03:00
|
|
|
new imgCacheValidator(progressproxy, this, request, aCX,
|
|
|
|
forcePrincipalCheck);
|
2011-07-14 22:47:34 +04:00
|
|
|
|
2013-09-28 22:28:42 +04: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 22:47:34 +04:00
|
|
|
|
2012-03-02 09:13:54 +04:00
|
|
|
// We must set the notification callbacks before setting up the
|
|
|
|
// CORS listener, because that's also interested inthe
|
|
|
|
// notification callbacks.
|
|
|
|
newChannel->SetNotificationCallbacks(hvc);
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
request->SetValidator(hvc);
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2010-08-02 23:44:49 +04: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-30 02:37:42 +03:00
|
|
|
// resulting from methods such as StartDecoding(). See bug 579122.
|
2015-03-05 09:18:09 +03:00
|
|
|
req->SetNotificationsDeferred(true);
|
2010-08-02 23:44:49 +04:00
|
|
|
|
|
|
|
// Add the proxy without notifying
|
2015-03-05 09:18:09 +03:00
|
|
|
hvc->AddProxy(req);
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2014-06-04 00:37:46 +04:00
|
|
|
mozilla::net::PredictorLearn(aURI, aInitialDocumentURI,
|
|
|
|
nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE, aLoadGroup);
|
2013-10-26 01:56:58 +04:00
|
|
|
|
2016-04-27 20:40:56 +03:00
|
|
|
rv = newChannel->AsyncOpen2(listener);
|
2015-03-05 09:18:09 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-03-05 09:18:09 +03:00
|
|
|
req.forget(aProxyRequest);
|
|
|
|
return true;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03: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-05 03:00:42 +04:00
|
|
|
{
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE(gImgLog, "imgLoader::ValidateEntry");
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasExpired;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t expirationTime = aEntry->GetExpiryTime();
|
2008-09-05 03:00:42 +04:00
|
|
|
if (expirationTime <= SecondsFromPRTime(PR_Now())) {
|
2011-10-17 18:59:28 +04:00
|
|
|
hasExpired = true;
|
2008-09-05 03:00:42 +04:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
hasExpired = false;
|
2008-09-05 03:00:42 +04: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 08:15:25 +03:00
|
|
|
uint32_t lastModTime = aEntry->GetLoadTime();
|
2008-09-05 03:00:42 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> theFile;
|
|
|
|
rv = fileUrl->GetFile(getter_AddRefs(theFile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-08-30 11:10:35 +04:00
|
|
|
PRTime fileLastMod;
|
2008-09-05 03:00:42 +04:00
|
|
|
rv = theFile->GetLastModifiedTime(&fileLastMod);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// nsIFile uses millisec, NSPR usec
|
|
|
|
fileLastMod *= 1000;
|
|
|
|
hasExpired = SecondsFromPRTime((PRTime)fileLastMod) > lastModTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> request(aEntry->GetRequest());
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (!request) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2014-11-18 16:46:53 +03:00
|
|
|
if (!ValidateSecurityInfo(request, aEntry->ForcePrincipalCheck(),
|
|
|
|
aCORSMode, aLoadingPrincipal,
|
2016-04-27 20:40:56 +03:00
|
|
|
aCX, aLoadPolicyType, aReferrerPolicy))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-07-14 22:47:34 +04:00
|
|
|
|
2014-10-22 13:48:36 +04: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 04:58:32 +04:00
|
|
|
nsAutoCString scheme;
|
|
|
|
aURI->GetScheme(scheme);
|
2014-10-22 13:48:36 +04:00
|
|
|
if (scheme.EqualsLiteral("data") &&
|
|
|
|
!(aLoadFlags & nsIRequest::LOAD_BYPASS_CACHE)) {
|
2012-11-21 04:58:32 +04:00
|
|
|
return true;
|
2014-10-22 13:48:36 +04:00
|
|
|
}
|
2012-11-21 04:58:32 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool validateRequest = false;
|
2008-09-05 03:00:42 +04: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 18:20:58 +04:00
|
|
|
// XXX: nullptr seems to be a 'special' key value that indicates that NO
|
2008-09-05 03:00:42 +04:00
|
|
|
// validation is required.
|
|
|
|
//
|
2015-04-08 00:49:00 +03:00
|
|
|
void *key = (void*) aCX;
|
2015-03-24 05:37:45 +03:00
|
|
|
if (request->LoadId() != key) {
|
2009-11-13 02:00:30 +03: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-08 00:49:00 +03:00
|
|
|
if (aLoadFlags & nsIRequest::LOAD_BYPASS_CACHE) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-11-13 02:00:30 +03:00
|
|
|
|
2016-04-02 21:53:12 +03:00
|
|
|
if (MOZ_UNLIKELY(ChaosMode::isActive(ChaosFeature::ImageCache))) {
|
|
|
|
if (ChaosMode::randomUint32LessThan(4) < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
// Determine whether the cache aEntry must be revalidated...
|
|
|
|
validateRequest = ShouldRevalidateEntry(aEntry, aLoadFlags, hasExpired);
|
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2013-03-30 00:14:19 +04:00
|
|
|
("imgLoader::ValidateEntry validating cache entry. "
|
2008-09-05 03:00:42 +04:00
|
|
|
"validateRequest = %d", validateRequest));
|
2015-11-16 20:21:00 +03:00
|
|
|
} else if (!key && MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2013-03-30 00:14:19 +04:00
|
|
|
("imgLoader::ValidateEntry BYPASSING cache validation for %s "
|
2016-08-26 09:02:31 +03:00
|
|
|
"because of NULL LoadID", aURI->GetSpecOrDefault().get()));
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2009-01-05 08:52:22 +03: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 05:37:45 +03:00
|
|
|
if ((appCacheContainer = do_GetInterface(request->GetRequest()))) {
|
2009-01-05 08:52:22 +03:00
|
|
|
appCacheContainer->GetApplicationCache(getter_AddRefs(requestAppCache));
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
|
|
|
if ((appCacheContainer = do_QueryInterface(aLoadGroup))) {
|
2009-01-05 08:52:22 +03:00
|
|
|
appCacheContainer->GetApplicationCache(getter_AddRefs(groupAppCache));
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
2009-01-05 08:52:22 +03:00
|
|
|
|
|
|
|
if (requestAppCache != groupAppCache) {
|
2015-11-16 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2009-01-05 08:52:22 +03:00
|
|
|
("imgLoader::ValidateEntry - Unable to use cached imgRequest "
|
|
|
|
"[request=%p] because of mismatched application caches\n",
|
|
|
|
address_of(request)));
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-05 08:52:22 +03:00
|
|
|
}
|
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
if (validateRequest && aCanMakeNewChannel) {
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE(gImgLog,
|
2015-04-08 00:49:00 +03:00
|
|
|
"imgLoader::ValidateRequest |cache hit| must validate");
|
2008-09-05 03:00:42 +04:00
|
|
|
|
|
|
|
return ValidateRequestWithNewChannel(request, aURI, aInitialDocumentURI,
|
2014-11-18 16:46:53 +03:00
|
|
|
aReferrerURI, aReferrerPolicy,
|
|
|
|
aLoadGroup, aObserver,
|
2014-08-20 01:49:38 +04:00
|
|
|
aCX, aLoadFlags, aLoadPolicyType,
|
|
|
|
aProxyRequest, aLoadingPrincipal,
|
|
|
|
aCORSMode);
|
2011-07-14 22:47:34 +04:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
|
|
|
return !validateRequest;
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
bool
|
2015-04-28 21:45:45 +03:00
|
|
|
imgLoader::RemoveFromCache(const ImageCacheKey& aKey)
|
2013-09-28 22:28:42 +04:00
|
|
|
{
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-04-28 21:45:45 +03:00
|
|
|
"imgLoader::RemoveFromCache", "uri", aKey.Spec());
|
2013-09-28 22:28:42 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
imgCacheTable& cache = GetCache(aKey);
|
|
|
|
imgCacheQueue& queue = GetCacheQueue(aKey);
|
2013-09-28 22:28:42 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgCacheEntry> entry;
|
2015-04-28 21:45:45 +03:00
|
|
|
if (cache.Get(aKey, getter_AddRefs(entry)) && entry) {
|
|
|
|
cache.Remove(aKey);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!entry->Evicted(), "Evicting an already-evicted cache entry!");
|
2009-01-31 05:17:47 +03:00
|
|
|
|
|
|
|
// Entries with no proxies are in the tracker.
|
|
|
|
if (entry->HasNoProxies()) {
|
2015-04-08 00:49:00 +03:00
|
|
|
if (mCacheTracker) {
|
2012-06-26 08:20:12 +04:00
|
|
|
mCacheTracker->RemoveObject(entry);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
queue.Remove(entry);
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
entry->SetEvicted(true);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> request = entry->GetRequest();
|
2011-10-17 18:59:28 +04:00
|
|
|
request->SetIsInCache(false);
|
2014-09-06 01:36:11 +04:00
|
|
|
AddToUncachedImages(request);
|
2009-03-18 00:07:16 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2015-04-08 00:49:00 +03:00
|
|
|
|
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
bool
|
|
|
|
imgLoader::RemoveFromCache(imgCacheEntry* entry)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_STATIC_FUNC(gImgLog, "imgLoader::RemoveFromCache entry");
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> request = entry->GetRequest();
|
2008-09-05 03:00:42 +04:00
|
|
|
if (request) {
|
2015-05-20 20:21:13 +03:00
|
|
|
const ImageCacheKey& key = request->CacheKey();
|
|
|
|
imgCacheTable& cache = GetCache(key);
|
|
|
|
imgCacheQueue& queue = GetCacheQueue(key);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_STATIC_FUNC_WITH_PARAM(gImgLog,
|
2015-05-20 20:21:13 +03:00
|
|
|
"imgLoader::RemoveFromCache", "entry's uri",
|
|
|
|
key.Spec());
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-05-20 20:21:13 +03:00
|
|
|
cache.Remove(key);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-05-20 20:21:13 +03:00
|
|
|
if (entry->HasNoProxies()) {
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_STATIC_FUNC(gImgLog,
|
2015-05-20 20:21:13 +03:00
|
|
|
"imgLoader::RemoveFromCache removing from tracker");
|
|
|
|
if (mCacheTracker) {
|
|
|
|
mCacheTracker->RemoveObject(entry);
|
2009-01-31 05:17:47 +03:00
|
|
|
}
|
2015-05-20 20:21:13 +03:00
|
|
|
queue.Remove(entry);
|
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-05-20 20:21:13 +03:00
|
|
|
entry->SetEvicted(true);
|
|
|
|
request->SetIsInCache(false);
|
|
|
|
AddToUncachedImages(request);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-05-20 20:21:13 +03:00
|
|
|
return true;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-31 05:17:47 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsresult
|
|
|
|
imgLoader::EvictEntries(imgCacheTable& aCacheToClear)
|
2008-09-05 03:00:42 +04:00
|
|
|
{
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_STATIC_FUNC(gImgLog, "imgLoader::EvictEntries table");
|
2008-09-05 03:00:42 +04:00
|
|
|
|
|
|
|
// We have to make a temporary, since RemoveFromCache removes the element
|
|
|
|
// from the queue, invalidating iterators.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<imgCacheEntry> > entries;
|
2015-11-11 08:30:02 +03:00
|
|
|
for (auto iter = aCacheToClear.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
RefPtr<imgCacheEntry>& data = iter.Data();
|
|
|
|
entries.AppendElement(data);
|
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
for (uint32_t i = 0; i < entries.Length(); ++i) {
|
|
|
|
if (!RemoveFromCache(entries[i])) {
|
2008-09-05 03:00:42 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
MOZ_ASSERT(aCacheToClear.Count() == 0);
|
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsresult
|
|
|
|
imgLoader::EvictEntries(imgCacheQueue& aQueueToClear)
|
2009-05-08 00:55:06 +04:00
|
|
|
{
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_STATIC_FUNC(gImgLog, "imgLoader::EvictEntries queue");
|
2009-05-08 00:55:06 +04:00
|
|
|
|
|
|
|
// We have to make a temporary, since RemoveFromCache removes the element
|
|
|
|
// from the queue, invalidating iterators.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<imgCacheEntry> > entries(aQueueToClear.GetNumElements());
|
2015-04-08 00:49:00 +03:00
|
|
|
for (imgCacheQueue::const_iterator i = aQueueToClear.begin();
|
|
|
|
i != aQueueToClear.end(); ++i) {
|
2009-05-08 00:55:06 +04:00
|
|
|
entries.AppendElement(*i);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-05-08 00:55:06 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
for (uint32_t i = 0; i < entries.Length(); ++i) {
|
|
|
|
if (!RemoveFromCache(entries[i])) {
|
2009-05-08 00:55:06 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
|
|
|
}
|
2009-05-08 00:55:06 +04:00
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
MOZ_ASSERT(aQueueToClear.GetNumElements() == 0);
|
|
|
|
|
2009-05-08 00:55:06 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgLoader::AddToUncachedImages(imgRequest* aRequest)
|
2014-09-06 01:36:11 +04:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mUncachedImagesMutex);
|
|
|
|
mUncachedImages.PutEntry(aRequest);
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgLoader::RemoveFromUncachedImages(imgRequest* aRequest)
|
2014-09-06 01:36:11 +04:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mUncachedImagesMutex);
|
|
|
|
mUncachedImages.RemoveEntry(aRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 03:00:42 +04: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-08 00:49:00 +03: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-23 01:01:03 +03:00
|
|
|
{
|
2014-08-20 01:49:38 +04:00
|
|
|
// Optional parameter, so defaults to 0 (== TYPE_INVALID)
|
|
|
|
if (!aContentPolicyType) {
|
2015-09-21 00:55:59 +03:00
|
|
|
aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE;
|
2014-08-20 01:49:38 +04:00
|
|
|
}
|
2015-04-08 00:49:00 +03:00
|
|
|
imgRequestProxy* proxy;
|
2014-11-18 16:46:53 +03:00
|
|
|
ReferrerPolicy refpol = ReferrerPolicyFromString(aReferrerPolicy);
|
2016-04-11 11:58:03 +03:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aCX);
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aCX);
|
2014-11-18 16:46:53 +03:00
|
|
|
nsresult rv = LoadImage(aURI,
|
|
|
|
aInitialDocumentURI,
|
|
|
|
aReferrerURI,
|
2016-05-30 10:17:45 +03:00
|
|
|
refpol == mozilla::net::RP_Unset ?
|
|
|
|
mozilla::net::RP_Default : refpol,
|
2014-11-18 16:46:53 +03:00
|
|
|
aLoadingPrincipal,
|
|
|
|
aLoadGroup,
|
|
|
|
aObserver,
|
2016-04-11 11:58:03 +03:00
|
|
|
node,
|
|
|
|
doc,
|
2014-11-18 16:46:53 +03:00
|
|
|
aLoadFlags,
|
|
|
|
aCacheKey,
|
|
|
|
aContentPolicyType,
|
|
|
|
EmptyString(),
|
|
|
|
&proxy);
|
2012-10-12 16:43:01 +04:00
|
|
|
*_retval = proxy;
|
2014-11-18 16:46:53 +03:00
|
|
|
return rv;
|
2012-10-12 16:43:01 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsresult
|
|
|
|
imgLoader::LoadImage(nsIURI* aURI,
|
|
|
|
nsIURI* aInitialDocumentURI,
|
|
|
|
nsIURI* aReferrerURI,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver,
|
2016-04-11 11:58:03 +03:00
|
|
|
nsINode *aContext,
|
|
|
|
nsIDocument* aLoadingDocument,
|
2015-04-08 00:49:00 +03:00
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
nsISupports* aCacheKey,
|
|
|
|
nsContentPolicyType aContentPolicyType,
|
|
|
|
const nsAString& initiatorType,
|
|
|
|
imgRequestProxy** _retval)
|
2012-10-12 16:43:01 +04:00
|
|
|
{
|
2014-08-20 01:49:38 +04:00
|
|
|
VerifyCacheSizes();
|
2004-05-06 01:17:31 +04:00
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
NS_ASSERTION(aURI, "imgLoader::LoadImage -- NULL URI pointer");
|
2008-09-04 20:36:27 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (!aURI) {
|
2001-03-30 05:59:03 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2001-03-30 05:59:03 +04:00
|
|
|
|
2016-08-26 09:02:31 +03:00
|
|
|
LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::LoadImage", "aURI",
|
|
|
|
aURI->GetSpecOrDefault().get());
|
2001-02-23 11:36:51 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> request;
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2001-10-17 09:57:29 +04:00
|
|
|
nsresult rv;
|
2002-09-19 02:08:12 +04:00
|
|
|
nsLoadFlags requestFlags = nsIRequest::LOAD_NORMAL;
|
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool isPrivate = false;
|
|
|
|
|
2012-11-04 07:04:07 +04:00
|
|
|
if (aLoadGroup) {
|
2012-06-26 08:20:12 +04: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-19 02:08:12 +04: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-05 03:00:42 +04:00
|
|
|
// The flags in aLoadFlags take precedence over the default flags!
|
2002-09-19 02:08:12 +04: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 19:56:38 +04:00
|
|
|
int32_t corsmode = imgIRequest::CORS_NONE;
|
2011-07-14 22:47:34 +04: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 08:24:48 +03:00
|
|
|
RefPtr<imgCacheEntry> entry;
|
2001-07-17 05:14:40 +04:00
|
|
|
|
2009-11-13 02:00:30 +03: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-08-04 21:22:00 +03:00
|
|
|
PrincipalOriginAttributes attrs;
|
|
|
|
if (aLoadingPrincipal) {
|
|
|
|
attrs = BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef();
|
|
|
|
}
|
2016-08-29 08:34:32 +03:00
|
|
|
ImageCacheKey key(aURI, attrs, aLoadingDocument, rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheTable& cache = GetCache(key);
|
2008-12-12 03:47:47 +03:00
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
if (cache.Get(key, getter_AddRefs(entry)) && entry) {
|
2010-05-21 00:08:02 +04:00
|
|
|
if (ValidateEntry(entry, aURI, aInitialDocumentURI, aReferrerURI,
|
2016-04-11 11:58:03 +03:00
|
|
|
aReferrerPolicy, aLoadGroup, aObserver, aLoadingDocument,
|
2014-11-18 16:46:53 +03:00
|
|
|
requestFlags, aContentPolicyType, true, _retval,
|
2014-08-20 01:49:38 +04:00
|
|
|
aLoadingPrincipal, corsmode)) {
|
2013-07-10 13:56:21 +04:00
|
|
|
request = entry->GetRequest();
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
// If this entry has no proxies, its request has no reference to the
|
|
|
|
// entry.
|
2009-11-13 02:00:30 +03:00
|
|
|
if (entry->HasNoProxies()) {
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog,
|
2015-04-28 21:45:45 +03:00
|
|
|
"imgLoader::LoadImage() adding proxyless entry", "uri", key.Spec());
|
2015-04-08 00:49:00 +03:00
|
|
|
MOZ_ASSERT(!request->HasCacheEntry(),
|
|
|
|
"Proxyless entry's request has cache entry!");
|
2009-11-13 02:00:30 +03:00
|
|
|
request->SetCacheEntry(entry);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (mCacheTracker) {
|
2012-06-26 08:20:12 +04:00
|
|
|
mCacheTracker->MarkUsed(entry);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2013-03-30 00:14:19 +04:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2009-11-13 02:00:30 +03:00
|
|
|
entry->Touch();
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
} else {
|
2009-11-13 02:00:30 +03: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 18:20:58 +04:00
|
|
|
entry = nullptr;
|
2001-03-06 07:46:20 +03:00
|
|
|
}
|
2001-10-17 09:57:29 +04:00
|
|
|
}
|
|
|
|
|
2009-07-28 20:13:48 +04:00
|
|
|
// Keep the channel in this scope, so we can adjust its notificationCallbacks
|
|
|
|
// later when we create the proxy.
|
|
|
|
nsCOMPtr<nsIChannel> newChannel;
|
2008-09-05 03:00:42 +04:00
|
|
|
// If we didn't get a cache hit, we need to load from the network.
|
|
|
|
if (!request) {
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE(gImgLog, "imgLoader::LoadImage |cache miss|");
|
2001-02-23 11:36:51 +03:00
|
|
|
|
2011-09-21 01:00:42 +04:00
|
|
|
bool forcePrincipalCheck;
|
2002-09-19 02:08:12 +04:00
|
|
|
rv = NewImageChannel(getter_AddRefs(newChannel),
|
2011-09-21 01:00:42 +04:00
|
|
|
&forcePrincipalCheck,
|
2002-09-19 02:08:12 +04:00
|
|
|
aURI,
|
|
|
|
aInitialDocumentURI,
|
2016-04-27 20:40:56 +03:00
|
|
|
corsmode,
|
2002-09-19 02:08:12 +04:00
|
|
|
aReferrerURI,
|
2014-11-18 16:46:53 +03:00
|
|
|
aReferrerPolicy,
|
2002-09-19 02:08:12 +04:00
|
|
|
aLoadGroup,
|
2009-07-15 11:22:40 +04:00
|
|
|
mAcceptHeader,
|
2010-05-21 00:08:02 +04:00
|
|
|
requestFlags,
|
2014-08-20 01:49:38 +04:00
|
|
|
aContentPolicyType,
|
2014-09-21 20:45:34 +04:00
|
|
|
aLoadingPrincipal,
|
2016-04-13 16:34:36 +03:00
|
|
|
aContext,
|
|
|
|
mRespectPrivacy);
|
2015-04-08 00:49:00 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2002-09-19 02:08:12 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2012-10-04 02:43:26 +04:00
|
|
|
MOZ_ASSERT(NS_UsePrivateBrowsing(newChannel) == mRespectPrivacy);
|
2012-06-26 08:20:12 +04:00
|
|
|
|
2015-05-20 20:21:13 +03:00
|
|
|
NewRequestAndEntry(forcePrincipalCheck, this, key,
|
|
|
|
getter_AddRefs(request),
|
2015-04-08 00:49:00 +03:00
|
|
|
getter_AddRefs(entry));
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2015-04-08 00:49:00 +03:00
|
|
|
("[this=%p] imgLoader::LoadImage -- Created new imgRequest"
|
|
|
|
" [request=%p]\n", this, request.get()));
|
2001-03-20 00:57:39 +03:00
|
|
|
|
2014-01-30 07:35:40 +04:00
|
|
|
nsCOMPtr<nsILoadGroup> channelLoadGroup;
|
|
|
|
newChannel->GetLoadGroup(getter_AddRefs(channelLoadGroup));
|
2016-08-29 08:34:32 +03:00
|
|
|
rv = request->Init(aURI, aURI, /* aHadInsecureRedirect = */ false,
|
|
|
|
channelLoadGroup, newChannel, entry, aLoadingDocument,
|
|
|
|
aLoadingPrincipal, corsmode, aReferrerPolicy);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2013-10-16 05:35:44 +04: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 06:42:56 +04:00
|
|
|
// create the proxy listener
|
2016-04-27 20:40:56 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> listener = new ProxyListener(request.get());
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2016-04-27 20:40:56 +03:00
|
|
|
("[this=%p] imgLoader::LoadImage -- Calling channel->AsyncOpen2()\n",
|
2015-04-08 00:49:00 +03:00
|
|
|
this));
|
2002-03-07 04:50:14 +03:00
|
|
|
|
2014-06-04 00:37:46 +04:00
|
|
|
mozilla::net::PredictorLearn(aURI, aInitialDocumentURI,
|
|
|
|
nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE, aLoadGroup);
|
2013-10-26 01:56:58 +04:00
|
|
|
|
2016-04-27 20:40:56 +03:00
|
|
|
nsresult openRes = newChannel->AsyncOpen2(listener);
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
|
2002-09-19 02:08:12 +04:00
|
|
|
if (NS_FAILED(openRes)) {
|
2015-11-16 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2016-04-27 20:40:56 +03:00
|
|
|
("[this=%p] imgLoader::LoadImage -- AsyncOpen2() failed: 0x%x\n",
|
2005-02-16 18:26:04 +03:00
|
|
|
this, openRes));
|
2008-12-23 01:20:46 +03:00
|
|
|
request->CancelAndAbort(openRes);
|
2002-09-19 02:08:12 +04: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 06:42:56 +04:00
|
|
|
}
|
2001-02-23 11:36:51 +03:00
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
// Try to add the new request into the cache.
|
2015-04-28 21:45:45 +03:00
|
|
|
PutIntoCache(key, entry);
|
2001-02-23 11:36:51 +03:00
|
|
|
} else {
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_MSG_WITH_PARAM(gImgLog,
|
2002-09-19 02:08:12 +04:00
|
|
|
"imgLoader::LoadImage |cache hit|", "request", request);
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2009-11-13 02:00:30 +03:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
// If we didn't get a proxy when validating the cache entry, we need to
|
|
|
|
// create one.
|
2008-09-05 03:00:42 +04:00
|
|
|
if (!*_retval) {
|
2009-11-13 02:00:30 +03: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 11:58:03 +03:00
|
|
|
request->SetLoadId(aLoadingDocument);
|
2003-05-14 09:42:06 +04:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_MSG(gImgLog, "imgLoader::LoadImage", "creating proxy request.");
|
2008-09-05 03:00:42 +04:00
|
|
|
rv = CreateNewProxyForRequest(request, aLoadGroup, aObserver,
|
2012-11-04 07:04:07 +04:00
|
|
|
requestFlags, _retval);
|
2010-05-25 18:34:04 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
imgRequestProxy* proxy = *_retval;
|
2003-05-14 09:42:06 +04:00
|
|
|
|
2009-07-28 20:13:48 +04: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-08 00:49:00 +03:00
|
|
|
if (!requestor) {
|
2009-07-28 20:13:48 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2009-07-28 20:13:48 +04:00
|
|
|
newChannel->SetNotificationCallbacks(requestor);
|
|
|
|
}
|
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
// Note that it's OK to add here even if the request is done. If it is,
|
2010-05-11 07:27:41 +04:00
|
|
|
// it'll send a OnStopRequest() to the proxy in imgRequestProxy::Notify and
|
|
|
|
// the proxy will be removed from the loadgroup.
|
2008-09-05 03:00:42 +04:00
|
|
|
proxy->AddToLoadGroup();
|
2008-09-04 19:23:16 +04:00
|
|
|
|
2010-07-29 01:52:14 +04: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-08 00:49:00 +03:00
|
|
|
if (!newChannel) {
|
2010-07-29 01:52:14 +04:00
|
|
|
proxy->NotifyListener();
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
|
|
|
return rv;
|
2003-05-14 09:42:06 +04:00
|
|
|
}
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
NS_ASSERTION(*_retval, "imgLoader::LoadImage -- no return value");
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
return NS_OK;
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgLoader::LoadImageWithChannelXPCOM(nsIChannel* channel,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsISupports* aCX,
|
|
|
|
nsIStreamListener** listener,
|
|
|
|
imgIRequest** _retval)
|
2012-10-12 16:43:01 +04:00
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
imgRequestProxy* proxy;
|
|
|
|
result = LoadImageWithChannel(channel,
|
|
|
|
aObserver,
|
|
|
|
aCX,
|
|
|
|
listener,
|
|
|
|
&proxy);
|
|
|
|
*_retval = proxy;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsresult
|
|
|
|
imgLoader::LoadImageWithChannel(nsIChannel* channel,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsISupports* aCX,
|
|
|
|
nsIStreamListener** listener,
|
|
|
|
imgRequestProxy** _retval)
|
2001-02-21 01:43:56 +03:00
|
|
|
{
|
2015-04-08 00:49:00 +03:00
|
|
|
NS_ASSERTION(channel,
|
|
|
|
"imgLoader::LoadImageWithChannel -- NULL channel pointer");
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2012-10-04 02:43:26 +04:00
|
|
|
MOZ_ASSERT(NS_UsePrivateBrowsing(channel) == mRespectPrivacy);
|
2012-06-26 08:20:12 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> request;
|
2001-02-21 01:43:56 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2003-03-26 08:29:11 +03:00
|
|
|
channel->GetURI(getter_AddRefs(uri));
|
2016-04-11 12:00:03 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aCX);
|
2016-08-04 21:22:00 +03:00
|
|
|
|
|
|
|
NS_ENSURE_TRUE(channel, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
|
|
|
|
|
|
|
PrincipalOriginAttributes attrs;
|
|
|
|
if (loadInfo) {
|
|
|
|
attrs.InheritFromNecko(loadInfo->GetOriginAttributes());
|
|
|
|
}
|
|
|
|
|
2016-08-29 08:34:32 +03:00
|
|
|
nsresult rv;
|
|
|
|
ImageCacheKey key(uri, attrs, doc, rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2002-09-19 02:08:12 +04:00
|
|
|
nsLoadFlags requestFlags = nsIRequest::LOAD_NORMAL;
|
|
|
|
channel->GetLoadFlags(&requestFlags);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgCacheEntry> entry;
|
2002-09-19 02:08:12 +04:00
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
if (requestFlags & nsIRequest::LOAD_BYPASS_CACHE) {
|
2015-04-28 21:45:45 +03:00
|
|
|
RemoveFromCache(key);
|
2008-09-05 03:00:42 +04: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 21:45:45 +03:00
|
|
|
imgCacheTable& cache = GetCache(key);
|
|
|
|
if (cache.Get(key, getter_AddRefs(entry)) && entry) {
|
2008-09-05 03:00:42 +04: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-20 01:49:38 +04:00
|
|
|
//
|
|
|
|
// Since aCanMakeNewChannel == false, we don't need to pass content policy
|
|
|
|
// type/principal/etc
|
2016-04-27 20:40:56 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
|
|
|
// if there is a loadInfo, use the right contentType, otherwise
|
|
|
|
// default to the internal image type
|
|
|
|
nsContentPolicyType policyType = loadInfo
|
|
|
|
? loadInfo->InternalContentPolicyType()
|
|
|
|
: nsIContentPolicy::TYPE_INTERNAL_IMAGE;
|
|
|
|
|
2014-11-18 16:46:53 +03:00
|
|
|
if (ValidateEntry(entry, uri, nullptr, nullptr, RP_Default,
|
|
|
|
nullptr, aObserver, aCX, requestFlags,
|
2016-04-27 20:40:56 +03:00
|
|
|
policyType, false, nullptr,
|
2014-08-20 01:49:38 +04:00
|
|
|
nullptr, imgIRequest::CORS_NONE)) {
|
2013-07-10 13:56:21 +04:00
|
|
|
request = entry->GetRequest();
|
2003-04-10 05:01:31 +04:00
|
|
|
} else {
|
2015-11-12 23:09:52 +03:00
|
|
|
nsCOMPtr<nsICacheInfoChannel> cacheChan(do_QueryInterface(channel));
|
2011-09-29 10:19:26 +04:00
|
|
|
bool bUseCacheCopy;
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (cacheChan) {
|
2008-09-05 03:00:42 +04:00
|
|
|
cacheChan->IsFromCache(&bUseCacheCopy);
|
2015-04-08 00:49:00 +03:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
bUseCacheCopy = false;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2013-07-10 13:56:21 +04:00
|
|
|
if (!bUseCacheCopy) {
|
2012-07-30 18:20:58 +04:00
|
|
|
entry = nullptr;
|
2013-07-10 13:56:21 +04:00
|
|
|
} else {
|
|
|
|
request = entry->GetRequest();
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
2002-09-19 02:08:12 +04:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
|
|
|
|
if (request && entry) {
|
2015-04-08 00:49:00 +03:00
|
|
|
// If this entry has no proxies, its request has no reference to
|
|
|
|
// the entry.
|
2009-01-31 05:17:47 +03:00
|
|
|
if (entry->HasNoProxies()) {
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog,
|
2015-04-08 00:49:00 +03:00
|
|
|
"imgLoader::LoadImageWithChannel() adding proxyless entry",
|
2015-04-28 21:45:45 +03:00
|
|
|
"uri", key.Spec());
|
2015-04-08 00:49:00 +03:00
|
|
|
MOZ_ASSERT(!request->HasCacheEntry(),
|
|
|
|
"Proxyless entry's request has cache entry!");
|
2009-01-31 05:17:47 +03:00
|
|
|
request->SetCacheEntry(entry);
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (mCacheTracker) {
|
2012-06-26 08:20:12 +04:00
|
|
|
mCacheTracker->MarkUsed(entry);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2013-03-30 00:14:19 +04:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
}
|
2002-09-19 02:08:12 +04:00
|
|
|
}
|
|
|
|
}
|
2001-05-08 08:21:49 +04:00
|
|
|
|
2002-01-15 08:23:33 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
channel->GetLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
|
2011-06-09 23:03:41 +04:00
|
|
|
// Filter out any load flags not from nsIRequest
|
|
|
|
requestFlags &= nsIRequest::LOAD_REQUESTMASK;
|
2010-07-29 01:52:14 +04:00
|
|
|
|
2016-08-29 08:34:32 +03:00
|
|
|
rv = NS_OK;
|
2001-02-21 02:35:22 +03:00
|
|
|
if (request) {
|
2001-02-21 01:43:56 +03:00
|
|
|
// we have this in our cache already.. cancel the current (document) load
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
// this should fire an OnStopRequest
|
|
|
|
channel->Cancel(NS_ERROR_PARSED_DATA_CACHED);
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*listener = nullptr; // give them back a null nsIStreamListener
|
2010-07-29 01:52:14 +04:00
|
|
|
|
|
|
|
rv = CreateNewProxyForRequest(request, loadGroup, aObserver,
|
2012-11-04 07:04:07 +04:00
|
|
|
requestFlags, _retval);
|
2010-07-29 01:52:14 +04:00
|
|
|
static_cast<imgRequestProxy*>(*_retval)->NotifyListener();
|
2001-02-21 01:43:56 +03:00
|
|
|
} else {
|
2015-05-20 20:21:13 +03: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.
|
2016-08-29 08:34:32 +03:00
|
|
|
ImageCacheKey originalURIKey(originalURI, attrs, doc, rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-05-20 20:21:13 +03:00
|
|
|
|
2011-09-21 01:00:42 +04: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 20:21:13 +03:00
|
|
|
NewRequestAndEntry(/* aForcePrincipalCheckForCacheEntry = */ true,
|
|
|
|
this, originalURIKey,
|
|
|
|
getter_AddRefs(request),
|
2015-04-08 00:49:00 +03:00
|
|
|
getter_AddRefs(entry));
|
2001-03-16 05:40:04 +03:00
|
|
|
|
2011-07-14 22:47:32 +04:00
|
|
|
// No principal specified here, because we're not passed one.
|
2014-12-16 04:40:43 +03: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.
|
2016-08-29 08:34:32 +03:00
|
|
|
rv = request->Init(originalURI, uri, /* aHadInsecureRedirect = */ false,
|
|
|
|
channel, channel, entry, aCX, nullptr,
|
|
|
|
imgIRequest::CORS_NONE, RP_Default);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProxyListener> pl =
|
2015-03-05 09:18:09 +03: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 06:42:56 +04:00
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
// Try to add the new request into the cache.
|
2015-05-20 20:21:13 +03:00
|
|
|
PutIntoCache(originalURIKey, entry);
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2010-07-29 01:52:14 +04:00
|
|
|
rv = CreateNewProxyForRequest(request, loadGroup, aObserver,
|
2012-11-04 07:04:07 +04:00
|
|
|
requestFlags, _retval);
|
2002-09-19 02:08:12 +04:00
|
|
|
|
2010-07-29 01:52:14 +04: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 06:42:56 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-12-05 22:33:08 +03:00
|
|
|
bool
|
|
|
|
imgLoader::SupportImageWithMimeType(const char* aMimeType,
|
|
|
|
AcceptedMimeTypes aAccept
|
|
|
|
/* = AcceptedMimeTypes::IMAGES */)
|
2002-03-23 16:21:33 +03:00
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString mimeType(aMimeType);
|
2002-04-02 01:14:07 +04:00
|
|
|
ToLowerCase(mimeType);
|
2014-12-05 22:33:08 +03:00
|
|
|
|
|
|
|
if (aAccept == AcceptedMimeTypes::IMAGES_AND_DOCUMENTS &&
|
|
|
|
mimeType.EqualsLiteral("image/svg+xml")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-23 08:39:48 +03:00
|
|
|
DecoderType type = DecoderFactory::GetDecoderType(mimeType.get());
|
|
|
|
return type != DecoderType::UNKNOWN;
|
2002-03-23 16:21:33 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgLoader::GetMIMETypeFromContent(nsIRequest* aRequest,
|
|
|
|
const uint8_t* aContents,
|
|
|
|
uint32_t aLength,
|
|
|
|
nsACString& aContentType)
|
2002-05-25 00:54:44 +04:00
|
|
|
{
|
2004-07-19 22:53:02 +04:00
|
|
|
return GetMimeTypeFromContent((const char*)aContents, aLength, aContentType);
|
2002-05-25 00:54:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2015-04-08 00:49:00 +03:00
|
|
|
nsresult
|
|
|
|
imgLoader::GetMimeTypeFromContent(const char* aContents,
|
|
|
|
uint32_t aLength,
|
|
|
|
nsACString& aContentType)
|
2002-03-23 16:21:33 +03:00
|
|
|
{
|
|
|
|
/* Is it a GIF? */
|
2009-04-06 04:30:03 +04:00
|
|
|
if (aLength >= 6 && (!nsCRT::strncmp(aContents, "GIF87a", 6) ||
|
2015-04-08 00:49:00 +03:00
|
|
|
!nsCRT::strncmp(aContents, "GIF89a", 6))) {
|
2013-01-09 01:40:47 +04:00
|
|
|
aContentType.AssignLiteral(IMAGE_GIF);
|
2002-03-23 16:21:33 +03:00
|
|
|
|
|
|
|
/* or a PNG? */
|
2015-04-08 00:49:00 +03: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-09 01:40:47 +04:00
|
|
|
aContentType.AssignLiteral(IMAGE_PNG);
|
2002-03-23 16:21:33 +03: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-08 00:49:00 +03:00
|
|
|
} else if (aLength >= 3 &&
|
|
|
|
((unsigned char)aContents[0])==0xFF &&
|
|
|
|
((unsigned char)aContents[1])==0xD8 &&
|
|
|
|
((unsigned char)aContents[2])==0xFF) {
|
2013-01-09 01:40:47 +04:00
|
|
|
aContentType.AssignLiteral(IMAGE_JPEG);
|
2002-03-23 16:21:33 +03:00
|
|
|
|
|
|
|
/* or how about ART? */
|
|
|
|
/* ART begins with JG (4A 47). Major version offset 2.
|
2013-08-23 23:51:00 +04:00
|
|
|
* Minor version offset 3. Offset 4 must be nullptr.
|
2002-03-23 16:21:33 +03:00
|
|
|
*/
|
2015-04-08 00:49:00 +03:00
|
|
|
} else if (aLength >= 5 &&
|
|
|
|
((unsigned char) aContents[0])==0x4a &&
|
|
|
|
((unsigned char) aContents[1])==0x47 &&
|
|
|
|
((unsigned char) aContents[4])==0x00 ) {
|
2013-01-09 01:40:47 +04:00
|
|
|
aContentType.AssignLiteral(IMAGE_ART);
|
2002-03-23 16:21:33 +03:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
} else if (aLength >= 2 && !nsCRT::strncmp(aContents, "BM", 2)) {
|
2013-01-09 01:40:47 +04:00
|
|
|
aContentType.AssignLiteral(IMAGE_BMP);
|
2002-03-23 16:21:33 +03:00
|
|
|
|
|
|
|
// ICOs always begin with a 2-byte 0 followed by a 2-byte 1.
|
2005-01-12 23:16:07 +03:00
|
|
|
// CURs begin with 2-byte 0 followed by 2-byte 2.
|
2015-04-08 00:49:00 +03:00
|
|
|
} else if (aLength >= 4 && (!memcmp(aContents, "\000\000\001\000", 4) ||
|
|
|
|
!memcmp(aContents, "\000\000\002\000", 4))) {
|
2013-01-09 01:40:47 +04:00
|
|
|
aContentType.AssignLiteral(IMAGE_ICO);
|
2002-03-23 16:21:33 +03:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
} else {
|
2002-06-12 02:40:29 +04:00
|
|
|
/* none of the above? I give up */
|
2004-07-19 22:53:02 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2002-06-04 12:48:12 +04:00
|
|
|
}
|
|
|
|
|
2004-07-19 22:53:02 +04:00
|
|
|
return NS_OK;
|
2002-03-23 16:21:33 +03:00
|
|
|
}
|
|
|
|
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
/**
|
|
|
|
* proxy stream listener class used to handle multipart/x-mixed-replace
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsIRequest.h"
|
|
|
|
#include "nsIStreamConverterService.h"
|
|
|
|
|
2014-04-27 11:06:00 +04: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 06:42:56 +04:00
|
|
|
|
2015-04-08 00:49:00 +03: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 06:42:56 +04:00
|
|
|
mDestListener(dest)
|
|
|
|
{
|
|
|
|
/* member initializers and constructor code */
|
|
|
|
}
|
|
|
|
|
|
|
|
ProxyListener::~ProxyListener()
|
|
|
|
{
|
|
|
|
/* destructor code */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** nsIRequestObserver methods **/
|
|
|
|
|
2015-04-08 00:49:00 +03: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 06:42:56 +04:00
|
|
|
{
|
2015-04-08 00:49:00 +03: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 06:42:56 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
|
|
|
if (channel) {
|
2014-10-29 18:35:05 +03: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 06:35:17 +04:00
|
|
|
nsAutoCString contentType;
|
2002-03-21 01:50:33 +03: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 06:42:56 +04:00
|
|
|
|
2002-03-21 01:50:33 +03: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 06:42:56 +04: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 08:23:33 +03: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 06:42:56 +04:00
|
|
|
|
2015-04-08 00:49:00 +03: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 06:42:56 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIStreamListener> toListener(mDestListener);
|
|
|
|
nsCOMPtr<nsIStreamListener> fromListener;
|
|
|
|
|
2004-06-29 20:45:07 +04: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 06:42:56 +04:00
|
|
|
toListener,
|
2012-07-30 18:20:58 +04: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 06:42:56 +04:00
|
|
|
getter_AddRefs(fromListener));
|
2015-04-08 00:49:00 +03: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 06:42:56 +04:00
|
|
|
mDestListener = fromListener;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mDestListener->OnStartRequest(aRequest, ctxt);
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03: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 06:42:56 +04:00
|
|
|
{
|
2015-04-08 00:49:00 +03: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 06:42:56 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
|
|
|
|
return mDestListener->OnStopRequest(aRequest, ctxt, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** nsIStreamListener methods **/
|
|
|
|
|
2012-09-06 06:41:02 +04:00
|
|
|
NS_IMETHODIMP
|
2015-04-08 00:49:00 +03:00
|
|
|
ProxyListener::OnDataAvailable(nsIRequest* aRequest, nsISupports* ctxt,
|
|
|
|
nsIInputStream* inStr, uint64_t sourceOffset,
|
2012-09-06 06:41:02 +04: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 06:42:56 +04:00
|
|
|
{
|
2015-04-08 00:49:00 +03: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 06:42:56 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
|
2015-04-08 00:49:00 +03: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 06:42:56 +04:00
|
|
|
}
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2013-09-28 22:28:42 +04: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 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2013-09-28 22:28:42 +04:00
|
|
|
("ProxyListener::CheckListenerChain %s [this=%p listener=%p rv=%x]",
|
|
|
|
(NS_SUCCEEDED(rv) ? "success" : "failure"),
|
|
|
|
this, (nsIStreamListener*)mDestListener, rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-01-15 08:23:33 +03:00
|
|
|
/**
|
|
|
|
* http validate class. check a channel for a 304
|
|
|
|
*/
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(imgCacheValidator, nsIStreamListener, nsIRequestObserver,
|
|
|
|
nsIThreadRetargetableStreamListener,
|
|
|
|
nsIChannelEventSink, nsIInterfaceRequestor,
|
|
|
|
nsIAsyncVerifyRedirectCallback)
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2011-07-01 21:03:38 +04:00
|
|
|
imgCacheValidator::imgCacheValidator(nsProgressNotificationProxy* progress,
|
2015-04-08 00:49:00 +03:00
|
|
|
imgLoader* loader, imgRequest* request,
|
2015-03-24 05:37:45 +03:00
|
|
|
nsISupports* aContext,
|
|
|
|
bool forcePrincipalCheckForCacheEntry)
|
2011-07-01 21:03:38 +04:00
|
|
|
: mProgressProxy(progress),
|
|
|
|
mRequest(request),
|
2012-06-26 08:20:12 +04:00
|
|
|
mContext(aContext),
|
2014-12-16 04:40:43 +03:00
|
|
|
mImgLoader(loader),
|
|
|
|
mHadInsecureRedirect(false)
|
2011-07-01 21:03:38 +04:00
|
|
|
{
|
2015-04-08 00:49:00 +03:00
|
|
|
NewRequestAndEntry(forcePrincipalCheckForCacheEntry, loader,
|
2015-05-20 20:21:13 +03:00
|
|
|
mRequest->CacheKey(),
|
2015-04-08 00:49:00 +03:00
|
|
|
getter_AddRefs(mNewRequest),
|
2012-06-26 08:20:12 +04:00
|
|
|
getter_AddRefs(mNewEntry));
|
2011-07-01 21:03:38 +04:00
|
|
|
}
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2002-12-24 17:30:12 +03:00
|
|
|
imgCacheValidator::~imgCacheValidator()
|
2002-01-15 08:23:33 +03:00
|
|
|
{
|
2003-04-02 07:19:50 +04:00
|
|
|
if (mRequest) {
|
2015-03-24 05:37:45 +03:00
|
|
|
mRequest->SetValidator(nullptr);
|
2003-04-02 07:19:50 +04:00
|
|
|
}
|
2002-01-15 08:23:33 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void
|
|
|
|
imgCacheValidator::AddProxy(imgRequestProxy* aProxy)
|
2002-01-15 08:23:33 +03:00
|
|
|
{
|
2003-05-14 09:42:06 +04:00
|
|
|
// aProxy needs to be in the loadgroup since we're validating from
|
|
|
|
// the network.
|
|
|
|
aProxy->AddToLoadGroup();
|
|
|
|
|
2005-06-01 22:28:20 +04:00
|
|
|
mProxies.AppendObject(aProxy);
|
2002-01-15 08:23:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** nsIRequestObserver methods **/
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgCacheValidator::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
|
2002-01-15 08:23:33 +03:00
|
|
|
{
|
2015-04-07 20:02:02 +03:00
|
|
|
// We may be holding on to a document, so ensure that it's released.
|
|
|
|
nsCOMPtr<nsISupports> context = mContext.forget();
|
|
|
|
|
2015-03-28 06:07:20 +03: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 21:03:42 +04: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 23:09:52 +03:00
|
|
|
nsCOMPtr<nsICacheInfoChannel> cacheChan(do_QueryInterface(aRequest));
|
2011-07-01 21:03:42 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
2012-11-08 22:54:00 +04:00
|
|
|
if (cacheChan && channel && !mRequest->CacheChanged(aRequest)) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isFromCache = false;
|
2011-07-01 21:03:42 +04:00
|
|
|
cacheChan->IsFromCache(&isFromCache);
|
2011-07-01 05:58:34 +04:00
|
|
|
|
2011-07-01 21:03:42 +04:00
|
|
|
nsCOMPtr<nsIURI> channelURI;
|
|
|
|
channel->GetURI(getter_AddRefs(channelURI));
|
2015-03-24 05:37:45 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
|
|
|
mRequest->GetCurrentURI(getter_AddRefs(currentURI));
|
|
|
|
|
|
|
|
bool sameURI = false;
|
|
|
|
if (channelURI && currentURI) {
|
|
|
|
channelURI->Equals(currentURI, &sameURI);
|
|
|
|
}
|
2011-07-01 21:03:42 +04:00
|
|
|
|
|
|
|
if (isFromCache && sameURI) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mProxies.Count();
|
|
|
|
for (int32_t i = count-1; i>=0; i--) {
|
2015-04-08 00:49:00 +03:00
|
|
|
imgRequestProxy* proxy = static_cast<imgRequestProxy*>(mProxies[i]);
|
2010-07-29 01:52:14 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
// Proxies waiting on cache validation should be deferring
|
|
|
|
// notifications. Undefer them.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(proxy->NotificationsDeferred(),
|
|
|
|
"Proxies waiting on cache validation should be "
|
|
|
|
"deferring notifications!");
|
2011-10-17 18:59:28 +04:00
|
|
|
proxy->SetNotificationsDeferred(false);
|
2010-08-02 23:44:49 +04:00
|
|
|
|
2010-07-29 01:52:14 +04:00
|
|
|
// Notify synchronously, because we're already in OnStartRequest, an
|
|
|
|
// asynchronously-called function.
|
|
|
|
proxy->SyncNotifyListener();
|
2002-01-15 08:23:33 +03:00
|
|
|
}
|
|
|
|
|
2011-07-01 21:03:42 +04:00
|
|
|
// We don't need to load this any more.
|
|
|
|
aRequest->Cancel(NS_BINDING_ABORTED);
|
|
|
|
|
2015-04-07 20:02:02 +03:00
|
|
|
mRequest->SetLoadId(context);
|
2015-03-24 05:37:45 +03:00
|
|
|
mRequest->SetValidator(nullptr);
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mRequest = nullptr;
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mNewRequest = nullptr;
|
|
|
|
mNewEntry = nullptr;
|
2011-07-01 21:03:38 +04:00
|
|
|
|
2002-01-15 08:23:33 +03:00
|
|
|
return NS_OK;
|
2002-12-24 17:30:12 +03:00
|
|
|
}
|
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2009-01-31 05:17:47 +03: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 17:30:12 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2013-09-28 22:28:42 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageURL> imageURL;
|
2013-09-28 22:28:42 +04:00
|
|
|
mRequest->GetURI(getter_AddRefs(imageURL));
|
|
|
|
uri = imageURL->ToIURI();
|
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
|
|
|
LOG_MSG_WITH_PARAM(gImgLog,
|
2015-05-11 23:42:30 +03:00
|
|
|
"imgCacheValidator::OnStartRequest creating new request",
|
2016-08-26 09:02:31 +03:00
|
|
|
"uri", uri->GetSpecOrDefault().get());
|
2015-05-11 23:42:30 +03:00
|
|
|
}
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t corsmode = mRequest->GetCORSMode();
|
2014-11-18 16:46:53 +03:00
|
|
|
ReferrerPolicy refpol = mRequest->GetReferrerPolicy();
|
2011-07-14 22:47:32 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> loadingPrincipal = mRequest->GetLoadingPrincipal();
|
|
|
|
|
2002-12-24 17:30:12 +03:00
|
|
|
// Doom the old request's cache entry
|
2003-06-24 02:55:17 +04:00
|
|
|
mRequest->RemoveFromCache();
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
mRequest->SetValidator(nullptr);
|
2012-07-30 18:20:58 +04:00
|
|
|
mRequest = nullptr;
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2008-12-23 01:20:46 +03:00
|
|
|
// We use originalURI here to fulfil the imgIRequest contract on GetURI.
|
2006-03-11 23:32:47 +03:00
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
channel->GetOriginalURI(getter_AddRefs(originalURI));
|
2016-08-29 08:34:32 +03:00
|
|
|
nsresult rv =
|
|
|
|
mNewRequest->Init(originalURI, uri, mHadInsecureRedirect, aRequest, channel,
|
|
|
|
mNewEntry, context, loadingPrincipal, corsmode, refpol);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2011-07-14 22:47:34 +04:00
|
|
|
mDestListener = new ProxyListener(mNewRequest);
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2009-01-31 05:17:47 +03: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 20:21:13 +03:00
|
|
|
mImgLoader->PutIntoCache(mNewRequest->CacheKey(), mNewEntry);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mProxies.Count();
|
|
|
|
for (int32_t i = count-1; i>=0; i--) {
|
2015-04-08 00:49:00 +03:00
|
|
|
imgRequestProxy* proxy = static_cast<imgRequestProxy*>(mProxies[i]);
|
2011-07-01 21:03:38 +04:00
|
|
|
proxy->ChangeOwner(mNewRequest);
|
2010-07-29 01:52:14 +04:00
|
|
|
|
|
|
|
// Notify synchronously, because we're already in OnStartRequest, an
|
|
|
|
// asynchronously-called function.
|
2012-10-22 20:44:53 +04:00
|
|
|
proxy->SetNotificationsDeferred(false);
|
2010-07-29 01:52:14 +04:00
|
|
|
proxy->SyncNotifyListener();
|
2002-01-15 08:23:33 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mNewRequest = nullptr;
|
|
|
|
mNewEntry = nullptr;
|
2002-01-15 08:23:33 +03:00
|
|
|
|
|
|
|
return mDestListener->OnStartRequest(aRequest, ctxt);
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgCacheValidator::OnStopRequest(nsIRequest* aRequest,
|
|
|
|
nsISupports* ctxt,
|
|
|
|
nsresult status)
|
2002-01-15 08:23:33 +03:00
|
|
|
{
|
2015-04-07 20:02:02 +03:00
|
|
|
// Be sure we've released the document that we may have been holding on to.
|
|
|
|
mContext = nullptr;
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
if (!mDestListener) {
|
2002-01-15 08:23:33 +03:00
|
|
|
return NS_OK;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2002-01-15 08:23:33 +03:00
|
|
|
|
|
|
|
return mDestListener->OnStopRequest(aRequest, ctxt, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** nsIStreamListener methods **/
|
|
|
|
|
|
|
|
|
2012-09-06 06:41:02 +04:00
|
|
|
NS_IMETHODIMP
|
2015-04-08 00:49:00 +03:00
|
|
|
imgCacheValidator::OnDataAvailable(nsIRequest* aRequest, nsISupports* ctxt,
|
|
|
|
nsIInputStream* inStr,
|
2012-09-06 06:41:02 +04:00
|
|
|
uint64_t sourceOffset, uint32_t count)
|
2002-01-15 08:23:33 +03:00
|
|
|
{
|
|
|
|
if (!mDestListener) {
|
|
|
|
// XXX see bug 113959
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t _retval;
|
2012-07-30 18:20:58 +04:00
|
|
|
inStr->ReadSegments(NS_DiscardSegment, nullptr, count, &_retval);
|
2002-01-15 08:23:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
return mDestListener->OnDataAvailable(aRequest, ctxt, inStr, sourceOffset,
|
|
|
|
count);
|
2002-01-15 08:23:33 +03:00
|
|
|
}
|
2011-07-01 21:03:38 +04:00
|
|
|
|
2013-09-28 22:28:42 +04: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 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Debug,
|
2013-09-28 22:28:42 +04:00
|
|
|
("[this=%p] imgCacheValidator::CheckListenerChain -- rv %d=%s",
|
|
|
|
this, NS_SUCCEEDED(rv) ? "succeeded" : "failed", rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-07-01 21:03:38 +04:00
|
|
|
/** nsIInterfaceRequestor methods **/
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgCacheValidator::GetInterface(const nsIID& aIID, void** aResult)
|
2011-07-01 21:03:38 +04:00
|
|
|
{
|
2015-04-08 00:49:00 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIChannelEventSink))) {
|
2011-07-01 21:03:38 +04:00
|
|
|
return QueryInterface(aIID, aResult);
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2011-07-01 21:03:38 +04: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-08 00:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgCacheValidator::
|
|
|
|
AsyncOnChannelRedirect(nsIChannel* oldChannel,
|
|
|
|
nsIChannel* newChannel,
|
|
|
|
uint32_t flags,
|
|
|
|
nsIAsyncVerifyRedirectCallback* callback)
|
2011-07-01 21:03:38 +04:00
|
|
|
{
|
|
|
|
// Note all cache information we get from the old channel.
|
|
|
|
mNewRequest->SetCacheValidation(mNewEntry, oldChannel);
|
|
|
|
|
2014-12-16 04:40:43 +03: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-08 00:49:00 +03:00
|
|
|
NS_FAILED(NS_URIChainHasFlags(oldURI,
|
|
|
|
nsIProtocolHandler::URI_IS_LOCAL_RESOURCE,
|
|
|
|
&schemeLocal)) ||
|
2014-12-16 04:40:43 +03:00
|
|
|
(!isHttps && !isChrome && !schemeLocal)) {
|
|
|
|
mHadInsecureRedirect = true;
|
|
|
|
}
|
|
|
|
|
2011-07-01 21:03:38 +04:00
|
|
|
// Prepare for callback
|
|
|
|
mRedirectCallback = callback;
|
|
|
|
mRedirectChannel = newChannel;
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
return mProgressProxy->AsyncOnChannelRedirect(oldChannel, newChannel, flags,
|
|
|
|
this);
|
2011-07-01 21:03:38 +04:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgCacheValidator::OnRedirectVerifyCallback(nsresult aResult)
|
2011-07-01 21:03:38 +04:00
|
|
|
{
|
|
|
|
// If we've already been told to abort, just do so.
|
|
|
|
if (NS_FAILED(aResult)) {
|
|
|
|
mRedirectCallback->OnRedirectVerifyCallback(aResult);
|
2012-07-30 18:20:58 +04:00
|
|
|
mRedirectCallback = nullptr;
|
|
|
|
mRedirectChannel = nullptr;
|
2011-07-01 21:03:38 +04: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 10:19:26 +04:00
|
|
|
bool doesNotReturnData = false;
|
2011-07-01 21:03:38 +04: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 18:20:58 +04:00
|
|
|
mRedirectCallback = nullptr;
|
|
|
|
mRedirectChannel = nullptr;
|
2011-07-01 21:03:38 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|