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

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

Issue 1430023002: Enable AutoResize for Constrained Web Dialogs for Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" 9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h"
10 #import "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h" 10 #import "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h"
11 #include "components/guest_view/browser/guest_view_base.h" 11 #include "components/guest_view/browser/guest_view_base.h"
12 #include "components/web_modal/web_contents_modal_dialog_manager.h"
13 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
14 13
15 using web_modal::WebContentsModalDialogManager; 14 using web_modal::WebContentsModalDialogManager;
16 15
16 ConstrainedWindowMac* ShowWebModalDialogMac(
17 ConstrainedWindowMacDelegate* delegate,
18 content::WebContents* web_contents,
19 id<ConstrainedWindowSheet> sheet) {
20 ConstrainedWindowMac* window = new ConstrainedWindowMac(delegate);
21 window->ShowDialog(web_contents, sheet);
22 return window;
23 }
24
25 ConstrainedWindowMac* CreateWebModalDialogMac(
26 ConstrainedWindowMacDelegate* delegate,
27 content::WebContents* web_contents,
28 id<ConstrainedWindowSheet> sheet) {
29 return new ConstrainedWindowMac(delegate, web_contents, sheet);
30 }
31
32 ConstrainedWindowMac::ConstrainedWindowMac(
33 ConstrainedWindowMacDelegate* delegate)
34 : delegate_(delegate) {
35 }
36
17 ConstrainedWindowMac::ConstrainedWindowMac( 37 ConstrainedWindowMac::ConstrainedWindowMac(
18 ConstrainedWindowMacDelegate* delegate, 38 ConstrainedWindowMacDelegate* delegate,
19 content::WebContents* web_contents, 39 content::WebContents* web_contents,
20 id<ConstrainedWindowSheet> sheet) 40 id<ConstrainedWindowSheet> sheet)
21 : delegate_(delegate) { 41 : delegate_(delegate),
42 sheet_(sheet) {
22 DCHECK(sheet); 43 DCHECK(sheet);
23 44
24 // |web_contents| may be embedded within a chain of nested GuestViews. If it 45 // |web_contents| may be embedded within a chain of nested GuestViews. If it
25 // is, follow the chain of embedders to the outermost WebContents and use it. 46 // is, follow the chain of embedders to the outermost WebContents and use it.
26 web_contents = 47 web_contents =
27 guest_view::GuestViewBase::GetTopLevelWebContents(web_contents); 48 guest_view::GuestViewBase::GetTopLevelWebContents(web_contents);
28 49
50 dialog_manager_ =
51 WebContentsModalDialogManager::FromWebContents(web_contents);
52 native_manager_.reset(
53 new SingleWebContentsDialogManagerCocoa(this, sheet_, dialog_manager_));
54 }
55
56 ConstrainedWindowMac::~ConstrainedWindowMac() {
57 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
58 native_manager_.reset();
59 DCHECK(!manager_);
60 }
61
62 void ConstrainedWindowMac::ShowDialog(
63 content::WebContents* web_contents,
64 id<ConstrainedWindowSheet> sheet) {
65 DCHECK(sheet);
66 web_contents =
67 guest_view::GuestViewBase::GetTopLevelWebContents(web_contents);
68
29 auto manager = WebContentsModalDialogManager::FromWebContents(web_contents); 69 auto manager = WebContentsModalDialogManager::FromWebContents(web_contents);
30 scoped_ptr<SingleWebContentsDialogManagerCocoa> native_manager( 70 scoped_ptr<SingleWebContentsDialogManagerCocoa> native_manager(
31 new SingleWebContentsDialogManagerCocoa(this, sheet, manager)); 71 new SingleWebContentsDialogManagerCocoa(this, sheet, manager));
32 manager->ShowDialogWithManager([sheet sheetWindow], native_manager.Pass()); 72 manager->ShowDialogWithManager([sheet sheetWindow], native_manager.Pass());
33 } 73 }
34 74
35 ConstrainedWindowMac::~ConstrainedWindowMac() { 75 void ConstrainedWindowMac::ShowDialog() {
36 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 76 dialog_manager_->ShowDialogWithManager(
37 DCHECK(!manager_); 77 [sheet_ sheetWindow], native_manager_.Pass());
38 } 78 }
39 79
40 void ConstrainedWindowMac::CloseWebContentsModalDialog() { 80 void ConstrainedWindowMac::CloseWebContentsModalDialog() {
41 if (manager_) 81 if (manager_)
42 manager_->Close(); 82 manager_->Close();
43 } 83 }
44 84
45 void ConstrainedWindowMac::OnDialogClosing() { 85 void ConstrainedWindowMac::OnDialogClosing() {
46 if (delegate_) 86 if (delegate_)
47 delegate_->OnConstrainedWindowClosed(this); 87 delegate_->OnConstrainedWindowClosed(this);
48 } 88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698