Java Code Examples for org.apache.cordova.Config#isUrlWhiteListed()

The following examples show how to use org.apache.cordova.Config#isUrlWhiteListed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CordovaWebView.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Load URL in webview.
 *
 * @param url
 */
void loadUrlNow(String url) {
    if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) {
        LOG.d(TAG, ">>> loadUrlNow()");
    }
    if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url)) {
        super.loadUrl(url);
    }
}
 
Example 2
Source File: CordovaWebView.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Load the specified URL in the Cordova webview or a new browser instance.
 *
 * NOTE: If openExternal is false, only URLs listed in whitelist can be loaded.
 *
 * @param url           The url to load.
 * @param openExternal  Load url in browser instead of Cordova webview.
 * @param clearHistory  Clear the history stack, so new page becomes top of history
 * @param params        Parameters for new app
 */
public void showWebPage(String url, boolean openExternal, boolean clearHistory, HashMap<String, Object> params) {
    LOG.d(TAG, "showWebPage(%s, %b, %b, HashMap", url, openExternal, clearHistory);

    // If clearing history
    if (clearHistory) {
        this.clearHistory();
    }

    // If loading into our webview
    if (!openExternal) {

        // Make sure url is in whitelist
        if (url.startsWith("file://") || Config.isUrlWhiteListed(url)) {
            // TODO: What about params?
            // Load new URL
            this.loadUrl(url);
            return;
        }
        // Load in default viewer if not
        LOG.w(TAG, "showWebPage: Cannot load URL into webview since it is not in white list.  Loading into browser instead. (URL=" + url + ")");
    }
    try {
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, resourceApi.getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        cordova.getActivity().startActivity(intent);
    } catch (android.content.ActivityNotFoundException e) {
        LOG.e(TAG, "Error loading url " + url, e);
    }
}
 
Example 3
Source File: CordovaWebView.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
/**
 * Load URL in webview.
 *
 * @param url
 */
void loadUrlNow(String url) {
    if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) {
        LOG.d(TAG, ">>> loadUrlNow()");
    }
    if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url)) {
        super.loadUrl(url);
    }
}
 
Example 4
Source File: CordovaWebView.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
/**
 * Load the specified URL in the Cordova webview or a new browser instance.
 *
 * NOTE: If openExternal is false, only URLs listed in whitelist can be loaded.
 *
 * @param url           The url to load.
 * @param openExternal  Load url in browser instead of Cordova webview.
 * @param clearHistory  Clear the history stack, so new page becomes top of history
 * @param params        Parameters for new app
 */
public void showWebPage(String url, boolean openExternal, boolean clearHistory, HashMap<String, Object> params) {
    LOG.d(TAG, "showWebPage(%s, %b, %b, HashMap", url, openExternal, clearHistory);

    // If clearing history
    if (clearHistory) {
        this.clearHistory();
    }

    // If loading into our webview
    if (!openExternal) {

        // Make sure url is in whitelist
        if (url.startsWith("file://") || Config.isUrlWhiteListed(url)) {
            // TODO: What about params?
            // Load new URL
            this.loadUrl(url);
            return;
        }
        // Load in default viewer if not
        LOG.w(TAG, "showWebPage: Cannot load URL into webview since it is not in white list.  Loading into browser instead. (URL=" + url + ")");
    }
    try {
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, resourceApi.getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        cordova.getActivity().startActivity(intent);
    } catch (android.content.ActivityNotFoundException e) {
        LOG.e(TAG, "Error loading url " + url, e);
    }
}
 
Example 5
Source File: CordovaWebView.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
/**
 * Load URL in webview.
 *
 * @param url
 */
void loadUrlNow(String url) {
    if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) {
        LOG.d(TAG, ">>> loadUrlNow()");
    }
    if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url)) {
        super.loadUrl(url);
    }
}
 
Example 6
Source File: CordovaWebView.java    From wildfly-samples with MIT License 5 votes vote down vote up
/**
 * Load URL in webview.
 *
 * @param url
 */
void loadUrlNow(String url) {
    if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) {
        LOG.d(TAG, ">>> loadUrlNow()");
    }
    if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url)) {
        super.loadUrl(url);
    }
}
 
Example 7
Source File: CordovaWebView.java    From wildfly-samples with MIT License 5 votes vote down vote up
/**
 * Load the specified URL in the Cordova webview or a new browser instance.
 *
 * NOTE: If openExternal is false, only URLs listed in whitelist can be loaded.
 *
 * @param url           The url to load.
 * @param openExternal  Load url in browser instead of Cordova webview.
 * @param clearHistory  Clear the history stack, so new page becomes top of history
 * @param params        Parameters for new app
 */
public void showWebPage(String url, boolean openExternal, boolean clearHistory, HashMap<String, Object> params) {
    LOG.d(TAG, "showWebPage(%s, %b, %b, HashMap", url, openExternal, clearHistory);

    // If clearing history
    if (clearHistory) {
        this.clearHistory();
    }

    // If loading into our webview
    if (!openExternal) {

        // Make sure url is in whitelist
        if (url.startsWith("file://") || Config.isUrlWhiteListed(url)) {
            // TODO: What about params?
            // Load new URL
            this.loadUrl(url);
            return;
        }
        // Load in default viewer if not
        LOG.w(TAG, "showWebPage: Cannot load URL into webview since it is not in white list.  Loading into browser instead. (URL=" + url + ")");
    }
    try {
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, resourceApi.getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        cordova.getActivity().startActivity(intent);
    } catch (android.content.ActivityNotFoundException e) {
        LOG.e(TAG, "Error loading url " + url, e);
    }
}
 
Example 8
Source File: CordovaWebView.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
/**
 * Load URL in webview.
 *
 * @param url
 */
void loadUrlNow(String url) {
    if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) {
        LOG.d(TAG, ">>> loadUrlNow()");
    }
    if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url)) {
        super.loadUrl(url);
    }
}