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: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ft=cpp tw=78 sw=2 et ts=8 : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsISupports.idl"
9 interface nsIURI;
10 interface nsIDOMNode;
11 interface nsIPrincipal;
13 /**
14 * The type of nsIContentPolicy::TYPE_*
15 */
16 typedef unsigned long nsContentPolicyType;
18 /**
19 * Interface for content policy mechanism. Implementations of this
20 * interface can be used to control loading of various types of out-of-line
21 * content, or processing of certain types of in-line content.
22 *
23 * WARNING: do not block the caller from shouldLoad or shouldProcess (e.g.,
24 * by launching a dialog to prompt the user for something).
25 */
27 [scriptable,uuid(b6a71698-c117-441d-86b9-480cf06e3952)]
28 interface nsIContentPolicy : nsISupports
29 {
30 /**
31 * Gecko/Firefox developers: Do not use TYPE_OTHER under any circumstances.
32 *
33 * Extension developers: Whenever it is reasonable, use one of the existing
34 * content types. If none of the existing content types are right for
35 * something you are doing, file a bug in the Core/DOM component that
36 * includes a patch that adds your new content type to the end of the list of
37 * TYPE_* constants here. But, don't start using your new content type until
38 * your patch has been accepted, because it will be uncertain what exact
39 * value and name your new content type will have; in that interim period,
40 * use TYPE_OTHER. In your patch, document your new content type in the style
41 * of the existing ones. In the bug you file, provide a more detailed
42 * description of the new type of content you want Gecko to support, so that
43 * the existing implementations of nsIContentPolicy can be properly modified
44 * to deal with that new type of content.
45 *
46 * Implementations of nsIContentPolicy should treat this the same way they
47 * treat unknown types, because existing users of TYPE_OTHER may be converted
48 * to use new content types.
49 */
50 const nsContentPolicyType TYPE_OTHER = 1;
52 /**
53 * Indicates an executable script (such as JavaScript).
54 */
55 const nsContentPolicyType TYPE_SCRIPT = 2;
57 /**
58 * Indicates an image (e.g., IMG elements).
59 */
60 const nsContentPolicyType TYPE_IMAGE = 3;
62 /**
63 * Indicates a stylesheet (e.g., STYLE elements).
64 */
65 const nsContentPolicyType TYPE_STYLESHEET = 4;
67 /**
68 * Indicates a generic object (plugin-handled content typically falls under
69 * this category).
70 */
71 const nsContentPolicyType TYPE_OBJECT = 5;
73 /**
74 * Indicates a document at the top-level (i.e., in a browser).
75 */
76 const nsContentPolicyType TYPE_DOCUMENT = 6;
78 /**
79 * Indicates a document contained within another document (e.g., IFRAMEs,
80 * FRAMES, and OBJECTs).
81 */
82 const nsContentPolicyType TYPE_SUBDOCUMENT = 7;
84 /**
85 * Indicates a timed refresh.
86 *
87 * shouldLoad will never get this, because it does not represent content
88 * to be loaded (the actual load triggered by the refresh will go through
89 * shouldLoad as expected).
90 *
91 * shouldProcess will get this for, e.g., META Refresh elements and HTTP
92 * Refresh headers.
93 */
94 const nsContentPolicyType TYPE_REFRESH = 8;
96 /**
97 * Indicates an XBL binding request, triggered either by -moz-binding CSS
98 * property.
99 */
100 const nsContentPolicyType TYPE_XBL = 9;
102 /**
103 * Indicates a ping triggered by a click on <A PING="..."> element.
104 */
105 const nsContentPolicyType TYPE_PING = 10;
107 /**
108 * Indicates an XMLHttpRequest. Also used for document.load and for EventSource.
109 */
110 const nsContentPolicyType TYPE_XMLHTTPREQUEST = 11;
111 const nsContentPolicyType TYPE_DATAREQUEST = 11; // alias
113 /**
114 * Indicates a request by a plugin.
115 */
116 const nsContentPolicyType TYPE_OBJECT_SUBREQUEST = 12;
118 /**
119 * Indicates a DTD loaded by an XML document.
120 */
121 const nsContentPolicyType TYPE_DTD = 13;
123 /**
124 * Indicates a font loaded via @font-face rule.
125 */
126 const nsContentPolicyType TYPE_FONT = 14;
128 /**
129 * Indicates a video or audio load.
130 */
131 const nsContentPolicyType TYPE_MEDIA = 15;
133 /**
134 * Indicates a WebSocket load.
135 */
136 const nsContentPolicyType TYPE_WEBSOCKET = 16;
138 /**
139 * Indicates a Content Security Policy report.
140 */
141 const nsContentPolicyType TYPE_CSP_REPORT = 17;
143 /**
144 * Indicates a style sheet transformation.
145 */
146 const nsContentPolicyType TYPE_XSLT = 18;
148 /**
149 * Indicates a beacon post.
150 */
151 const nsContentPolicyType TYPE_BEACON = 19;
153 /* When adding new content types, please update nsContentBlocker,
154 * NS_CP_ContentTypeName, contentSecurityPolicy.js, all nsIContentPolicy
155 * implementations, and other things that are not listed here that are
156 * related to nsIContentPolicy. */
158 //////////////////////////////////////////////////////////////////////
160 /**
161 * Returned from shouldLoad or shouldProcess if the load or process request
162 * is rejected based on details of the request.
163 */
164 const short REJECT_REQUEST = -1;
166 /**
167 * Returned from shouldLoad or shouldProcess if the load/process is rejected
168 * based solely on its type (of the above flags).
169 *
170 * NOTE that it is not meant to stop future requests for this type--only the
171 * current request.
172 */
173 const short REJECT_TYPE = -2;
175 /**
176 * Returned from shouldLoad or shouldProcess if the load/process is rejected
177 * based on the server it is hosted on or requested from (aContentLocation or
178 * aRequestOrigin), e.g., if you block an IMAGE because it is served from
179 * goatse.cx (even if you don't necessarily block other types from that
180 * server/domain).
181 *
182 * NOTE that it is not meant to stop future requests for this server--only the
183 * current request.
184 */
185 const short REJECT_SERVER = -3;
187 /**
188 * Returned from shouldLoad or shouldProcess if the load/process is rejected
189 * based on some other criteria. Mozilla callers will handle this like
190 * REJECT_REQUEST; third-party implementors may, for example, use this to
191 * direct their own callers to consult the extra parameter for additional
192 * details.
193 */
194 const short REJECT_OTHER = -4;
196 /**
197 * Returned from shouldLoad or shouldProcess if the load or process request
198 * is not rejected.
199 */
200 const short ACCEPT = 1;
202 //////////////////////////////////////////////////////////////////////
204 /**
205 * Should the resource at this location be loaded?
206 * ShouldLoad will be called before loading the resource at aContentLocation
207 * to determine whether to start the load at all.
208 *
209 * @param aContentType the type of content being tested. This will be one
210 * one of the TYPE_* constants.
211 *
212 * @param aContentLocation the location of the content being checked; must
213 * not be null
214 *
215 * @param aRequestOrigin OPTIONAL. the location of the resource that
216 * initiated this load request; can be null if
217 * inapplicable
218 *
219 * @param aContext OPTIONAL. the nsIDOMNode or nsIDOMWindow that
220 * initiated the request, or something that can QI
221 * to one of those; can be null if inapplicable.
222 * Note that for navigation events (new windows and
223 * link clicks), this is the NEW window.
224 *
225 * @param aMimeTypeGuess OPTIONAL. a guess for the requested content's
226 * MIME type, based on information available to
227 * the request initiator (e.g., an OBJECT's type
228 * attribute); does not reliably reflect the
229 * actual MIME type of the requested content
230 *
231 * @param aExtra an OPTIONAL argument, pass-through for non-Gecko
232 * callers to pass extra data to callees.
233 *
234 * @param aRequestPrincipal an OPTIONAL argument, defines the principal that
235 * caused the load. This is optional only for
236 * non-gecko code: all gecko code should set this
237 * argument. For navigation events, this is
238 * the principal of the page that caused this load.
239 *
240 * @return ACCEPT or REJECT_*
241 *
242 * @note shouldLoad can be called while the DOM and layout of the document
243 * involved is in an inconsistent state. This means that implementors of
244 * this method MUST NOT do any of the following:
245 * 1) Modify the DOM in any way (e.g. setting attributes is a no-no).
246 * 2) Query any DOM properties that depend on layout (e.g. offset*
247 * properties).
248 * 3) Query any DOM properties that depend on style (e.g. computed style).
249 * 4) Query any DOM properties that depend on the current state of the DOM
250 * outside the "context" node (e.g. lengths of node lists).
251 * 5) [JavaScript implementations only] Access properties of any sort on any
252 * object without using XPCNativeWrapper (either explicitly or
253 * implicitly). Due to various DOM0 things, this leads to item 4.
254 * If you do any of these things in your shouldLoad implementation, expect
255 * unpredictable behavior, possibly including crashes, content not showing
256 * up, content showing up doubled, etc. If you need to do any of the things
257 * above, do them off timeout or event.
258 */
259 short shouldLoad(in nsContentPolicyType aContentType,
260 in nsIURI aContentLocation,
261 in nsIURI aRequestOrigin,
262 in nsISupports aContext,
263 in ACString aMimeTypeGuess,
264 in nsISupports aExtra,
265 [optional] in nsIPrincipal aRequestPrincipal);
267 /**
268 * Should the resource be processed?
269 * ShouldProcess will be called once all the information passed to it has
270 * been determined about the resource, typically after part of the resource
271 * has been loaded.
272 *
273 * @param aContentType the type of content being tested. This will be one
274 * one of the TYPE_* constants.
275 *
276 * @param aContentLocation OPTIONAL; the location of the resource being
277 * requested: MAY be, e.g., a post-redirection URI
278 * for the resource.
279 *
280 * @param aRequestOrigin OPTIONAL. the location of the resource that
281 * initiated this load request; can be null if
282 * inapplicable
283 *
284 * @param aContext OPTIONAL. the nsIDOMNode or nsIDOMWindow that
285 * initiated the request, or something that can QI
286 * to one of those; can be null if inapplicable.
287 *
288 * @param aMimeType the MIME type of the requested resource (e.g.,
289 * image/png), as reported by the networking library,
290 * if available (may be empty if inappropriate for
291 * the type, e.g., TYPE_REFRESH).
292 *
293 * @param aExtra an OPTIONAL argument, pass-through for non-Gecko
294 * callers to pass extra data to callees.
295 *
296 * @return ACCEPT or REJECT_*
297 *
298 * @note shouldProcess can be called while the DOM and layout of the document
299 * involved is in an inconsistent state. See the note on shouldLoad to see
300 * what this means for implementors of this method.
301 */
302 short shouldProcess(in nsContentPolicyType aContentType,
303 in nsIURI aContentLocation,
304 in nsIURI aRequestOrigin,
305 in nsISupports aContext,
306 in ACString aMimeType,
307 in nsISupports aExtra,
308 [optional] in nsIPrincipal aRequestPrincipal);
310 };