OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/media_stream_infobar_delegate_android.h" | 5 #include "chrome/browser/media/media_stream_infobar_delegate_android.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
14 #include "chrome/browser/permissions/permission_uma_util.h" | |
15 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
16 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
17 #include "components/content_settings/core/common/content_settings_types.h" | 16 #include "components/content_settings/core/common/content_settings_types.h" |
18 #include "components/google/core/browser/google_util.h" | 17 #include "components/google/core/browser/google_util.h" |
19 #include "components/infobars/core/infobar.h" | 18 #include "components/infobars/core/infobar.h" |
20 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/origin_util.h" | 20 #include "content/public/common/origin_util.h" |
22 #include "grit/components_strings.h" | 21 #include "grit/components_strings.h" |
23 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
24 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); | 66 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
68 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { | 67 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { |
69 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); | 68 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); |
70 return true; | 69 return true; |
71 } | 70 } |
72 } | 71 } |
73 infobar_service->AddInfoBar(std::move(infobar)); | 72 infobar_service->AddInfoBar(std::move(infobar)); |
74 return true; | 73 return true; |
75 } | 74 } |
76 | 75 |
77 void MediaStreamInfoBarDelegateAndroid::RecordPermissionAcceptedUma( | |
78 int position, | |
79 bool persist) { | |
80 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( | |
81 controller_->GetPermissionTypeForContentSettingsType( | |
82 GetContentSettingType(position)), | |
83 persist); | |
84 } | |
85 | |
86 void MediaStreamInfoBarDelegateAndroid::RecordPermissionDeniedUma( | |
87 int position, | |
88 bool persist) { | |
89 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( | |
90 controller_->GetPermissionTypeForContentSettingsType( | |
91 GetContentSettingType(position)), | |
92 persist); | |
93 } | |
94 | |
95 infobars::InfoBarDelegate::InfoBarIdentifier | 76 infobars::InfoBarDelegate::InfoBarIdentifier |
96 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { | 77 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { |
97 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; | 78 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; |
98 } | 79 } |
99 | 80 |
100 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( | 81 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( |
101 std::unique_ptr<MediaStreamDevicesController> controller) | 82 std::unique_ptr<MediaStreamDevicesController> controller) |
102 : GroupedPermissionInfoBarDelegate( | 83 : GroupedPermissionInfoBarDelegate( |
103 controller->GetOrigin(), | 84 controller->GetOrigin(), |
104 GetContentSettingsTypes(controller.get())), | 85 GetContentSettingsTypes(controller.get())), |
105 controller_(std::move(controller)) { | 86 controller_(std::move(controller)) { |
106 DCHECK(controller_.get()); | 87 DCHECK(controller_.get()); |
107 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); | 88 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); |
108 } | 89 } |
109 | 90 |
110 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { | 91 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { |
111 // Deny the request if the infobar was closed with the 'x' button, since | 92 // Deny the request if the infobar was closed with the 'x' button, since |
112 // we don't want WebRTC to be waiting for an answer that will never come. | 93 // we don't want WebRTC to be waiting for an answer that will never come. |
113 controller_->Cancelled(); | 94 controller_->Cancelled(); |
114 } | 95 } |
115 | 96 |
116 MediaStreamInfoBarDelegateAndroid* | 97 MediaStreamInfoBarDelegateAndroid* |
117 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { | 98 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { |
118 return this; | 99 return this; |
119 } | 100 } |
120 | 101 |
121 bool MediaStreamInfoBarDelegateAndroid::Accept() { | 102 bool MediaStreamInfoBarDelegateAndroid::Accept() { |
122 bool persist_permission = true; | |
123 if (ShouldShowPersistenceToggle()) { | |
124 persist_permission = persist(); | |
125 | |
126 // TODO(dominickn): fold these metrics calls into | |
127 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076. | |
128 if (GetPermissionCount() == 2) { | |
129 RecordPermissionAcceptedUma(kGroupedInfobarAudioPosition, | |
130 persist_permission); | |
131 RecordPermissionAcceptedUma(kGroupedInfobarVideoPosition, | |
132 persist_permission); | |
133 } else { | |
134 DCHECK_EQ(1, GetPermissionCount()); | |
135 RecordPermissionAcceptedUma(0, persist_permission); | |
136 } | |
137 } | |
138 | |
139 controller_->set_persist(persist_permission); | |
140 if (GetPermissionCount() == 2) { | 103 if (GetPermissionCount() == 2) { |
141 controller_->GroupedRequestFinished( | 104 controller_->GroupedRequestFinished( |
142 GetAcceptState(kGroupedInfobarAudioPosition), | 105 GetAcceptState(kGroupedInfobarAudioPosition), |
143 GetAcceptState(kGroupedInfobarVideoPosition)); | 106 GetAcceptState(kGroupedInfobarVideoPosition)); |
144 } else { | 107 } else { |
145 DCHECK_EQ(1, GetPermissionCount()); | 108 DCHECK_EQ(1, GetPermissionCount()); |
146 controller_->PermissionGranted(); | 109 controller_->PermissionGranted(); |
147 } | 110 } |
148 return true; | 111 return true; |
149 } | 112 } |
150 | 113 |
151 bool MediaStreamInfoBarDelegateAndroid::Cancel() { | 114 bool MediaStreamInfoBarDelegateAndroid::Cancel() { |
152 bool persist_permission = true; | |
153 if (ShouldShowPersistenceToggle()) { | |
154 persist_permission = persist(); | |
155 | |
156 // TODO(dominickn): fold these metrics calls into | |
157 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076. | |
158 if (GetPermissionCount() == 2) { | |
159 RecordPermissionDeniedUma(kGroupedInfobarAudioPosition, | |
160 persist_permission); | |
161 RecordPermissionDeniedUma(kGroupedInfobarVideoPosition, | |
162 persist_permission); | |
163 } else { | |
164 DCHECK_EQ(1, GetPermissionCount()); | |
165 RecordPermissionDeniedUma(0, persist_permission); | |
166 } | |
167 } | |
168 controller_->set_persist(persist_permission); | |
169 controller_->PermissionDenied(); | 115 controller_->PermissionDenied(); |
170 return true; | 116 return true; |
171 } | 117 } |
OLD | NEW |