Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/CSPDictionariesBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM CSPDictionaries.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "CSPDictionariesBinding.h"
5
#include "mozilla/OwningNonNull.h"
6
#include "mozilla/dom/BindingUtils.h"
7
#include "mozilla/dom/NonRefcountedDOMObject.h"
8
#include "mozilla/dom/PrimitiveConversions.h"
9
#include "mozilla/dom/ScriptSettings.h"
10
#include "mozilla/dom/SimpleGlobalObject.h"
11
12
namespace mozilla {
13
namespace dom {
14
15
namespace binding_detail {}; // Just to make sure it's known as a namespace
16
using namespace mozilla::dom::binding_detail;
17
18
19
20
CSP::CSP()
21
0
{
22
0
  // Safe to pass a null context if we pass a null value
23
0
  Init(nullptr, JS::NullHandleValue);
24
0
}
25
26
27
28
bool
29
CSP::InitIds(JSContext* cx, CSPAtoms* atomsCache)
30
0
{
31
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
32
0
33
0
  // Initialize these in reverse order so that any failure leaves the first one
34
0
  // uninitialized.
35
0
  if (!atomsCache->worker_src_id.init(cx, "worker-src") ||
36
0
      !atomsCache->upgrade_insecure_requests_id.init(cx, "upgrade-insecure-requests") ||
37
0
      !atomsCache->style_src_id.init(cx, "style-src") ||
38
0
      !atomsCache->script_src_id.init(cx, "script-src") ||
39
0
      !atomsCache->sandbox_id.init(cx, "sandbox") ||
40
0
      !atomsCache->require_sri_for_id.init(cx, "require-sri-for") ||
41
0
      !atomsCache->report_uri_id.init(cx, "report-uri") ||
42
0
      !atomsCache->report_only_id.init(cx, "report-only") ||
43
0
      !atomsCache->referrer_id.init(cx, "referrer") ||
44
0
      !atomsCache->object_src_id.init(cx, "object-src") ||
45
0
      !atomsCache->media_src_id.init(cx, "media-src") ||
46
0
      !atomsCache->manifest_src_id.init(cx, "manifest-src") ||
47
0
      !atomsCache->img_src_id.init(cx, "img-src") ||
48
0
      !atomsCache->frame_src_id.init(cx, "frame-src") ||
49
0
      !atomsCache->frame_ancestors_id.init(cx, "frame-ancestors") ||
50
0
      !atomsCache->form_action_id.init(cx, "form-action") ||
51
0
      !atomsCache->font_src_id.init(cx, "font-src") ||
52
0
      !atomsCache->default_src_id.init(cx, "default-src") ||
53
0
      !atomsCache->connect_src_id.init(cx, "connect-src") ||
54
0
      !atomsCache->child_src_id.init(cx, "child-src") ||
55
0
      !atomsCache->block_all_mixed_content_id.init(cx, "block-all-mixed-content") ||
56
0
      !atomsCache->base_uri_id.init(cx, "base-uri")) {
57
0
    return false;
58
0
  }
59
0
  return true;
60
0
}
61
62
bool
63
CSP::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
64
0
{
65
0
  // Passing a null JSContext is OK only if we're initing from null,
66
0
  // Since in that case we will not have to do any property gets
67
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
68
0
  // checkers by static analysis tools
69
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
70
0
  CSPAtoms* atomsCache = nullptr;
71
0
  if (cx) {
72
0
    atomsCache = GetAtomCache<CSPAtoms>(cx);
73
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
74
0
      return false;
75
0
    }
76
0
  }
77
0
78
0
  if (!IsConvertibleToDictionary(val)) {
79
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
80
0
  }
81
0
82
0
  bool isNull = val.isNullOrUndefined();
83
0
  // We only need these if !isNull, in which case we have |cx|.
84
0
  Maybe<JS::Rooted<JSObject *> > object;
85
0
  Maybe<JS::Rooted<JS::Value> > temp;
86
0
  if (!isNull) {
87
0
    MOZ_ASSERT(cx);
88
0
    object.emplace(cx, &val.toObject());
89
0
    temp.emplace(cx);
90
0
  }
91
0
  if (!isNull) {
92
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->base_uri_id, temp.ptr())) {
93
0
      return false;
94
0
    }
95
0
  }
96
0
  if (!isNull && !temp->isUndefined()) {
97
0
    mBase_uri.Construct();
98
0
    if (temp.ref().isObject()) {
99
0
      JS::ForOfIterator iter(cx);
100
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
101
0
        return false;
102
0
      }
103
0
      if (!iter.valueIsIterable()) {
104
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'base-uri' member of CSP");
105
0
        return false;
106
0
      }
107
0
      Sequence<nsString> &arr = (mBase_uri.Value());
108
0
      JS::Rooted<JS::Value> temp(cx);
109
0
      while (true) {
110
0
        bool done;
111
0
        if (!iter.next(&temp, &done)) {
112
0
          return false;
113
0
        }
114
0
        if (done) {
115
0
          break;
116
0
        }
117
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
118
0
        if (!slotPtr) {
119
0
          JS_ReportOutOfMemory(cx);
120
0
          return false;
121
0
        }
122
0
        nsString& slot = *slotPtr;
123
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
124
0
          return false;
125
0
        }
126
0
      }
127
0
    } else {
128
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'base-uri' member of CSP");
129
0
      return false;
130
0
    }
131
0
    mIsAnyMemberPresent = true;
132
0
  }
133
0
134
0
  if (!isNull) {
135
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->block_all_mixed_content_id, temp.ptr())) {
136
0
      return false;
137
0
    }
138
0
  }
139
0
  if (!isNull && !temp->isUndefined()) {
140
0
    mBlock_all_mixed_content.Construct();
141
0
    if (temp.ref().isObject()) {
142
0
      JS::ForOfIterator iter(cx);
143
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
144
0
        return false;
145
0
      }
146
0
      if (!iter.valueIsIterable()) {
147
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'block-all-mixed-content' member of CSP");
148
0
        return false;
149
0
      }
150
0
      Sequence<nsString> &arr = (mBlock_all_mixed_content.Value());
151
0
      JS::Rooted<JS::Value> temp(cx);
152
0
      while (true) {
153
0
        bool done;
154
0
        if (!iter.next(&temp, &done)) {
155
0
          return false;
156
0
        }
157
0
        if (done) {
158
0
          break;
159
0
        }
160
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
161
0
        if (!slotPtr) {
162
0
          JS_ReportOutOfMemory(cx);
163
0
          return false;
164
0
        }
165
0
        nsString& slot = *slotPtr;
166
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
167
0
          return false;
168
0
        }
169
0
      }
170
0
    } else {
171
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'block-all-mixed-content' member of CSP");
172
0
      return false;
173
0
    }
174
0
    mIsAnyMemberPresent = true;
175
0
  }
176
0
177
0
  if (!isNull) {
178
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->child_src_id, temp.ptr())) {
179
0
      return false;
180
0
    }
181
0
  }
182
0
  if (!isNull && !temp->isUndefined()) {
183
0
    mChild_src.Construct();
184
0
    if (temp.ref().isObject()) {
185
0
      JS::ForOfIterator iter(cx);
186
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
187
0
        return false;
188
0
      }
189
0
      if (!iter.valueIsIterable()) {
190
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'child-src' member of CSP");
191
0
        return false;
192
0
      }
193
0
      Sequence<nsString> &arr = (mChild_src.Value());
194
0
      JS::Rooted<JS::Value> temp(cx);
195
0
      while (true) {
196
0
        bool done;
197
0
        if (!iter.next(&temp, &done)) {
198
0
          return false;
199
0
        }
200
0
        if (done) {
201
0
          break;
202
0
        }
203
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
204
0
        if (!slotPtr) {
205
0
          JS_ReportOutOfMemory(cx);
206
0
          return false;
207
0
        }
208
0
        nsString& slot = *slotPtr;
209
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
210
0
          return false;
211
0
        }
212
0
      }
213
0
    } else {
214
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'child-src' member of CSP");
215
0
      return false;
216
0
    }
217
0
    mIsAnyMemberPresent = true;
218
0
  }
219
0
220
0
  if (!isNull) {
221
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->connect_src_id, temp.ptr())) {
222
0
      return false;
223
0
    }
224
0
  }
225
0
  if (!isNull && !temp->isUndefined()) {
226
0
    mConnect_src.Construct();
227
0
    if (temp.ref().isObject()) {
228
0
      JS::ForOfIterator iter(cx);
229
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
230
0
        return false;
231
0
      }
232
0
      if (!iter.valueIsIterable()) {
233
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'connect-src' member of CSP");
234
0
        return false;
235
0
      }
236
0
      Sequence<nsString> &arr = (mConnect_src.Value());
237
0
      JS::Rooted<JS::Value> temp(cx);
238
0
      while (true) {
239
0
        bool done;
240
0
        if (!iter.next(&temp, &done)) {
241
0
          return false;
242
0
        }
243
0
        if (done) {
244
0
          break;
245
0
        }
246
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
247
0
        if (!slotPtr) {
248
0
          JS_ReportOutOfMemory(cx);
249
0
          return false;
250
0
        }
251
0
        nsString& slot = *slotPtr;
252
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
253
0
          return false;
254
0
        }
255
0
      }
