* @ngdoc service * @name $sce * @kind function * * @description * * `$sce` is a service that provides Strict Contextual Escaping services to AngularJS. * * ## Strict Contextual Escaping * * Strict Contextual Escaping (SCE) is a mode in which AngularJS constrains bindings to only render *
()
| 20101 | */ |
| 20102 | |
| 20103 | function $SceProvider() { |
| 20104 | var enabled = true; |
| 20105 | |
| 20106 | /** |
| 20107 | * @ngdoc method |
| 20108 | * @name $sceProvider#enabled |
| 20109 | * @kind function |
| 20110 | * |
| 20111 | * @param {boolean=} value If provided, then enables/disables SCE application-wide. |
| 20112 | * @return {boolean} True if SCE is enabled, false otherwise. |
| 20113 | * |
| 20114 | * @description |
| 20115 | * Enables/disables SCE and returns the current value. |
| 20116 | */ |
| 20117 | this.enabled = function(value) { |
| 20118 | if (arguments.length) { |
| 20119 | enabled = !!value; |
| 20120 | } |
| 20121 | return enabled; |
| 20122 | }; |
| 20123 | |
| 20124 | |
| 20125 | /* Design notes on the default implementation for SCE. |
| 20126 | * |
| 20127 | * The API contract for the SCE delegate |
| 20128 | * ------------------------------------- |
| 20129 | * The SCE delegate object must provide the following 3 methods: |
| 20130 | * |
| 20131 | * - trustAs(contextEnum, value) |
| 20132 | * This method is used to tell the SCE service that the provided value is OK to use in the |
| 20133 | * contexts specified by contextEnum. It must return an object that will be accepted by |
| 20134 | * getTrusted() for a compatible contextEnum and return this value. |
| 20135 | * |
| 20136 | * - valueOf(value) |
| 20137 | * For values that were not produced by trustAs(), return them as is. For values that were |
| 20138 | * produced by trustAs(), return the corresponding input value to trustAs. Basically, if |
| 20139 | * trustAs is wrapping the given values into some type, this operation unwraps it when given |
| 20140 | * such a value. |
| 20141 | * |
| 20142 | * - getTrusted(contextEnum, value) |
| 20143 | * This function should return the value that is safe to use in the context specified by |
| 20144 | * contextEnum or throw and exception otherwise. |
| 20145 | * |
| 20146 | * NOTE: This contract deliberately does NOT state that values returned by trustAs() must be |
| 20147 | * opaque or wrapped in some holder object. That happens to be an implementation detail. For |
| 20148 | * instance, an implementation could maintain a registry of all trusted objects by context. In |
| 20149 | * such a case, trustAs() would return the same object that was passed in. getTrusted() would |
| 20150 | * return the same object passed in if it was found in the registry under a compatible context or |
| 20151 | * throw an exception otherwise. An implementation might only wrap values some of the time based |
| 20152 | * on some criteria. getTrusted() might return a value and not throw an exception for special |
| 20153 | * constants or objects even if not wrapped. All such implementations fulfill this contract. |
| 20154 | * |
| 20155 | * |
| 20156 | * A note on the inheritance model for SCE contexts |
| 20157 | * ------------------------------------------------ |
| 20158 | * I've used inheritance and made RESOURCE_URL wrapped types a subtype of URL wrapped types. This |
| 20159 | * is purely an implementation details. |
| 20160 | * |
nothing calls this directly
no test coverage detected