blob: 908ecb2cd19f5970003a1ef656100b62cab50d45 [file] [log] [blame]
Joel Hockey18f767a2024-08-20 03:23:441// Copyright 2024 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UI_ANDROID_MODAL_DIALOG_BRIDGE_H_
6#define UI_ANDROID_MODAL_DIALOG_BRIDGE_H_
7
8#include <memory>
9
10#include "base/android/jni_string.h"
11#include "base/android/scoped_java_ref.h"
12#include "ui/android/ui_android_export.h"
13#include "ui/base/models/dialog_model_host.h"
14
15namespace ui {
16class DialogModel;
17class WindowAndroid;
18} // namespace ui
19
20namespace ui {
21
22// Allows dialogs defined by ui::DialogModel() to be shown in android.
23// This makes a best effort to map between ui::DialogModel() and Java
24// PropertyModel.
25//
26// Maps title, an optional single paragraph, and ok and cancel buttons.
27// Default labels for IDS_APP_OK and IDS_APP_CANCEL will be used for buttons
28// if labels are not specified.
29// Replacements (if any) are performed in paragraph text, but any emphasis is
30// not included since it is not supported in android dialogs.
31class UI_ANDROID_EXPORT ModalDialogBridge : public ui::DialogModelHost {
32 public:
33 // Shows a tab modal dialog based on `dialog_model`.
34 static void ShowTabModal(std::unique_ptr<ui::DialogModel> dialog_model,
35 ui::WindowAndroid* web_contents);
36
37 explicit ModalDialogBridge(std::unique_ptr<ui::DialogModel> dialog_model);
38 ModalDialogBridge(const ModalDialogBridge&) = delete;
39 ModalDialogBridge& operator=(const ModalDialogBridge&) = delete;
40 virtual ~ModalDialogBridge();
41
42 // JNI methods.
43 void PositiveButtonClicked(JNIEnv* env);
44 void NegativeButtonClicked(JNIEnv* env);
45 void Dismissed(JNIEnv* env);
46 void Destroy(JNIEnv* env);
47
48 private:
49 // ui::DialogModelHost:
50 void Close() override;
51 void OnDialogButtonChanged() override;
52
53 // Build java PropertyModel from ui::DialogModel.
54 void BuildPropertyModel();
55
56 // Show the dialog. This object will destroy itself when it is dismissed.
57 void Show(ui::WindowAndroid* web_contents);
58
59 // Call to java ModalDialogBridge#onDismiss(DialogDismissalCause);
60 void Dismiss(int dismissalCause);
61
62 std::unique_ptr<ui::DialogModel> dialog_model_;
63 base::android::ScopedJavaGlobalRef<jobject> java_obj_;
64};
65
66} // namespace ui
67
68#endif // UI_ANDROID_MODAL_DIALOG_BRIDGE_H_