Chromium Code Reviews| Index: chrome/browser/ui/views/simple_message_box_views.cc |
| diff --git a/chrome/browser/ui/views/simple_message_box_views.cc b/chrome/browser/ui/views/simple_message_box_views.cc |
| index fc3f02623d4a22f854ba671ddae77ae4cb1c83fe..bb07920ad7c92095e5307c496a0137be107d6ca6 100644 |
| --- a/chrome/browser/ui/views/simple_message_box_views.cc |
| +++ b/chrome/browser/ui/views/simple_message_box_views.cc |
| @@ -37,6 +37,7 @@ class SimpleMessageBoxViews : public views::DialogDelegate { |
| MessageBoxType type, |
| const base::string16& yes_text, |
| const base::string16& no_text, |
| + const base::string16& checkbox_text, |
| bool is_system_modal); |
| ~SimpleMessageBoxViews() override; |
| @@ -65,9 +66,10 @@ class SimpleMessageBoxViews : public views::DialogDelegate { |
| base::string16 yes_text_; |
| base::string16 no_text_; |
| MessageBoxResult* result_; |
| - bool is_system_modal_; |
| views::MessageBoxView* message_box_view_; |
| base::Closure quit_runloop_; |
| + bool is_system_modal_; |
| + bool has_checkbox_; |
| DISALLOW_COPY_AND_ASSIGN(SimpleMessageBoxViews); |
| }; |
| @@ -75,20 +77,23 @@ class SimpleMessageBoxViews : public views::DialogDelegate { |
| //////////////////////////////////////////////////////////////////////////////// |
| // SimpleMessageBoxViews, public: |
| -SimpleMessageBoxViews::SimpleMessageBoxViews(const base::string16& title, |
| - const base::string16& message, |
| - MessageBoxType type, |
| - const base::string16& yes_text, |
| - const base::string16& no_text, |
| - bool is_system_modal) |
| +SimpleMessageBoxViews::SimpleMessageBoxViews( |
| + const base::string16& title, |
| + const base::string16& message, |
| + MessageBoxType type, |
| + const base::string16& yes_text, |
| + const base::string16& no_text, |
| + const base::string16& checkbox_text, |
| + bool is_system_modal) |
| : window_title_(title), |
| type_(type), |
| yes_text_(yes_text), |
| no_text_(no_text), |
| result_(NULL), |
| - is_system_modal_(is_system_modal), |
| message_box_view_(new views::MessageBoxView( |
| - views::MessageBoxView::InitParams(message))) { |
| + views::MessageBoxView::InitParams(message))), |
| + is_system_modal_(is_system_modal), |
| + has_checkbox_(!checkbox_text.empty()) { |
| if (yes_text_.empty()) { |
| yes_text_ = |
| type_ == MESSAGE_BOX_TYPE_QUESTION |
| @@ -98,6 +103,11 @@ SimpleMessageBoxViews::SimpleMessageBoxViews(const base::string16& title, |
| if (no_text_.empty() && type_ == MESSAGE_BOX_TYPE_QUESTION) |
| no_text_ = l10n_util::GetStringUTF16(IDS_CANCEL); |
| + |
| + if (has_checkbox_) { |
| + message_box_view_->SetCheckBoxLabel(checkbox_text); |
| + message_box_view_->SetCheckBoxSelected(true); |
| + } |
| } |
| SimpleMessageBoxViews::~SimpleMessageBoxViews() { |
| @@ -137,7 +147,10 @@ bool SimpleMessageBoxViews::Cancel() { |
| } |
| bool SimpleMessageBoxViews::Accept() { |
| - *result_ = MESSAGE_BOX_RESULT_YES; |
| + *result_ = !has_checkbox_ ? MESSAGE_BOX_RESULT_YES |
|
Lei Zhang
2016/07/09 01:04:47
I'm not a fan of nested ternary operators, but tha
afakhry
2016/07/11 16:47:45
Done.
|
| + : (message_box_view_->IsCheckBoxSelected() |
| + ? MESSAGE_BOX_RESULT_YES_CHECKED |
| + : MESSAGE_BOX_RESULT_YES_NOT_CHECKED); |
| Done(); |
| return true; |
| } |
| @@ -193,7 +206,8 @@ MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent, |
| const base::string16& message, |
| MessageBoxType type, |
| const base::string16& yes_text, |
| - const base::string16& no_text) { |
| + const base::string16& no_text, |
| + const base::string16& checkbox_text) { |
| startup_metric_utils::SetNonBrowserUIDisplayed(); |
| if (internal::g_should_skip_message_box_for_test) |
| return MESSAGE_BOX_RESULT_YES; |
| @@ -205,6 +219,7 @@ MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent, |
| if (!base::MessageLoopForUI::IsCurrent() || |
| !base::MessageLoopForUI::current()->is_running() || |
| !ResourceBundle::HasSharedInstance()) { |
| + LOG_IF(ERROR, !checkbox_text.empty()) << "Dialog checkbox won't be shown"; |
| int result = ui::MessageBox(views::HWNDForNativeWindow(parent), message, |
| title, GetMessageBoxFlagsFromType(type)); |
| return (result == IDYES || result == IDOK) ? |
| @@ -219,14 +234,10 @@ MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent, |
| } |
| #endif |
| - SimpleMessageBoxViews* dialog = |
| - new SimpleMessageBoxViews(title, |
| - message, |
| - type, |
| - yes_text, |
| - no_text, |
| - parent == NULL // is_system_modal |
| - ); |
| + SimpleMessageBoxViews* dialog = new SimpleMessageBoxViews( |
| + title, message, type, yes_text, no_text, checkbox_text, |
| + parent == NULL // is_system_modal |
| + ); |
| constrained_window::CreateBrowserModalDialogViews(dialog, parent)->Show(); |
| // NOTE: |dialog| may have been deleted by the time |RunDialogAndGetResult()| |
| @@ -240,14 +251,24 @@ void ShowWarningMessageBox(gfx::NativeWindow parent, |
| const base::string16& title, |
| const base::string16& message) { |
| ShowMessageBoxImpl(parent, title, message, MESSAGE_BOX_TYPE_WARNING, |
| - base::string16(), base::string16()); |
| + base::string16(), base::string16(), base::string16()); |
| +} |
| + |
| +bool ShowWarningMessageBoxWithCheckbox(gfx::NativeWindow parent, |
| + const base::string16& title, |
| + const base::string16& message, |
| + const base::string16& checkbox_text) { |
| + return ShowMessageBoxImpl(parent, title, message, MESSAGE_BOX_TYPE_WARNING, |
| + base::string16(), base::string16(), |
| + checkbox_text) == MESSAGE_BOX_RESULT_YES_CHECKED; |
| } |
| MessageBoxResult ShowQuestionMessageBox(gfx::NativeWindow parent, |
| const base::string16& title, |
| const base::string16& message) { |
| return ShowMessageBoxImpl(parent, title, message, MESSAGE_BOX_TYPE_QUESTION, |
| - base::string16(), base::string16()); |
| + base::string16(), base::string16(), |
| + base::string16()); |
| } |
| MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent, |
| @@ -255,8 +276,8 @@ MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent, |
| const base::string16& message, |
| const base::string16& yes_text, |
| const base::string16& no_text) { |
| - return ShowMessageBoxImpl( |
| - parent, title, message, MESSAGE_BOX_TYPE_QUESTION, yes_text, no_text); |
| + return ShowMessageBoxImpl(parent, title, message, MESSAGE_BOX_TYPE_QUESTION, |
| + yes_text, no_text, base::string16()); |
| } |
| } // namespace chrome |