summaryrefslogtreecommitdiff
path: root/dom/base/nsIContentPolicyBase.idl
blob: 184257d11d9c2677c9bfa656186a1199c9706596 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"

interface nsIURI;
interface nsIDOMNode;
interface nsIPrincipal;

/**
 * The type of nsIContentPolicy::TYPE_*
 */
typedef unsigned long nsContentPolicyType;

/**
 * Interface for content policy mechanism.  Implementations of this
 * interface can be used to control loading of various types of out-of-line
 * content, or processing of certain types of in-line content.
 *
 * WARNING: do not block the caller from shouldLoad or shouldProcess (e.g.,
 * by launching a dialog to prompt the user for something).
 */

[scriptable,uuid(d6ab1d11-8e24-4db4-8582-c40a78281737)]
interface nsIContentPolicyBase : nsISupports
{
  /**
   * Indicates a unset or bogus policy type.
   */
  const nsContentPolicyType TYPE_INVALID = 0;

  /**
   * Gecko/Firefox developers: Avoid using TYPE_OTHER. Especially for
   * requests that are coming from webpages. Or requests in general which
   * you expect that security checks will be done on.
   * Always use a more specific type if one is available. And do not hesitate
   * to add more types as appropriate.
   * But if you are fairly sure that no one would care about your more specific
   * type, then it's ok to use TYPE_OTHER.
   *
   * Extension developers: Whenever it is reasonable, use one of the existing
   * content types. If none of the existing content types are right for
   * something you are doing, file a bug in the Core/DOM component that
   * includes a patch that adds your new content type to the end of the list of
   * TYPE_* constants here. But, don't start using your new content type until
   * your patch has been accepted, because it will be uncertain what exact
   * value and name your new content type will have; in that interim period,
   * use TYPE_OTHER. In your patch, document your new content type in the style
   * of the existing ones. In the bug you file, provide a more detailed
   * description of the new type of content you want Gecko to support, so that
   * the existing implementations of nsIContentPolicy can be properly modified
   * to deal with that new type of content.
   *
   * Implementations of nsIContentPolicy should treat this the same way they
   * treat unknown types, because existing users of TYPE_OTHER may be converted
   * to use new content types.
   *
   * Note that the TYPE_INTERNAL_* constants are never passed to content
   * policy implementations.  They are mapped to other TYPE_* constants, and
   * are only intended for internal usage inside Gecko.
   */
  const nsContentPolicyType TYPE_OTHER = 1;

  /**
   * Indicates an executable script (such as JavaScript).
   */
  const nsContentPolicyType TYPE_SCRIPT = 2;

  /**
   * Indicates an image (e.g., IMG elements).
   */
  const nsContentPolicyType TYPE_IMAGE = 3;

  /**
   * Indicates a stylesheet (e.g., STYLE elements).
   */
  const nsContentPolicyType TYPE_STYLESHEET = 4;

  /**
   * Indicates a generic object (plugin-handled content typically falls under
   * this category).
   */
  const nsContentPolicyType TYPE_OBJECT = 5;

  /**
   * Indicates a document at the top-level (i.e., in a browser).
   */
  const nsContentPolicyType TYPE_DOCUMENT = 6;

  /**
   * Indicates a document contained within another document (e.g., IFRAMEs,
   * FRAMES, and OBJECTs).
   */
  const nsContentPolicyType TYPE_SUBDOCUMENT = 7;

  /**
   * Indicates a timed refresh.
   *
   * shouldLoad will never get this, because it does not represent content
   * to be loaded (the actual load triggered by the refresh will go through
   * shouldLoad as expected).
   *
   * shouldProcess will get this for, e.g., META Refresh elements and HTTP
   * Refresh headers.
   */
  const nsContentPolicyType TYPE_REFRESH = 8;

  /**
   * Indicates an XBL binding request, triggered either by -moz-binding CSS
   * property.
   */
  const nsContentPolicyType TYPE_XBL = 9;

  /**
   * Indicates a ping triggered by a click on <A PING="..."> element.
   */
  const nsContentPolicyType TYPE_PING = 10;

