Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 #include "domstubs.idl"
8 interface nsIAtom;
9 interface nsIArray;
10 interface nsISimpleEnumerator;
11 interface nsIXULTemplateResult;
12 interface nsIXULTemplateRuleFilter;
13 interface nsIXULTemplateBuilder;
15 /**
16 * A query processor takes a template query and generates results for it given
17 * a datasource and a reference point. There is a one-to-one relationship
18 * between a template builder and a query processor. The template builder
19 * creates the query processor, and there is no other means to retrieve it.
20 *
21 * A template query is the contents inside a <query> element within the
22 * template. The actual syntax is opaque to the template builder and defined
23 * by a query processor. The query is expected to consist of either text or
24 * DOM nodes that, when executed by a call to the generateResults method, will
25 * allow the generation of a list of results.
26 *
27 * The template builder will supply two variables, the reference variable and
28 * the member variable to further indicate what part of the datasource is to
29 * be examined in addition to the query itself. The reference is always
30 * a placeholder for the starting point and the member is always a placeholder
31 * for the end points (the results).
32 *
33 * The reference point is important when generating output recursively, as
34 * the query will be the same for each iteration, however, the reference point
35 * will differ.
36 *
37 * For instance, when examining an XML source, an XML query processor might
38 * begin at the node referred by the reference variable and end at a list of
39 * that node's children.
40 *
41 * Some queries may not need the reference variable if the syntax or the form
42 * of the data implies the value. For instance, a datasource that holds a
43 * table that can only produce one set of results.
44 *
45 * The reference variable may be specified in a template by setting the
46 * "container" attribute on the <template> element to the variable to use. The
47 * member variable may be specified in a similar way using the "member"
48 * attribute, or it may be specified in the first <action> body in the
49 * template as the value of a uri attribute on an element. A breadth-first
50 * search of the first action is performed to find this element.
51 *
52 * If unspecified, the default value of the reference variable is ?uri.
53 *
54 * For example, a query might have the following syntax:
55 *
56 * (?id, ?name, ?url) from Bookmarks where parentfolder = ?start
57 *
58 * This query might generate a result for each bookmark within a given folder.
59 * The variable ?start would be the reference variable, while the variable ?id
60 * would be the member variable, since it is the unique value that identifies
61 * a result. Each result will have the four variables referred to defined for
62 * it and the values may be retrieved using the result's getBindingFor and
63 * getBindingObjectFor methods.
64 *
65 * The template builder must call initializeForBuilding before the other
66 * methods, except for translateRef. The builder will then call compileQuery
67 * for each query in the template to compile the queries. When results need
68 * to be generated, the builder will call generateResults. The
69 * initializeForBuilding, compileQuery and addBinding methods may not be
70 * called after generateResults has been called until the builder indicates
71 * that the generated output is being removed by calling the done method.
72 *
73 * Currently, the datasource supplied to the methods will always be an
74 * nsIRDFDataSource or a DOM node, and will always be the same one in between
75 * calls to initializeForBuilding and done.
76 */
77 [scriptable, uuid(C257573F-444F-468A-BA27-DE979DC55FE4)]
78 interface nsIXULTemplateQueryProcessor : nsISupports
79 {
80 /**
81 * Retrieve the datasource to use for the query processor. The list of
82 * datasources in a template is specified using the datasources attribute as
83 * a space separated list of URIs. This list is processed by the builder and
84 * supplied to the query processor in the aDataSources array as a list of
85 * nsIURI objects or nsIDOMNode objects. This method may return an object
86 * corresponding to these URIs and the builder will supply this object to
87 * other query processor methods. For example, for an XML source, the
88 * datasource might be an nsIDOMNode.
89 *
90 * All of these URIs are checked by the builder so it is safe to use them,
91 * however note that a URI that redirects may still needs to be checked to
92 * ensure that the document containing aRootNode may access it. This is the
93 * responsibility of the query processor if it needs to load the content of
94 * the URI.
95 *
96 * If the query processor needs to load the datasource asynchronously, it
97 * may set the aShouldDelayBuilding returned parameter to true to delay
98 * building the template content, and call the builder's Rebuild method when
99 * the data is available.
100 *
101 * @param aDataSources the list of nsIURI objects and/or nsIDOMNode objects
102 * @param aRootNode the root node the builder is attached to
103 * @param aIsTrusted true if the template is in a trusted document
104 * @param aBuilder the template builder
105 * @param aShouldDelayBuilding [out] whether the builder should wait to
106 * build the content or not
107 * @returns a datasource object
108 */
109 nsISupports getDatasource(in nsIArray aDataSources,
110 in nsIDOMNode aRootNode,
111 in boolean aIsTrusted,
112 in nsIXULTemplateBuilder aBuilder,
113 out boolean aShouldDelayBuilding);
115 /**
116 * Initialize for query generation. This will be called before the rules are
117 * processed and whenever the template is rebuilt. This method must be
118 * called once before any of the other query processor methods except for
119 * translateRef.
120 *
121 * @param aDatasource datasource for the data
122 * @param aBuilder the template builder
123 * @param aRootNode the root node the builder is attached to
124 *
125 * @throws NS_ERROR_INVALID_ARG if the datasource is not supported or
126 * NS_ERROR_UNEXPECTED if generateResults has already been called.
127 */
128 void initializeForBuilding(in nsISupports aDatasource,
129 in nsIXULTemplateBuilder aBuilder,
130 in nsIDOMNode aRootNode);
132 /**
133 * Called when the template builder is being destroyed so that the query
134 * processor can clean up any state. The query processor should remove as
135 * much state as possible, such as results or references to the builder.
136 * This method will also be called when the template is going to be rebuilt.
137 */
138 void done();
140 /**
141 * Compile a query from a node. The result of this function will later be
142 * passed to generateResults for result generation. If null is returned,
143 * the query will be ignored.
144 *
145 * The template builder will call this method once for each query within
146 * the template, before any results can be generated using generateResults,
147 * but after initializeForBuilding has been called. This method should not
148 * be called again for the same query unless the template is rebuilt.
149 *
150 * The reference variable may be used by the query processor as a
151 * placeholder for the reference point, or starting point in the query.
152 *
153 * The member variable is determined from the member attribute on the
154 * template, or from the uri in the first action's rule if that attribute is
155 * not present. A rule processor may use the member variable as a hint to
156 * indicate what variable is expected to contain the results.
157 *
158 * @param aBuilder the template builder
159 * @param aQuery <query> node to compile
160 * @param aRefVariable the reference variable
161 * @param aMemberVariable the member variable
162 *
163 * @returns a compiled query object
164 */
165 nsISupports compileQuery(in nsIXULTemplateBuilder aBuilder,
166 in nsIDOMNode aQuery,
167 in nsIAtom aRefVariable,
168 in nsIAtom aMemberVariable);
170 /**
171 * Generate the results of a query and return them in an enumerator. The
172 * enumerator must contain nsIXULTemplateResult objects. If there are no
173 * results, an empty enumerator must be returned.
174 *
175 * The datasource will be the same as the one passed to the earlier
176 * initializeForBuilding method. The context reference (aRef) is a reference
177 * point used when calculating results.
178 *
179 * The value of aQuery must be the result of a previous call to compileQuery
180 * from this query processor. This method may be called multiple times,
181 * typically with different values for aRef.
182 *
183 * @param aDatasource datasource for the data
184 * @param aRef context reference value used as a starting point
185 * @param aQuery the compiled query returned from query compilation
186 *
187 * @returns an enumerator of nsIXULTemplateResult objects as the results
188 *
189 * @throws NS_ERROR_INVALID_ARG if aQuery is invalid
190 */
191 nsISimpleEnumerator generateResults(in nsISupports aDatasource,
192 in nsIXULTemplateResult aRef,
193 in nsISupports aQuery);
195 /**
196 * Add a variable binding for a particular rule. A binding allows an
197 * additional variable to be set for a result, outside of those defined
198 * within the query. These bindings are always optional, in that they will
199 * never affect the results generated.
200 *
201 * This function will never be called after generateResults. Any bindings
202 * that were added should be applied to each result when the result's
203 * ruleMatched method is called, since the bindings are different for each
204 * rule.
205 *
206 * The reference aRef may be used to determine the reference when
207 * calculating the value for the binding, for example when a value should
208 * depend on the value of another variable.
209 *
210 * The syntax of the expression aExpr is defined by the query processor. If
211 * the syntax is invalid, the binding should be ignored. Only fatal errors
212 * should be thrown, or NS_ERROR_UNEXPECTED if generateResults has already
213 * been called.
214 *
215 * As an example, if the reference aRef is the variable '?count' which
216 * holds the value 5, and the expression aExpr is the string '+2', the value
217 * of the variable aVar would be 7, assuming the query processor considers
218 * the syntax '+2' to mean add two to the reference.
219 *
220 * @param aRuleNode rule to add the binding to
221 * @param aVar variable that will be bound
222 * @param aRef variable that holds reference value
223 * @param aExpr expression used to compute the value to assign
224 */
225 void addBinding(in nsIDOMNode aRuleNode,
226 in nsIAtom aVar,
227 in nsIAtom aRef,
228 in AString aExpr);
230 /**
231 * Translate a ref attribute string into a result. This is used as the
232 * reference point by the template builder when generating the first level
233 * of content. For recursive generation, the result from the parent
234 * generation phase will be used directly as the reference so a translation
235 * is not needed. This allows all levels to be generated using objects that
236 * all implement the nsIXULTemplateResult interface.
237 *
238 * This method may be called before initializeForBuilding, so the
239 * implementation may use the supplied datasource if it is needed to
240 * translate the reference.
241 *
242 * @param aDatasource datasource for the data
243 * @param aRefString the ref attribute string
244 *
245 * @return the translated ref
246 */
247 nsIXULTemplateResult translateRef(in nsISupports aDatasource,
248 in AString aRefString);
250 /**
251 * Compare two results to determine their order, used when sorting results.
252 * This method should return -1 when the left result is less than the right,
253 * 0 if both are equivalent, and 1 if the left is greater than the right.
254 * The comparison should only consider the values for the specified
255 * variable.
256 *
257 * If the comparison variable is null, the results may be
258 * sorted in a natural order, for instance, based on the order the data in
259 * stored in the datasource.
260 *
261 * The sort hints are the flags in nsIXULSortService.
262 *
263 * This method must only be called with results that were created by this
264 * query processor.
265 *
266 * @param aLeft the left result to compare
267 * @param aRight the right result to compare
268 * @param aVar variable to compare
269 *
270 * @param returns -1 if less, 0 if equal, or 1 if greater
271 */
272 int32_t compareResults(in nsIXULTemplateResult aLeft,
273 in nsIXULTemplateResult aRight,
274 in nsIAtom aVar,
275 in unsigned long aSortHints);
276 };