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