Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsXULContentSink_h__ |
michael@0 | 7 | #define nsXULContentSink_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.h" |
michael@0 | 10 | #include "nsIExpatSink.h" |
michael@0 | 11 | #include "nsIXMLContentSink.h" |
michael@0 | 12 | #include "nsAutoPtr.h" |
michael@0 | 13 | #include "nsNodeInfoManager.h" |
michael@0 | 14 | #include "nsWeakPtr.h" |
michael@0 | 15 | #include "nsXULElement.h" |
michael@0 | 16 | #include "nsIDTD.h" |
michael@0 | 17 | |
michael@0 | 18 | class nsIDocument; |
michael@0 | 19 | class nsIScriptSecurityManager; |
michael@0 | 20 | class nsAttrName; |
michael@0 | 21 | class nsXULPrototypeDocument; |
michael@0 | 22 | class nsXULPrototypeElement; |
michael@0 | 23 | class nsXULPrototypeNode; |
michael@0 | 24 | |
michael@0 | 25 | class XULContentSinkImpl : public nsIXMLContentSink, |
michael@0 | 26 | public nsIExpatSink |
michael@0 | 27 | { |
michael@0 | 28 | public: |
michael@0 | 29 | XULContentSinkImpl(); |
michael@0 | 30 | virtual ~XULContentSinkImpl(); |
michael@0 | 31 | |
michael@0 | 32 | // nsISupports |
michael@0 | 33 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 34 | NS_DECL_NSIEXPATSINK |
michael@0 | 35 | |
michael@0 | 36 | NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(XULContentSinkImpl, nsIXMLContentSink) |
michael@0 | 37 | |
michael@0 | 38 | // nsIContentSink |
michael@0 | 39 | NS_IMETHOD WillParse(void) MOZ_OVERRIDE { return NS_OK; } |
michael@0 | 40 | NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) MOZ_OVERRIDE; |
michael@0 | 41 | NS_IMETHOD DidBuildModel(bool aTerminated) MOZ_OVERRIDE; |
michael@0 | 42 | NS_IMETHOD WillInterrupt(void) MOZ_OVERRIDE; |
michael@0 | 43 | NS_IMETHOD WillResume(void) MOZ_OVERRIDE; |
michael@0 | 44 | NS_IMETHOD SetParser(nsParserBase* aParser) MOZ_OVERRIDE; |
michael@0 | 45 | virtual void FlushPendingNotifications(mozFlushType aType) MOZ_OVERRIDE { } |
michael@0 | 46 | NS_IMETHOD SetDocumentCharset(nsACString& aCharset) MOZ_OVERRIDE; |
michael@0 | 47 | virtual nsISupports *GetTarget() MOZ_OVERRIDE; |
michael@0 | 48 | |
michael@0 | 49 | /** |
michael@0 | 50 | * Initialize the content sink, giving it an nsIDocument object |
michael@0 | 51 | * with which to communicate with the outside world, and an |
michael@0 | 52 | * nsXULPrototypeDocument to build. |
michael@0 | 53 | */ |
michael@0 | 54 | nsresult Init(nsIDocument* aDocument, nsXULPrototypeDocument* aPrototype); |
michael@0 | 55 | |
michael@0 | 56 | protected: |
michael@0 | 57 | // pseudo-constants |
michael@0 | 58 | char16_t* mText; |
michael@0 | 59 | int32_t mTextLength; |
michael@0 | 60 | int32_t mTextSize; |
michael@0 | 61 | bool mConstrainSize; |
michael@0 | 62 | |
michael@0 | 63 | nsresult AddAttributes(const char16_t** aAttributes, |
michael@0 | 64 | const uint32_t aAttrLen, |
michael@0 | 65 | nsXULPrototypeElement* aElement); |
michael@0 | 66 | |
michael@0 | 67 | nsresult OpenRoot(const char16_t** aAttributes, |
michael@0 | 68 | const uint32_t aAttrLen, |
michael@0 | 69 | nsINodeInfo *aNodeInfo); |
michael@0 | 70 | |
michael@0 | 71 | nsresult OpenTag(const char16_t** aAttributes, |
michael@0 | 72 | const uint32_t aAttrLen, |
michael@0 | 73 | const uint32_t aLineNumber, |
michael@0 | 74 | nsINodeInfo *aNodeInfo); |
michael@0 | 75 | |
michael@0 | 76 | // If OpenScript returns NS_OK and after it returns our state is eInScript, |
michael@0 | 77 | // that means that we created a prototype script and stuck it on |
michael@0 | 78 | // mContextStack. If NS_OK is returned but the state is still |
michael@0 | 79 | // eInDocumentElement then we didn't create a prototype script (e.g. the |
michael@0 | 80 | // script had an unknown type), and the caller should create a prototype |
michael@0 | 81 | // element. |
michael@0 | 82 | nsresult OpenScript(const char16_t** aAttributes, |
michael@0 | 83 | const uint32_t aLineNumber); |
michael@0 | 84 | |
michael@0 | 85 | static bool IsDataInBuffer(char16_t* aBuffer, int32_t aLength); |
michael@0 | 86 | |
michael@0 | 87 | // Text management |
michael@0 | 88 | nsresult FlushText(bool aCreateTextNode = true); |
michael@0 | 89 | nsresult AddText(const char16_t* aText, int32_t aLength); |
michael@0 | 90 | |
michael@0 | 91 | |
michael@0 | 92 | nsRefPtr<nsNodeInfoManager> mNodeInfoManager; |
michael@0 | 93 | |
michael@0 | 94 | nsresult NormalizeAttributeString(const char16_t *aExpatName, |
michael@0 | 95 | nsAttrName &aName); |
michael@0 | 96 | nsresult CreateElement(nsINodeInfo *aNodeInfo, |
michael@0 | 97 | nsXULPrototypeElement** aResult); |
michael@0 | 98 | |
michael@0 | 99 | |
michael@0 | 100 | public: |
michael@0 | 101 | enum State { eInProlog, eInDocumentElement, eInScript, eInEpilog }; |
michael@0 | 102 | protected: |
michael@0 | 103 | |
michael@0 | 104 | State mState; |
michael@0 | 105 | |
michael@0 | 106 | // content stack management |
michael@0 | 107 | class ContextStack { |
michael@0 | 108 | protected: |
michael@0 | 109 | struct Entry { |
michael@0 | 110 | nsRefPtr<nsXULPrototypeNode> mNode; |
michael@0 | 111 | // a LOT of nodes have children; preallocate for 8 |
michael@0 | 112 | nsPrototypeArray mChildren; |
michael@0 | 113 | State mState; |
michael@0 | 114 | Entry* mNext; |
michael@0 | 115 | Entry() : mChildren(8) {} |
michael@0 | 116 | }; |
michael@0 | 117 | |
michael@0 | 118 | Entry* mTop; |
michael@0 | 119 | int32_t mDepth; |
michael@0 | 120 | |
michael@0 | 121 | public: |
michael@0 | 122 | ContextStack(); |
michael@0 | 123 | ~ContextStack(); |
michael@0 | 124 | |
michael@0 | 125 | int32_t Depth() { return mDepth; } |
michael@0 | 126 | |
michael@0 | 127 | nsresult Push(nsXULPrototypeNode* aNode, State aState); |
michael@0 | 128 | nsresult Pop(State* aState); |
michael@0 | 129 | |
michael@0 | 130 | nsresult GetTopNode(nsRefPtr<nsXULPrototypeNode>& aNode); |
michael@0 | 131 | nsresult GetTopChildren(nsPrototypeArray** aChildren); |
michael@0 | 132 | |
michael@0 | 133 | void Clear(); |
michael@0 | 134 | |
michael@0 | 135 | void Traverse(nsCycleCollectionTraversalCallback& aCallback); |
michael@0 | 136 | }; |
michael@0 | 137 | |
michael@0 | 138 | friend class ContextStack; |
michael@0 | 139 | ContextStack mContextStack; |
michael@0 | 140 | |
michael@0 | 141 | nsWeakPtr mDocument; // [OWNER] |
michael@0 | 142 | nsCOMPtr<nsIURI> mDocumentURL; // [OWNER] |
michael@0 | 143 | |
michael@0 | 144 | nsRefPtr<nsXULPrototypeDocument> mPrototype; // [OWNER] |
michael@0 | 145 | |
michael@0 | 146 | // We use regular pointer b/c of funky exports on nsIParser: |
michael@0 | 147 | nsParserBase* mParser; // [OWNER] |
michael@0 | 148 | nsCOMPtr<nsIScriptSecurityManager> mSecMan; |
michael@0 | 149 | }; |
michael@0 | 150 | |
michael@0 | 151 | #endif /* nsXULContentSink_h__ */ |