2001-01-23 01:01:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
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
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#ifndef mozilla_image_imgLoader_h
|
|
|
|
#define mozilla_image_imgLoader_h
|
2010-08-14 08:09:48 +04:00
|
|
|
|
2012-01-03 00:23:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-09-06 01:36:11 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2015-10-17 13:53:28 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2012-01-03 00:23:41 +04:00
|
|
|
|
2001-02-21 02:45:51 +03:00
|
|
|
#include "imgILoader.h"
|
2008-09-05 03:00:42 +04:00
|
|
|
#include "imgICache.h"
|
|
|
|
#include "nsWeakReference.h"
|
2004-07-19 22:53:02 +04:00
|
|
|
#include "nsIContentSniffer.h"
|
2008-09-05 03:00:42 +04:00
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsExpirationTracker.h"
|
2015-05-20 20:21:09 +03:00
|
|
|
#include "ImageCacheKey.h"
|
2008-09-05 03:00:42 +04:00
|
|
|
#include "imgRequest.h"
|
2011-07-01 21:03:38 +04:00
|
|
|
#include "nsIProgressEventSink.h"
|
|
|
|
#include "nsIChannel.h"
|
2013-09-28 22:28:42 +04:00
|
|
|
#include "nsIThreadRetargetableStreamListener.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
#include "imgIRequest.h"
|
2014-11-18 16:46:53 +03:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
class imgLoader;
|
2002-01-15 08:23:33 +03:00
|
|
|
class imgRequestProxy;
|
2012-10-12 20:11:22 +04:00
|
|
|
class imgINotificationObserver;
|
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
|
|
|
class nsILoadGroup;
|
2012-06-26 08:20:12 +04:00
|
|
|
class imgCacheExpirationTracker;
|
|
|
|
class imgMemoryReporter;
|
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
|
|
|
|
2013-09-28 22:28:42 +04:00
|
|
|
namespace mozilla {
|
2015-07-13 18:25:42 +03:00
|
|
|
namespace image {} // namespace image
|
|
|
|
} // namespace mozilla
|
2013-09-28 22:28:42 +04:00
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
class imgCacheEntry {
|
|
|
|
public:
|
2017-12-07 16:28:28 +03:00
|
|
|
static uint32_t SecondsFromPRTime(PRTime prTime);
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
imgCacheEntry(imgLoader* loader, imgRequest* request,
|
|
|
|
bool aForcePrincipalCheck);
|
2009-01-31 05:17:47 +03:00
|
|
|
~imgCacheEntry();
|
2008-09-05 03:00:42 +04:00
|
|
|
|
|
|
|
nsrefcnt AddRef() {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");
|
2017-04-26 18:41:32 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(imgCacheEntry);
|
2008-09-05 03:00:42 +04:00
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "imgCacheEntry", sizeof(*this));
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
2013-03-30 00:14:19 +04:00
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
nsrefcnt Release() {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(0 != mRefCnt, "dup release");
|
2017-04-26 18:41:32 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(imgCacheEntry);
|
2008-09-05 03:00:42 +04:00
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "imgCacheEntry");
|
|
|
|
if (mRefCnt == 0) {
|
|
|
|
mRefCnt = 1; /* stabilize */
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-30 00:14:19 +04:00
|
|
|
return mRefCnt;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetDataSize() const { return mDataSize; }
|
|
|
|
void SetDataSize(uint32_t aDataSize) {
|
|
|
|
int32_t oldsize = mDataSize;
|
2008-09-05 03:00:42 +04:00
|
|
|
mDataSize = aDataSize;
|
2009-09-13 02:44:18 +04:00
|
|
|
UpdateCache(mDataSize - oldsize);
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t GetTouchedTime() const { return mTouchedTime; }
|
|
|
|
void SetTouchedTime(int32_t time) {
|
2008-09-05 03:00:42 +04:00
|
|
|
mTouchedTime = time;
|
2011-10-17 18:59:28 +04:00
|
|
|
Touch(/* updateTime = */ false);
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2015-10-20 08:15:25 +03:00
|
|
|
uint32_t GetLoadTime() const { return mLoadTime; }
|
|
|
|
|
|
|
|
void UpdateLoadTime();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t GetExpiryTime() const { return mExpiryTime; }
|
|
|
|
void SetExpiryTime(int32_t aExpiryTime) {
|
2008-09-05 03:00:42 +04:00
|
|
|
mExpiryTime = aExpiryTime;
|
|
|
|
Touch();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetMustValidate() const { return mMustValidate; }
|
|
|
|
void SetMustValidate(bool aValidate) {
|
2011-07-01 21:03:35 +04:00
|
|
|
mMustValidate = aValidate;
|
2008-09-05 03:00:42 +04:00
|
|
|
Touch();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<imgRequest> GetRequest() const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> req = mRequest;
|
2013-04-22 15:15:59 +04:00
|
|
|
return req.forget();
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Evicted() const { return mEvicted; }
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsExpirationState* GetExpirationState() { return &mExpirationState; }
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasNoProxies() const { return mHasNoProxies; }
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2011-09-21 01:00:42 +04:00
|
|
|
bool ForcePrincipalCheck() const { return mForcePrincipalCheck; }
|
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
imgLoader* Loader() const { return mLoader; }
|
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
private: // methods
|
|
|
|
friend class imgLoader;
|
|
|
|
friend class imgCacheQueue;
|
2011-09-29 10:19:26 +04:00
|
|
|
void Touch(bool updateTime = true);
|
2012-08-22 19:56:38 +04:00
|
|
|
void UpdateCache(int32_t diff = 0);
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetEvicted(bool evict) { mEvicted = evict; }
|
|
|
|
void SetHasNoProxies(bool hasNoProxies);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
|
|
|
// Private, unimplemented copy constructor.
|
2014-11-14 20:59:00 +03:00
|
|
|
imgCacheEntry(const imgCacheEntry&);
|
2008-09-05 03:00:42 +04:00
|
|
|
|
|
|
|
private: // data
|
|
|
|
nsAutoRefCnt mRefCnt;
|
|
|
|
NS_DECL_OWNINGTHREAD
|
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
imgLoader* mLoader;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> mRequest;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mDataSize;
|
|
|
|
int32_t mTouchedTime;
|
2015-10-20 08:15:25 +03:00
|
|
|
uint32_t mLoadTime;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mExpiryTime;
|
2008-09-05 03:00:42 +04:00
|
|
|
nsExpirationState mExpirationState;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mMustValidate : 1;
|
|
|
|
bool mEvicted : 1;
|
|
|
|
bool mHasNoProxies : 1;
|
|
|
|
bool mForcePrincipalCheck : 1;
|
2008-09-05 03:00:42 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2001-02-21 02:45:51 +03:00
|
|
|
#define NS_IMGLOADER_CID \
|
2014-09-06 01:36:11 +04:00
|
|
|
{ /* c1354898-e3fe-4602-88a7-c4520c21cb4e */ \
|
|
|
|
0xc1354898, 0xe3fe, 0x4602, { \
|
|
|
|
0x88, 0xa7, 0xc4, 0x52, 0x0c, 0x21, 0xcb, 0x4e \
|
|
|
|
} \
|
2001-01-23 01:01:03 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
class imgCacheQueue {
|
2013-03-30 00:14:19 +04:00
|
|
|
public:
|
2008-09-05 03:00:42 +04:00
|
|
|
imgCacheQueue();
|
2015-04-08 00:49:00 +03:00
|
|
|
void Remove(imgCacheEntry*);
|
|
|
|
void Push(imgCacheEntry*);
|
2008-09-05 03:00:42 +04:00
|
|
|
void MarkDirty();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsDirty();
|
2008-09-05 03:00:42 +04:00
|
|
|
already_AddRefed<imgCacheEntry> Pop();
|
|
|
|
void Refresh();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetSize() const;
|
|
|
|
void UpdateSize(int32_t diff);
|
|
|
|
uint32_t GetNumElements() const;
|
2017-09-06 23:12:05 +03:00
|
|
|
bool Contains(imgCacheEntry* aEntry) const;
|
2017-09-06 02:20:18 +03:00
|
|
|
typedef nsTArray<RefPtr<imgCacheEntry>> queueContainer;
|
2008-09-05 03:00:42 +04:00
|
|
|
typedef queueContainer::iterator iterator;
|
|
|
|
typedef queueContainer::const_iterator const_iterator;
|
|
|
|
|
|
|
|
iterator begin();
|
|
|
|
const_iterator begin() const;
|
|
|
|
iterator end();
|
|
|
|
const_iterator end() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
queueContainer mQueue;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDirty;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mSize;
|
2008-09-05 03:00:42 +04:00
|
|
|
};
|
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class AcceptedMimeTypes : uint8_t {
|
2014-12-05 22:33:08 +03:00
|
|
|
IMAGES,
|
|
|
|
IMAGES_AND_DOCUMENTS,
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-12-05 22:33:08 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class imgLoader final : public imgILoader,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIContentSniffer,
|
|
|
|
public imgICache,
|
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsIObserver {
|
2014-06-23 22:49:08 +04:00
|
|
|
virtual ~imgLoader();
|
|
|
|
|
2001-01-23 01:01:03 +03:00
|
|
|
public:
|
2015-05-20 20:21:09 +03:00
|
|
|
typedef mozilla::image::ImageCacheKey ImageCacheKey;
|
2015-04-28 21:45:45 +03:00
|
|
|
typedef nsRefPtrHashtable<nsGenericHashKey<ImageCacheKey>, imgCacheEntry>
|
|
|
|
imgCacheTable;
|
2014-09-06 01:36:11 +04:00
|
|
|
typedef nsTHashtable<nsPtrHashKey<imgRequest>> imgSet;
|
2014-11-18 16:46:53 +03:00
|
|
|
typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
|
2014-09-06 01:36:11 +04:00
|
|
|
typedef mozilla::Mutex Mutex;
|
2013-09-28 22:28:42 +04:00
|
|
|
|
2001-01-23 01:01:03 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
2001-02-21 02:49:46 +03:00
|
|
|
NS_DECL_IMGILOADER
|
2004-07-19 22:53:02 +04:00
|
|
|
NS_DECL_NSICONTENTSNIFFER
|
2008-09-05 03:00:42 +04:00
|
|
|
NS_DECL_IMGICACHE
|
2009-07-15 11:22:40 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2016-05-19 15:31:15 +03:00
|
|
|
/**
|
|
|
|
* Get the normal image loader instance that is used by gecko code, creating
|
|
|
|
* it if necessary.
|
|
|
|
*/
|
|
|
|
static imgLoader* NormalLoader();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Private Browsing image loader instance that is used by gecko code,
|
|
|
|
* creating it if necessary.
|
|
|
|
*/
|
|
|
|
static imgLoader* PrivateBrowsingLoader();
|
2014-04-09 02:51:33 +04:00
|
|
|
|
2016-05-19 15:31:15 +03:00
|
|
|
/**
|
2016-05-19 15:31:15 +03:00
|
|
|
* Gecko code should use NormalLoader() or PrivateBrowsingLoader() to get the
|
|
|
|
* appropriate image loader.
|
2016-05-19 15:31:15 +03:00
|
|
|
*
|
|
|
|
* This constructor is public because the XPCOM module code that creates
|
|
|
|
* instances of "@mozilla.org/image/loader;1" / "@mozilla.org/image/cache;1"
|
|
|
|
* for nsIComponentManager.createInstance()/nsIServiceManager.getService()
|
|
|
|
* calls (now only made by add-ons) needs access to it.
|
|
|
|
*
|
|
|
|
* XXX We would like to get rid of the nsIServiceManager.getService (and
|
|
|
|
* nsIComponentManager.createInstance) method of creating imgLoader objects,
|
|
|
|
* but there are add-ons that are still using it. These add-ons don't
|
|
|
|
* actually do anything useful with the loaders that they create since nobody
|
|
|
|
* who creates an imgLoader using this method actually QIs to imgILoader and
|
|
|
|
* loads images. They all just QI to imgICache and either call clearCache()
|
|
|
|
* or findEntryProperties(). Since they're doing this on an imgLoader that
|
|
|
|
* has never loaded images, these calls are useless. It seems likely that
|
|
|
|
* the code that is doing this is just legacy code left over from a time when
|
|
|
|
* there was only one imgLoader instance for the entire process. (Nowadays
|
|
|
|
* the correct method to get an imgILoader/imgICache is to call
|
|
|
|
* imgITools::getImgCacheForDocument/imgITools::getImgLoaderForDocument.)
|
|
|
|
* All the same, even though what these add-ons are doing is a no-op,
|
|
|
|
* removing the nsIServiceManager.getService method of creating/getting an
|
|
|
|
* imgLoader objects would cause an exception in these add-ons that could
|
|
|
|
* break things.
|
|
|
|
*/
|
2001-02-21 02:45:51 +03:00
|
|
|
imgLoader();
|
2009-07-15 11:22:40 +04:00
|
|
|
nsresult Init();
|
|
|
|
|
2016-08-29 08:34:32 +03:00
|
|
|
MOZ_MUST_USE nsresult
|
|
|
|
LoadImage(nsIURI* aURI, nsIURI* aInitialDocumentURI, nsIURI* aReferrerURI,
|
|
|
|
ReferrerPolicy aReferrerPolicy, nsIPrincipal* aLoadingPrincipal,
|
2017-09-21 03:09:00 +03:00
|
|
|
uint64_t aRequestContextID, nsILoadGroup* aLoadGroup,
|
2016-08-29 08:34:32 +03:00
|
|
|
imgINotificationObserver* aObserver, nsINode* aContext,
|
2019-01-02 16:05:23 +03:00
|
|
|
mozilla::dom::Document* aLoadingDocument, nsLoadFlags aLoadFlags,
|
2016-08-29 08:34:32 +03:00
|
|
|
nsISupports* aCacheKey, nsContentPolicyType aContentPolicyType,
|
|
|
|
const nsAString& initiatorType, bool aUseUrgentStartForChannel,
|
|
|
|
imgRequestProxy** _retval);
|
|
|
|
|
|
|
|
MOZ_MUST_USE nsresult
|
|
|
|
LoadImageWithChannel(nsIChannel* channel, imgINotificationObserver* aObserver,
|
|
|
|
nsISupports* aCX, nsIStreamListener** listener,
|
|
|
|
imgRequestProxy** _retval);
|
2012-10-12 16:43:01 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
static nsresult GetMimeTypeFromContent(const char* aContents,
|
|
|
|
uint32_t aLength,
|
|
|
|
nsACString& aContentType);
|
2014-12-05 22:33:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given mime type may be interpreted as an image.
|
|
|
|
*
|
|
|
|
* Some MIME types may be interpreted as both images and documents. (At the
|
|
|
|
* moment only "image/svg+xml" falls into this category, but there may be more
|
|
|
|
* in the future.) Callers which want this function to return true for such
|
2015-04-08 00:49:00 +03:00
|
|
|
* MIME types should pass AcceptedMimeTypes::IMAGES_AND_DOCUMENTS for
|
|
|
|
* @aAccept.
|
2014-12-05 22:33:08 +03:00
|
|
|
*
|
|
|
|
* @param aMimeType The MIME type to evaluate.
|
|
|
|
* @param aAcceptedMimeTypes Which kinds of MIME types to treat as images.
|
|
|
|
*/
|
|
|
|
static bool SupportImageWithMimeType(
|
|
|
|
const char* aMimeType,
|
|
|
|
AcceptedMimeTypes aAccept = AcceptedMimeTypes::IMAGES);
|
2002-05-25 00:54:44 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
static void GlobalInit(); // for use by the factory
|
2008-09-05 03:00:42 +04:00
|
|
|
static void Shutdown(); // for use by the factory
|
2016-09-19 20:29:59 +03:00
|
|
|
static void ShutdownMemoryReporter();
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
nsresult ClearChromeImageCache();
|
|
|
|
nsresult ClearImageCache();
|
|
|
|
void MinimizeCaches();
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
nsresult InitCache();
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
bool RemoveFromCache(const ImageCacheKey& aKey);
|
2017-09-06 23:12:05 +03:00
|
|
|
|
|
|
|
// Enumeration describing if a given entry is in the cache queue or not.
|
|
|
|
// There are some cases we know the entry is definitely not in the queue.
|
|
|
|
enum class QueueState { MaybeExists, AlreadyRemoved };
|
|
|
|
|
|
|
|
bool RemoveFromCache(imgCacheEntry* entry,
|
|
|
|
QueueState aQueueState = QueueState::MaybeExists);
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
bool PutIntoCache(const ImageCacheKey& aKey, imgCacheEntry* aEntry);
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2014-09-06 01:36:11 +04:00
|
|
|
void AddToUncachedImages(imgRequest* aRequest);
|
|
|
|
void RemoveFromUncachedImages(imgRequest* aRequest);
|
|
|
|
|
2009-06-16 02:33:48 +04:00
|
|
|
// Returns true if we should prefer evicting cache entry |two| over cache
|
|
|
|
// entry |one|.
|
2008-09-05 03:00:42 +04:00
|
|
|
// This mixes units in the worst way, but provides reasonable results.
|
2015-10-18 08:24:48 +03:00
|
|
|
inline static bool CompareCacheEntries(const RefPtr<imgCacheEntry>& one,
|
|
|
|
const RefPtr<imgCacheEntry>& two) {
|
2015-04-08 00:49:00 +03:00
|
|
|
if (!one) {
|
2008-09-05 03:00:42 +04:00
|
|
|
return false;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
|
|
|
if (!two) {
|
2008-09-05 03:00:42 +04:00
|
|
|
return true;
|
2015-04-08 00:49:00 +03:00
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2009-06-16 02:33:48 +04:00
|
|
|
const double sizeweight = 1.0 - sCacheTimeWeight;
|
|
|
|
|
|
|
|
// We want large, old images to be evicted first (depending on their
|
|
|
|
// relative weights). Since a larger time is actually newer, we subtract
|
|
|
|
// time's weight, so an older image has a larger weight.
|
|
|
|
double oneweight = double(one->GetDataSize()) * sizeweight -
|
|
|
|
double(one->GetTouchedTime()) * sCacheTimeWeight;
|
|
|
|
double twoweight = double(two->GetDataSize()) * sizeweight -
|
|
|
|
double(two->GetTouchedTime()) * sCacheTimeWeight;
|
|
|
|
|
|
|
|
return oneweight < twoweight;
|
2008-09-05 03:00:42 +04:00
|
|
|
}
|
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
void VerifyCacheSizes();
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2009-01-31 05:17:47 +03:00
|
|
|
// The image loader maintains a hash table of all imgCacheEntries. However,
|
|
|
|
// only some of them will be evicted from the cache: those who have no
|
2013-03-30 00:14:19 +04:00
|
|
|
// imgRequestProxies watching their imgRequests.
|
2009-01-31 05:17:47 +03:00
|
|
|
//
|
|
|
|
// Once an imgRequest has no imgRequestProxies, it should notify us by
|
|
|
|
// calling HasNoObservers(), and null out its cache entry pointer.
|
2013-03-30 00:14:19 +04:00
|
|
|
//
|
2009-01-31 05:17:47 +03:00
|
|
|
// Upon having a proxy start observing again, it should notify us by calling
|
|
|
|
// HasObservers(). The request's cache entry will be re-set before this
|
|
|
|
// happens, by calling imgRequest::SetCacheEntry() when an entry with no
|
|
|
|
// observers is re-requested.
|
2015-04-08 00:49:00 +03:00
|
|
|
bool SetHasNoProxies(imgRequest* aRequest, imgCacheEntry* aEntry);
|
|
|
|
bool SetHasProxies(imgRequest* aRequest);
|
2009-01-31 05:17:47 +03:00
|
|
|
|
2008-09-05 03:00:42 +04:00
|
|
|
private: // methods
|
2016-05-19 15:31:15 +03:00
|
|
|
static already_AddRefed<imgLoader> CreateImageLoader();
|
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
bool ValidateEntry(imgCacheEntry* aEntry, nsIURI* aKey,
|
|
|
|
nsIURI* aInitialDocumentURI, nsIURI* aReferrerURI,
|
|
|
|
ReferrerPolicy aReferrerPolicy, nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver, nsISupports* aCX,
|
2019-01-02 16:05:23 +03:00
|
|
|
mozilla::dom::Document* aLoadingDocument,
|
|
|
|
nsLoadFlags aLoadFlags,
|
2015-04-08 00:49:00 +03:00
|
|
|
nsContentPolicyType aContentPolicyType,
|
2018-08-01 07:35:24 +03:00
|
|
|
bool aCanMakeNewChannel, bool* aNewChannelCreated,
|
2015-04-08 00:49:00 +03:00
|
|
|
imgRequestProxy** aProxyRequest,
|
|
|
|
nsIPrincipal* aLoadingPrincipal, int32_t aCORSMode);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
bool ValidateRequestWithNewChannel(
|
|
|
|
imgRequest* request, nsIURI* aURI, nsIURI* aInitialDocumentURI,
|
|
|
|
nsIURI* aReferrerURI, ReferrerPolicy aReferrerPolicy,
|
|
|
|
nsILoadGroup* aLoadGroup, imgINotificationObserver* aObserver,
|
2019-01-02 16:05:23 +03:00
|
|
|
nsISupports* aCX, mozilla::dom::Document* aLoadingDocument,
|
|
|
|
nsLoadFlags aLoadFlags, nsContentPolicyType aContentPolicyType,
|
|
|
|
imgRequestProxy** aProxyRequest, nsIPrincipal* aLoadingPrincipal,
|
|
|
|
int32_t aCORSMode, bool* aNewChannelCreated);
|
2015-04-08 00:49:00 +03:00
|
|
|
|
|
|
|
nsresult CreateNewProxyForRequest(imgRequest* aRequest,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
2019-01-02 16:05:23 +03:00
|
|
|
mozilla::dom::Document* aLoadingDocument,
|
2015-04-08 00:49:00 +03:00
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
imgRequestProxy** _retval);
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2011-06-12 06:30:15 +04:00
|
|
|
void ReadAcceptHeaderPref();
|
2009-07-15 11:22:40 +04:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
nsresult EvictEntries(imgCacheTable& aCacheToClear);
|
|
|
|
nsresult EvictEntries(imgCacheQueue& aQueueToClear);
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2015-04-28 21:45:45 +03:00
|
|
|
imgCacheTable& GetCache(bool aForChrome);
|
|
|
|
imgCacheTable& GetCache(const ImageCacheKey& aKey);
|
|
|
|
imgCacheQueue& GetCacheQueue(bool aForChrome);
|
|
|
|
imgCacheQueue& GetCacheQueue(const ImageCacheKey& aKey);
|
|
|
|
void CacheEntriesChanged(bool aForChrome, int32_t aSizeDiff = 0);
|
2015-04-08 00:49:00 +03:00
|
|
|
void CheckCacheLimits(imgCacheTable& cache, imgCacheQueue& queue);
|
2008-09-05 03:00:42 +04:00
|
|
|
|
|
|
|
private: // data
|
|
|
|
friend class imgCacheEntry;
|
2010-05-22 08:10:14 +04:00
|
|
|
friend class imgMemoryReporter;
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
imgCacheTable mCache;
|
|
|
|
imgCacheQueue mCacheQueue;
|
|
|
|
|
|
|
|
imgCacheTable mChromeCache;
|
|
|
|
imgCacheQueue mChromeCacheQueue;
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2014-09-06 01:36:11 +04:00
|
|
|
// Hash set of every imgRequest for this loader that isn't in mCache or
|
|
|
|
// mChromeCache. The union over all imgLoader's of mCache, mChromeCache, and
|
|
|
|
// mUncachedImages should be every imgRequest that is alive. These are weak
|
|
|
|
// pointers so we rely on the imgRequest destructor to remove itself.
|
|
|
|
imgSet mUncachedImages;
|
|
|
|
// The imgRequest can have refs to them held on non-main thread, so we need
|
|
|
|
// a mutex because we modify the uncached images set from the imgRequest
|
|
|
|
// destructor.
|
|
|
|
Mutex mUncachedImagesMutex;
|
|
|
|
|
2012-08-09 11:09:42 +04:00
|
|
|
static double sCacheTimeWeight;
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sCacheMaxSize;
|
2012-06-26 08:20:12 +04:00
|
|
|
static imgMemoryReporter* sMemReporter;
|
2009-07-15 11:22:40 +04:00
|
|
|
|
|
|
|
nsCString mAcceptHeader;
|
2012-06-26 08:20:12 +04:00
|
|
|
|
2015-10-17 13:53:28 +03:00
|
|
|
mozilla::UniquePtr<imgCacheExpirationTracker> mCacheTracker;
|
2012-06-26 08:20:12 +04:00
|
|
|
bool mRespectPrivacy;
|
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 "nsCOMPtr.h"
|
|
|
|
#include "nsIStreamListener.h"
|
2013-09-28 22:28:42 +04:00
|
|
|
#include "nsIThreadRetargetableStreamListener.h"
|
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
|
|
|
|
|
|
|
class ProxyListener : public nsIStreamListener,
|
2013-09-28 22:28:42 +04:00
|
|
|
public nsIThreadRetargetableStreamListener {
|
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
|
|
|
public:
|
2015-04-08 00:49:00 +03:00
|
|
|
explicit 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
|
|
|
|
|
|
|
/* additional members */
|
2015-03-05 09:18:12 +03:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
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
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2013-09-28 22:28:42 +04:00
|
|
|
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
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
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
|
|
|
|
private:
|
2014-06-23 22:49:08 +04:00
|
|
|
virtual ~ProxyListener();
|
|
|
|
|
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<nsIStreamListener> mDestListener;
|
2001-01-23 01:01:03 +03:00
|
|
|
};
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2011-07-01 21:03:38 +04:00
|
|
|
/**
|
|
|
|
* A class that implements nsIProgressEventSink and forwards all calls to it to
|
|
|
|
* the original notification callbacks of the channel. Also implements
|
|
|
|
* nsIInterfaceRequestor and gives out itself for nsIProgressEventSink calls,
|
|
|
|
* and forwards everything else to the channel's notification callbacks.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsProgressNotificationProxy final : public nsIProgressEventSink,
|
2012-01-03 00:23:41 +04:00
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIInterfaceRequestor {
|
2011-07-01 21:03:38 +04:00
|
|
|
public:
|
|
|
|
nsProgressNotificationProxy(nsIChannel* channel, imgIRequest* proxy)
|
|
|
|
: mImageRequest(proxy) {
|
|
|
|
channel->GetNotificationCallbacks(getter_AddRefs(mOriginalCallbacks));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIPROGRESSEVENTSINK
|
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
private:
|
2015-04-08 00:49:00 +03:00
|
|
|
~nsProgressNotificationProxy() {}
|
2011-07-01 21:03:38 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mOriginalCallbacks;
|
|
|
|
nsCOMPtr<nsIRequest> mImageRequest;
|
|
|
|
};
|
2002-01-15 08:23:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* validate checker
|
|
|
|
*/
|
|
|
|
|
2005-06-01 22:28:20 +04:00
|
|
|
#include "nsCOMArray.h"
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2011-07-01 21:03:38 +04:00
|
|
|
class imgCacheValidator : public nsIStreamListener,
|
2013-09-28 22:28:42 +04:00
|
|
|
public nsIThreadRetargetableStreamListener,
|
2011-07-01 21:03:38 +04:00
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIAsyncVerifyRedirectCallback {
|
2002-01-15 08:23:33 +03:00
|
|
|
public:
|
2012-06-26 08:20:12 +04:00
|
|
|
imgCacheValidator(nsProgressNotificationProxy* progress, imgLoader* loader,
|
2015-03-24 05:37:45 +03:00
|
|
|
imgRequest* aRequest, nsISupports* aContext,
|
|
|
|
bool forcePrincipalCheckForCacheEntry);
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2015-04-08 00:49:00 +03:00
|
|
|
void AddProxy(imgRequestProxy* aProxy);
|
2017-11-14 20:02:59 +03:00
|
|
|
void RemoveProxy(imgRequestProxy* aProxy);
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2017-07-06 09:16:41 +03:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2013-09-28 22:28:42 +04:00
|
|
|
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
2002-01-15 08:23:33 +03:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
2011-07-01 21:03:38 +04:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
|
2002-01-15 08:23:33 +03:00
|
|
|
|
|
|
|
private:
|
2018-04-17 21:42:35 +03:00
|
|
|
void UpdateProxies(bool aCancelRequest, bool aSyncNotify);
|
2014-06-23 22:49:08 +04:00
|
|
|
virtual ~imgCacheValidator();
|
|
|
|
|
2002-01-15 08:23:33 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> mDestListener;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsProgressNotificationProxy> mProgressProxy;
|
2011-07-01 21:03:38 +04:00
|
|
|
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
|
|
|
|
nsCOMPtr<nsIChannel> mRedirectChannel;
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> mRequest;
|
2018-02-07 15:27:27 +03:00
|
|
|
AutoTArray<RefPtr<imgRequestProxy>, 4> mProxies;
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> mNewRequest;
|
|
|
|
RefPtr<imgCacheEntry> mNewEntry;
|
2011-07-01 21:03:38 +04:00
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
nsCOMPtr<nsISupports> mContext;
|
2008-09-05 03:00:42 +04:00
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
imgLoader* mImgLoader;
|
2014-12-16 04:40:43 +03:00
|
|
|
|
|
|
|
bool mHadInsecureRedirect;
|
2002-01-15 08:23:33 +03:00
|
|
|
};
|
2010-08-14 08:09:48 +04:00
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#endif // mozilla_image_imgLoader_h
|