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__
|
|
|
|
|
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"
|
2012-10-07 11:01:08 -07:00
|
|
|
#include "nsStringGlue.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2009-12-10 20:02:13 -08:00
|
|
|
#include "imgIRequest.h"
|
2010-08-04 19:15:55 -07:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class imgCacheValidator;
|
2012-10-03 13:17:26 -07:00
|
|
|
class imgStatusTracker;
|
2012-06-25 21:20:12 -07:00
|
|
|
class imgLoader;
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
|
|
|
|
2012-10-12 09:11:21 -07:00
|
|
|
class imgRequest : public nsIStreamListener,
|
2008-12-22 14:20:46 -08:00
|
|
|
public nsIChannelEventSink,
|
2010-08-04 19:15:55 -07:00
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIAsyncVerifyRedirectCallback
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-06-25 21:20:12 -07:00
|
|
|
imgRequest(imgLoader* aLoader);
|
2007-03-22 10:30:00 -07:00
|
|
|
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,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aCORSMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-10 20:27:41 -07:00
|
|
|
// Callers must call imgRequestProxy::Notify later.
|
2012-10-03 15:39:59 -07:00
|
|
|
void AddProxy(imgRequestProxy *proxy);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-11 09:35:43 -07:00
|
|
|
nsresult RemoveProxy(imgRequestProxy *proxy, nsresult aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-06 15:05:23 -07:00
|
|
|
void SniffMimeType(const char *buf, uint32_t len, nsACString& newType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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();
|
2012-10-04 13:02:15 -07:00
|
|
|
nsresult StartDecoding();
|
2009-09-15 17:33:14 -07:00
|
|
|
nsresult RequestDecode();
|
2010-05-14 13:47:59 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
inline void SetInnerWindowID(uint64_t aInnerWindowId) {
|
2011-08-24 13:44:35 -07:00
|
|
|
mInnerWindowId = aInnerWindowId;
|
2010-12-20 08:21:59 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
inline uint64_t InnerWindowID() const {
|
2011-08-24 13:44:35 -07:00
|
|
|
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.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetCORSMode() const { return mCORSMode; }
|
2011-07-14 11:47:34 -07:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2012-10-12 09:11:21 -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();
|
|
|
|
|
2012-10-12 09:11:20 -07:00
|
|
|
// Get the current principal of the image. No AddRefing.
|
|
|
|
inline nsIPrincipal* GetPrincipal() const { return mPrincipal.get(); };
|
|
|
|
|
2012-10-12 09:11:21 -07:00
|
|
|
// Resize the cache entry to 0 if it exists
|
|
|
|
void ResetCacheEntry();
|
|
|
|
|
|
|
|
// Update the cache entry size based on the image container
|
|
|
|
void UpdateCacheEntrySize();
|
|
|
|
|
|
|
|
nsresult GetURI(nsIURI **aURI);
|
|
|
|
|
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();
|
|
|
|
|
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
|
|
|
|
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 the priority of the underlying network request, or return
|
|
|
|
// PRIORITY_NORMAL if it doesn't support nsISupportsPriority.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t Priority() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Adjust the priority of the underlying network request by the given delta
|
|
|
|
// on behalf of the given proxy.
|
2012-08-22 08:56:38 -07:00
|
|
|
void AdjustPriority(imgRequestProxy *aProxy, int32_t aDelta);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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
|
|
|
|
2012-10-12 09:11:21 -07:00
|
|
|
bool IsBlockingOnload() const;
|
|
|
|
void SetBlockingOnload(bool block) const;
|
2009-09-12 15:44:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
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;
|
|
|
|
|
2012-06-25 21:20:12 -07:00
|
|
|
// Weak reference to parent loader; this request cannot outlive its owner.
|
|
|
|
imgLoader* mLoader;
|
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
|
|
|
|
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.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t 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.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mCORSMode;
|
2011-07-14 11:47:34 -07:00
|
|
|
|
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;
|
2012-08-13 15:58:53 -07:00
|
|
|
bool mBlockingOnload : 1;
|
2012-09-06 15:05:23 -07:00
|
|
|
bool mResniffMimeType : 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|