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

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: Refining and fixed tests 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" 8 #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" 9 #include "components/web_modal/web_contents_modal_dialog_manager.h"
15 #include "content/public/browser/browser_thread.h" 10 #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" 11 #include "extensions/browser/guest_view/guest_view_base.h"
18 12
19 using web_modal::WebContentsModalDialogManager; 13 using web_modal::WebContentsModalDialogManager;
20 using web_modal::NativeWebContentsModalDialog; 14 using web_modal::NativeWebContentsModalDialog;
21 15
22 ConstrainedWindowMac::ConstrainedWindowMac( 16 ConstrainedWindowMac::ConstrainedWindowMac(
23 ConstrainedWindowMacDelegate* delegate, 17 ConstrainedWindowMacDelegate* delegate,
24 content::WebContents* web_contents, 18 content::WebContents* web_contents,
25 id<ConstrainedWindowSheet> sheet) 19 id<ConstrainedWindowSheet> sheet)
26 : delegate_(delegate), 20 : delegate_(delegate),
27 web_contents_(NULL), 21 web_contents_(NULL),
28 sheet_([sheet retain]), 22 sheet_([sheet retain]) {
29 shown_(false) {
30 DCHECK(web_contents); 23 DCHECK(web_contents);
31 extensions::GuestViewBase* guest_view = 24 extensions::GuestViewBase* guest_view =
32 extensions::GuestViewBase::FromWebContents(web_contents); 25 extensions::GuestViewBase::FromWebContents(web_contents);
33 // For embedded WebContents, use the embedder's WebContents for constrained 26 // For embedded WebContents, use the embedder's WebContents for constrained
34 // window. 27 // window.
35 web_contents_ = guest_view && guest_view->embedder_web_contents() ? 28 web_contents_ = guest_view && guest_view->embedder_web_contents() ?
36 guest_view->embedder_web_contents() : web_contents; 29 guest_view->embedder_web_contents() : web_contents;
37 DCHECK(sheet_.get()); 30 DCHECK(sheet_.get());
38 web_modal::PopupManager* popup_manager = 31
39 web_modal::PopupManager::FromWebContents(web_contents_); 32 auto manager = WebContentsModalDialogManager::FromWebContents(web_contents_);
40 if (popup_manager) 33 native_manager_ = new WebContentsModalDialogManagerCocoa(sheet_, manager);
41 popup_manager->ShowModalDialog(this, web_contents_); 34 native_manager_->AddObserver(this);
35 manager->ShowDialogWithManager([sheet_ sheetWindow],
36 make_scoped_ptr(native_manager_));
tapted 2015/02/26 23:34:49 This feels a bit like "cheating" to me :). i.e. pa
Andre 2015/03/02 02:55:56 Done, PTAL. But the separation between ModalDialog
tapted 2015/03/02 04:28:50 I'm not opposed to merging them, but there might b
Andre 2015/03/02 18:47:31 I merged them in the latest patch, it looks good.
tapted 2015/03/02 22:25:46 still lgtm after the merge.
42 } 37 }
43 38
44 ConstrainedWindowMac::~ConstrainedWindowMac() { 39 ConstrainedWindowMac::~ConstrainedWindowMac() {
45 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 40 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
46 } 41 if (native_manager_)
tapted 2015/02/26 23:34:49 I *think* this should be DCHECK(!GetManager()); [
Andre 2015/03/02 02:55:55 Done. Added the DCHECK in ~ModalDialogClientCocoa.
47 42 native_manager_->RemoveObserver(this);
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 } 43 }
63 44
64 void ConstrainedWindowMac::CloseWebContentsModalDialog() { 45 void ConstrainedWindowMac::CloseWebContentsModalDialog() {
65 [[ConstrainedWindowSheetController controllerForSheet:sheet_] 46 if (native_manager_)
tapted 2015/02/26 23:34:49 in a `CocoaModalDialgClient` world this would be
Andre 2015/03/02 02:55:56 Done. I went with calling super's Close() to match
66 closeSheet:sheet_]; 47 native_manager_->Close();
67 // TODO(gbillock): get this object in config, not from a global. 48 }
68 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
69 WebContentsModalDialogManager::FromWebContents(web_contents_);
70 49
71 // Will result in the delegate being deleted. 50 void ConstrainedWindowMac::OnDialogClosing() {
51 native_manager_ = nullptr;
72 if (delegate_) 52 if (delegate_)
73 delegate_->OnConstrainedWindowClosed(this); 53 delegate_->OnConstrainedWindowClosed(this);
74
75 // Will cause this object to be deleted.
76 web_contents_modal_dialog_manager->WillClose(this);
77 } 54 }
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