256
0
    } else {
257
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'connect-src' member of CSP");
258
0
      return false;
259
0
    }
260
0
    mIsAnyMemberPresent = true;
261
0
  }
262
0
263
0
  if (!isNull) {
264
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->default_src_id, temp.ptr())) {
265
0
      return false;
266
0
    }
267
0
  }
268
0
  if (!isNull && !temp->isUndefined()) {
269
0
    mDefault_src.Construct();
270
0
    if (temp.ref().isObject()) {
271
0
      JS::ForOfIterator iter(cx);
272
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
273
0
        return false;
274
0
      }
275
0
      if (!iter.valueIsIterable()) {
276
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'default-src' member of CSP");
277
0
        return false;
278
0
      }
279
0
      Sequence<nsString> &arr = (mDefault_src.Value());
280
0
      JS::Rooted<JS::Value> temp(cx);
281
0
      while (true) {
282
0
        bool done;
283
0
        if (!iter.next(&temp, &done)) {
284
0
          return false;
285
0
        }
286
0
        if (done) {
287
0
          break;
288
0
        }
289
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
290
0
        if (!slotPtr) {
291
0
          JS_ReportOutOfMemory(cx);
292
0
          return false;
293
0
        }
294
0
        nsString& slot = *slotPtr;
295
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
296
0
          return false;
297
0
        }
298
0
      }
299
0
    } else {
300
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'default-src' member of CSP");
301
0
      return false;
302
0
    }
303
0
    mIsAnyMemberPresent = true;
304
0
  }
305
0
306
0
  if (!isNull) {
307
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->font_src_id, temp.ptr())) {
308
0
      return false;
309
0
    }
310
0
  }
311
0
  if (!isNull && !temp->isUndefined()) {
312
0
    mFont_src.Construct();
313
0
    if (temp.ref().isObject()) {
314
0
      JS::ForOfIterator iter(cx);
315
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
316
0
        return false;
317
0
      }
318
0
      if (!iter.valueIsIterable()) {
319
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'font-src' member of CSP");
320
0
        return false;
321
0
      }
322
0
      Sequence<nsString> &arr = (mFont_src.Value());
323
0
      JS::Rooted<JS::Value> temp(cx);
324
0
      while (true) {
325
0
        bool done;
326
0
        if (!iter.next(&temp, &done)) {
327
0
          return false;
328
0
        }
329
0
        if (done) {
330
0
          break;
331
0
        }
332
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
333
0
        if (!slotPtr) {
334
0
          JS_ReportOutOfMemory(cx);
335
0
          return false;
336
0
        }
337
0
        nsString& slot = *slotPtr;
338
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
339
0
          return false;
340
0
        }
341
0
      }
342
0
    } else {
343
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'font-src' member of CSP");
344
0
      return false;
345
0
    }
346
0
    mIsAnyMemberPresent = true;
347
0
  }
348
0
349
0
  if (!isNull) {
350
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->form_action_id, temp.ptr())) {
351
0
      return false;
352
0
    }
353
0
  }
354
0
  if (!isNull && !temp->isUndefined()) {
355
0
    mForm_action.Construct();
356
0
    if (temp.ref().isObject()) {
357
0
      JS::ForOfIterator iter(cx);
358
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
359
0
        return false;
360
0
      }
361
0
      if (!iter.valueIsIterable()) {
362
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'form-action' member of CSP");
363
0
        return false;
364
0
      }
365
0
      Sequence<nsString> &arr = (mForm_action.Value());
366
0
      JS::Rooted<JS::Value> temp(cx);
367
0
      while (true) {
368
0
        bool done;
369
0
        if (!iter.next(&temp, &done)) {
370
0
          return false;
371
0
        }
372
0
        if (done) {
373
0
          break;
374
0
        }
375
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
376
0
        if (!slotPtr) {
377
0
          JS_ReportOutOfMemory(cx);
378
0
          return false;
379
0
        }
380
0
        nsString& slot = *slotPtr;
381
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
382
0
          return false;
383
0
        }
384
0
      }
385
0
    } else {
386
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'form-action' member of CSP");
387
0
      return false;
388
0
    }
389
0
    mIsAnyMemberPresent = true;
390
0
  }
391
0
392
0
  if (!isNull) {
393
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->frame_ancestors_id, temp.ptr())) {
394
0
      return false;
395
0
    }
396
0
  }
397
0
  if (!isNull && !temp->isUndefined()) {
398
0
    mFrame_ancestors.Construct();
399
0
    if (temp.ref().isObject()) {
400
0
      JS::ForOfIterator iter(cx);
401
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
402
0
        return false;
403
0
      }
404
0
      if (!iter.valueIsIterable()) {
405
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'frame-ancestors' member of CSP");
406
0
        return false;
407
0
      }
408
0
      Sequence<nsString> &arr = (mFrame_ancestors.Value());
409
0
      JS::Rooted<JS::Value> temp(cx);
410
0
      while (true) {
411
0
        bool done;
412
0
        if (!iter.next(&temp, &done)) {
413
0
          return false;
414
0
        }
415
0
        if (done) {
416
0
          break;
417
0
        }
418
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
419
0
        if (!slotPtr) {
420
0
          JS_ReportOutOfMemory(cx);
421
0
          return false;
422
0
        }
423
0
        nsString& slot = *slotPtr;
424
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
425
0
          return false;
426
0
        }
427
0
      }
428
0
    } else {
429
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'frame-ancestors' member of CSP");
430
0
      return false;
431
0
    }
432
0
    mIsAnyMemberPresent = true;
433
0
  }
434
0
435
0
  if (!isNull) {
436
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->frame_src_id, temp.ptr())) {
437
0
      return false;
438
0
    }
439
0
  }
440
0
  if (!isNull && !temp->isUndefined()) {
441
0
    mFrame_src.Construct();
442
0
    if (temp.ref().isObject()) {
443
0
      JS::ForOfIterator iter(cx);
444
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
445
0
        return false;
446
0
      }
447
0
      if (!iter.valueIsIterable()) {
448
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'frame-src' member of CSP");
449
0
        return false;
450
0
      }
451
0
      Sequence<nsString> &arr = (mFrame_src.Value());
452
0
      JS::Rooted<JS::Value> temp(cx);
453
0
      while (true) {
454
0
        bool done;
455
0
        if (!iter.next(&temp, &done)) {
456
0
          return false;
457
0
        }
458
0
        if (done) {
459
0
          break;
460
0
        }
461
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
462
0
        if (!slotPtr) {
463
0
          JS_ReportOutOfMemory(cx);
464
0
          return false;
465
0
        }
466
0
        nsString& slot = *slotPtr;
467
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
468
0
          return false;
469
0
        }
470
0
      }
471
0
    } else {
472
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'frame-src' member of CSP");
473
0
      return false;
474
0
    }
475
0
    mIsAnyMemberPresent = true;
476
0
  }
477
0
478
0
  if (!isNull) {
479
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->img_src_id, temp.ptr())) {
480
0
      return false;
481
0
    }
482
0
  }
483
0
  if (!isNull && !temp->isUndefined()) {
484
0
    mImg_src.Construct();
485
0
    if (temp.ref().isObject()) {
486
0
      JS::ForOfIterator iter(cx);
487
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
488
0
        return false;
489
0
      }
490
0
      if (!iter.valueIsIterable()) {
491
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'img-src' member of CSP");
492
0
        return false;
493
0
      }
494
0
      Sequence<nsString> &arr = (mImg_src.Value());
495
0
      JS::Rooted<JS::Value> temp(cx);
496
0
      while (true) {
497
0
        bool done;
498
0
        if (!iter.next(&temp, &done)) {
499
0
          return false;
500
0
        }
501
0
        if (done) {
502
0
          break;
503
0
        }
504
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
505
0
        if (!slotPtr) {
506
0
          JS_ReportOutOfMemory(cx);
507
0
          return false;
508
0
        }
509
0
        nsString& slot = *slotPtr;
510
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
511
0
          return false;
512
0
        }
513
0
      }
514
0
    } else {
515
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'img-src' member of CSP");
516
0
      return false;
517
0
    }
518
0
    mIsAnyMemberPresent = true;
519
0
  }
520
0
521
0
  if (!isNull) {
522
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->manifest_src_id, temp.ptr())) {
523
0
      return false;
524
0
    }
525
0
  }
526
0
  if (!isNull && !temp->isUndefined()) {
527
0
    mManifest_src.Construct();
528
0
    if (temp.ref().isObject()) {
529
0
      JS::ForOfIterator iter(cx);
530
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
531
0
        return false;
532
0
      }
533
0
      if (!iter.valueIsIterable()) {
534
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'manifest-src' member of CSP");
535
0
        return false;
536
0
      }
537
0
      Sequence<nsString> &arr = (mManifest_src.Value());
538
0
      JS::Rooted<JS::Value> temp(cx);
539
0
      while (true) {
540
0
        bool done;
541
0
        if (!iter.next(&temp, &done)) {
542
0
          return false;
543
0
        }
544
0
        if (done) {
545
0
          break;
546
0
        }
547
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
548
0
        if (!slotPtr) {
549
0
          JS_ReportOutOfMemory(cx);
550
0
          return false;
551
0
        }
552
0
        nsString& slot = *slotPtr;
553
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
554
0
          return false;
555
0
        }
556
0
      }
