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

Side by Side Diff: chrome/browser/extensions/device_permissions_dialog_controller.cc

Issue 2390823005: Update device permissions dialog ui for Chrome apps and extensions (Closed)
Patch Set: address more comments Created 4 years 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 2016 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 #include "chrome/browser/extensions/device_permissions_dialog_controller.h"
6
7 #include "chrome/grit/generated_resources.h"
8 #include "extensions/strings/grit/extensions_strings.h"
9 #include "ui/base/l10n/l10n_util.h"
10
11 DevicePermissionsDialogController::DevicePermissionsDialogController(
12 content::RenderFrameHost* owner,
13 scoped_refptr<extensions::DevicePermissionsPrompt::Prompt> prompt)
14 : ChooserController(
15 owner,
16 prompt->multiple() ? IDS_DEVICE_PERMISSIONS_PROMPT_MULTIPLE_SELECTION
17 : IDS_DEVICE_PERMISSIONS_PROMPT_SINGLE_SELECTION,
18 prompt->multiple() ? IDS_DEVICE_PERMISSIONS_PROMPT_MULTIPLE_SELECTION
19 : IDS_DEVICE_PERMISSIONS_PROMPT_SINGLE_SELECTION),
20 prompt_(prompt) {
21 prompt_->SetObserver(this);
22 }
23
24 DevicePermissionsDialogController::~DevicePermissionsDialogController() {
25 prompt_->SetObserver(nullptr);
26 }
27
28 bool DevicePermissionsDialogController::ShouldShowFootnoteView() const {
29 return false;
30 }
31
32 bool DevicePermissionsDialogController::AllowMultipleSelection() const {
33 return prompt_->multiple();
34 }
35
36 base::string16 DevicePermissionsDialogController::GetNoOptionsText() const {
37 return l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT);
38 }
39
40 base::string16 DevicePermissionsDialogController::GetOkButtonLabel() const {
41 return l10n_util::GetStringUTF16(IDS_DEVICE_PERMISSIONS_DIALOG_SELECT);
42 }
43
44 size_t DevicePermissionsDialogController::NumOptions() const {
45 return prompt_->GetDeviceCount();
46 }
47
48 base::string16 DevicePermissionsDialogController::GetOption(
49 size_t index) const {
50 base::string16 device_name = prompt_->GetDeviceName(index);
51 const auto& it = device_name_map_.find(device_name);
52 DCHECK(it != device_name_map_.end());
53 return it->second == 1
54 ? device_name
55 : l10n_util::GetStringFUTF16(
56 IDS_DEVICE_CHOOSER_DEVICE_NAME_WITH_ID, device_name,
57 prompt_->GetDeviceSerialNumber(index));
58 }
59
60 void DevicePermissionsDialogController::RefreshOptions() {}
61
62 base::string16 DevicePermissionsDialogController::GetStatus() const {
63 return base::string16();
64 }
65
66 void DevicePermissionsDialogController::Select(
67 const std::vector<size_t>& indices) {
68 for (size_t index : indices)
69 prompt_->GrantDevicePermission(index);
70 prompt_->Dismissed();
71 }
72
73 void DevicePermissionsDialogController::Cancel() {
74 prompt_->Dismissed();
75 }
76
77 void DevicePermissionsDialogController::Close() {
78 prompt_->Dismissed();
79 }
80
81 void DevicePermissionsDialogController::OpenHelpCenterUrl() const {}
82
83 void DevicePermissionsDialogController::OnDeviceAdded(
84 size_t index,
85 const base::string16& device_name) {
86 if (view()) {
87 ++device_name_map_[device_name];
88 view()->OnOptionAdded(index);
89 }
90 }
91
92 void DevicePermissionsDialogController::OnDeviceRemoved(
93 size_t index,
94 const base::string16& device_name) {
95 if (view()) {
96 DCHECK_GT(device_name_map_[device_name], 0);
97 if (--device_name_map_[device_name] == 0)
98 device_name_map_.erase(device_name);
99 view()->OnOptionRemoved(index);
100 }
101 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/device_permissions_dialog_controller.h ('k') | chrome/browser/ui/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698