/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * 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/. */
class imgLoader final : public imgILoader, public nsIContentSniffer, public imgICache, public nsSupportsWeakReference, public nsIObserver { virtual ~imgLoader();
public: using ImageCacheKey = mozilla::image::ImageCacheKey; using imgCacheTable =
nsRefPtrHashtable<nsGenericHashKey<ImageCacheKey>, imgCacheEntry>; using imgSet = nsTHashSet<imgRequest*>; using Mutex = mozilla::Mutex;
/** * 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();
/** * Gecko code should use NormalLoader() or PrivateBrowsingLoader() to get the * appropriate image loader. * * 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.
*/
imgLoader();
nsresult Init();
/** * 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 * 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.
*/ staticbool SupportImageWithMimeType( const nsACString&, AcceptedMimeTypes aAccept = AcceptedMimeTypes::IMAGES);
staticvoid GlobalInit(); // for use by the factory staticvoid Shutdown(); // for use by the factory staticvoid ShutdownMemoryReporter();
// 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. enumclass QueueState { MaybeExists, AlreadyRemoved };
// 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. inlinestaticbool CompareCacheEntries(const RefPtr<imgCacheEntry>& one, const RefPtr<imgCacheEntry>& two) { if (!one) { returnfalse;
} if (!two) { returntrue;
}
constdouble 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;
// 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 // imgRequestProxies watching their imgRequests. // // Once an imgRequest has no imgRequestProxies, it should notify us by // calling HasNoObservers(), and null out its cache entry pointer. // // 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. bool SetHasNoProxies(imgRequest* aRequest, imgCacheEntry* aEntry); bool SetHasProxies(imgRequest* aRequest);
void NotifyObserversForCachedImage(
imgCacheEntry* aEntry, imgRequest* request, nsIURI* aURI,
nsIReferrerInfo* aReferrerInfo, mozilla::dom::Document* aLoadingDocument,
nsIPrincipal* aTriggeringPrincipal, mozilla::CORSMode,
uint64_t aEarlyHintPreloaderId,
mozilla::dom::FetchPriority aFetchPriority); // aURI may be different from imgRequest's URI in the case of blob URIs, as we // can share requests with different URIs.
nsresult CreateNewProxyForRequest(imgRequest* aRequest, nsIURI* aURI,
nsILoadGroup* aLoadGroup,
mozilla::dom::Document* aLoadingDocument,
imgINotificationObserver* aObserver,
nsLoadFlags aLoadFlags,
imgRequestProxy** _retval);
private: // data friendclass imgCacheEntry; friendclass imgMemoryReporter;
imgCacheTable mCache;
imgCacheQueue mCacheQueue;
// 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 MOZ_GUARDED_BY(mUncachedImagesMutex); // 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;
class ProxyListener : public nsIThreadRetargetableStreamListener { public: explicit ProxyListener(nsIStreamListener* dest);
/* additional members */
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER
private: virtual ~ProxyListener();
nsCOMPtr<nsIStreamListener> mDestListener;
};
/** * 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.
*/ class nsProgressNotificationProxy final : public nsIProgressEventSink, public nsIChannelEventSink, public nsIInterfaceRequestor { public:
nsProgressNotificationProxy(nsIChannel* channel, imgIRequest* proxy)
: mImageRequest(proxy) {
channel->GetNotificationCallbacks(getter_AddRefs(mOriginalCallbacks));
}
class imgCacheValidator : public nsIThreadRetargetableStreamListener, public nsIChannelEventSink, public nsIInterfaceRequestor, public nsIAsyncVerifyRedirectCallback { public:
imgCacheValidator(nsProgressNotificationProxy* progress, imgLoader* loader,
imgRequest* aRequest, mozilla::dom::Document* aDocument,
uint64_t aInnerWindowId, bool forcePrincipalCheckForCacheEntry);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.