557
0
    } else {
558
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'manifest-src' member of CSP");
559
0
      return false;
560
0
    }
561
0
    mIsAnyMemberPresent = true;
562
0
  }
563
0
564
0
  if (!isNull) {
565
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->media_src_id, temp.ptr())) {
566
0
      return false;
567
0
    }
568
0
  }
569
0
  if (!isNull && !temp->isUndefined()) {
570
0
    mMedia_src.Construct();
571
0
    if (temp.ref().isObject()) {
572
0
      JS::ForOfIterator iter(cx);
573
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
574
0
        return false;
575
0
      }
576
0
      if (!iter.valueIsIterable()) {
577
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'media-src' member of CSP");
578
0
        return false;
579
0
      }
580
0
      Sequence<nsString> &arr = (mMedia_src.Value());
581
0
      JS::Rooted<JS::Value> temp(cx);
582
0
      while (true) {
583
0
        bool done;
584
0
        if (!iter.next(&temp, &done)) {
585
0
          return false;
586
0
        }
587
0
        if (done) {
588
0
          break;
589
0
        }
590
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
591
0
        if (!slotPtr) {
592
0
          JS_ReportOutOfMemory(cx);
593
0
          return false;
594
0
        }
595
0
        nsString& slot = *slotPtr;
596
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
597
0
          return false;
598
0
        }
599
0
      }
600
0
    } else {
601
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'media-src' member of CSP");
602
0
      return false;
603
0
    }
604
0
    mIsAnyMemberPresent = true;
605
0
  }
606
0
607
0
  if (!isNull) {
608
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->object_src_id, temp.ptr())) {
609
0
      return false;
610
0
    }
611
0
  }
612
0
  if (!isNull && !temp->isUndefined()) {
613
0
    mObject_src.Construct();
614
0
    if (temp.ref().isObject()) {
615
0
      JS::ForOfIterator iter(cx);
616
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
617
0
        return false;
618
0
      }
619
0
      if (!iter.valueIsIterable()) {
620
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'object-src' member of CSP");
621
0
        return false;
622
0
      }
623
0
      Sequence<nsString> &arr = (mObject_src.Value());
624
0
      JS::Rooted<JS::Value> temp(cx);
625
0
      while (true) {
626
0
        bool done;
627
0
        if (!iter.next(&temp, &done)) {
628
0
          return false;
629
0
        }
630
0
        if (done) {
631
0
          break;
632
0
        }
633
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
634
0
        if (!slotPtr) {
635
0
          JS_ReportOutOfMemory(cx);
636
0
          return false;
637
0
        }
638
0
        nsString& slot = *slotPtr;
639
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
640
0
          return false;
641
0
        }
642
0
      }
643
0
    } else {
644
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'object-src' member of CSP");
645
0
      return false;
646
0
    }
647
0
    mIsAnyMemberPresent = true;
648
0
  }
649
0
650
0
  if (!isNull) {
651
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->referrer_id, temp.ptr())) {
652
0
      return false;
653
0
    }
654
0
  }
655
0
  if (!isNull && !temp->isUndefined()) {
656
0
    mReferrer.Construct();
657
0
    if (temp.ref().isObject()) {
658
0
      JS::ForOfIterator iter(cx);
659
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
660
0
        return false;
661
0
      }
662
0
      if (!iter.valueIsIterable()) {
663
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'referrer' member of CSP");
664
0
        return false;
665
0
      }
666
0
      Sequence<nsString> &arr = (mReferrer.Value());
667
0
      JS::Rooted<JS::Value> temp(cx);
668
0
      while (true) {
669
0
        bool done;
670
0
        if (!iter.next(&temp, &done)) {
671
0
          return false;
672
0
        }
673
0
        if (done) {
674
0
          break;
675
0
        }
676
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
677
0
        if (!slotPtr) {
678
0
          JS_ReportOutOfMemory(cx);
679
0
          return false;
680
0
        }
681
0
        nsString& slot = *slotPtr;
682
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
683
0
          return false;
684
0
        }
685
0
      }
686
0
    } else {
687
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'referrer' member of CSP");
688
0
      return false;
689
0
    }
690
0
    mIsAnyMemberPresent = true;
691
0
  }
692
0
693
0
  if (!isNull) {
694
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->report_only_id, temp.ptr())) {
695
0
      return false;
696
0
    }
697
0
  }
698
0
  if (!isNull && !temp->isUndefined()) {
699
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mReport_only)) {
700
0
      return false;
701
0
    }
702
0
  } else {
703
0
    mReport_only = false;
704
0
  }
705
0
  mIsAnyMemberPresent = true;
706
0
707
0
  if (!isNull) {
708
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->report_uri_id, temp.ptr())) {
709
0
      return false;
710
0
    }
711
0
  }
712
0
  if (!isNull && !temp->isUndefined()) {
713
0
    mReport_uri.Construct();
714
0
    if (temp.ref().isObject()) {
715
0
      JS::ForOfIterator iter(cx);
716
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
717
0
        return false;
718
0
      }
719
0
      if (!iter.valueIsIterable()) {
720
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'report-uri' member of CSP");
721
0
        return false;
722
0
      }
723
0
      Sequence<nsString> &arr = (mReport_uri.Value());
724
0
      JS::Rooted<JS::Value> temp(cx);
725
0
      while (true) {
726
0
        bool done;
727
0
        if (!iter.next(&temp, &done)) {
728
0
          return false;
729
0
        }
730
0
        if (done) {
731
0
          break;
732
0
        }
733
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
734
0
        if (!slotPtr) {
735
0
          JS_ReportOutOfMemory(cx);
736
0
          return false;
737
0
        }
738
0
        nsString& slot = *slotPtr;
739
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
740
0
          return false;
741
0
        }
742
0
      }
743
0
    } else {
744
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'report-uri' member of CSP");
745
0
      return false;
746
0
    }
747
0
    mIsAnyMemberPresent = true;
748
0
  }
749
0
750
0
  if (!isNull) {
751
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->require_sri_for_id, temp.ptr())) {
752
0
      return false;
753
0
    }
754
0
  }
755
0
  if (!isNull && !temp->isUndefined()) {
756
0
    mRequire_sri_for.Construct();
757
0
    if (temp.ref().isObject()) {
758
0
      JS::ForOfIterator iter(cx);
759
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
760
0
        return false;
761
0
      }
762
0
      if (!iter.valueIsIterable()) {
763
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'require-sri-for' member of CSP");
764
0
        return false;
765
0
      }
766
0
      Sequence<nsString> &arr = (mRequire_sri_for.Value());
767
0
      JS::Rooted<JS::Value> temp(cx);
768
0
      while (true) {
769
0
        bool done;
770
0
        if (!iter.next(&temp, &done)) {
771
0
          return false;
772
0
        }
773
0
        if (done) {
774
0
          break;
775
0
        }
776
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
777
0
        if (!slotPtr) {
778
0
          JS_ReportOutOfMemory(cx);
779
0
          return false;
780
0
        }
781
0
        nsString& slot = *slotPtr;
782
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
783
0
          return false;
784
0
        }
785
0
      }
786
0
    } else {
787
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'require-sri-for' member of CSP");
788
0
      return false;
789
0
    }
790
0
    mIsAnyMemberPresent = true;
791
0
  }
792
0
793
0
  if (!isNull) {
794
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->sandbox_id, temp.ptr())) {
795
0
      return false;
796
0
    }
797
0
  }
798
0
  if (!isNull && !temp->isUndefined()) {
799
0
    mSandbox.Construct();
800
0
    if (temp.ref().isObject()) {
801
0
      JS::ForOfIterator iter(cx);
802
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
803
0
        return false;
804
0
      }
805
0
      if (!iter.valueIsIterable()) {
806
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'sandbox' member of CSP");
807
0
        return false;
808
0
      }
809
0
      Sequence<nsString> &arr = (mSandbox.Value());
810
0
      JS::Rooted<JS::Value> temp(cx);
811
0
      while (true) {
812
0
        bool done;
813
0
        if (!iter.next(&temp, &done)) {
814
0
          return false;
815
0
        }
816
0
        if (done) {
817
0
          break;
818
0
        }
819
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
820
0
        if (!slotPtr) {
821
0
          JS_ReportOutOfMemory(cx);
822
0
          return false;
823
0
        }
824
0
        nsString& slot = *slotPtr;
825
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
826
0
          return false;
827
0
        }
828
0
      }
829
0
    } else {
830
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'sandbox' member of CSP");
831
0
      return false;
832
0
    }
833
0
    mIsAnyMemberPresent = true;
834
0
  }
835
0
836
0
  if (!isNull) {
837
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->script_src_id, temp.ptr())) {
838
0
      return false;
839
0
    }
840
0
  }
