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/memory/scoped_ptr.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "chrome/browser/ui/browser_finder.h" | |
9 #include "chrome/browser/ui/browser_window.h" | |
10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" | 9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" |
11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 10 #import "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h" |
12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | |
13 #include "components/web_modal/popup_manager.h" | |
14 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 11 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
15 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/web_contents.h" | |
17 #include "extensions/browser/guest_view/guest_view_base.h" | 13 #include "extensions/browser/guest_view/guest_view_base.h" |
18 | 14 |
19 using web_modal::WebContentsModalDialogManager; | 15 using web_modal::WebContentsModalDialogManager; |
20 using web_modal::NativeWebContentsModalDialog; | |
21 | 16 |
22 ConstrainedWindowMac::ConstrainedWindowMac( | 17 ConstrainedWindowMac::ConstrainedWindowMac( |
23 ConstrainedWindowMacDelegate* delegate, | 18 ConstrainedWindowMacDelegate* delegate, |
24 content::WebContents* web_contents, | 19 content::WebContents* web_contents, |
25 id<ConstrainedWindowSheet> sheet) | 20 id<ConstrainedWindowSheet> sheet) |
26 : delegate_(delegate), | 21 : delegate_(delegate) { |
27 web_contents_(NULL), | 22 DCHECK(sheet); |
28 sheet_([sheet retain]), | |
29 shown_(false) { | |
30 DCHECK(web_contents); | |
31 extensions::GuestViewBase* guest_view = | 23 extensions::GuestViewBase* guest_view = |
32 extensions::GuestViewBase::FromWebContents(web_contents); | 24 extensions::GuestViewBase::FromWebContents(web_contents); |
33 // For embedded WebContents, use the embedder's WebContents for constrained | 25 // For embedded WebContents, use the embedder's WebContents for constrained |
34 // window. | 26 // window. |
35 web_contents_ = guest_view && guest_view->embedder_web_contents() ? | 27 web_contents = guest_view && guest_view->embedder_web_contents() ? |
36 guest_view->embedder_web_contents() : web_contents; | 28 guest_view->embedder_web_contents() : web_contents; |
37 DCHECK(sheet_.get()); | 29 |
38 web_modal::PopupManager* popup_manager = | 30 auto manager = WebContentsModalDialogManager::FromWebContents(web_contents); |
39 web_modal::PopupManager::FromWebContents(web_contents_); | 31 scoped_ptr<SingleWebContentsDialogManagerCocoa> native_manager( |
40 if (popup_manager) | 32 new SingleWebContentsDialogManagerCocoa(this, sheet, manager)); |
41 popup_manager->ShowModalDialog(this, web_contents_); | 33 manager->ShowDialogWithManager([sheet sheetWindow], native_manager.Pass()); |
42 } | 34 } |
43 | 35 |
44 ConstrainedWindowMac::~ConstrainedWindowMac() { | 36 ConstrainedWindowMac::~ConstrainedWindowMac() { |
45 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 37 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
46 } | 38 DCHECK(!manager_); |
47 | |
48 void ConstrainedWindowMac::ShowWebContentsModalDialog() { | |
49 if (shown_) | |
50 return; | |
51 | |
52 NSWindow* parent_window = web_contents_->GetTopLevelNativeWindow(); | |
53 NSView* parent_view = GetSheetParentViewForWebContents(web_contents_); | |
54 if (!parent_window || !parent_view) | |
55 return; | |
56 | |
57 shown_ = true; | |
58 ConstrainedWindowSheetController* controller = | |
59 [ConstrainedWindowSheetController | |
60 controllerForParentWindow:parent_window]; | |
61 [controller showSheet:sheet_ forParentView:parent_view]; | |
62 } | 39 } |
63 | 40 |
64 void ConstrainedWindowMac::CloseWebContentsModalDialog() { | 41 void ConstrainedWindowMac::CloseWebContentsModalDialog() { |
65 [[ConstrainedWindowSheetController controllerForSheet:sheet_] | 42 if (manager_) |
66 closeSheet:sheet_]; | 43 manager_->Close(); |
67 // TODO(gbillock): get this object in config, not from a global. | 44 } |
68 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | |
69 WebContentsModalDialogManager::FromWebContents(web_contents_); | |
70 | 45 |
71 // Will result in the delegate being deleted. | 46 void ConstrainedWindowMac::OnDialogClosing() { |
72 if (delegate_) | 47 if (delegate_) |
73 delegate_->OnConstrainedWindowClosed(this); | 48 delegate_->OnConstrainedWindowClosed(this); |
74 | |
75 // Will cause this object to be deleted. | |
76 web_contents_modal_dialog_manager->WillClose(this); | |
77 } | 49 } |
78 | |
79 void ConstrainedWindowMac::FocusWebContentsModalDialog() { | |
80 } | |
81 | |
82 void ConstrainedWindowMac::PulseWebContentsModalDialog() { | |
83 [[ConstrainedWindowSheetController controllerForSheet:sheet_] | |
84 pulseSheet:sheet_]; | |
85 } | |
86 | |
87 NativeWebContentsModalDialog ConstrainedWindowMac::GetNativeDialog() { | |
88 // TODO(wittman): Ultimately this should be changed to the | |
89 // ConstrainedWindowSheet pointer, in conjunction with the corresponding | |
90 // changes to NativeWebContentsModalDialogManagerCocoa. | |
91 return this; | |
92 } | |
OLD | NEW |