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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.mm
diff --git a/chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.mm b/chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.mm
new file mode 100644
index 0000000000000000000000000000000000000000..c058708e557b3d1e59196e1fa6a862acee8bc037
--- /dev/null
+++ b/chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.mm
@@ -0,0 +1,79 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "base/mac/bundle_locations.h"
+#include "base/strings/sys_string_conversions.h"
+#import "chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.h"
+#include "chrome/grit/generated_resources.h"
+#include "device/usb/usb_device.h"
+#import "ui/base/l10n/l10n_util_mac.h"
+
+using extensions::DevicePermissionsPrompt;
+
+@implementation DevicePermissionsViewController
+
+- (id)initWithDelegate:(DevicePermissionsPrompt::Delegate*)delegate
+ prompt:(scoped_refptr<DevicePermissionsPrompt::Prompt>)prompt {
+ if ((self = [super initWithNibName:@"DevicePermissionsPrompt"
+ bundle:base::mac::FrameworkBundle()])) {
+ delegate_ = delegate;
+ prompt_ = prompt;
+ }
+ return self;
+}
+
+- (IBAction)cancel:(id)sender {
+ std::vector<scoped_refptr<device::UsbDevice>> empty;
+ delegate_->OnUsbDevicesChosen(empty);
+}
+
+- (IBAction)ok:(id)sender {
+ __block std::vector<scoped_refptr<device::UsbDevice>> devices;
+ [[tableView_ selectedRowIndexes]
+ enumerateIndexesUsingBlock:^(NSUInteger index, BOOL* stop) {
+ prompt_->GrantDevicePermission(index);
+ devices.push_back(prompt_->GetDevice(index));
+ }];
+ delegate_->OnUsbDevicesChosen(devices);
+}
+
+- (void)devicesChanged {
+ [tableView_ reloadData];
+}
+
+- (void)awakeFromNib {
+ [titleField_ setStringValue:base::SysUTF16ToNSString(prompt_->GetHeading())];
+ [promptField_
+ setStringValue:base::SysUTF16ToNSString(prompt_->GetPromptMessage())];
+ [tableView_ setAllowsMultipleSelection:prompt_->multiple()];
+ [[deviceNameColumn_ headerCell]
+ setStringValue:l10n_util::GetNSString(
+ IDS_DEVICE_PERMISSIONS_DIALOG_DEVICE_NAME_COLUMN)];
+ [[serialNumberColumn_ headerCell]
+ setStringValue:l10n_util::GetNSString(
+ IDS_DEVICE_PERMISSIONS_DIALOG_SERIAL_NUMBER_COLUMN)];
+ [okButton_
+ setTitle:l10n_util::GetNSString(IDS_DEVICE_PERMISSIONS_DIALOG_SELECT)];
+ [cancelButton_ setTitle:l10n_util::GetNSString(IDS_CANCEL)];
+}
+
+- (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView {
+ DCHECK_EQ(tableView_, tableView);
+ return prompt_->GetDeviceCount();
+}
+
+- (id)tableView:(NSTableView*)tableView
+ objectValueForTableColumn:(NSTableColumn*)tableColumn
+ row:(NSInteger)rowIndex {
+ if (tableColumn == deviceNameColumn_) {
+ return base::SysUTF16ToNSString(prompt_->GetDeviceName(rowIndex));
+ } else if (tableColumn == serialNumberColumn_) {
+ return base::SysUTF16ToNSString(prompt_->GetDeviceSerialNumber(rowIndex));
+ } else {
+ NOTREACHED();
+ return @"";
+ }
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698