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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/device_permissions_view_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: Rename UsbDevicesChosen -> OnUsbDevicesChosen. 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 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 "base/mac/bundle_locations.h"
6 #include "base/strings/sys_string_conversions.h"
7 #import "chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.h "
8 #include "chrome/grit/generated_resources.h"
9 #include "device/usb/usb_device.h"
10 #import "ui/base/l10n/l10n_util_mac.h"
11
12 using extensions::DevicePermissionsPrompt;
13
14 @implementation DevicePermissionsViewController
15
16 - (id)initWithDelegate:(DevicePermissionsPrompt::Delegate*)delegate
17 prompt:(scoped_refptr<DevicePermissionsPrompt::Prompt>)prompt {
18 if ((self = [super initWithNibName:@"DevicePermissionsPrompt"
19 bundle:base::mac::FrameworkBundle()])) {
20 delegate_ = delegate;
21 prompt_ = prompt;
22 }
23 return self;
24 }
25
26 - (IBAction)cancel:(id)sender {
27 std::vector<scoped_refptr<device::UsbDevice>> empty;
28 delegate_->OnUsbDevicesChosen(empty);
29 }
30
31 - (IBAction)ok:(id)sender {
32 __block std::vector<scoped_refptr<device::UsbDevice>> devices;
33 [[tableView_ selectedRowIndexes]
34 enumerateIndexesUsingBlock:^(NSUInteger index, BOOL* stop) {
35 prompt_->GrantDevicePermission(index);
36 devices.push_back(prompt_->GetDevice(index));
37 }];
38 delegate_->OnUsbDevicesChosen(devices);
39 }
40
41 - (void)devicesChanged {
42 [tableView_ reloadData];
43 }
44
45 - (void)awakeFromNib {
46 [titleField_ setStringValue:base::SysUTF16ToNSString(prompt_->GetHeading())];
47 [promptField_
48 setStringValue:base::SysUTF16ToNSString(prompt_->GetPromptMessage())];
49 [tableView_ setAllowsMultipleSelection:prompt_->multiple()];
50 [[deviceNameColumn_ headerCell]
51 setStringValue:l10n_util::GetNSString(
52 IDS_DEVICE_PERMISSIONS_DIALOG_DEVICE_NAME_COLUMN)];
53 [[serialNumberColumn_ headerCell]
54 setStringValue:l10n_util::GetNSString(
55 IDS_DEVICE_PERMISSIONS_DIALOG_SERIAL_NUMBER_COLUMN)];
56 [okButton_
57 setTitle:l10n_util::GetNSString(IDS_DEVICE_PERMISSIONS_DIALOG_SELECT)];
58 [cancelButton_ setTitle:l10n_util::GetNSString(IDS_CANCEL)];
59 }
60
61 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView {
62 DCHECK_EQ(tableView_, tableView);
63 return prompt_->GetDeviceCount();
64 }
65
66 - (id)tableView:(NSTableView*)tableView
67 objectValueForTableColumn:(NSTableColumn*)tableColumn
68 row:(NSInteger)rowIndex {
69 if (tableColumn == deviceNameColumn_) {
70 return base::SysUTF16ToNSString(prompt_->GetDeviceName(rowIndex));
71 } else if (tableColumn == serialNumberColumn_) {
72 return base::SysUTF16ToNSString(prompt_->GetDeviceSerialNumber(rowIndex));
73 } else {
74 NOTREACHED();
75 return @"";
76 }
77 }
78
79 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698