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__
|
|
|
|
|
2010-07-28 14:52:14 -07:00
|
|
|
#include "imgContainer.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "imgIDecoder.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"
|
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-05-14 13:47:59 -07:00
|
|
|
#include "imgContainer.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
|
|
|
|
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,
|
|
|
|
public nsIInterfaceRequestor
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
imgRequest();
|
|
|
|
virtual ~imgRequest();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsresult Init(nsIURI *aURI,
|
2008-12-23 17:31:30 -08:00
|
|
|
nsIURI *aKeyURI,
|
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,
|
|
|
|
void *aLoadId);
|
|
|
|
|
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-05-14 13:47:59 -07:00
|
|
|
PRBool IsReusable(void *aCacheId) {
|
|
|
|
return (mImage && mImage->GetStatusTracker().IsLoading()) ||
|
|
|
|
(aCacheId == mCacheId);
|
|
|
|
}
|
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);
|
|
|
|
|
2009-09-15 17:33:14 -07:00
|
|
|
// Methods that get forwarded to the imgContainer, or deferred until it's
|
|
|
|
// instantiated.
|
|
|
|
nsresult LockImage();
|
|
|
|
nsresult UnlockImage();
|
|
|
|
nsresult RequestDecode();
|
2010-05-14 13:47:59 -07:00
|
|
|
|
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;
|
|
|
|
mLoadTime = PR_Now();
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
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;
|
2008-12-23 17:31:30 -08:00
|
|
|
// The original URI we were loaded with.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2008-12-23 17:31:30 -08:00
|
|
|
// The URI we are keyed on in the cache.
|
|
|
|
nsCOMPtr<nsIURI> mKeyURI;
|
2007-11-08 18:55:41 -08:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2010-05-14 13:47:59 -07:00
|
|
|
nsRefPtr<imgContainer> 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
|
|
|
|
|
|
|
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;
|
|
|
|
PRTime mLoadTime;
|
|
|
|
|
|
|
|
imgCacheValidator *mValidator;
|
2007-09-02 09:10:57 -07:00
|
|
|
nsCategoryCache<nsIContentSniffer> mImageSniffers;
|
2009-03-04 19:56:14 -08: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.
|
|
|
|
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
|