]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Fix detecting attached modal dialog.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 10 Feb 2014 12:07:38 +0000 (20:07 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 10 Feb 2014 12:07:38 +0000 (20:07 +0800)
browser/native_window.cc
browser/native_window.h
browser/native_window_win.cc
browser/native_window_win.h
browser/ui/file_dialog_win.cc
browser/ui/message_box_win.cc

index c81625c367d6cc36b13a8948ce89a6f98ff70459..7c47c3122b188639508d577cc779f6e5ba7990a6 100644 (file)
@@ -49,6 +49,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
       has_frame_(true),
       is_closed_(false),
       node_integration_("all"),
+      has_dialog_attached_(false),
       weak_factory_(this),
       inspectable_web_contents_(
           brightray::InspectableWebContents::Create(web_contents)) {
@@ -158,6 +159,10 @@ void NativeWindow::InitFromOptions(base::DictionaryValue* options) {
     Show();
 }
 
+bool NativeWindow::HasModalDialog() {
+  return has_dialog_attached_;
+}
+
 void NativeWindow::OpenDevTools() {
   inspectable_web_contents()->ShowDevTools();
 }
index ad6e8a152b76d7ccb3a1993eb15ba1c177b53f1f..0e802fd110d977b155683e751ba82bcce88d05a6 100644 (file)
@@ -54,6 +54,25 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   typedef base::Callback<void(const std::vector<unsigned char>& buffer)>
       CapturePageCallback;
 
+  class DialogScope {
+   public:
+    DialogScope(NativeWindow* window)
+        : window_(window) {
+      if (window_ != NULL)
+        window_->set_has_dialog_attached(true);
+    }
+
+    ~DialogScope() {
+      if (window_ != NULL)
+        window_->set_has_dialog_attached(false);
+    }
+
+   private:
+    NativeWindow* window_;
+
+    DISALLOW_COPY_AND_ASSIGN(DialogScope);
+  };
+
   virtual ~NativeWindow();
 
   // Create window with existing WebContents.
@@ -100,7 +119,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual void FlashFrame(bool flash) = 0;
   virtual void SetKiosk(bool kiosk) = 0;
   virtual bool IsKiosk() = 0;
-  virtual bool HasModalDialog() = 0;
+  virtual bool HasModalDialog();
   virtual gfx::NativeWindow GetNativeWindow() = 0;
 
   virtual bool IsClosed() const { return is_closed_; }
@@ -142,6 +161,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   bool has_frame() const { return has_frame_; }
   std::string node_integration() const { return node_integration_; }
 
+  void set_has_dialog_attached(bool has_dialog_attached) {
+    has_dialog_attached_ = has_dialog_attached;
+  }
+
  protected:
   explicit NativeWindow(content::WebContents* web_contents,
                         base::DictionaryValue* options);
@@ -223,6 +246,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   // The security token of iframe.
   std::string node_integration_;
 
+  // There is a dialog that has been attached to window.
+  bool has_dialog_attached_;
+
   // Closure that would be called when window is unresponsive when closing,
   // it should be cancelled when we can prove that the window is responsive.
   base::CancelableClosure window_unresposive_closure_;
index 2bbe78e90b38ba7ad0ca76f46c8208c776f9599e..fefe1b2b98a295b008ba570ea4c635769153f655 100644 (file)
@@ -194,17 +194,6 @@ class NativeWindowFramelessView : public views::NonClientFrameView {
   DISALLOW_COPY_AND_ASSIGN(NativeWindowFramelessView);
 };
 
-bool WindowHasModalDialog(HWND parent, HWND except, HWND after = NULL) {
-  HWND hwnd = ::FindWindowEx(parent, after, NULL, NULL);
-  if (hwnd != except &&
-      (::GetWindowLong(hwnd, GWL_STYLE) & (WS_VISIBLE | WS_POPUP)))
-    return true;
-  else if (hwnd == NULL)
-    return false;
-  else
-    return WindowHasModalDialog(parent, except, hwnd);
-}
-
 }  // namespace
 
 NativeWindowWin::NativeWindowWin(content::WebContents* web_contents,
@@ -370,11 +359,6 @@ bool NativeWindowWin::IsKiosk() {
   return IsFullscreen();
 }
 
-bool NativeWindowWin::HasModalDialog() {
-  return WindowHasModalDialog(GetNativeWindow(),
-                              GetWebContents()->GetView()->GetNativeView());
-}
-
 gfx::NativeWindow NativeWindowWin::GetNativeWindow() {
   return window_->GetNativeView();
 }
index d7f58f55e14b3c3211e2d6cfede9722dfd87c366..738c98d68a4022fcd5060b6cd4173465a1e92761 100644 (file)
@@ -65,7 +65,6 @@ class NativeWindowWin : public NativeWindow,
   virtual void FlashFrame(bool flash) OVERRIDE;
   virtual void SetKiosk(bool kiosk) OVERRIDE;
   virtual bool IsKiosk() OVERRIDE;
-  virtual bool HasModalDialog() OVERRIDE;
   virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
 
   void OnMenuCommand(int position, HMENU menu);
index 1f806dd5380f18affa5c3798ceaa7baa75c081ed..b8b8233db9f4a4aa147e90ee642a5a6375072773 100644 (file)
@@ -163,6 +163,7 @@ class FileDialog {
   }
 
   bool Show(atom::NativeWindow* parent_window) {
+    atom::NativeWindow::DialogScope dialog_scope(parent_window);
     HWND window = parent_window ? parent_window->GetNativeWindow() : NULL;
     return dialog_->DoModal(window) == IDOK;
   }
index d7714931174a375a58d47ba5dbc1928b3ba28d4b..c7a61b8edbb78e2f6897456e94207a150f1b3c26 100644 (file)
@@ -76,6 +76,7 @@ class MessageDialog : public base::MessageLoop::Dispatcher,
   string16 title_;
   views::Widget* widget_;
   views::MessageBoxView* message_box_view_;
+  scoped_ptr<NativeWindow::DialogScope> dialog_scope_;
   std::vector<views::LabelButton*> buttons_;
   MessageBoxCallback callback_;
 
@@ -96,7 +97,8 @@ MessageDialog::MessageDialog(NativeWindow* parent_window,
       result_(-1),
       title_(UTF8ToUTF16(title)),
       widget_(NULL),
-      message_box_view_(NULL) {
+      message_box_view_(NULL),
+      dialog_scope_(new NativeWindow::DialogScope(parent_window)) {
   DCHECK_GT(buttons.size(), 0u);
   set_owned_by_client();
 
@@ -174,6 +176,7 @@ string16 MessageDialog::GetWindowTitle() const {
 
 void MessageDialog::WindowClosing() {
   should_close_ = true;
+  dialog_scope_.reset();
 
   if (delete_on_close_) {
     callback_.Run(GetResult());