s.prompt.MODAL_TYPE_WINDOW,
      Services.prompt.MODAL_TYPE_INTERNAL_WINDOW,
    ].includes(this.args.modalType);
  }

  get tabModal() {
    return this.window?.Dialog;
  }

  get promptType() {
    return this.args.inPermitUnload ? "beforeunload" : this.args.promptType;
  }

  get ui() {
    let tm = this.tabModal;
    return tm ? tm.ui : null;
  }

  /**
   * For Android, this returns a GeckoViewPrompter, which can be used to control prompts.
   * Otherwise, this returns the ChromeWindow associated with an open dialog window if
   * it is currently attached to the DOM.
   */
  get window() {
    if (this.#win) {
      let win = this.#win.get();
      if (win && (lazy.AppInfo.isAndroid || win.parent)) {
        return win;
      }
    }
    return null;
  }

  /**
   * Sets the text of a prompt's input field.
   *
   * @param {string} inputText
   *     The text to set for the input field.
   */
  set text(inputText) {
    if (lazy.AppInfo.isAndroid) {
      this.window.setInputText(inputText);
    } else {
      // see toolkit/components/prompts/content/commonDialog.js
      let { loginTextbox } = this.ui;
      loginTextbox.value = inputText;
    }
  }

  /**
   * Accept the user prompt.
   */
  accept() {
    if (lazy.AppInfo.isAndroid) {
      // GeckoView does not have a UI, so the methods are called directly
      this.window.acceptPrompt();
    } else {
      const { button0 } = this.ui;
      button0.click();
    }
  }

  /**
   * Dismiss the user prompt.
   */
  dismiss() {
    if (lazy.AppInfo.isAndroid) {
      // GeckoView does not have a UI, so the methods are called directly
      this.window.dismissPrompt();
    } else {
      const { button0, button1 } = this.ui;
      (button1 ? button1 : button0).click();
    }
  }

  /**
   * Returns text of the prompt.
   *
   * @returns {Promise<string>}
   *     Returns a Promise resolving to the prompt text.
   */
  getText() {
    if (lazy.AppInfo.isAndroid) {
      return this.window.getPromptText();
    }

    return Promise.resolve(this.ui.infoBody.textContent);
  }

  /**
   * Returns text of the prompt input.
   *
   * @returns {Promise<string>}
   *     Returns a Promise resolving to the input's text.
   */
  getInputText() {
    if (lazy.AppInfo.isAndroid) {
      return this.window.getInputText();
    }

    return Promise.resolve(this.ui.loginTextbox.value);
  }
};
PK