* @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 *
()
| 20681 | */ |
| 20682 | |
| 20683 | function $SceProvider() { |
| 20684 | var enabled = true; |
| 20685 | |
| 20686 | /** |
| 20687 | * @ngdoc method |
| 20688 | * @name $sceProvider#enabled |
| 20689 | * @kind function |
| 20690 | * |
| 20691 | * @param {boolean=} value If provided, then enables/disables SCE application-wide. |
| 20692 | * @return {boolean} True if SCE is enabled, false otherwise. |
| 20693 | * |
| 20694 | * @description |
| 20695 | * Enables/disables SCE and returns the current value. |
| 20696 | */ |
| 20697 | this.enabled = function(value) { |
| 20698 | if (arguments.length) { |
| 20699 | enabled = !!value; |
| 20700 | } |
| 20701 | return enabled; |
| 20702 | }; |
| 20703 | |
| 20704 | |
| 20705 | /* Design notes on the default implementation for SCE. |
| 20706 | * |
| 20707 | * The API contract for the SCE delegate |
| 20708 | * ------------------------------------- |
| 20709 | * The SCE delegate object must provide the following 3 methods: |
| 20710 | * |
| 20711 | * - trustAs(contextEnum, value) |
| 20712 | * This method is used to tell the SCE service that the provided value is OK to use in the |
| 20713 | * contexts specified by contextEnum. It must return an object that will be accepted by |
| 20714 | * getTrusted() for a compatible contextEnum and return this value. |
| 20715 | * |
| 20716 | * - valueOf(value) |
| 20717 | * For values that were not produced by trustAs(), return them as is. For values that were |
| 20718 | * produced by trustAs(), return the corresponding input value to trustAs. Basically, if |
| 20719 | * trustAs is wrapping the given values into some type, this operation unwraps it when given |
| 20720 | * such a value. |
| 20721 | * |
| 20722 | * - getTrusted(contextEnum, value) |
| 20723 | * This function should return the value that is safe to use in the context specified by |
| 20724 | * contextEnum or throw and exception otherwise. |
| 20725 | * |
| 20726 | * NOTE: This contract deliberately does NOT state that values returned by trustAs() must be |
| 20727 | * opaque or wrapped in some holder object. That happens to be an implementation detail. For |
| 20728 | * instance, an implementation could maintain a registry of all trusted objects by context. In |
| 20729 | * such a case, trustAs() would return the same object that was passed in. getTrusted() would |
| 20730 | * return the same object passed in if it was found in the registry under a compatible context or |
| 20731 | * throw an exception otherwise. An implementation might only wrap values some of the time based |
| 20732 | * on some criteria. getTrusted() might return a value and not throw an exception for special |
| 20733 | * constants or objects even if not wrapped. All such implementations fulfill this contract. |
| 20734 | * |
| 20735 | * |
| 20736 | * A note on the inheritance model for SCE contexts |
| 20737 | * ------------------------------------------------ |
| 20738 | * I've used inheritance and made RESOURCE_URL wrapped types a subtype of URL wrapped types. This |
| 20739 | * is purely an implementation details. |
| 20740 | * |
nothing calls this directly
no test coverage detected