@Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View v = inflater.inflate(R.layout.sync_enter_passphrase, null);

    TextView promptText = (TextView) v.findViewById(R.id.prompt_text);
    promptText.setText(getPromptText());

    TextView resetText = (TextView) v.findViewById(R.id.reset_text);
    resetText.setText(getResetText());
    resetText.setMovementMethod(LinkMovementMethod.getInstance());
    resetText.setVisibility(View.VISIBLE);

    EditText passphrase = (EditText) v.findViewById(R.id.passphrase);
    passphrase.setHint(R.string.sync_enter_custom_passphrase_hint);
    passphrase.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_NEXT) {
              handleOk();
            }
            return false;
          }
        });

    final AlertDialog d =
        new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
            .setView(v)
            .setPositiveButton(
                R.string.ok,
                new Dialog.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface d, int which) {
                    // We override the onclick. This is a hack to not dismiss the dialog after
                    // click of OK and instead dismiss it after confirming the passphrase
                    // is correct.
                  }
                })
            .setNegativeButton(R.string.cancel, this)
            .setTitle(R.string.sign_in_google_account)
            .create();
    d.getDelegate().setHandleNativeActionModesEnabled(false);
    d.setOnShowListener(
        new DialogInterface.OnShowListener() {
          @Override
          public void onShow(DialogInterface dialog) {
            Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
            b.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                    handleOk();
                  }
                });
          }
        });
    return d;
  }
  @CalledByNative
  void showJavascriptAppModalDialog(WindowAndroid window, long nativeDialogPointer) {
    assert window != null;
    Context context = window.getActivity().get();
    // If the activity has gone away, then just clean up the native pointer.
    if (context == null) {
      nativeDidCancelAppModalDialog(nativeDialogPointer, false);
      return;
    }

    // Cache the native dialog pointer so that we can use it to return the response.
    mNativeDialogPointer = nativeDialogPointer;

    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.js_modal_dialog, null);
    mSuppressCheckBox = (CheckBox) layout.findViewById(R.id.suppress_js_modal_dialogs);
    mPromptTextView = (TextView) layout.findViewById(R.id.js_modal_dialog_prompt);

    prepare(layout);

    AlertDialog.Builder builder =
        new AlertDialog.Builder(context, R.style.AlertDialogTheme)
            .setView(layout)
            .setTitle(mTitle)
            .setOnCancelListener(
                new DialogInterface.OnCancelListener() {
                  @Override
                  public void onCancel(DialogInterface dialog) {
                    cancel(false);
                  }
                });
    if (hasPositiveButton()) {
      builder.setPositiveButton(getPositiveButtonText(), this);
    }
    if (hasNegativeButton()) {
      builder.setNegativeButton(getNegativeButtonText(), this);
    }

    mDialog = builder.create();
    mDialog.setCanceledOnTouchOutside(false);
    mDialog.getDelegate().setHandleNativeActionModesEnabled(false);
    mDialog.show();
  }