nsHtml5StringParser.h (3175B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef nsHtml5StringParser_h 6 #define nsHtml5StringParser_h 7 8 #include "mozilla/UniquePtr.h" 9 #include "nsHtml5AtomTable.h" 10 #include "nsParserBase.h" 11 12 class nsHtml5OplessBuilder; 13 class nsHtml5TreeBuilder; 14 class nsHtml5Tokenizer; 15 class nsIContent; 16 namespace mozilla { 17 namespace dom { 18 class Document; 19 } 20 } // namespace mozilla 21 22 class nsHtml5StringParser : public nsParserBase { 23 public: 24 NS_DECL_ISUPPORTS 25 26 /** 27 * Constructor for use ONLY by nsContentUtils. Others, please call the 28 * nsContentUtils statics that wrap this. 29 */ 30 nsHtml5StringParser(); 31 32 /** 33 * Invoke the fragment parsing algorithm (innerHTML). 34 * DO NOT CALL from outside nsContentUtils.cpp. 35 * 36 * @param aSourceBuffer the string being set as innerHTML 37 * @param aTargetNode the target container 38 * @param aContextLocalName local name of context node 39 * @param aContextNamespace namespace of context node 40 * @param aQuirks true to make <table> not close <p> 41 * @param aPreventScriptExecution true to prevent scripts from executing; 42 * don't set to false when parsing into a target node that has been bound 43 * to tree. 44 * @param aAllowDeclarativeShadowRoots allow the creation of declarative 45 * shadow roots. 46 */ 47 nsresult ParseFragment(const nsAString& aSourceBuffer, 48 nsIContent* aTargetNode, nsAtom* aContextLocalName, 49 int32_t aContextNamespace, bool aQuirks, 50 bool aPreventScriptExecution, 51 bool aAllowDeclarativeShadowRoots); 52 53 /** 54 * Parse an entire HTML document from a source string. 55 * DO NOT CALL from outside nsContentUtils.cpp. 56 * 57 */ 58 nsresult ParseDocument(const nsAString& aSourceBuffer, 59 mozilla::dom::Document* aTargetDoc, 60 bool aScriptingEnabledForNoscriptParsing); 61 62 private: 63 virtual ~nsHtml5StringParser(); 64 65 nsresult Tokenize(const nsAString& aSourceBuffer, 66 mozilla::dom::Document* aDocument, 67 bool aScriptingEnabledForNoscriptParsing, 68 bool aDeclarativeShadowRootsAllowed); 69 70 void TryCache(); 71 void ClearCaches(); 72 73 /** 74 * The tree operation executor 75 */ 76 RefPtr<nsHtml5OplessBuilder> mBuilder; 77 78 /** 79 * The HTML5 tree builder 80 */ 81 const mozilla::UniquePtr<nsHtml5TreeBuilder> mTreeBuilder; 82 83 /** 84 * The HTML5 tokenizer 85 */ 86 const mozilla::UniquePtr<nsHtml5Tokenizer> mTokenizer; 87 88 /** 89 * The scoped atom table 90 */ 91 nsHtml5AtomTable mAtomTable; 92 93 class CacheClearer : public mozilla::Runnable { 94 public: 95 explicit CacheClearer(nsHtml5StringParser* aParser) 96 : Runnable("CacheClearer"), mParser(aParser) {} 97 NS_IMETHOD Run() { 98 if (mParser) { 99 mParser->ClearCaches(); 100 } 101 return NS_OK; 102 } 103 void Disconnect() { mParser = nullptr; } 104 105 private: 106 nsHtml5StringParser* mParser; 107 }; 108 109 RefPtr<CacheClearer> mCacheClearer; 110 }; 111 112 #endif // nsHtml5StringParser_h