| 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/webrtc/media_stream_infobar_delegate_android.h" | 5 #include "chrome/browser/media/webrtc/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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 void DoNothing(bool update_content_setting, PermissionAction decision) {} | 29 void DoNothing(bool update_content_setting, PermissionAction decision) {} |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 // static | 33 // static |
| 34 bool MediaStreamInfoBarDelegateAndroid::Create( | 34 bool MediaStreamInfoBarDelegateAndroid::Create( |
| 35 content::WebContents* web_contents, | 35 content::WebContents* web_contents, |
| 36 bool user_gesture, | 36 bool user_gesture, |
| 37 std::unique_ptr<MediaStreamDevicesController> controller) { | 37 std::unique_ptr<MediaStreamDevicesController::Request> request) { |
| 38 InfoBarService* infobar_service = | 38 InfoBarService* infobar_service = |
| 39 InfoBarService::FromWebContents(web_contents); | 39 InfoBarService::FromWebContents(web_contents); |
| 40 if (!infobar_service) { | 40 if (!infobar_service) { |
| 41 // Deny the request if there is no place to show the infobar, e.g. when | 41 // Deny the request if there is no place to show the infobar, e.g. when |
| 42 // the request comes from a background extension page. | 42 // the request comes from a background extension page. |
| 43 controller->Cancelled(); | 43 request->Cancelled(); |
| 44 return false; | 44 return false; |
| 45 } | 45 } |
| 46 | 46 |
| 47 std::unique_ptr<infobars::InfoBar> infobar( | 47 std::unique_ptr<infobars::InfoBar> infobar( |
| 48 CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>( | 48 CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>( |
| 49 new MediaStreamInfoBarDelegateAndroid( | 49 new MediaStreamInfoBarDelegateAndroid( |
| 50 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 50 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
| 51 user_gesture, | 51 user_gesture, std::move(request))))); |
| 52 std::move(controller))))); | |
| 53 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 52 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
| 54 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); | 53 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
| 55 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { | 54 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { |
| 56 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); | 55 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); |
| 57 return true; | 56 return true; |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 infobar_service->AddInfoBar(std::move(infobar)); | 59 infobar_service->AddInfoBar(std::move(infobar)); |
| 61 return true; | 60 return true; |
| 62 } | 61 } |
| 63 | 62 |
| 64 infobars::InfoBarDelegate::InfoBarIdentifier | 63 infobars::InfoBarDelegate::InfoBarIdentifier |
| 65 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { | 64 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { |
| 66 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; | 65 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; |
| 67 } | 66 } |
| 68 | 67 |
| 69 infobars::InfoBarDelegate::Type | 68 infobars::InfoBarDelegate::Type |
| 70 MediaStreamInfoBarDelegateAndroid::GetInfoBarType() const { | 69 MediaStreamInfoBarDelegateAndroid::GetInfoBarType() const { |
| 71 return PAGE_ACTION_TYPE; | 70 return PAGE_ACTION_TYPE; |
| 72 } | 71 } |
| 73 | 72 |
| 74 int MediaStreamInfoBarDelegateAndroid::GetIconId() const { | 73 int MediaStreamInfoBarDelegateAndroid::GetIconId() const { |
| 75 return controller_->IsAskingForVideo() ? IDR_INFOBAR_MEDIA_STREAM_CAMERA | 74 return request_->IsAskingForVideo() ? IDR_INFOBAR_MEDIA_STREAM_CAMERA |
| 76 : IDR_INFOBAR_MEDIA_STREAM_MIC; | 75 : IDR_INFOBAR_MEDIA_STREAM_MIC; |
| 77 } | 76 } |
| 78 | 77 |
| 79 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( | 78 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( |
| 80 Profile* profile, | 79 Profile* profile, |
| 81 bool user_gesture, | 80 bool user_gesture, |
| 82 std::unique_ptr<MediaStreamDevicesController> controller) | 81 std::unique_ptr<MediaStreamDevicesController::Request> request) |
| 83 : PermissionInfoBarDelegate( | 82 : PermissionInfoBarDelegate( |
| 84 controller->GetOrigin(), | 83 request->GetOrigin(), |
| 85 // The content setting type and permission type here are only passed | 84 // The content setting type and permission type here are only passed |
| 86 // in to fit into PermissionInfoBarDelegate, even though media infobar | 85 // in to fit into PermissionInfoBarDelegate, even though media infobar |
| 87 // controls both mic and camera. This is a temporary state for easy | 86 // controls both mic and camera. This is a temporary state for easy |
| 88 // refactoring. | 87 // refactoring. |
| 89 // TODO(lshang): Merge MediaStreamInfoBarDelegateAndroid into | 88 // TODO(lshang): Merge MediaStreamInfoBarDelegateAndroid into |
| 90 // GroupedPermissionInfoBarDelegate. See crbug.com/606138. | 89 // GroupedPermissionInfoBarDelegate. See crbug.com/606138. |
| 91 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 90 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 92 user_gesture, | 91 user_gesture, |
| 93 profile, | 92 profile, |
| 94 // This is only passed in to fit into PermissionInfoBarDelegate. | 93 // This is only passed in to fit into PermissionInfoBarDelegate. |
| 95 // Infobar accepted/denied/dismissed is handled by controller, not via | 94 // Infobar accepted/denied/dismissed is handled by |request|, not via |
| 96 // callbacks. | 95 // callbacks. |
| 97 base::Bind(&DoNothing)), | 96 base::Bind(&DoNothing)), |
| 98 controller_(std::move(controller)) { | 97 request_(std::move(request)) { |
| 99 DCHECK(controller_.get()); | 98 DCHECK(request_.get()); |
| 100 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); | 99 DCHECK(request_->IsAskingForAudio() || request_->IsAskingForVideo()); |
| 101 } | 100 } |
| 102 | 101 |
| 103 MediaStreamInfoBarDelegateAndroid::~MediaStreamInfoBarDelegateAndroid() {} | 102 MediaStreamInfoBarDelegateAndroid::~MediaStreamInfoBarDelegateAndroid() {} |
| 104 | 103 |
| 105 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { | 104 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { |
| 106 // Deny the request if the infobar was closed with the 'x' button, since | 105 // Deny the request if the infobar was closed with the 'x' button, since |
| 107 // we don't want WebRTC to be waiting for an answer that will never come. | 106 // we don't want WebRTC to be waiting for an answer that will never come. |
| 108 controller_->Cancelled(); | 107 request_->Cancelled(); |
| 109 } | 108 } |
| 110 | 109 |
| 111 MediaStreamInfoBarDelegateAndroid* | 110 MediaStreamInfoBarDelegateAndroid* |
| 112 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { | 111 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { |
| 113 return this; | 112 return this; |
| 114 } | 113 } |
| 115 | 114 |
| 116 base::string16 MediaStreamInfoBarDelegateAndroid::GetMessageText() const { | 115 base::string16 MediaStreamInfoBarDelegateAndroid::GetMessageText() const { |
| 117 return controller_->GetMessageText(); | 116 return request_->GetMessageText(); |
| 118 } | 117 } |
| 119 | 118 |
| 120 base::string16 MediaStreamInfoBarDelegateAndroid::GetButtonLabel( | 119 base::string16 MediaStreamInfoBarDelegateAndroid::GetButtonLabel( |
| 121 InfoBarButton button) const { | 120 InfoBarButton button) const { |
| 122 switch (button) { | 121 switch (button) { |
| 123 case BUTTON_OK: | 122 case BUTTON_OK: |
| 124 return l10n_util::GetStringUTF16(IDS_MEDIA_CAPTURE_ALLOW); | 123 return l10n_util::GetStringUTF16(IDS_MEDIA_CAPTURE_ALLOW); |
| 125 case BUTTON_CANCEL: | 124 case BUTTON_CANCEL: |
| 126 return l10n_util::GetStringUTF16(IDS_MEDIA_CAPTURE_BLOCK); | 125 return l10n_util::GetStringUTF16(IDS_MEDIA_CAPTURE_BLOCK); |
| 127 default: | 126 default: |
| 128 NOTREACHED(); | 127 NOTREACHED(); |
| 129 return base::string16(); | 128 return base::string16(); |
| 130 } | 129 } |
| 131 } | 130 } |
| 132 | 131 |
| 133 int MediaStreamInfoBarDelegateAndroid::GetMessageResourceId() const { | 132 int MediaStreamInfoBarDelegateAndroid::GetMessageResourceId() const { |
| 134 if (!controller_->IsAskingForAudio()) | 133 if (!request_->IsAskingForAudio()) |
| 135 return IDS_MEDIA_CAPTURE_VIDEO_ONLY; | 134 return IDS_MEDIA_CAPTURE_VIDEO_ONLY; |
| 136 else if (!controller_->IsAskingForVideo()) | 135 else if (!request_->IsAskingForVideo()) |
| 137 return IDS_MEDIA_CAPTURE_AUDIO_ONLY; | 136 return IDS_MEDIA_CAPTURE_AUDIO_ONLY; |
| 138 return IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; | 137 return IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; |
| 139 } | 138 } |
| 140 | 139 |
| 141 bool MediaStreamInfoBarDelegateAndroid::Accept() { | 140 bool MediaStreamInfoBarDelegateAndroid::Accept() { |
| 142 // TODO(dominickn): fold these metrics calls into | 141 // TODO(dominickn): fold these metrics calls into |
| 143 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076. | 142 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076. |
| 144 PermissionUmaUtil::RecordPermissionPromptAccepted( | 143 PermissionUmaUtil::RecordPermissionPromptAccepted( |
| 145 controller_->GetPermissionRequestType(), | 144 request_->GetPermissionRequestType(), |
| 146 PermissionUtil::GetGestureType(user_gesture())); | 145 PermissionUtil::GetGestureType(user_gesture())); |
| 147 | 146 |
| 148 bool persist_permission = true; | 147 bool persist_permission = true; |
| 149 if (ShouldShowPersistenceToggle()) { | 148 if (ShouldShowPersistenceToggle()) { |
| 150 persist_permission = persist(); | 149 persist_permission = persist(); |
| 151 | 150 |
| 152 if (controller_->IsAskingForAudio()) { | 151 if (request_->IsAskingForAudio()) { |
| 153 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( | 152 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( |
| 154 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, persist_permission); | 153 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, persist_permission); |
| 155 } | 154 } |
| 156 if (controller_->IsAskingForVideo()) { | 155 if (request_->IsAskingForVideo()) { |
| 157 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( | 156 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( |
| 158 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, persist_permission); | 157 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, persist_permission); |
| 159 } | 158 } |
| 160 } | 159 } |
| 161 | 160 |
| 162 controller_->set_persist(persist_permission); | 161 request_->set_persist(persist_permission); |
| 163 controller_->PermissionGranted(); | 162 request_->PermissionGranted(); |
| 164 return true; | 163 return true; |
| 165 } | 164 } |
| 166 | 165 |
| 167 bool MediaStreamInfoBarDelegateAndroid::Cancel() { | 166 bool MediaStreamInfoBarDelegateAndroid::Cancel() { |
| 168 // TODO(dominickn): fold these metrics calls into | 167 // TODO(dominickn): fold these metrics calls into |
| 169 // PermissionUmaUtil::PermissionDenied. See crbug.com/638076. | 168 // PermissionUmaUtil::PermissionDenied. See crbug.com/638076. |
| 170 PermissionUmaUtil::RecordPermissionPromptDenied( | 169 PermissionUmaUtil::RecordPermissionPromptDenied( |
| 171 controller_->GetPermissionRequestType(), | 170 request_->GetPermissionRequestType(), |
| 172 PermissionUtil::GetGestureType(user_gesture())); | 171 PermissionUtil::GetGestureType(user_gesture())); |
| 173 | 172 |
| 174 bool persist_permission = true; | 173 bool persist_permission = true; |
| 175 if (ShouldShowPersistenceToggle()) { | 174 if (ShouldShowPersistenceToggle()) { |
| 176 persist_permission = persist(); | 175 persist_permission = persist(); |
| 177 | 176 |
| 178 if (controller_->IsAskingForAudio()) { | 177 if (request_->IsAskingForAudio()) { |
| 179 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( | 178 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( |
| 180 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, persist_permission); | 179 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, persist_permission); |
| 181 } | 180 } |
| 182 if (controller_->IsAskingForVideo()) { | 181 if (request_->IsAskingForVideo()) { |
| 183 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( | 182 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( |
| 184 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, persist_permission); | 183 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, persist_permission); |
| 185 } | 184 } |
| 186 } | 185 } |
| 187 controller_->set_persist(persist_permission); | 186 request_->set_persist(persist_permission); |
| 188 controller_->PermissionDenied(); | 187 request_->PermissionDenied(); |
| 189 return true; | 188 return true; |
| 190 } | 189 } |
| 191 | 190 |
| 192 base::string16 MediaStreamInfoBarDelegateAndroid::GetLinkText() const { | 191 base::string16 MediaStreamInfoBarDelegateAndroid::GetLinkText() const { |
| 193 return base::string16(); | 192 return base::string16(); |
| 194 } | 193 } |
| 195 | 194 |
| 196 GURL MediaStreamInfoBarDelegateAndroid::GetLinkURL() const { | 195 GURL MediaStreamInfoBarDelegateAndroid::GetLinkURL() const { |
| 197 return GURL(chrome::kMediaAccessLearnMoreUrl); | 196 return GURL(chrome::kMediaAccessLearnMoreUrl); |
| 198 } | 197 } |
| 199 | 198 |
| 200 std::vector<int> MediaStreamInfoBarDelegateAndroid::content_settings_types() | 199 std::vector<int> MediaStreamInfoBarDelegateAndroid::content_settings_types() |
| 201 const { | 200 const { |
| 202 std::vector<int> types; | 201 std::vector<int> types; |
| 203 if (controller_->IsAskingForAudio()) | 202 if (request_->IsAskingForAudio()) |
| 204 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 203 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 205 if (controller_->IsAskingForVideo()) | 204 if (request_->IsAskingForVideo()) |
| 206 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 205 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 207 return types; | 206 return types; |
| 208 } | 207 } |
| OLD | NEW |