Index: chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.mm |
diff --git a/chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.mm b/chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.mm |
index 11d1166877c382f98d1e9cd9013c7268f1089ebf..9e4889049b0bd6543639ae950cb5671518c23d7d 100644 |
--- a/chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.mm |
+++ b/chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.mm |
@@ -10,6 +10,8 @@ |
#include "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h" |
#include "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
#include "chrome/browser/ui/constrained_window_tab_helper.h" |
+#include "content/public/browser/notification_source.h" |
+#include "content/public/browser/notification_types.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/browser/web_contents_view.h" |
@@ -19,12 +21,17 @@ ConstrainedWindowMac2::ConstrainedWindowMac2( |
NSWindow* window) |
: delegate_(delegate), |
web_contents_(web_contents), |
- window_([window retain]) { |
+ window_([window retain]), |
+ pending_show_(false) { |
DCHECK(web_contents); |
DCHECK(window_.get()); |
ConstrainedWindowTabHelper* constrained_window_tab_helper = |
ConstrainedWindowTabHelper::FromWebContents(web_contents); |
constrained_window_tab_helper->AddConstrainedDialog(this); |
+ |
+ registrar_.Add(this, |
+ content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
+ content::Source<content::WebContents>(web_contents)); |
} |
ConstrainedWindowMac2::~ConstrainedWindowMac2() { |
@@ -32,11 +39,11 @@ ConstrainedWindowMac2::~ConstrainedWindowMac2() { |
void ConstrainedWindowMac2::ShowConstrainedWindow() { |
NSWindow* parent_window = GetParentWindow(); |
- if (!parent_window) |
- return; |
- |
NSView* parent_view = GetSheetParentViewForWebContents(web_contents_); |
- DCHECK(parent_view); |
+ if (!parent_window || !parent_view) { |
+ pending_show_ = true; |
+ return; |
+ } |
ConstrainedWindowSheetController* controller = |
[ConstrainedWindowSheetController |
@@ -45,6 +52,10 @@ void ConstrainedWindowMac2::ShowConstrainedWindow() { |
} |
void ConstrainedWindowMac2::CloseConstrainedWindow() { |
+ // This function may be called even if the constrained window was never shown. |
+ // Unset |pending_show_| to prevent the window from being reshown. |
+ pending_show_ = false; |
+ |
[[ConstrainedWindowSheetController controllerForSheet:window_] |
closeSheet:window_]; |
ConstrainedWindowTabHelper* constrained_window_tab_helper = |
@@ -70,6 +81,21 @@ bool ConstrainedWindowMac2::CanShowConstrainedWindow() { |
return !browser->window()->IsInstantTabShowing(); |
} |
+void ConstrainedWindowMac2::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ if (type != content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ if (pending_show_) { |
+ pending_show_ = false; |
+ ShowConstrainedWindow(); |
+ } |
+} |
+ |
NSWindow* ConstrainedWindowMac2::GetParentWindow() const { |
// Tab contents in a tabbed browser may not be inside a window. For this |
// reason use a browser window if possible. |