public class

Whitelist

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

Class Overview

Defines a set of URL patterns to match a URL.

Summary

Nested Classes
interface Whitelist.OnWhitelistCallback Interface that defines a callback that can be used to reject whitelisting of a URL. 
@interface Whitelist.Scope  
Constants
int SCOPE_ALL Whitelist entry applies to both url and JS interface.
int SCOPE_JAVASCRIPT_INTERFACE Whitelist entry applies to JS interface.
int SCOPE_OPEN_URL Whitelist entry applies to any url handling.
Public Constructors
Whitelist()
Public Methods
boolean addEntry(String pattern, int scope)
Adds an entry to the whitelist for URL matching.
boolean addEntry(String pattern)
Adds an entry to the whitelist for URL matching.
boolean isWhitelisted(String url, int scope)
Checks if a given URL is whitelisted or not.
boolean isWhitelisted(String url)
Checks if a given URL is whitelisted or not with scope SCOPE_ALL.
void setOpenUrlWhitelistingEnabled(boolean isOpenUrlWhitelistingEnabled)
Enables/disbales SCOPE_OPEN_URL checking.
void setWhitelistCallback(Whitelist.OnWhitelistCallback whitelistCallback)
Sets the whitelist callback.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int SCOPE_ALL

Whitelist entry applies to both url and JS interface.

Constant Value: 3 (0x00000003)

public static final int SCOPE_JAVASCRIPT_INTERFACE

Whitelist entry applies to JS interface.

Constant Value: 1 (0x00000001)

public static final int SCOPE_OPEN_URL

Whitelist entry applies to any url handling.

Constant Value: 2 (0x00000002)

Public Constructors

public Whitelist ()

Public Methods

public boolean addEntry (String pattern, int scope)

Adds an entry to the whitelist 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 whitelist 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 whitelist 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 whitelist 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 isWhitelisted (String url, int scope)

Checks if a given URL is whitelisted or not.

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

public boolean isWhitelisted (String url)

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

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

public void setOpenUrlWhitelistingEnabled (boolean isOpenUrlWhitelistingEnabled)

Enables/disbales SCOPE_OPEN_URL checking. If disabled, all URL checks for the open url scope will be allowed.

Parameters
isOpenUrlWhitelistingEnabled true to enable whitelist checking for SCOPE_OPEN_URL, otherwise false.

public void setWhitelistCallback (Whitelist.OnWhitelistCallback whitelistCallback)

Sets the whitelist callback.

Parameters
whitelistCallback The whitelist callback.