/** * Returns the TrustedResourceUrl built so far. */ @CheckReturnValue public TrustedResourceUrl build() { return TrustedResourceUrls.create(url.toString()); } }
/** * Creates a TrustedResourceUrl from the given compile-time constant string {@code url}. * * <p>No runtime validation or sanitization is performed on {@code url}; being under application * control, it is simply assumed to comply with the TrustedResourceUrl contract. */ public static TrustedResourceUrl fromConstant(@CompileTimeConstant final String url) { return create(url); }
/** * Deserializes a TrustedResourceUrlProto into a TrustedResourceUrl instance. * * <p>Protocol-message forms are intended to be opaque. The fields of the protocol message should * be considered encapsulated and are not intended for direct inspection or manipulation. Protocol * message forms of this type should be produced by {@link #toProto(TrustedResourceUrl)} or its * equivalent in other implementation languages. * * <p><b>Important:</b> It is unsafe to invoke this method on a protocol message that has been * received from an entity outside the application's trust domain. Data coming from the browser * is outside the application's trust domain. */ public static TrustedResourceUrl fromProto(TrustedResourceUrlProto proto) { return create(proto.getPrivateDoNotAccessOrElseTrustedResourceUrlWrappedValue()); }
/** * Creates a {@link TrustedResourceUrl} from the value of an environment variable. In a server * setting, environment variables are part of the application's deployment configuration and are * hence considered application-controlled. If the variable is not defined returns null. * * * <p>No runtime validation or sanitization is performed on the value of the environment variable; * being under application control, it is simply assumed to comply with the TrustedResourceUrl * contract. * * @throws SecurityException if a security manager exists and its checkPermission method doesn't * allow access to the environment variable name */ @GwtIncompatible("System.getEnv") @Nullable public static TrustedResourceUrl fromEnvironmentVariable( @CompileTimeConstant final String variableName) { String var = System.getenv(variableName); if (var == null) { return null; } return create(var); }