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