| 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 "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.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/guest_view/browser/guest_view_base.h" | 11 #include "components/guest_view/browser/guest_view_base.h" |
| 12 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 13 | 14 |
| 14 using web_modal::WebContentsModalDialogManager; | 15 using web_modal::WebContentsModalDialogManager; |
| 15 | 16 |
| 16 ConstrainedWindowMac* CreateAndShowWebModalDialogMac( | |
| 17 ConstrainedWindowMacDelegate* delegate, | |
| 18 content::WebContents* web_contents, | |
| 19 id<ConstrainedWindowSheet> sheet) { | |
| 20 ConstrainedWindowMac* window = | |
| 21 new ConstrainedWindowMac(delegate, web_contents, sheet); | |
| 22 window->ShowWebContentsModalDialog(); | |
| 23 return window; | |
| 24 } | |
| 25 | |
| 26 ConstrainedWindowMac* CreateWebModalDialogMac( | |
| 27 ConstrainedWindowMacDelegate* delegate, | |
| 28 content::WebContents* web_contents, | |
| 29 id<ConstrainedWindowSheet> sheet) { | |
| 30 return new ConstrainedWindowMac(delegate, web_contents, sheet); | |
| 31 } | |
| 32 | |
| 33 ConstrainedWindowMac::ConstrainedWindowMac( | 17 ConstrainedWindowMac::ConstrainedWindowMac( |
| 34 ConstrainedWindowMacDelegate* delegate, | 18 ConstrainedWindowMacDelegate* delegate, |
| 35 content::WebContents* web_contents, | 19 content::WebContents* web_contents, |
| 36 id<ConstrainedWindowSheet> sheet) | 20 id<ConstrainedWindowSheet> sheet) |
| 37 : delegate_(delegate), | 21 : delegate_(delegate) { |
| 38 sheet_([sheet retain]) { | |
| 39 DCHECK(sheet); | 22 DCHECK(sheet); |
| 40 | 23 |
| 41 // |web_contents| may be embedded within a chain of nested GuestViews. If it | 24 // |web_contents| may be embedded within a chain of nested GuestViews. If it |
| 42 // is, follow the chain of embedders to the outermost WebContents and use it. | 25 // is, follow the chain of embedders to the outermost WebContents and use it. |
| 43 web_contents_ = | 26 web_contents = |
| 44 guest_view::GuestViewBase::GetTopLevelWebContents(web_contents); | 27 guest_view::GuestViewBase::GetTopLevelWebContents(web_contents); |
| 45 | 28 |
| 46 native_manager_.reset( | 29 auto manager = WebContentsModalDialogManager::FromWebContents(web_contents); |
| 47 new SingleWebContentsDialogManagerCocoa(this, sheet_.get(), | 30 scoped_ptr<SingleWebContentsDialogManagerCocoa> native_manager( |
| 48 GetDialogManager())); | 31 new SingleWebContentsDialogManagerCocoa(this, sheet, manager)); |
| 32 manager->ShowDialogWithManager([sheet sheetWindow], native_manager.Pass()); |
| 49 } | 33 } |
| 50 | 34 |
| 51 ConstrainedWindowMac::~ConstrainedWindowMac() { | 35 ConstrainedWindowMac::~ConstrainedWindowMac() { |
| 52 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 36 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 53 native_manager_.reset(); | |
| 54 DCHECK(!manager_); | 37 DCHECK(!manager_); |
| 55 } | 38 } |
| 56 | 39 |
| 57 void ConstrainedWindowMac::ShowWebContentsModalDialog() { | |
| 58 GetDialogManager()->ShowDialogWithManager( | |
| 59 [sheet_.get() sheetWindow], native_manager_.Pass()); | |
| 60 } | |
| 61 | |
| 62 void ConstrainedWindowMac::CloseWebContentsModalDialog() { | 40 void ConstrainedWindowMac::CloseWebContentsModalDialog() { |
| 63 if (manager_) | 41 if (manager_) |
| 64 manager_->Close(); | 42 manager_->Close(); |
| 65 } | 43 } |
| 66 | 44 |
| 67 void ConstrainedWindowMac::OnDialogClosing() { | 45 void ConstrainedWindowMac::OnDialogClosing() { |
| 68 if (delegate_) | 46 if (delegate_) |
| 69 delegate_->OnConstrainedWindowClosed(this); | 47 delegate_->OnConstrainedWindowClosed(this); |
| 70 } | 48 } |
| 71 | |
| 72 WebContentsModalDialogManager* ConstrainedWindowMac::GetDialogManager() { | |
| 73 DCHECK(web_contents_); | |
| 74 return WebContentsModalDialogManager::FromWebContents(web_contents_); | |
| 75 } | |
| OLD | NEW |