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 fbed7d9068997964eca32f356caa67c21baa4981..8deeebc76fac75a1d1cf8f6a64aaa267f072d795 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 @@ |
// destroyed before a box in an outer-loop. So to avoid this, ref-counting is |
// used so that the SimpleMessageBoxViews gets deleted at the right time. |
class SimpleMessageBoxViews : public views::DialogDelegate, |
+ public base::MessagePumpDispatcher, |
public base::RefCounted<SimpleMessageBoxViews> { |
public: |
SimpleMessageBoxViews(const base::string16& title, |
@@ -62,12 +63,12 @@ |
virtual views::Widget* GetWidget() OVERRIDE; |
virtual const views::Widget* GetWidget() const OVERRIDE; |
+ // Overridden from MessagePumpDispatcher: |
+ virtual uint32_t Dispatch(const base::NativeEvent& event) OVERRIDE; |
+ |
private: |
friend class base::RefCounted<SimpleMessageBoxViews>; |
virtual ~SimpleMessageBoxViews(); |
- |
- // This terminates the nested message-loop. |
- void Done(); |
const base::string16 window_title_; |
const MessageBoxType type_; |
@@ -75,6 +76,10 @@ |
base::string16 no_text_; |
MessageBoxResult result_; |
views::MessageBoxView* message_box_view_; |
+ |
+ // Set to false as soon as the user clicks a dialog button; this tells the |
+ // dispatcher we're done. |
+ bool should_show_dialog_; |
DISALLOW_COPY_AND_ASSIGN(SimpleMessageBoxViews); |
}; |
@@ -93,7 +98,8 @@ |
no_text_(no_text), |
result_(MESSAGE_BOX_RESULT_NO), |
message_box_view_(new views::MessageBoxView( |
- views::MessageBoxView::InitParams(message))) { |
+ views::MessageBoxView::InitParams(message))), |
+ should_show_dialog_(true) { |
AddRef(); |
if (yes_text_.empty()) { |
@@ -132,14 +138,14 @@ |
} |
bool SimpleMessageBoxViews::Cancel() { |
+ should_show_dialog_= false; |
result_ = MESSAGE_BOX_RESULT_NO; |
- Done(); |
return true; |
} |
bool SimpleMessageBoxViews::Accept() { |
+ should_show_dialog_ = false; |
result_ = MESSAGE_BOX_RESULT_YES; |
- Done(); |
return true; |
} |
@@ -165,6 +171,13 @@ |
const views::Widget* SimpleMessageBoxViews::GetWidget() const { |
return message_box_view_->GetWidget(); |
+} |
+ |
+uint32_t SimpleMessageBoxViews::Dispatch(const base::NativeEvent& event) { |
+ uint32_t action = POST_DISPATCH_PERFORM_DEFAULT; |
+ if (!should_show_dialog_) |
+ action |= POST_DISPATCH_QUIT_LOOP; |
+ return action; |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -190,13 +203,6 @@ |
return flags | MB_OK | MB_ICONWARNING; |
} |
#endif |
- |
-void SimpleMessageBoxViews::Done() { |
- aura::Window* window = GetWidget()->GetNativeView(); |
- aura::client::DispatcherClient* client = |
- aura::client::GetDispatcherClient(window->GetRootWindow()); |
- client->QuitNestedMessageLoop(); |
-} |
MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent, |
const base::string16& title, |
@@ -228,7 +234,7 @@ |
anchor = dialog->GetWidget()->GetNativeWindow(); |
client = aura::client::GetDispatcherClient(anchor->GetRootWindow()); |
} |
- client->RunWithDispatcher(NULL, anchor); |
+ client->RunWithDispatcher(dialog.get(), anchor); |
return dialog->result(); |
} |