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