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

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: Another idea Created 5 years, 10 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"
14 #include "components/web_modal/web_contents_modal_dialog_manager.h" 13 #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 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
17 #include "extensions/browser/guest_view/guest_view_base.h" 16 #include "extensions/browser/guest_view/guest_view_base.h"
18 17
19 using web_modal::WebContentsModalDialogManager; 18 using web_modal::WebContentsModalDialogManager;
20 using web_modal::NativeWebContentsModalDialog; 19 using web_modal::NativeWebContentsModalDialog;
21 20
22 ConstrainedWindowMac::ConstrainedWindowMac( 21 ConstrainedWindowMac::ConstrainedWindowMac(
23 ConstrainedWindowMacDelegate* delegate, 22 ConstrainedWindowMacDelegate* delegate,
24 content::WebContents* web_contents, 23 content::WebContents* web_contents,
25 id<ConstrainedWindowSheet> sheet) 24 id<ConstrainedWindowSheet> sheet)
26 : delegate_(delegate), 25 : delegate_(delegate),
27 web_contents_(NULL), 26 web_contents_(NULL),
28 sheet_([sheet retain]), 27 sheet_([sheet retain]),
29 shown_(false) { 28 shown_(false) {
30 DCHECK(web_contents); 29 DCHECK(web_contents);
31 extensions::GuestViewBase* guest_view = 30 extensions::GuestViewBase* guest_view =
32 extensions::GuestViewBase::FromWebContents(web_contents); 31 extensions::GuestViewBase::FromWebContents(web_contents);
33 // For embedded WebContents, use the embedder's WebContents for constrained 32 // For embedded WebContents, use the embedder's WebContents for constrained
34 // window. 33 // window.
35 web_contents_ = guest_view && guest_view->embedder_web_contents() ? 34 web_contents_ = guest_view && guest_view->embedder_web_contents() ?
36 guest_view->embedder_web_contents() : web_contents; 35 guest_view->embedder_web_contents() : web_contents;
37 DCHECK(sheet_.get()); 36 DCHECK(sheet_.get());
38 web_modal::PopupManager* popup_manager = 37
39 web_modal::PopupManager::FromWebContents(web_contents_); 38 ShowWebContentsModalDialog();
40 if (popup_manager)
41 popup_manager->ShowModalDialog(this, web_contents_);
42 } 39 }
43 40
44 ConstrainedWindowMac::~ConstrainedWindowMac() { 41 ConstrainedWindowMac::~ConstrainedWindowMac() {
45 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 42 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
46 } 43 }
47 44
48 void ConstrainedWindowMac::ShowWebContentsModalDialog() { 45 void ConstrainedWindowMac::ShowWebContentsModalDialog() {
49 if (shown_) 46 if (shown_)
50 return; 47 return;
51 48
52 NSWindow* parent_window = web_contents_->GetTopLevelNativeWindow(); 49 NSWindow* parent_window = web_contents_->GetTopLevelNativeWindow();
53 NSView* parent_view = GetSheetParentViewForWebContents(web_contents_); 50 NSView* parent_view = GetSheetParentViewForWebContents(web_contents_);
54 if (!parent_window || !parent_view) 51 if (!parent_window || !parent_view)
55 return; 52 return;
56 53
57 shown_ = true; 54 shown_ = true;
58 ConstrainedWindowSheetController* controller = 55 ConstrainedWindowSheetController* controller =
59 [ConstrainedWindowSheetController 56 [ConstrainedWindowSheetController
60 controllerForParentWindow:parent_window]; 57 controllerForParentWindow:parent_window];
61 [controller showSheet:sheet_ forParentView:parent_view]; 58 [controller showSheet:sheet_ forParentView:parent_view];
62 } 59 }
63 60
64 void ConstrainedWindowMac::CloseWebContentsModalDialog() { 61 void ConstrainedWindowMac::CloseWebContentsModalDialog() {
65 [[ConstrainedWindowSheetController controllerForSheet:sheet_] 62 [[ConstrainedWindowSheetController controllerForSheet:sheet_]
66 closeSheet:sheet_]; 63 closeSheet:sheet_];
67 // TODO(gbillock): get this object in config, not from a global.
68 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
69 WebContentsModalDialogManager::FromWebContents(web_contents_);
70 64
71 // Will result in the delegate being deleted. 65 // Will result in the delegate being deleted.
72 if (delegate_) 66 if (delegate_)
73 delegate_->OnConstrainedWindowClosed(this); 67 delegate_->OnConstrainedWindowClosed(this);
74
75 // Will cause this object to be deleted.
76 web_contents_modal_dialog_manager->WillClose(this);
77 } 68 }
78 69
79 void ConstrainedWindowMac::FocusWebContentsModalDialog() { 70 void ConstrainedWindowMac::FocusWebContentsModalDialog() {
80 } 71 }
81 72
82 void ConstrainedWindowMac::PulseWebContentsModalDialog() { 73 void ConstrainedWindowMac::PulseWebContentsModalDialog() {
83 [[ConstrainedWindowSheetController controllerForSheet:sheet_] 74 [[ConstrainedWindowSheetController controllerForSheet:sheet_]
84 pulseSheet:sheet_]; 75 pulseSheet:sheet_];
85 } 76 }
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698