| 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/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 16 #include "components/content_settings/core/common/content_settings_types.h" |
| 16 #include "components/google/core/browser/google_util.h" | 17 #include "components/google/core/browser/google_util.h" |
| 17 #include "components/infobars/core/infobar.h" | 18 #include "components/infobars/core/infobar.h" |
| 18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/common/origin_util.h" | 20 #include "content/public/common/origin_util.h" |
| 20 #include "grit/components_strings.h" | 21 #include "grit/components_strings.h" |
| 21 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 24 | 25 |
| 26 namespace { |
| 27 |
| 28 std::vector<ContentSettingsType> GetContentSettingsTypes( |
| 29 MediaStreamDevicesController* controller) { |
| 30 std::vector<ContentSettingsType> types; |
| 31 if (controller->IsAskingForAudio()) |
| 32 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 33 if (controller->IsAskingForVideo()) |
| 34 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 35 return types; |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
| 25 MediaStreamInfoBarDelegateAndroid::~MediaStreamInfoBarDelegateAndroid() {} | 40 MediaStreamInfoBarDelegateAndroid::~MediaStreamInfoBarDelegateAndroid() {} |
| 26 | 41 |
| 27 // static | 42 // static |
| 28 bool MediaStreamInfoBarDelegateAndroid::Create( | 43 bool MediaStreamInfoBarDelegateAndroid::Create( |
| 29 content::WebContents* web_contents, | 44 content::WebContents* web_contents, |
| 30 std::unique_ptr<MediaStreamDevicesController> controller) { | 45 std::unique_ptr<MediaStreamDevicesController> controller) { |
| 31 InfoBarService* infobar_service = | 46 InfoBarService* infobar_service = |
| 32 InfoBarService::FromWebContents(web_contents); | 47 InfoBarService::FromWebContents(web_contents); |
| 33 if (!infobar_service) { | 48 if (!infobar_service) { |
| 34 // Deny the request if there is no place to show the infobar, e.g. when | 49 // Deny the request if there is no place to show the infobar, e.g. when |
| 35 // the request comes from a background extension page. | 50 // the request comes from a background extension page. |
| 36 controller->Cancelled(); | 51 controller->Cancelled(); |
| 37 return false; | 52 return false; |
| 38 } | 53 } |
| 39 | 54 |
| 40 std::unique_ptr<infobars::InfoBar> infobar( | 55 std::unique_ptr<infobars::InfoBar> infobar( |
| 41 infobar_service->CreateConfirmInfoBar( | 56 GroupedPermissionInfoBarDelegate::CreateInfoBar(infobar_service, |
| 42 std::unique_ptr<ConfirmInfoBarDelegate>( | 57 std::unique_ptr<GroupedPermissionInfoBarDelegate>( |
| 43 new MediaStreamInfoBarDelegateAndroid(std::move(controller))))); | 58 new MediaStreamInfoBarDelegateAndroid(std::move(controller))))); |
| 44 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 59 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
| 45 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); | 60 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
| 46 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { | 61 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { |
| 47 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); | 62 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); |
| 48 return true; | 63 return true; |
| 49 } | 64 } |
| 50 } | 65 } |
| 51 infobar_service->AddInfoBar(std::move(infobar)); | 66 infobar_service->AddInfoBar(std::move(infobar)); |
| 52 return true; | 67 return true; |
| 53 } | 68 } |
| 54 | 69 |
| 55 bool MediaStreamInfoBarDelegateAndroid::IsRequestingVideoAccess() const { | |
| 56 return controller_->IsAskingForVideo(); | |
| 57 } | |
| 58 | |
| 59 bool MediaStreamInfoBarDelegateAndroid::IsRequestingMicrophoneAccess() const { | |
| 60 return controller_->IsAskingForAudio(); | |
| 61 } | |
| 62 | |
| 63 infobars::InfoBarDelegate::InfoBarIdentifier | 70 infobars::InfoBarDelegate::InfoBarIdentifier |
| 64 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { | 71 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { |
| 65 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; | 72 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; |
| 66 } | 73 } |
| 67 | 74 |
| 68 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( | 75 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( |
| 69 std::unique_ptr<MediaStreamDevicesController> controller) | 76 std::unique_ptr<MediaStreamDevicesController> controller) |
| 70 : ConfirmInfoBarDelegate(), controller_(std::move(controller)) { | 77 : GroupedPermissionInfoBarDelegate( |
| 78 controller->GetOrigin(), |
| 79 GetContentSettingsTypes(controller.get())), |
| 80 controller_(std::move(controller)) { |
| 71 DCHECK(controller_.get()); | 81 DCHECK(controller_.get()); |
| 72 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); | 82 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); |
| 73 } | 83 } |
| 74 | 84 |
| 75 infobars::InfoBarDelegate::Type | |
| 76 MediaStreamInfoBarDelegateAndroid::GetInfoBarType() const { | |
| 77 return PAGE_ACTION_TYPE; | |
| 78 } | |
| 79 | |
| 80 int MediaStreamInfoBarDelegateAndroid::GetIconId() const { | |
| 81 return controller_->IsAskingForVideo() ? IDR_INFOBAR_MEDIA_STREAM_CAMERA | |
| 82 : IDR_INFOBAR_MEDIA_STREAM_MIC; | |
| 83 } | |
| 84 | |
| 85 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { | 85 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { |
| 86 // Deny the request if the infobar was closed with the 'x' button, since | 86 // Deny the request if the infobar was closed with the 'x' button, since |
| 87 // we don't want WebRTC to be waiting for an answer that will never come. | 87 // we don't want WebRTC to be waiting for an answer that will never come. |
| 88 controller_->Cancelled(); | 88 controller_->Cancelled(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 MediaStreamInfoBarDelegateAndroid* | 91 MediaStreamInfoBarDelegateAndroid* |
| 92 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { | 92 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { |
| 93 return this; | 93 return this; |
| 94 } | 94 } |
| 95 | 95 |
| 96 base::string16 MediaStreamInfoBarDelegateAndroid::GetMessageText() const { | |
| 97 return controller_->GetMessageText(); | |
| 98 } | |
| 99 | |
| 100 base::string16 MediaStreamInfoBarDelegateAndroid::GetButtonLabel( | |
| 101 InfoBarButton button) const { | |
| 102 return l10n_util::GetStringUTF16((button == BUTTON_OK) | |
| 103 ? IDS_MEDIA_CAPTURE_ALLOW | |
| 104 : IDS_MEDIA_CAPTURE_BLOCK); | |
| 105 } | |
| 106 | |
| 107 bool MediaStreamInfoBarDelegateAndroid::Accept() { | 96 bool MediaStreamInfoBarDelegateAndroid::Accept() { |
| 108 controller_->PermissionGranted(); | 97 controller_->PermissionGranted(); |
| 109 return true; | 98 return true; |
| 110 } | 99 } |
| 111 | 100 |
| 112 bool MediaStreamInfoBarDelegateAndroid::Cancel() { | 101 bool MediaStreamInfoBarDelegateAndroid::Cancel() { |
| 113 controller_->PermissionDenied(); | 102 controller_->PermissionDenied(); |
| 114 return true; | 103 return true; |
| 115 } | 104 } |
| 116 | |
| 117 base::string16 MediaStreamInfoBarDelegateAndroid::GetLinkText() const { | |
| 118 return base::string16(); | |
| 119 } | |
| 120 | |
| 121 GURL MediaStreamInfoBarDelegateAndroid::GetLinkURL() const { | |
| 122 return GURL(chrome::kMediaAccessLearnMoreUrl); | |
| 123 } | |
| OLD | NEW |