  /**
   * Indicates an XMLHttpRequest. Also used for document.load and for EventSource.
   */
  const nsContentPolicyType TYPE_XMLHTTPREQUEST = 11;
  const nsContentPolicyType TYPE_DATAREQUEST    = 11; // alias

  /**
   * Indicates a request by a plugin.
   */
  const nsContentPolicyType TYPE_OBJECT_SUBREQUEST = 12;

  /**
   * Indicates a DTD loaded by an XML document.
   */
  const nsContentPolicyType TYPE_DTD = 13;

  /**
   * Indicates a font loaded via @font-face rule.
   */
  const nsContentPolicyType TYPE_FONT = 14;

  /**
   * Indicates a video or audio load.
   */
  const nsContentPolicyType TYPE_MEDIA = 15;

  /**
   * Indicates a WebSocket load.
   */
  const nsContentPolicyType TYPE_WEBSOCKET = 16;

  /**
   * Indicates a Content Security Policy report.
   */
  const nsContentPolicyType TYPE_CSP_REPORT = 17;

  /**
   * Indicates a style sheet transformation.
   */
  const nsContentPolicyType TYPE_XSLT = 18;

  /**
   * Indicates a beacon post.
   */
  const nsContentPolicyType TYPE_BEACON = 19;

  /**
   * Indicates a load initiated by the fetch() function from the Fetch
   * specification.
   */
  const nsContentPolicyType TYPE_FETCH = 20;

  /**
   * Indicates a <img srcset> or <picture> request.
   */
  const nsContentPolicyType TYPE_IMAGESET = 21;

  /**
   * Indicates a web manifest.
   */
  const nsContentPolicyType TYPE_WEB_MANIFEST = 22;

  /**
   * Indicates an internal constant for scripts loaded through script
   * elements.
   *
   * This will be mapped to TYPE_SCRIPT before being passed to content policy
   * implementations.
   */
  const nsContentPolicyType TYPE_INTERNAL_SCRIPT = 23;

  /**
   * Indicates an internal constant for scripts loaded through a dedicated
   * worker.
   *
   * This will be mapped to TYPE_SCRIPT before being passed to content policy
   * implementations.
   */
  const nsContentPolicyType TYPE_INTERNAL_WORKER = 24;

  /**
   * Indicates an internal constant for scripts loaded through a shared
   * worker.
   *
   * This will be mapped to TYPE_SCRIPT before being passed to content policy
   * implementations.
   */
  const nsContentPolicyType TYPE_INTERNAL_SHARED_WORKER = 25;

  /**
   * Indicates an internal constant for content loaded from embed elements.
   *
   * This will be mapped to TYPE_OBJECT.
   */
  const nsContentPolicyType TYPE_INTERNAL_EMBED = 26;

  /**
   * Indicates an internal constant for content loaded from object elements.
   *
   * This will be mapped to TYPE_OBJECT.
   */
  const nsContentPolicyType TYPE_INTERNAL_OBJECT = 27;

  /**
   * Indicates an internal constant for content loaded from frame elements.
   *
   * This will be mapped to TYPE_SUBDOCUMENT.
   */
  const nsContentPolicyType TYPE_INTERNAL_FRAME = 28;

  /**
   * Indicates an internal constant for content loaded from iframe elements.
   *
   * This will be mapped to TYPE_SUBDOCUMENT.
   */
  const nsContentPolicyType TYPE_INTERNAL_IFRAME = 29;

  /**
   * Indicates an internal constant for content loaded from audio elements.
   *
   * This will be mapped to TYPE_MEDIA.
   */
  const nsContentPolicyType TYPE_INTERNAL_AUDIO = 30;

  /**
   * Indicates an internal constant for content loaded from video elements.
   *
   * This will be mapped to TYPE_MEDIA.
   */
  const nsContentPolicyType TYPE_INTERNAL_VIDEO = 31;

  /**
   * Indicates an internal constant for content loaded from track elements.
   *
   * This will be mapped to TYPE_MEDIA.
   */
  const nsContentPolicyType TYPE_INTERNAL_TRACK = 32;

  /**
   * Indicates an internal constant for an XMLHttpRequest.
   *
   * This will be mapped to TYPE_XMLHTTPREQUEST.
   */
  const nsContentPolicyType TYPE_INTERNAL_XMLHTTPREQUEST = 33;

