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

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: Fixes for tapted Created 5 years, 9 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"
9 #include "chrome/browser/ui/browser_window.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"
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"
15 #include "content/public/browser/browser_thread.h" 8 #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" 9 #include "extensions/browser/guest_view/guest_view_base.h"
18 10
19 using web_modal::WebContentsModalDialogManager;
20 using web_modal::NativeWebContentsModalDialog;
21
22 ConstrainedWindowMac::ConstrainedWindowMac( 11 ConstrainedWindowMac::ConstrainedWindowMac(
23 ConstrainedWindowMacDelegate* delegate, 12 ConstrainedWindowMacDelegate* delegate,
24 content::WebContents* web_contents, 13 content::WebContents* web_contents,
25 id<ConstrainedWindowSheet> sheet) 14 id<ConstrainedWindowSheet> sheet)
26 : delegate_(delegate), 15 : delegate_(delegate) {
27 web_contents_(NULL), 16 DCHECK(sheet);
28 sheet_([sheet retain]),
29 shown_(false) {
30 DCHECK(web_contents);
31 extensions::GuestViewBase* guest_view = 17 extensions::GuestViewBase* guest_view =
32 extensions::GuestViewBase::FromWebContents(web_contents); 18 extensions::GuestViewBase::FromWebContents(web_contents);
33 // For embedded WebContents, use the embedder's WebContents for constrained 19 // For embedded WebContents, use the embedder's WebContents for constrained
34 // window. 20 // window.
35 web_contents_ = guest_view && guest_view->embedder_web_contents() ? 21 web_contents = guest_view && guest_view->embedder_web_contents() ?
36 guest_view->embedder_web_contents() : web_contents; 22 guest_view->embedder_web_contents() : web_contents;
37 DCHECK(sheet_.get()); 23 Show(sheet, web_contents);
38 web_modal::PopupManager* popup_manager =
39 web_modal::PopupManager::FromWebContents(web_contents_);
40 if (popup_manager)
41 popup_manager->ShowModalDialog(this, web_contents_);
42 } 24 }
43 25
44 ConstrainedWindowMac::~ConstrainedWindowMac() { 26 ConstrainedWindowMac::~ConstrainedWindowMac() {
45 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 27 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
46 } 28 }
47 29
48 void ConstrainedWindowMac::ShowWebContentsModalDialog() { 30 void ConstrainedWindowMac::CloseWebContentsModalDialog() {
49 if (shown_) 31 Close();
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 } 32 }
63 33
64 void ConstrainedWindowMac::CloseWebContentsModalDialog() { 34 void ConstrainedWindowMac::OnDialogClosing() {
65 [[ConstrainedWindowSheetController controllerForSheet:sheet_]
66 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
71 // Will result in the delegate being deleted.
72 if (delegate_) 35 if (delegate_)
73 delegate_->OnConstrainedWindowClosed(this); 36 delegate_->OnConstrainedWindowClosed(this);
74
75 // Will cause this object to be deleted.
76 web_contents_modal_dialog_manager->WillClose(this);
77 } 37 }
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698