/** * Notify the host application that an SSL error occurred while loading a resource. The host * application must call either callback.onReceiveValue(true) or callback.onReceiveValue(false) . * Note that the decision may be retained for use in response to future SSL errors. The default * behavior is to pop up a dialog * * @param view the xwalkview that is initiating the callback * @param callback passing 'true' means accepting the ssl error and continue to load. passing * 'false' means forbidding to load the web page. * @param error the SSL error object * @since 4.0 */ @XWalkAPI public void onReceivedSslError( XWalkViewInternal view, ValueCallback<Boolean> callback, SslError error) { final ValueCallback<Boolean> valueCallback = callback; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(view.getContext()); dialogBuilder .setTitle(R.string.ssl_alert_title) .setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { valueCallback.onReceiveValue(true); dialog.dismiss(); } }) .setNegativeButton( android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { valueCallback.onReceiveValue(false); dialog.dismiss(); } }) .setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { valueCallback.onReceiveValue(false); } }); dialogBuilder.create().show(); }
/** * Notify the host application to handle an authentication request. The default behavior is to * cancel the request. * * @param view The XWalkViewInternal that is initiating the callback. * @param handler The XWalkHttpAuthHandler that will handle the user's response. * @param host The host requiring authentication. * @param realm A description to help store user credentials for future visits. */ @XWalkAPI public void onReceivedHttpAuthRequest( XWalkViewInternal view, XWalkHttpAuthHandlerInternal handler, String host, String realm) { if (view == null) return; final XWalkHttpAuthHandlerInternal haHandler = handler; Context context = view.getContext(); LinearLayout layout = new LinearLayout(context); final EditText userNameEditText = new EditText(context); final EditText passwordEditText = new EditText(context); layout.setOrientation(LinearLayout.VERTICAL); layout.setPaddingRelative(10, 0, 10, 20); userNameEditText.setHint(R.string.http_auth_user_name); passwordEditText.setHint(R.string.http_auth_password); passwordEditText.setInputType( InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); layout.addView(userNameEditText); layout.addView(passwordEditText); final Activity curActivity = view.getActivity(); AlertDialog.Builder httpAuthDialog = new AlertDialog.Builder(curActivity); httpAuthDialog .setTitle(R.string.http_auth_title) .setView(layout) .setCancelable(false) .setPositiveButton( R.string.http_auth_log_in, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { String userName = userNameEditText.getText().toString(); String password = passwordEditText.getText().toString(); haHandler.proceed(userName, password); dialog.dismiss(); } }) .setNegativeButton(android.R.string.cancel, null) .setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { haHandler.cancel(); } }) .create() .show(); }
/** * Report an error to the client. * * @param view the owner XWalkViewInternal instance. * @param errorCode the error id. * @param description A String describing the error. * @param failingUrl The url that failed to load. * @since 1.0 */ public void onReceivedLoadError( XWalkViewInternal view, int errorCode, String description, String failingUrl) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(view.getContext()); dialogBuilder .setTitle(android.R.string.dialog_alert_title) .setMessage(description) .setCancelable(false) .setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog dialog = dialogBuilder.create(); dialog.show(); }
/** * Report an error to the client. * * @param view the owner XWalkViewInternal instance. * @param errorCode the error id. * @param description A String describing the error. * @param failingUrl The url that failed to load. * @since 1.0 */ @XWalkAPI public void onReceivedLoadError( XWalkViewInternal view, int errorCode, String description, String failingUrl) { Toast.makeText(view.getActivity(), description, Toast.LENGTH_SHORT).show(); }