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.
5 #import "base/mac/bundle_locations.h"
6 #include "base/strings/sys_string_conversions.h"
7 #import "chrome/browser/ui/cocoa/extensions/device_permissions_dialog_controller.h"
8 #import "chrome/browser/ui/cocoa/extensions/device_permissions_view_controller.h"
9 #include "chrome/grit/generated_resources.h"
10 #import "ui/base/l10n/l10n_util_mac.h"
12 using extensions::DevicePermissionsPrompt;
14 @implementation DevicePermissionsViewController
16 - (id)initWithController:(DevicePermissionsDialogController*)controller
18 (scoped_refptr<DevicePermissionsPrompt::Prompt>)prompt {
19 if ((self = [super initWithNibName:@"DevicePermissionsPrompt"
20 bundle:base::mac::FrameworkBundle()])) {
21 controller_ = controller;
27 - (IBAction)cancel:(id)sender {
28 controller_->Dismissed();
31 - (IBAction)ok:(id)sender {
32 [[tableView_ selectedRowIndexes]
33 enumerateIndexesUsingBlock:^(NSUInteger index, BOOL* stop) {
34 prompt_->GrantDevicePermission(index);
36 controller_->Dismissed();
39 - (void)devicesChanged {
40 [tableView_ reloadData];
43 - (void)awakeFromNib {
44 [titleField_ setStringValue:base::SysUTF16ToNSString(prompt_->GetHeading())];
46 setStringValue:base::SysUTF16ToNSString(prompt_->GetPromptMessage())];
47 [tableView_ setAllowsMultipleSelection:prompt_->multiple()];
48 [[deviceNameColumn_ headerCell]
49 setStringValue:l10n_util::GetNSString(
50 IDS_DEVICE_PERMISSIONS_DIALOG_DEVICE_NAME_COLUMN)];
51 [[serialNumberColumn_ headerCell]
52 setStringValue:l10n_util::GetNSString(
53 IDS_DEVICE_PERMISSIONS_DIALOG_SERIAL_NUMBER_COLUMN)];
55 setTitle:l10n_util::GetNSString(IDS_DEVICE_PERMISSIONS_DIALOG_SELECT)];
56 [cancelButton_ setTitle:l10n_util::GetNSString(IDS_CANCEL)];
59 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView {
60 DCHECK_EQ(tableView_, tableView);
61 return prompt_->GetDeviceCount();
64 - (id)tableView:(NSTableView*)tableView
65 objectValueForTableColumn:(NSTableColumn*)tableColumn
66 row:(NSInteger)rowIndex {
67 if (tableColumn == deviceNameColumn_) {
68 return base::SysUTF16ToNSString(prompt_->GetDeviceName(rowIndex));
69 } else if (tableColumn == serialNumberColumn_) {
70 return base::SysUTF16ToNSString(prompt_->GetDeviceSerialNumber(rowIndex));