com.amazon.android.webkit.AmazonWebView Java Examples

The following examples show how to use com.amazon.android.webkit.AmazonWebView. 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: InAppBrowser.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_ERROR_EVENT);
        obj.put("url", failingUrl);
        obj.put("code", errorCode);
        obj.put("message", description);
    
        sendUpdate(obj, true, PluginResult.Status.ERROR);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
	
}
 
Example #2
Source File: InAppBrowser.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_ERROR_EVENT);
        obj.put("url", failingUrl);
        obj.put("code", errorCode);
        obj.put("message", description);
    
        sendUpdate(obj, true, PluginResult.Status.ERROR);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
	
}
 
Example #3
Source File: InAppBrowser.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_ERROR_EVENT);
        obj.put("url", failingUrl);
        obj.put("code", errorCode);
        obj.put("message", description);
    
        sendUpdate(obj, true, PluginResult.Status.ERROR);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
	
}
 
Example #4
Source File: CordovaWebViewClient.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
/**
 * Notify the host application that an SSL error occurred while loading a resource.
 * The host application must call either handler.cancel() or handler.proceed().
 * Note that the decision may be retained for use in response to future SSL errors.
 * The default behavior is to cancel the load.
 *
 * @param view          The AmazonWebView that is initiating the callback.
 * @param handler       An AmazonSslErrorHandler object that will handle the user's response.
 * @param error         The SSL error object.
 */
@TargetApi(8)
@Override
public void onReceivedSslError(AmazonWebView view, AmazonSslErrorHandler handler, SslError error) {

    final String packageName = this.cordova.getActivity().getPackageName();
    final PackageManager pm = this.cordova.getActivity().getPackageManager();

    ApplicationInfo appInfo;
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            // debug = true
            handler.proceed();
            return;
        } else {
            // debug = false
            super.onReceivedSslError(view, handler, error);
        }
    } catch (NameNotFoundException e) {
        // When it doubt, lock it out!
        super.onReceivedSslError(view, handler, error);
    }
}
 
Example #5
Source File: CordovaWebViewClient.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
/**
 * Notify the host application that a page has started loading.
 * This method is called once for each main frame load so a page with iframes or framesets will call onPageStarted
 * one time for the main frame. This also means that onPageStarted will not be called when the contents of an
 * embedded frame changes, i.e. clicking a link whose target is an iframe.
 *
 * @param view          The webview initiating the callback.
 * @param url           The url of the page.
 */
@Override
public void onPageStarted(AmazonWebView view, String url, Bitmap favicon) {
    super.onPageStarted(view, url, favicon);
    isCurrentlyLoading = true;
    LOG.d(TAG, "onPageStarted(" + url + ")");
    // Flush stale messages.
    this.appView.bridge.reset(url);

    // Broadcast message that page has loaded
    this.appView.postMessage("onPageStarted", url);

    // Notify all plugins of the navigation, so they can clean up if necessary.
    if (this.appView.pluginManager != null) {
        this.appView.pluginManager.onReset();
    }
}
 
Example #6
Source File: Purity.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
public boolean checkRenderView(AmazonWebView view)
{
    if(state == null)
    {
        setBitmap(view);
        return false;
    }
    else
    {
        Picture p = view.capturePicture();
        Bitmap newState = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
        boolean result = newState.equals(state);
        newState.recycle();
        return result;
    }
}
 
Example #7
Source File: InAppBrowser.java    From ultimate-cordova-webview-app with MIT License 5 votes vote down vote up
public void onPageFinished(AmazonWebView view, String url) {
    super.onPageFinished(view, url);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);
    
        sendUpdate(obj, true);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #8
Source File: InAppBrowser.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
public void onPageFinished(AmazonWebView view, String url) {
    super.onPageFinished(view, url);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);
    
        sendUpdate(obj, true);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #9
Source File: InAppBrowser.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
public void onPageFinished(AmazonWebView view, String url) {
    super.onPageFinished(view, url);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);
    
        sendUpdate(obj, true);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #10
Source File: InAppBrowser.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
public void onPageFinished(AmazonWebView view, String url) {
    super.onPageFinished(view, url);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);
    
        sendUpdate(obj, true);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #11
