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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/device_permissions_dialog_controller.mm

Issue 633793002: Prompt for granting permission to access USB devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Marked float literals to fix Windows build. Created 6 years, 2 months 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
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
Avi (use Gerrit) 2014/10/15 01:57:46 No (c)
Reilly Grant (use Gerrit) 2014/10/15 19:15:32 Done.
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/thread_task_runner_handle.h"
11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h"
12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h"
13 #import "chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.h "
14 #include "device/usb/usb_device.h"
15
16 using extensions::DevicePermissionsPrompt;
17
18 namespace {
19
20 void ShowDevicePermissionsDialogImpl(
21 content::WebContents* web_contents,
22 DevicePermissionsPrompt::Delegate* delegate,
23 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt) {
24 // These objects will delete themselves when the dialog closes.
25 new DevicePermissionsDialogController(web_contents, delegate, prompt);
26 }
27
28 } // namespace
29
30 DevicePermissionsDialogController::DevicePermissionsDialogController(
31 content::WebContents* web_contents,
32 DevicePermissionsPrompt::Delegate* delegate,
33 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt)
34 : delegate_(delegate), prompt_(prompt) {
35 view_controller_.reset(
36 [[DevicePermissionsViewController alloc] initWithDelegate:this
37 prompt:prompt]);
38
39 prompt_->SetObserver(this);
40
41 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc]
42 initWithContentRect:[[view_controller_ view] bounds]]);
43 [[window contentView] addSubview:[view_controller_ view]];
44
45 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
46 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]);
47 constrained_window_.reset(
48 new ConstrainedWindowMac(this, web_contents, sheet));
49 }
50
51 DevicePermissionsDialogController::~DevicePermissionsDialogController() {
52 prompt_->SetObserver(nullptr);
53 }
54
55 void DevicePermissionsDialogController::UsbDevicesChosen(
56 const std::vector<scoped_refptr<device::UsbDevice>>& devices) {
57 delegate_->UsbDevicesChosen(devices);
58 delegate_ = NULL;
Avi (use Gerrit) 2014/10/15 01:57:46 nullptr
Reilly Grant (use Gerrit) 2014/10/15 19:15:32 Done.
59 constrained_window_->CloseWebContentsModalDialog();
60 }
61
62 void DevicePermissionsDialogController::OnDevicesChanged() {
63 [view_controller_ devicesChanged];
64 }
65
66 void DevicePermissionsDialogController::OnConstrainedWindowClosed(
67 ConstrainedWindowMac* window) {
68 if (delegate_) {
69 std::vector<scoped_refptr<device::UsbDevice>> empty;
70 delegate_->UsbDevicesChosen(empty);
71 }
72 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
73 }
74
75 // static
76 DevicePermissionsPrompt::ShowDialogCallback
77 DevicePermissionsPrompt::GetDefaultShowDialogCallback() {
78 return base::Bind(&ShowDevicePermissionsDialogImpl);
79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698