#include "chrome/browser/ui/views/message_box_dialog.h"
#include <utility>
#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/task/current_thread.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/simple_message_box.h"
#include "chrome/browser/ui/simple_message_box_internal.h"
#include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/base/mojom/ui_base_types.mojom-shared.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/display/screen.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/controls/message_box_view.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/ui/base/window_properties.h"
#include "ui/aura/window.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "ui/base/win/message_box_win.h"
#include "ui/views/win/hwnd_util.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/ui/cocoa/simple_message_box_cocoa.h"
#endif
namespace {
#if BUILDFLAG(IS_WIN)
UINT GetMessageBoxFlagsFromType(chrome::MessageBoxType type) {
UINT flags = MB_SETFOREGROUND;
switch (type) {
case chrome::MESSAGE_BOX_TYPE_WARNING:
return flags | MB_OK | MB_ICONWARNING;
case chrome::MESSAGE_BOX_TYPE_QUESTION:
return flags | MB_YESNO | MB_ICONQUESTION;
}
NOTREACHED();
}
#endif
chrome::MessageBoxResult ShowSync(gfx::NativeWindow parent,
std::u16string_view title,
std::u16string_view message,
chrome::MessageBoxType type,
std::u16string_view yes_text,
std::u16string_view no_text,
std::u16string_view checkbox_text) { … }
bool CanUseNativeMessageBox() { … }
bool CanUseViewsMessageBox() { … }
void ShowNativeMessageBox(gfx::NativeWindow parent,
std::u16string_view title,
std::u16string_view message,
chrome::MessageBoxType type,
std::u16string_view yes_text,
std::u16string_view no_text,
std::u16string_view checkbox_text,
MessageBoxDialog::MessageBoxResultCallback callback) { … }
}
chrome::MessageBoxResult MessageBoxDialog::Show(
gfx::NativeWindow parent,
std::u16string_view title,
std::u16string_view message,
chrome::MessageBoxType type,
std::u16string_view yes_text,
std::u16string_view no_text,
std::u16string_view checkbox_text,
MessageBoxDialog::MessageBoxResultCallback callback) { … }
void MessageBoxDialog::OnDialogAccepted() { … }
std::u16string MessageBoxDialog::GetWindowTitle() const { … }
views::View* MessageBoxDialog::GetContentsView() { … }
bool MessageBoxDialog::ShouldShowCloseButton() const { … }
void MessageBoxDialog::OnWidgetActivationChanged(views::Widget* widget,
bool active) { … }
void MessageBoxDialog::OnWidgetDestroying(views::Widget* widget) { … }
MessageBoxDialog::MessageBoxDialog(std::u16string_view title,
std::u16string_view message,
chrome::MessageBoxType type,
std::u16string_view yes_text,
std::u16string_view no_text,
std::u16string_view checkbox_text)
: … { … }
MessageBoxDialog::~MessageBoxDialog() { … }
void MessageBoxDialog::Run(MessageBoxResultCallback result_callback) { … }
void MessageBoxDialog::Done(chrome::MessageBoxResult result) { … }
views::Widget* MessageBoxDialog::GetWidget() { … }
const views::Widget* MessageBoxDialog::GetWidget() const { … }
namespace chrome {
MessageBoxResult ShowWarningMessageBox(gfx::NativeWindow parent,
const std::u16string& title,
const std::u16string& message) { … }
void ShowWarningMessageBoxWithCheckbox(
gfx::NativeWindow parent,
const std::u16string& title,
const std::u16string& message,
const std::u16string& checkbox_text,
base::OnceCallback<void(bool checked)> callback) { … }
MessageBoxResult ShowQuestionMessageBoxSync(gfx::NativeWindow parent,
const std::u16string& title,
const std::u16string& message) { … }
void ShowQuestionMessageBox(
gfx::NativeWindow parent,
const std::u16string& title,
const std::u16string& message,
base::OnceCallback<void(MessageBoxResult)> callback) { … }
MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent,
const std::u16string& title,
const std::u16string& message,
const std::u16string& yes_text,
const std::u16string& no_text) { … }
}