Index: chrome/browser/ui/cocoa/constrained_window_mac.mm |
diff --git a/chrome/browser/ui/cocoa/constrained_window_mac.mm b/chrome/browser/ui/cocoa/constrained_window_mac.mm |
index 1d018f160838b2dc24cbd176e3f4a787908aaef2..d826dc3d0b36054ec1ba316c04d44a64d1ff3030 100644 |
--- a/chrome/browser/ui/cocoa/constrained_window_mac.mm |
+++ b/chrome/browser/ui/cocoa/constrained_window_mac.mm |
@@ -4,7 +4,6 @@ |
#include "chrome/browser/ui/cocoa/constrained_window_mac.h" |
-#import "chrome/browser/ui/cocoa/browser_window_controller.h" |
#include "chrome/browser/ui/constrained_window_tab_helper.h" |
#include "chrome/browser/ui/tab_contents/tab_contents.h" |
#include "content/public/browser/web_contents.h" |
@@ -105,12 +104,26 @@ void ConstrainedWindowMac::ShowConstrainedWindow() { |
// The WebContents only has a native window if it is currently visible. In |
// this case, open the sheet now. Else, Realize() will be called later, when |
// our tab becomes visible. |
- NSWindow* browserWindow = |
+ NSWindow* window = |
tab_contents_->web_contents()->GetView()->GetTopLevelNativeWindow(); |
- BrowserWindowController* browser_controller = |
- [BrowserWindowController browserWindowControllerForWindow:browserWindow]; |
- if ([browser_controller canAttachConstrainedWindow]) |
- Realize(browser_controller); |
+ NSWindowController<ConstrainedWindowSupport>* window_controller = nil; |
+ while (window) { |
+ if ([[window windowController] conformsToProtocol: |
+ @protocol(ConstrainedWindowSupport)]) { |
+ window_controller = [window windowController]; |
+ break; |
+ } |
+ window = [window parentWindow]; |
+ } |
+ |
+ // It's valid for the window to be nil. For example, background tabs don't |
+ // have a window set. However, if a window exists then there should always |
+ // be a window controller that implements the ConstrainedWindowSupport |
+ // protocol. |
+ DCHECK(!window || window_controller); |
+ |
+ if ([window_controller canAttachConstrainedWindow]) |
+ Realize(window_controller); |
} |
void ConstrainedWindowMac::CloseConstrainedWindow() { |
@@ -131,7 +144,8 @@ void ConstrainedWindowMac::CloseConstrainedWindow() { |
delete this; |
} |
-void ConstrainedWindowMac::Realize(BrowserWindowController* controller) { |
+void ConstrainedWindowMac::Realize( |
+ NSWindowController<ConstrainedWindowSupport>* controller) { |
if (!should_be_visible_) |
return; |