Source File: IceCreamCordovaWebViewClient.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonWebResourceResponse shouldInterceptRequest(AmazonWebView view, String url) {
    try {
        // Check the against the whitelist and lock out access to the WebView directory
        // Changing this will cause problems for your application
        if (isUrlHarmful(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new AmazonWebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = appView.getResourceApi();
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept AmazonWebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);
        
        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new AmazonWebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new AmazonWebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
Example #12
Source File: CordovaWebViewClient.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The AmazonWebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 */
@Override
public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) {
    // Ignore error due to stopLoading().
    if (!isCurrentlyLoading) {
        return;
    }
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);

    // Clear timeout flag
    this.appView.loadUrlTimeout++;

    // If this is a "Protocol Not Supported" error, then revert to the previous
    // page. If there was no previous page, then punt. The application's config
    // is likely incorrect (start page set to sms: or something like that)
    if (errorCode == AmazonWebViewClient.ERROR_UNSUPPORTED_SCHEME) {
        if (view.canGoBack()) {
            view.goBack();
            return;
        } else {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    }

    // Handle other errors by passing them to the webview in JS
    JSONObject data = new JSONObject();
    try {
        data.put("errorCode", errorCode);
        data.put("description", description);
        data.put("url", failingUrl);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    this.appView.postMessage("onReceivedError", data);
}
 
Example #13
Source File: CordovaWebViewClient.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
/**
 * On received http auth request.
 * The method reacts on all registered authentication tokens. There is one and only one authentication token for any host + realm combination
 *
 * @param view
 * @param handler
 * @param host
 * @param realm
 */
@Override
public void onReceivedHttpAuthRequest(AmazonWebView view, AmazonHttpAuthHandler handler, String host, String realm) {

    // Get the authentication token
    AuthenticationToken token = this.getAuthenticationToken(host, realm);
    if (token != null) {
        handler.proceed(token.getUserName(), token.getPassword());
    }
    else {
        // Handle 401 like we'd normally do!
        super.onReceivedHttpAuthRequest(view, handler, host, realm);
    }
}
 
Example #14
Source File: InAppBrowser.java    From reader with MIT License 5 votes vote down vote up
public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_ERROR_EVENT);
        obj.put("url", failingUrl);
        obj.put("code", errorCode);
        obj.put("message", description);
    
        sendUpdate(obj, true, PluginResult.Status.ERROR);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #15
Source File: InAppBrowser.java    From reader with MIT License 5 votes vote down vote up
public void onPageFinished(AmazonWebView view, String url) {
    super.onPageFinished(view, url);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);
    
        sendUpdate(obj, true);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #16
Source File: InAppBrowser.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
public void onPageFinished(AmazonWebView view, String url) {
    super.onPageFinished(view, url);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);
    
        sendUpdate(obj, true);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #17
Source File: InAppBrowser.java    From ultimate-cordova-webview-app with MIT License 5 votes vote down vote up
/**
 * Closes the dialog
 */
public void closeDialog() {
    final AmazonWebView childView = this.inAppWebView;
    // The JS protects against multiple calls, so this should happen only when
    // closeDialog() is called by other native code.
    if (childView == null) {
        return;
    }
    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            childView.setWebViewClient(new AmazonWebViewClient() {
                // NB: wait for about:blank before dismissing
                public void onPageFinished(AmazonWebView view, String url) {
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                }
            });
            // NB: From SDK 19: "If you call methods on WebView from any thread
            // other than your app's UI thread, it can cause unexpected results."
            // http://developer.android.com/guide/webapps/migrating.html#Threads
            childView.loadUrl("about:blank");
        }
    });
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", EXIT_EVENT);
        sendUpdate(obj, false);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #18
Source File: InAppBrowser.java    From ultimate-cordova-webview-app with MIT License 5 votes vote down vote up
public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_ERROR_EVENT);
        obj.put("url", failingUrl);
        obj.put("code", errorCode);
        obj.put("message", description);
    
        sendUpdate(obj, true, PluginResult.Status.ERROR);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #19
Source File: InAppBrowser.java    From AvI with MIT License 5 votes vote down vote up
/**
 * Closes the dialog
 */
public void closeDialog() {
    final AmazonWebView childView = this.inAppWebView;
    // The JS protects against multiple calls, so this should happen only when
    // closeDialog() is called by other native code.
    if (childView == null) {
        return;
    }
    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            childView.setWebViewClient(new AmazonWebViewClient() {
                // NB: wait for about:blank before dismissing
                public void onPageFinished(AmazonWebView view, String url) {
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                }
            });
            // NB: From SDK 19: "If you call methods on WebView from any thread
            // other than your app's UI thread, it can cause unexpected results."
            // http://developer.android.com/guide/webapps/migrating.html#Threads
            childView.loadUrl("about:blank");
        }
    });
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", EXIT_EVENT);
        sendUpdate(obj, false);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #20
Source File: InAppBrowser.java    From AvI with MIT License 5 votes vote down vote up
public void onPageFinished(AmazonWebView view, String url) {
    super.onPageFinished(view, url);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);
    
        sendUpdate(obj, true);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #21
Source File: InAppBrowser.java    From AvI with MIT License 5 votes vote down vote up
public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_ERROR_EVENT);
        obj.put("url", failingUrl);
        obj.put("code", errorCode);
        obj.put("message", description);
    
        sendUpdate(obj, true, PluginResult.Status.ERROR);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #22
