Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / single_web_contents_dialog_manager_cocoa.mm
blob8dd21402c0b2a6609fbe2fda4c39c5727e007706
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)
18     : client_(client),
19       sheet_([sheet retain]),
20       delegate_(delegate),
21       shown_(false) {
22   if (client)
23     client->set_manager(this);
26 SingleWebContentsDialogManagerCocoa::~SingleWebContentsDialogManagerCocoa() {
29 void SingleWebContentsDialogManagerCocoa::Show() {
30   if (shown_)
31     return;
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)
40     return;
42   shown_ = true;
43   [[ConstrainedWindowSheetController controllerForParentWindow:parent_window]
44       showSheet:sheet_ forParentView:parent_view];
47 void SingleWebContentsDialogManagerCocoa::Hide() {
50 void SingleWebContentsDialogManagerCocoa::Close() {
51   [[ConstrainedWindowSheetController controllerForSheet:sheet_]
52       closeSheet:sheet_];
53   if (client_) {
54     client_->set_manager(nullptr);
55     client_->OnDialogClosing();  // |client_| might delete itself here.
56     client_ = nullptr;
57   }
58   delegate_->WillClose(dialog());
61 void SingleWebContentsDialogManagerCocoa::Focus() {
64 void SingleWebContentsDialogManagerCocoa::Pulse() {
65   [[ConstrainedWindowSheetController controllerForSheet:sheet_]
66       pulseSheet:sheet_];
69 void SingleWebContentsDialogManagerCocoa::HostChanged(
70     web_modal::WebContentsModalDialogHost* new_host) {
73 gfx::NativeWindow SingleWebContentsDialogManagerCocoa::dialog() {
74   return [sheet_ sheetWindow];