2014-03-05 23:38:49 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef nsHtml5DocumentBuilder_h
|
|
|
|
#define nsHtml5DocumentBuilder_h
|
|
|
|
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2014-03-05 23:38:50 +04:00
|
|
|
#include "nsContentSink.h"
|
|
|
|
#include "nsHtml5DocumentMode.h"
|
2014-06-17 03:01:22 +04:00
|
|
|
#include "nsIContent.h"
|
2014-03-05 23:38:49 +04:00
|
|
|
|
2020-11-23 19:07:43 +03:00
|
|
|
namespace mozilla::dom {
|
|
|
|
class Document;
|
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:49 +04:00
|
|
|
typedef nsIContent* nsIContentPtr;
|
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
enum eHtml5FlushState {
|
|
|
|
eNotFlushing = 0, // not flushing
|
|
|
|
eInFlush = 1, // the Flush() method is on the call stack
|
|
|
|
eInDocUpdate = 2, // inside an update batch on the document
|
2014-03-05 23:38:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsHtml5DocumentBuilder : public nsContentSink {
|
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>;
|
|
|
|
|
2014-03-05 23:38:49 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHtml5DocumentBuilder,
|
|
|
|
nsContentSink)
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2014-06-17 03:01:22 +04:00
|
|
|
inline void HoldElement(already_AddRefed<nsIContent> aContent) {
|
|
|
|
*(mOwnedElements.AppendElement()) = aContent;
|
2014-03-05 23:38:49 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult Init(Document* aDoc, nsIURI* aURI, nsISupports* aContainer,
|
2018-03-16 18:26:06 +03:00
|
|
|
nsIChannel* aChannel);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
// Getters and setters for fields from nsContentSink
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* GetDocument() { return mDocument; }
|
2014-03-05 23:38:50 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
nsNodeInfoManager* GetNodeInfoManager() { return mNodeInfoManager; }
|
2014-03-05 23:38:49 +04:00
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
/**
|
|
|
|
* Marks this parser as broken and tells the stream parser (if any) to
|
|
|
|
* terminate.
|
|
|
|
*
|
|
|
|
* @return aReason for convenience
|
|
|
|
*/
|
|
|
|
virtual nsresult MarkAsBroken(nsresult aReason);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if this parser is broken. Returns a non-NS_OK (i.e. non-0)
|
|
|
|
* value if broken.
|
|
|
|
*/
|
2018-03-16 18:26:06 +03:00
|
|
|
inline nsresult IsBroken() { return mBroken; }
|
2014-03-05 23:38:50 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
inline bool IsComplete() { return !mParser; }
|
2017-10-27 10:06:33 +03:00
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
inline void BeginDocUpdate() {
|
2017-10-27 10:06:33 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsInFlush(), "Tried to double-open doc update.");
|
|
|
|
MOZ_RELEASE_ASSERT(mParser, "Started doc update without parser.");
|
2014-03-05 23:38:50 +04:00
|
|
|
mFlushState = eInDocUpdate;
|
2018-05-15 16:56:38 +03:00
|
|
|
mDocument->BeginUpdate();
|
2014-03-05 23:38:50 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
inline void EndDocUpdate() {
|
2017-10-27 10:06:33 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsInDocUpdate(),
|
|
|
|
"Tried to end doc update without one open.");
|
|
|
|
mFlushState = eInFlush;
|
2018-05-15 16:56:38 +03:00
|
|
|
mDocument->EndUpdate();
|
2017-10-27 10:06:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void BeginFlush() {
|
|
|
|
MOZ_RELEASE_ASSERT(mFlushState == eNotFlushing,
|
|
|
|
"Tried to start a flush when already flushing.");
|
|
|
|
MOZ_RELEASE_ASSERT(mParser, "Started a flush without parser.");
|
|
|
|
mFlushState = eInFlush;
|
2014-03-05 23:38:50 +04:00
|
|
|
}
|
|
|
|
|
2017-10-27 10:06:33 +03:00
|
|
|
inline void EndFlush() {
|
|
|
|
MOZ_RELEASE_ASSERT(IsInFlush(), "Tried to end flush when not flushing.");
|
|
|
|
mFlushState = eNotFlushing;
|
2014-06-17 03:01:22 +04:00
|
|
|
}
|
|
|
|
|
2017-10-27 10:06:33 +03:00
|
|
|
inline bool IsInDocUpdate() { return mFlushState == eInDocUpdate; }
|
|
|
|
|
|
|
|
inline bool IsInFlush() { return mFlushState == eInFlush; }
|
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
void SetDocumentCharsetAndSource(NotNull<const Encoding*> aEncoding,
|
|
|
|
int32_t aCharsetSource);
|
2014-03-05 23:38:50 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up style sheet load / parse
|
|
|
|
*/
|
|
|
|
void UpdateStyleSheet(nsIContent* aElement);
|
|
|
|
|
|
|
|
void SetDocumentMode(nsHtml5DocumentMode m);
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
void SetNodeInfoManager(nsNodeInfoManager* aManager) {
|
2014-03-05 23:38:50 +04:00
|
|
|
mNodeInfoManager = aManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsContentSink methods
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void UpdateChildCounts() override;
|
|
|
|
virtual nsresult FlushTags() override;
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
protected:
|
2014-09-02 02:04:20 +04:00
|
|
|
explicit nsHtml5DocumentBuilder(bool aRunsToCompletion);
|
2014-03-05 23:38:50 +04:00
|
|
|
virtual ~nsHtml5DocumentBuilder();
|
|
|
|
|
2014-03-05 23:38:49 +04:00
|
|
|
protected:
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<nsCOMPtr<nsIContent>, 32> mOwnedElements;
|
2014-03-05 23:38:50 +04:00
|
|
|
/**
|
|
|
|
* Non-NS_OK if this parser should refuse to process any more input.
|
|
|
|
* For example, the parser needs to be marked as broken if it drops some
|
|
|
|
* input due to a memory allocation failure. In such a case, the whole
|
|
|
|
* parser needs to be marked as broken, because some input has been lost
|
|
|
|
* and parsing more input could lead to a DOM where pieces of HTML source
|
|
|
|
* that weren't supposed to become scripts become scripts.
|
|
|
|
*/
|
2018-03-16 18:26:06 +03:00
|
|
|
nsresult mBroken;
|
|
|
|
eHtml5FlushState mFlushState;
|
2014-03-05 23:38:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsHtml5DocumentBuilder_h
|