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

Side by Side Diff: chrome/browser/permissions/grouped_permission_infobar_delegate_android.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_android .h"
6
7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/browser/permissions/permission_util.h"
10 #include "chrome/browser/ui/android/infobars/grouped_permission_infobar.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "chrome/grit/theme_resources.h"
13 #include "components/infobars/core/infobar.h"
14 #include "components/url_formatter/elide_url.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/strings/grit/ui_strings.h"
17
18 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {}
19
20 // static
21 infobars::InfoBar* GroupedPermissionInfoBarDelegate::Create(
22 InfoBarService* infobar_service,
23 const GURL& requesting_origin,
24 const std::vector<ContentSettingsType>& types) {
25 return infobar_service->AddInfoBar(
26 base::MakeUnique<GroupedPermissionInfoBar>(base::WrapUnique(
27 new GroupedPermissionInfoBarDelegate(requesting_origin, types))));
28 }
29
30 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const {
31 return PermissionUtil::ShouldShowPersistenceToggle();
32 }
33
34 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType(
35 size_t position) const {
36 DCHECK_LT(position, types_.size());
37 return types_[position];
38 }
39
40 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(
41 size_t position) const {
42 DCHECK_LT(position, types_.size());
43 ContentSettingsType type = types_[position];
44 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)
45 return IDR_INFOBAR_MEDIA_STREAM_MIC;
46 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)
47 return IDR_INFOBAR_MEDIA_STREAM_CAMERA;
48
49 return IDR_INFOBAR_WARNING;
50 }
51
52 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment(
53 size_t position) const {
54 DCHECK_LT(position, types_.size());
55 ContentSettingsType type = types_[position];
56
57 const bool is_mic = (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
58 DCHECK(is_mic || (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
59 return l10n_util::GetStringUTF16(
60 is_mic ? IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT
61 : IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT);
62 }
63
64 void GroupedPermissionInfoBarDelegate::ToggleAccept(size_t position,
65 bool new_value) {
66 DCHECK_LT(position, types_.size());
67 accept_states_[position] = new_value;
68 }
69
70 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const {
71 return l10n_util::GetStringFUTF16(
72 IDS_PERMISSIONS_BUBBLE_PROMPT,
73 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_));
74 }
75
76 bool GroupedPermissionInfoBarDelegate::GetAcceptState(size_t position) {
77 DCHECK_LT(position, types_.size());
78 return accept_states_[position];
79 }
80
81 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate(
82 const GURL& requesting_origin,
83 const std::vector<ContentSettingsType>& types)
84 : requesting_origin_(requesting_origin),
85 types_(types),
86 accept_states_(types_.size(), true),
87 persist_(true) {}
88
89 infobars::InfoBarDelegate::InfoBarIdentifier
90 GroupedPermissionInfoBarDelegate::GetIdentifier() const {
91 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID;
92 }
93
94 infobars::InfoBarDelegate::Type
95 GroupedPermissionInfoBarDelegate::GetInfoBarType() const {
96 return PAGE_ACTION_TYPE;
97 }
98
99 int GroupedPermissionInfoBarDelegate::GetButtons() const {
100 // If there is only one permission in the infobar, we show both OK and CANCEL
101 // button to allow/deny it. If there are multiple, we only show OK button
102 // which means making decision for all permissions according to each accept
103 // toggle.
104 return (permission_count() > 1) ? BUTTON_OK : (BUTTON_OK | BUTTON_CANCEL);
105 }
106
107 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel(
108 InfoBarButton button) const {
109 if (permission_count() > 1) {
110 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK
111 : IDS_APP_CANCEL);
112 }
113
114 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW
115 : IDS_PERMISSION_DENY);
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698