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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" | 9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" |
10 #import "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h" | 10 #import "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h" |
11 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 11 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "extensions/browser/guest_view/guest_view_base.h" | 13 #include "extensions/browser/guest_view/guest_view_base.h" |
14 | 14 |
15 using web_modal::WebContentsModalDialogManager; | 15 using web_modal::WebContentsModalDialogManager; |
16 | 16 |
17 ConstrainedWindowMac::ConstrainedWindowMac( | 17 ConstrainedWindowMac::ConstrainedWindowMac( |
18 ConstrainedWindowMacDelegate* delegate, | 18 ConstrainedWindowMacDelegate* delegate, |
19 content::WebContents* web_contents, | 19 content::WebContents* web_contents, |
20 id<ConstrainedWindowSheet> sheet) | 20 id<ConstrainedWindowSheet> sheet) |
21 : delegate_(delegate) { | 21 : delegate_(delegate) { |
22 DCHECK(sheet); | 22 DCHECK(sheet); |
23 extensions::GuestViewBase* guest_view = | 23 |
24 extensions::GuestViewBase::FromWebContents(web_contents); | 24 // |web_contents| may be embedded within a chain of nested GuestViews. If it |
25 // For embedded WebContents, use the embedder's WebContents for constrained | 25 // is, follow the chain of embedders to the outermost WebContents and use it. |
26 // window. | 26 while (extensions::GuestViewBase* guest_view = |
Fady Samuel
2015/03/26 01:43:02
Drive by comment: This pattern has started emergin
| |
27 web_contents = guest_view && guest_view->embedder_web_contents() ? | 27 extensions::GuestViewBase::FromWebContents(web_contents)) { |
28 guest_view->embedder_web_contents() : web_contents; | 28 if (!guest_view->embedder_web_contents()) |
29 break; | |
30 web_contents = guest_view->embedder_web_contents(); | |
31 } | |
29 | 32 |
30 auto manager = WebContentsModalDialogManager::FromWebContents(web_contents); | 33 auto manager = WebContentsModalDialogManager::FromWebContents(web_contents); |
31 scoped_ptr<SingleWebContentsDialogManagerCocoa> native_manager( | 34 scoped_ptr<SingleWebContentsDialogManagerCocoa> native_manager( |
32 new SingleWebContentsDialogManagerCocoa(this, sheet, manager)); | 35 new SingleWebContentsDialogManagerCocoa(this, sheet, manager)); |
33 manager->ShowDialogWithManager([sheet sheetWindow], native_manager.Pass()); | 36 manager->ShowDialogWithManager([sheet sheetWindow], native_manager.Pass()); |
34 } | 37 } |
35 | 38 |
36 ConstrainedWindowMac::~ConstrainedWindowMac() { | 39 ConstrainedWindowMac::~ConstrainedWindowMac() { |
37 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 40 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
38 DCHECK(!manager_); | 41 DCHECK(!manager_); |
39 } | 42 } |
40 | 43 |
41 void ConstrainedWindowMac::CloseWebContentsModalDialog() { | 44 void ConstrainedWindowMac::CloseWebContentsModalDialog() { |
42 if (manager_) | 45 if (manager_) |
43 manager_->Close(); | 46 manager_->Close(); |
44 } | 47 } |
45 | 48 |
46 void ConstrainedWindowMac::OnDialogClosing() { | 49 void ConstrainedWindowMac::OnDialogClosing() { |
47 if (delegate_) | 50 if (delegate_) |
48 delegate_->OnConstrainedWindowClosed(this); | 51 delegate_->OnConstrainedWindowClosed(this); |
49 } | 52 } |
OLD | NEW |