OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" | 5 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
8 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
9 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" | 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" |
11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 13 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
13 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 14 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 | 17 |
17 using web_modal::WebContentsModalDialogManager; | 18 using web_modal::WebContentsModalDialogManager; |
18 using web_modal::NativeWebContentsModalDialog; | 19 using web_modal::NativeWebContentsModalDialog; |
19 | 20 |
20 ConstrainedWindowMac::ConstrainedWindowMac( | 21 ConstrainedWindowMac::ConstrainedWindowMac( |
21 ConstrainedWindowMacDelegate* delegate, | 22 ConstrainedWindowMacDelegate* delegate, |
22 content::WebContents* web_contents, | 23 content::WebContents* web_contents, |
23 id<ConstrainedWindowSheet> sheet) | 24 id<ConstrainedWindowSheet> sheet) |
24 : delegate_(delegate), | 25 : delegate_(delegate), |
25 web_contents_(web_contents), | 26 web_contents_(NULL), |
26 sheet_([sheet retain]), | 27 sheet_([sheet retain]), |
27 shown_(false) { | 28 shown_(false) { |
28 DCHECK(web_contents); | 29 DCHECK(web_contents); |
| 30 WebViewGuest* web_view_guest = WebViewGuest::FromWebContents(web_contents); |
| 31 // For embedded WebContents, use the embedder's WebContents for constrained |
| 32 // window. |
| 33 web_contents_ = web_view_guest && web_view_guest->embedder_web_contents() ? |
| 34 web_view_guest->embedder_web_contents() : web_contents; |
29 DCHECK(sheet_.get()); | 35 DCHECK(sheet_.get()); |
30 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 36 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
31 WebContentsModalDialogManager::FromWebContents(web_contents); | 37 WebContentsModalDialogManager::FromWebContents(web_contents_); |
32 web_contents_modal_dialog_manager->ShowModalDialog(this); | 38 web_contents_modal_dialog_manager->ShowModalDialog(this); |
33 } | 39 } |
34 | 40 |
35 ConstrainedWindowMac::~ConstrainedWindowMac() { | 41 ConstrainedWindowMac::~ConstrainedWindowMac() { |
36 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 42 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
37 } | 43 } |
38 | 44 |
39 void ConstrainedWindowMac::ShowWebContentsModalDialog() { | 45 void ConstrainedWindowMac::ShowWebContentsModalDialog() { |
40 if (shown_) | 46 if (shown_) |
41 return; | 47 return; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 90 |
85 NSWindow* ConstrainedWindowMac::GetParentWindow() const { | 91 NSWindow* ConstrainedWindowMac::GetParentWindow() const { |
86 // Tab contents in a tabbed browser may not be inside a window. For this | 92 // Tab contents in a tabbed browser may not be inside a window. For this |
87 // reason use a browser window if possible. | 93 // reason use a browser window if possible. |
88 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 94 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
89 if (browser) | 95 if (browser) |
90 return browser->window()->GetNativeWindow(); | 96 return browser->window()->GetNativeWindow(); |
91 | 97 |
92 return web_contents_->GetTopLevelNativeWindow(); | 98 return web_contents_->GetTopLevelNativeWindow(); |
93 } | 99 } |
OLD | NEW |