Chromium Code Reviews| Index: chrome/browser/media/webrtc/media_stream_infobar_delegate_android.cc |
| diff --git a/chrome/browser/media/webrtc/media_stream_infobar_delegate_android.cc b/chrome/browser/media/webrtc/media_stream_infobar_delegate_android.cc |
| index a096927938f8b005594c893d51d01356aed774fb..f8a922627a80dc665e1f2efb7e0a95a81f01f66c 100644 |
| --- a/chrome/browser/media/webrtc/media_stream_infobar_delegate_android.cc |
| +++ b/chrome/browser/media/webrtc/media_stream_infobar_delegate_android.cc |
| @@ -12,36 +12,18 @@ |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/infobars/infobar_service.h" |
| #include "chrome/browser/permissions/permission_uma_util.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/url_constants.h" |
| +#include "chrome/grit/generated_resources.h" |
| +#include "chrome/grit/theme_resources.h" |
| #include "components/content_settings/core/common/content_settings_types.h" |
| #include "components/google/core/browser/google_util.h" |
| #include "components/infobars/core/infobar.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/common/origin_util.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| #include "url/gurl.h" |
| -namespace { |
| - |
| -const int kGroupedInfobarAudioPosition = 0; |
| -const int kGroupedInfobarVideoPosition = 1; |
| - |
| -// Get a list of content types being requested. Note that the order of the |
| -// resulting array corresponds to the kGroupedInfobarAudio/VideoPermission |
| -// constants. |
| -std::vector<ContentSettingsType> GetContentSettingsTypes( |
| - MediaStreamDevicesController* controller) { |
| - std::vector<ContentSettingsType> types; |
| - if (controller->IsAskingForAudio()) |
| - types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| - if (controller->IsAskingForVideo()) |
| - types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| - return types; |
| -} |
| - |
| -} // namespace |
| - |
| -MediaStreamInfoBarDelegateAndroid::~MediaStreamInfoBarDelegateAndroid() {} |
| - |
| // static |
| bool MediaStreamInfoBarDelegateAndroid::Create( |
| content::WebContents* web_contents, |
| @@ -55,10 +37,13 @@ bool MediaStreamInfoBarDelegateAndroid::Create( |
| return false; |
| } |
| + Profile* profile = |
|
dominickn
2016/09/21 05:09:16
Nit: inline this call into the new MediaStreamInfo
lshang
2016/09/21 06:57:54
Done.
|
| + Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| + |
| std::unique_ptr<infobars::InfoBar> infobar( |
| - GroupedPermissionInfoBarDelegate::CreateInfoBar(infobar_service, |
| - std::unique_ptr<GroupedPermissionInfoBarDelegate>( |
| - new MediaStreamInfoBarDelegateAndroid(std::move(controller))))); |
| + CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>( |
| + new MediaStreamInfoBarDelegateAndroid(profile, |
| + std::move(controller))))); |
| for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
| infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
| if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { |
| @@ -70,39 +55,51 @@ bool MediaStreamInfoBarDelegateAndroid::Create( |
| return true; |
| } |
| -void MediaStreamInfoBarDelegateAndroid::RecordPermissionAcceptedUma( |
| - int position, |
| - bool persist) { |
| - PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( |
| - controller_->GetPermissionTypeForContentSettingsType( |
| - GetContentSettingType(position)), |
| - persist); |
| -} |
| - |
| -void MediaStreamInfoBarDelegateAndroid::RecordPermissionDeniedUma( |
| - int position, |
| - bool persist) { |
| - PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( |
| - controller_->GetPermissionTypeForContentSettingsType( |
| - GetContentSettingType(position)), |
| - persist); |
| -} |
| +void MediaStreamInfoBarDelegateAndroid::DoNothing(bool update_content_setting, |
| + PermissionAction decision) {} |
| infobars::InfoBarDelegate::InfoBarIdentifier |
| MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { |
| return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; |
| } |
| +infobars::InfoBarDelegate::Type |
| +MediaStreamInfoBarDelegateAndroid::GetInfoBarType() const { |
| + return PAGE_ACTION_TYPE; |
| +} |
| + |
| +int MediaStreamInfoBarDelegateAndroid::GetIconId() const { |
| + return controller_->IsAskingForVideo() ? IDR_INFOBAR_MEDIA_STREAM_CAMERA |
| + : IDR_INFOBAR_MEDIA_STREAM_MIC; |
| +} |
| + |
| MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( |
| + Profile* profile, |
| std::unique_ptr<MediaStreamDevicesController> controller) |
| - : GroupedPermissionInfoBarDelegate( |
| + : PermissionInfoBarDelegate( |
| controller->GetOrigin(), |
| - GetContentSettingsTypes(controller.get())), |
| + // The content setting type and permission type here are only passed |
| + // in to fit into PermissionInfoBarDelegate, even though media infobar |
| + // controls both mic and camera. This is a temporary state for easy |
| + // refactoring. |
| + // TODO(lshang): Merge MediaStreamInfoBarDelegateAndroid into |
| + // GroupedPermissionInfoBarDelegate. See crbug.com/606138. |
| + content::PermissionType::AUDIO_CAPTURE, |
| + CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| + false, |
| + profile, |
| + // This is only passed in to fit into PermissionInfoBarDelegate. |
| + // Infobar accepted/denied/dismissed is handled by controller, not via |
| + // callbacks. |
| + base::Bind(&MediaStreamInfoBarDelegateAndroid::DoNothing, |
|
dominickn
2016/09/21 05:09:16
Nit: can you declare DoNothing in the anonymous na
lshang
2016/09/21 06:57:54
Done.
|
| + base::Unretained(this))), |
| controller_(std::move(controller)) { |
| DCHECK(controller_.get()); |
| DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); |
| } |
| +MediaStreamInfoBarDelegateAndroid::~MediaStreamInfoBarDelegateAndroid() {} |
| + |
| void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { |
| // Deny the request if the infobar was closed with the 'x' button, since |
| // we don't want WebRTC to be waiting for an answer that will never come. |
| @@ -114,6 +111,25 @@ MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { |
| return this; |
| } |
| +base::string16 MediaStreamInfoBarDelegateAndroid::GetMessageText() const { |
| + return controller_->GetMessageText(); |
| +} |
| + |
| +base::string16 MediaStreamInfoBarDelegateAndroid::GetButtonLabel( |
| + InfoBarButton button) const { |
| + return l10n_util::GetStringUTF16((button == BUTTON_OK) |
| + ? IDS_MEDIA_CAPTURE_ALLOW |
| + : IDS_MEDIA_CAPTURE_BLOCK); |
| +} |
| + |
| +int MediaStreamInfoBarDelegateAndroid::GetMessageResourceId() const { |
| + if (!controller_->IsAskingForAudio()) |
| + return IDS_MEDIA_CAPTURE_VIDEO_ONLY; |
| + else if (!controller_->IsAskingForVideo()) |
| + return IDS_MEDIA_CAPTURE_AUDIO_ONLY; |
| + return IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; |
| +} |
| + |
| bool MediaStreamInfoBarDelegateAndroid::Accept() { |
| bool persist_permission = true; |
| if (ShouldShowPersistenceToggle()) { |
| @@ -121,26 +137,16 @@ bool MediaStreamInfoBarDelegateAndroid::Accept() { |
| // TODO(dominickn): fold these metrics calls into |
| // PermissionUmaUtil::PermissionGranted. See crbug.com/638076. |
| - if (GetPermissionCount() == 2) { |
| - RecordPermissionAcceptedUma(kGroupedInfobarAudioPosition, |
| - persist_permission); |
| - RecordPermissionAcceptedUma(kGroupedInfobarVideoPosition, |
| - persist_permission); |
| - } else { |
| - DCHECK_EQ(1, GetPermissionCount()); |
| - RecordPermissionAcceptedUma(0, persist_permission); |
| - } |
| + if (controller_->IsAskingForAudio()) |
| + PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( |
| + content::PermissionType::AUDIO_CAPTURE, persist_permission); |
| + if (controller_->IsAskingForVideo()) |
| + PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( |
| + content::PermissionType::VIDEO_CAPTURE, persist_permission); |
| } |
| controller_->set_persist(persist_permission); |
| - if (GetPermissionCount() == 2) { |
| - controller_->GroupedRequestFinished( |
| - GetAcceptState(kGroupedInfobarAudioPosition), |
| - GetAcceptState(kGroupedInfobarVideoPosition)); |
| - } else { |
| - DCHECK_EQ(1, GetPermissionCount()); |
| - controller_->PermissionGranted(); |
| - } |
| + controller_->PermissionGranted(); |
| return true; |
| } |
| @@ -151,17 +157,31 @@ bool MediaStreamInfoBarDelegateAndroid::Cancel() { |
| // TODO(dominickn): fold these metrics calls into |
| // PermissionUmaUtil::PermissionGranted. See crbug.com/638076. |
| - if (GetPermissionCount() == 2) { |
| - RecordPermissionDeniedUma(kGroupedInfobarAudioPosition, |
| - persist_permission); |
| - RecordPermissionDeniedUma(kGroupedInfobarVideoPosition, |
| - persist_permission); |
| - } else { |
| - DCHECK_EQ(1, GetPermissionCount()); |
| - RecordPermissionDeniedUma(0, persist_permission); |
| - } |
| + if (controller_->IsAskingForAudio()) |
| + PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( |
| + content::PermissionType::AUDIO_CAPTURE, persist_permission); |
| + if (controller_->IsAskingForVideo()) |
| + PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( |
| + content::PermissionType::VIDEO_CAPTURE, persist_permission); |
| } |
| controller_->set_persist(persist_permission); |
| controller_->PermissionDenied(); |
| return true; |
| } |
| + |
| +base::string16 MediaStreamInfoBarDelegateAndroid::GetLinkText() const { |
| + return base::string16(); |
| +} |
| + |
| +GURL MediaStreamInfoBarDelegateAndroid::GetLinkURL() const { |
| + return GURL(chrome::kMediaAccessLearnMoreUrl); |
| +} |
| + |
| +std::vector<int> MediaStreamInfoBarDelegateAndroid::content_settings() const { |
| + std::vector<int> types; |
| + if (controller_->IsAskingForAudio()) |
| + types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| + if (controller_->IsAskingForVideo()) |
| + types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| + return types; |
| +} |