| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "base/mac/bundle_locations.h" | 5 #import "base/mac/bundle_locations.h" |
| 6 #include "base/strings/sys_string_conversions.h" | 6 #include "base/strings/sys_string_conversions.h" |
| 7 #import "chrome/browser/ui/cocoa/extensions/device_permissions_dialog_controller
.h" |
| 7 #import "chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.h
" | 8 #import "chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.h
" |
| 8 #include "chrome/grit/generated_resources.h" | 9 #include "chrome/grit/generated_resources.h" |
| 9 #include "device/usb/usb_device.h" | |
| 10 #import "ui/base/l10n/l10n_util_mac.h" | 10 #import "ui/base/l10n/l10n_util_mac.h" |
| 11 | 11 |
| 12 using extensions::DevicePermissionsPrompt; | 12 using extensions::DevicePermissionsPrompt; |
| 13 | 13 |
| 14 @implementation DevicePermissionsViewController | 14 @implementation DevicePermissionsViewController |
| 15 | 15 |
| 16 - (id)initWithDelegate:(DevicePermissionsPrompt::Delegate*)delegate | 16 - (id)initWithController:(DevicePermissionsDialogController*)controller |
| 17 prompt:(scoped_refptr<DevicePermissionsPrompt::Prompt>)prompt { | 17 prompt: |
| 18 (scoped_refptr<DevicePermissionsPrompt::Prompt>)prompt { |
| 18 if ((self = [super initWithNibName:@"DevicePermissionsPrompt" | 19 if ((self = [super initWithNibName:@"DevicePermissionsPrompt" |
| 19 bundle:base::mac::FrameworkBundle()])) { | 20 bundle:base::mac::FrameworkBundle()])) { |
| 20 delegate_ = delegate; | 21 controller_ = controller; |
| 21 prompt_ = prompt; | 22 prompt_ = prompt; |
| 22 } | 23 } |
| 23 return self; | 24 return self; |
| 24 } | 25 } |
| 25 | 26 |
| 26 - (IBAction)cancel:(id)sender { | 27 - (IBAction)cancel:(id)sender { |
| 27 std::vector<scoped_refptr<device::UsbDevice>> empty; | 28 controller_->Dismissed(); |
| 28 delegate_->OnUsbDevicesChosen(empty); | |
| 29 } | 29 } |
| 30 | 30 |
| 31 - (IBAction)ok:(id)sender { | 31 - (IBAction)ok:(id)sender { |
| 32 __block std::vector<scoped_refptr<device::UsbDevice>> devices; | 32 __block std::vector<scoped_refptr<device::UsbDevice>> devices; |
| 33 [[tableView_ selectedRowIndexes] | 33 [[tableView_ selectedRowIndexes] |
| 34 enumerateIndexesUsingBlock:^(NSUInteger index, BOOL* stop) { | 34 enumerateIndexesUsingBlock:^(NSUInteger index, BOOL* stop) { |
| 35 prompt_->GrantDevicePermission(index); | 35 prompt_->GrantDevicePermission(index); |
| 36 devices.push_back(prompt_->GetDevice(index)); | |
| 37 }]; | 36 }]; |
| 38 delegate_->OnUsbDevicesChosen(devices); | 37 controller_->Dismissed(); |
| 39 } | 38 } |
| 40 | 39 |
| 41 - (void)devicesChanged { | 40 - (void)devicesChanged { |
| 42 [tableView_ reloadData]; | 41 [tableView_ reloadData]; |
| 43 } | 42 } |
| 44 | 43 |
| 45 - (void)awakeFromNib { | 44 - (void)awakeFromNib { |
| 46 [titleField_ setStringValue:base::SysUTF16ToNSString(prompt_->GetHeading())]; | 45 [titleField_ setStringValue:base::SysUTF16ToNSString(prompt_->GetHeading())]; |
| 47 [promptField_ | 46 [promptField_ |
| 48 setStringValue:base::SysUTF16ToNSString(prompt_->GetPromptMessage())]; | 47 setStringValue:base::SysUTF16ToNSString(prompt_->GetPromptMessage())]; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 70 return base::SysUTF16ToNSString(prompt_->GetDeviceName(rowIndex)); | 69 return base::SysUTF16ToNSString(prompt_->GetDeviceName(rowIndex)); |
| 71 } else if (tableColumn == serialNumberColumn_) { | 70 } else if (tableColumn == serialNumberColumn_) { |
| 72 return base::SysUTF16ToNSString(prompt_->GetDeviceSerialNumber(rowIndex)); | 71 return base::SysUTF16ToNSString(prompt_->GetDeviceSerialNumber(rowIndex)); |
| 73 } else { | 72 } else { |
| 74 NOTREACHED(); | 73 NOTREACHED(); |
| 75 return @""; | 74 return @""; |
| 76 } | 75 } |
| 77 } | 76 } |
| 78 | 77 |
| 79 @end | 78 @end |
| OLD | NEW |