| 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.h" | 5 #include "chrome/browser/media/media_stream_infobar_delegate_android.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 12 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 13 #include "components/google/core/browser/google_util.h" | 13 #include "components/google/core/browser/google_util.h" |
| 14 #include "components/infobars/core/infobar.h" | 14 #include "components/infobars/core/infobar.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/origin_util.h" | 16 #include "content/public/common/origin_util.h" |
| 17 #include "grit/components_strings.h" | 17 #include "grit/components_strings.h" |
| 18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 enum DevicePermissionActions { | 24 enum DevicePermissionActions { |
| 25 kAllowHttps = 0, | 25 kAllowHttps = 0, |
| 26 kAllowHttp, | 26 kAllowHttp, |
| 27 kDeny, | 27 kDeny, |
| 28 kCancel, | 28 kCancel, |
| 29 kPermissionActionsMax // Must always be last! | 29 kPermissionActionsMax // Must always be last! |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 MediaStreamInfoBarDelegate::~MediaStreamInfoBarDelegate() { | 34 MediaStreamInfoBarDelegateAndroid::~MediaStreamInfoBarDelegateAndroid() {} |
| 35 } | |
| 36 | 35 |
| 37 // static | 36 // static |
| 38 bool MediaStreamInfoBarDelegate::Create( | 37 bool MediaStreamInfoBarDelegateAndroid::Create( |
| 39 content::WebContents* web_contents, | 38 content::WebContents* web_contents, |
| 40 scoped_ptr<MediaStreamDevicesController> controller) { | 39 scoped_ptr<MediaStreamDevicesController> controller) { |
| 41 | |
| 42 InfoBarService* infobar_service = | 40 InfoBarService* infobar_service = |
| 43 InfoBarService::FromWebContents(web_contents); | 41 InfoBarService::FromWebContents(web_contents); |
| 44 if (!infobar_service) { | 42 if (!infobar_service) { |
| 45 // Deny the request if there is no place to show the infobar, e.g. when | 43 // Deny the request if there is no place to show the infobar, e.g. when |
| 46 // the request comes from a background extension page. | 44 // the request comes from a background extension page. |
| 47 controller->Cancelled(); | 45 controller->Cancelled(); |
| 48 return false; | 46 return false; |
| 49 } | 47 } |
| 50 | 48 |
| 51 scoped_ptr<infobars::InfoBar> infobar( | 49 scoped_ptr<infobars::InfoBar> infobar( |
| 52 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( | 50 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( |
| 53 new MediaStreamInfoBarDelegate(controller.Pass())))); | 51 new MediaStreamInfoBarDelegateAndroid(controller.Pass())))); |
| 54 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 52 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
| 55 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); | 53 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
| 56 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegate()) { | 54 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { |
| 57 infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass()); | 55 infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass()); |
| 58 return true; | 56 return true; |
| 59 } | 57 } |
| 60 } | 58 } |
| 61 infobar_service->AddInfoBar(infobar.Pass()); | 59 infobar_service->AddInfoBar(infobar.Pass()); |
| 62 return true; | 60 return true; |
| 63 } | 61 } |
| 64 | 62 |
| 65 bool MediaStreamInfoBarDelegate::IsRequestingVideoAccess() const { | 63 bool MediaStreamInfoBarDelegateAndroid::IsRequestingVideoAccess() const { |
| 66 return controller_->IsAskingForVideo(); | 64 return controller_->IsAskingForVideo(); |
| 67 } | 65 } |
| 68 | 66 |
| 69 bool MediaStreamInfoBarDelegate::IsRequestingMicrophoneAccess() const { | 67 bool MediaStreamInfoBarDelegateAndroid::IsRequestingMicrophoneAccess() const { |
| 70 return controller_->IsAskingForAudio(); | 68 return controller_->IsAskingForAudio(); |
| 71 } | 69 } |
| 72 | 70 |
| 73 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate( | 71 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( |
| 74 scoped_ptr<MediaStreamDevicesController> controller) | 72 scoped_ptr<MediaStreamDevicesController> controller) |
| 75 : ConfirmInfoBarDelegate(), | 73 : ConfirmInfoBarDelegate(), controller_(controller.Pass()) { |
| 76 controller_(controller.Pass()) { | |
| 77 DCHECK(controller_.get()); | 74 DCHECK(controller_.get()); |
| 78 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); | 75 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); |
| 79 } | 76 } |
| 80 | 77 |
| 81 infobars::InfoBarDelegate::Type | 78 infobars::InfoBarDelegate::Type |
| 82 MediaStreamInfoBarDelegate::GetInfoBarType() const { | 79 MediaStreamInfoBarDelegateAndroid::GetInfoBarType() const { |
| 83 return PAGE_ACTION_TYPE; | 80 return PAGE_ACTION_TYPE; |
| 84 } | 81 } |
| 85 | 82 |
| 86 int MediaStreamInfoBarDelegate::GetIconId() const { | 83 int MediaStreamInfoBarDelegateAndroid::GetIconId() const { |
| 87 return controller_->IsAskingForVideo() ? IDR_INFOBAR_MEDIA_STREAM_CAMERA | 84 return controller_->IsAskingForVideo() ? IDR_INFOBAR_MEDIA_STREAM_CAMERA |
| 88 : IDR_INFOBAR_MEDIA_STREAM_MIC; | 85 : IDR_INFOBAR_MEDIA_STREAM_MIC; |
| 89 } | 86 } |
| 90 | 87 |
| 91 void MediaStreamInfoBarDelegate::InfoBarDismissed() { | 88 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { |
| 92 // Deny the request if the infobar was closed with the 'x' button, since | 89 // Deny the request if the infobar was closed with the 'x' button, since |
| 93 // we don't want WebRTC to be waiting for an answer that will never come. | 90 // we don't want WebRTC to be waiting for an answer that will never come. |
| 94 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", | 91 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kCancel, |
| 95 kCancel, kPermissionActionsMax); | 92 kPermissionActionsMax); |
| 96 controller_->Cancelled(); | 93 controller_->Cancelled(); |
| 97 } | 94 } |
| 98 | 95 |
| 99 MediaStreamInfoBarDelegate* | 96 MediaStreamInfoBarDelegateAndroid* |
| 100 MediaStreamInfoBarDelegate::AsMediaStreamInfoBarDelegate() { | 97 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { |
| 101 return this; | 98 return this; |
| 102 } | 99 } |
| 103 | 100 |
| 104 base::string16 MediaStreamInfoBarDelegate::GetMessageText() const { | 101 base::string16 MediaStreamInfoBarDelegateAndroid::GetMessageText() const { |
| 105 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; | 102 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; |
| 106 if (!controller_->IsAskingForAudio()) | 103 if (!controller_->IsAskingForAudio()) |
| 107 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; | 104 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; |
| 108 else if (!controller_->IsAskingForVideo()) | 105 else if (!controller_->IsAskingForVideo()) |
| 109 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; | 106 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; |
| 110 return l10n_util::GetStringFUTF16( | 107 return l10n_util::GetStringFUTF16( |
| 111 message_id, base::UTF8ToUTF16(controller_->GetSecurityOriginSpec())); | 108 message_id, base::UTF8ToUTF16(controller_->GetSecurityOriginSpec())); |
| 112 } | 109 } |
| 113 | 110 |
| 114 base::string16 MediaStreamInfoBarDelegate::GetButtonLabel( | 111 base::string16 MediaStreamInfoBarDelegateAndroid::GetButtonLabel( |
| 115 InfoBarButton button) const { | 112 InfoBarButton button) const { |
| 116 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 113 return l10n_util::GetStringUTF16((button == BUTTON_OK) |
| 117 IDS_MEDIA_CAPTURE_ALLOW : IDS_MEDIA_CAPTURE_BLOCK); | 114 ? IDS_MEDIA_CAPTURE_ALLOW |
| 115 : IDS_MEDIA_CAPTURE_BLOCK); |
| 118 } | 116 } |
| 119 | 117 |
| 120 bool MediaStreamInfoBarDelegate::Accept() { | 118 bool MediaStreamInfoBarDelegateAndroid::Accept() { |
| 121 GURL origin(controller_->GetSecurityOriginSpec()); | 119 GURL origin(controller_->GetSecurityOriginSpec()); |
| 122 if (content::IsOriginSecure(origin)) { | 120 if (content::IsOriginSecure(origin)) { |
| 123 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", | 121 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kAllowHttps, |
| 124 kAllowHttps, kPermissionActionsMax); | 122 kPermissionActionsMax); |
| 125 } else { | 123 } else { |
| 126 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", | 124 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kAllowHttp, |
| 127 kAllowHttp, kPermissionActionsMax); | 125 kPermissionActionsMax); |
| 128 } | 126 } |
| 129 controller_->PermissionGranted(); | 127 controller_->PermissionGranted(); |
| 130 return true; | 128 return true; |
| 131 } | 129 } |
| 132 | 130 |
| 133 bool MediaStreamInfoBarDelegate::Cancel() { | 131 bool MediaStreamInfoBarDelegateAndroid::Cancel() { |
| 134 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", | 132 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kDeny, |
| 135 kDeny, kPermissionActionsMax); | 133 kPermissionActionsMax); |
| 136 controller_->PermissionDenied(); | 134 controller_->PermissionDenied(); |
| 137 return true; | 135 return true; |
| 138 } | 136 } |
| 139 | 137 |
| 140 base::string16 MediaStreamInfoBarDelegate::GetLinkText() const { | 138 base::string16 MediaStreamInfoBarDelegateAndroid::GetLinkText() const { |
| 141 return base::string16(); | 139 return base::string16(); |
| 142 } | 140 } |
| 143 | 141 |
| 144 GURL MediaStreamInfoBarDelegate::GetLinkURL() const { | 142 GURL MediaStreamInfoBarDelegateAndroid::GetLinkURL() const { |
| 145 return GURL(chrome::kMediaAccessLearnMoreUrl); | 143 return GURL(chrome::kMediaAccessLearnMoreUrl); |
| 146 } | 144 } |
| OLD | NEW |