841
0
  if (!isNull && !temp->isUndefined()) {
842
0
    mScript_src.Construct();
843
0
    if (temp.ref().isObject()) {
844
0
      JS::ForOfIterator iter(cx);
845
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
846
0
        return false;
847
0
      }
848
0
      if (!iter.valueIsIterable()) {
849
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'script-src' member of CSP");
850
0
        return false;
851
0
      }
852
0
      Sequence<nsString> &arr = (mScript_src.Value());
853
0
      JS::Rooted<JS::Value> temp(cx);
854
0
      while (true) {
855
0
        bool done;
856
0
        if (!iter.next(&temp, &done)) {
857
0
          return false;
858
0
        }
859
0
        if (done) {
860
0
          break;
861
0
        }
862
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
863
0
        if (!slotPtr) {
864
0
          JS_ReportOutOfMemory(cx);
865
0
          return false;
866
0
        }
867
0
        nsString& slot = *slotPtr;
868
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
869
0
          return false;
870
0
        }
871
0
      }
872
0
    } else {
873
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'script-src' member of CSP");
874
0
      return false;
875
0
    }
876
0
    mIsAnyMemberPresent = true;
877
0
  }
878
0
879
0
  if (!isNull) {
880
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->style_src_id, temp.ptr())) {
881
0
      return false;
882
0
    }
883
0
  }
884
0
  if (!isNull && !temp->isUndefined()) {
885
0
    mStyle_src.Construct();
886
0
    if (temp.ref().isObject()) {
887
0
      JS::ForOfIterator iter(cx);
888
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
889
0
        return false;
890
0
      }
891
0
      if (!iter.valueIsIterable()) {
892
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'style-src' member of CSP");
893
0
        return false;
894
0
      }
895
0
      Sequence<nsString> &arr = (mStyle_src.Value());
896
0
      JS::Rooted<JS::Value> temp(cx);
897
0
      while (true) {
898
0
        bool done;
899
0
        if (!iter.next(&temp, &done)) {
900
0
          return false;
901
0
        }
902
0
        if (done) {
903
0
          break;
904
0
        }
905
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
906
0
        if (!slotPtr) {
907
0
          JS_ReportOutOfMemory(cx);
908
0
          return false;
909
0
        }
910
0
        nsString& slot = *slotPtr;
911
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
912
0
          return false;
913
0
        }
914
0
      }
915
0
    } else {
916
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'style-src' member of CSP");
917
0
      return false;
918
0
    }
919
0
    mIsAnyMemberPresent = true;
920
0
  }
921
0
922
0
  if (!isNull) {
923
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->upgrade_insecure_requests_id, temp.ptr())) {
924
0
      return false;
925
0
    }
926
0
  }
927
0
  if (!isNull && !temp->isUndefined()) {
928
0
    mUpgrade_insecure_requests.Construct();
929
0
    if (temp.ref().isObject()) {
930
0
      JS::ForOfIterator iter(cx);
931
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
932
0
        return false;
933
0
      }
934
0
      if (!iter.valueIsIterable()) {
935
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'upgrade-insecure-requests' member of CSP");
936
0
        return false;
937
0
      }
938
0
      Sequence<nsString> &arr = (mUpgrade_insecure_requests.Value());
939
0
      JS::Rooted<JS::Value> temp(cx);
940
0
      while (true) {
941
0
        bool done;
942
0
        if (!iter.next(&temp, &done)) {
943
0
          return false;
944
0
        }
945
0
        if (done) {
946
0
          break;
947
0
        }
948
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
949
0
        if (!slotPtr) {
950
0
          JS_ReportOutOfMemory(cx);
951
0
          return false;
952
0
        }
953
0
        nsString& slot = *slotPtr;
954
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
955
0
          return false;
956
0
        }
957
0
      }
958
0
    } else {
959
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'upgrade-insecure-requests' member of CSP");
960
0
      return false;
961
0
    }
962
0
    mIsAnyMemberPresent = true;
963
0
  }
964
0
965
0
  if (!isNull) {
966
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->worker_src_id, temp.ptr())) {
967
0
      return false;
968
0
    }
969
0
  }
970
0
  if (!isNull && !temp->isUndefined()) {
971
0
    mWorker_src.Construct();
972
0
    if (temp.ref().isObject()) {
973
0
      JS::ForOfIterator iter(cx);
974
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
975
0
        return false;
976
0
      }
977
0
      if (!iter.valueIsIterable()) {
978
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'worker-src' member of CSP");
979
0
        return false;
980
0
      }
981
0
      Sequence<nsString> &arr = (mWorker_src.Value());
982
0
      JS::Rooted<JS::Value> temp(cx);
983
0
      while (true) {
984
0
        bool done;
985
0
        if (!iter.next(&temp, &done)) {
986
0
          return false;
987
0
        }
988
0
        if (done) {
989
0
          break;
990
0
        }
991
0
        nsString* slotPtr = arr.AppendElement(mozilla::fallible);
992
0
        if (!slotPtr) {
993
0
          JS_ReportOutOfMemory(cx);
994
0
          return false;
995
0
        }
996
0
        nsString& slot = *slotPtr;
997
0
        if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
998
0
          return false;
999
0
        }
1000
0
      }
1001
0
    } else {
1002
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'worker-src' member of CSP");
1003
0
      return false;
1004
0
    }
1005
0
    mIsAnyMemberPresent = true;
1006
0
  }
1007
0
  return true;
1008
0
}
1009
1010
bool
1011
CSP::Init(const nsAString& aJSON)
1012
0
{
1013
0
  AutoJSAPI jsapi;
1014
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
1015
0
  if (!cleanGlobal) {
1016
0
    return false;
1017
0
  }
1018
0
  if (!jsapi.Init(cleanGlobal)) {
1019
0
    return false;
1020
0
  }
1021
0
  JSContext* cx = jsapi.cx();
1022
0
  JS::Rooted<JS::Value> json(cx);
1023
0
  bool ok = ParseJSON(cx, aJSON, &json);
1024
0
  NS_ENSURE_TRUE(ok, false);
1025
0
  return Init(cx, json);
1026
0
}
1027
1028
bool
1029
CSP::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
1030
0
{
1031
0
  CSPAtoms* atomsCache = GetAtomCache<CSPAtoms>(cx);
1032
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1033
0
    return false;
1034
0
  }
1035
0
1036
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
1037
0
  if (!obj) {
1038
0
    return false;
1039
0
  }
1040
0
  rval.set(JS::ObjectValue(*obj));
1041
0
1042
0
  if (mBase_uri.WasPassed()) {
1043
0
    do {
1044
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1045
0
      JS::Rooted<JS::Value> temp(cx);
1046
0
      Sequence<nsString> const & currentValue = mBase_uri.InternalValue();
1047
0
1048
0
      uint32_t length = currentValue.Length();
1049
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1050
0
      if (!returnArray) {
1051
0
        return false;
1052
0
      }
1053
0
      // Scope for 'tmp'
1054
0
      {
1055
0
        JS::Rooted<JS::Value> tmp(cx);
1056
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1057
0
          // Control block to let us common up the JS_DefineElement calls when there
1058
0
          // are different ways to succeed at wrapping the object.
1059
0
          do {
1060
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1061
0
              return false;
1062
0
            }
1063
0
            break;
1064
0
          } while (false);
1065
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1066
0
                                JSPROP_ENUMERATE)) {
1067
0
            return false;
1068
0
          }
1069
0
        }
1070
0
      }
1071
0
      temp.setObject(*returnArray);
1072
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->base_uri_id, temp, JSPROP_ENUMERATE)) {
1073
0
        return false;
1074
0
      }
1075
0
      break;
1076
0
    } while(false);
1077
0
  }
1078
0
1079
0
  if (mBlock_all_mixed_content.WasPassed()) {
1080
0
    do {
1081
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1082
0
      JS::Rooted<JS::Value> temp(cx);
1083
0
      Sequence<nsString> const & currentValue = mBlock_all_mixed_content.InternalValue();
1084
0
1085
0
      uint32_t length = currentValue.Length();
1086
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1087
0
      if (!returnArray) {
1088
0
        return false;
1089
0
      }
1090
0
      // Scope for 'tmp'
1091
0
      {
1092
0
        JS::Rooted<JS::Value> tmp(cx);
1093
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1094
0
          // Control block to let us common up the JS_DefineElement calls when there
1095
0
          // are different ways to succeed at wrapping the object.
1096
0
          do {
1097
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1098
0
              return false;
1099
0
            }
1100
0
            break;
1101
0
          } while (false);
1102
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1103
0
                                JSPROP_ENUMERATE)) {
1104
0
            return false;
1105
0
          }
1106
0
        }
1107
0
      }
1108
0
      temp.setObject(*returnArray);
1109
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->block_all_mixed_content_id, temp, JSPROP_ENUMERATE)) {
1110
0
        return false;
1111
0
      }
1112
0
      break;
1113
0
    } while(false);
1114
0
  }
