2012-05-29 19:52:43 +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/. */
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2013-08-23 19:07:10 +04:00
|
|
|
#ifndef nsHtml5TreeOpExecutor_h
|
|
|
|
#define nsHtml5TreeOpExecutor_h
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2014-03-05 23:38:49 +04:00
|
|
|
#include "nsTraceRefcnt.h"
|
2009-09-18 13:21:47 +04:00
|
|
|
#include "nsHtml5TreeOperation.h"
|
2010-02-26 12:18:38 +03:00
|
|
|
#include "nsHtml5SpeculativeLoad.h"
|
2009-09-18 13:21:47 +04:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsContentSink.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsHtml5DocumentMode.h"
|
|
|
|
#include "nsIScriptElement.h"
|
|
|
|
#include "nsIParser.h"
|
2009-09-21 17:18:20 +04:00
|
|
|
#include "nsAHtml5TreeOpSink.h"
|
|
|
|
#include "nsHtml5TreeOpStage.h"
|
2010-02-26 12:18:38 +03:00
|
|
|
#include "nsIURI.h"
|
2011-11-09 00:22:47 +04:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2012-06-14 22:00:05 +04:00
|
|
|
#include "mozilla/LinkedList.h"
|
2014-03-05 23:38:49 +04:00
|
|
|
#include "nsHtml5DocumentBuilder.h"
|
2014-11-18 16:46:29 +03:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2011-09-04 14:49:29 +04:00
|
|
|
class nsHtml5Parser;
|
2009-09-18 13:21:47 +04:00
|
|
|
class nsHtml5StreamParser;
|
2014-08-18 18:44:50 +04:00
|
|
|
class nsIContent;
|
2019-01-02 16:05:23 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Document;
|
|
|
|
}
|
|
|
|
} // namespace mozilla
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
class nsHtml5TreeOpExecutor final
|
|
|
|
: public nsHtml5DocumentBuilder,
|
|
|
|
public nsIContentSink,
|
|
|
|
public nsAHtml5TreeOpSink,
|
|
|
|
public mozilla::LinkedListElement<nsHtml5TreeOpExecutor> {
|
2010-02-26 12:18:38 +03:00
|
|
|
friend class nsHtml5FlushLoopGuard;
|
2014-11-18 16:46:29 +03:00
|
|
|
typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
|
2017-06-18 14:37:50 +03:00
|
|
|
using Encoding = mozilla::Encoding;
|
2018-03-16 18:26:06 +03:00
|
|
|
template <typename T>
|
|
|
|
using NotNull = mozilla::NotNull<T>;
|
2010-02-26 12:18:38 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
private:
|
2010-01-14 16:58:27 +03:00
|
|
|
#ifdef DEBUG_NS_HTML5_TREE_OP_EXECUTOR_FLUSH
|
2018-03-16 18:26:06 +03:00
|
|
|
static uint32_t sAppendBatchMaxSize;
|
|
|
|
static uint32_t sAppendBatchSlotsExamined;
|
|
|
|
static uint32_t sAppendBatchExaminations;
|
|
|
|
static uint32_t sLongestTimeOffTheEventLoop;
|
|
|
|
static uint32_t sTimesFlushLoopInterrupted;
|
2009-09-18 13:21:47 +04:00
|
|
|
#endif
|
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Whether EOF needs to be suppressed
|
|
|
|
*/
|
|
|
|
bool mSuppressEOF;
|
2018-01-23 16:07:37 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
bool mReadingFromStage;
|
|
|
|
nsTArray<nsHtml5TreeOperation> mOpQueue;
|
|
|
|
nsHtml5StreamParser* mStreamParser;
|
2018-01-23 16:07:37 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* URLs already preloaded/preloading.
|
|
|
|
*/
|
|
|
|
nsTHashtable<nsCStringHashKey> mPreloadedURLs;
|
2010-02-26 12:18:38 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
nsCOMPtr<nsIURI> mSpeculationBaseURI;
|
2010-07-26 15:18:43 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Speculative referrer policy
|
|
|
|
*/
|
|
|
|
ReferrerPolicy mSpeculationReferrerPolicy;
|
2014-11-18 16:46:29 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
nsCOMPtr<nsIURI> mViewSourceBaseURI;
|
2010-07-30 14:15:38 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Whether the parser has started
|
|
|
|
*/
|
|
|
|
bool mStarted;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
nsHtml5TreeOpStage mStage;
|
2009-10-15 15:29:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
bool mRunFlushLoopOnStack;
|
2010-02-26 12:18:38 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
bool mCallContinueInterruptedParsingIfEnabled;
|
2010-02-26 12:18:38 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Whether this executor has already complained about matters related
|
|
|
|
* to character encoding declarations.
|
|
|
|
*/
|
|
|
|
bool mAlreadyComplainedAboutCharset;
|
2012-03-24 15:34:42 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
public:
|
|
|
|
nsHtml5TreeOpExecutor();
|
2014-07-09 01:23:18 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
protected:
|
|
|
|
virtual ~nsHtml5TreeOpExecutor();
|
2014-07-09 01:23:18 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
public:
|
|
|
|
// nsIContentSink
|
2014-07-09 01:23:18 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Unimplemented. For interface compat only.
|
|
|
|
*/
|
|
|
|
NS_IMETHOD WillParse() override;
|
2014-07-09 01:23:18 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) override;
|
2014-07-09 01:23:18 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Emits EOF.
|
|
|
|
*/
|
|
|
|
NS_IMETHOD DidBuildModel(bool aTerminated) override;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Forwards to nsContentSink
|
|
|
|
*/
|
|
|
|
NS_IMETHOD WillInterrupt() override;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Unimplemented. For interface compat only.
|
|
|
|
*/
|
|
|
|
NS_IMETHOD WillResume() override;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Sets the parser.
|
|
|
|
*/
|
|
|
|
NS_IMETHOD SetParser(nsParserBase* aParser) override;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* No-op for backwards compat.
|
|
|
|
*/
|
|
|
|
virtual void FlushPendingNotifications(mozilla::FlushType aType) override;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Don't call. For interface compat only.
|
|
|
|
*/
|
|
|
|
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) override {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("No one should call this.");
|
2018-03-16 18:26:06 +03:00
|
|
|
}
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Returns the document.
|
|
|
|
*/
|
|
|
|
virtual nsISupports* GetTarget() override;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
virtual void ContinueInterruptedParsingAsync() override;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
bool IsScriptExecuting() override { return IsScriptExecutingImpl(); }
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
// Not from interface
|
2018-01-23 16:07:37 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void SetStreamParser(nsHtml5StreamParser* aStreamParser) {
|
|
|
|
mStreamParser = aStreamParser;
|
|
|
|
}
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void InitializeDocWriteParserState(nsAHtml5TreeBuilderState* aState,
|
|
|
|
int32_t aLine);
|
2010-03-09 15:39:32 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
bool IsScriptEnabled();
|
2014-03-06 00:26:07 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
virtual nsresult MarkAsBroken(nsresult aReason) override;
|
2018-01-23 16:07:37 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void StartLayout(bool* aInterrupted);
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void PauseDocUpdate(bool* aInterrupted);
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void FlushSpeculativeLoads();
|
2014-03-06 00:26:07 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void RunFlushLoop();
|
2017-03-17 04:50:28 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
nsresult FlushDocumentWrite();
|
2018-01-23 16:07:37 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void MaybeSuspend();
|
2018-01-23 16:07:37 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void Start();
|
2010-02-26 12:18:38 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void NeedsCharsetSwitchTo(NotNull<const Encoding*> aEncoding, int32_t aSource,
|
|
|
|
uint32_t aLineNumber);
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void MaybeComplainAboutCharset(const char* aMsgId, bool aError,
|
|
|
|
uint32_t aLineNumber);
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void ComplainAboutBogusProtocolCharset(mozilla::dom::Document*);
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
bool HasStarted() { return mStarted; }
|
2012-03-24 15:34:42 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
bool IsFlushing() { return mFlushState >= eInFlush; }
|
2010-02-26 12:18:38 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2018-03-16 18:26:06 +03:00
|
|
|
bool IsInFlushLoop() { return mRunFlushLoopOnStack; }
|
2010-02-26 12:18:38 +03:00
|
|
|
#endif
|
2018-01-23 16:07:37 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void RunScript(nsIContent* aScriptElement);
|
2018-01-23 16:07:37 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Flush the operations from the tree operations from the argument
|
|
|
|
* queue unconditionally. (This is for the main thread case.)
|
|
|
|
*/
|
|
|
|
virtual void MoveOpsFrom(nsTArray<nsHtml5TreeOperation>& aOpQueue) override;
|
2017-10-27 10:06:33 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void ClearOpQueue();
|
2017-10-27 10:06:33 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void RemoveFromStartOfOpQueue(size_t aNumberOfOpsToRemove);
|
2017-10-27 10:06:33 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
inline size_t OpQueueLength() { return mOpQueue.Length(); }
|
2017-10-27 10:06:33 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
nsHtml5TreeOpStage* GetStage() { return &mStage; }
|
2018-01-23 16:07:37 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void StartReadingFromStage() { mReadingFromStage = true; }
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void StreamEnded();
|
2018-01-23 16:07:37 +03:00
|
|
|
|
2009-10-12 17:08:04 +04:00
|
|
|
#ifdef DEBUG
|
2018-03-16 18:26:06 +03:00
|
|
|
void AssertStageEmpty() { mStage.AssertEmpty(); }
|
2009-10-12 17:08:04 +04:00
|
|
|
#endif
|
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
nsIURI* GetViewSourceBaseURI();
|
2010-07-30 14:15:38 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void PreloadScript(const nsAString& aURL, const nsAString& aCharset,
|
|
|
|
const nsAString& aType, const nsAString& aCrossOrigin,
|
|
|
|
const nsAString& aIntegrity,
|
2018-11-19 12:39:16 +03:00
|
|
|
ReferrerPolicy aReferrerPolicy, bool aScriptFromHead,
|
2018-03-16 18:26:06 +03:00
|
|
|
bool aAsync, bool aDefer, bool aNoModule);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void PreloadStyle(const nsAString& aURL, const nsAString& aCharset,
|
|
|
|
const nsAString& aCrossOrigin,
|
|
|
|
const nsAString& aReferrerPolicy,
|
|
|
|
const nsAString& aIntegrity);
|
2010-02-26 12:18:38 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void PreloadImage(const nsAString& aURL, const nsAString& aCrossOrigin,
|
|
|
|
const nsAString& aSrcset, const nsAString& aSizes,
|
|
|
|
const nsAString& aImageReferrerPolicy);
|
2014-12-11 02:54:00 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void PreloadOpenPicture();
|
2014-12-11 02:54:00 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void PreloadEndPicture();
|
2014-12-11 02:54:00 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void PreloadPictureSource(const nsAString& aSrcset, const nsAString& aSizes,
|
|
|
|
const nsAString& aType, const nsAString& aMedia);
|
2010-02-26 12:18:38 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void SetSpeculationBase(const nsAString& aURL);
|
2014-11-18 16:46:29 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void SetSpeculationReferrerPolicy(ReferrerPolicy aReferrerPolicy);
|
|
|
|
void SetSpeculationReferrerPolicy(const nsAString& aReferrerPolicy);
|
2014-12-11 02:54:00 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void AddSpeculationCSP(const nsAString& aCSP);
|
2015-11-15 06:28:51 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void AddBase(const nsAString& aURL);
|
2010-07-26 15:18:43 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
private:
|
|
|
|
nsHtml5Parser* GetParser();
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
bool IsExternalViewSource();
|
2012-03-27 10:27:45 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Get a nsIURI for an nsString if the URL hasn't been preloaded yet.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsIURI> ConvertIfNotPreloadedYet(const nsAString& aURL);
|
2010-02-26 12:18:38 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* The base URI we would use for current preload operations
|
|
|
|
*/
|
|
|
|
nsIURI* BaseURIForPreload();
|
2014-12-11 02:54:00 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Returns true if we haven't preloaded this URI yet, and adds it to the
|
|
|
|
* list of preloaded URIs
|
|
|
|
*/
|
|
|
|
bool ShouldPreloadURI(nsIURI* aURI);
|
2018-11-19 12:39:16 +03:00
|
|
|
|
|
|
|
ReferrerPolicy GetPreloadReferrerPolicy(const nsAString& aReferrerPolicy);
|
2009-09-18 13:21:47 +04:00
|
|
|
};
|
|
|
|
|
2013-08-23 19:07:10 +04:00
|
|
|
#endif // nsHtml5TreeOpExecutor_h
|