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

Side by Side Diff: chrome/browser/permissions/grouped_permission_infobar_delegate.cc

Issue 2319443002: Add InfoBarIdentifier to GroupedPermissionInfoBarDelegate (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/permissions/grouped_permission_infobar_delegate.h" 5 #include "chrome/browser/permissions/grouped_permission_infobar_delegate.h"
6 #include "chrome/grit/generated_resources.h" 6 #include "chrome/grit/generated_resources.h"
7 #include "chrome/grit/theme_resources.h" 7 #include "chrome/grit/theme_resources.h"
8 #include "components/url_formatter/elide_url.h" 8 #include "components/url_formatter/elide_url.h"
9 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
10 10
11 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( 11 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate(
12 const GURL& requesting_origin, 12 const GURL& requesting_origin,
13 const std::vector<ContentSettingsType>& types) 13 const std::vector<ContentSettingsType>& types)
14 : requesting_origin_(requesting_origin), 14 : requesting_origin_(requesting_origin),
15 types_(types), 15 types_(types),
16 accept_states_(types_.size(), true) {} 16 accept_states_(types_.size(), true) {}
17 17
18 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} 18 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {}
19 19
20 infobars::InfoBarDelegate::Type 20 infobars::InfoBarDelegate::Type
21 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { 21 GroupedPermissionInfoBarDelegate::GetInfoBarType() const {
22 return PAGE_ACTION_TYPE; 22 return PAGE_ACTION_TYPE;
23 } 23 }
24 24
25 int GroupedPermissionInfoBarDelegate::GetButtons() const { 25 int GroupedPermissionInfoBarDelegate::GetButtons() const {
26 if (GetPermissionCount() >= 2) 26 if (GetPermissionCount() >= 2)
Peter Kasting 2016/09/08 04:06:24 Nit: Prefer "> 1" to ">= 2" (slightly conceptually
lshang 2016/09/21 07:09:32 Done.
27 return ConfirmInfoBarDelegate::InfoBarButton::BUTTON_OK; 27 return ConfirmInfoBarDelegate::InfoBarButton::BUTTON_OK;
28 else 28 else
Peter Kasting 2016/09/08 04:06:24 Nit: No else after return (3 places)
lshang 2016/09/21 07:09:33 Done.
29 return ConfirmInfoBarDelegate::GetButtons(); 29 return ConfirmInfoBarDelegate::GetButtons();
30 } 30 }
31 31
32 infobars::InfoBarDelegate::InfoBarIdentifier
33 GroupedPermissionInfoBarDelegate::GetIdentifier() const {
34 return GROUPED_PERMISSION_INFOBAR_DELEGATE;
35 }
36
32 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( 37 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel(
33 InfoBarButton button) const { 38 InfoBarButton button) const {
34 if (GetPermissionCount() >= 2) { 39 if (GetPermissionCount() >= 2) {
35 return ConfirmInfoBarDelegate::GetButtonLabel(button); 40 return ConfirmInfoBarDelegate::GetButtonLabel(button);
Peter Kasting 2016/09/08 04:06:24 It's really odd that the function above uses the b
tsergeant 2016/09/08 05:19:57 This is an artifact of how the UI works out. It mi
Peter Kasting 2016/09/08 06:24:08 I think that would probably make sense. I would a
36 } else { 41 } else {
37 return l10n_util::GetStringUTF16( 42 return l10n_util::GetStringUTF16(
38 (button == BUTTON_OK) ? IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY); 43 (button == BUTTON_OK) ? IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY);
39 } 44 }
40 } 45 }
41 46
42 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { 47 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const {
43 return l10n_util::GetStringFUTF16( 48 return l10n_util::GetStringFUTF16(
44 IDS_PERMISSIONS_BUBBLE_PROMPT, 49 IDS_PERMISSIONS_BUBBLE_PROMPT,
45 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); 50 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_));
46 } 51 }
47 52
48 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const { 53 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const {
49 return types_.size(); 54 return types_.size();
Peter Kasting 2016/09/08 04:06:24 Nit: This is an implicit cast from size_t to int.
lshang 2016/09/21 07:09:32 Done.
50 } 55 }
51 56
52 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( 57 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType(
53 int index) const { 58 int index) const {
54 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); 59 DCHECK(index >= 0 && index < static_cast<int>(types_.size()));
55 return types_[index]; 60 return types_[index];
Peter Kasting 2016/09/08 04:06:24 Nit: This line means this function should be takin
lshang 2016/09/21 07:09:32 Done.
56 } 61 }
57 62
58 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(int index) const { 63 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(int index) const {
59 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); 64 DCHECK(index >= 0 && index < static_cast<int>(types_.size()));
60 ContentSettingsType type = types_[index]; 65 ContentSettingsType type = types_[index];
61 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { 66 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
62 return IDR_INFOBAR_MEDIA_STREAM_MIC; 67 return IDR_INFOBAR_MEDIA_STREAM_MIC;
63 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { 68 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
64 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; 69 return IDR_INFOBAR_MEDIA_STREAM_CAMERA;
65 } 70 }
66 return IDR_INFOBAR_WARNING; 71 return IDR_INFOBAR_WARNING;
67 } 72 }
68 73
69 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment( 74 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment(
70 int index) const { 75 int index) const {
71 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); 76 DCHECK(index >= 0 && index < static_cast<int>(types_.size()));
72 ContentSettingsType type = types_[index]; 77 ContentSettingsType type = types_[index];
73 int message_id; 78 int message_id;
74 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { 79 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
75 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT; 80 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT;
76 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { 81 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
77 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT; 82 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT;
78 } else { 83 } else {
79 NOTREACHED(); 84 NOTREACHED();
80 return base::string16(); 85 return base::string16();
81 } 86 }
82 return l10n_util::GetStringUTF16(message_id); 87 return l10n_util::GetStringUTF16(message_id);
Peter Kasting 2016/09/08 04:06:24 Nit: Simpler: const bool is_mic = (type == CONT
lshang 2016/09/21 07:09:32 Done.
83 } 88 }
84 89
85 void GroupedPermissionInfoBarDelegate::ToggleAccept(int position, 90 void GroupedPermissionInfoBarDelegate::ToggleAccept(int position,
86 bool new_value) { 91 bool new_value) {
87 DCHECK(position >= 0 && position < static_cast<int>(types_.size())); 92 DCHECK(position >= 0 && position < static_cast<int>(types_.size()));
88 accept_states_[position] = new_value; 93 accept_states_[position] = new_value;
89 } 94 }
90 95
91 bool GroupedPermissionInfoBarDelegate::GetAcceptState(int position) { 96 bool GroupedPermissionInfoBarDelegate::GetAcceptState(int position) {
92 DCHECK(position >= 0 && position < static_cast<int>(types_.size())); 97 DCHECK(position >= 0 && position < static_cast<int>(types_.size()));
93 return accept_states_[position]; 98 return accept_states_[position];
94 } 99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698