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"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIStreamListener.h"
|
2013-09-28 11:28:42 -07:00
|
|
|
#include "nsIThreadRetargetableStreamListener.h"
|
2007-11-08 18:55:41 -08:00
|
|
|
#include "nsIPrincipal.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-20 16:08:06 -08:00
|
|
|
#include "nsAutoPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2013-09-28 11:28:42 -07:00
|
|
|
#include "nsProxyRelease.h"
|
2013-09-25 00:27:54 -07:00
|
|
|
#include "nsStringGlue.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2010-08-04 19:15:55 -07:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class imgCacheValidator;
|
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;
|
2013-09-07 06:01:08 -07:00
|
|
|
class nsIApplicationCache;
|
|
|
|
class nsIProperties;
|
|
|
|
class nsIRequest;
|
|
|
|
class nsITimedChannel;
|
|
|
|
class nsIURI;
|
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;
|
2013-09-28 11:28:42 -07:00
|
|
|
class ImageURL;
|
2014-11-14 20:10:47 -08:00
|
|
|
class ProgressTracker;
|
2012-01-06 08:02:27 -08:00
|
|
|
} // namespace image
|
2010-08-13 21:09:48 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-08-05 10:33:55 -07:00
|
|
|
class imgRequest MOZ_FINAL : public nsIStreamListener,
|
|
|
|
public nsIThreadRetargetableStreamListener,
|
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIAsyncVerifyRedirectCallback
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-06-23 11:49:08 -07:00
|
|
|
virtual ~imgRequest();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2014-11-14 20:10:47 -08:00
|
|
|
typedef mozilla::image::Image Image;
|
2013-09-28 11:28:42 -07:00
|
|
|
typedef mozilla::image::ImageURL ImageURL;
|
2014-11-14 20:10:47 -08:00
|
|
|
typedef mozilla::image::ProgressTracker ProgressTracker;
|
|
|
|
|
2014-08-05 14:58:18 -07:00
|
|
|
explicit imgRequest(imgLoader* aLoader);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-09-28 11:28:42 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
2014-09-05 14:36:11 -07:00
|
|
|
void ClearLoader();
|
|
|
|
|
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
|
|
|
|
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);
|
|
|
|
|
2013-10-15 16:33:11 -07:00
|
|
|
// Called or dispatched by cancel for main thread only execution.
|
|
|
|
void ContinueCancel(nsresult aStatus);
|
|
|
|
|
2014-06-08 15:15:00 -07:00
|
|
|
// Called or dispatched by EvictFromCache for main thread only execution.
|
|
|
|
void ContinueEvict();
|
|
|
|
|
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-11-08 10:54:00 -08:00
|
|
|
// Check if application cache of the original load is different from
|
|
|
|
// application cache of the new load. Also lack of application cache
|
|
|
|
// on one of the loads is considered a change of a loading cache since
|
|
|
|
// HTTP cache may contain a different data then app cache.
|
|
|
|
bool CacheChanged(nsIRequest* aNewRequest);
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-11-14 20:10:47 -08:00
|
|
|
// Return the ProgressTracker associated with this imgRequest. It may live
|
|
|
|
// in |mProgressTracker| or in |mImage.mProgressTracker|, depending on whether
|
2012-10-12 09:11:21 -07:00
|
|
|
// mImage has been instantiated yet.
|
2014-11-14 20:10:47 -08:00
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker();
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-10-12 09:11:20 -07:00
|
|
|
// Get the current principal of the image. No AddRefing.
|
2012-12-09 09:23:19 -08:00
|
|
|
inline nsIPrincipal* GetPrincipal() const { return mPrincipal.get(); }
|
2012-10-12 09:11:20 -07:00
|
|
|
|
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();
|
|
|
|
|
2013-09-28 11:28:42 -07:00
|
|
|
// OK to use on any thread.
|
|
|
|
nsresult GetURI(ImageURL **aURI);
|
2014-11-10 14:06:24 -08:00
|
|
|
nsresult GetCurrentURI(nsIURI **aURI);
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2014-07-18 18:47:11 -07:00
|
|
|
nsresult GetImageErrorCode(void);
|
|
|
|
|
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;
|
2009-01-30 18:17:47 -08:00
|
|
|
friend class imgCacheExpirationTracker;
|
2010-07-28 14:52:14 -07:00
|
|
|
friend class imgRequestNotifyRunnable;
|
2014-11-14 20:10:47 -08:00
|
|
|
friend class mozilla::image::ProgressTracker;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
inline void SetLoadId(void *aLoadId) {
|
|
|
|
mLoadId = aLoadId;
|
|
|
|
}
|
|
|
|
void Cancel(nsresult aStatus);
|
2014-06-08 15:15:00 -07:00
|
|
|
void EvictFromCache();
|
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;
|
|
|
|
}
|
2013-03-29 13:14:19 -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
|
|
|
|
2014-09-05 14:36:11 -07:00
|
|
|
bool HasConsumers();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2013-09-28 11:28:42 -07:00
|
|
|
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
|
|
|
2013-09-28 11:28:42 -07:00
|
|
|
// Sets properties for this image; will dispatch to main thread if needed.
|
|
|
|
void SetProperties(nsIChannel* aChan);
|
|
|
|
|
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
|
2013-09-28 11:28:42 -07:00
|
|
|
// keyed on in the cache. We store a string here to avoid off main thread
|
|
|
|
// refcounting issues with nsStandardURL.
|
|
|
|
nsRefPtr<ImageURL> 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;
|
2014-11-14 20:10:47 -08:00
|
|
|
// Progress tracker -- transferred to mImage, when it gets instantiated.
|
|
|
|
nsRefPtr<ProgressTracker> mProgressTracker;
|
|
|
|
nsRefPtr<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;
|
2012-11-08 10:54:00 -08:00
|
|
|
nsCOMPtr<nsIApplicationCache> mApplicationCache;
|
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;
|
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
|
|
|
|
2014-07-18 18:47:11 -07:00
|
|
|
nsresult mImageErrorCode;
|
|
|
|
|
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
|