1115
0
1116
0
  if (mChild_src.WasPassed()) {
1117
0
    do {
1118
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1119
0
      JS::Rooted<JS::Value> temp(cx);
1120
0
      Sequence<nsString> const & currentValue = mChild_src.InternalValue();
1121
0
1122
0
      uint32_t length = currentValue.Length();
1123
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1124
0
      if (!returnArray) {
1125
0
        return false;
1126
0
      }
1127
0
      // Scope for 'tmp'
1128
0
      {
1129
0
        JS::Rooted<JS::Value> tmp(cx);
1130
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1131
0
          // Control block to let us common up the JS_DefineElement calls when there
1132
0
          // are different ways to succeed at wrapping the object.
1133
0
          do {
1134
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1135
0
              return false;
1136
0
            }
1137
0
            break;
1138
0
          } while (false);
1139
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1140
0
                                JSPROP_ENUMERATE)) {
1141
0
            return false;
1142
0
          }
1143
0
        }
1144
0
      }
1145
0
      temp.setObject(*returnArray);
1146
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->child_src_id, temp, JSPROP_ENUMERATE)) {
1147
0
        return false;
1148
0
      }
1149
0
      break;
1150
0
    } while(false);
1151
0
  }
1152
0
1153
0
  if (mConnect_src.WasPassed()) {
1154
0
    do {
1155
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1156
0
      JS::Rooted<JS::Value> temp(cx);
1157
0
      Sequence<nsString> const & currentValue = mConnect_src.InternalValue();
1158
0
1159
0
      uint32_t length = currentValue.Length();
1160
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1161
0
      if (!returnArray) {
1162
0
        return false;
1163
0
      }
1164
0
      // Scope for 'tmp'
1165
0
      {
1166
0
        JS::Rooted<JS::Value> tmp(cx);
1167
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1168
0
          // Control block to let us common up the JS_DefineElement calls when there
1169
0
          // are different ways to succeed at wrapping the object.
1170
0
          do {
1171
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1172
0
              return false;
1173
0
            }
1174
0
            break;
1175
0
          } while (false);
1176
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1177
0
                                JSPROP_ENUMERATE)) {
1178
0
            return false;
1179
0
          }
1180
0
        }
1181
0
      }
1182
0
      temp.setObject(*returnArray);
1183
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->connect_src_id, temp, JSPROP_ENUMERATE)) {
1184
0
        return false;
1185
0
      }
1186
0
      break;
1187
0
    } while(false);
1188
0
  }
1189
0
1190
0
  if (mDefault_src.WasPassed()) {
1191
0
    do {
1192
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1193
0
      JS::Rooted<JS::Value> temp(cx);
1194
0
      Sequence<nsString> const & currentValue = mDefault_src.InternalValue();
1195
0
1196
0
      uint32_t length = currentValue.Length();
1197
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1198
0
      if (!returnArray) {
1199
0
        return false;
1200
0
      }
1201
0
      // Scope for 'tmp'
1202
0
      {
1203
0
        JS::Rooted<JS::Value> tmp(cx);
1204
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1205
0
          // Control block to let us common up the JS_DefineElement calls when there
1206
0
          // are different ways to succeed at wrapping the object.
1207
0
          do {
1208
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1209
0
              return false;
1210
0
            }
1211
0
            break;
1212
0
          } while (false);
1213
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1214
0
                                JSPROP_ENUMERATE)) {
1215
0
            return false;
1216
0
          }
1217
0
        }
1218
0
      }
1219
0
      temp.setObject(*returnArray);
1220
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->default_src_id, temp, JSPROP_ENUMERATE)) {
1221
0
        return false;
1222
0
      }
1223
0
      break;
1224
0
    } while(false);
1225
0
  }
1226
0
1227
0
  if (mFont_src.WasPassed()) {
1228
0
    do {
1229
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1230
0
      JS::Rooted<JS::Value> temp(cx);
1231
0
      Sequence<nsString> const & currentValue = mFont_src.InternalValue();
1232
0
1233
0
      uint32_t length = currentValue.Length();
1234
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1235
0
      if (!returnArray) {
1236
0
        return false;
1237
0
      }
1238
0
      // Scope for 'tmp'
1239
0
      {
1240
0
        JS::Rooted<JS::Value> tmp(cx);
1241
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1242
0
          // Control block to let us common up the JS_DefineElement calls when there
1243
0
          // are different ways to succeed at wrapping the object.
1244
0
          do {
1245
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1246
0
              return false;
1247
0
            }
1248
0
            break;
1249
0
          } while (false);
1250
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1251
0
                                JSPROP_ENUMERATE)) {
1252
0
            return false;
1253
0
          }
1254
0
        }
1255
0
      }
1256
0
      temp.setObject(*returnArray);
1257
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->font_src_id, temp, JSPROP_ENUMERATE)) {
1258
0
        return false;
1259
0
      }
1260
0
      break;
1261
0
    } while(false);
1262
0
  }
1263
0
1264
0
  if (mForm_action.WasPassed()) {
1265
0
    do {
1266
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1267
0
      JS::Rooted<JS::Value> temp(cx);
1268
0
      Sequence<nsString> const & currentValue = mForm_action.InternalValue();
1269
0
1270
0
      uint32_t length = currentValue.Length();
1271
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1272
0
      if (!returnArray) {
1273
0
        return false;
1274
0
      }
1275
0
      // Scope for 'tmp'
1276
0
      {
1277
0
        JS::Rooted<JS::Value> tmp(cx);
1278
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1279
0
          // Control block to let us common up the JS_DefineElement calls when there
1280
0
          // are different ways to succeed at wrapping the object.
1281
0
          do {
1282
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1283
0
              return false;
1284
0
            }
1285
0
            break;
1286
0
          } while (false);
1287
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1288
0
                                JSPROP_ENUMERATE)) {
1289
0
            return false;
1290
0
          }
1291
0
        }
1292
0
      }
1293
0
      temp.setObject(*returnArray);
1294
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->form_action_id, temp, JSPROP_ENUMERATE)) {
1295
0
        return false;
1296
0
      }
1297
0
      break;
1298
0
    } while(false);
1299
0
  }
1300
0
1301
0
  if (mFrame_ancestors.WasPassed()) {
1302
0
    do {
1303
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1304
0
      JS::Rooted<JS::Value> temp(cx);
1305
0
      Sequence<nsString> const & currentValue = mFrame_ancestors.InternalValue();
1306
0
1307
0
      uint32_t length = currentValue.Length();
1308
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1309
0
      if (!returnArray) {
1310
0
        return false;
1311
0
      }
1312
0
      // Scope for 'tmp'
1313
0
      {
1314
0
        JS::Rooted<JS::Value> tmp(cx);
1315
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1316
0
          // Control block to let us common up the JS_DefineElement calls when there
1317
0
          // are different ways to succeed at wrapping the object.
1318
0
          do {
1319
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1320
0
              return false;
1321
0
            }
1322
0
            break;
1323
0
          } while (false);
1324
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1325
0
                                JSPROP_ENUMERATE)) {
1326
0
            return false;
1327
0
          }
1328
0
        }
1329
0
      }
1330
0
      temp.setObject(*returnArray);
1331
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->frame_ancestors_id, temp, JSPROP_ENUMERATE)) {
1332
0
        return false;
1333
0
      }
1334
0
      break;
1335
0
    } while(false);
1336
0
  }
1337
0
1338
0
  if (mFrame_src.WasPassed()) {
1339
0
    do {
1340
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1341
0
      JS::Rooted<JS::Value> temp(cx);
1342
0
      Sequence<nsString> const & currentValue = mFrame_src.InternalValue();
1343
0
1344
0
      uint32_t length = currentValue.Length();
1345
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1346
0
      if (!returnArray) {
1347
0
        return false;
1348
0
      }
1349
0
      // Scope for 'tmp'
1350
0
      {
1351
0
        JS::Rooted<JS::Value> tmp(cx);
1352
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1353
0
          // Control block to let us common up the JS_DefineElement calls when there
1354
0
          // are different ways to succeed at wrapping the object.
1355
0
          do {
1356
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1357
0
              return false;
1358
0
            }
1359
0
            break;
1360
0
          } while (false);
1361
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1362
0
                                JSPROP_ENUMERATE)) {
1363
0
            return false;
1364
0
          }
1365
0
        }
1366
0
      }
1367
0
      temp.setObject(*returnArray);
1368
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->frame_src_id, temp, JSPROP_ENUMERATE)) {
1369
0
        return false;
1370
0
      }
1371
0
      break;
1372
0
    } while(false);
1373
0
  }
1374
0
1375
0
  if (mImg_src.WasPassed()) {
1376
0
    do {
1377
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1378
0
      JS::Rooted<JS::Value> temp(cx);
1379
0
      Sequence<nsString> const & currentValue = mImg_src.InternalValue();
1380
0
1381
0
      uint32_t length = currentValue.Length();
1382
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1383
0
      if (!returnArray) {
1384
0
        return false;
1385
0
      }
1386
0
      // Scope for 'tmp'
1387
0
      {
1388
0
        JS::Rooted<JS::Value> tmp(cx);
1389
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1390
0
          // Control block to let us common up the JS_DefineElement calls when there
1391
0
          // are different ways to succeed at wrapping the object.
1392
0
          do {
1393
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1394
0
              return false;
1395
0
            }
1396
0
            break;
1397
0
          } while (false);
1398
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1399
0
                                JSPROP_ENUMERATE)) {
1400
0
            return false;
1401
0
          }
1402
0
        }
