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