@@ -131,12 +131,6 @@ function $SceDelegateProvider() {
131
131
return resourceUrlBlacklist ;
132
132
} ;
133
133
134
- // Helper functions for matching resource urls by policy.
135
- function isCompatibleProtocol ( documentProtocol , resourceProtocol ) {
136
- return ( ( documentProtocol === resourceProtocol ) ||
137
- ( documentProtocol === "http:" && resourceProtocol === "https:" ) ) ;
138
- }
139
-
140
134
this . $get = [ '$log' , '$document' , '$injector' , '$$urlUtils' , function (
141
135
$log , $document , $injector , $$urlUtils ) {
142
136
@@ -179,32 +173,38 @@ function $SceDelegateProvider() {
179
173
return allowed ;
180
174
}
181
175
182
- function generateHolderType ( base ) {
176
+ function generateHolderType ( base , useCache ) {
177
+ var cacheInstances = { } ;
183
178
var holderType = function TrustedValueHolderType ( trustedValue ) {
179
+ if ( cacheInstances [ trustedValue ] && useCache ) {
180
+ return cacheInstances [ trustedValue ] ;
181
+ }
182
+
183
+ cacheInstances [ trustedValue ] = this ;
184
184
this . $$unwrapTrustedValue = function ( ) {
185
185
return trustedValue ;
186
186
} ;
187
187
} ;
188
188
if ( base ) {
189
- holderType . prototype = new base ( ) ;
189
+ holderType . prototype = new base ( '' ) ;
190
190
}
191
191
holderType . prototype . valueOf = function sceValueOf ( ) {
192
192
return this . $$unwrapTrustedValue ( ) ;
193
- }
193
+ } ;
194
194
holderType . prototype . toString = function sceToString ( ) {
195
195
return this . $$unwrapTrustedValue ( ) . toString ( ) ;
196
- }
196
+ } ;
197
197
return holderType ;
198
198
}
199
199
200
200
var trustedValueHolderBase = generateHolderType ( ) ,
201
201
byType = { } ;
202
202
203
- byType [ SCE_CONTEXTS . HTML ] = generateHolderType ( trustedValueHolderBase ) ;
204
- byType [ SCE_CONTEXTS . CSS ] = generateHolderType ( trustedValueHolderBase ) ;
205
- byType [ SCE_CONTEXTS . URL ] = generateHolderType ( trustedValueHolderBase ) ;
206
- byType [ SCE_CONTEXTS . JS ] = generateHolderType ( trustedValueHolderBase ) ;
207
- byType [ SCE_CONTEXTS . RESOURCE_URL ] = generateHolderType ( byType [ SCE_CONTEXTS . URL ] ) ;
203
+ byType [ SCE_CONTEXTS . HTML ] = generateHolderType ( trustedValueHolderBase , true ) ;
204
+ byType [ SCE_CONTEXTS . CSS ] = generateHolderType ( trustedValueHolderBase , true ) ;
205
+ byType [ SCE_CONTEXTS . URL ] = generateHolderType ( trustedValueHolderBase , true ) ;
206
+ byType [ SCE_CONTEXTS . JS ] = generateHolderType ( trustedValueHolderBase , true ) ;
207
+ byType [ SCE_CONTEXTS . RESOURCE_URL ] = generateHolderType ( byType [ SCE_CONTEXTS . URL ] , true ) ;
208
208
209
209
/**
210
210
* @ngdoc method
@@ -341,7 +341,7 @@ function $SceDelegateProvider() {
341
341
* # Strict Contextual Escaping
342
342
*
343
343
* Strict Contextual Escaping (SCE) is a mode in which AngularJS requires bindings in certain
344
- * contexts to result in a value that is marked as safe to use for that context One example of such
344
+ * contexts to result in a value that is marked as safe to use for that context. One example of such
345
345
* a context is binding arbitrary html controlled by the user via `ng-bind-html`. We refer to these
346
346
* contexts as privileged or SCE contexts.
347
347
*
@@ -419,7 +419,7 @@ function $SceDelegateProvider() {
419
419
* By default, Angular only loads templates from the same domain and protocol as the application
420
420
* document. This is done by calling {@link ng.$sce#getTrustedResourceUrl
421
421
* $sce.getTrustedResourceUrl} on the template URL. To load templates from other domains and/or
422
- * protocols, you may either either {@link ng.$sceDelegateProvider#resourceUrlWhitelist whitelist
422
+ * protocols, you may either {@link ng.$sceDelegateProvider#resourceUrlWhitelist whitelist
423
423
* them} or {@link ng.$sce#trustAsResourceUrl wrap it} into a trusted value.
424
424
*
425
425
* *Please note*:
@@ -935,13 +935,13 @@ function $SceProvider() {
935
935
var lName = lowercase ( name ) ;
936
936
sce [ camelCase ( "parse_as_" + lName ) ] = function ( expr ) {
937
937
return parse ( enumValue , expr ) ;
938
- }
938
+ } ;
939
939
sce [ camelCase ( "get_trusted_" + lName ) ] = function ( value ) {
940
940
return getTrusted ( enumValue , value ) ;
941
- }
941
+ } ;
942
942
sce [ camelCase ( "trust_as_" + lName ) ] = function ( value ) {
943
943
return trustAs ( enumValue , value ) ;
944
- }
944
+ } ;
945
945
} ) ;
946
946
947
947
return sce ;
0 commit comments