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

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

Issue 2019573002: Permissions: Allow control of individual requests in media permission infobars (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: benwells@ review comments Created 4 years, 6 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 "components/url_formatter/elide_url.h" 7 #include "components/url_formatter/elide_url.h"
8 #include "grit/theme_resources.h" 8 #include "grit/theme_resources.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), types_(types) {} 14 : requesting_origin_(requesting_origin),
15 types_(types),
16 accept_states_(types_.size(), true) {
benwells 2016/06/06 01:10:02 Super nit: {} on same line to match destructor.
tsergeant 2016/06/06 02:43:55 Done.
17 }
15 18
16 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} 19 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {}
17 20
18 infobars::InfoBarDelegate::Type 21 infobars::InfoBarDelegate::Type
19 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { 22 GroupedPermissionInfoBarDelegate::GetInfoBarType() const {
20 return PAGE_ACTION_TYPE; 23 return PAGE_ACTION_TYPE;
21 } 24 }
22 25
26 int GroupedPermissionInfoBarDelegate::GetButtons() const {
27 if (GetPermissionCount() >= 2)
28 return ConfirmInfoBarDelegate::InfoBarButton::BUTTON_OK;
29 else
30 return ConfirmInfoBarDelegate::GetButtons();
31 }
32
23 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( 33 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel(
24 InfoBarButton button) const { 34 InfoBarButton button) const {
25 return l10n_util::GetStringUTF16( 35 if (GetPermissionCount() >= 2) {
26 (button == BUTTON_OK) ? IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY); 36 return ConfirmInfoBarDelegate::GetButtonLabel(button);
37 } else {
38 return l10n_util::GetStringUTF16(
39 (button == BUTTON_OK) ? IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY);
40 }
27 } 41 }
28 42
29 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { 43 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const {
30 return l10n_util::GetStringFUTF16( 44 return l10n_util::GetStringFUTF16(
31 IDS_PERMISSIONS_BUBBLE_PROMPT, 45 IDS_PERMISSIONS_BUBBLE_PROMPT,
32 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); 46 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_));
33 } 47 }
34 48
35 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const { 49 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const {
36 return types_.size(); 50 return types_.size();
(...skipping 24 matching lines...) Expand all
61 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { 75 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
62 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT; 76 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT;
63 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { 77 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
64 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT; 78 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT;
65 } else { 79 } else {
66 NOTREACHED(); 80 NOTREACHED();
67 return base::string16(); 81 return base::string16();
68 } 82 }
69 return l10n_util::GetStringUTF16(message_id); 83 return l10n_util::GetStringUTF16(message_id);
70 } 84 }
85
86 void GroupedPermissionInfoBarDelegate::ToggleAccept(int position,
87 bool new_value) {
88 DCHECK(position >= 0 && position < static_cast<int>(types_.size()));
89 accept_states_[position] = new_value;
90 }
91
92 bool GroupedPermissionInfoBarDelegate::GetAcceptState(int position) {
93 DCHECK(position >= 0 && position < static_cast<int>(types_.size()));
94 return accept_states_[position];
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698