2001-01-22 22:01:03 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#ifndef mozilla_image_imgLoader_h
|
|
|
|
#define mozilla_image_imgLoader_h
|
2010-08-14 04:09:48 +00:00
|
|
|
|
2012-01-02 20:23:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-09-05 21:36:11 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2015-10-17 10:53:28 +00:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2012-01-02 20:23:41 +00:00
|
|
|
|
2001-02-20 23:45:51 +00:00
|
|
|
#include "imgILoader.h"
|
2008-09-04 23:00:42 +00:00
|
|
|
#include "imgICache.h"
|
|
|
|
#include "nsWeakReference.h"
|
2004-07-19 18:53:02 +00:00
|
|
|
#include "nsIContentSniffer.h"
|
2008-09-04 23:00:42 +00:00
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsExpirationTracker.h"
|
2015-05-20 17:21:09 +00:00
|
|
|
#include "ImageCacheKey.h"
|
2008-09-04 23:00:42 +00:00
|
|
|
#include "imgRequest.h"
|
2011-07-01 17:03:38 +00:00
|
|
|
#include "nsIProgressEventSink.h"
|
|
|
|
#include "nsIChannel.h"
|
2013-09-28 18:28:42 +00:00
|
|
|
#include "nsIThreadRetargetableStreamListener.h"
|
2013-09-07 13:01:08 +00:00
|
|
|
#include "imgIRequest.h"
|
2014-11-18 13:46:53 +00:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
class imgLoader;
|
2002-01-15 05:23:33 +00:00
|
|
|
class imgRequestProxy;
|
2012-10-12 16:11:22 +00: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 02:42:56 +00:00
|
|
|
class nsILoadGroup;
|
2012-06-26 04:20:12 +00: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 02:42:56 +00:00
|
|
|
|
2013-09-28 18:28:42 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace image {
|
|
|
|
class ImageURL;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|
2013-09-28 18:28:42 +00:00
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
class imgCacheEntry
|
|
|
|
{
|
|
|
|
public:
|
2015-04-07 21:49:00 +00:00
|
|
|
imgCacheEntry(imgLoader* loader, imgRequest* request,
|
|
|
|
bool aForcePrincipalCheck);
|
2009-01-31 02:17:47 +00:00
|
|
|
~imgCacheEntry();
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
nsrefcnt AddRef()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_PRECONDITION(int32_t(mRefCnt) >= 0, "illegal refcnt");
|
2015-04-07 21:49:00 +00:00
|
|
|
MOZ_ASSERT(_mOwningThread.GetThread() == PR_GetCurrentThread(),
|
|
|
|
"imgCacheEntry addref isn't thread-safe!");
|
2008-09-04 23:00:42 +00:00
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "imgCacheEntry", sizeof(*this));
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
2013-03-29 20:14:19 +00:00
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
nsrefcnt Release()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
2015-04-07 21:49:00 +00:00
|
|
|
MOZ_ASSERT(_mOwningThread.GetThread() == PR_GetCurrentThread(),
|
|
|
|
"imgCacheEntry release isn't thread-safe!");
|
2008-09-04 23:00:42 +00:00
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "imgCacheEntry");
|
|
|
|
if (mRefCnt == 0) {
|
|
|
|
mRefCnt = 1; /* stabilize */
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-29 20:14:19 +00:00
|
|
|
return mRefCnt;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t GetDataSize() const
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return mDataSize;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
void SetDataSize(uint32_t aDataSize)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t oldsize = mDataSize;
|
2008-09-04 23:00:42 +00:00
|
|
|
mDataSize = aDataSize;
|
2009-09-12 22:44:18 +00:00
|
|
|
UpdateCache(mDataSize - oldsize);
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t GetTouchedTime() const
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return mTouchedTime;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
void SetTouchedTime(int32_t time)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
mTouchedTime = time;
|
2011-10-17 14:59:28 +00:00
|
|
|
Touch(/* updateTime = */ false);
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 05:15:25 +00:00
|
|
|
uint32_t GetLoadTime() const
|
|
|
|
{
|
|
|
|
return mLoadTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateLoadTime();
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t GetExpiryTime() const
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return mExpiryTime;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
void SetExpiryTime(int32_t aExpiryTime)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
mExpiryTime = aExpiryTime;
|
|
|
|
Touch();
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool GetMustValidate() const
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2011-07-01 17:03:35 +00:00
|
|
|
return mMustValidate;
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetMustValidate(bool aValidate)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2011-07-01 17:03:35 +00:00
|
|
|
mMustValidate = aValidate;
|
2008-09-04 23:00:42 +00:00
|
|
|
Touch();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<imgRequest> GetRequest() const
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> req = mRequest;
|
2013-04-22 11:15:59 +00:00
|
|
|
return req.forget();
|
2008-09-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Evicted() const
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return mEvicted;
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsExpirationState* GetExpirationState()
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return &mExpirationState;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool HasNoProxies() const
|
2009-01-31 02:17:47 +00:00
|
|
|
{
|
|
|
|
return mHasNoProxies;
|
|
|
|
}
|
|
|
|
|
2011-09-20 21:00:42 +00:00
|
|
|
bool ForcePrincipalCheck() const
|
|
|
|
{
|
|
|
|
return mForcePrincipalCheck;
|
|
|
|
}
|
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
imgLoader* Loader() const
|
|
|
|
{
|
|
|
|
return mLoader;
|
|
|
|
}
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
private: // methods
|
|
|
|
friend class imgLoader;
|
|
|
|
friend class imgCacheQueue;
|
2011-09-29 06:19:26 +00:00
|
|
|
void Touch(bool updateTime = true);
|
2012-08-22 15:56:38 +00:00
|
|
|
void UpdateCache(int32_t diff = 0);
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetEvicted(bool evict)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
mEvicted = evict;
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetHasNoProxies(bool hasNoProxies);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
|
|
|
// Private, unimplemented copy constructor.
|
2014-11-14 17:59:00 +00:00
|
|
|
imgCacheEntry(const imgCacheEntry&);
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
private: // data
|
|
|
|
nsAutoRefCnt mRefCnt;
|
|
|
|
NS_DECL_OWNINGTHREAD
|
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
imgLoader* mLoader;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> mRequest;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mDataSize;
|
|
|
|
int32_t mTouchedTime;
|
2015-10-20 05:15:25 +00:00
|
|
|
uint32_t mLoadTime;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mExpiryTime;
|
2008-09-04 23:00:42 +00:00
|
|
|
nsExpirationState mExpirationState;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mMustValidate : 1;
|
|
|
|
bool mEvicted : 1;
|
|
|
|
bool mHasNoProxies : 1;
|
|
|
|
bool mForcePrincipalCheck : 1;
|
2008-09-04 23:00:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2001-02-20 23:45:51 +00:00
|
|
|
#define NS_IMGLOADER_CID \
|
2014-09-05 21:36:11 +00:00
|
|
|
{ /* c1354898-e3fe-4602-88a7-c4520c21cb4e */ \
|
|
|
|
0xc1354898, \
|
|
|
|
0xe3fe, \
|
|
|
|
0x4602, \
|
|
|
|
{0x88, 0xa7, 0xc4, 0x52, 0x0c, 0x21, 0xcb, 0x4e} \
|
2001-01-22 22:01:03 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
class imgCacheQueue
|
|
|
|
{
|
2013-03-29 20:14:19 +00:00
|
|
|
public:
|
2008-09-04 23:00:42 +00:00
|
|
|
imgCacheQueue();
|
2015-04-07 21:49:00 +00:00
|
|
|
void Remove(imgCacheEntry*);
|
|
|
|
void Push(imgCacheEntry*);
|
2008-09-04 23:00:42 +00:00
|
|
|
void MarkDirty();
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsDirty();
|
2008-09-04 23:00:42 +00:00
|
|
|
already_AddRefed<imgCacheEntry> Pop();
|
|
|
|
void Refresh();
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t GetSize() const;
|
|
|
|
void UpdateSize(int32_t diff);
|
|
|
|
uint32_t GetNumElements() const;
|
2015-10-18 05:24:48 +00:00
|
|
|
typedef std::vector<RefPtr<imgCacheEntry> > queueContainer;
|
2008-09-04 23:00:42 +00: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 06:19:26 +00:00
|
|
|
bool mDirty;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mSize;
|
2008-09-04 23:00:42 +00:00
|
|
|
};
|
|
|
|
|
2015-01-25 22:22:07 +00:00
|
|
|
enum class AcceptedMimeTypes : uint8_t {
|
2014-12-05 19:33:08 +00:00
|
|
|
IMAGES,
|
|
|
|
IMAGES_AND_DOCUMENTS,
|
2015-01-25 22:22:07 +00:00
|
|
|
};
|
2014-12-05 19:33:08 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class imgLoader final : public imgILoader,
|
2015-03-27 18:52:19 +00:00
|
|
|
public nsIContentSniffer,
|
|
|
|
public imgICache,
|
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsIObserver
|
2001-01-22 22:01:03 +00:00
|
|
|
{
|
2014-06-23 18:49:08 +00:00
|
|
|
virtual ~imgLoader();
|
|
|
|
|
2001-01-22 22:01:03 +00:00
|
|
|
public:
|
2015-05-20 17:21:09 +00:00
|
|
|
typedef mozilla::image::ImageCacheKey ImageCacheKey;
|
2013-09-28 18:28:42 +00:00
|
|
|
typedef mozilla::image::ImageURL ImageURL;
|
2015-04-28 18:45:45 +00:00
|
|
|
typedef nsRefPtrHashtable<nsGenericHashKey<ImageCacheKey>,
|
|
|
|
imgCacheEntry> imgCacheTable;
|
2014-09-05 21:36:11 +00:00
|
|
|
typedef nsTHashtable<nsPtrHashKey<imgRequest>> imgSet;
|
2014-11-18 13:46:53 +00:00
|
|
|
typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
|
2014-09-05 21:36:11 +00:00
|
|
|
typedef mozilla::Mutex Mutex;
|
2013-09-28 18:28:42 +00:00
|
|
|
|
2001-01-22 22:01:03 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2001-02-20 23:49:46 +00:00
|
|
|
NS_DECL_IMGILOADER
|
2004-07-19 18:53:02 +00:00
|
|
|
NS_DECL_NSICONTENTSNIFFER
|
2008-09-04 23:00:42 +00:00
|
|
|
NS_DECL_IMGICACHE
|
2009-07-15 07:22:40 +00:00
|
|
|
NS_DECL_NSIOBSERVER
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2014-04-08 22:51:33 +00:00
|
|
|
static imgLoader* Singleton();
|
|
|
|
static imgLoader* PBSingleton();
|
|
|
|
|
2001-02-20 23:45:51 +00:00
|
|
|
imgLoader();
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2009-07-15 07:22:40 +00:00
|
|
|
nsresult Init();
|
|
|
|
|
2012-11-16 18:24:58 +00:00
|
|
|
static imgLoader* Create()
|
|
|
|
{
|
|
|
|
// Unfortunately, we rely on XPCOM module init happening
|
|
|
|
// before imgLoader creation. For now, it's easier
|
|
|
|
// to just call CallCreateInstance() which will init
|
|
|
|
// the image module instead of calling new imgLoader
|
|
|
|
// directly.
|
2015-04-07 21:49:00 +00:00
|
|
|
imgILoader* loader;
|
2012-11-16 18:24:58 +00:00
|
|
|
CallCreateInstance("@mozilla.org/image/loader;1", &loader);
|
|
|
|
// There's only one imgLoader implementation so we
|
|
|
|
// can safely cast to it.
|
|
|
|
return static_cast<imgLoader*>(loader);
|
|
|
|
}
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
static already_AddRefed<imgLoader>
|
|
|
|
GetInstance();
|
2012-10-12 12:43:01 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult LoadImage(nsIURI* aURI,
|
|
|
|
nsIURI* aInitialDocumentURI,
|
|
|
|
nsIURI* aReferrerURI,
|
2014-11-18 13:46:53 +00:00
|
|
|
ReferrerPolicy aReferrerPolicy,
|
2012-10-12 12:43:01 +00:00
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
2015-04-07 21:49:00 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsISupports* aCX,
|
2012-10-12 12:43:01 +00:00
|
|
|
nsLoadFlags aLoadFlags,
|
2015-04-07 21:49:00 +00:00
|
|
|
nsISupports* aCacheKey,
|
2014-08-19 21:49:38 +00:00
|
|
|
nsContentPolicyType aContentPolicyType,
|
2013-10-16 01:35:44 +00:00
|
|
|
const nsAString& initiatorType,
|
2015-04-07 21:49:00 +00:00
|
|
|
imgRequestProxy** _retval);
|
2014-08-19 21:49:38 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult LoadImageWithChannel(nsIChannel* channel,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsISupports* aCX,
|
|
|
|
nsIStreamListener** listener,
|
|
|
|
imgRequestProxy** _retval);
|
2012-10-12 12:43:01 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
static nsresult GetMimeTypeFromContent(const char* aContents,
|
|
|
|
uint32_t aLength,
|
|
|
|
nsACString& aContentType);
|
2014-12-05 19:33:08 +00: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-07 21:49:00 +00:00
|
|
|
* MIME types should pass AcceptedMimeTypes::IMAGES_AND_DOCUMENTS for
|
|
|
|
* @aAccept.
|
2014-12-05 19:33:08 +00:00
|
|
|
*
|
|
|
|
* @param aMimeType The MIME type to evaluate.
|
|
|
|
* @param aAcceptedMimeTypes Which kinds of MIME types to treat as images.
|
|
|
|
*/
|
|
|
|
static NS_EXPORT_(bool)
|
|
|
|
SupportImageWithMimeType(const char* aMimeType,
|
|
|
|
AcceptedMimeTypes aAccept =
|
|
|
|
AcceptedMimeTypes::IMAGES);
|
2002-05-24 20:54:44 +00:00
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
static void GlobalInit(); // for use by the factory
|
2008-09-04 23:00:42 +00:00
|
|
|
static void Shutdown(); // for use by the factory
|
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
nsresult ClearChromeImageCache();
|
|
|
|
nsresult ClearImageCache();
|
|
|
|
void MinimizeCaches();
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
nsresult InitCache();
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
bool RemoveFromCache(const ImageCacheKey& aKey);
|
2015-04-07 21:49:00 +00:00
|
|
|
bool RemoveFromCache(imgCacheEntry* entry);
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-28 18:45:45 +00:00
|
|
|
bool PutIntoCache(const ImageCacheKey& aKey, imgCacheEntry* aEntry);
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2014-09-05 21:36:11 +00:00
|
|
|
void AddToUncachedImages(imgRequest* aRequest);
|
|
|
|
void RemoveFromUncachedImages(imgRequest* aRequest);
|
|
|
|
|
2009-06-15 22:33:48 +00:00
|
|
|
// Returns true if we should prefer evicting cache entry |two| over cache
|
|
|
|
// entry |one|.
|
2008-09-04 23:00:42 +00:00
|
|
|
// This mixes units in the worst way, but provides reasonable results.
|
2015-10-18 05:24:48 +00:00
|
|
|
inline static bool CompareCacheEntries(const RefPtr<imgCacheEntry>& one,
|
|
|
|
const RefPtr<imgCacheEntry>& two)
|
2008-09-04 23:00:42 +00:00
|
|
|
{
|
2015-04-07 21:49:00 +00:00
|
|
|
if (!one) {
|
2008-09-04 23:00:42 +00:00
|
|
|
return false;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
|
|
|
if (!two) {
|
2008-09-04 23:00:42 +00:00
|
|
|
return true;
|
2015-04-07 21:49:00 +00:00
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2009-06-15 22:33:48 +00: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-04 23:00:42 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
void VerifyCacheSizes();
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2009-01-31 02:17:47 +00: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-29 20:14:19 +00:00
|
|
|
// imgRequestProxies watching their imgRequests.
|
2009-01-31 02:17:47 +00:00
|
|
|
//
|
|
|
|
// Once an imgRequest has no imgRequestProxies, it should notify us by
|
|
|
|
// calling HasNoObservers(), and null out its cache entry pointer.
|
2013-03-29 20:14:19 +00:00
|
|
|
//
|
2009-01-31 02:17:47 +00: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-07 21:49:00 +00:00
|
|
|
bool SetHasNoProxies(imgRequest* aRequest, imgCacheEntry* aEntry);
|
|
|
|
bool SetHasProxies(imgRequest* aRequest);
|
2009-01-31 02:17:47 +00:00
|
|
|
|
2008-09-04 23:00:42 +00:00
|
|
|
private: // methods
|
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
bool ValidateEntry(imgCacheEntry* aEntry, nsIURI* aKey,
|
|
|
|
nsIURI* aInitialDocumentURI, nsIURI* aReferrerURI,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver, nsISupports* aCX,
|
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
nsContentPolicyType aContentPolicyType,
|
|
|
|
bool aCanMakeNewChannel,
|
|
|
|
imgRequestProxy** aProxyRequest,
|
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
|
|
|
int32_t aCORSMode);
|
|
|
|
|
|
|
|
bool ValidateRequestWithNewChannel(imgRequest* request, nsIURI* aURI,
|
|
|
|
nsIURI* aInitialDocumentURI,
|
|
|
|
nsIURI* aReferrerURI,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsISupports* aCX, nsLoadFlags aLoadFlags,
|
|
|
|
nsContentPolicyType aContentPolicyType,
|
|
|
|
imgRequestProxy** aProxyRequest,
|
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
|
|
|
int32_t aCORSMode);
|
|
|
|
|
|
|
|
nsresult CreateNewProxyForRequest(imgRequest* aRequest,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
imgINotificationObserver* aObserver,
|
|
|
|
nsLoadFlags aLoadFlags,
|
|
|
|
imgRequestProxy** _retval);
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2011-06-12 02:30:15 +00:00
|
|
|
void ReadAcceptHeaderPref();
|
2009-07-15 07:22:40 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
nsresult EvictEntries(imgCacheTable& aCacheToClear);
|
|
|
|
nsresult EvictEntries(imgCacheQueue& aQueueToClear);
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2015-04-28 18:45:45 +00: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-07 21:49:00 +00:00
|
|
|
void CheckCacheLimits(imgCacheTable& cache, imgCacheQueue& queue);
|
2008-09-04 23:00:42 +00:00
|
|
|
|
|
|
|
private: // data
|
|
|
|
friend class imgCacheEntry;
|
2010-05-22 04:10:14 +00:00
|
|
|
friend class imgMemoryReporter;
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
imgCacheTable mCache;
|
|
|
|
imgCacheQueue mCacheQueue;
|
|
|
|
|
|
|
|
imgCacheTable mChromeCache;
|
|
|
|
imgCacheQueue mChromeCacheQueue;
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2014-09-05 21:36:11 +00: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 07:09:42 +00:00
|
|
|
static double sCacheTimeWeight;
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t sCacheMaxSize;
|
2012-06-26 04:20:12 +00:00
|
|
|
static imgMemoryReporter* sMemReporter;
|
2009-07-15 07:22:40 +00:00
|
|
|
|
|
|
|
nsCString mAcceptHeader;
|
2012-06-26 04:20:12 +00:00
|
|
|
|
2015-10-17 10:53:28 +00:00
|
|
|
mozilla::UniquePtr<imgCacheExpirationTracker> mCacheTracker;
|
2012-06-26 04:20:12 +00: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 02:42:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* proxy stream listener class used to handle multipart/x-mixed-replace
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIStreamListener.h"
|
2013-09-28 18:28:42 +00: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 02:42:56 +00:00
|
|
|
|
|
|
|
class ProxyListener : public nsIStreamListener
|
2013-09-28 18:28:42 +00: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 02:42:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-04-07 21:49:00 +00: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 02:42:56 +00:00
|
|
|
|
|
|
|
/* additional members */
|
2015-03-05 06:18:12 +00: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 02:42:56 +00:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2013-09-28 18:28:42 +00: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 02:42:56 +00:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
|
|
|
|
private:
|
2014-06-23 18:49:08 +00: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 02:42:56 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> mDestListener;
|
2001-01-22 22:01:03 +00:00
|
|
|
};
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2011-07-01 17:03:38 +00: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 16:28:04 +00:00
|
|
|
class nsProgressNotificationProxy final
|
2012-01-02 20:23:41 +00:00
|
|
|
: public nsIProgressEventSink
|
|
|
|
, public nsIChannelEventSink
|
|
|
|
, public nsIInterfaceRequestor
|
2011-07-01 17:03:38 +00: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-07 21:49:00 +00:00
|
|
|
~nsProgressNotificationProxy() { }
|
2011-07-01 17:03:38 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mOriginalCallbacks;
|
|
|
|
nsCOMPtr<nsIRequest> mImageRequest;
|
|
|
|
};
|
2002-01-15 05:23:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* validate checker
|
|
|
|
*/
|
|
|
|
|
2005-06-01 18:28:20 +00:00
|
|
|
#include "nsCOMArray.h"
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2011-07-01 17:03:38 +00:00
|
|
|
class imgCacheValidator : public nsIStreamListener,
|
2013-09-28 18:28:42 +00:00
|
|
|
public nsIThreadRetargetableStreamListener,
|
2011-07-01 17:03:38 +00:00
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIAsyncVerifyRedirectCallback
|
2002-01-15 05:23:33 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-06-26 04:20:12 +00:00
|
|
|
imgCacheValidator(nsProgressNotificationProxy* progress, imgLoader* loader,
|
2015-03-24 02:37:45 +00:00
|
|
|
imgRequest* aRequest, nsISupports* aContext,
|
|
|
|
bool forcePrincipalCheckForCacheEntry);
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2015-04-07 21:49:00 +00:00
|
|
|
void AddProxy(imgRequestProxy* aProxy);
|
2002-01-15 05:23:33 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2013-09-28 18:28:42 +00:00
|
|
|
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
2002-01-15 05:23:33 +00:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
2011-07-01 17:03:38 +00:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
|
2002-01-15 05:23:33 +00:00
|
|
|
|
|
|
|
private:
|
2014-06-23 18:49:08 +00:00
|
|
|
virtual ~imgCacheValidator();
|
|
|
|
|
2002-01-15 05:23:33 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> mDestListener;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsProgressNotificationProxy> mProgressProxy;
|
2011-07-01 17:03:38 +00:00
|
|
|
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
|
|
|
|
nsCOMPtr<nsIChannel> mRedirectChannel;
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> mRequest;
|
2005-06-01 18:28:20 +00:00
|
|
|
nsCOMArray<imgIRequest> mProxies;
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> mNewRequest;
|
|
|
|
RefPtr<imgCacheEntry> mNewEntry;
|
2011-07-01 17:03:38 +00:00
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
nsCOMPtr<nsISupports> mContext;
|
2008-09-04 23:00:42 +00:00
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
imgLoader* mImgLoader;
|
2014-12-16 01:40:43 +00:00
|
|
|
|
|
|
|
bool mHadInsecureRedirect;
|
2002-01-15 05:23:33 +00:00
|
|
|
};
|
2010-08-14 04:09:48 +00:00
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#endif // mozilla_image_imgLoader_h
|