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