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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.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"
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"
15 using web_modal::WebContentsModalDialogManager;
17 ConstrainedWindowMac::ConstrainedWindowMac(
18 ConstrainedWindowMacDelegate* delegate,
19 content::WebContents* web_contents,
20 id<ConstrainedWindowSheet> sheet)
21 : delegate_(delegate) {
24 // |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.
27 guest_view::GuestViewBase::GetTopLevelWebContents(web_contents);
29 auto manager = WebContentsModalDialogManager::FromWebContents(web_contents);
30 scoped_ptr<SingleWebContentsDialogManagerCocoa> native_manager(
31 new SingleWebContentsDialogManagerCocoa(this, sheet, manager));
32 manager->ShowDialogWithManager([sheet sheetWindow], native_manager.Pass());
35 ConstrainedWindowMac::~ConstrainedWindowMac() {
36 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
40 void ConstrainedWindowMac::CloseWebContentsModalDialog() {
45 void ConstrainedWindowMac::OnDialogClosing() {
47 delegate_->OnConstrainedWindowClosed(this);