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
|
|
|
|
2015-03-25 10:59:00 -07:00
|
|
|
#ifndef mozilla_image_src_imgRequestProxy_h
|
|
|
|
#define mozilla_image_src_imgRequestProxy_h
|
2010-05-14 13:47:59 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "imgIRequest.h"
|
2008-09-01 13:53:59 -07:00
|
|
|
#include "nsISecurityInfoProvider.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#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"
|
2013-10-15 18:35:44 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "imgRequest.h"
|
2015-01-07 01:35:20 -08:00
|
|
|
#include "IProgressObserver.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define NS_IMGREQUESTPROXY_CID \
|
|
|
|
{ /* 20557898-1dd2-11b2-8f65-9c462ee2bc95 */ \
|
|
|
|
0x20557898, \
|
|
|
|
0x1dd2, \
|
|
|
|
0x11b2, \
|
|
|
|
{0x8f, 0x65, 0x9c, 0x46, 0x2e, 0xe2, 0xbc, 0x95} \
|
|
|
|
}
|
|
|
|
|
2013-09-07 06:01:08 -07:00
|
|
|
class imgINotificationObserver;
|
2010-07-28 14:52:14 -07:00
|
|
|
class imgStatusNotifyRunnable;
|
2014-06-18 17:57:51 -07:00
|
|
|
struct nsIntRect;
|
2012-10-19 12:39:38 -07:00
|
|
|
class ProxyBehaviour;
|
2010-07-28 14:52:14 -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
|
|
|
|
|
2013-03-29 13:14:19 -07:00
|
|
|
class imgRequestProxy : public imgIRequest,
|
2015-01-07 01:35:20 -08:00
|
|
|
public mozilla::image::IProgressObserver,
|
2013-03-29 13:14:19 -07:00
|
|
|
public nsISupportsPriority,
|
2011-06-09 14:11:57 -07:00
|
|
|
public nsISecurityInfoProvider,
|
2015-01-07 01:35:20 -08:00
|
|
|
public nsITimedChannel
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-06-23 11:49:08 -07:00
|
|
|
protected:
|
|
|
|
virtual ~imgRequestProxy();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(imgRequestProxy)
|
2007-03-22 10:30:00 -07:00
|
|
|
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();
|
|
|
|
|
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.
|
2012-12-19 13:28:54 -08:00
|
|
|
nsresult Init(imgRequest* aOwner,
|
2015-03-25 10:59:00 -07:00
|
|
|
nsILoadGroup* aLoadGroup,
|
2013-09-28 11:28:42 -07:00
|
|
|
ImageURL* aURI,
|
2015-03-25 10:59:00 -07:00
|
|
|
imgINotificationObserver* aObserver);
|
2010-05-10 20:27:41 -07:00
|
|
|
|
2015-03-25 10:59:00 -07:00
|
|
|
nsresult ChangeOwner(imgRequest* aNewOwner); // this will change mOwner.
|
|
|
|
// Do not call this if the
|
|
|
|
// previous owner has already
|
|
|
|
// sent notifications out!
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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 {
|
2012-07-30 07:20:58 -07:00
|
|
|
return mListener != nullptr;
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2015-01-07 01:35:20 -08:00
|
|
|
// imgINotificationObserver methods:
|
|
|
|
virtual void Notify(int32_t aType,
|
2015-03-21 09:28:04 -07:00
|
|
|
const nsIntRect* aRect = nullptr) override;
|
|
|
|
virtual void OnLoadComplete(bool aLastPart) override;
|
2015-01-07 01:35:20 -08:00
|
|
|
|
|
|
|
// imgIOnloadBlocker methods:
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void BlockOnload() override;
|
|
|
|
virtual void UnblockOnload() override;
|
2015-01-07 01:35:20 -08:00
|
|
|
|
|
|
|
// Other, internal-only methods:
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void SetHasImage() override;
|
|
|
|
virtual void OnStartDecode() override;
|
2015-01-07 01:35:20 -08:00
|
|
|
|
2014-11-14 20:10:47 -08:00
|
|
|
// Whether we want notifications from ProgressTracker to be deferred until
|
2010-08-02 12:44:49 -07:00
|
|
|
// an event it has scheduled has been fired.
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool NotificationsDeferred() const override
|
2010-08-02 12:44:49 -07:00
|
|
|
{
|
|
|
|
return mDeferNotifications;
|
|
|
|
}
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void SetNotificationsDeferred(bool aDeferNotifications) override
|
2010-08-02 12:44:49 -07:00
|
|
|
{
|
|
|
|
mDeferNotifications = aDeferNotifications;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2015-03-25 10:59:00 -07:00
|
|
|
virtual nsresult Clone(imgINotificationObserver* aObserver,
|
|
|
|
imgRequestProxy** aClone);
|
2012-10-12 05:43:01 -07:00
|
|
|
nsresult GetStaticRequest(imgRequestProxy** aReturn);
|
|
|
|
|
2015-03-25 10:59:00 -07:00
|
|
|
nsresult GetURI(ImageURL** aURI);
|
2013-09-28 11:28:42 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2014-11-14 20:10:47 -08:00
|
|
|
friend class mozilla::image::ProgressTracker;
|
2010-07-28 14:52:14 -07:00
|
|
|
friend class imgStatusNotifyRunnable;
|
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)
|
2015-03-25 10:59:00 -07:00
|
|
|
{ }
|
2008-12-19 14:35:50 -08:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD Run() override {
|
2008-12-19 14:35:50 -08:00
|
|
|
mOwner->DoCancel(mStatus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<imgRequestProxy> mOwner;
|
|
|
|
nsresult mStatus;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
2014-11-14 20:10:47 -08:00
|
|
|
// Return the ProgressTracker associated with mOwner and/or mImage. It may
|
2010-08-23 15:44:07 -07:00
|
|
|
// live either on mOwner or mImage, depending on whether
|
|
|
|
// (a) we have an mOwner at all
|
|
|
|
// (b) whether mOwner has instantiated its image yet
|
2014-11-14 20:10:47 -08:00
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker() const;
|
2010-08-23 15:44:07 -07:00
|
|
|
|
2011-06-09 14:11:57 -07:00
|
|
|
nsITimedChannel* TimedChannel()
|
|
|
|
{
|
2015-03-23 19:37:45 -07:00
|
|
|
if (!GetOwner()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2015-03-23 19:37:45 -07:00
|
|
|
}
|
|
|
|
return GetOwner()->GetTimedChannel();
|
2011-06-09 14:11:57 -07:00
|
|
|
}
|
|
|
|
|
2014-11-14 20:10:47 -08:00
|
|
|
already_AddRefed<Image> GetImage() const;
|
2013-09-28 11:28:44 -07:00
|
|
|
bool HasImage() const;
|
2012-10-19 12:39:38 -07:00
|
|
|
imgRequest* GetOwner() const;
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-10-12 09:11:22 -07:00
|
|
|
nsresult PerformClone(imgINotificationObserver* aObserver,
|
|
|
|
imgRequestProxy* (aAllocFn)(imgRequestProxy*),
|
2012-10-12 05:43:01 -07:00
|
|
|
imgRequestProxy** aClone);
|
2012-10-12 09:11:22 -07:00
|
|
|
|
2011-06-09 14:11:57 -07:00
|
|
|
public:
|
|
|
|
NS_FORWARD_SAFE_NSITIMEDCHANNEL(TimedChannel())
|
|
|
|
|
2012-10-19 12:39:38 -07:00
|
|
|
protected:
|
|
|
|
nsAutoPtr<ProxyBehaviour> mBehaviour;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
friend class imgCacheValidator;
|
2012-10-19 12:39:38 -07:00
|
|
|
friend imgRequestProxy* NewStaticProxy(imgRequestProxy* aThis);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-10 20:27:41 -07:00
|
|
|
// The URI of our request.
|
2013-09-28 11:28:42 -07:00
|
|
|
nsRefPtr<ImageURL> mURI;
|
2010-05-10 20:27:41 -07:00
|
|
|
|
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.
|
2012-10-12 09:11:22 -07:00
|
|
|
imgINotificationObserver* mListener;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
|
|
|
|
|
|
nsLoadFlags mLoadFlags;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mLockCount;
|
|
|
|
uint32_t 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;
|
2012-10-11 18:34:22 -07:00
|
|
|
};
|
|
|
|
|
2012-10-12 09:11:20 -07:00
|
|
|
// Used for static image proxies for which no requests are available, so
|
|
|
|
// certain behaviours must be overridden to compensate.
|
|
|
|
class imgRequestProxyStatic : public imgRequestProxy
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2014-11-14 20:10:47 -08:00
|
|
|
imgRequestProxyStatic(Image* aImage, nsIPrincipal* aPrincipal);
|
2012-10-12 09:11:20 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD GetImagePrincipal(nsIPrincipal** aPrincipal) override;
|
2012-10-12 09:11:20 -07:00
|
|
|
|
2013-06-04 11:38:37 -07:00
|
|
|
using imgRequestProxy::Clone;
|
|
|
|
|
|
|
|
virtual nsresult Clone(imgINotificationObserver* aObserver,
|
2015-03-21 09:28:04 -07:00
|
|
|
imgRequestProxy** aClone) override;
|
2012-10-12 09:11:22 -07:00
|
|
|
|
2012-10-12 09:11:20 -07:00
|
|
|
protected:
|
2012-10-12 09:11:22 -07:00
|
|
|
friend imgRequestProxy* NewStaticProxy(imgRequestProxy*);
|
|
|
|
|
2012-10-12 09:11:20 -07:00
|
|
|
// Our principal. We have to cache it, rather than accessing the underlying
|
|
|
|
// request on-demand, because static proxies don't have an underlying request.
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
};
|
|
|
|
|
2015-03-25 10:59:00 -07:00
|
|
|
#endif // mozilla_image_src_imgRequestProxy_h
|