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

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

Issue 2319443002: Add InfoBarIdentifier to GroupedPermissionInfoBarDelegate (Closed)
Patch Set: address review comments 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_android .h"
6
7 #include "chrome/browser/infobars/infobar_service.h"
6 #include "chrome/browser/permissions/permission_util.h" 8 #include "chrome/browser/permissions/permission_util.h"
7 #include "chrome/grit/generated_resources.h" 9 #include "chrome/grit/generated_resources.h"
8 #include "chrome/grit/theme_resources.h" 10 #include "chrome/grit/theme_resources.h"
11 #include "components/infobars/core/infobar.h"
9 #include "components/url_formatter/elide_url.h" 12 #include "components/url_formatter/elide_url.h"
10 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
11 14
12 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate(
13 const GURL& requesting_origin,
14 const std::vector<ContentSettingsType>& types)
15 : requesting_origin_(requesting_origin),
16 types_(types),
17 accept_states_(types_.size(), true),
18 persist_(true) {}
19
20 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} 15 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {}
21 16
22 infobars::InfoBarDelegate::Type 17 // static
23 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { 18 infobars::InfoBar* GroupedPermissionInfoBarDelegate::Create(
24 return PAGE_ACTION_TYPE; 19 InfoBarService* infobar_service,
20 const GURL& requesting_origin,
21 const std::vector<ContentSettingsType>& types) {
22 return infobar_service->AddInfoBar(CreateGroupedPermissionInfoBar(
23 std::unique_ptr<GroupedPermissionInfoBarDelegate>(
24 new GroupedPermissionInfoBarDelegate(requesting_origin, types))));
25 } 25 }
26 26
27 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { 27 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const {
28 return PermissionUtil::ShouldShowPersistenceToggle(); 28 return PermissionUtil::ShouldShowPersistenceToggle();
29 } 29 }
30 30
31 int GroupedPermissionInfoBarDelegate::GetButtons() const {
32 if (GetPermissionCount() >= 2)
33 return ConfirmInfoBarDelegate::InfoBarButton::BUTTON_OK;
34 else
35 return ConfirmInfoBarDelegate::GetButtons();
36 }
37
38 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel(
39 InfoBarButton button) const {
40 if (GetPermissionCount() >= 2) {
41 return ConfirmInfoBarDelegate::GetButtonLabel(button);
42 } else {
43 return l10n_util::GetStringUTF16(
44 (button == BUTTON_OK) ? IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY);
45 }
46 }
47
48 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const {
49 return l10n_util::GetStringFUTF16(
50 IDS_PERMISSIONS_BUBBLE_PROMPT,
51 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_));
52 }
53
54 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const {
55 return types_.size();
56 }
57
58 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( 31 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType(
59 int index) const { 32 size_t index) const {
60 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); 33 DCHECK_LT(index, types_.size());
61 return types_[index]; 34 return types_[index];
62 } 35 }
63 36
64 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(int index) const { 37 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(
65 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); 38 size_t index) const {
39 DCHECK_LT(index, types_.size());
66 ContentSettingsType type = types_[index]; 40 ContentSettingsType type = types_[index];
67 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { 41 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
Peter Kasting 2016/09/21 18:44:39 Nit: {} not necessary
lshang 2016/09/22 02:11:30 Done.
68 return IDR_INFOBAR_MEDIA_STREAM_MIC; 42 return IDR_INFOBAR_MEDIA_STREAM_MIC;
69 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { 43 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
Peter Kasting 2016/09/21 18:44:39 Nit: No else after return
lshang 2016/09/22 02:11:30 Done.
70 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; 44 return IDR_INFOBAR_MEDIA_STREAM_CAMERA;
71 } 45 }
72 return IDR_INFOBAR_WARNING; 46 return IDR_INFOBAR_WARNING;
73 } 47 }
74 48
75 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment( 49 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const {
76 int index) const { 50 return l10n_util::GetStringFUTF16(
77 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); 51 IDS_PERMISSIONS_BUBBLE_PROMPT,
78 ContentSettingsType type = types_[index]; 52 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_));
79 int message_id;
80 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
81 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT;
82 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
83 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT;
84 } else {
85 NOTREACHED();
86 return base::string16();
87 }
88 return l10n_util::GetStringUTF16(message_id);
89 } 53 }
90 54
91 void GroupedPermissionInfoBarDelegate::ToggleAccept(int position, 55 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment(
56 size_t index) const {
57 DCHECK_LT(index, types_.size());
58 ContentSettingsType type = types_[index];
59
60 const bool is_mic = (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
61 DCHECK(is_mic || (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
62 return l10n_util::GetStringUTF16(
63 is_mic ? IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT
64 : IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT);
65 }
66
67 void GroupedPermissionInfoBarDelegate::ToggleAccept(size_t position,
92 bool new_value) { 68 bool new_value) {
93 DCHECK(position >= 0 && position < static_cast<int>(types_.size())); 69 DCHECK_LT(position, types_.size());
94 accept_states_[position] = new_value; 70 accept_states_[position] = new_value;
95 } 71 }
96 72
97 bool GroupedPermissionInfoBarDelegate::GetAcceptState(int position) { 73 bool GroupedPermissionInfoBarDelegate::GetAcceptState(size_t position) {
98 DCHECK(position >= 0 && position < static_cast<int>(types_.size())); 74 DCHECK_LT(position, types_.size());
99 return accept_states_[position]; 75 return accept_states_[position];
100 } 76 }
77
78 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate(
79 const GURL& requesting_origin,
80 const std::vector<ContentSettingsType>& types)
81 : requesting_origin_(requesting_origin),
82 types_(types),
83 accept_states_(types_.size(), true),
84 persist_(true) {}
85
86 infobars::InfoBarDelegate::InfoBarIdentifier
87 GroupedPermissionInfoBarDelegate::GetIdentifier() const {
88 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID;
89 }
90
91 infobars::InfoBarDelegate::Type
92 GroupedPermissionInfoBarDelegate::GetInfoBarType() const {
93 return PAGE_ACTION_TYPE;
94 }
95
96 int GroupedPermissionInfoBarDelegate::GetButtons() const {
97 if (GetPermissionCount() > 1)
98 return ConfirmInfoBarDelegate::InfoBarButton::BUTTON_OK;
99
100 return ConfirmInfoBarDelegate::GetButtons();
Peter Kasting 2016/09/21 18:44:39 Nit: I still think it's strange for these two meth
lshang 2016/09/22 02:11:30 Done.
101 }
102
103 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel(
104 InfoBarButton button) const {
105 if (GetPermissionCount() > 1) {
106 return ConfirmInfoBarDelegate::GetButtonLabel(button);
107 } else {
Peter Kasting 2016/09/21 18:44:39 Nit: No else after return
lshang 2016/09/22 02:11:30 Done.
108 return l10n_util::GetStringUTF16(
109 (button == BUTTON_OK) ? IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY);
110 }
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698