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.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsXULTemplateQueryProcessorXML_h__
7 #define nsXULTemplateQueryProcessorXML_h__
9 #include "nsIXULTemplateBuilder.h"
10 #include "nsIXULTemplateQueryProcessor.h"
12 #include "nsISimpleEnumerator.h"
13 #include "nsString.h"
14 #include "nsCOMArray.h"
15 #include "nsRefPtrHashtable.h"
16 #include "nsIDOMElement.h"
17 #include "nsIDOMEventListener.h"
18 #include "nsIDOMXPathExpression.h"
19 #include "nsIDOMXPathEvaluator.h"
20 #include "nsIDOMXPathResult.h"
21 #include "nsXMLBinding.h"
22 #include "nsCycleCollectionParticipant.h"
23 #include "nsIXMLHttpRequest.h"
24 #include "mozilla/Attributes.h"
26 class nsXULTemplateQueryProcessorXML;
28 #define NS_IXMLQUERY_IID \
29 {0x0358d692, 0xccce, 0x4a97, \
30 { 0xb2, 0x51, 0xba, 0x8f, 0x17, 0x0f, 0x3b, 0x6f }}
32 class nsXMLQuery MOZ_FINAL : public nsISupports
33 {
34 public:
35 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXMLQUERY_IID)
37 NS_DECL_ISUPPORTS
39 // return a weak reference to the processor the query was created from
40 nsXULTemplateQueryProcessorXML* Processor() { return mProcessor; }
42 // return a weak reference t the member variable for the query
43 nsIAtom* GetMemberVariable() { return mMemberVariable; }
45 // return a weak reference to the expression used to generate results
46 nsIDOMXPathExpression* GetResultsExpression() { return mResultsExpr; }
48 // return a weak reference to the additional required bindings
49 nsXMLBindingSet* GetBindingSet() { return mRequiredBindings; }
51 // add a required binding for the query
52 nsresult
53 AddBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr)
54 {
55 if (!mRequiredBindings) {
56 mRequiredBindings = new nsXMLBindingSet();
57 NS_ENSURE_TRUE(mRequiredBindings, NS_ERROR_OUT_OF_MEMORY);
58 }
60 return mRequiredBindings->AddBinding(aVar, aExpr);
61 }
63 nsXMLQuery(nsXULTemplateQueryProcessorXML* aProcessor,
64 nsIAtom* aMemberVariable,
65 nsIDOMXPathExpression* aResultsExpr)
66 : mProcessor(aProcessor),
67 mMemberVariable(aMemberVariable),
68 mResultsExpr(aResultsExpr)
69 { }
71 protected:
72 nsXULTemplateQueryProcessorXML* mProcessor;
74 nsCOMPtr<nsIAtom> mMemberVariable;
76 nsCOMPtr<nsIDOMXPathExpression> mResultsExpr;
78 nsRefPtr<nsXMLBindingSet> mRequiredBindings;
79 };
81 NS_DEFINE_STATIC_IID_ACCESSOR(nsXMLQuery, NS_IXMLQUERY_IID)
83 class nsXULTemplateResultSetXML MOZ_FINAL : public nsISimpleEnumerator
84 {
85 private:
87 // reference back to the query
88 nsCOMPtr<nsXMLQuery> mQuery;
90 // the binding set created from <assign> nodes
91 nsRefPtr<nsXMLBindingSet> mBindingSet;
93 // set of results contained in this enumerator
94 nsCOMPtr<nsIDOMXPathResult> mResults;
96 // current position within the list of results
97 uint32_t mPosition;
99 public:
101 // nsISupports interface
102 NS_DECL_ISUPPORTS
104 // nsISimpleEnumerator interface
105 NS_DECL_NSISIMPLEENUMERATOR
107 nsXULTemplateResultSetXML(nsXMLQuery* aQuery,
108 nsIDOMXPathResult* aResults,
109 nsXMLBindingSet* aBindingSet)
110 : mQuery(aQuery),
111 mBindingSet(aBindingSet),
112 mResults(aResults),
113 mPosition(0)
114 {}
115 };
117 class nsXULTemplateQueryProcessorXML MOZ_FINAL : public nsIXULTemplateQueryProcessor,
118 public nsIDOMEventListener
119 {
120 public:
122 nsXULTemplateQueryProcessorXML()
123 : mGenerationStarted(false)
124 {}
126 // nsISupports interface
127 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
128 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULTemplateQueryProcessorXML,
129 nsIXULTemplateQueryProcessor)
131 // nsIXULTemplateQueryProcessor interface
132 NS_DECL_NSIXULTEMPLATEQUERYPROCESSOR
134 // nsIDOMEventListener interface
135 NS_DECL_NSIDOMEVENTLISTENER
137 nsXMLBindingSet*
138 GetOptionalBindingsForRule(nsIDOMNode* aRuleNode);
140 // create an XPath expression from aExpr, using aNode for
141 // resolving namespaces
142 nsresult
143 CreateExpression(const nsAString& aExpr,
144 nsIDOMNode* aNode,
145 nsIDOMXPathExpression** aCompiledExpr);
147 private:
149 bool mGenerationStarted;
151 nsRefPtrHashtable<nsISupportsHashKey, nsXMLBindingSet> mRuleToBindingsMap;
153 nsCOMPtr<nsIDOMElement> mRoot;
155 nsCOMPtr<nsIDOMXPathEvaluator> mEvaluator;
157 nsCOMPtr<nsIXULTemplateBuilder> mTemplateBuilder;
159 nsCOMPtr<nsIXMLHttpRequest> mRequest;
160 };
163 #endif // nsXULTemplateQueryProcessorXML_h__