@ngdoc method
@name $sceDelegate#getTrusted

@description
Given an object and a security context in which to assign it, returns a value that's safe to
use in this context, which was represented by the parameter. To do so, this function either
unwraps the safe type it has been given (for instance, a {@link ng.$sceDelegate#trustAs
`$sceDelegate.trustAs`} result), or it might try to sanitize the value given, depending on
the context and sanitizer availablility.

The contexts that can be sanitized are $sce.MEDIA_URL, $sce.URL and $sce.HTML. The first two are available
by default, and the third one relies on the `$sanitize` service (which may be loaded through
the `ngSanitize` module). Furthermore, for $sce.RESOURCE_URL context, a plain string may be
accepted if the resource url policy defined by {@link ng.$sceDelegateProvider#resourceUrlWhitelist
`$sceDelegateProvider.resourceUrlWhitelist`} and {@link ng.$sceDelegateProvider#resourceUrlBlacklist
`$sceDelegateProvider.resourceUrlBlacklist`} accepts that resource.

This function will throw if the safe type isn't appropriate for this context, or if the
value given cannot be accepted in the context (which might be caused by sanitization not
being available, or the value not being recognized as safe).

<div class="alert alert-danger">
Disabling auto-escaping is extremely dangerous, it usually creates a Cross Site Scripting
(XSS) vulnerability in your application.
</div>

@param {string} type The context in which this value is to be used (such as `$sce.HTML`).
@param {*} maybeTrusted The result of a prior {@link ng.$sceDelegate#trustAs
`$sceDelegate.trustAs`} call, or anything else (which will not be considered trusted.)
@return {*} A version of the value that's safe to use in the given context, or throws an
exception if this is impossible.
function getTrusted(type, maybeTrusted) {
      if (maybeTrusted === null || isUndefined(maybeTrusted) || maybeTrusted === '') {
        return maybeTrusted;
      }
      var constructor = (byType.hasOwnProperty(type) ? byType[type] : null);
      // If maybeTrusted is a trusted class instance or subclass instance, then unwrap and return
      // as-is.
      if (constructor && maybeTrusted instanceof constructor) {
        return maybeTrusted.$$unwrapTrustedValue();
      }

      // If maybeTrusted is a trusted class instance but not of the correct trusted type
      // then unwrap it and allow it to pass through to the rest of the checks
      if (isFunction(maybeTrusted.$$unwrapTrustedValue)) {
        maybeTrusted = maybeTrusted.$$unwrapTrustedValue();
      }

      // If we get here, then we will either sanitize the value or throw an exception.
      if (type === SCE_CONTEXTS.MEDIA_URL || type === SCE_CONTEXTS.URL) {
        // we attempt to sanitize non-resource URLs
        return $$sanitizeUri(maybeTrusted.toString(), type === SCE_CONTEXTS.MEDIA_URL);
      } else if (type === SCE_CONTEXTS.RESOURCE_URL) {
        if (isResourceUrlAllowedByPolicy(maybeTrusted)) {
          return maybeTrusted;
        } else {
          throw $sceMinErr('insecurl',
              'Blocked loading resource from url not allowed by $sceDelegate policy.  URL: {0}',
              maybeTrusted.toString());
        }
      } else if (type === SCE_CONTEXTS.HTML) {
        // htmlSanitizer throws its own error when no sanitizer is available.
        return htmlSanitizer(maybeTrusted);
      }
      // Default error when the $sce service has no way to make the input safe.
      throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.');
    }