Skip to content

Commit 416cf1b

Browse files
committed
Bug 1931295 - Implement Trusted Types support for Worker/SharedWorker's constructors for Window. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D229344 UltraBlame original commit: b54dcba0386af7c7204fc3f334d137d9bd22c98d
1 parent 5a2c4be commit 416cf1b

File tree

9 files changed

+321
-40
lines changed

9 files changed

+321
-40
lines changed

dom/security/trusted-types/TrustedTypeUtils.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,27 @@ std
15641564
is_same_v
15651565
<
15661566
TrustedTypeOrStringArg
1567+
TrustedScriptURLOrUSVString
1568+
>
1569+
)
1570+
{
1571+
return
1572+
aInput
1573+
.
1574+
IsUSVString
1575+
(
1576+
)
1577+
;
1578+
}
1579+
if
1580+
constexpr
1581+
(
1582+
std
1583+
:
1584+
:
1585+
is_same_v
1586+
<
1587+
TrustedTypeOrStringArg
15671588
const
15681589
nsAString
15691590
*
@@ -1689,6 +1710,28 @@ std
16891710
is_same_v
16901711
<
16911712
TrustedTypeOrStringArg
1713+
TrustedScriptURLOrUSVString
1714+
>
1715+
)
1716+
{
1717+
return
1718+
&
1719+
aInput
1720+
.
1721+
GetAsUSVString
1722+
(
1723+
)
1724+
;
1725+
}
1726+
if
1727+
constexpr
1728+
(
1729+
std
1730+
:
1731+
:
1732+
is_same_v
1733+
<
1734+
TrustedTypeOrStringArg
16921735
const
16931736
nsAString
16941737
*
@@ -1810,6 +1853,16 @@ is_same_v
18101853
TrustedTypeOrStringArg
18111854
TrustedScriptURLOrString
18121855
>
1856+
|
1857+
|
1858+
std
1859+
:
1860+
:
1861+
is_same_v
1862+
<
1863+
TrustedTypeOrStringArg
1864+
TrustedScriptURLOrUSVString
1865+
>
18131866
)
18141867
{
18151868
return
@@ -1950,6 +2003,16 @@ is_same_v
19502003
TrustedTypeOrStringArg
19512004
TrustedScriptURLOrString
19522005
>
2006+
|
2007+
|
2008+
std
2009+
:
2010+
:
2011+
is_same_v
2012+
<
2013+
TrustedTypeOrStringArg
2014+
TrustedScriptURLOrUSVString
2015+
>
19532016
)
19542017
{
19552018
return
@@ -2700,6 +2763,13 @@ const
27002763
nsINode
27012764
)
27022765
;
2766+
IMPL_GET_TRUSTED_TYPES_COMPLIANT_STRING
2767+
(
2768+
TrustedScriptURLOrUSVString
2769+
TrustedScriptURL
2770+
nsIGlobalObject
2771+
)
2772+
;
27032773
MOZ_CAN_RUN_SCRIPT
27042774
const
27052775
nsAString

dom/security/trusted-types/TrustedTypeUtils.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ class
234234
TrustedScriptURLOrString
235235
;
236236
class
237+
TrustedScriptURLOrUSVString
238+
;
239+
class
237240
TrustedHTMLOrTrustedScriptOrTrustedScriptURLOrString
238241
;
239242
namespace
@@ -659,6 +662,38 @@ MOZ_CAN_RUN_SCRIPT
659662
const
660663
nsAString
661664
*
665+
GetTrustedTypesCompliantString
666+
(
667+
const
668+
TrustedScriptURLOrUSVString
669+
&
670+
aInput
671+
const
672+
nsAString
673+
&
674+
aSink
675+
const
676+
nsAString
677+
&
678+
aSinkGroup
679+
nsIGlobalObject
680+
&
681+
aGlobalObject
682+
Maybe
683+
<
684+
nsAutoString
685+
>
686+
&
687+
aResultHolder
688+
ErrorResult
689+
&
690+
aError
691+
)
692+
;
693+
MOZ_CAN_RUN_SCRIPT
694+
const
695+
nsAString
696+
*
662697
GetTrustedTypesCompliantStringForTrustedHTML
663698
(
664699
const

dom/webidl/SharedWorker.webidl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ Throws
106106
]
107107
constructor
108108
(
109+
(
110+
TrustedScriptURL
111+
or
109112
USVString
113+
)
110114
scriptURL
111115
optional
112116
(

dom/webidl/Worker.webidl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ Throws
173173
]
174174
constructor
175175
(
176+
(
177+
TrustedScriptURL
178+
or
176179
USVString
180+
)
177181
scriptURL
178182
optional
179183
WorkerOptions

dom/workers/Worker.cpp

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,28 @@ RefPtr
249249
h
250250
"
251251
#
252+
include
253+
"
254+
mozilla
255+
/
256+
dom
257+
/
258+
TrustedTypeUtils
259+
.
260+
h
261+
"
262+
#
263+
include
264+
"
265+
mozilla
266+
/
267+
dom
268+
/
269+
TrustedTypesConstants
270+
.
271+
h
272+
"
273+
#
252274
ifdef
253275
XP_WIN
254276
#
@@ -281,7 +303,7 @@ GlobalObject
281303
&
282304
aGlobal
283305
const
284-
nsAString
306+
TrustedScriptURLOrUSVString
285307
&
286308
aScriptURL
287309
const
@@ -364,6 +386,55 @@ return
364386
nullptr
365387
;
366388
}
389+
constexpr
390+
nsLiteralString
391+
sink
392+
=
393+
u
394+
"
395+
Worker
396+
constructor
397+
"
398+
_ns
399+
;
400+
Maybe
401+
<
402+
nsAutoString
403+
>
404+
compliantStringHolder
405+
;
406+
const
407+
nsAString
408+
*
409+
compliantString
410+
=
411+
TrustedTypeUtils
412+
:
413+
:
414+
GetTrustedTypesCompliantString
415+
(
416+
aScriptURL
417+
sink
418+
kTrustedTypesOnlySinkGroup
419+
*
420+
globalObject
421+
compliantStringHolder
422+
aRv
423+
)
424+
;
425+
if
426+
(
427+
aRv
428+
.
429+
Failed
430+
(
431+
)
432+
)
433+
{
434+
return
435+
nullptr
436+
;
437+
}
367438
RefPtr
368439
<
369440
WorkerPrivate
@@ -376,7 +447,8 @@ WorkerPrivate
376447
Constructor
377448
(
378449
cx
379-
aScriptURL
450+
*
451+
compliantString
380452
false
381453
/
382454
*

dom/workers/Worker.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ class
194194
WorkerPrivate
195195
;
196196
class
197+
TrustedScriptURLOrUSVString
198+
;
199+
class
197200
Worker
198201
:
199202
public
@@ -209,6 +212,24 @@ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED
209212
Worker
210213
DOMEventTargetHelper
211214
)
215+
/
216+
/
217+
TODO
218+
(
219+
bug
220+
1749042
221+
)
222+
:
223+
Mark
224+
as
225+
MOZ_CAN_RUN_SCRIPT
226+
when
227+
IDL
228+
constructors
229+
can
230+
be
231+
.
232+
MOZ_CAN_RUN_SCRIPT_BOUNDARY
212233
static
213234
already_AddRefed
214235
<
@@ -221,7 +242,7 @@ GlobalObject
221242
&
222243
aGlobal
223244
const
224-
nsAString
245+
TrustedScriptURLOrUSVString
225246
&
226247
aScriptURL
227248
const

0 commit comments

Comments
 (0)