Source File: InAppBrowser.java    From reacteu-app with MIT License 5 votes vote down vote up
/**
 * Closes the dialog
 */
public void closeDialog() {
    final AmazonWebView childView = this.inAppWebView;
    // The JS protects against multiple calls, so this should happen only when
    // closeDialog() is called by other native code.
    if (childView == null) {
        return;
    }
    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            childView.setWebViewClient(new AmazonWebViewClient() {
                // NB: wait for about:blank before dismissing
                public void onPageFinished(AmazonWebView view, String url) {
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                }
            });
            // NB: From SDK 19: "If you call methods on WebView from any thread
            // other than your app's UI thread, it can cause unexpected results."
            // http://developer.android.com/guide/webapps/migrating.html#Threads
            childView.loadUrl("about:blank");
        }
    });
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", EXIT_EVENT);
        sendUpdate(obj, false);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #23
Source File: InAppBrowser.java    From reacteu-app with MIT License 5 votes vote down vote up
public void onPageFinished(AmazonWebView view, String url) {
    super.onPageFinished(view, url);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);
    
        sendUpdate(obj, true);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #24
Source File: InAppBrowser.java    From reacteu-app with MIT License 5 votes vote down vote up
public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_ERROR_EVENT);
        obj.put("url", failingUrl);
        obj.put("code", errorCode);
        obj.put("message", description);
    
        sendUpdate(obj, true, PluginResult.Status.ERROR);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #25
Source File: InAppBrowser.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the dialog
 */
public void closeDialog() {
    final AmazonWebView childView = this.inAppWebView;
    // The JS protects against multiple calls, so this should happen only when
    // closeDialog() is called by other native code.
    if (childView == null) {
        return;
    }
    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            childView.setWebViewClient(new AmazonWebViewClient() {
                // NB: wait for about:blank before dismissing
                public void onPageFinished(AmazonWebView view, String url) {
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                }
            });
            // NB: From SDK 19: "If you call methods on WebView from any thread
            // other than your app's UI thread, it can cause unexpected results."
            // http://developer.android.com/guide/webapps/migrating.html#Threads
            childView.loadUrl("about:blank");
        }
    });
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", EXIT_EVENT);
        sendUpdate(obj, false);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #26
Source File: InAppBrowser.java    From reader with MIT License 5 votes vote down vote up
/**
 * Closes the dialog
 */
public void closeDialog() {
    final AmazonWebView childView = this.inAppWebView;
    // The JS protects against multiple calls, so this should happen only when
    // closeDialog() is called by other native code.
    if (childView == null) {
        return;
    }
    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            childView.setWebViewClient(new AmazonWebViewClient() {
                // NB: wait for about:blank before dismissing
                public void onPageFinished(AmazonWebView view, String url) {
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                }
            });
            // NB: From SDK 19: "If you call methods on WebView from any thread
            // other than your app's UI thread, it can cause unexpected results."
            // http://developer.android.com/guide/webapps/migrating.html#Threads
            childView.loadUrl("about:blank");
        }
    });
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", EXIT_EVENT);
        sendUpdate(obj, false);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #27
Source File: InAppBrowser.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_ERROR_EVENT);
        obj.put("url", failingUrl);
        obj.put("code", errorCode);
        obj.put("message", description);
    
        sendUpdate(obj, true, PluginResult.Status.ERROR);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #28
Source File: InAppBrowser.java    From reader with MIT License 5 votes vote down vote up
/**
 * Closes the dialog
 */
public void closeDialog() {
    final AmazonWebView childView = this.inAppWebView;
    // The JS protects against multiple calls, so this should happen only when
    // closeDialog() is called by other native code.
    if (childView == null) {
        return;
    }
    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            childView.setWebViewClient(new AmazonWebViewClient() {
                // NB: wait for about:blank before dismissing
                public void onPageFinished(AmazonWebView view, String url) {
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                }
            });
            // NB: From SDK 19: "If you call methods on WebView from any thread
            // other than your app's UI thread, it can cause unexpected results."
            // http://developer.android.com/guide/webapps/migrating.html#Threads
            childView.loadUrl("about:blank");
        }
    });
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", EXIT_EVENT);
        sendUpdate(obj, false);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #29
Source File: InAppBrowser.java    From reader with MIT License 5 votes vote down vote up
public void onPageFinished(AmazonWebView view, String url) {
    super.onPageFinished(view, url);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);
    
        sendUpdate(obj, true);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
 
Example #30
Source File: InAppBrowser.java    From reader with MIT License 5 votes vote down vote up
public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);
    
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_ERROR_EVENT);
        obj.put("url", failingUrl);
        obj.put("code", errorCode);
        obj.put("message", description);
    
        sendUpdate(obj, true, PluginResult.Status.ERROR);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}