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 * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef imgLoader_h__ #ifndef mozilla_image_src_imgLoader_h
#define imgLoader_h__ #define mozilla_image_src_imgLoader_h
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/Mutex.h" #include "mozilla/Mutex.h"
@ -40,13 +40,15 @@ class ImageURL;
class imgCacheEntry class imgCacheEntry
{ {
public: public:
imgCacheEntry(imgLoader* loader, imgRequest *request, bool aForcePrincipalCheck); imgCacheEntry(imgLoader* loader, imgRequest* request,
bool aForcePrincipalCheck);
~imgCacheEntry(); ~imgCacheEntry();
nsrefcnt AddRef() nsrefcnt AddRef()
{ {
NS_PRECONDITION(int32_t(mRefCnt) >= 0, "illegal refcnt"); 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; ++mRefCnt;
NS_LOG_ADDREF(this, mRefCnt, "imgCacheEntry", sizeof(*this)); NS_LOG_ADDREF(this, mRefCnt, "imgCacheEntry", sizeof(*this));
return mRefCnt; return mRefCnt;
@ -55,7 +57,8 @@ public:
nsrefcnt Release() nsrefcnt Release()
{ {
NS_PRECONDITION(0 != mRefCnt, "dup 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; --mRefCnt;
NS_LOG_RELEASE(this, mRefCnt, "imgCacheEntry"); NS_LOG_RELEASE(this, mRefCnt, "imgCacheEntry");
if (mRefCnt == 0) { if (mRefCnt == 0) {
@ -118,7 +121,7 @@ public:
return mEvicted; return mEvicted;
} }
nsExpirationState *GetExpirationState() nsExpirationState* GetExpirationState()
{ {
return &mExpirationState; return &mExpirationState;
} }
@ -182,8 +185,8 @@ class imgCacheQueue
{ {
public: public:
imgCacheQueue(); imgCacheQueue();
void Remove(imgCacheEntry *); void Remove(imgCacheEntry*);
void Push(imgCacheEntry *); void Push(imgCacheEntry*);
void MarkDirty(); void MarkDirty();
bool IsDirty(); bool IsDirty();
already_AddRefed<imgCacheEntry> Pop(); already_AddRefed<imgCacheEntry> Pop();
@ -246,36 +249,39 @@ public:
// to just call CallCreateInstance() which will init // to just call CallCreateInstance() which will init
// the image module instead of calling new imgLoader // the image module instead of calling new imgLoader
// directly. // directly.
imgILoader *loader; imgILoader* loader;
CallCreateInstance("@mozilla.org/image/loader;1", &loader); CallCreateInstance("@mozilla.org/image/loader;1", &loader);
// There's only one imgLoader implementation so we // There's only one imgLoader implementation so we
// can safely cast to it. // can safely cast to it.
return static_cast<imgLoader*>(loader); return static_cast<imgLoader*>(loader);
} }
static already_AddRefed<imgLoader> GetInstance(); static already_AddRefed<imgLoader>
GetInstance();
nsresult LoadImage(nsIURI *aURI, nsresult LoadImage(nsIURI* aURI,
nsIURI *aInitialDocumentURI, nsIURI* aInitialDocumentURI,
nsIURI *aReferrerURI, nsIURI* aReferrerURI,
ReferrerPolicy aReferrerPolicy, ReferrerPolicy aReferrerPolicy,
nsIPrincipal* aLoadingPrincipal, nsIPrincipal* aLoadingPrincipal,
nsILoadGroup *aLoadGroup, nsILoadGroup* aLoadGroup,
imgINotificationObserver *aObserver, imgINotificationObserver* aObserver,
nsISupports *aCX, nsISupports* aCX,
nsLoadFlags aLoadFlags, nsLoadFlags aLoadFlags,
nsISupports *aCacheKey, nsISupports* aCacheKey,
nsContentPolicyType aContentPolicyType, nsContentPolicyType aContentPolicyType,
const nsAString& initiatorType, const nsAString& initiatorType,
imgRequestProxy **_retval); imgRequestProxy** _retval);
nsresult LoadImageWithChannel(nsIChannel *channel, nsresult LoadImageWithChannel(nsIChannel* channel,
imgINotificationObserver *aObserver, imgINotificationObserver* aObserver,
nsISupports *aCX, nsISupports* aCX,
nsIStreamListener **listener, nsIStreamListener** listener,
imgRequestProxy **_retval); 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. * 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 * 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 * 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 * 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 aMimeType The MIME type to evaluate.
* @param aAcceptedMimeTypes Which kinds of MIME types to treat as images. * @param aAcceptedMimeTypes Which kinds of MIME types to treat as images.
@ -302,14 +309,14 @@ public:
nsresult InitCache(); nsresult InitCache();
bool RemoveFromCache(nsIURI *aKey); bool RemoveFromCache(nsIURI* aKey);
bool RemoveFromCache(ImageURL *aKey); bool RemoveFromCache(ImageURL* aKey);
bool RemoveFromCache(nsCString &spec, bool RemoveFromCache(nsCString& spec,
imgCacheTable &cache, imgCacheTable& cache,
imgCacheQueue &queue); imgCacheQueue& queue);
bool RemoveFromCache(imgCacheEntry *entry); bool RemoveFromCache(imgCacheEntry* entry);
bool PutIntoCache(nsIURI *key, imgCacheEntry *entry); bool PutIntoCache(nsIURI* key, imgCacheEntry* entry);
void AddToUncachedImages(imgRequest* aRequest); void AddToUncachedImages(imgRequest* aRequest);
void RemoveFromUncachedImages(imgRequest* aRequest); void RemoveFromUncachedImages(imgRequest* aRequest);
@ -317,13 +324,15 @@ public:
// Returns true if we should prefer evicting cache entry |two| over cache // Returns true if we should prefer evicting cache entry |two| over cache
// entry |one|. // entry |one|.
// This mixes units in the worst way, but provides reasonable results. // This mixes units in the worst way, but provides reasonable results.
inline static bool CompareCacheEntries(const nsRefPtr<imgCacheEntry> &one, inline static bool CompareCacheEntries(const nsRefPtr<imgCacheEntry>& one,
const nsRefPtr<imgCacheEntry> &two) const nsRefPtr<imgCacheEntry>& two)
{ {
if (!one) if (!one) {
return false; return false;
if (!two) }
if (!two) {
return true; return true;
}
const double sizeweight = 1.0 - sCacheTimeWeight; const double sizeweight = 1.0 - sCacheTimeWeight;
@ -351,50 +360,52 @@ public:
// HasObservers(). The request's cache entry will be re-set before this // HasObservers(). The request's cache entry will be re-set before this
// happens, by calling imgRequest::SetCacheEntry() when an entry with no // happens, by calling imgRequest::SetCacheEntry() when an entry with no
// observers is re-requested. // observers is re-requested.
bool SetHasNoProxies(imgRequest *aRequest, imgCacheEntry *aEntry); bool SetHasNoProxies(imgRequest* aRequest, imgCacheEntry* aEntry);
bool SetHasProxies(imgRequest *aRequest); bool SetHasProxies(imgRequest* aRequest);
private: // methods private: // methods
bool ValidateEntry(imgCacheEntry *aEntry, nsIURI *aKey, bool ValidateEntry(imgCacheEntry* aEntry, nsIURI* aKey,
nsIURI *aInitialDocumentURI, nsIURI *aReferrerURI, nsIURI* aInitialDocumentURI, nsIURI* aReferrerURI,
ReferrerPolicy aReferrerPolicy, ReferrerPolicy aReferrerPolicy,
nsILoadGroup *aLoadGroup, nsILoadGroup* aLoadGroup,
imgINotificationObserver *aObserver, nsISupports *aCX, imgINotificationObserver* aObserver, nsISupports* aCX,
nsLoadFlags aLoadFlags, nsLoadFlags aLoadFlags,
nsContentPolicyType aContentPolicyType, nsContentPolicyType aContentPolicyType,
bool aCanMakeNewChannel, bool aCanMakeNewChannel,
imgRequestProxy **aProxyRequest, imgRequestProxy** aProxyRequest,
nsIPrincipal* aLoadingPrincipal, nsIPrincipal* aLoadingPrincipal,
int32_t aCORSMode); int32_t aCORSMode);
bool ValidateRequestWithNewChannel(imgRequest *request, nsIURI *aURI, bool ValidateRequestWithNewChannel(imgRequest* request, nsIURI* aURI,
nsIURI *aInitialDocumentURI, nsIURI* aInitialDocumentURI,
nsIURI *aReferrerURI, nsIURI* aReferrerURI,
ReferrerPolicy aReferrerPolicy, ReferrerPolicy aReferrerPolicy,
nsILoadGroup *aLoadGroup, nsILoadGroup* aLoadGroup,
imgINotificationObserver *aObserver, imgINotificationObserver* aObserver,
nsISupports *aCX, nsLoadFlags aLoadFlags, nsISupports* aCX, nsLoadFlags aLoadFlags,
nsContentPolicyType aContentPolicyType, nsContentPolicyType aContentPolicyType,
imgRequestProxy **aProxyRequest, imgRequestProxy** aProxyRequest,
nsIPrincipal* aLoadingPrincipal, nsIPrincipal* aLoadingPrincipal,
int32_t aCORSMode); int32_t aCORSMode);
nsresult CreateNewProxyForRequest(imgRequest *aRequest, nsILoadGroup *aLoadGroup, nsresult CreateNewProxyForRequest(imgRequest* aRequest,
imgINotificationObserver *aObserver, nsILoadGroup* aLoadGroup,
nsLoadFlags aLoadFlags, imgRequestProxy **_retval); imgINotificationObserver* aObserver,
nsLoadFlags aLoadFlags,
imgRequestProxy** _retval);
void ReadAcceptHeaderPref(); void ReadAcceptHeaderPref();
nsresult EvictEntries(imgCacheTable &aCacheToClear); nsresult EvictEntries(imgCacheTable& aCacheToClear);
nsresult EvictEntries(imgCacheQueue &aQueueToClear); nsresult EvictEntries(imgCacheQueue& aQueueToClear);
imgCacheTable &GetCache(nsIURI *aURI); imgCacheTable& GetCache(nsIURI* aURI);
imgCacheQueue &GetCacheQueue(nsIURI *aURI); imgCacheQueue& GetCacheQueue(nsIURI* aURI);
imgCacheTable &GetCache(ImageURL *aURI); imgCacheTable& GetCache(ImageURL* aURI);
imgCacheQueue &GetCacheQueue(ImageURL *aURI); imgCacheQueue& GetCacheQueue(ImageURL* aURI);
void CacheEntriesChanged(ImageURL *aURI, int32_t sizediff = 0); void CacheEntriesChanged(ImageURL* aURI, int32_t sizediff = 0);
void CheckCacheLimits(imgCacheTable &cache, imgCacheQueue &queue); void CheckCacheLimits(imgCacheTable& cache, imgCacheQueue& queue);
private: // data private: // data
friend class imgCacheEntry; friend class imgCacheEntry;
@ -440,7 +451,7 @@ class ProxyListener : public nsIStreamListener
, public nsIThreadRetargetableStreamListener , public nsIThreadRetargetableStreamListener
{ {
public: public:
explicit ProxyListener(nsIStreamListener *dest); explicit ProxyListener(nsIStreamListener* dest);
/* additional members */ /* additional members */
NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_THREADSAFE_ISUPPORTS
@ -477,7 +488,7 @@ class nsProgressNotificationProxy final
NS_DECL_NSICHANNELEVENTSINK NS_DECL_NSICHANNELEVENTSINK
NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSIINTERFACEREQUESTOR
private: private:
~nsProgressNotificationProxy() {} ~nsProgressNotificationProxy() { }
nsCOMPtr<nsIInterfaceRequestor> mOriginalCallbacks; nsCOMPtr<nsIInterfaceRequestor> mOriginalCallbacks;
nsCOMPtr<nsIRequest> mImageRequest; nsCOMPtr<nsIRequest> mImageRequest;
@ -500,7 +511,7 @@ public:
imgRequest* aRequest, nsISupports* aContext, imgRequest* aRequest, nsISupports* aContext,
bool forcePrincipalCheckForCacheEntry); bool forcePrincipalCheckForCacheEntry);
void AddProxy(imgRequestProxy *aProxy); void AddProxy(imgRequestProxy* aProxy);
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
@ -531,4 +542,4 @@ private:
bool mHadInsecureRedirect; bool mHadInsecureRedirect;
}; };
#endif // imgLoader_h__ #endif // mozilla_image_src_imgLoader_h