Chromium Code Reviews| Index: chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.mm |
| diff --git a/chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.mm b/chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.mm |
| index f043fad5a0c019634695a187d725aec839d59d58..d0fb9375de1f2bfec2c60381c414e91df36630a9 100644 |
| --- a/chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.mm |
| +++ b/chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.mm |
| @@ -9,34 +9,56 @@ |
| #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" |
| #import "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h" |
| #include "components/guest_view/browser/guest_view_base.h" |
| -#include "components/web_modal/web_contents_modal_dialog_manager.h" |
| #include "content/public/browser/browser_thread.h" |
| using web_modal::WebContentsModalDialogManager; |
| +ConstrainedWindowMac* CreateAndShowWebModalDialogMac( |
| + ConstrainedWindowMacDelegate* delegate, |
| + content::WebContents* web_contents, |
| + id<ConstrainedWindowSheet> sheet) { |
| + ConstrainedWindowMac* window = |
| + new ConstrainedWindowMac(delegate, web_contents, sheet); |
| + window->ShowWebContentsModalDialog(); |
| + return window; |
| +} |
| + |
| +ConstrainedWindowMac* CreateWebModalDialogMac( |
| + ConstrainedWindowMacDelegate* delegate, |
| + content::WebContents* web_contents, |
| + id<ConstrainedWindowSheet> sheet) { |
| + return new ConstrainedWindowMac(delegate, web_contents, sheet); |
| +} |
| + |
| ConstrainedWindowMac::ConstrainedWindowMac( |
| ConstrainedWindowMacDelegate* delegate, |
| content::WebContents* web_contents, |
| id<ConstrainedWindowSheet> sheet) |
| - : delegate_(delegate) { |
| + : delegate_(delegate), |
| + sheet_(sheet) { |
|
erikchen
2015/11/12 22:14:57
You probably want [sheet retain] here.
apacible
2015/11/13 00:04:01
Done.
|
| DCHECK(sheet); |
| // |web_contents| may be embedded within a chain of nested GuestViews. If it |
| // is, follow the chain of embedders to the outermost WebContents and use it. |
| - web_contents = |
| + web_contents_ = |
| guest_view::GuestViewBase::GetTopLevelWebContents(web_contents); |
| - auto manager = WebContentsModalDialogManager::FromWebContents(web_contents); |
| - scoped_ptr<SingleWebContentsDialogManagerCocoa> native_manager( |
| - new SingleWebContentsDialogManagerCocoa(this, sheet, manager)); |
| - manager->ShowDialogWithManager([sheet sheetWindow], native_manager.Pass()); |
| + native_manager_.reset( |
| + new SingleWebContentsDialogManagerCocoa(this, sheet_.get(), |
| + GetDialogManager())); |
| } |
| ConstrainedWindowMac::~ConstrainedWindowMac() { |
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + native_manager_.reset(); |
| DCHECK(!manager_); |
| } |
| +void ConstrainedWindowMac::ShowWebContentsModalDialog() { |
| + GetDialogManager()->ShowDialogWithManager( |
| + [sheet_.release() sheetWindow], native_manager_.Pass()); |
|
erikchen
2015/11/12 22:14:57
This will leak a reference to the sheet, which is
apacible
2015/11/13 00:04:01
Done.
|
| +} |
| + |
| void ConstrainedWindowMac::CloseWebContentsModalDialog() { |
| if (manager_) |
| manager_->Close(); |
| @@ -46,3 +68,8 @@ void ConstrainedWindowMac::OnDialogClosing() { |
| if (delegate_) |
| delegate_->OnConstrainedWindowClosed(this); |
| } |
| + |
| +WebContentsModalDialogManager* ConstrainedWindowMac::GetDialogManager() { |
| + DCHECK(web_contents_); |
| + return WebContentsModalDialogManager::FromWebContents(web_contents_); |
| +} |