Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit 6ab690b

Browse files
kotonreid260
authored andcommitted
goog.createTrustedTypesPolicy supports the newer version of the API where window.trustedTypes replaces window.TrustedTypes. Change introduced in w3c/trusted-types#205.
RELNOTES: n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=264631395
1 parent 7aa211d commit 6ab690b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

closure/goog/base.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4150,7 +4150,9 @@ goog.identity_ = function(s) {
41504150
*/
41514151
goog.createTrustedTypesPolicy = function(name) {
41524152
var policy = null;
4153-
if (typeof TrustedTypes === 'undefined' || !TrustedTypes.createPolicy) {
4153+
// TODO(koto): Remove window.TrustedTypes variant when the newer API ships.
4154+
var policyFactory = goog.global.trustedTypes || goog.global.TrustedTypes;
4155+
if (!policyFactory || !policyFactory.createPolicy) {
41544156
return policy;
41554157
}
41564158
// TrustedTypes.createPolicy throws if called with a name that is already
@@ -4159,7 +4161,7 @@ goog.createTrustedTypesPolicy = function(name) {
41594161
// will fall back to using regular Safe Types.
41604162
// TODO(koto): Remove catching once createPolicy API stops throwing.
41614163
try {
4162-
policy = TrustedTypes.createPolicy(name, {
4164+
policy = policyFactory.createPolicy(name, {
41634165
createHTML: goog.identity_,
41644166
createScript: goog.identity_,
41654167
createScriptURL: goog.identity_,
@@ -4175,10 +4177,10 @@ goog.createTrustedTypesPolicy = function(name) {
41754177
// to TrustedURL. This is a best-effort attempt. If that does not succeed,
41764178
// the application fails close - TrustedURL values will simply be required
41774179
// at all relevant sinks.
4178-
if (typeof TrustedURL !== 'undefined' && TrustedTypes.getPolicyNames &&
4179-
TrustedTypes.getPolicyNames().indexOf('default') === -1) {
4180+
if (goog.global.TrustedURL && policyFactory.getPolicyNames &&
4181+
policyFactory.getPolicyNames().indexOf('default') === -1) {
41804182
try {
4181-
TrustedTypes.createPolicy('default', {createURL: goog.identity_}, true);
4183+
policyFactory.createPolicy('default', {createURL: goog.identity_}, true);
41824184
} catch (e) {
41834185
goog.logToConsole_(e.message);
41844186
}

0 commit comments

Comments
 (0)