1 // Copyright 2015 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 #import "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h"
7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h"
10 #include "chrome/browser/ui/tab_dialogs.h"
11 #include "components/web_modal/web_contents_modal_dialog_manager.h"
12 #include "content/public/browser/web_contents.h"
14 SingleWebContentsDialogManagerCocoa::SingleWebContentsDialogManagerCocoa(
15 ConstrainedWindowMac* client,
16 id<ConstrainedWindowSheet> sheet,
17 web_modal::SingleWebContentsDialogManagerDelegate* delegate)
19 sheet_([sheet retain]),
23 client->set_manager(this);
26 SingleWebContentsDialogManagerCocoa::~SingleWebContentsDialogManagerCocoa() {
29 void SingleWebContentsDialogManagerCocoa::Show() {
33 content::WebContents* web_contents = delegate_->GetWebContents();
34 NSWindow* parent_window = web_contents->GetTopLevelNativeWindow();
35 TabDialogs* tab_dialogs = TabDialogs::FromWebContents(web_contents);
36 // |tab_dialogs| is null when |web_contents| is inside a packaged app window.
37 NSView* parent_view = tab_dialogs ? tab_dialogs->GetDialogParentView()
38 : web_contents->GetNativeView();
39 if (!parent_window || !parent_view)
43 [[ConstrainedWindowSheetController controllerForParentWindow:parent_window]
44 showSheet:sheet_ forParentView:parent_view];
47 void SingleWebContentsDialogManagerCocoa::Hide() {
50 void SingleWebContentsDialogManagerCocoa::Close() {
51 [[ConstrainedWindowSheetController controllerForSheet:sheet_]
54 client_->set_manager(nullptr);
55 client_->OnDialogClosing(); // |client_| might delete itself here.
58 delegate_->WillClose(dialog());
61 void SingleWebContentsDialogManagerCocoa::Focus() {
64 void SingleWebContentsDialogManagerCocoa::Pulse() {
65 [[ConstrainedWindowSheetController controllerForSheet:sheet_]
69 void SingleWebContentsDialogManagerCocoa::HostChanged(
70 web_modal::WebContentsModalDialogHost* new_host) {
73 gfx::NativeWindow SingleWebContentsDialogManagerCocoa::dialog() {
74 return [sheet_ sheetWindow];