Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / simple_message_box_views.cc
index 4203532..29d9e6d 100644 (file)
@@ -33,6 +33,7 @@ class SimpleMessageBoxViews : public views::DialogDelegate {
                         MessageBoxType type,
                         const base::string16& yes_text,
                         const base::string16& no_text,
+                        bool is_system_modal,
                         MessageBoxResult* result);
   virtual ~SimpleMessageBoxViews();
 
@@ -61,6 +62,7 @@ class SimpleMessageBoxViews : public views::DialogDelegate {
   base::string16 yes_text_;
   base::string16 no_text_;
   MessageBoxResult* result_;
+  bool is_system_modal_;
   views::MessageBoxView* message_box_view_;
 
   DISALLOW_COPY_AND_ASSIGN(SimpleMessageBoxViews);
@@ -74,12 +76,14 @@ SimpleMessageBoxViews::SimpleMessageBoxViews(const base::string16& title,
                                              MessageBoxType type,
                                              const base::string16& yes_text,
                                              const base::string16& no_text,
+                                             bool is_system_modal,
                                              MessageBoxResult* result)
     : window_title_(title),
       type_(type),
       yes_text_(yes_text),
       no_text_(no_text),
       result_(result),
+      is_system_modal_(is_system_modal),
       message_box_view_(new views::MessageBoxView(
           views::MessageBoxView::InitParams(message))) {
   CHECK(result_);
@@ -142,7 +146,7 @@ void SimpleMessageBoxViews::DeleteDelegate() {
 }
 
 ui::ModalType SimpleMessageBoxViews::GetModalType() const {
-  return ui::MODAL_TYPE_WINDOW;
+  return is_system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_WINDOW;
 }
 
 views::View* SimpleMessageBoxViews::GetContentsView() {
@@ -191,24 +195,35 @@ MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent,
                                     MessageBoxType type,
                                     const base::string16& yes_text,
                                     const base::string16& no_text) {
+  // Views dialogs cannot be shown outside the UI thread message loop.
+  // Fallback to logging with a default response or a Windows MessageBox.
+  if (!base::MessageLoopForUI::IsCurrent() ||
+      !base::MessageLoopForUI::current()->is_running()) {
 #if defined(OS_WIN)
-  // GPU-based dialogs can't be used early on; fallback to a Windows MessageBox.
-  if (!base::MessageLoop::current()->is_running()) {
     int result = ui::MessageBox(views::HWNDForNativeWindow(parent), message,
                                 title, GetMessageBoxFlagsFromType(type));
     return (result == IDYES || result == IDOK) ?
         MESSAGE_BOX_RESULT_YES : MESSAGE_BOX_RESULT_NO;
-  }
+#else
+    LOG(ERROR) << "Unable to show a dialog outside the UI thread message loop: "
+               << title << " - " << message;
+    return MESSAGE_BOX_RESULT_NO;
 #endif
+  }
 
   MessageBoxResult result = MESSAGE_BOX_RESULT_NO;
   SimpleMessageBoxViews* dialog = new SimpleMessageBoxViews(
-      title, message, type, yes_text, no_text, &result);
+      title,
+      message,
+      type,
+      yes_text,
+      no_text,
+      parent == NULL,  // is_system_modal
+      &result);
   CreateBrowserModalDialogViews(dialog, parent)->Show();
 
-  // Use the widget's window itself so that the message loop
-  // exists when the dialog is closed by some other means than
-  // |Cancel| or |Accept|.
+  // Use the widget's window itself so that the message loop exists when the
+  // dialog is closed by some other means than |Cancel| or |Accept|.
   aura::Window* anchor = dialog->GetWidget()->GetNativeWindow();
   aura::client::DispatcherClient* client =
       aura::client::GetDispatcherClient(anchor->GetRootWindow());