/**
   * 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
  */
 @XWalkAPI
 public void onReceivedLoadError(
     XWalkViewInternal view, int errorCode, String description, String failingUrl) {
   Toast.makeText(view.getActivity(), description, Toast.LENGTH_SHORT).show();
 }