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