win: Fix detecting attached modal dialog.

This commit is contained in:
Cheng Zhao 2014-02-10 20:07:38 +08:00
parent f4a2c12d75
commit 9ba7db8815
6 changed files with 37 additions and 19 deletions

View 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();
}

View 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_;

View 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();
}

View 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);

View 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;
}

View 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());