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

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

Issue 2319443002: Add InfoBarIdentifier to GroupedPermissionInfoBarDelegate (Closed)
Patch Set: minor change in comments Created 4 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 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/permissions/grouped_permission_infobar_delegate.h"
6 #include "chrome/browser/permissions/permission_util.h"
7 #include "chrome/grit/generated_resources.h"
8 #include "chrome/grit/theme_resources.h"
9 #include "components/url_formatter/elide_url.h"
10 #include "ui/base/l10n/l10n_util.h"
11
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() {}
21
22 infobars::InfoBarDelegate::Type
23 GroupedPermissionInfoBarDelegate::GetInfoBarType() const {
24 return PAGE_ACTION_TYPE;
25 }
26
27 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const {
28 return PermissionUtil::ShouldShowPersistenceToggle();
29 }
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(
59 int index) const {
60 DCHECK(index >= 0 && index < static_cast<int>(types_.size()));
61 return types_[index];
62 }
63
64 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(int index) const {
65 DCHECK(index >= 0 && index < static_cast<int>(types_.size()));
66 ContentSettingsType type = types_[index];
67 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
68 return IDR_INFOBAR_MEDIA_STREAM_MIC;
69 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
70 return IDR_INFOBAR_MEDIA_STREAM_CAMERA;
71 }
72 return IDR_INFOBAR_WARNING;
73 }
74
75 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment(
76 int index) const {
77 DCHECK(index >= 0 && index < static_cast<int>(types_.size()));
78 ContentSettingsType type = types_[index];
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 }
90
91 void GroupedPermissionInfoBarDelegate::ToggleAccept(int position,
92 bool new_value) {
93 DCHECK(position >= 0 && position < static_cast<int>(types_.size()));
94 accept_states_[position] = new_value;
95 }
96
97 bool GroupedPermissionInfoBarDelegate::GetAcceptState(int position) {
98 DCHECK(position >= 0 && position < static_cast<int>(types_.size()));
99 return accept_states_[position];
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698