2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2006-03-31 12:00:42 +04:00
|
|
|
/*
|
|
|
|
* A base class which implements nsIImageLoadingContent and can be
|
|
|
|
* subclassed by various content nodes that want to provide image
|
|
|
|
* loading functionality (eg <img>, <object>, etc).
|
|
|
|
*/
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
#ifndef nsImageLoadingContent_h__
|
|
|
|
#define nsImageLoadingContent_h__
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
#include "imgINotificationObserver.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "mozilla/CORSMode.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2015-07-08 00:00:08 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2003-03-19 04:08:22 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsIImageLoadingContent.h"
|
|
|
|
#include "nsIRequest.h"
|
2013-02-01 15:00:41 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-08-20 01:49:38 +04:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2018-11-08 20:45:50 +03:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2018-08-08 14:56:01 +03:00
|
|
|
#include "nsAttrValue.h"
|
2003-03-19 04:08:22 +03:00
|
|
|
|
|
|
|
class nsIURI;
|
2013-02-01 15:00:41 +04:00
|
|
|
class nsPresContext;
|
|
|
|
class nsIContent;
|
|
|
|
class imgRequestProxy;
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2016-10-06 07:30:35 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class AsyncEventDispatcher;
|
2018-07-04 20:26:09 +03:00
|
|
|
namespace dom {
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
struct BindContext;
|
2019-01-02 16:05:23 +03:00
|
|
|
class Document;
|
2018-07-04 20:26:09 +03:00
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
2016-10-06 07:30:35 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-03-12 05:11:37 +04:00
|
|
|
#ifdef LoadImage
|
|
|
|
// Undefine LoadImage to prevent naming conflict with Windows.
|
|
|
|
# undef LoadImage
|
|
|
|
#endif
|
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
class nsImageLoadingContent : public nsIImageLoadingContent {
|
2016-03-26 00:49:43 +03:00
|
|
|
template <typename T>
|
|
|
|
using Maybe = mozilla::Maybe<T>;
|
|
|
|
using Nothing = mozilla::Nothing;
|
|
|
|
using OnNonvisible = mozilla::OnNonvisible;
|
|
|
|
using Visibility = mozilla::Visibility;
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
/* METHODS */
|
|
|
|
public:
|
|
|
|
nsImageLoadingContent();
|
|
|
|
virtual ~nsImageLoadingContent();
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
NS_DECL_IMGINOTIFICATIONOBSERVER
|
2003-03-19 04:08:22 +03:00
|
|
|
NS_DECL_NSIIMAGELOADINGCONTENT
|
|
|
|
|
2013-01-02 23:30:02 +04:00
|
|
|
// Web IDL binding methods.
|
2018-01-19 22:19:39 +03:00
|
|
|
// Note that the XPCOM SetLoadingEnabled, ForceImageState methods are OK for
|
|
|
|
// Web IDL bindings to use as well, since none of them throw when called via
|
|
|
|
// the Web IDL bindings.
|
2013-01-02 23:30:02 +04:00
|
|
|
|
|
|
|
bool LoadingEnabled() const { return mLoadingEnabled; }
|
|
|
|
int16_t ImageBlockingStatus() const { return mImageBlockingStatus; }
|
2018-01-19 22:19:39 +03:00
|
|
|
void AddObserver(imgINotificationObserver* aObserver);
|
|
|
|
void RemoveObserver(imgINotificationObserver* aObserver);
|
2013-01-02 23:30:02 +04:00
|
|
|
already_AddRefed<imgIRequest> GetRequest(int32_t aRequestType,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
int32_t GetRequestType(imgIRequest* aRequest, mozilla::ErrorResult& aError);
|
|
|
|
already_AddRefed<nsIURI> GetCurrentURI(mozilla::ErrorResult& aError);
|
2017-11-14 13:20:03 +03:00
|
|
|
already_AddRefed<nsIURI> GetCurrentRequestFinalURI();
|
2018-01-19 22:19:39 +03:00
|
|
|
void ForceReload(bool aNotify, mozilla::ErrorResult& aError);
|
2013-01-02 23:30:02 +04:00
|
|
|
|
2018-07-04 20:26:09 +03:00
|
|
|
mozilla::dom::Element* FindImageMap();
|
|
|
|
|
2018-08-08 14:56:01 +03:00
|
|
|
/**
|
|
|
|
* Toggle whether or not to synchronously decode an image on draw.
|
|
|
|
*/
|
|
|
|
void SetSyncDecodingHint(bool aHint);
|
|
|
|
|
2018-11-08 20:45:50 +03:00
|
|
|
/**
|
|
|
|
* Notify us that the document state has changed. Called by nsDocument so that
|
|
|
|
* we may reject any promises which require the document to be active.
|
|
|
|
*/
|
|
|
|
void NotifyOwnerDocumentActivityChanged();
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
protected:
|
2014-08-20 01:49:38 +04:00
|
|
|
enum ImageLoadType {
|
|
|
|
// Most normal image loads
|
|
|
|
eImageLoadType_Normal,
|
|
|
|
// From a <img srcset> or <picture> context. Affects type given to content
|
|
|
|
// policy.
|
|
|
|
eImageLoadType_Imageset
|
|
|
|
};
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
/**
|
2006-01-01 14:25:43 +03:00
|
|
|
* LoadImage is called by subclasses when the appropriate
|
2003-03-19 04:08:22 +03:00
|
|
|
* attributes (eg 'src' for <img> tags) change. The string passed
|
|
|
|
* in is the new uri string; this consolidates the code for getting
|
2005-04-06 06:55:02 +04:00
|
|
|
* the charset, constructing URI objects, and any other incidentals
|
2014-08-20 01:49:38 +04:00
|
|
|
* into this superclass.
|
2003-03-19 04:08:22 +03:00
|
|
|
*
|
|
|
|
* @param aNewURI the URI spec to be loaded (may be a relative URI)
|
2005-04-06 06:55:02 +04:00
|
|
|
* @param aForce If true, make sure to load the URI. If false, only
|
|
|
|
* load if the URI is different from the currently loaded URI.
|
2005-09-18 22:05:40 +04:00
|
|
|
* @param aNotify If true, nsIDocumentObserver state change notifications
|
2005-09-18 23:46:20 +04:00
|
|
|
* will be sent as needed.
|
2014-08-20 01:49:38 +04:00
|
|
|
* @param aImageLoadType The ImageLoadType for this request
|
2017-10-03 06:28:32 +03:00
|
|
|
* @param aTriggeringPrincipal Optional parameter specifying the triggering
|
|
|
|
* principal to use for the image load
|
2003-03-19 04:08:22 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult LoadImage(const nsAString& aNewURI, bool aForce, bool aNotify,
|
2017-10-03 06:28:32 +03:00
|
|
|
ImageLoadType aImageLoadType,
|
|
|
|
nsIPrincipal* aTriggeringPrincipal = nullptr);
|
2005-09-18 22:05:40 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ImageState is called by subclasses that are computing their content state.
|
|
|
|
* The return value will have the NS_EVENT_STATE_BROKEN,
|
|
|
|
* NS_EVENT_STATE_USERDISABLED, and NS_EVENT_STATE_SUPPRESSED bits set as
|
|
|
|
* needed. Note that this state assumes that this node is "trying" to be an
|
|
|
|
* image (so for example complete lack of attempt to load an image will lead
|
|
|
|
* to NS_EVENT_STATE_BROKEN being set). Subclasses that are not "trying" to
|
|
|
|
* be an image (eg an HTML <input> of type other than "image") should just
|
|
|
|
* not call this method when computing their intrinsic state.
|
|
|
|
*/
|
2014-04-03 08:18:36 +04:00
|
|
|
mozilla::EventStates ImageState() const;
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2005-09-21 23:14:30 +04:00
|
|
|
/**
|
2006-01-01 14:25:43 +03:00
|
|
|
* LoadImage is called by subclasses when the appropriate
|
2005-09-21 23:14:30 +04:00
|
|
|
* attributes (eg 'src' for <img> tags) change. If callers have an
|
|
|
|
* URI object already available, they should use this method.
|
|
|
|
*
|
|
|
|
* @param aNewURI the URI to be loaded
|
|
|
|
* @param aForce If true, make sure to load the URI. If false, only
|
|
|
|
* load if the URI is different from the currently loaded URI.
|
|
|
|
* @param aNotify If true, nsIDocumentObserver state change notifications
|
|
|
|
* will be sent as needed.
|
2014-08-20 01:49:38 +04:00
|
|
|
* @param aImageLoadType The ImageLoadType for this request
|
2016-10-05 05:06:27 +03:00
|
|
|
* @param aLoadStart If true, dispatch "loadstart" event.
|
2005-09-21 23:14:30 +04:00
|
|
|
* @param aDocument Optional parameter giving the document this node is in.
|
|
|
|
* This is purely a performance optimization.
|
2006-09-08 02:51:57 +04:00
|
|
|
* @param aLoadFlags Optional parameter specifying load flags to use for
|
|
|
|
* the image load
|
2017-10-03 06:28:32 +03:00
|
|
|
* @param aTriggeringPrincipal Optional parameter specifying the triggering
|
|
|
|
* principal to use for the image load
|
2005-09-21 23:14:30 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult LoadImage(nsIURI* aNewURI, bool aForce, bool aNotify,
|
2016-10-05 05:06:27 +03:00
|
|
|
ImageLoadType aImageLoadType, bool aLoadStart = true,
|
2019-01-02 16:05:23 +03:00
|
|
|
mozilla::dom::Document* aDocument = nullptr,
|
2017-10-03 06:28:32 +03:00
|
|
|
nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL,
|
|
|
|
nsIPrincipal* aTriggeringPrincipal = nullptr);
|
|
|
|
|
|
|
|
nsresult LoadImage(nsIURI* aNewURI, bool aForce, bool aNotify,
|
|
|
|
ImageLoadType aImageLoadType,
|
|
|
|
nsIPrincipal* aTriggeringPrincipal) {
|
|
|
|
return LoadImage(aNewURI, aForce, aNotify, aImageLoadType, true, nullptr,
|
|
|
|
nsIRequest::LOAD_NORMAL, aTriggeringPrincipal);
|
|
|
|
}
|
2005-09-21 23:14:30 +04:00
|
|
|
|
|
|
|
/**
|
2012-08-14 02:11:50 +04:00
|
|
|
* helpers to get the document for this content (from the nodeinfo
|
|
|
|
* and such). Not named GetOwnerDoc/GetCurrentDoc to prevent ambiguous
|
|
|
|
* method names in subclasses
|
2005-09-21 23:14:30 +04:00
|
|
|
*
|
|
|
|
* @return the document we belong to
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
mozilla::dom::Document* GetOurOwnerDoc();
|
|
|
|
mozilla::dom::Document* GetOurCurrentDoc();
|
2005-09-21 23:14:30 +04:00
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
/**
|
|
|
|
* Helper function to get the frame associated with this content. Not named
|
|
|
|
* GetPrimaryFrame to prevent ambiguous method names in subclasses.
|
|
|
|
*
|
2012-07-30 18:20:58 +04:00
|
|
|
* @return The frame which we belong to, or nullptr if it doesn't exist.
|
2011-11-10 01:39:16 +04:00
|
|
|
*/
|
|
|
|
nsIFrame* GetOurPrimaryFrame();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to get the PresContext associated with this content's
|
|
|
|
* frame. Not named GetPresContext to prevent ambiguous method names in
|
|
|
|
* subclasses.
|
|
|
|
*
|
2012-07-30 18:20:58 +04:00
|
|
|
* @return The nsPresContext associated with our frame, or nullptr if either
|
2011-11-10 01:39:16 +04:00
|
|
|
* the frame doesn't exist, or the frame's prescontext doesn't exist.
|
|
|
|
*/
|
|
|
|
nsPresContext* GetFramePresContext();
|
|
|
|
|
2005-08-19 18:55:07 +04:00
|
|
|
/**
|
|
|
|
* CancelImageRequests is called by subclasses when they want to
|
|
|
|
* cancel all image requests (for example when the subclass is
|
|
|
|
* somehow not an image anymore).
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void CancelImageRequests(bool aNotify);
|
2005-08-19 18:55:07 +04:00
|
|
|
|
2006-06-01 22:35:21 +04:00
|
|
|
/**
|
|
|
|
* Derived classes of nsImageLoadingContent MUST call
|
|
|
|
* DestroyImageLoadingContent from their destructor, or earlier. It
|
|
|
|
* does things that cannot be done in ~nsImageLoadingContent because
|
|
|
|
* they rely on being able to QueryInterface to other derived classes,
|
|
|
|
* which cannot happen once the derived class destructor has started
|
|
|
|
* calling the base class destructors.
|
|
|
|
*/
|
|
|
|
void DestroyImageLoadingContent();
|
|
|
|
|
2011-07-14 22:47:35 +04:00
|
|
|
/**
|
|
|
|
* Returns the CORS mode that will be used for all future image loads. The
|
2012-01-26 02:31:30 +04:00
|
|
|
* default implementation returns CORS_NONE unconditionally.
|
2011-07-14 22:47:35 +04:00
|
|
|
*/
|
2012-03-10 20:13:51 +04:00
|
|
|
virtual mozilla::CORSMode GetCORSMode();
|
2011-07-14 22:47:35 +04:00
|
|
|
|
2019-08-21 16:24:45 +03:00
|
|
|
virtual mozilla::dom::ReferrerPolicy GetImageReferrerPolicy();
|
2015-06-06 01:25:24 +03:00
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
// Subclasses are *required* to call BindToTree/UnbindFromTree.
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
void BindToTree(mozilla::dom::BindContext&, nsINode& aParent);
|
2019-05-29 01:47:08 +03:00
|
|
|
void UnbindFromTree(bool aNullParent);
|
2012-08-14 02:11:50 +04:00
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
nsresult OnLoadComplete(imgIRequest* aRequest, nsresult aStatus);
|
2013-02-25 04:59:22 +04:00
|
|
|
void OnUnlockedDraw();
|
2012-10-12 20:11:22 +04:00
|
|
|
nsresult OnImageIsAnimated(imgIRequest* aRequest);
|
|
|
|
|
2014-08-20 01:49:38 +04:00
|
|
|
// The nsContentPolicyType we would use for this ImageLoadType
|
|
|
|
static nsContentPolicyType PolicyTypeForLoad(ImageLoadType aImageLoadType);
|
|
|
|
|
2016-10-06 07:30:35 +03:00
|
|
|
void AsyncEventRunning(mozilla::AsyncEventDispatcher* aEvent);
|
|
|
|
|
2017-03-17 00:43:34 +03:00
|
|
|
// Get ourselves as an nsIContent*. Not const because some of the callers
|
|
|
|
// want a non-const nsIContent.
|
|
|
|
virtual nsIContent* AsContent() = 0;
|
|
|
|
|
2018-11-20 04:20:17 +03:00
|
|
|
// Hooks for subclasses to call to get the intrinsic width and height.
|
|
|
|
uint32_t NaturalWidth();
|
|
|
|
uint32_t NaturalHeight();
|
|
|
|
|
2018-11-08 20:45:50 +03:00
|
|
|
/**
|
|
|
|
* Create a promise and queue a microtask which will ensure the current
|
|
|
|
* request (after any pending loads are applied) has requested a full decode.
|
|
|
|
* The promise is fulfilled once the request has a fully decoded surface that
|
|
|
|
* is available for drawing, or an error condition occurrs (e.g. broken image,
|
|
|
|
* current request is updated, etc).
|
|
|
|
*
|
|
|
|
* https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-decode
|
|
|
|
*/
|
|
|
|
already_AddRefed<mozilla::dom::Promise> QueueDecodeAsync(
|
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
|
2018-08-08 14:56:01 +03:00
|
|
|
enum class ImageDecodingType : uint8_t {
|
|
|
|
Auto,
|
|
|
|
Async,
|
|
|
|
Sync,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const nsAttrValue::EnumTable kDecodingTable[];
|
|
|
|
static const nsAttrValue::EnumTable* kDecodingTableDefault;
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
private:
|
2018-11-08 20:45:50 +03:00
|
|
|
/**
|
|
|
|
* Enqueue and/or fulfill a promise created by QueueDecodeAsync.
|
|
|
|
*/
|
|
|
|
void DecodeAsync(RefPtr<mozilla::dom::Promise>&& aPromise,
|
|
|
|
uint32_t aRequestGeneration);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to resolve all queued promises based on the state of the current
|
|
|
|
* request. If the current request does not yet have all of the encoded data,
|
|
|
|
* or the decoding has not yet completed, it will return without changing the
|
|
|
|
* promise states.
|
|
|
|
*/
|
|
|
|
void MaybeResolveDecodePromises();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reject all queued promises with the given status.
|
|
|
|
*/
|
|
|
|
void RejectDecodePromises(nsresult aStatus);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Age the generation counter if we have a new current request with a
|
|
|
|
* different URI. If the generation counter is aged, then all queued promises
|
|
|
|
* will also be rejected.
|
|
|
|
*/
|
|
|
|
void MaybeAgeRequestGeneration(nsIURI* aNewURI);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deregister as an observer for the owner document's activity notifications
|
|
|
|
* if we have no outstanding decode promises.
|
|
|
|
*/
|
|
|
|
void MaybeDeregisterActivityObserver();
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
/**
|
2017-07-19 21:15:11 +03:00
|
|
|
* Struct used to manage the native image observers.
|
2003-03-19 04:08:22 +03:00
|
|
|
*/
|
|
|
|
struct ImageObserver {
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit ImageObserver(imgINotificationObserver* aObserver);
|
2013-02-01 15:00:41 +04:00
|
|
|
~ImageObserver();
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
nsCOMPtr<imgINotificationObserver> mObserver;
|
2003-03-19 04:08:22 +03:00
|
|
|
ImageObserver* mNext;
|
|
|
|
};
|
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
/**
|
|
|
|
* Struct used to manage the scripted/XPCOM image observers.
|
|
|
|
*/
|
|
|
|
class ScriptedImageObserver final {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(ScriptedImageObserver)
|
|
|
|
|
|
|
|
ScriptedImageObserver(imgINotificationObserver* aObserver,
|
|
|
|
RefPtr<imgRequestProxy>&& aCurrentRequest,
|
|
|
|
RefPtr<imgRequestProxy>&& aPendingRequest);
|
|
|
|
bool CancelRequests();
|
|
|
|
|
|
|
|
nsCOMPtr<imgINotificationObserver> mObserver;
|
|
|
|
RefPtr<imgRequestProxy> mCurrentRequest;
|
|
|
|
RefPtr<imgRequestProxy> mPendingRequest;
|
|
|
|
|
|
|
|
private:
|
|
|
|
~ScriptedImageObserver();
|
|
|
|
};
|
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
/**
|
|
|
|
* Struct to report state changes
|
|
|
|
*/
|
|
|
|
struct AutoStateChanger {
|
|
|
|
AutoStateChanger(nsImageLoadingContent* aImageContent, bool aNotify)
|
|
|
|
: mImageContent(aImageContent), mNotify(aNotify) {
|
2010-07-31 21:54:59 +04:00
|
|
|
mImageContent->mStateChangerDepth++;
|
2005-09-18 22:05:40 +04:00
|
|
|
}
|
|
|
|
~AutoStateChanger() {
|
2010-07-31 21:54:59 +04:00
|
|
|
mImageContent->mStateChangerDepth--;
|
2005-09-18 22:05:40 +04:00
|
|
|
mImageContent->UpdateImageState(mNotify);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsImageLoadingContent* mImageContent;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mNotify;
|
2005-09-18 22:05:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
friend struct AutoStateChanger;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UpdateImageState recomputes the current state of this image loading
|
|
|
|
* content and updates what ImageState() returns accordingly. It will also
|
|
|
|
* fire a ContentStatesChanged() notification as needed if aNotify is true.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void UpdateImageState(bool aNotify);
|
2005-09-18 22:05:40 +04:00
|
|
|
|
2011-01-11 08:57:57 +03:00
|
|
|
/**
|
|
|
|
* Method to fire an event once we know what's going on with the image load.
|
|
|
|
*
|
2016-08-16 07:01:12 +03:00
|
|
|
* @param aEventType "loadstart", "loadend", "load", or "error" depending on
|
|
|
|
* how things went
|
2016-10-06 07:30:35 +03:00
|
|
|
* @param aIsCancelable true if event is cancelable.
|
|
|
|
*/
|
|
|
|
nsresult FireEvent(const nsAString& aEventType, bool aIsCancelable = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to cancel and null-out pending event if they exist.
|
2011-01-11 08:57:57 +03:00
|
|
|
*/
|
2016-10-06 07:30:35 +03:00
|
|
|
void CancelPendingEvent();
|
|
|
|
|
|
|
|
RefPtr<mozilla::AsyncEventDispatcher> mPendingEvent;
|
2013-01-02 23:30:02 +04:00
|
|
|
|
2011-01-11 08:57:57 +03:00
|
|
|
protected:
|
2003-03-19 04:08:22 +03:00
|
|
|
/**
|
|
|
|
* Method to create an nsIURI object from the given string (will
|
|
|
|
* handle getting the right charset, base, etc). You MUST pass in a
|
|
|
|
* non-null document to this function.
|
|
|
|
*
|
|
|
|
* @param aSpec the string spec (from an HTML attribute, eg)
|
|
|
|
* @param aDocument the document we belong to
|
|
|
|
* @return the URI we want to be loading
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult StringToURI(const nsAString& aSpec,
|
|
|
|
mozilla::dom::Document* aDocument, nsIURI** aURI);
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
void CreateStaticImageClone(nsImageLoadingContent* aDest) const;
|
2006-06-01 22:35:21 +04:00
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
/**
|
|
|
|
* Prepare and returns a reference to the "next request". If there's already
|
|
|
|
* a _usable_ current request (one with SIZE_AVAILABLE), this request is
|
|
|
|
* "pending" until it becomes usable. Otherwise, this becomes the current
|
|
|
|
* request.
|
2014-08-20 01:49:38 +04:00
|
|
|
*
|
|
|
|
* @param aImageLoadType The ImageLoadType for this request
|
2010-07-31 21:54:59 +04:00
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy>& PrepareNextRequest(ImageLoadType aImageLoadType);
|
2010-07-31 21:54:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a COMPtr reference to the current/pending image requests, cleaning
|
|
|
|
* up and canceling anything that was there before. Note that if you just want
|
|
|
|
* to get rid of one of the requests, you should call
|
2017-02-03 06:49:07 +03:00
|
|
|
* Clear*Request(NS_BINDING_ABORTED) instead.
|
2014-08-20 01:49:38 +04:00
|
|
|
*
|
|
|
|
* @param aImageLoadType The ImageLoadType for this request
|
2010-07-31 21:54:59 +04:00
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy>& PrepareCurrentRequest(ImageLoadType aImageLoadType);
|
|
|
|
RefPtr<imgRequestProxy>& PreparePendingRequest(ImageLoadType aImageLoadType);
|
2010-07-31 21:54:59 +04:00
|
|
|
|
2012-03-20 02:22:02 +04:00
|
|
|
/**
|
|
|
|
* Switch our pending request to be our current request.
|
|
|
|
* mPendingRequest must be non-null!
|
|
|
|
*/
|
|
|
|
void MakePendingRequestCurrent();
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
/**
|
|
|
|
* Cancels and nulls-out the "current" and "pending" requests if they exist.
|
2016-08-16 07:01:12 +03:00
|
|
|
*
|
2015-02-06 13:51:12 +03:00
|
|
|
* @param aNonvisibleAction An action to take if the image is no longer
|
|
|
|
* visible as a result; see |UntrackImage|.
|
2010-07-31 21:54:59 +04:00
|
|
|
*/
|
2016-03-26 00:49:43 +03:00
|
|
|
void ClearCurrentRequest(
|
|
|
|
nsresult aReason,
|
|
|
|
const Maybe<OnNonvisible>& aNonvisibleAction = Nothing());
|
|
|
|
void ClearPendingRequest(
|
|
|
|
nsresult aReason,
|
|
|
|
const Maybe<OnNonvisible>& aNonvisibleAction = Nothing());
|
2010-07-31 21:54:59 +04:00
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
/**
|
|
|
|
* Retrieve a pointer to the 'registered with the refresh driver' flag for
|
|
|
|
* which a particular image request corresponds.
|
|
|
|
*
|
|
|
|
* @returns A pointer to the boolean flag for a given image request, or
|
2012-07-30 18:20:58 +04:00
|
|
|
* |nullptr| if the request is not either |mPendingRequest| or
|
2011-11-10 01:39:16 +04:00
|
|
|
* |mCurrentRequest|.
|
|
|
|
*/
|
|
|
|
bool* GetRegisteredFlagForRequest(imgIRequest* aRequest);
|
|
|
|
|
2012-06-14 05:12:37 +04:00
|
|
|
/**
|
|
|
|
* Reset animation of the current request if
|
|
|
|
* |mNewRequestsWillNeedAnimationReset| was true when the request was
|
|
|
|
* prepared.
|
|
|
|
*/
|
|
|
|
void ResetAnimationIfNeeded();
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
/**
|
|
|
|
* Static helper method to tell us if we have the size of a request. The
|
|
|
|
* image may be null.
|
|
|
|
*/
|
|
|
|
static bool HaveSize(imgIRequest* aImage);
|
|
|
|
|
2010-08-04 04:40:29 +04:00
|
|
|
/**
|
|
|
|
* Adds/Removes a given imgIRequest from our document's tracker.
|
2010-09-01 05:26:41 +04:00
|
|
|
*
|
|
|
|
* No-op if aImage is null.
|
2013-02-25 04:59:21 +04:00
|
|
|
*
|
2017-03-22 08:32:48 +03:00
|
|
|
* @param aFrame If called from FrameCreated the frame passed to FrameCreated.
|
|
|
|
* This is our frame, but at the time of the FrameCreated call
|
|
|
|
* our primary frame pointer hasn't been set yet, so this is
|
|
|
|
* only way to get our frame.
|
|
|
|
*
|
2016-03-26 00:49:43 +03:00
|
|
|
* @param aNonvisibleAction A requested action if the frame has become
|
|
|
|
* nonvisible. If Nothing(), no action is
|
|
|
|
* requested. If DISCARD_IMAGES is specified, the
|
|
|
|
* frame is requested to ask any images it's
|
|
|
|
* associated with to discard their surfaces if
|
|
|
|
* possible.
|
2010-08-04 04:40:29 +04:00
|
|
|
*/
|
2017-03-22 08:32:48 +03:00
|
|
|
void TrackImage(imgIRequest* aImage, nsIFrame* aFrame = nullptr);
|
2015-02-06 13:51:12 +03:00
|
|
|
void UntrackImage(imgIRequest* aImage,
|
2016-03-26 00:49:43 +03:00
|
|
|
const Maybe<OnNonvisible>& aNonvisibleAction = Nothing());
|
2010-08-04 04:40:29 +04:00
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
/* MEMBERS */
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy> mCurrentRequest;
|
|
|
|
RefPtr<imgRequestProxy> mPendingRequest;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mCurrentRequestFlags;
|
|
|
|
uint32_t mPendingRequestFlags;
|
2012-08-14 02:11:50 +04:00
|
|
|
|
|
|
|
enum {
|
2013-02-14 00:18:08 +04:00
|
|
|
// Set if the request needs ResetAnimation called on it.
|
2012-08-14 02:11:50 +04:00
|
|
|
REQUEST_NEEDS_ANIMATION_RESET = 0x00000001U,
|
2013-02-14 00:18:08 +04:00
|
|
|
// Set if the request is currently tracked with the document.
|
2014-08-20 01:49:38 +04:00
|
|
|
REQUEST_IS_TRACKED = 0x00000004U,
|
|
|
|
// Set if this is an imageset request, such as from <img srcset> or
|
|
|
|
// <picture>
|
|
|
|
REQUEST_IS_IMAGESET = 0x00000008U
|
2012-08-14 02:11:50 +04:00
|
|
|
};
|
2010-07-31 21:54:59 +04:00
|
|
|
|
|
|
|
// If the image was blocked or if there was an error loading, it's nice to
|
|
|
|
// still keep track of what the URI was despite not having an imgIRequest.
|
|
|
|
// We only maintain this in those situations (in the common case, this is
|
|
|
|
// always null).
|
2004-06-05 21:57:00 +04:00
|
|
|
nsCOMPtr<nsIURI> mCurrentURI;
|
2003-03-19 04:08:22 +03:00
|
|
|
|
|
|
|
private:
|
2017-07-19 21:15:11 +03:00
|
|
|
/**
|
|
|
|
* Clones the given "current" or "pending" request for each scripted observer.
|
|
|
|
*/
|
|
|
|
void CloneScriptedRequests(imgRequestProxy* aRequest);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels and nulls-out the "current" or "pending" requests if they exist
|
|
|
|
* for each scripted observer.
|
|
|
|
*/
|
|
|
|
void ClearScriptedRequests(int32_t aRequestType, nsresult aReason);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves the "pending" request into the "current" request for each scripted
|
|
|
|
* observer. If there is an existing "current" request, it will cancel it
|
|
|
|
* first.
|
|
|
|
*/
|
|
|
|
void MakePendingScriptedRequestsCurrent();
|
|
|
|
|
2018-08-08 14:56:01 +03:00
|
|
|
/**
|
|
|
|
* Depending on the configured decoding hint, and/or how recently we updated
|
|
|
|
* the image request, force or stop the frame from decoding the image
|
|
|
|
* synchronously when it is drawn.
|
|
|
|
* @param aPrepareNextRequest True if this is when updating the image request.
|
|
|
|
* @param aFrame If called from FrameCreated the frame passed to FrameCreated.
|
|
|
|
* This is our frame, but at the time of the FrameCreated call
|
|
|
|
* our primary frame pointer hasn't been set yet, so this is
|
|
|
|
* only way to get our frame.
|
|
|
|
*/
|
|
|
|
void MaybeForceSyncDecoding(bool aPrepareNextRequest,
|
|
|
|
nsIFrame* aFrame = nullptr);
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
/**
|
|
|
|
* Typically we will have only one observer (our frame in the screen
|
|
|
|
* prescontext), so we want to only make space for one and to
|
|
|
|
* heap-allocate anything past that (saves memory and malloc churn
|
|
|
|
* in the common case). The storage is a linked list, we just
|
|
|
|
* happen to actually hold the first observer instead of a pointer
|
|
|
|
* to it.
|
|
|
|
*/
|
|
|
|
ImageObserver mObserverList;
|
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
/**
|
|
|
|
* Typically we will have no scripted observers, as this is only used by
|
|
|
|
* chrome, legacy extensions, and some mochitests. An empty array reserves
|
|
|
|
* minimal memory.
|
|
|
|
*/
|
|
|
|
nsTArray<RefPtr<ScriptedImageObserver>> mScriptedObservers;
|
|
|
|
|
2018-11-08 20:45:50 +03:00
|
|
|
/**
|
|
|
|
* Promises created by QueueDecodeAsync that are still waiting to be
|
|
|
|
* fulfilled by the image being fully decoded.
|
|
|
|
*/
|
|
|
|
nsTArray<RefPtr<mozilla::dom::Promise>> mDecodePromises;
|
|
|
|
|
2009-06-26 11:25:17 +04:00
|
|
|
/**
|
|
|
|
* When mIsImageStateForced is true, this holds the ImageState that we'll
|
|
|
|
* return in ImageState().
|
|
|
|
*/
|
2014-04-03 08:18:36 +04:00
|
|
|
mozilla::EventStates mForcedImageState;
|
2009-06-26 11:25:17 +04:00
|
|
|
|
2015-07-08 00:00:08 +03:00
|
|
|
mozilla::TimeStamp mMostRecentRequestChange;
|
|
|
|
|
2018-11-08 20:45:50 +03:00
|
|
|
/**
|
|
|
|
* Total number of outstanding decode promises, including those stored in
|
|
|
|
* mDecodePromises and those embedded in runnables waiting to be enqueued.
|
|
|
|
* This is used to determine whether we need to register as an observer for
|
|
|
|
* document activity notifications.
|
|
|
|
*/
|
|
|
|
size_t mOutstandingDecodePromises;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An incrementing counter representing the current request generation;
|
|
|
|
* Each time mCurrentRequest is modified with a different URI, this will
|
|
|
|
* be incremented. Each QueueDecodeAsync call will cache the generation
|
|
|
|
* of the current request so that when it is processed, it knows if it
|
|
|
|
* should have rejected because the request changed.
|
|
|
|
*/
|
|
|
|
uint32_t mRequestGeneration;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t mImageBlockingStatus;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mLoadingEnabled : 1;
|
2005-09-18 22:05:40 +04:00
|
|
|
|
2009-06-26 11:25:17 +04:00
|
|
|
/**
|
|
|
|
* When true, we return mForcedImageState from ImageState().
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsImageStateForced : 1;
|
2009-06-26 11:25:17 +04:00
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
/**
|
|
|
|
* The state we had the last time we checked whether we needed to notify the
|
|
|
|
* document of a state change. These are maintained by UpdateImageState.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mLoading : 1;
|
|
|
|
bool mBroken : 1;
|
|
|
|
bool mUserDisabled : 1;
|
|
|
|
bool mSuppressed : 1;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2011-01-26 21:52:48 +03:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* A hack to get animations to reset, see bug 594771. On requests
|
|
|
|
* that originate from setting .src, we mark them for needing their animation
|
|
|
|
* reset when they are ready. mNewRequestsWillNeedAnimationReset is set to
|
|
|
|
* true while preparing such requests (as a hack around needing to change an
|
|
|
|
* interface), and the other two booleans store which of the current
|
|
|
|
* and pending requests are of the sort that need their animation restarted.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mNewRequestsWillNeedAnimationReset : 1;
|
2011-01-26 21:52:48 +03:00
|
|
|
|
2017-04-25 04:17:38 +03:00
|
|
|
/**
|
|
|
|
* Flag to indicate whether the channel should be mark as urgent-start.
|
|
|
|
* It should be set in *Element and passed to nsContentUtils::LoadImage.
|
|
|
|
* True if we want to set nsIClassOfService::UrgentStart to the channel to
|
|
|
|
* get the response ASAP for better user responsiveness.
|
|
|
|
*/
|
|
|
|
bool mUseUrgentStartForChannel;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-01-26 21:52:48 +03:00
|
|
|
private:
|
2010-07-31 21:54:59 +04:00
|
|
|
/* The number of nested AutoStateChangers currently tracking our state. */
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mStateChangerDepth;
|
2011-11-10 01:39:16 +04:00
|
|
|
|
|
|
|
// Flags to indicate whether each of the current and pending requests are
|
|
|
|
// registered with the refresh driver.
|
|
|
|
bool mCurrentRequestRegistered;
|
|
|
|
bool mPendingRequestRegistered;
|
2017-03-16 11:09:50 +03:00
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// Bug 1353685: Should ServiceWorker call SetBlockedRequest?
|
|
|
|
//
|
|
|
|
// This member is used in SetBlockedRequest, if it's true, then this call is
|
|
|
|
// triggered from LoadImage.
|
|
|
|
// If this is false, it means this call is from other places like
|
|
|
|
// ServiceWorker, then we will ignore call to SetBlockedRequest for now.
|
|
|
|
//
|
|
|
|
// Also we use this variable to check if some evil code is reentering
|
|
|
|
// LoadImage.
|
|
|
|
bool mIsStartingImageLoad;
|
2018-08-08 14:56:01 +03:00
|
|
|
|
|
|
|
// If true, force frames to synchronously decode images on draw.
|
|
|
|
bool mSyncDecodingHint;
|
2003-03-19 04:08:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsImageLoadingContent_h__
|