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

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

Issue 2339863002: Use vector of PermissionRequest instead of ContentSettingsTypes for GroupedPermissionInfoBarDelegate (Closed)
Patch Set: Merge branch 'undo_media_infobar_delegate' into use_array_of_PR_for_GPID 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
« no previous file with comments | « chrome/browser/permissions/grouped_permission_infobar_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/media/webrtc/media_stream_devices_controller.h"
tsergeant 2016/09/22 06:53:56 Is this include necessary?
lshang 2016/09/27 07:21:52 Removed.
5 #include "chrome/browser/permissions/grouped_permission_infobar_delegate.h" 6 #include "chrome/browser/permissions/grouped_permission_infobar_delegate.h"
7 #include "chrome/browser/permissions/permission_request.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"
9 #include "components/url_formatter/elide_url.h" 11 #include "components/url_formatter/elide_url.h"
10 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
11 13
14 namespace {
15
16 ContentSettingsType PermissionRequestTypeToContentType(
tsergeant 2016/09/22 06:53:56 I think it would be good to avoid adding this conv
lshang 2016/09/27 07:21:52 I moved this conversion to PermissionRequest, but
17 PermissionRequestType request_type) {
18 ContentSettingsType type = CONTENT_SETTINGS_TYPE_DEFAULT;
19 switch (request_type) {
20 case PermissionRequestType::PERMISSION_GEOLOCATION:
21 type = CONTENT_SETTINGS_TYPE_GEOLOCATION;
22 break;
23 case PermissionRequestType::PERMISSION_NOTIFICATIONS:
24 type = CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
25 break;
26 case PermissionRequestType::PERMISSION_MIDI_SYSEX:
27 type = CONTENT_SETTINGS_TYPE_MIDI_SYSEX;
28 break;
29 case PermissionRequestType::PERMISSION_PUSH_MESSAGING:
30 type = CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
31 break;
32 case PermissionRequestType::PERMISSION_PROTECTED_MEDIA_IDENTIFIER:
33 type = CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER;
34 break;
35 default:
36 NOTREACHED();
37 }
38 return type;
39 }
40
41 } // namespace
42
12 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( 43 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate(
13 const GURL& requesting_origin, 44 const GURL& requesting_origin,
14 const std::vector<ContentSettingsType>& types) 45 const std::vector<PermissionRequest*>& requests)
15 : requesting_origin_(requesting_origin), 46 : requesting_origin_(requesting_origin),
16 types_(types), 47 requests_(requests),
17 accept_states_(types_.size(), true), 48 accept_states_(requests_.size(), true),
18 persist_(true) {} 49 persist_(true) {}
19 50
20 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} 51 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {}
21 52
22 infobars::InfoBarDelegate::Type 53 infobars::InfoBarDelegate::Type
23 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { 54 GroupedPermissionInfoBarDelegate::GetInfoBarType() const {
24 return PAGE_ACTION_TYPE; 55 return PAGE_ACTION_TYPE;
25 } 56 }
26 57
27 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { 58 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const {
(...skipping 17 matching lines...) Expand all
45 } 76 }
46 } 77 }
47 78
48 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { 79 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const {
49 return l10n_util::GetStringFUTF16( 80 return l10n_util::GetStringFUTF16(
50 IDS_PERMISSIONS_BUBBLE_PROMPT, 81 IDS_PERMISSIONS_BUBBLE_PROMPT,
51 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); 82 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_));
52 } 83 }
53 84
54 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const { 85 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const {
55 return types_.size(); 86 return requests_.size();
56 } 87 }
57 88
58 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( 89 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType(
59 int index) const { 90 int index) const {
60 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); 91 DCHECK(index >= 0 && index < static_cast<int>(requests_.size()));
61 return types_[index]; 92 return PermissionRequestTypeToContentType(
tsergeant 2016/09/22 06:53:56 The way that this method was written doesn't neces
lshang 2016/09/27 07:21:52 I think this CL is not ready for adding support fo
tsergeant 2016/09/28 00:01:06 Yeah, you're right -- there are complications in t
93 requests_[index]->GetPermissionRequestType());
62 } 94 }
63 95
64 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(int index) const { 96 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(int index) const {
65 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); 97 DCHECK(index >= 0 && index < static_cast<int>(requests_.size()));
66 ContentSettingsType type = types_[index]; 98 return requests_[index]->GetIconId();
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 } 99 }
74 100
75 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment( 101 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment(
76 int index) const { 102 int index) const {
77 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); 103 DCHECK(index >= 0 && index < static_cast<int>(requests_.size()));
78 ContentSettingsType type = types_[index]; 104 return requests_[index]->GetMessageTextFragment();
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 } 105 }
90 106
91 void GroupedPermissionInfoBarDelegate::ToggleAccept(int position, 107 void GroupedPermissionInfoBarDelegate::ToggleAccept(int position,
92 bool new_value) { 108 bool new_value) {
93 DCHECK(position >= 0 && position < static_cast<int>(types_.size())); 109 DCHECK(position >= 0 && position < static_cast<int>(requests_.size()));
94 accept_states_[position] = new_value; 110 accept_states_[position] = new_value;
95 } 111 }
96 112
97 bool GroupedPermissionInfoBarDelegate::GetAcceptState(int position) { 113 bool GroupedPermissionInfoBarDelegate::GetAcceptState(int position) {
98 DCHECK(position >= 0 && position < static_cast<int>(types_.size())); 114 DCHECK(position >= 0 && position < static_cast<int>(requests_.size()));
99 return accept_states_[position]; 115 return accept_states_[position];
100 } 116 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/grouped_permission_infobar_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698