1403
0
      }
1404
0
      temp.setObject(*returnArray);
1405
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->img_src_id, temp, JSPROP_ENUMERATE)) {
1406
0
        return false;
1407
0
      }
1408
0
      break;
1409
0
    } while(false);
1410
0
  }
1411
0
1412
0
  if (mManifest_src.WasPassed()) {
1413
0
    do {
1414
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1415
0
      JS::Rooted<JS::Value> temp(cx);
1416
0
      Sequence<nsString> const & currentValue = mManifest_src.InternalValue();
1417
0
1418
0
      uint32_t length = currentValue.Length();
1419
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1420
0
      if (!returnArray) {
1421
0
        return false;
1422
0
      }
1423
0
      // Scope for 'tmp'
1424
0
      {
1425
0
        JS::Rooted<JS::Value> tmp(cx);
1426
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1427
0
          // Control block to let us common up the JS_DefineElement calls when there
1428
0
          // are different ways to succeed at wrapping the object.
1429
0
          do {
1430
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1431
0
              return false;
1432
0
            }
1433
0
            break;
1434
0
          } while (false);
1435
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1436
0
                                JSPROP_ENUMERATE)) {
1437
0
            return false;
1438
0
          }
1439
0
        }
1440
0
      }
1441
0
      temp.setObject(*returnArray);
1442
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->manifest_src_id, temp, JSPROP_ENUMERATE)) {
1443
0
        return false;
1444
0
      }
1445
0
      break;
1446
0
    } while(false);
1447
0
  }
1448
0
1449
0
  if (mMedia_src.WasPassed()) {
1450
0
    do {
1451
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1452
0
      JS::Rooted<JS::Value> temp(cx);
1453
0
      Sequence<nsString> const & currentValue = mMedia_src.InternalValue();
1454
0
1455
0
      uint32_t length = currentValue.Length();
1456
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1457
0
      if (!returnArray) {
1458
0
        return false;
1459
0
      }
1460
0
      // Scope for 'tmp'
1461
0
      {
1462
0
        JS::Rooted<JS::Value> tmp(cx);
1463
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1464
0
          // Control block to let us common up the JS_DefineElement calls when there
1465
0
          // are different ways to succeed at wrapping the object.
1466
0
          do {
1467
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1468
0
              return false;
1469
0
            }
1470
0
            break;
1471
0
          } while (false);
1472
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1473
0
                                JSPROP_ENUMERATE)) {
1474
0
            return false;
1475
0
          }
1476
0
        }
1477
0
      }
1478
0
      temp.setObject(*returnArray);
1479
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->media_src_id, temp, JSPROP_ENUMERATE)) {
1480
0
        return false;
1481
0
      }
1482
0
      break;
1483
0
    } while(false);
1484
0
  }
1485
0
1486
0
  if (mObject_src.WasPassed()) {
1487
0
    do {
1488
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1489
0
      JS::Rooted<JS::Value> temp(cx);
1490
0
      Sequence<nsString> const & currentValue = mObject_src.InternalValue();
1491
0
1492
0
      uint32_t length = currentValue.Length();
1493
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1494
0
      if (!returnArray) {
1495
0
        return false;
1496
0
      }
1497
0
      // Scope for 'tmp'
1498
0
      {
1499
0
        JS::Rooted<JS::Value> tmp(cx);
1500
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1501
0
          // Control block to let us common up the JS_DefineElement calls when there
1502
0
          // are different ways to succeed at wrapping the object.
1503
0
          do {
1504
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1505
0
              return false;
1506
0
            }
1507
0
            break;
1508
0
          } while (false);
1509
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1510
0
                                JSPROP_ENUMERATE)) {
1511
0
            return false;
1512
0
          }
1513
0
        }
1514
0
      }
1515
0
      temp.setObject(*returnArray);
1516
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->object_src_id, temp, JSPROP_ENUMERATE)) {
1517
0
        return false;
1518
0
      }
1519
0
      break;
1520
0
    } while(false);
1521
0
  }
1522
0
1523
0
  if (mReferrer.WasPassed()) {
1524
0
    do {
1525
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1526
0
      JS::Rooted<JS::Value> temp(cx);
1527
0
      Sequence<nsString> const & currentValue = mReferrer.InternalValue();
1528
0
1529
0
      uint32_t length = currentValue.Length();
1530
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1531
0
      if (!returnArray) {
1532
0
        return false;
1533
0
      }
1534
0
      // Scope for 'tmp'
1535
0
      {
1536
0
        JS::Rooted<JS::Value> tmp(cx);
1537
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1538
0
          // Control block to let us common up the JS_DefineElement calls when there
1539
0
          // are different ways to succeed at wrapping the object.
1540
0
          do {
1541
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1542
0
              return false;
1543
0
            }
1544
0
            break;
1545
0
          } while (false);
1546
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1547
0
                                JSPROP_ENUMERATE)) {
1548
0
            return false;
1549
0
          }
1550
0
        }
1551
0
      }
1552
0
      temp.setObject(*returnArray);
1553
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->referrer_id, temp, JSPROP_ENUMERATE)) {
1554
0
        return false;
1555
0
      }
1556
0
      break;
1557
0
    } while(false);
1558
0
  }
1559
0
1560
0
  do {
1561
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1562
0
    JS::Rooted<JS::Value> temp(cx);
1563
0
    bool const & currentValue = mReport_only;
1564
0
    temp.setBoolean(currentValue);
1565
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->report_only_id, temp, JSPROP_ENUMERATE)) {
1566
0
      return false;
1567
0
    }
1568
0
    break;
1569
0
  } while(false);
1570
0
1571
0
  if (mReport_uri.WasPassed()) {
1572
0
    do {
1573
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1574
0
      JS::Rooted<JS::Value> temp(cx);
1575
0
      Sequence<nsString> const & currentValue = mReport_uri.InternalValue();
1576
0
1577
0
      uint32_t length = currentValue.Length();
1578
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1579
0
      if (!returnArray) {
1580
0
        return false;
1581
0
      }
1582
0
      // Scope for 'tmp'
1583
0
      {
1584
0
        JS::Rooted<JS::Value> tmp(cx);
1585
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1586
0
          // Control block to let us common up the JS_DefineElement calls when there
1587
0
          // are different ways to succeed at wrapping the object.
1588
0
          do {
1589
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1590
0
              return false;
1591
0
            }
1592
0
            break;
1593
0
          } while (false);
1594
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1595
0
                                JSPROP_ENUMERATE)) {
1596
0
            return false;
1597
0
          }
1598
0
        }
1599
0
      }
1600
0
      temp.setObject(*returnArray);
1601
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->report_uri_id, temp, JSPROP_ENUMERATE)) {
1602
0
        return false;
1603
0
      }
1604
0
      break;
1605
0
    } while(false);
1606
0
  }
1607
0
1608
0
  if (mRequire_sri_for.WasPassed()) {
1609
0
    do {
1610
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1611
0
      JS::Rooted<JS::Value> temp(cx);
1612
0
      Sequence<nsString> const & currentValue = mRequire_sri_for.InternalValue();
1613
0
1614
0
      uint32_t length = currentValue.Length();
1615
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1616
0
      if (!returnArray) {
1617
0
        return false;
1618
0
      }
1619
0
      // Scope for 'tmp'
1620
0
      {
1621
0
        JS::Rooted<JS::Value> tmp(cx);
1622
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1623
0
          // Control block to let us common up the JS_DefineElement calls when there
1624
0
          // are different ways to succeed at wrapping the object.
1625
0
          do {
1626
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1627
0
              return false;
1628
0
            }
1629
0
            break;
1630
0
          } while (false);
1631
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1632
0
                                JSPROP_ENUMERATE)) {
1633
0
            return false;
1634
0
          }
1635
0
        }
1636
0
      }
1637
0
      temp.setObject(*returnArray);
1638
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->require_sri_for_id, temp, JSPROP_ENUMERATE)) {
1639
0
        return false;
1640
0
      }
1641
0
      break;
1642
0
    } while(false);
1643
0
  }
1644
0
1645
0
  if (mSandbox.WasPassed()) {
1646
0
    do {
1647
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1648
0
      JS::Rooted<JS::Value> temp(cx);
1649
0
      Sequence<nsString> const & currentValue = mSandbox.InternalValue();
1650
0
1651
0
      uint32_t length = currentValue.Length();
1652
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1653
0
      if (!returnArray) {
1654
0
        return false;
1655
0
      }
1656
0
      // Scope for 'tmp'
1657
0
      {
1658
0
        JS::Rooted<JS::Value> tmp(cx);
1659
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1660
0
          // Control block to let us common up the JS_DefineElement calls when there
1661
0
          // are different ways to succeed at wrapping the object.
1662
0
          do {
1663
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1664
0
              return false;
1665
0
            }
1666
0
            break;
1667
0
          } while (false);
1668
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1669
0
                                JSPROP_ENUMERATE)) {
1670
0
            return false;
1671
0
          }
1672
0
        }
1673
0
      }
1674
0
      temp.setObject(*returnArray);
1675
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->sandbox_id, temp, JSPROP_ENUMERATE)) {
1676
0
        return false;
1677
0
      }
