Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.mm

Issue 866263008: MacViews: Unify web contents modal dialog types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ValidationMessageBubble
Patch Set: Fix test crashes Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/ui/browser_finder.h" 8 #include "chrome/browser/ui/browser_finder.h"
9 #include "chrome/browser/ui/browser_window.h" 9 #include "chrome/browser/ui/browser_window.h"
10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" 10 #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" 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con troller.h"
12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
13 #include "components/web_modal/popup_manager.h" 13 #include "components/web_modal/popup_manager.h"
14 #include "components/web_modal/web_contents_modal_dialog_manager.h" 14 #include "components/web_modal/web_contents_modal_dialog_manager.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "extensions/browser/guest_view/guest_view_base.h" 17 #include "extensions/browser/guest_view/guest_view_base.h"
18 18
19 using web_modal::WebContentsModalDialogManager; 19 using web_modal::WebContentsModalDialogManager;
20 using web_modal::NativeWebContentsModalDialog; 20 using web_modal::NativeWebContentsModalDialog;
21 21
22 namespace {
23
24 class NativeWebContentsModalDialogManagerCocoa
25 : public web_modal::SingleWebContentsDialogManager {
26 public:
27 NativeWebContentsModalDialogManagerCocoa(
28 ConstrainedWindowMac* owner)
29 : owner_(owner) {
30 DCHECK(owner);
31 }
32
33 ~NativeWebContentsModalDialogManagerCocoa() override {}
34
35 // SingleWebContentsDialogManager overrides
36 void Show() override {
37 owner_->ShowWebContentsModalDialog();
38 }
39
40 void Hide() override {}
41
42 void Close() override {
43 owner_->CloseWebContentsModalDialog();
44 }
45
46 void Focus() override {
47 owner_->FocusWebContentsModalDialog();
48 }
49
50 void Pulse() override {
51 owner_->PulseWebContentsModalDialog();
52 }
53
54 void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override {}
55
56 NativeWebContentsModalDialog dialog() override {
57 return owner_->GetNativeDialog();
58 }
59
60 private:
61 ConstrainedWindowMac* owner_; // Weak. Owns this.
62
63 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerCocoa);
64 };
65
66 } // namespace
67
22 ConstrainedWindowMac::ConstrainedWindowMac( 68 ConstrainedWindowMac::ConstrainedWindowMac(
23 ConstrainedWindowMacDelegate* delegate, 69 ConstrainedWindowMacDelegate* delegate,
24 content::WebContents* web_contents, 70 content::WebContents* web_contents,
25 id<ConstrainedWindowSheet> sheet) 71 id<ConstrainedWindowSheet> sheet)
26 : delegate_(delegate), 72 : delegate_(delegate),
27 web_contents_(NULL), 73 web_contents_(NULL),
28 sheet_([sheet retain]), 74 sheet_([sheet retain]),
29 shown_(false) { 75 shown_(false) {
30 DCHECK(web_contents); 76 DCHECK(web_contents);
31 extensions::GuestViewBase* guest_view = 77 extensions::GuestViewBase* guest_view =
32 extensions::GuestViewBase::FromWebContents(web_contents); 78 extensions::GuestViewBase::FromWebContents(web_contents);
33 // For embedded WebContents, use the embedder's WebContents for constrained 79 // For embedded WebContents, use the embedder's WebContents for constrained
34 // window. 80 // window.
35 web_contents_ = guest_view && guest_view->embedder_web_contents() ? 81 web_contents_ = guest_view && guest_view->embedder_web_contents() ?
36 guest_view->embedder_web_contents() : web_contents; 82 guest_view->embedder_web_contents() : web_contents;
37 DCHECK(sheet_.get()); 83 DCHECK(sheet_.get());
38 web_modal::PopupManager* popup_manager = 84 WebContentsModalDialogManager* wm_manager =
39 web_modal::PopupManager::FromWebContents(web_contents_); 85 WebContentsModalDialogManager::FromWebContents(web_contents);
40 if (popup_manager) 86 if (wm_manager) {
41 popup_manager->ShowModalDialog(this, web_contents_); 87 scoped_ptr<NativeWebContentsModalDialogManagerCocoa> manager(
88 new NativeWebContentsModalDialogManagerCocoa(this));
89 wm_manager->ShowDialogWithManager(GetNativeDialog(), manager.Pass());
90 }
42 } 91 }
43 92
44 ConstrainedWindowMac::~ConstrainedWindowMac() { 93 ConstrainedWindowMac::~ConstrainedWindowMac() {
45 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 94 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
46 } 95 }
47 96
48 void ConstrainedWindowMac::ShowWebContentsModalDialog() { 97 void ConstrainedWindowMac::ShowWebContentsModalDialog() {
49 if (shown_) 98 if (shown_)
50 return; 99 return;
51 100
52 NSWindow* parent_window = web_contents_->GetTopLevelNativeWindow(); 101 NSWindow* parent_window = web_contents_->GetTopLevelNativeWindow();
53 NSView* parent_view = GetSheetParentViewForWebContents(web_contents_); 102 NSView* parent_view = GetSheetParentViewForWebContents(web_contents_);
54 if (!parent_window || !parent_view) 103 if (!parent_window || !parent_view)
55 return; 104 return;
56 105
57 shown_ = true; 106 shown_ = true;
58 ConstrainedWindowSheetController* controller = 107 ConstrainedWindowSheetController* controller =
59 [ConstrainedWindowSheetController 108 [ConstrainedWindowSheetController
60 controllerForParentWindow:parent_window]; 109 controllerForParentWindow:parent_window];
61 [controller showSheet:sheet_ forParentView:parent_view]; 110 [controller showSheet:sheet_ forParentView:parent_view];
62 } 111 }
63 112
64 void ConstrainedWindowMac::CloseWebContentsModalDialog() { 113 void ConstrainedWindowMac::CloseWebContentsModalDialog() {
65 [[ConstrainedWindowSheetController controllerForSheet:sheet_] 114 [[ConstrainedWindowSheetController controllerForSheet:sheet_]
66 closeSheet:sheet_]; 115 closeSheet:sheet_];
67 // TODO(gbillock): get this object in config, not from a global. 116 // TODO(gbillock): get this object in config, not from a global.
68 WebContentsModalDialogManager* web_contents_modal_dialog_manager = 117 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
69 WebContentsModalDialogManager::FromWebContents(web_contents_); 118 WebContentsModalDialogManager::FromWebContents(web_contents_);
70 119
71 // Will result in the delegate being deleted. 120 // Will cause our NativeWebContentsModalDialogManagerCocoa to be deleted.
121 web_contents_modal_dialog_manager->WillClose(GetNativeDialog());
122
123 // Will cause this object to be deleted.
72 if (delegate_) 124 if (delegate_)
73 delegate_->OnConstrainedWindowClosed(this); 125 delegate_->OnConstrainedWindowClosed(this);
74
75 // Will cause this object to be deleted.
76 web_contents_modal_dialog_manager->WillClose(this);
77 } 126 }
78 127
79 void ConstrainedWindowMac::FocusWebContentsModalDialog() { 128 void ConstrainedWindowMac::FocusWebContentsModalDialog() {
80 } 129 }
81 130
82 void ConstrainedWindowMac::PulseWebContentsModalDialog() { 131 void ConstrainedWindowMac::PulseWebContentsModalDialog() {
83 [[ConstrainedWindowSheetController controllerForSheet:sheet_] 132 [[ConstrainedWindowSheetController controllerForSheet:sheet_]
84 pulseSheet:sheet_]; 133 pulseSheet:sheet_];
85 } 134 }
86 135
87 NativeWebContentsModalDialog ConstrainedWindowMac::GetNativeDialog() { 136 NativeWebContentsModalDialog ConstrainedWindowMac::GetNativeDialog() {
88 // TODO(wittman): Ultimately this should be changed to the 137 // TODO(wittman): Ultimately this should be changed to the
89 // ConstrainedWindowSheet pointer, in conjunction with the corresponding 138 // ConstrainedWindowSheet pointer, in conjunction with the corresponding
90 // changes to NativeWebContentsModalDialogManagerCocoa. 139 // changes to NativeWebContentsModalDialogManagerCocoa.
91 return this; 140 return [sheet_ sheetWindow];
92 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698