2001-02-20 22:43:56 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00: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/. */
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#ifndef mozilla_image_imgRequestProxy_h
|
|
|
|
#define mozilla_image_imgRequestProxy_h
|
2010-05-14 20:47:59 +00:00
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
#include "imgIRequest.h"
|
2008-09-01 20:53:59 +00:00
|
|
|
#include "nsISecurityInfoProvider.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2001-03-06 04:46:20 +00:00
|
|
|
#include "nsILoadGroup.h"
|
2005-02-21 20:58:01 +00:00
|
|
|
#include "nsISupportsPriority.h"
|
2011-06-09 21:11:57 +00:00
|
|
|
#include "nsITimedChannel.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2008-12-19 22:35:50 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2013-10-16 01:35:44 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2015-10-17 10:53:28 +00:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2015-04-21 15:04:57 +00:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
#include "imgRequest.h"
|
2015-01-07 09:35:20 +00:00
|
|
|
#include "IProgressObserver.h"
|
2001-10-12 06:43:52 +00:00
|
|
|
|
2001-02-20 23:35:22 +00:00
|
|
|
#define NS_IMGREQUESTPROXY_CID \
|
2001-02-20 22:43:56 +00:00
|
|
|
{ /* 20557898-1dd2-11b2-8f65-9c462ee2bc95 */ \
|
|
|
|
0x20557898, \
|
|
|
|
0x1dd2, \
|
|
|
|
0x11b2, \
|
|
|
|
{0x8f, 0x65, 0x9c, 0x46, 0x2e, 0xe2, 0xbc, 0x95} \
|
|
|
|
}
|
|
|
|
|
2013-09-07 13:01:08 +00:00
|
|
|
class imgINotificationObserver;
|
2010-07-28 21:52:14 +00:00
|
|
|
class imgStatusNotifyRunnable;
|
2012-10-19 19:39:38 +00:00
|
|
|
class ProxyBehaviour;
|
2010-07-28 21:52:14 +00:00
|
|
|
|
2010-08-14 04:09:48 +00:00
|
|
|
namespace mozilla {
|
2012-01-06 16:02:27 +00:00
|
|
|
namespace image {
|
2010-08-14 04:09:48 +00:00
|
|
|
class Image;
|
2013-09-28 18:28:42 +00:00
|
|
|
class ImageURL;
|
2014-11-15 04:10:47 +00:00
|
|
|
class ProgressTracker;
|
2012-01-06 16:02:27 +00:00
|
|
|
} // namespace image
|
2010-08-14 04:09:48 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-03-29 20:14:19 +00:00
|
|
|
class imgRequestProxy : public imgIRequest,
|
2015-01-07 09:35:20 +00:00
|
|
|
public mozilla::image::IProgressObserver,
|
2013-03-29 20:14:19 +00:00
|
|
|
public nsISupportsPriority,
|
2011-06-09 21:11:57 +00:00
|
|
|
public nsISecurityInfoProvider,
|
2015-01-07 09:35:20 +00:00
|
|
|
public nsITimedChannel
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2014-06-23 18:49:08 +00:00
|
|
|
protected:
|
|
|
|
virtual ~imgRequestProxy();
|
|
|
|
|
2001-02-20 22:43:56 +00:00
|
|
|
public:
|
2014-11-15 04:10:47 +00:00
|
|
|
typedef mozilla::image::Image Image;
|
2013-09-28 18:28:42 +00:00
|
|
|
typedef mozilla::image::ImageURL ImageURL;
|
2014-11-15 04:10:47 +00:00
|
|
|
typedef mozilla::image::ProgressTracker ProgressTracker;
|
|
|
|
|
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(imgRequestProxy)
|
2001-02-20 22:43:56 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2001-02-20 23:27:48 +00:00
|
|
|
NS_DECL_IMGIREQUEST
|
2001-03-06 04:46:20 +00:00
|
|
|
NS_DECL_NSIREQUEST
|
2005-02-21 20:58:01 +00:00
|
|
|
NS_DECL_NSISUPPORTSPRIORITY
|
2008-09-01 20:53:59 +00:00
|
|
|
NS_DECL_NSISECURITYINFOPROVIDER
|
2011-06-09 21:11:57 +00:00
|
|
|
// nsITimedChannel declared below
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2001-02-20 23:27:48 +00:00
|
|
|
imgRequestProxy();
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2010-05-11 03:27:41 +00:00
|
|
|
// Callers to Init or ChangeOwner are required to call NotifyListener after
|
|
|
|
// (although not immediately after) doing so.
|
2012-12-19 21:28:54 +00:00
|
|
|
nsresult Init(imgRequest* aOwner,
|
2015-03-25 17:59:00 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
2013-09-28 18:28:42 +00:00
|
|
|
ImageURL* aURI,
|
2015-03-25 17:59:00 +00:00
|
|
|
imgINotificationObserver* aObserver);
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
nsresult ChangeOwner(imgRequest* aNewOwner); // this will change mOwner.
|
|
|
|
// Do not call this if the
|
|
|
|
// previous owner has already
|
|
|
|
// sent notifications out!
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2003-05-14 05:42:06 +00:00
|
|
|
void AddToLoadGroup();
|
2011-09-29 06:19:26 +00:00
|
|
|
void RemoveFromLoadGroup(bool releaseLoadGroup);
|
2003-05-14 05:42:06 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
inline bool HasObserver() const {
|
2012-07-30 14:20:58 +00:00
|
|
|
return mListener != nullptr;
|
2010-05-14 20:47:59 +00:00
|
|
|
}
|
|
|
|
|
2010-07-28 21:52:14 +00: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 20:47:59 +00:00
|
|
|
void NotifyListener();
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2010-07-28 21:52:14 +00: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 09:35:20 +00:00
|
|
|
// imgINotificationObserver methods:
|
|
|
|
virtual void Notify(int32_t aType,
|
2015-04-21 15:04:57 +00:00
|
|
|
const mozilla::gfx::IntRect* aRect = nullptr) override;
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void OnLoadComplete(bool aLastPart) override;
|
2015-01-07 09:35:20 +00:00
|
|
|
|
|
|
|
// imgIOnloadBlocker methods:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void BlockOnload() override;
|
|
|
|
virtual void UnblockOnload() override;
|
2015-01-07 09:35:20 +00:00
|
|
|
|
|
|
|
// Other, internal-only methods:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void SetHasImage() override;
|
2015-01-07 09:35:20 +00:00
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
// Whether we want notifications from ProgressTracker to be deferred until
|
2010-08-02 19:44:49 +00:00
|
|
|
// an event it has scheduled has been fired.
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool NotificationsDeferred() const override
|
2010-08-02 19:44:49 +00:00
|
|
|
{
|
|
|
|
return mDeferNotifications;
|
|
|
|
}
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void SetNotificationsDeferred(bool aDeferNotifications) override
|
2010-08-02 19:44:49 +00:00
|
|
|
{
|
|
|
|
mDeferNotifications = aDeferNotifications;
|
|
|
|
}
|
|
|
|
|
2010-09-08 00:33:02 +00: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 17:59:00 +00:00
|
|
|
virtual nsresult Clone(imgINotificationObserver* aObserver,
|
|
|
|
imgRequestProxy** aClone);
|
2012-10-12 12:43:01 +00:00
|
|
|
nsresult GetStaticRequest(imgRequestProxy** aReturn);
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
nsresult GetURI(ImageURL** aURI);
|
2013-09-28 18:28:42 +00:00
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
protected:
|
2014-11-15 04:10:47 +00:00
|
|
|
friend class mozilla::image::ProgressTracker;
|
2010-07-28 21:52:14 +00:00
|
|
|
friend class imgStatusNotifyRunnable;
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2008-12-19 22:35:50 +00:00
|
|
|
class imgCancelRunnable;
|
|
|
|
friend class imgCancelRunnable;
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class imgCancelRunnable : public mozilla::Runnable
|
2008-12-19 22:35:50 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
imgCancelRunnable(imgRequestProxy* owner, nsresult status)
|
|
|
|
: mOwner(owner), mStatus(status)
|
2015-03-25 17:59:00 +00:00
|
|
|
{ }
|
2008-12-19 22:35:50 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD Run() override {
|
2008-12-19 22:35:50 +00:00
|
|
|
mOwner->DoCancel(mStatus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequestProxy> mOwner;
|
2008-12-19 22:35:50 +00:00
|
|
|
nsresult mStatus;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Finish up canceling ourselves */
|
|
|
|
void DoCancel(nsresult status);
|
|
|
|
|
2008-03-19 19:07:59 +00:00
|
|
|
/* Do the proper refcount management to null out mListener */
|
|
|
|
void NullOutListener();
|
2010-03-08 19:34:52 +00:00
|
|
|
|
|
|
|
void DoRemoveFromLoadGroup() {
|
2011-10-17 14:59:28 +00:00
|
|
|
RemoveFromLoadGroup(true);
|
2010-03-08 19:34:52 +00:00
|
|
|
}
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
// Return the ProgressTracker associated with mOwner and/or mImage. It may
|
2010-08-23 22:44:07 +00: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-15 04:10:47 +00:00
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker() const;
|
2010-08-23 22:44:07 +00:00
|
|
|
|
2011-06-09 21:11:57 +00:00
|
|
|
nsITimedChannel* TimedChannel()
|
|
|
|
{
|
2015-03-24 02:37:45 +00:00
|
|
|
if (!GetOwner()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2015-03-24 02:37:45 +00:00
|
|
|
}
|
|
|
|
return GetOwner()->GetTimedChannel();
|
2011-06-09 21:11:57 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
already_AddRefed<Image> GetImage() const;
|
2013-09-28 18:28:44 +00:00
|
|
|
bool HasImage() const;
|
2012-10-19 19:39:38 +00:00
|
|
|
imgRequest* GetOwner() const;
|
2012-10-12 16:11:21 +00:00
|
|
|
|
2012-10-12 16:11:22 +00:00
|
|
|
nsresult PerformClone(imgINotificationObserver* aObserver,
|
|
|
|
imgRequestProxy* (aAllocFn)(imgRequestProxy*),
|
2012-10-12 12:43:01 +00:00
|
|
|
imgRequestProxy** aClone);
|
2012-10-12 16:11:22 +00:00
|
|
|
|
2011-06-09 21:11:57 +00:00
|
|
|
public:
|
|
|
|
NS_FORWARD_SAFE_NSITIMEDCHANNEL(TimedChannel())
|
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
protected:
|
2015-10-17 10:53:28 +00:00
|
|
|
mozilla::UniquePtr<ProxyBehaviour> mBehaviour;
|
2012-10-19 19:39:38 +00:00
|
|
|
|
2001-02-20 22:43:56 +00:00
|
|
|
private:
|
2002-12-24 14:30:12 +00:00
|
|
|
friend class imgCacheValidator;
|
2012-10-19 19:39:38 +00:00
|
|
|
friend imgRequestProxy* NewStaticProxy(imgRequestProxy* aThis);
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2010-05-11 03:27:41 +00:00
|
|
|
// The URI of our request.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ImageURL> mURI;
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2008-03-19 19:07:59 +00: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.
|
2015-06-15 18:21:00 +00:00
|
|
|
imgINotificationObserver* MOZ_UNSAFE_REF("Observers must call Cancel() or "
|
|
|
|
"CancelAndForgetObserver() before "
|
|
|
|
"they are destroyed") mListener;
|
|
|
|
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
2001-03-06 04:46:20 +00:00
|
|
|
|
2001-07-17 01:14:40 +00:00
|
|
|
nsLoadFlags mLoadFlags;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mLockCount;
|
|
|
|
uint32_t mAnimationConsumers;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mCanceled;
|
|
|
|
bool mIsInLoadGroup;
|
|
|
|
bool mListenerIsStrongRef;
|
|
|
|
bool mDecodeRequested;
|
2010-07-28 21:52:14 +00:00
|
|
|
|
|
|
|
// Whether we want to defer our notifications by the non-virtual Observer
|
|
|
|
// interfaces as image loads proceed.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mDeferNotifications;
|
2012-10-12 01:34:22 +00:00
|
|
|
};
|
|
|
|
|
2012-10-12 16:11:20 +00: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-15 04:10:47 +00:00
|
|
|
imgRequestProxyStatic(Image* aImage, nsIPrincipal* aPrincipal);
|
2012-10-12 16:11:20 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD GetImagePrincipal(nsIPrincipal** aPrincipal) override;
|
2012-10-12 16:11:20 +00:00
|
|
|
|
2013-06-04 18:38:37 +00:00
|
|
|
using imgRequestProxy::Clone;
|
|
|
|
|
|
|
|
virtual nsresult Clone(imgINotificationObserver* aObserver,
|
2015-03-21 16:28:04 +00:00
|
|
|
imgRequestProxy** aClone) override;
|
2012-10-12 16:11:22 +00:00
|
|
|
|
2012-10-12 16:11:20 +00:00
|
|
|
protected:
|
2012-10-12 16:11:22 +00:00
|
|
|
friend imgRequestProxy* NewStaticProxy(imgRequestProxy*);
|
|
|
|
|
2012-10-12 16:11:20 +00: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-05-15 03:52:05 +00:00
|
|
|
#endif // mozilla_image_imgRequestProxy_h
|