  /**
   * Indicates an internal constant for EventSource.
   *
   * This will be mapped to TYPE_DATAREQUEST.
   */
  const nsContentPolicyType TYPE_INTERNAL_EVENTSOURCE = 34;

  /**
   * Indicates an internal constant for scripts loaded through a service
   * worker.
   *
   * This will be mapped to TYPE_SCRIPT before being passed to content policy
   * implementations.
   */
  const nsContentPolicyType TYPE_INTERNAL_SERVICE_WORKER = 35;

  /**
   * Indicates an internal constant for *preloaded* scripts
   * loaded through script elements.
   *
   * This will be mapped to TYPE_SCRIPT before being passed
   * to content policy implementations.
   */
  const nsContentPolicyType TYPE_INTERNAL_SCRIPT_PRELOAD = 36;

  /**
   * Indicates an internal constant for normal images.
   *
   * This will be mapped to TYPE_IMAGE before being passed
   * to content policy implementations.
   */
  const nsContentPolicyType TYPE_INTERNAL_IMAGE = 37;

  /**
   * Indicates an internal constant for *preloaded* images.
   *
   * This will be mapped to TYPE_IMAGE before being passed
   * to content policy implementations.
   */
  const nsContentPolicyType TYPE_INTERNAL_IMAGE_PRELOAD = 38;

  /**
   * Indicates an internal constant for normal stylesheets.
   *
   * This will be mapped to TYPE_STYLESHEET before being passed
   * to content policy implementations.
   */
  const nsContentPolicyType TYPE_INTERNAL_STYLESHEET = 39;

  /**
   * Indicates an internal constant for *preloaded* stylesheets.
   *
   * This will be mapped to TYPE_STYLESHEET before being passed
   * to content policy implementations.
   */
  const nsContentPolicyType TYPE_INTERNAL_STYLESHEET_PRELOAD = 40;

  /**
   * Indicates an internal constant for favicon.
   *
   * This will be mapped to TYPE_IMAGE before being passed
   * to content policy implementations.
   */
  const nsContentPolicyType TYPE_INTERNAL_IMAGE_FAVICON = 41;

  /**
   * Indicates an save-as link download from the front-end code.
   */
  const nsContentPolicyType TYPE_SAVEAS_DOWNLOAD = 42;

  /* When adding new content types, please update nsContentBlocker,
   * NS_CP_ContentTypeName, nsCSPContext, CSP_ContentTypeToDirective,
   * DoContentSecurityChecks, all nsIContentPolicy implementations, the
   * static_assert in dom/cache/DBSchema.cpp, nsPermissionManager.cpp,
   * and other things that are not listed here that are related
   * to nsIContentPolicy. */

  //////////////////////////////////////////////////////////////////////

  /**
   * Returned from shouldLoad or shouldProcess if the load or process request
   * is rejected based on details of the request.
   */
  const short REJECT_REQUEST = -1;

  /**
   * Returned from shouldLoad or shouldProcess if the load/process is rejected
   * based solely on its type (of the above flags).
   *
   * NOTE that it is not meant to stop future requests for this type--only the
   * current request.
   */
  const short REJECT_TYPE = -2;

  /**
   * Returned from shouldLoad or shouldProcess if the load/process is rejected
   * based on the server it is hosted on or requested from (aContentLocation or
   * aRequestOrigin), e.g., if you block an IMAGE because it is served from
   * goatse.cx (even if you don't necessarily block other types from that
   * server/domain).
   *
   * NOTE that it is not meant to stop future requests for this server--only the
   * current request.
   */
  const short REJECT_SERVER = -3;

  /**
   * Returned from shouldLoad or shouldProcess if the load/process is rejected
   * based on some other criteria. Mozilla callers will handle this like
   * REJECT_REQUEST; third-party implementors may, for example, use this to
   * direct their own callers to consult the extra parameter for additional
   * details.
   */
  const short REJECT_OTHER = -4;

  /**
   * Returned from shouldLoad or shouldProcess if the load or process request
   * is not rejected.
   */
  const short ACCEPT = 1;
};