OLD | NEW |
| (Empty) |
1 // Copyright 2014 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. | |
4 | |
5 #import "chrome/browser/ui/cocoa/extensions/device_permissions_dialog_controller
.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/location.h" | |
9 #include "base/single_thread_task_runner.h" | |
10 #include "base/threading/thread_task_runner_handle.h" | |
11 #include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h" | |
12 #include "chrome/browser/ui/browser_dialogs.h" | |
13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" | |
14 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" | |
15 #import "chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.h
" | |
16 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
17 #include "device/usb/usb_device.h" | |
18 | |
19 using extensions::DevicePermissionsPrompt; | |
20 | |
21 DevicePermissionsDialogController::DevicePermissionsDialogController( | |
22 content::WebContents* web_contents, | |
23 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt) | |
24 : prompt_(prompt) { | |
25 view_controller_.reset( | |
26 [[DevicePermissionsViewController alloc] initWithController:this | |
27 prompt:prompt]); | |
28 | |
29 prompt_->SetObserver(this); | |
30 | |
31 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc] | |
32 initWithContentRect:[[view_controller_ view] bounds]]); | |
33 [[window contentView] addSubview:[view_controller_ view]]; | |
34 | |
35 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | |
36 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]); | |
37 constrained_window_ = | |
38 CreateAndShowWebModalDialogMac(this, web_contents, sheet); | |
39 } | |
40 | |
41 DevicePermissionsDialogController::~DevicePermissionsDialogController() { | |
42 prompt_->SetObserver(nullptr); | |
43 } | |
44 | |
45 void DevicePermissionsDialogController::Dismissed() { | |
46 constrained_window_->CloseWebContentsModalDialog(); | |
47 } | |
48 | |
49 void DevicePermissionsDialogController::OnDevicesChanged() { | |
50 [view_controller_ devicesChanged]; | |
51 } | |
52 | |
53 void DevicePermissionsDialogController::OnConstrainedWindowClosed( | |
54 ConstrainedWindowMac* window) { | |
55 prompt_->Dismissed(); | |
56 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | |
57 } | |
58 | |
59 void ChromeDevicePermissionsPrompt::ShowDialog() { | |
60 if (chrome::ToolkitViewsWebUIDialogsEnabled()) | |
61 return ChromeDevicePermissionsPrompt::ShowDialogViews(); | |
62 web_modal::WebContentsModalDialogManager* manager = | |
63 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents()); | |
64 if (manager) { | |
65 // These objects will delete themselves when the dialog closes. | |
66 new DevicePermissionsDialogController(web_contents(), prompt()); | |
67 } else { | |
68 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
69 FROM_HERE, | |
70 base::Bind(&DevicePermissionsPrompt::Prompt::Dismissed, prompt())); | |
71 } | |
72 } | |
OLD | NEW |