2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef imgRequest_h__
|
|
|
|
#define imgRequest_h__
|
|
|
|
|
|
|
|
#include "imgIDecoderObserver.h"
|
|
|
|
|
2008-12-22 14:20:46 -08:00
|
|
|
#include "nsIChannelEventSink.h"
|
2007-09-02 09:10:57 -07:00
|
|
|
#include "nsIContentSniffer.h"
|
2008-12-22 14:20:46 -08:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIRequest.h"
|
|
|
|
#include "nsIProperties.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIURI.h"
|
2007-11-08 18:55:41 -08:00
|
|
|
#include "nsIPrincipal.h"
|
2011-06-09 14:11:57 -07:00
|
|
|
#include "nsITimedChannel.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-02 09:10:57 -07:00
|
|
|
#include "nsCategoryCache.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
2007-09-22 12:40:57 -07:00
|
|
|
#include "nsTObserverArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsWeakReference.h"
|
2009-12-10 20:02:13 -08:00
|
|
|
#include "ImageErrors.h"
|
|
|
|
#include "imgIRequest.h"
|
2010-08-23 15:44:07 -07:00
|
|
|
#include "imgStatusTracker.h"
|
2010-08-04 19:15:55 -07:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class imgCacheValidator;
|
|
|
|
|
|
|
|
class imgRequestProxy;
|
2008-09-04 16:00:42 -07:00
|
|
|
class imgCacheEntry;
|
2010-05-21 21:10:14 -07:00
|
|
|
class imgMemoryReporter;
|
2010-07-28 14:52:14 -07:00
|
|
|
class imgRequestNotifyRunnable;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-13 21:09:48 -07:00
|
|
|
namespace mozilla {
|
2012-01-06 08:02:27 -08:00
|
|
|
namespace image {
|
2010-08-13 21:09:48 -07:00
|
|
|
class Image;
|
2012-01-06 08:02:27 -08:00
|
|
|
} // namespace image
|
2010-08-13 21:09:48 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
class imgRequest : public imgIDecoderObserver,
|
2007-03-22 10:30:00 -07:00
|
|
|
public nsIStreamListener,
|
2008-12-22 14:20:46 -08:00
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsIChannelEventSink,
|
2010-08-04 19:15:55 -07:00
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIAsyncVerifyRedirectCallback
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
imgRequest();
|
|
|
|
virtual ~imgRequest();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsresult Init(nsIURI *aURI,
|
2011-07-01 10:03:40 -07:00
|
|
|
nsIURI *aCurrentURI,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIRequest *aRequest,
|
2008-12-22 14:20:46 -08:00
|
|
|
nsIChannel *aChannel,
|
2008-09-04 16:00:42 -07:00
|
|
|
imgCacheEntry *aCacheEntry,
|
2011-07-14 11:47:32 -07:00
|
|
|
void *aLoadId,
|
2011-07-14 11:47:34 -07:00
|
|
|
nsIPrincipal* aLoadingPrincipal,
|
|
|
|
PRInt32 aCORSMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-10 20:27:41 -07:00
|
|
|
// Callers must call imgRequestProxy::Notify later.
|
2007-09-22 12:40:57 -07:00
|
|
|
nsresult AddProxy(imgRequestProxy *proxy);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// aNotify==false still sends OnStopRequest.
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult RemoveProxy(imgRequestProxy *proxy, nsresult aStatus, bool aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void SniffMimeType(const char *buf, PRUint32 len);
|
|
|
|
|
2008-12-22 14:20:46 -08:00
|
|
|
// Cancel, but also ensure that all work done in Init() is undone. Call this
|
|
|
|
// only when the channel has failed to open, and so calling Cancel() on it
|
|
|
|
// won't be sufficient.
|
|
|
|
void CancelAndAbort(nsresult aStatus);
|
|
|
|
|
2010-08-13 21:09:48 -07:00
|
|
|
// Methods that get forwarded to the Image, or deferred until it's
|
2009-09-15 17:33:14 -07:00
|
|
|
// instantiated.
|
|
|
|
nsresult LockImage();
|
|
|
|
nsresult UnlockImage();
|
|
|
|
nsresult RequestDecode();
|
2010-05-14 13:47:59 -07:00
|
|
|
|
2011-08-24 13:44:35 -07:00
|
|
|
inline void SetInnerWindowID(PRUint64 aInnerWindowId) {
|
|
|
|
mInnerWindowId = aInnerWindowId;
|
2010-12-20 08:21:59 -08:00
|
|
|
}
|
|
|
|
|
2011-08-24 13:44:35 -07:00
|
|
|
inline PRUint64 InnerWindowID() const {
|
|
|
|
return mInnerWindowId;
|
2010-12-20 08:21:59 -08:00
|
|
|
}
|
|
|
|
|
2011-07-01 10:03:33 -07:00
|
|
|
// Set the cache validation information (expiry time, whether we must
|
|
|
|
// validate, etc) on the cache entry based on the request information.
|
|
|
|
// If this function is called multiple times, the information set earliest
|
|
|
|
// wins.
|
|
|
|
static void SetCacheValidation(imgCacheEntry* aEntry, nsIRequest* aRequest);
|
|
|
|
|
2012-05-19 12:32:37 -07:00
|
|
|
bool GetMultipart() const { return mIsMultiPartChannel; }
|
|
|
|
|
2011-07-14 11:47:34 -07:00
|
|
|
// The CORS mode for which we loaded this image.
|
|
|
|
PRInt32 GetCORSMode() const { return mCORSMode; }
|
|
|
|
|
2011-07-14 11:47:32 -07:00
|
|
|
// The principal for the document that loaded this image. Used when trying to
|
|
|
|
// validate a CORS image load.
|
|
|
|
already_AddRefed<nsIPrincipal> GetLoadingPrincipal() const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = mLoadingPrincipal;
|
|
|
|
return principal.forget();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2008-09-04 16:00:42 -07:00
|
|
|
friend class imgCacheEntry;
|
2007-03-22 10:30:00 -07:00
|
|
|
friend class imgRequestProxy;
|
|
|
|
friend class imgLoader;
|
|
|
|
friend class imgCacheValidator;
|
2010-07-28 14:52:34 -07:00
|
|
|
friend class imgStatusTracker;
|
2009-01-30 18:17:47 -08:00
|
|
|
friend class imgCacheExpirationTracker;
|
2010-07-28 14:52:14 -07:00
|
|
|
friend class imgRequestNotifyRunnable;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
inline void SetLoadId(void *aLoadId) {
|
|
|
|
mLoadId = aLoadId;
|
|
|
|
}
|
|
|
|
void Cancel(nsresult aStatus);
|
2010-05-14 13:47:59 -07:00
|
|
|
void RemoveFromCache();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult GetURI(nsIURI **aURI);
|
2008-09-01 13:53:59 -07:00
|
|
|
nsresult GetSecurityInfo(nsISupports **aSecurityInfo);
|
2010-05-14 13:47:59 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
inline const char *GetMimeType() const {
|
|
|
|
return mContentType.get();
|
|
|
|
}
|
|
|
|
inline nsIProperties *Properties() {
|
|
|
|
return mProperties;
|
|
|
|
}
|
|
|
|
|
2010-08-23 15:44:07 -07:00
|
|
|
// Return the imgStatusTracker associated with this imgRequest. It may live
|
|
|
|
// in |mStatusTracker| or in |mImage.mStatusTracker|, depending on whether
|
|
|
|
// mImage has been instantiated yet..
|
|
|
|
imgStatusTracker& GetStatusTracker();
|
|
|
|
|
2009-01-30 18:17:47 -08:00
|
|
|
// Reset the cache entry after we've dropped our reference to it. Used by the
|
|
|
|
// imgLoader when our cache entry is re-requested after we've dropped our
|
|
|
|
// reference to it.
|
|
|
|
void SetCacheEntry(imgCacheEntry *entry);
|
|
|
|
|
|
|
|
// Returns whether we've got a reference to the cache entry.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasCacheEntry() const;
|
2009-01-30 18:17:47 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Return true if at least one of our proxies, excluding
|
|
|
|
// aProxyToIgnore, has an observer. aProxyToIgnore may be null.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HaveProxyWithObserver(imgRequestProxy* aProxyToIgnore) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Return the priority of the underlying network request, or return
|
|
|
|
// PRIORITY_NORMAL if it doesn't support nsISupportsPriority.
|
|
|
|
PRInt32 Priority() const;
|
|
|
|
|
|
|
|
// Adjust the priority of the underlying network request by the given delta
|
|
|
|
// on behalf of the given proxy.
|
|
|
|
void AdjustPriority(imgRequestProxy *aProxy, PRInt32 aDelta);
|
|
|
|
|
2009-02-16 06:11:30 -08:00
|
|
|
// Return whether we've seen some data at this point
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasTransferredData() const { return mGotData; }
|
2009-02-16 06:11:30 -08:00
|
|
|
|
2009-03-17 14:07:16 -07:00
|
|
|
// Set whether this request is stored in the cache. If it isn't, regardless
|
|
|
|
// of whether this request has a non-null mCacheEntry, this imgRequest won't
|
|
|
|
// try to update or modify the image cache.
|
2011-09-28 23:19:26 -07:00
|
|
|
void SetIsInCache(bool cacheable);
|
2009-03-04 19:56:14 -08:00
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
// Update the cache entry size based on the image container
|
|
|
|
void UpdateCacheEntrySize();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
NS_DECL_IMGIDECODEROBSERVER
|
|
|
|
NS_DECL_IMGICONTAINEROBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
2008-12-22 14:20:46 -08:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2010-08-04 19:15:55 -07:00
|
|
|
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
private:
|
2010-05-21 21:10:14 -07:00
|
|
|
friend class imgMemoryReporter;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIRequest> mRequest;
|
2011-07-01 10:03:40 -07:00
|
|
|
// The original URI we were loaded with. This is the same as the URI we are
|
|
|
|
// keyed on in the cache.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2011-07-01 10:03:40 -07:00
|
|
|
// The URI of the resource we ended up loading after all redirects, etc.
|
|
|
|
nsCOMPtr<nsIURI> mCurrentURI;
|
2011-07-14 11:47:32 -07:00
|
|
|
// The principal of the document which loaded this image. Used when validating for CORS.
|
|
|
|
nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
|
|
|
|
// The principal of this image.
|
2007-11-08 18:55:41 -08:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2010-08-23 15:44:07 -07:00
|
|
|
// Status-tracker -- transferred to mImage, when it gets instantiated
|
|
|
|
nsAutoPtr<imgStatusTracker> mStatusTracker;
|
2012-01-06 08:02:27 -08:00
|
|
|
nsRefPtr<mozilla::image::Image> mImage;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIProperties> mProperties;
|
2008-09-01 13:53:59 -07:00
|
|
|
nsCOMPtr<nsISupports> mSecurityInfo;
|
2008-12-22 14:20:46 -08:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mPrevChannelSink;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
nsTObserverArray<imgRequestProxy*> mObservers;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-09 14:11:57 -07:00
|
|
|
nsCOMPtr<nsITimedChannel> mTimedChannel;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCString mContentType;
|
|
|
|
|
2008-09-04 16:00:42 -07:00
|
|
|
nsRefPtr<imgCacheEntry> mCacheEntry; /* we hold on to this to this so long as we have observers */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void *mLoadId;
|
|
|
|
|
|
|
|
imgCacheValidator *mValidator;
|
2007-09-02 09:10:57 -07:00
|
|
|
nsCategoryCache<nsIContentSniffer> mImageSniffers;
|
2010-08-04 19:15:55 -07:00
|
|
|
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
|
|
|
|
nsCOMPtr<nsIChannel> mNewRedirectChannel;
|
2010-12-20 08:21:59 -08:00
|
|
|
|
2011-08-24 13:44:35 -07:00
|
|
|
// The ID of the inner window origin, used for error reporting.
|
|
|
|
PRUint64 mInnerWindowId;
|
2010-12-20 08:21:59 -08:00
|
|
|
|
2011-07-14 11:47:34 -07:00
|
|
|
// The CORS mode (defined in imgIRequest) this image was loaded with. By
|
|
|
|
// default, imgIRequest::CORS_NONE.
|
|
|
|
PRInt32 mCORSMode;
|
|
|
|
|
2009-09-15 17:33:14 -07:00
|
|
|
// Sometimes consumers want to do things before the image is ready. Let them,
|
|
|
|
// and apply the action when the image becomes available.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDecodeRequested : 1;
|
2009-09-15 17:33:14 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsMultiPartChannel : 1;
|
|
|
|
bool mGotData : 1;
|
|
|
|
bool mIsInCache : 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|