Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 @interface DevicePermissionsViewController () | |
| 15 | |
| 16 @end | |
|
Avi (use Gerrit)
2014/10/15 01:57:47
You don't need a class extension if you have nothi
Reilly Grant (use Gerrit)
2014/10/15 19:15:33
Oops. I put that there in case I needed it.
| |
| 17 | |
| 18 @implementation DevicePermissionsViewController | |
| 19 | |
| 20 - (id)initWithDelegate:(DevicePermissionsPrompt::Delegate*)delegate | |
| 21 prompt:(scoped_refptr<DevicePermissionsPrompt::Prompt>)prompt { | |
| 22 if ((self = [super initWithNibName:@"DevicePermissionsPrompt" | |
| 23 bundle:base::mac::FrameworkBundle()])) { | |
| 24 delegate_ = delegate; | |
| 25 prompt_ = prompt; | |
| 26 } | |
| 27 return self; | |
| 28 } | |
| 29 | |
| 30 - (IBAction)cancel:(id)sender { | |
| 31 std::vector<scoped_refptr<device::UsbDevice>> empty; | |
| 32 delegate_->UsbDevicesChosen(empty); | |
| 33 } | |
| 34 | |
| 35 - (IBAction)ok:(id)sender { | |
| 36 __block std::vector<scoped_refptr<device::UsbDevice>> devices; | |
| 37 [[tableView_ selectedRowIndexes] | |
| 38 enumerateIndexesUsingBlock:^void(NSUInteger index, BOOL* stop) { | |
|
Avi (use Gerrit)
2014/10/15 01:57:47
Drop the "void"; you shouldn't need to explicitly
Reilly Grant (use Gerrit)
2014/10/15 19:15:33
Done.
| |
| 39 prompt_->GrantDevicePermission(index); | |
| 40 devices.push_back(prompt_->GetDevice(index)); | |
| 41 }]; | |
| 42 delegate_->UsbDevicesChosen(devices); | |
| 43 } | |
| 44 | |
| 45 - (void)devicesChanged { | |
| 46 [tableView_ reloadData]; | |
| 47 } | |
| 48 | |
| 49 - (void)awakeFromNib { | |
| 50 [titleField_ setStringValue:base::SysUTF16ToNSString(prompt_->GetHeading())]; | |
| 51 [promptField_ | |
| 52 setStringValue:base::SysUTF16ToNSString(prompt_->GetPromptMessage())]; | |
| 53 [tableView_ setAllowsMultipleSelection:prompt_->multiple()]; | |
| 54 [[deviceNameColumn_ headerCell] | |
| 55 setStringValue:l10n_util::GetNSString( | |
| 56 IDS_DEVICE_PERMISSIONS_DIALOG_DEVICE_NAME_COLUMN)]; | |
| 57 [[serialNumberColumn_ headerCell] | |
| 58 setStringValue:l10n_util::GetNSString( | |
| 59 IDS_DEVICE_PERMISSIONS_DIALOG_SERIAL_NUMBER_COLUMN)]; | |
| 60 [okButton_ | |
| 61 setTitle:l10n_util::GetNSString(IDS_DEVICE_PERMISSIONS_DIALOG_SELECT)]; | |
| 62 [cancelButton_ setTitle:l10n_util::GetNSString(IDS_CANCEL)]; | |
| 63 } | |
| 64 | |
| 65 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { | |
| 66 DCHECK_EQ(tableView_, tableView); | |
| 67 return prompt_->GetDeviceCount(); | |
| 68 } | |
| 69 | |
| 70 - (id)tableView:(NSTableView*)tableView | |
| 71 objectValueForTableColumn:(NSTableColumn*)tableColumn | |
| 72 row:(NSInteger)rowIndex { | |
| 73 if (tableColumn == deviceNameColumn_) { | |
| 74 return base::SysUTF16ToNSString(prompt_->GetDeviceName(rowIndex)); | |
| 75 } else if (tableColumn == serialNumberColumn_) { | |
| 76 return base::SysUTF16ToNSString(prompt_->GetDeviceSerialNumber(rowIndex)); | |
| 77 } else { | |
| 78 NOTREACHED(); | |
| 79 return @""; | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 @end | |
| OLD | NEW |