2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Stuart Parmenter <pavlov@netscape.com>
|
2009-09-12 15:44:18 -07:00
|
|
|
* Bobby Holley <bobbyholley@gmail.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#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 {
|
|
|
|
namespace imagelib {
|
|
|
|
class Image;
|
|
|
|
} // namespace imagelib
|
|
|
|
} // 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,
|
2007-03-22 10:30:00 -07:00
|
|
|
void *aCacheId,
|
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
|
|
|
|
|
|
|
// aNotify==PR_FALSE still sends OnStopRequest.
|
|
|
|
nsresult RemoveProxy(imgRequestProxy *proxy, nsresult aStatus, PRBool aNotify);
|
|
|
|
|
|
|
|
void SniffMimeType(const char *buf, PRUint32 len);
|
|
|
|
|
|
|
|
// a request is "reusable" if it has already been loaded, or it is
|
|
|
|
// currently being loaded on the same event queue as the new request
|
|
|
|
// being made...
|
2010-08-13 21:09:48 -07:00
|
|
|
PRBool IsReusable(void *aCacheId);
|
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();
|
|
|
|
nsresult RequestDecode();
|
2010-05-14 13:47:59 -07:00
|
|
|
|
2010-12-20 08:21:59 -08:00
|
|
|
inline void SetWindowID(PRUint64 aWindowId) {
|
|
|
|
mWindowId = aWindowId;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PRUint64 WindowID() const {
|
|
|
|
return mWindowId;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
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-12-23 17:31:30 -08:00
|
|
|
nsresult GetKeyURI(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.
|
|
|
|
PRBool HasCacheEntry() const;
|
|
|
|
|
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.
|
|
|
|
PRBool HaveProxyWithObserver(imgRequestProxy* aProxyToIgnore) const;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
PRBool HasTransferredData() const { return mGotData; }
|
|
|
|
|
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.
|
|
|
|
void SetIsInCache(PRBool 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;
|
2010-08-13 21:09:48 -07:00
|
|
|
nsRefPtr<mozilla::imagelib::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 *mCacheId;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// Originating outer window ID. Used for error reporting.
|
|
|
|
PRUint64 mWindowId;
|
|
|
|
|
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.
|
|
|
|
PRPackedBool mDecodeRequested : 1;
|
|
|
|
|
2009-03-04 19:56:14 -08:00
|
|
|
PRPackedBool mIsMultiPartChannel : 1;
|
|
|
|
PRPackedBool mGotData : 1;
|
2009-03-17 14:07:16 -07:00
|
|
|
PRPackedBool mIsInCache : 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|