* @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 *
()
| 20746 | */ |
| 20747 | |
| 20748 | function $SceProvider() { |
| 20749 | var enabled = true; |
| 20750 | |
| 20751 | /** |
| 20752 | * @ngdoc method |
| 20753 | * @name $sceProvider#enabled |
| 20754 | * @kind function |
| 20755 | * |
| 20756 | * @param {boolean=} value If provided, then enables/disables SCE application-wide. |
| 20757 | * @return {boolean} True if SCE is enabled, false otherwise. |
| 20758 | * |
| 20759 | * @description |
| 20760 | * Enables/disables SCE and returns the current value. |
| 20761 | */ |
| 20762 | this.enabled = function(value) { |
| 20763 | if (arguments.length) { |
| 20764 | enabled = !!value; |
| 20765 | } |
| 20766 | return enabled; |
| 20767 | }; |
| 20768 | |
| 20769 | |
| 20770 | /* Design notes on the default implementation for SCE. |
| 20771 | * |
| 20772 | * The API contract for the SCE delegate |
| 20773 | * ------------------------------------- |
| 20774 | * The SCE delegate object must provide the following 3 methods: |
| 20775 | * |
| 20776 | * - trustAs(contextEnum, value) |
| 20777 | * This method is used to tell the SCE service that the provided value is OK to use in the |
| 20778 | * contexts specified by contextEnum. It must return an object that will be accepted by |
| 20779 | * getTrusted() for a compatible contextEnum and return this value. |
| 20780 | * |
| 20781 | * - valueOf(value) |
| 20782 | * For values that were not produced by trustAs(), return them as is. For values that were |
| 20783 | * produced by trustAs(), return the corresponding input value to trustAs. Basically, if |
| 20784 | * trustAs is wrapping the given values into some type, this operation unwraps it when given |
| 20785 | * such a value. |
| 20786 | * |
| 20787 | * - getTrusted(contextEnum, value) |
| 20788 | * This function should return the value that is safe to use in the context specified by |
| 20789 | * contextEnum or throw and exception otherwise. |
| 20790 | * |
| 20791 | * NOTE: This contract deliberately does NOT state that values returned by trustAs() must be |
| 20792 | * opaque or wrapped in some holder object. That happens to be an implementation detail. For |
| 20793 | * instance, an implementation could maintain a registry of all trusted objects by context. In |
| 20794 | * such a case, trustAs() would return the same object that was passed in. getTrusted() would |
| 20795 | * return the same object passed in if it was found in the registry under a compatible context or |
| 20796 | * throw an exception otherwise. An implementation might only wrap values some of the time based |
| 20797 | * on some criteria. getTrusted() might return a value and not throw an exception for special |
| 20798 | * constants or objects even if not wrapped. All such implementations fulfill this contract. |
| 20799 | * |
| 20800 | * |
| 20801 | * A note on the inheritance model for SCE contexts |
| 20802 | * ------------------------------------------------ |
| 20803 | * I've used inheritance and made RESOURCE_URL wrapped types a subtype of URL wrapped types. This |
| 20804 | * is purely an implementation details. |
| 20805 | * |
nothing calls this directly
no test coverage detected