public class

UrlAllowList

extends Object
java.lang.Object
   ↳ com.urbanairship.js.UrlAllowList

Class Overview

Defines a set of URL patterns to match a URL.

Summary

Nested Classes
interface UrlAllowList.OnUrlAllowListCallback Interface that defines a callback that can be used to reject or allow a URL. 
@interface UrlAllowList.Scope  
Constants
int SCOPE_ALL UrlAllowList entry applies to both url and JS interface.
int SCOPE_JAVASCRIPT_INTERFACE UrlAllowList entry applies to JS interface.
int SCOPE_OPEN_URL UrlAllowList entry applies to any url handling.
Public Constructors
UrlAllowList()
Public Methods
boolean addEntry(String pattern, int scope)
Adds an entry to the URL allow list for URL matching.
boolean addEntry(String pattern)
Adds an entry to the URL allow list for URL matching.
boolean isAllowed(String url)
Checks if a given URL is allowed or not with scope SCOPE_ALL.
boolean isAllowed(String url, int scope)
Checks if a given URL is allowed or not.
void setUrlAllowListCallback(UrlAllowList.OnUrlAllowListCallback urlAllowListCallback)
Sets the urlAllowList callback.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int SCOPE_ALL

UrlAllowList entry applies to both url and JS interface.

Constant Value: 3 (0x00000003)

public static final int SCOPE_JAVASCRIPT_INTERFACE

UrlAllowList entry applies to JS interface.

Constant Value: 1 (0x00000001)

public static final int SCOPE_OPEN_URL

UrlAllowList entry applies to any url handling.

Constant Value: 2 (0x00000002)

Public Constructors

public UrlAllowList ()

Public Methods

public boolean addEntry (String pattern, int scope)

Adds an entry to the URL allow list for URL matching. Patterns must be defined with the following syntax:

 <pattern> := '*' | <scheme>'://'<host>/<path> | <scheme>'://'<host> | <scheme>':/'<path> | <scheme>':///'<path>
 <scheme> := <any char combination, '*' are treated as wild cards>
 <host> := '*' | '*.'<any char combination except '/' and '*'> | <any char combination except '/' and '*'>
 <path> := <any char combination, '*' are treated as wild cards>
 

 Examples:

  '*' will match any URI
  '*://www.urbanairship.com' will match any schema from www.urbanairship.com
  'https://*.urbanairship.com' will match any https URL from urbanairship.com and any of its subdomains.
  'file:///android_asset/*' will match any file in the android assets directory.
  'http://urbanairship.com/foo/*.html' will match any url from urbanairship.com that ends in .html
  and the path starts with /foo/.

 

Note: International domains should add entries for both the ASCII and the unicode versions of the domain.

Parameters
pattern The URL pattern to add as a URL allow list matcher.
scope The scope that entry applies to.
Returns
  • true if the pattern was added successfully, false if the pattern was unable to be added because it was either null or did not match the url-pattern syntax.

public boolean addEntry (String pattern)

Adds an entry to the URL allow list for URL matching. Patterns must be defined with the following syntax:

 <pattern> := '*' | <scheme>'://'<host>/<path> | <scheme>'://'<host> | <scheme>':/'<path> | <scheme>':///'<path>  | <scheme>':'<path>
 <scheme> := <any char combination ' ', '*' are treated as wild cards>
 <host> := '*' | '*.'<any char combination except ' ', '/' and '*'> | <any char combination except ' ', '/', and '*'>
 <path> := <any char combination except ' ', '*' are treated as wild cards>
 

 Examples:

  '*' will match any URI
  '*://www.urbanairship.com' will match any schema from www.urbanairship.com
  'https://*.urbanairship.com' will match any https URL from urbanairship.com and any of its subdomains.
  'file:///android_asset/*' will match any file in the android assets directory.
  'http://urbanairship.com/foo/*.html' will match any url from urbanairship.com that ends in .html
  and the path starts with /foo/.

 

Note: International domains should add entries for both the ASCII and the unicode versions of the domain.

Parameters
pattern The URL pattern to add as a URL allow list matcher.
Returns
  • true if the pattern was added successfully, false if the pattern was unable to be added because it was either null or did not match the url-pattern syntax.

public boolean isAllowed (String url)

Checks if a given URL is allowed or not with scope SCOPE_ALL.

Parameters
url The URL.
Returns
  • true If the URL matches any entries in the URL allow list.

public boolean isAllowed (String url, int scope)

Checks if a given URL is allowed or not.

Parameters
url The URL.
scope The scope.
Returns
  • true If the URL matches any entries in the URL allow list.

public void setUrlAllowListCallback (UrlAllowList.OnUrlAllowListCallback urlAllowListCallback)

Sets the urlAllowList callback.

Parameters
urlAllowListCallback The urlAllowList callback.