1678
0
      break;
1679
0
    } while(false);
1680
0
  }
1681
0
1682
0
  if (mScript_src.WasPassed()) {
1683
0
    do {
1684
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1685
0
      JS::Rooted<JS::Value> temp(cx);
1686
0
      Sequence<nsString> const & currentValue = mScript_src.InternalValue();
1687
0
1688
0
      uint32_t length = currentValue.Length();
1689
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1690
0
      if (!returnArray) {
1691
0
        return false;
1692
0
      }
1693
0
      // Scope for 'tmp'
1694
0
      {
1695
0
        JS::Rooted<JS::Value> tmp(cx);
1696
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1697
0
          // Control block to let us common up the JS_DefineElement calls when there
1698
0
          // are different ways to succeed at wrapping the object.
1699
0
          do {
1700
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1701
0
              return false;
1702
0
            }
1703
0
            break;
1704
0
          } while (false);
1705
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1706
0
                                JSPROP_ENUMERATE)) {
1707
0
            return false;
1708
0
          }
1709
0
        }
1710
0
      }
1711
0
      temp.setObject(*returnArray);
1712
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->script_src_id, temp, JSPROP_ENUMERATE)) {
1713
0
        return false;
1714
0
      }
1715
0
      break;
1716
0
    } while(false);
1717
0
  }
1718
0
1719
0
  if (mStyle_src.WasPassed()) {
1720
0
    do {
1721
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1722
0
      JS::Rooted<JS::Value> temp(cx);
1723
0
      Sequence<nsString> const & currentValue = mStyle_src.InternalValue();
1724
0
1725
0
      uint32_t length = currentValue.Length();
1726
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1727
0
      if (!returnArray) {
1728
0
        return false;
1729
0
      }
1730
0
      // Scope for 'tmp'
1731
0
      {
1732
0
        JS::Rooted<JS::Value> tmp(cx);
1733
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1734
0
          // Control block to let us common up the JS_DefineElement calls when there
1735
0
          // are different ways to succeed at wrapping the object.
1736
0
          do {
1737
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1738
0
              return false;
1739
0
            }
1740
0
            break;
1741
0
          } while (false);
1742
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1743
0
                                JSPROP_ENUMERATE)) {
1744
0
            return false;
1745
0
          }
1746
0
        }
1747
0
      }
1748
0
      temp.setObject(*returnArray);
1749
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->style_src_id, temp, JSPROP_ENUMERATE)) {
1750
0
        return false;
1751
0
      }
1752
0
      break;
1753
0
    } while(false);
1754
0
  }
1755
0
1756
0
  if (mUpgrade_insecure_requests.WasPassed()) {
1757
0
    do {
1758
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1759
0
      JS::Rooted<JS::Value> temp(cx);
1760
0
      Sequence<nsString> const & currentValue = mUpgrade_insecure_requests.InternalValue();
1761
0
1762
0
      uint32_t length = currentValue.Length();
1763
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1764
0
      if (!returnArray) {
1765
0
        return false;
1766
0
      }
1767
0
      // Scope for 'tmp'
1768
0
      {
1769
0
        JS::Rooted<JS::Value> tmp(cx);
1770
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1771
0
          // Control block to let us common up the JS_DefineElement calls when there
1772
0
          // are different ways to succeed at wrapping the object.
1773
0
          do {
1774
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1775
0
              return false;
1776
0
            }
1777
0
            break;
1778
0
          } while (false);
1779
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1780
0
                                JSPROP_ENUMERATE)) {
1781
0
            return false;
1782
0
          }
1783
0
        }
1784
0
      }
1785
0
      temp.setObject(*returnArray);
1786
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->upgrade_insecure_requests_id, temp, JSPROP_ENUMERATE)) {
1787
0
        return false;
1788
0
      }
1789
0
      break;
1790
0
    } while(false);
1791
0
  }
1792
0
1793
0
  if (mWorker_src.WasPassed()) {
1794
0
    do {
1795
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1796
0
      JS::Rooted<JS::Value> temp(cx);
1797
0
      Sequence<nsString> const & currentValue = mWorker_src.InternalValue();
1798
0
1799
0
      uint32_t length = currentValue.Length();
1800
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
1801
0
      if (!returnArray) {
1802
0
        return false;
1803
0
      }
1804
0
      // Scope for 'tmp'
1805
0
      {
1806
0
        JS::Rooted<JS::Value> tmp(cx);
1807
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
1808
0
          // Control block to let us common up the JS_DefineElement calls when there
1809
0
          // are different ways to succeed at wrapping the object.
1810
0
          do {
1811
0
            if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
1812
0
              return false;
1813
0
            }
1814
0
            break;
1815
0
          } while (false);
1816
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
1817
0
                                JSPROP_ENUMERATE)) {
1818
0
            return false;
1819
0
          }
1820
0
        }
1821
0
      }
1822
0
      temp.setObject(*returnArray);
1823
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->worker_src_id, temp, JSPROP_ENUMERATE)) {
1824
0
        return false;
1825
0
      }
1826
0
      break;
1827
0
    } while(false);
1828
0
  }
1829
0
1830
0
  return true;
1831
0
}
1832
1833
bool
1834
CSP::ToJSON(nsAString& aJSON) const
1835
0
{
1836
0
  AutoJSAPI jsapi;
1837
0
  jsapi.Init();
1838
0
  JSContext *cx = jsapi.cx();
1839
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
1840
0
  // because we'll only be creating objects, in ways that have no
1841
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
1842
0
  // which likewise guarantees no side-effects for the sorts of
1843
0
  // things we will pass it.
1844
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
1845
0
  JS::Rooted<JS::Value> val(cx);
1846
0
  if (!ToObjectInternal(cx, &val)) {
1847
0
    return false;
1848
0
  }
1849
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
1850
0
  return StringifyToJSON(cx, obj, aJSON);
1851
0
}
1852
1853
void
1854
CSP::TraceDictionary(JSTracer* trc)
1855
0
{
1856
0
}
1857
1858
CSP&
1859
CSP::operator=(const CSP& aOther)
1860
0
{
1861
0
  DictionaryBase::operator=(aOther);
1862
0
  mBase_uri.Reset();
1863
0
  if (aOther.mBase_uri.WasPassed()) {
1864
0
    mBase_uri.Construct(aOther.mBase_uri.Value());
1865
0
  }
1866
0
  mBlock_all_mixed_content.Reset();
1867
0
  if (aOther.mBlock_all_mixed_content.WasPassed()) {
1868
0
    mBlock_all_mixed_content.Construct(aOther.mBlock_all_mixed_content.Value());
1869
0
  }
1870
0
  mChild_src.Reset();
1871
0
  if (aOther.mChild_src.WasPassed()) {
1872
0
    mChild_src.Construct(aOther.mChild_src.Value());
1873
0
  }
1874
0
  mConnect_src.Reset();
1875
0
  if (aOther.mConnect_src.WasPassed()) {
1876
0
    mConnect_src.Construct(aOther.mConnect_src.Value());
1877
0
  }
1878
0
  mDefault_src.Reset();
1879
0
  if (aOther.mDefault_src.WasPassed()) {
1880
0
    mDefault_src.Construct(aOther.mDefault_src.Value());
1881
0
  }
1882
0
  mFont_src.Reset();
1883
0
  if (aOther.mFont_src.WasPassed()) {
1884
0
    mFont_src.Construct(aOther.mFont_src.Value());
1885
0
  }
1886
0
  mForm_action.Reset();
1887
0
  if (aOther.mForm_action.WasPassed()) {
1888
0
    mForm_action.Construct(aOther.mForm_action.Value());
1889
0
  }
1890
0
  mFrame_ancestors.Reset();
1891
0
  if (aOther.mFrame_ancestors.WasPassed()) {
1892
0
    mFrame_ancestors.Construct(aOther.mFrame_ancestors.Value());
1893
0
  }
1894
0
  mFrame_src.Reset();
1895
0
  if (aOther.mFrame_src.WasPassed()) {
1896
0
    mFrame_src.Construct(aOther.mFrame_src.Value());
1897
0
  }
1898
0
  mImg_src.Reset();
1899
0
  if (aOther.mImg_src.WasPassed()) {
1900
0
    mImg_src.Construct(aOther.mImg_src.Value());
1901
0
  }
1902
0
  mManifest_src.Reset();
1903
0
  if (aOther.mManifest_src.WasPassed()) {
1904
0
    mManifest_src.Construct(aOther.mManifest_src.Value());
1905
0
  }
1906
0
  mMedia_src.Reset();
1907
0
  if (aOther.mMedia_src.WasPassed()) {
1908
0
    mMedia_src.Construct(aOther.mMedia_src.Value());
1909
0
  }
1910
0
  mObject_src.Reset();
1911
0
  if (aOther.mObject_src.WasPassed()) {
1912
0
    mObject_src.Construct(aOther.mObject_src.Value());
1913
0
  }
1914
0
  mReferrer.Reset();
1915
0
  if (aOther.mReferrer.WasPassed()) {
1916
0
    mReferrer.Construct(aOther.mReferrer.Value());
1917
0
  }
1918
0
  mReport_only = aOther.mReport_only;
1919
0
  mReport_uri.Reset();
1920
0
  if (aOther.mReport_uri.WasPassed()) {
1921
0
    mReport_uri.Construct(aOther.mReport_uri.Value());
1922
0
  }
1923
0
  mRequire_sri_for.Reset();
1924
0
  if (aOther.mRequire_sri_for.WasPassed()) {
1925
0
    mRequire_sri_for.Construct(aOther.mRequire_sri_for.Value());
1926
0
  }
1927
0
  mSandbox.Reset();
1928
0
  if (aOther.mSandbox.WasPassed()) {
1929
0
    mSandbox.Construct(aOther.mSandbox.Value());
1930
0
  }
1931
0
  mScript_src.Reset();
1932
0
  if (aOther.mScript_src.WasPassed()) {
1933
0
    mScript_src.Construct(aOther.mScript_src.Value());
1934
0
  }
1935
0
  mStyle_src.Reset();
1936
0
  if (aOther.mStyle_src.WasPassed()) {
1937
0
    mStyle_src.Construct(aOther.mStyle_src.Value());
1938
0
  }
1939
0
  mUpgrade_insecure_requests.Reset();
1940
0
  if (aOther.mUpgrade_insecure_requests.WasPassed()) {
1941
0
    mUpgrade_insecure_requests.Construct(aOther.mUpgrade_insecure_requests.Value());
1942
0
  }
1943
0
  mWorker_src.Reset();
1944
0
  if (aOther.mWorker_src.WasPassed()) {
1945
0
    mWorker_src.Construct(aOther.mWorker_src.Value());
1946
0
  }
1947
0
  return *this;
1948
0
}
1949
1950
namespace binding_detail {
1951
} // namespace binding_detail
1952
1953
1954
1955
CSPPolicies::CSPPolicies()
1956
0
{
1957
0
  // Safe to pass a null context if we pass a null value
1958
0
  Init(nullptr, JS::NullHandleValue);
1959
0
}
1960
1961
1962
1963
bool
1964
CSPPolicies::InitIds(JSContext* cx, CSPPoliciesAtoms* atomsCache)
1965
0
{
1966
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
1967
0
1968
0
  // Initialize these in reverse order so that any failure leaves the first one
1969
0
  // uninitialized.
1970
0
  if (!atomsCache->csp_policies_id.init(cx, "csp-policies")) {
1971
0
    return false;
1972
0
  }
1973
0
  return true;
1974
0
}
1975
1976
bool
1977
CSPPolicies::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
1978
0
{
1979
0
  // Passing a null JSContext is OK only if we're initing from null,
1980
0
  // Since in that case we will not have to do any property gets
1981
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
1982
0
  // checkers by static analysis tools
1983
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
1984
0
  CSPPoliciesAtoms* atomsCache = nullptr;
1985
0
  if (cx) {
1986
0
    atomsCache = GetAtomCache<CSPPoliciesAtoms>(cx);
1987
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1988
0
      return false;
1989
0
    }
1990
0
  }
