Bug 1102048 (Part 20, imgLoader) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth

This commit is contained in:
Glenn Randers-Pehrson 2015-04-07 14:49:00 -07:00
parent 5b06f4967b
commit 2d13dfa2f6
2 changed files with 638 additions and 453 deletions

File diff suppressed because it is too large Load Diff

View File

@ -4,8 +4,8 @@
* 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/. */
#ifndef imgLoader_h__
#define imgLoader_h__
#ifndef mozilla_image_src_imgLoader_h
#define mozilla_image_src_imgLoader_h
#include "mozilla/Attributes.h"
#include "mozilla/Mutex.h"
@ -40,13 +40,15 @@ class ImageURL;
class imgCacheEntry
{
public:
imgCacheEntry(imgLoader* loader, imgRequest *request, bool aForcePrincipalCheck);
imgCacheEntry(imgLoader* loader, imgRequest* request,
bool aForcePrincipalCheck);
~imgCacheEntry();
nsrefcnt AddRef()
{
NS_PRECONDITION(int32_t(mRefCnt) >= 0, "illegal refcnt");
MOZ_ASSERT(_mOwningThread.GetThread() == PR_GetCurrentThread(), "imgCacheEntry addref isn't thread-safe!");
MOZ_ASSERT(_mOwningThread.GetThread() == PR_GetCurrentThread(),
"imgCacheEntry addref isn't thread-safe!");
++mRefCnt;
NS_LOG_ADDREF(this, mRefCnt, "imgCacheEntry", sizeof(*this));
return mRefCnt;
@ -55,7 +57,8 @@ public:
nsrefcnt Release()
{
NS_PRECONDITION(0 != mRefCnt, "dup release");
MOZ_ASSERT(_mOwningThread.GetThread() == PR_GetCurrentThread(), "imgCacheEntry release isn't thread-safe!");
MOZ_ASSERT(_mOwningThread.GetThread() == PR_GetCurrentThread(),
"imgCacheEntry release isn't thread-safe!");
--mRefCnt;
NS_LOG_RELEASE(this, mRefCnt, "imgCacheEntry");
if (mRefCnt == 0) {
@ -118,7 +121,7 @@ public:
return mEvicted;
}
nsExpirationState *GetExpirationState()
nsExpirationState* GetExpirationState()
{
return &mExpirationState;
}
@ -182,8 +185,8 @@ class imgCacheQueue
{
public:
imgCacheQueue();
void Remove(imgCacheEntry *);
void Push(imgCacheEntry *);
void Remove(imgCacheEntry*);
void Push(imgCacheEntry*);
void MarkDirty();
bool IsDirty();
already_AddRefed<imgCacheEntry> Pop();
@ -246,36 +249,39 @@ public:
// to just call CallCreateInstance() which will init
// the image module instead of calling new imgLoader
// directly.
imgILoader *loader;
imgILoader* loader;
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);
}
static already_AddRefed<imgLoader> GetInstance();
static already_AddRefed<imgLoader>
GetInstance();
nsresult LoadImage(nsIURI *aURI,
nsIURI *aInitialDocumentURI,
nsIURI *aReferrerURI,
nsresult LoadImage(nsIURI* aURI,
nsIURI* aInitialDocumentURI,
nsIURI* aReferrerURI,
ReferrerPolicy aReferrerPolicy,
nsIPrincipal* aLoadingPrincipal,
nsILoadGroup *aLoadGroup,
imgINotificationObserver *aObserver,
nsISupports *aCX,
nsILoadGroup* aLoadGroup,
imgINotificationObserver* aObserver,
nsISupports* aCX,
nsLoadFlags aLoadFlags,
nsISupports *aCacheKey,
nsISupports* aCacheKey,
nsContentPolicyType aContentPolicyType,
const nsAString& initiatorType,
imgRequestProxy **_retval);
imgRequestProxy** _retval);
nsresult LoadImageWithChannel(nsIChannel *channel,
imgINotificationObserver *aObserver,
nsISupports *aCX,
nsIStreamListener **listener,
imgRequestProxy **_retval);
nsresult LoadImageWithChannel(nsIChannel* channel,
imgINotificationObserver* aObserver,
nsISupports* aCX,
nsIStreamListener** listener,
imgRequestProxy** _retval);
static nsresult GetMimeTypeFromContent(const char* aContents, uint32_t aLength, nsACString& aContentType);
static nsresult GetMimeTypeFromContent(const char* aContents,
uint32_t aLength,
nsACString& aContentType);
/**
* Returns true if the given mime type may be interpreted as an image.
@ -283,7 +289,8 @@ public:
* 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
* MIME types should pass AcceptedMimeTypes::IMAGES_AND_DOCUMENTS for @aAccept.
* MIME types should pass AcceptedMimeTypes::IMAGES_AND_DOCUMENTS for
* @aAccept.
*
* @param aMimeType The MIME type to evaluate.
* @param aAcceptedMimeTypes Which kinds of MIME types to treat as images.
@ -302,14 +309,14 @@ public:
nsresult InitCache();
bool RemoveFromCache(nsIURI *aKey);
bool RemoveFromCache(ImageURL *aKey);
bool RemoveFromCache(nsCString &spec,
imgCacheTable &cache,
imgCacheQueue &queue);
bool RemoveFromCache(imgCacheEntry *entry);
bool RemoveFromCache(nsIURI* aKey);
bool RemoveFromCache(ImageURL* aKey);
bool RemoveFromCache(nsCString& spec,
imgCacheTable& cache,
imgCacheQueue& queue);
bool RemoveFromCache(imgCacheEntry* entry);
bool PutIntoCache(nsIURI *key, imgCacheEntry *entry);
bool PutIntoCache(nsIURI* key, imgCacheEntry* entry);
void AddToUncachedImages(imgRequest* aRequest);
void RemoveFromUncachedImages(imgRequest* aRequest);
@ -317,13 +324,15 @@ public:
// Returns true if we should prefer evicting cache entry |two| over cache
// entry |one|.
// This mixes units in the worst way, but provides reasonable results.
inline static bool CompareCacheEntries(const nsRefPtr<imgCacheEntry> &one,
const nsRefPtr<imgCacheEntry> &two)
inline static bool CompareCacheEntries(const nsRefPtr<imgCacheEntry>& one,
const nsRefPtr<imgCacheEntry>& two)
{
if (!one)
if (!one) {
return false;
if (!two)
}
if (!two) {
return true;
}
const double sizeweight = 1.0 - sCacheTimeWeight;
@ -351,50 +360,52 @@ public:
// 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.
bool SetHasNoProxies(imgRequest *aRequest, imgCacheEntry *aEntry);
bool SetHasProxies(imgRequest *aRequest);
bool SetHasNoProxies(imgRequest* aRequest, imgCacheEntry* aEntry);
bool SetHasProxies(imgRequest* aRequest);
private: // methods
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 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);
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);
nsresult CreateNewProxyForRequest(imgRequest* aRequest,
nsILoadGroup* aLoadGroup,
imgINotificationObserver* aObserver,
nsLoadFlags aLoadFlags,
imgRequestProxy** _retval);
void ReadAcceptHeaderPref();
nsresult EvictEntries(imgCacheTable &aCacheToClear);
nsresult EvictEntries(imgCacheQueue &aQueueToClear);
nsresult EvictEntries(imgCacheTable& aCacheToClear);
nsresult EvictEntries(imgCacheQueue& aQueueToClear);
imgCacheTable &GetCache(nsIURI *aURI);
imgCacheQueue &GetCacheQueue(nsIURI *aURI);
imgCacheTable &GetCache(ImageURL *aURI);
imgCacheQueue &GetCacheQueue(ImageURL *aURI);
void CacheEntriesChanged(ImageURL *aURI, int32_t sizediff = 0);
void CheckCacheLimits(imgCacheTable &cache, imgCacheQueue &queue);
imgCacheTable& GetCache(nsIURI* aURI);
imgCacheQueue& GetCacheQueue(nsIURI* aURI);
imgCacheTable& GetCache(ImageURL* aURI);
imgCacheQueue& GetCacheQueue(ImageURL* aURI);
void CacheEntriesChanged(ImageURL* aURI, int32_t sizediff = 0);
void CheckCacheLimits(imgCacheTable& cache, imgCacheQueue& queue);
private: // data
friend class imgCacheEntry;
@ -440,7 +451,7 @@ class ProxyListener : public nsIStreamListener
, public nsIThreadRetargetableStreamListener
{
public:
explicit ProxyListener(nsIStreamListener *dest);
explicit ProxyListener(nsIStreamListener* dest);
/* additional members */
NS_DECL_THREADSAFE_ISUPPORTS
@ -477,7 +488,7 @@ class nsProgressNotificationProxy final
NS_DECL_NSICHANNELEVENTSINK
NS_DECL_NSIINTERFACEREQUESTOR
private:
~nsProgressNotificationProxy() {}
~nsProgressNotificationProxy() { }
nsCOMPtr<nsIInterfaceRequestor> mOriginalCallbacks;
nsCOMPtr<nsIRequest> mImageRequest;
@ -500,7 +511,7 @@ public:
imgRequest* aRequest, nsISupports* aContext,
bool forcePrincipalCheckForCacheEntry);
void AddProxy(imgRequestProxy *aProxy);
void AddProxy(imgRequestProxy* aProxy);
NS_DECL_ISUPPORTS
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
@ -531,4 +542,4 @@ private:
bool mHadInsecureRedirect;
};
#endif // imgLoader_h__
#endif // mozilla_image_src_imgLoader_h