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>
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
2010-05-14 13:47:59 -07:00
|
|
|
#ifndef imgRequestProxy_h__
|
|
|
|
#define imgRequestProxy_h__
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "imgIRequest.h"
|
|
|
|
#include "imgIDecoderObserver.h"
|
2008-09-01 13:53:59 -07:00
|
|
|
#include "nsISecurityInfoProvider.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIRequestObserver.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsILoadGroup.h"
|
|
|
|
#include "nsISupportsPriority.h"
|
2011-06-09 14:11:57 -07:00
|
|
|
#include "nsITimedChannel.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2007-09-22 12:40:57 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2008-12-19 14:35:50 -08:00
|
|
|
#include "nsThreadUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "imgRequest.h"
|
|
|
|
|
|
|
|
#define NS_IMGREQUESTPROXY_CID \
|
|
|
|
{ /* 20557898-1dd2-11b2-8f65-9c462ee2bc95 */ \
|
|
|
|
0x20557898, \
|
|
|
|
0x1dd2, \
|
|
|
|
0x11b2, \
|
|
|
|
{0x8f, 0x65, 0x9c, 0x46, 0x2e, 0xe2, 0xbc, 0x95} \
|
|
|
|
}
|
|
|
|
|
2010-07-28 14:52:14 -07:00
|
|
|
class imgRequestNotifyRunnable;
|
|
|
|
class imgStatusNotifyRunnable;
|
|
|
|
|
2010-08-13 21:09:48 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace imagelib {
|
|
|
|
class Image;
|
|
|
|
} // namespace imagelib
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-06-09 14:11:57 -07:00
|
|
|
class imgRequestProxy : public imgIRequest,
|
|
|
|
public nsISupportsPriority,
|
|
|
|
public nsISecurityInfoProvider,
|
|
|
|
public nsITimedChannel
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_IMGIREQUEST
|
|
|
|
NS_DECL_NSIREQUEST
|
|
|
|
NS_DECL_NSISUPPORTSPRIORITY
|
2008-09-01 13:53:59 -07:00
|
|
|
NS_DECL_NSISECURITYINFOPROVIDER
|
2011-06-09 14:11:57 -07:00
|
|
|
// nsITimedChannel declared below
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
imgRequestProxy();
|
|
|
|
virtual ~imgRequestProxy();
|
|
|
|
|
2010-05-10 20:27:41 -07:00
|
|
|
// Callers to Init or ChangeOwner are required to call NotifyListener after
|
|
|
|
// (although not immediately after) doing so.
|
2010-08-13 21:09:48 -07:00
|
|
|
nsresult Init(imgRequest *request, nsILoadGroup *aLoadGroup,
|
|
|
|
mozilla::imagelib::Image* aImage,
|
2010-05-14 13:47:59 -07:00
|
|
|
nsIURI* aURI, imgIDecoderObserver *aObserver);
|
2010-05-10 20:27:41 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult ChangeOwner(imgRequest *aNewOwner); // this will change mOwner. Do not call this if the previous
|
|
|
|
// owner has already sent notifications out!
|
|
|
|
|
|
|
|
void AddToLoadGroup();
|
2011-09-28 23:19:26 -07:00
|
|
|
void RemoveFromLoadGroup(bool releaseLoadGroup);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool HasObserver() const {
|
2010-05-14 13:47:59 -07:00
|
|
|
return mListener != nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPrincipal(nsIPrincipal *aPrincipal);
|
|
|
|
|
2010-07-28 14:52:14 -07:00
|
|
|
// Asynchronously notify this proxy's listener of the current state of the
|
|
|
|
// image, and, if we have an imgRequest mOwner, any status changes that
|
|
|
|
// happen between the time this function is called and the time the
|
|
|
|
// notification is scheduled.
|
2010-05-14 13:47:59 -07:00
|
|
|
void NotifyListener();
|
2010-05-10 20:27:41 -07:00
|
|
|
|
2010-07-28 14:52:14 -07:00
|
|
|
// Synchronously notify this proxy's listener of the current state of the
|
|
|
|
// image. Only use this function if you are currently servicing an
|
|
|
|
// asynchronously-called function.
|
|
|
|
void SyncNotifyListener();
|
|
|
|
|
2010-08-02 12:44:49 -07:00
|
|
|
// Whether we want notifications from imgStatusTracker to be deferred until
|
|
|
|
// an event it has scheduled has been fired.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool NotificationsDeferred() const
|
2010-08-02 12:44:49 -07:00
|
|
|
{
|
|
|
|
return mDeferNotifications;
|
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
void SetNotificationsDeferred(bool aDeferNotifications)
|
2010-08-02 12:44:49 -07:00
|
|
|
{
|
|
|
|
mDeferNotifications = aDeferNotifications;
|
|
|
|
}
|
|
|
|
|
2010-08-23 15:44:07 -07:00
|
|
|
// Setter for our |mImage| pointer, for imgRequest to use, once it
|
|
|
|
// instantiates an Image.
|
|
|
|
void SetImage(mozilla::imagelib::Image* aImage);
|
|
|
|
|
2010-09-07 17:33:02 -07:00
|
|
|
// Removes all animation consumers that were created with
|
|
|
|
// IncrementAnimationConsumers. This is necessary since we need
|
|
|
|
// to do it before the proxy itself is destroyed. See
|
|
|
|
// imgRequest::RemoveProxy
|
|
|
|
void ClearAnimationConsumers();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2010-05-14 13:47:59 -07:00
|
|
|
friend class imgStatusTracker;
|
2010-07-28 14:52:14 -07:00
|
|
|
friend class imgStatusNotifyRunnable;
|
|
|
|
friend class imgRequestNotifyRunnable;
|
2010-05-10 20:27:41 -07:00
|
|
|
|
2008-12-19 14:35:50 -08:00
|
|
|
class imgCancelRunnable;
|
|
|
|
friend class imgCancelRunnable;
|
|
|
|
|
|
|
|
class imgCancelRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
imgCancelRunnable(imgRequestProxy* owner, nsresult status)
|
|
|
|
: mOwner(owner), mStatus(status)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
mOwner->DoCancel(mStatus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<imgRequestProxy> mOwner;
|
|
|
|
nsresult mStatus;
|
|
|
|
};
|
|
|
|
|
2010-07-28 14:52:14 -07:00
|
|
|
// The following notification functions are protected to ensure that (friend
|
|
|
|
// class) imgStatusTracker is the only class allowed to send us
|
|
|
|
// notifications.
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* non-virtual imgIDecoderObserver methods */
|
2011-11-09 13:39:15 -08:00
|
|
|
void OnStartDecode ();
|
|
|
|
void OnStartContainer (imgIContainer *aContainer);
|
|
|
|
void OnStartFrame (PRUint32 aFrame);
|
|
|
|
void OnDataAvailable (bool aCurrentFrame, const nsIntRect * aRect);
|
|
|
|
void OnStopFrame (PRUint32 aFrame);
|
|
|
|
void OnStopContainer (imgIContainer *aContainer);
|
|
|
|
void OnStopDecode (nsresult status, const PRUnichar *statusArg);
|
|
|
|
void OnDiscard ();
|
|
|
|
void OnImageIsAnimated ();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* non-virtual imgIContainerObserver methods */
|
2010-08-13 21:09:48 -07:00
|
|
|
void FrameChanged(imgIContainer *aContainer,
|
|
|
|
const nsIntRect *aDirtyRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-10 20:25:11 -07:00
|
|
|
/* non-virtual sort-of-nsIRequestObserver methods */
|
|
|
|
void OnStartRequest();
|
2011-09-28 23:19:26 -07:00
|
|
|
void OnStopRequest(bool aLastPart);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-19 14:35:50 -08:00
|
|
|
/* Finish up canceling ourselves */
|
|
|
|
void DoCancel(nsresult status);
|
|
|
|
|
2008-03-19 12:07:59 -07:00
|
|
|
/* Do the proper refcount management to null out mListener */
|
|
|
|
void NullOutListener();
|
2010-03-08 11:34:52 -08:00
|
|
|
|
|
|
|
void DoRemoveFromLoadGroup() {
|
2011-10-17 07:59:28 -07:00
|
|
|
RemoveFromLoadGroup(true);
|
2010-03-08 11:34:52 -08:00
|
|
|
}
|
2010-05-10 20:27:41 -07:00
|
|
|
|
2010-08-23 15:44:07 -07:00
|
|
|
// Return the imgStatusTracker associated with mOwner and/or mImage. It may
|
|
|
|
// live either on mOwner or mImage, depending on whether
|
|
|
|
// (a) we have an mOwner at all
|
|
|
|
// (b) whether mOwner has instantiated its image yet
|
|
|
|
imgStatusTracker& GetStatusTracker();
|
|
|
|
|
2011-06-09 14:11:57 -07:00
|
|
|
nsITimedChannel* TimedChannel()
|
|
|
|
{
|
|
|
|
if (!mOwner)
|
|
|
|
return nsnull;
|
|
|
|
return mOwner->mTimedChannel;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_FORWARD_SAFE_NSITIMEDCHANNEL(TimedChannel())
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
friend class imgCacheValidator;
|
|
|
|
|
2007-09-22 12:40:57 -07:00
|
|
|
// We maintain the following invariant:
|
|
|
|
// The proxy is registered at most with a single imgRequest as an observer,
|
|
|
|
// and whenever it is, mOwner points to that object. This helps ensure that
|
|
|
|
// imgRequestProxy::~imgRequestProxy unregisters the proxy as an observer
|
|
|
|
// from whatever request it was registered with (if any). This, in turn,
|
|
|
|
// means that imgRequest::mObservers will not have any stale pointers in it.
|
|
|
|
nsRefPtr<imgRequest> mOwner;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-10 20:27:41 -07:00
|
|
|
// The URI of our request.
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
|
|
|
|
// The image we represent. Is null until data has been received, and is then
|
|
|
|
// set by imgRequest.
|
2010-08-13 21:09:48 -07:00
|
|
|
nsRefPtr<mozilla::imagelib::Image> mImage;
|
2010-05-10 20:27:41 -07:00
|
|
|
|
|
|
|
// Our principal. Is null until data has been received from the channel, and
|
|
|
|
// is then set by imgRequest.
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
|
2008-03-19 12:07:59 -07:00
|
|
|
// mListener is only promised to be a weak ref (see imgILoader.idl),
|
|
|
|
// but we actually keep a strong ref to it until we've seen our
|
|
|
|
// first OnStopRequest.
|
|
|
|
imgIDecoderObserver* mListener;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
|
|
|
|
|
|
nsLoadFlags mLoadFlags;
|
2010-08-25 23:21:34 -07:00
|
|
|
PRUint32 mLockCount;
|
2010-09-07 17:33:02 -07:00
|
|
|
PRUint32 mAnimationConsumers;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mCanceled;
|
|
|
|
bool mIsInLoadGroup;
|
|
|
|
bool mListenerIsStrongRef;
|
|
|
|
bool mDecodeRequested;
|
2010-07-28 14:52:14 -07:00
|
|
|
|
|
|
|
// Whether we want to defer our notifications by the non-virtual Observer
|
|
|
|
// interfaces as image loads proceed.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDeferNotifications;
|
2010-08-12 08:59:37 -07:00
|
|
|
|
|
|
|
// We only want to send OnStartContainer once for each proxy, but we might
|
|
|
|
// get multiple OnStartContainer calls (e.g. from multipart/x-mixed-replace).
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mSentStartContainer;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
2010-05-14 13:47:59 -07:00
|
|
|
|
|
|
|
#endif // imgRequestProxy_h__
|