1991
0
1992
0
  if (!IsConvertibleToDictionary(val)) {
1993
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
1994
0
  }
1995
0
1996
0
  bool isNull = val.isNullOrUndefined();
1997
0
  // We only need these if !isNull, in which case we have |cx|.
1998
0
  Maybe<JS::Rooted<JSObject *> > object;
1999
0
  Maybe<JS::Rooted<JS::Value> > temp;
2000
0
  if (!isNull) {
2001
0
    MOZ_ASSERT(cx);
2002
0
    object.emplace(cx, &val.toObject());
2003
0
    temp.emplace(cx);
2004
0
  }
2005
0
  if (!isNull) {
2006
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->csp_policies_id, temp.ptr())) {
2007
0
      return false;
2008
0
    }
2009
0
  }
2010
0
  if (!isNull && !temp->isUndefined()) {
2011
0
    mCsp_policies.Construct();
2012
0
    if (temp.ref().isObject()) {
2013
0
      JS::ForOfIterator iter(cx);
2014
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
2015
0
        return false;
2016
0
      }
2017
0
      if (!iter.valueIsIterable()) {
2018
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'csp-policies' member of CSPPolicies");
2019
0
        return false;
2020
0
      }
2021
0
      Sequence<CSP> &arr = (mCsp_policies.Value());
2022
0
      JS::Rooted<JS::Value> temp(cx);
2023
0
      while (true) {
2024
0
        bool done;
2025
0
        if (!iter.next(&temp, &done)) {
2026
0
          return false;
2027
0
        }
2028
0
        if (done) {
2029
0
          break;
2030
0
        }
2031
0
        CSP* slotPtr = arr.AppendElement(mozilla::fallible);
2032
0
        if (!slotPtr) {
2033
0
          JS_ReportOutOfMemory(cx);
2034
0
          return false;
2035
0
        }
2036
0
        CSP& slot = *slotPtr;
2037
0
        if (!slot.Init(cx, temp,  "Element of 'csp-policies' member of CSPPolicies", passedToJSImpl)) {
2038
0
          return false;
2039
0
        }
2040
0
      }
2041
0
    } else {
2042
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'csp-policies' member of CSPPolicies");
2043
0
      return false;
2044
0
    }
2045
0
    mIsAnyMemberPresent = true;
2046
0
  }
2047
0
  return true;
2048
0
}
2049
2050
bool
2051
CSPPolicies::Init(const nsAString& aJSON)
2052
0
{
2053
0
  AutoJSAPI jsapi;
2054
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
2055
0
  if (!cleanGlobal) {
2056
0
    return false;
2057
0
  }
2058
0
  if (!jsapi.Init(cleanGlobal)) {
2059
0
    return false;
2060
0
  }
2061
0
  JSContext* cx = jsapi.cx();
2062
0
  JS::Rooted<JS::Value> json(cx);
2063
0
  bool ok = ParseJSON(cx, aJSON, &json);
2064
0
  NS_ENSURE_TRUE(ok, false);
2065
0
  return Init(cx, json);
2066
0
}
2067
2068
bool
2069
CSPPolicies::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
2070
0
{
2071
0
  CSPPoliciesAtoms* atomsCache = GetAtomCache<CSPPoliciesAtoms>(cx);
2072
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
2073
0
    return false;
2074
0
  }
2075
0
2076
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
2077
0
  if (!obj) {
2078
0
    return false;
2079
0
  }
2080
0
  rval.set(JS::ObjectValue(*obj));
2081
0
2082
0
  if (mCsp_policies.WasPassed()) {
2083
0
    do {
2084
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2085
0
      JS::Rooted<JS::Value> temp(cx);
2086
0
      Sequence<CSP> const & currentValue = mCsp_policies.InternalValue();
2087
0
2088
0
      uint32_t length = currentValue.Length();
2089
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
2090
0
      if (!returnArray) {
2091
0
        return false;
2092
0
      }
2093
0
      // Scope for 'tmp'
2094
0
      {
2095
0
        JS::Rooted<JS::Value> tmp(cx);
2096
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
2097
0
          // Control block to let us common up the JS_DefineElement calls when there
2098
0
          // are different ways to succeed at wrapping the object.
2099
0
          do {
2100
0
            if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) {
2101
0
              return false;
2102
0
            }
2103
0
            break;
2104
0
          } while (false);
2105
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
2106
0
                                JSPROP_ENUMERATE)) {
2107
0
            return false;
2108
0
          }
2109
0
        }
2110
0
      }
2111
0
      temp.setObject(*returnArray);
2112
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->csp_policies_id, temp, JSPROP_ENUMERATE)) {
2113
0
        return false;
2114
0
      }
2115
0
      break;
2116
0
    } while(false);
2117
0
  }
2118
0
2119
0
  return true;
2120
0
}
2121
2122
bool
2123
CSPPolicies::ToJSON(nsAString& aJSON) const
2124
0
{
2125
0
  AutoJSAPI jsapi;
2126
0
  jsapi.Init();
2127
0
  JSContext *cx = jsapi.cx();
2128
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
2129
0
  // because we'll only be creating objects, in ways that have no
2130
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
2131
0
  // which likewise guarantees no side-effects for the sorts of
2132
0
  // things we will pass it.
2133
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
2134
0
  JS::Rooted<JS::Value> val(cx);
2135
0
  if (!ToObjectInternal(cx, &val)) {
2136
0
    return false;
2137
0
  }
2138
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
2139
0
  return StringifyToJSON(cx, obj, aJSON);
2140
0
}
2141
2142
void
2143
CSPPolicies::TraceDictionary(JSTracer* trc)
2144
0
{
2145
0
}
2146
2147
CSPPolicies&
2148
CSPPolicies::operator=(const CSPPolicies& aOther)
2149
0
{
2150
0
  DictionaryBase::operator=(aOther);
2151
0
  mCsp_policies.Reset();
2152
0
  if (aOther.mCsp_policies.WasPassed()) {
2153
0
    mCsp_policies.Construct(aOther.mCsp_policies.Value());
2154
0
  }
2155
0
  return *this;
2156
0
}
2157
2158
namespace binding_detail {
2159
} // namespace binding_detail
2160
2161
2162
} // namespace dom
2163
} // namespace mozilla