| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/simple_message_box.h" | 5 #include "chrome/browser/ui/simple_message_box.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 base::string16 yes_text_; | 66 base::string16 yes_text_; |
| 67 base::string16 no_text_; | 67 base::string16 no_text_; |
| 68 MessageBoxResult* result_; | 68 MessageBoxResult* result_; |
| 69 views::MessageBoxView* message_box_view_; | 69 views::MessageBoxView* message_box_view_; |
| 70 base::Closure quit_runloop_; | 70 base::Closure quit_runloop_; |
| 71 bool is_system_modal_; | 71 bool is_system_modal_; |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(SimpleMessageBoxViews); | 73 DISALLOW_COPY_AND_ASSIGN(SimpleMessageBoxViews); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // The currently showing message box, if there is one. Used for tests. |
| 77 SimpleMessageBoxViews* g_current_message_box = nullptr; |
| 78 |
| 76 //////////////////////////////////////////////////////////////////////////////// | 79 //////////////////////////////////////////////////////////////////////////////// |
| 77 // SimpleMessageBoxViews, public: | 80 // SimpleMessageBoxViews, public: |
| 78 | 81 |
| 79 SimpleMessageBoxViews::SimpleMessageBoxViews( | 82 SimpleMessageBoxViews::SimpleMessageBoxViews( |
| 80 const base::string16& title, | 83 const base::string16& title, |
| 81 const base::string16& message, | 84 const base::string16& message, |
| 82 MessageBoxType type, | 85 MessageBoxType type, |
| 83 const base::string16& yes_text, | 86 const base::string16& yes_text, |
| 84 const base::string16& no_text, | 87 const base::string16& no_text, |
| 85 const base::string16& checkbox_text, | 88 const base::string16& checkbox_text, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 105 if (!checkbox_text.empty()) { | 108 if (!checkbox_text.empty()) { |
| 106 message_box_view_->SetCheckBoxLabel(checkbox_text); | 109 message_box_view_->SetCheckBoxLabel(checkbox_text); |
| 107 message_box_view_->SetCheckBoxSelected(true); | 110 message_box_view_->SetCheckBoxSelected(true); |
| 108 } | 111 } |
| 109 } | 112 } |
| 110 | 113 |
| 111 SimpleMessageBoxViews::~SimpleMessageBoxViews() { | 114 SimpleMessageBoxViews::~SimpleMessageBoxViews() { |
| 112 } | 115 } |
| 113 | 116 |
| 114 MessageBoxResult SimpleMessageBoxViews::RunDialogAndGetResult() { | 117 MessageBoxResult SimpleMessageBoxViews::RunDialogAndGetResult() { |
| 118 g_current_message_box = this; |
| 115 MessageBoxResult result = MESSAGE_BOX_RESULT_NO; | 119 MessageBoxResult result = MESSAGE_BOX_RESULT_NO; |
| 116 result_ = &result; | 120 result_ = &result; |
| 117 // TODO(pkotwicz): Exit message loop when the dialog is closed by some other | 121 // TODO(pkotwicz): Exit message loop when the dialog is closed by some other |
| 118 // means than |Cancel| or |Accept|. crbug.com/404385 | 122 // means than |Cancel| or |Accept|. crbug.com/404385 |
| 119 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | 123 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 120 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); | 124 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); |
| 121 base::RunLoop run_loop; | 125 base::RunLoop run_loop; |
| 122 quit_runloop_ = run_loop.QuitClosure(); | 126 quit_runloop_ = run_loop.QuitClosure(); |
| 123 run_loop.Run(); | 127 run_loop.Run(); |
| 128 g_current_message_box = nullptr; |
| 124 return result; | 129 return result; |
| 125 } | 130 } |
| 126 | 131 |
| 127 int SimpleMessageBoxViews::GetDialogButtons() const { | 132 int SimpleMessageBoxViews::GetDialogButtons() const { |
| 128 if (type_ == MESSAGE_BOX_TYPE_QUESTION) | 133 if (type_ == MESSAGE_BOX_TYPE_QUESTION) |
| 129 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; | 134 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; |
| 130 | 135 |
| 131 return ui::DIALOG_BUTTON_OK; | 136 return ui::DIALOG_BUTTON_OK; |
| 132 } | 137 } |
| 133 | 138 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 checkbox_text, !parent /* is_system_modal */); | 245 checkbox_text, !parent /* is_system_modal */); |
| 241 constrained_window::CreateBrowserModalDialogViews(dialog, parent)->Show(); | 246 constrained_window::CreateBrowserModalDialogViews(dialog, parent)->Show(); |
| 242 | 247 |
| 243 // NOTE: |dialog| may have been deleted by the time |RunDialogAndGetResult()| | 248 // NOTE: |dialog| may have been deleted by the time |RunDialogAndGetResult()| |
| 244 // returns. | 249 // returns. |
| 245 return dialog->RunDialogAndGetResult(); | 250 return dialog->RunDialogAndGetResult(); |
| 246 } | 251 } |
| 247 | 252 |
| 248 } // namespace | 253 } // namespace |
| 249 | 254 |
| 255 bool CloseMessageBoxForTest(bool accept) { |
| 256 if (!g_current_message_box) |
| 257 return false; |
| 258 |
| 259 if (accept) |
| 260 g_current_message_box->Accept(); |
| 261 else |
| 262 g_current_message_box->Cancel(); |
| 263 return true; |
| 264 } |
| 265 |
| 250 void ShowWarningMessageBox(gfx::NativeWindow parent, | 266 void ShowWarningMessageBox(gfx::NativeWindow parent, |
| 251 const base::string16& title, | 267 const base::string16& title, |
| 252 const base::string16& message) { | 268 const base::string16& message) { |
| 253 ShowMessageBoxImpl(parent, title, message, MESSAGE_BOX_TYPE_WARNING, | 269 ShowMessageBoxImpl(parent, title, message, MESSAGE_BOX_TYPE_WARNING, |
| 254 base::string16(), base::string16(), base::string16()); | 270 base::string16(), base::string16(), base::string16()); |
| 255 } | 271 } |
| 256 | 272 |
| 257 bool ShowWarningMessageBoxWithCheckbox(gfx::NativeWindow parent, | 273 bool ShowWarningMessageBoxWithCheckbox(gfx::NativeWindow parent, |
| 258 const base::string16& title, | 274 const base::string16& title, |
| 259 const base::string16& message, | 275 const base::string16& message, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 274 MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent, | 290 MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent, |
| 275 const base::string16& title, | 291 const base::string16& title, |
| 276 const base::string16& message, | 292 const base::string16& message, |
| 277 const base::string16& yes_text, | 293 const base::string16& yes_text, |
| 278 const base::string16& no_text) { | 294 const base::string16& no_text) { |
| 279 return ShowMessageBoxImpl(parent, title, message, MESSAGE_BOX_TYPE_QUESTION, | 295 return ShowMessageBoxImpl(parent, title, message, MESSAGE_BOX_TYPE_QUESTION, |
| 280 yes_text, no_text, base::string16()); | 296 yes_text, no_text, base::string16()); |
| 281 } | 297 } |
| 282 | 298 |
| 283 } // namespace chrome | 299 } // namespace chrome |
| OLD | NEW |