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 |
25 namespace { | 26 namespace { |
26 | 27 |
27 enum DevicePermissionActions { | 28 enum DevicePermissionActions { |
28 kAllowHttps = 0, | 29 kAllowHttps = 0, |
29 kAllowHttp, | 30 kAllowHttp, |
30 kDeny, | 31 kDeny, |
31 kCancel, | 32 kCancel, |
32 kPermissionActionsMax // Must always be last! | 33 kPermissionActionsMax // Must always be last! |
33 }; | 34 }; |
34 | 35 |
| 36 std::vector<ContentSettingsType> GetContentSettingsTypes( |
| 37 MediaStreamDevicesController* controller) { |
| 38 std::vector<ContentSettingsType> types; |
| 39 if (controller->IsAskingForAudio()) |
| 40 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 41 if (controller->IsAskingForVideo()) |
| 42 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 43 return types; |
| 44 } |
| 45 |
35 } // namespace | 46 } // namespace |
36 | 47 |
37 MediaStreamInfoBarDelegateAndroid::~MediaStreamInfoBarDelegateAndroid() {} | 48 MediaStreamInfoBarDelegateAndroid::~MediaStreamInfoBarDelegateAndroid() {} |
38 | 49 |
39 // static | 50 // static |
40 bool MediaStreamInfoBarDelegateAndroid::Create( | 51 bool MediaStreamInfoBarDelegateAndroid::Create( |
41 content::WebContents* web_contents, | 52 content::WebContents* web_contents, |
42 std::unique_ptr<MediaStreamDevicesController> controller) { | 53 std::unique_ptr<MediaStreamDevicesController> controller) { |
43 InfoBarService* infobar_service = | 54 InfoBarService* infobar_service = |
44 InfoBarService::FromWebContents(web_contents); | 55 InfoBarService::FromWebContents(web_contents); |
45 if (!infobar_service) { | 56 if (!infobar_service) { |
46 // Deny the request if there is no place to show the infobar, e.g. when | 57 // Deny the request if there is no place to show the infobar, e.g. when |
47 // the request comes from a background extension page. | 58 // the request comes from a background extension page. |
48 controller->Cancelled(); | 59 controller->Cancelled(); |
49 return false; | 60 return false; |
50 } | 61 } |
51 | 62 |
52 std::unique_ptr<infobars::InfoBar> infobar( | 63 std::unique_ptr<infobars::InfoBar> infobar( |
53 infobar_service->CreateConfirmInfoBar( | 64 GroupedPermissionInfoBarDelegate::CreateInfoBar(infobar_service, |
54 std::unique_ptr<ConfirmInfoBarDelegate>( | 65 std::unique_ptr<GroupedPermissionInfoBarDelegate>( |
55 new MediaStreamInfoBarDelegateAndroid(std::move(controller))))); | 66 new MediaStreamInfoBarDelegateAndroid(std::move(controller))))); |
56 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 67 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
57 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); | 68 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
58 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { | 69 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { |
59 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); | 70 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); |
60 return true; | 71 return true; |
61 } | 72 } |
62 } | 73 } |
63 infobar_service->AddInfoBar(std::move(infobar)); | 74 infobar_service->AddInfoBar(std::move(infobar)); |
64 return true; | 75 return true; |
65 } | 76 } |
66 | 77 |
67 bool MediaStreamInfoBarDelegateAndroid::IsRequestingVideoAccess() const { | |
68 return controller_->IsAskingForVideo(); | |
69 } | |
70 | |
71 bool MediaStreamInfoBarDelegateAndroid::IsRequestingMicrophoneAccess() const { | |
72 return controller_->IsAskingForAudio(); | |
73 } | |
74 | |
75 infobars::InfoBarDelegate::InfoBarIdentifier | 78 infobars::InfoBarDelegate::InfoBarIdentifier |
76 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { | 79 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { |
77 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; | 80 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; |
78 } | 81 } |
79 | 82 |
80 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( | 83 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( |
81 std::unique_ptr<MediaStreamDevicesController> controller) | 84 std::unique_ptr<MediaStreamDevicesController> controller) |
82 : ConfirmInfoBarDelegate(), controller_(std::move(controller)) { | 85 : GroupedPermissionInfoBarDelegate( |
| 86 controller->GetOrigin(), |
| 87 GetContentSettingsTypes(controller.get())), |
| 88 controller_(std::move(controller)) { |
83 DCHECK(controller_.get()); | 89 DCHECK(controller_.get()); |
84 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); | 90 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); |
85 } | 91 } |
86 | 92 |
87 infobars::InfoBarDelegate::Type | |
88 MediaStreamInfoBarDelegateAndroid::GetInfoBarType() const { | |
89 return PAGE_ACTION_TYPE; | |
90 } | |
91 | |
92 int MediaStreamInfoBarDelegateAndroid::GetIconId() const { | |
93 return controller_->IsAskingForVideo() ? IDR_INFOBAR_MEDIA_STREAM_CAMERA | |
94 : IDR_INFOBAR_MEDIA_STREAM_MIC; | |
95 } | |
96 | |
97 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { | 93 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { |
98 // Deny the request if the infobar was closed with the 'x' button, since | 94 // Deny the request if the infobar was closed with the 'x' button, since |
99 // we don't want WebRTC to be waiting for an answer that will never come. | 95 // we don't want WebRTC to be waiting for an answer that will never come. |
100 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kCancel, | 96 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kCancel, |
101 kPermissionActionsMax); | 97 kPermissionActionsMax); |
102 controller_->Cancelled(); | 98 controller_->Cancelled(); |
103 } | 99 } |
104 | 100 |
105 MediaStreamInfoBarDelegateAndroid* | 101 MediaStreamInfoBarDelegateAndroid* |
106 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { | 102 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { |
107 return this; | 103 return this; |
108 } | 104 } |
109 | 105 |
110 base::string16 MediaStreamInfoBarDelegateAndroid::GetMessageText() const { | |
111 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; | |
112 if (!controller_->IsAskingForAudio()) | |
113 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; | |
114 else if (!controller_->IsAskingForVideo()) | |
115 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; | |
116 return l10n_util::GetStringFUTF16( | |
117 message_id, base::UTF8ToUTF16(controller_->GetSecurityOriginSpec())); | |
118 } | |
119 | |
120 base::string16 MediaStreamInfoBarDelegateAndroid::GetButtonLabel( | |
121 InfoBarButton button) const { | |
122 return l10n_util::GetStringUTF16((button == BUTTON_OK) | |
123 ? IDS_MEDIA_CAPTURE_ALLOW | |
124 : IDS_MEDIA_CAPTURE_BLOCK); | |
125 } | |
126 | |
127 bool MediaStreamInfoBarDelegateAndroid::Accept() { | 106 bool MediaStreamInfoBarDelegateAndroid::Accept() { |
128 GURL origin(controller_->GetSecurityOriginSpec()); | 107 GURL origin(controller_->GetSecurityOriginSpec()); |
129 if (content::IsOriginSecure(origin)) { | 108 if (content::IsOriginSecure(origin)) { |
130 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kAllowHttps, | 109 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kAllowHttps, |
131 kPermissionActionsMax); | 110 kPermissionActionsMax); |
132 } else { | 111 } else { |
133 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kAllowHttp, | 112 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kAllowHttp, |
134 kPermissionActionsMax); | 113 kPermissionActionsMax); |
135 } | 114 } |
136 controller_->PermissionGranted(); | 115 controller_->PermissionGranted(); |
137 return true; | 116 return true; |
138 } | 117 } |
139 | 118 |
140 bool MediaStreamInfoBarDelegateAndroid::Cancel() { | 119 bool MediaStreamInfoBarDelegateAndroid::Cancel() { |
141 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kDeny, | 120 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", kDeny, |
142 kPermissionActionsMax); | 121 kPermissionActionsMax); |
143 controller_->PermissionDenied(); | 122 controller_->PermissionDenied(); |
144 return true; | 123 return true; |
145 } | 124 } |
146 | |
147 base::string16 MediaStreamInfoBarDelegateAndroid::GetLinkText() const { | |
148 return base::string16(); | |
149 } | |
150 | |
151 GURL MediaStreamInfoBarDelegateAndroid::GetLinkURL() const { | |
152 return GURL(chrome::kMediaAccessLearnMoreUrl); | |
153 } | |
OLD | NEW |