Commit d4843952 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

cbuiv: make message box closure unconditional

This change:
1) Removes the can_close parameter to chrome::ShowWarningMessageBox()
2) Removes the code supporting that parameter, making close always possible
   on message boxes
3) Renames SimpleMessageBoxViews to MessageBoxDialog, to indicate that it
   is a dialog rather than a View

Bug: 1011446
Change-Id: Ia4e0ba79ad170bc7837d48eb380ff752236c05ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2028667Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736889}
parent 328c515e
......@@ -88,8 +88,7 @@ class DeleteProfileDialogManager : public BrowserListObserver {
IDS_PROFILE_WILL_BE_DELETED_DIALOG_DESCRIPTION,
base::ASCIIToUTF16(primary_account_email_),
base::ASCIIToUTF16(
gaia::ExtractDomainName(primary_account_email_))),
/*can_close=*/false);
gaia::ExtractDomainName(primary_account_email_))));
webui::DeleteProfileAtPath(
profile_->GetPath(),
......
......@@ -3026,6 +3026,8 @@ jumbo_static_library("ui") {
"views/media_router/presentation_receiver_window_view.h",
"views/media_router/web_contents_display_observer_view.cc",
"views/media_router/web_contents_display_observer_view.h",
"views/message_box_dialog.cc",
"views/message_box_dialog.h",
"views/native_file_system/native_file_system_access_icon_view.cc",
"views/native_file_system/native_file_system_access_icon_view.h",
"views/native_file_system/native_file_system_directory_access_confirmation_view.cc",
......@@ -3212,8 +3214,6 @@ jumbo_static_library("ui") {
"views/sharing/sharing_dialog_view.h",
"views/sharing/sharing_icon_view.cc",
"views/sharing/sharing_icon_view.h",
"views/simple_message_box_views.cc",
"views/simple_message_box_views.h",
"views/status_bubble_views.cc",
"views/status_bubble_views.h",
"views/storage/storage_pressure_bubble_view.cc",
......
......@@ -13,8 +13,7 @@ namespace chrome {
void ShowWarningMessageBox(gfx::NativeWindow parent,
const base::string16& title,
const base::string16& message,
bool can_close) {
const base::string16& message) {
NOTIMPLEMENTED();
}
......
......@@ -42,8 +42,7 @@ enum MessageBoxType {
// infobars; consult the UI leads for a recommendation.
void ShowWarningMessageBox(gfx::NativeWindow parent,
const base::string16& title,
const base::string16& message,
bool can_close = true);
const base::string16& message);
// As above, but shows the dialog box asynchronously with a checkbox.
// |callback| will be invoked after the dialog is dismissed. It is invoked with
......
......@@ -15,7 +15,7 @@
#include "build/build_config.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/simple_message_box_internal.h"
#include "chrome/browser/ui/views/simple_message_box_views.h"
#include "chrome/browser/ui/views/message_box_dialog.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"
......@@ -59,16 +59,15 @@ chrome::MessageBoxResult ShowSync(gfx::NativeWindow parent,
chrome::MessageBoxType type,
const base::string16& yes_text,
const base::string16& no_text,
const base::string16& checkbox_text,
bool can_close) {
const base::string16& checkbox_text) {
chrome::MessageBoxResult result = chrome::MESSAGE_BOX_RESULT_NO;
// TODO(pkotwicz): Exit message loop when the dialog is closed by some other
// means than |Cancel| or |Accept|. crbug.com/404385
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
SimpleMessageBoxViews::Show(
parent, title, message, type, yes_text, no_text, checkbox_text, can_close,
MessageBoxDialog::Show(
parent, title, message, type, yes_text, no_text, checkbox_text,
base::Bind(
[](base::RunLoop* run_loop, chrome::MessageBoxResult* out_result,
chrome::MessageBoxResult messagebox_result) {
......@@ -83,10 +82,10 @@ chrome::MessageBoxResult ShowSync(gfx::NativeWindow parent,
} // namespace
////////////////////////////////////////////////////////////////////////////////
// SimpleMessageBoxViews, public:
// MessageBoxDialog, public:
// static
chrome::MessageBoxResult SimpleMessageBoxViews::Show(
chrome::MessageBoxResult MessageBoxDialog::Show(
gfx::NativeWindow parent,
const base::string16& title,
const base::string16& message,
......@@ -94,11 +93,10 @@ chrome::MessageBoxResult SimpleMessageBoxViews::Show(
const base::string16& yes_text,
const base::string16& no_text,
const base::string16& checkbox_text,
bool can_close,
SimpleMessageBoxViews::MessageBoxResultCallback callback) {
MessageBoxDialog::MessageBoxResultCallback callback) {
if (!callback)
return ShowSync(parent, title, message, type, yes_text, no_text,
checkbox_text, can_close);
checkbox_text);
startup_metric_utils::SetNonBrowserUIDisplayed();
if (chrome::internal::g_should_skip_message_box_for_test) {
......@@ -146,14 +144,13 @@ chrome::MessageBoxResult SimpleMessageBoxViews::Show(
bool is_system_modal = !parent;
#if defined(OS_MACOSX)
// Mac does not support system modals, so never ask SimpleMessageBoxViews to
// Mac does not support system modals, so never ask MessageBoxDialog to
// be system modal.
is_system_modal = false;
#endif
SimpleMessageBoxViews* dialog =
new SimpleMessageBoxViews(title, message, type, yes_text, no_text,
checkbox_text, is_system_modal, can_close);
MessageBoxDialog* dialog = new MessageBoxDialog(
title, message, type, yes_text, no_text, checkbox_text, is_system_modal);
views::Widget* widget =
constrained_window::CreateBrowserModalDialogViews(dialog, parent);
......@@ -170,78 +167,70 @@ chrome::MessageBoxResult SimpleMessageBoxViews::Show(
return chrome::MESSAGE_BOX_RESULT_DEFERRED;
}
bool SimpleMessageBoxViews::Cancel() {
result_ = chrome::MESSAGE_BOX_RESULT_NO;
Done();
return true;
}
bool SimpleMessageBoxViews::Accept() {
void MessageBoxDialog::OnDialogAccepted() {
if (!message_box_view_->HasCheckBox() ||
message_box_view_->IsCheckBoxSelected()) {
result_ = chrome::MESSAGE_BOX_RESULT_YES;
Done(chrome::MESSAGE_BOX_RESULT_YES);
} else {
result_ = chrome::MESSAGE_BOX_RESULT_NO;
Done(chrome::MESSAGE_BOX_RESULT_NO);
}
Done();
return true;
}
bool SimpleMessageBoxViews::Close() {
return can_close_ && DialogDelegate::Close();
}
base::string16 SimpleMessageBoxViews::GetWindowTitle() const {
base::string16 MessageBoxDialog::GetWindowTitle() const {
return window_title_;
}
void SimpleMessageBoxViews::DeleteDelegate() {
void MessageBoxDialog::DeleteDelegate() {
delete this;
}
ui::ModalType SimpleMessageBoxViews::GetModalType() const {
ui::ModalType MessageBoxDialog::GetModalType() const {
return is_system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_WINDOW;
}
views::View* SimpleMessageBoxViews::GetContentsView() {
views::View* MessageBoxDialog::GetContentsView() {
return message_box_view_;
}
bool SimpleMessageBoxViews::ShouldShowCloseButton() const {
return can_close_;
bool MessageBoxDialog::ShouldShowCloseButton() const {
return true;
}
void SimpleMessageBoxViews::OnWidgetActivationChanged(views::Widget* widget,
void MessageBoxDialog::OnWidgetActivationChanged(views::Widget* widget,
bool active) {
if (!active)
GetWidget()->Close();
}
////////////////////////////////////////////////////////////////////////////////
// SimpleMessageBoxViews, private:
// MessageBoxDialog, private:
SimpleMessageBoxViews::SimpleMessageBoxViews(
const base::string16& title,
MessageBoxDialog::MessageBoxDialog(const base::string16& title,
const base::string16& message,
chrome::MessageBoxType type,
const base::string16& yes_text,
const base::string16& no_text,
const base::string16& checkbox_text,
bool is_system_modal,
bool can_close)
bool is_system_modal)
: window_title_(title),
type_(type),
result_(chrome::MESSAGE_BOX_RESULT_NO),
message_box_view_(new views::MessageBoxView(
views::MessageBoxView::InitParams(message))),
is_system_modal_(is_system_modal),
can_close_(can_close) {
is_system_modal_(is_system_modal) {
DialogDelegate::set_buttons(type_ == chrome::MESSAGE_BOX_TYPE_QUESTION
? ui::DIALOG_BUTTON_OK |
ui::DIALOG_BUTTON_CANCEL
: ui::DIALOG_BUTTON_OK);
DialogDelegate::set_accept_callback(base::BindOnce(
&MessageBoxDialog::OnDialogAccepted, base::Unretained(this)));
DialogDelegate::set_cancel_callback(
base::BindOnce(&MessageBoxDialog::Done, base::Unretained(this),
chrome::MESSAGE_BOX_RESULT_NO));
DialogDelegate::set_close_callback(
base::BindOnce(&MessageBoxDialog::Done, base::Unretained(this),
chrome::MESSAGE_BOX_RESULT_NO));
base::string16 ok_text = yes_text;
if (ok_text.empty()) {
ok_text =
......@@ -264,21 +253,21 @@ SimpleMessageBoxViews::SimpleMessageBoxViews(
chrome::RecordDialogCreation(chrome::DialogIdentifier::SIMPLE_MESSAGE_BOX);
}
SimpleMessageBoxViews::~SimpleMessageBoxViews() {
MessageBoxDialog::~MessageBoxDialog() {
GetWidget()->RemoveObserver(this);
}
void SimpleMessageBoxViews::Run(MessageBoxResultCallback result_callback) {
void MessageBoxDialog::Run(MessageBoxResultCallback result_callback) {
GetWidget()->AddObserver(this);
result_callback_ = std::move(result_callback);
}
void SimpleMessageBoxViews::Done() {
void MessageBoxDialog::Done(chrome::MessageBoxResult result) {
CHECK(!result_callback_.is_null());
std::move(result_callback_).Run(result_);
std::move(result_callback_).Run(result);
}
const views::Widget* SimpleMessageBoxViews::GetWidgetImpl() const {
const views::Widget* MessageBoxDialog::GetWidgetImpl() const {
return message_box_view_->GetWidget();
}
......@@ -286,11 +275,10 @@ namespace chrome {
void ShowWarningMessageBox(gfx::NativeWindow parent,
const base::string16& title,
const base::string16& message,
bool can_close) {
SimpleMessageBoxViews::Show(
parent, title, message, chrome::MESSAGE_BOX_TYPE_WARNING,
base::string16(), base::string16(), base::string16(), can_close);
const base::string16& message) {
MessageBoxDialog::Show(parent, title, message,
chrome::MESSAGE_BOX_TYPE_WARNING, base::string16(),
base::string16(), base::string16());
}
void ShowWarningMessageBoxWithCheckbox(
......@@ -299,9 +287,9 @@ void ShowWarningMessageBoxWithCheckbox(
const base::string16& message,
const base::string16& checkbox_text,
base::OnceCallback<void(bool checked)> callback) {
SimpleMessageBoxViews::Show(
parent, title, message, chrome::MESSAGE_BOX_TYPE_WARNING,
base::string16(), base::string16(), checkbox_text, /*can_close=*/true,
MessageBoxDialog::Show(parent, title, message,
chrome::MESSAGE_BOX_TYPE_WARNING, base::string16(),
base::string16(), checkbox_text,
base::Bind(
[](base::OnceCallback<void(bool checked)> callback,
MessageBoxResult message_box_result) {
......@@ -314,9 +302,9 @@ void ShowWarningMessageBoxWithCheckbox(
MessageBoxResult ShowQuestionMessageBox(gfx::NativeWindow parent,
const base::string16& title,
const base::string16& message) {
return SimpleMessageBoxViews::Show(
return MessageBoxDialog::Show(
parent, title, message, chrome::MESSAGE_BOX_TYPE_QUESTION,
base::string16(), base::string16(), base::string16(), /*can_close=*/true);
base::string16(), base::string16(), base::string16());
}
MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent,
......@@ -324,10 +312,9 @@ MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent,
const base::string16& message,
const base::string16& yes_text,
const base::string16& no_text) {
return SimpleMessageBoxViews::Show(parent, title, message,
chrome::MESSAGE_BOX_TYPE_QUESTION,
yes_text, no_text, base::string16(),
/*can_close=*/true);
return MessageBoxDialog::Show(parent, title, message,
chrome::MESSAGE_BOX_TYPE_QUESTION, yes_text,
no_text, base::string16());
}
} // namespace chrome
......@@ -2,16 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_SIMPLE_MESSAGE_BOX_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_SIMPLE_MESSAGE_BOX_VIEWS_H_
#ifndef CHROME_BROWSER_UI_VIEWS_MESSAGE_BOX_DIALOG_H_
#define CHROME_BROWSER_UI_VIEWS_MESSAGE_BOX_DIALOG_H_
#include "chrome/browser/ui/simple_message_box.h"
#include "ui/views/controls/message_box_view.h"
#include "ui/views/widget/widget_observer.h"
#include "ui/views/window/dialog_delegate.h"
class SimpleMessageBoxViews : public views::DialogDelegate,
namespace views {
class MessageBoxView;
}
class MessageBoxDialog : public views::DialogDelegate,
public views::WidgetObserver {
public:
using MessageBoxResultCallback =
......@@ -25,13 +28,9 @@ class SimpleMessageBoxViews : public views::DialogDelegate,
const base::string16& yes_text,
const base::string16& no_text,
const base::string16& checkbox_text,
bool can_close,
MessageBoxResultCallback callback = MessageBoxResultCallback());
// views::DialogDelegate:
bool Cancel() override;
bool Accept() override;
bool Close() override;
base::string16 GetWindowTitle() const override;
void DeleteDelegate() override;
ui::ModalType GetModalType() const override;
......@@ -42,31 +41,30 @@ class SimpleMessageBoxViews : public views::DialogDelegate,
void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
private:
SimpleMessageBoxViews(const base::string16& title,
MessageBoxDialog(const base::string16& title,
const base::string16& message,
chrome::MessageBoxType type,
const base::string16& yes_text,
const base::string16& no_text,
const base::string16& checkbox_text,
bool is_system_modal,
bool can_close);
~SimpleMessageBoxViews() override;
bool is_system_modal);
~MessageBoxDialog() override;
void Run(MessageBoxResultCallback result_callback);
void Done();
void Done(chrome::MessageBoxResult result);
// views::DialogDelegate:
void OnDialogAccepted();
// WidgetGetter:
const views::Widget* GetWidgetImpl() const override;
const base::string16 window_title_;
const chrome::MessageBoxType type_;
chrome::MessageBoxResult result_;
views::MessageBoxView* message_box_view_;
MessageBoxResultCallback result_callback_;
bool is_system_modal_;
bool can_close_;
DISALLOW_COPY_AND_ASSIGN(SimpleMessageBoxViews);
DISALLOW_COPY_AND_ASSIGN(MessageBoxDialog);
};
#endif // CHROME_BROWSER_UI_VIEWS_SIMPLE_MESSAGE_BOX_VIEWS_H_
#endif // CHROME_BROWSER_UI_VIEWS_MESSAGE_BOX_DIALOG_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment