2001-02-21 01:43:56 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04: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-21 01:43:56 +03:00
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#ifndef mozilla_image_imgRequestProxy_h
|
|
|
|
#define mozilla_image_imgRequestProxy_h
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2001-10-12 10:43:52 +04:00
|
|
|
#include "imgIRequest.h"
|
2008-09-02 00:53:59 +04:00
|
|
|
#include "nsISecurityInfoProvider.h"
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2001-03-06 07:46:20 +03:00
|
|
|
#include "nsILoadGroup.h"
|
2005-02-21 23:58:01 +03:00
|
|
|
#include "nsISupportsPriority.h"
|
2011-06-10 01:11:57 +04:00
|
|
|
#include "nsITimedChannel.h"
|
2001-02-21 01:43:56 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2008-12-20 01:35:50 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2013-10-16 05:35:44 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2015-10-17 13:53:28 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2015-04-21 18:04:57 +03:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2001-10-12 10:43:52 +04:00
|
|
|
#include "imgRequest.h"
|
2015-01-07 12:35:20 +03:00
|
|
|
#include "IProgressObserver.h"
|
2001-10-12 10:43:52 +04:00
|
|
|
|
2001-02-21 02:35:22 +03:00
|
|
|
#define NS_IMGREQUESTPROXY_CID \
|
2001-02-21 01:43:56 +03:00
|
|
|
{ /* 20557898-1dd2-11b2-8f65-9c462ee2bc95 */ \
|
|
|
|
0x20557898, \
|
|
|
|
0x1dd2, \
|
|
|
|
0x11b2, \
|
|
|
|
{0x8f, 0x65, 0x9c, 0x46, 0x2e, 0xe2, 0xbc, 0x95} \
|
|
|
|
}
|
|
|
|
|
2018-02-07 15:27:27 +03:00
|
|
|
class imgCacheValidator;
|
2013-09-07 17:01:08 +04:00
|
|
|
class imgINotificationObserver;
|
2010-07-29 01:52:14 +04:00
|
|
|
class imgStatusNotifyRunnable;
|
2012-10-19 23:39:38 +04:00
|
|
|
class ProxyBehaviour;
|
2010-07-29 01:52:14 +04:00
|
|
|
|
2010-08-14 08:09:48 +04:00
|
|
|
namespace mozilla {
|
2017-07-19 21:15:11 +03:00
|
|
|
namespace dom {
|
|
|
|
class TabGroup;
|
|
|
|
}
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2010-08-14 08:09:48 +04:00
|
|
|
class Image;
|
2013-09-28 22:28:42 +04:00
|
|
|
class ImageURL;
|
2014-11-15 07:10:47 +03:00
|
|
|
class ProgressTracker;
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-08-14 08:09:48 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-03-30 00:14:19 +04:00
|
|
|
class imgRequestProxy : public imgIRequest,
|
2015-01-07 12:35:20 +03:00
|
|
|
public mozilla::image::IProgressObserver,
|
2013-03-30 00:14:19 +04:00
|
|
|
public nsISupportsPriority,
|
2011-06-10 01:11:57 +04:00
|
|
|
public nsISecurityInfoProvider,
|
2015-01-07 12:35:20 +03:00
|
|
|
public nsITimedChannel
|
2001-02-21 01:43:56 +03:00
|
|
|
{
|
2014-06-23 22:49:08 +04:00
|
|
|
protected:
|
|
|
|
virtual ~imgRequestProxy();
|
|
|
|
|
2001-02-21 01:43:56 +03:00
|
|
|
public:
|
2014-11-15 07:10:47 +03:00
|
|
|
typedef mozilla::image::Image Image;
|
2013-09-28 22:28:42 +04:00
|
|
|
typedef mozilla::image::ImageURL ImageURL;
|
2014-11-15 07:10:47 +03:00
|
|
|
typedef mozilla::image::ProgressTracker ProgressTracker;
|
|
|
|
|
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(imgRequestProxy)
|
2001-02-21 01:43:56 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
2001-02-21 02:27:48 +03:00
|
|
|
NS_DECL_IMGIREQUEST
|
2001-03-06 07:46:20 +03:00
|
|
|
NS_DECL_NSIREQUEST
|
2005-02-21 23:58:01 +03:00
|
|
|
NS_DECL_NSISUPPORTSPRIORITY
|
2008-09-02 00:53:59 +04:00
|
|
|
NS_DECL_NSISECURITYINFOPROVIDER
|
2011-06-10 01:11:57 +04:00
|
|
|
// nsITimedChannel declared below
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2001-02-21 02:27:48 +03:00
|
|
|
imgRequestProxy();
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2010-05-11 07:27:41 +04:00
|
|
|
// Callers to Init or ChangeOwner are required to call NotifyListener after
|
|
|
|
// (although not immediately after) doing so.
|
2012-12-20 01:28:54 +04:00
|
|
|
nsresult Init(imgRequest* aOwner,
|
2015-03-25 20:59:00 +03:00
|
|
|
nsILoadGroup* aLoadGroup,
|
2017-07-19 21:15:11 +03:00
|
|
|
nsIDocument* aLoadingDocument,
|
2013-09-28 22:28:42 +04:00
|
|
|
ImageURL* aURI,
|
2015-03-25 20:59:00 +03:00
|
|
|
imgINotificationObserver* aObserver);
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
nsresult ChangeOwner(imgRequest* aNewOwner); // this will change mOwner.
|
|
|
|
// Do not call this if the
|
|
|
|
// previous owner has already
|
|
|
|
// sent notifications out!
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
// Add the request to the load group, if any. This should only be called once
|
|
|
|
// during initialization.
|
2003-05-14 09:42:06 +04:00
|
|
|
void AddToLoadGroup();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool HasObserver() const {
|
2012-07-30 18:20:58 +04:00
|
|
|
return mListener != nullptr;
|
2010-05-15 00:47:59 +04:00
|
|
|
}
|
|
|
|
|
2010-07-29 01:52:14 +04: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-15 00:47:59 +04:00
|
|
|
void NotifyListener();
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2010-07-29 01:52:14 +04: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 12:35:20 +03:00
|
|
|
// imgINotificationObserver methods:
|
|
|
|
virtual void Notify(int32_t aType,
|
2015-04-21 18:04:57 +03:00
|
|
|
const mozilla::gfx::IntRect* aRect = nullptr) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void OnLoadComplete(bool aLastPart) override;
|
2015-01-07 12:35:20 +03:00
|
|
|
|
|
|
|
// Other, internal-only methods:
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetHasImage() override;
|
2015-01-07 12:35:20 +03:00
|
|
|
|
2014-11-15 07:10:47 +03:00
|
|
|
// Whether we want notifications from ProgressTracker to be deferred until
|
2018-02-07 15:27:27 +03:00
|
|
|
// an event it has scheduled has been fired and/or validation is complete.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool NotificationsDeferred() const override
|
2010-08-02 23:44:49 +04:00
|
|
|
{
|
2018-02-07 15:27:27 +03:00
|
|
|
return IsValidating() || mPendingNotify;
|
2010-08-02 23:44:49 +04:00
|
|
|
}
|
2018-02-07 15:27:27 +03:00
|
|
|
virtual void MarkPendingNotify() override
|
2010-08-02 23:44:49 +04:00
|
|
|
{
|
2018-02-07 15:27:27 +03:00
|
|
|
mPendingNotify = true;
|
|
|
|
}
|
|
|
|
virtual void ClearPendingNotify() override
|
|
|
|
{
|
|
|
|
mPendingNotify = false;
|
2010-08-02 23:44:49 +04:00
|
|
|
}
|
2018-02-07 15:27:27 +03:00
|
|
|
bool IsValidating() const
|
|
|
|
{
|
|
|
|
return mValidating;
|
|
|
|
}
|
|
|
|
void MarkValidating();
|
|
|
|
void ClearValidating();
|
2010-08-02 23:44:49 +04:00
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
bool IsOnEventTarget() const;
|
|
|
|
already_AddRefed<nsIEventTarget> GetEventTarget() const override;
|
|
|
|
|
2010-09-08 04:33:02 +04: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();
|
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
nsresult SyncClone(imgINotificationObserver* aObserver,
|
|
|
|
nsIDocument* aLoadingDocument,
|
|
|
|
imgRequestProxy** aClone);
|
|
|
|
nsresult Clone(imgINotificationObserver* aObserver,
|
|
|
|
nsIDocument* aLoadingDocument,
|
|
|
|
imgRequestProxy** aClone);
|
2017-07-19 21:15:11 +03:00
|
|
|
nsresult GetStaticRequest(nsIDocument* aLoadingDocument,
|
|
|
|
imgRequestProxy** aReturn);
|
2012-10-12 16:43:01 +04:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
nsresult GetURI(ImageURL** aURI);
|
2013-09-28 22:28:42 +04:00
|
|
|
|
2001-10-12 10:43:52 +04:00
|
|
|
protected:
|
2014-11-15 07:10:47 +03:00
|
|
|
friend class mozilla::image::ProgressTracker;
|
2010-07-29 01:52:14 +04:00
|
|
|
friend class imgStatusNotifyRunnable;
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2008-12-20 01:35:50 +03:00
|
|
|
class imgCancelRunnable;
|
|
|
|
friend class imgCancelRunnable;
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class imgCancelRunnable : public mozilla::Runnable
|
2008-12-20 01:35:50 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
imgCancelRunnable(imgRequestProxy* owner, nsresult status)
|
2017-02-11 09:11:48 +03:00
|
|
|
: Runnable("imgCancelRunnable"), mOwner(owner), mStatus(status)
|
2015-03-25 20:59:00 +03:00
|
|
|
{ }
|
2008-12-20 01:35:50 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2008-12-20 01:35:50 +03:00
|
|
|
mOwner->DoCancel(mStatus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy> mOwner;
|
2008-12-20 01:35:50 +03:00
|
|
|
nsresult mStatus;
|
|
|
|
};
|
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
/* Remove from and forget the load group. */
|
|
|
|
void RemoveFromLoadGroup();
|
|
|
|
|
|
|
|
/* Remove from the load group and readd as a background request. */
|
|
|
|
void MoveToBackgroundInLoadGroup();
|
|
|
|
|
2008-12-20 01:35:50 +03:00
|
|
|
/* Finish up canceling ourselves */
|
|
|
|
void DoCancel(nsresult status);
|
|
|
|
|
2008-03-19 22:07:59 +03:00
|
|
|
/* Do the proper refcount management to null out mListener */
|
|
|
|
void NullOutListener();
|
2010-03-08 22:34:52 +03:00
|
|
|
|
2014-11-15 07:10:47 +03:00
|
|
|
// Return the ProgressTracker associated with mOwner and/or mImage. It may
|
2010-08-24 02:44:07 +04: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 07:10:47 +03:00
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker() const;
|
2010-08-24 02:44:07 +04:00
|
|
|
|
2011-06-10 01:11:57 +04:00
|
|
|
nsITimedChannel* TimedChannel()
|
|
|
|
{
|
2015-03-24 05:37:45 +03:00
|
|
|
if (!GetOwner()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
|
|
|
return GetOwner()->GetTimedChannel();
|
2011-06-10 01:11:57 +04:00
|
|
|
}
|
|
|
|
|
2014-11-15 07:10:47 +03:00
|
|
|
already_AddRefed<Image> GetImage() const;
|
2013-09-28 22:28:44 +04:00
|
|
|
bool HasImage() const;
|
2012-10-19 23:39:38 +04:00
|
|
|
imgRequest* GetOwner() const;
|
2018-02-07 15:27:27 +03:00
|
|
|
imgCacheValidator* GetValidator() const;
|
2012-10-12 20:11:21 +04:00
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
nsresult PerformClone(imgINotificationObserver* aObserver,
|
2017-07-19 21:15:11 +03:00
|
|
|
nsIDocument* aLoadingDocument,
|
2017-07-19 21:15:11 +03:00
|
|
|
bool aSyncNotify,
|
2012-10-12 16:43:01 +04:00
|
|
|
imgRequestProxy** aClone);
|
2012-10-12 20:11:22 +04:00
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
virtual imgRequestProxy* NewClonedProxy();
|
|
|
|
|
2011-06-10 01:11:57 +04:00
|
|
|
public:
|
|
|
|
NS_FORWARD_SAFE_NSITIMEDCHANNEL(TimedChannel())
|
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
protected:
|
2015-10-17 13:53:28 +03:00
|
|
|
mozilla::UniquePtr<ProxyBehaviour> mBehaviour;
|
2012-10-19 23:39:38 +04:00
|
|
|
|
2001-02-21 01:43:56 +03:00
|
|
|
private:
|
2002-12-24 17:30:12 +03:00
|
|
|
friend class imgCacheValidator;
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
void AddToOwner(nsIDocument* aLoadingDocument);
|
2018-02-07 15:27:27 +03:00
|
|
|
void RemoveFromOwner(nsresult aStatus);
|
2017-07-19 21:15:11 +03:00
|
|
|
|
2017-08-15 14:14:51 +03:00
|
|
|
nsresult DispatchWithTargetIfAvailable(already_AddRefed<nsIRunnable> aEvent);
|
|
|
|
void DispatchWithTarget(already_AddRefed<nsIRunnable> aEvent);
|
2017-07-19 21:15:11 +03:00
|
|
|
|
2010-05-11 07:27:41 +04:00
|
|
|
// The URI of our request.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageURL> mURI;
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2008-03-19 22:07:59 +03: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 21:21:00 +03: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 06:42:56 +04:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
2017-07-19 21:15:11 +03:00
|
|
|
RefPtr<mozilla::dom::TabGroup> mTabGroup;
|
|
|
|
nsCOMPtr<nsIEventTarget> mEventTarget;
|
2001-03-06 07:46:20 +03:00
|
|
|
|
2001-07-17 05:14:40 +04:00
|
|
|
nsLoadFlags mLoadFlags;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mLockCount;
|
|
|
|
uint32_t mAnimationConsumers;
|
2017-07-19 21:15:12 +03:00
|
|
|
bool mCanceled : 1;
|
|
|
|
bool mIsInLoadGroup : 1;
|
2017-11-01 13:59:10 +03:00
|
|
|
bool mForceDispatchLoadGroup : 1;
|
2017-07-19 21:15:12 +03:00
|
|
|
bool mListenerIsStrongRef : 1;
|
|
|
|
bool mDecodeRequested : 1;
|
2010-07-29 01:52:14 +04:00
|
|
|
|
|
|
|
// Whether we want to defer our notifications by the non-virtual Observer
|
|
|
|
// interfaces as image loads proceed.
|
2018-02-07 15:27:27 +03:00
|
|
|
bool mPendingNotify : 1;
|
2018-02-07 15:27:27 +03:00
|
|
|
bool mValidating : 1;
|
2017-07-19 21:15:12 +03:00
|
|
|
bool mHadListener : 1;
|
|
|
|
bool mHadDispatch : 1;
|
2012-10-12 05:34:22 +04:00
|
|
|
};
|
|
|
|
|
2012-10-12 20:11:20 +04: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 07:10:47 +03:00
|
|
|
imgRequestProxyStatic(Image* aImage, nsIPrincipal* aPrincipal);
|
2012-10-12 20:11:20 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD GetImagePrincipal(nsIPrincipal** aPrincipal) override;
|
2012-10-12 20:11:20 +04:00
|
|
|
|
|
|
|
protected:
|
2017-07-19 21:15:11 +03:00
|
|
|
imgRequestProxy* NewClonedProxy() override;
|
2012-10-12 20:11:22 +04:00
|
|
|
|
2012-10-12 20:11:20 +04: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 06:52:05 +03:00
|
|
|
#endif // mozilla_image_imgRequestProxy_h
|