Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/browser/media/webrtc/permission_bubble_media_access_handler.cc

Issue 2619603002: Remove android_java_ui as it is not used (Closed)
Patch Set: Rebase to master Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/permission_bubble_media_access_handler.h" 5 #include "chrome/browser/media/webrtc/permission_bubble_media_access_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "chrome/browser/media/webrtc/media_permission.h" 10 #include "chrome/browser/media/webrtc/media_permission.h"
11 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" 11 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h"
12 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" 12 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/features.h"
15 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
16 #include "components/content_settings/core/browser/host_content_settings_map.h" 15 #include "components/content_settings/core/browser/host_content_settings_map.h"
17 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_types.h" 18 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
21 20
22 #if BUILDFLAG(ANDROID_JAVA_UI) 21 #if defined(OS_ANDROID)
23 #include <vector> 22 #include <vector>
24 23
25 #include "base/bind.h" 24 #include "base/bind.h"
26 #include "base/bind_helpers.h" 25 #include "base/bind_helpers.h"
27 #include "chrome/browser/android/chrome_feature_list.h" 26 #include "chrome/browser/android/chrome_feature_list.h"
28 #include "chrome/browser/media/webrtc/media_stream_infobar_delegate_android.h" 27 #include "chrome/browser/media/webrtc/media_stream_infobar_delegate_android.h"
29 #include "chrome/browser/media/webrtc/screen_capture_infobar_delegate_android.h" 28 #include "chrome/browser/media/webrtc/screen_capture_infobar_delegate_android.h"
30 #include "chrome/browser/permissions/permission_dialog_delegate.h" 29 #include "chrome/browser/permissions/permission_dialog_delegate.h"
31 #include "chrome/browser/permissions/permission_uma_util.h" 30 #include "chrome/browser/permissions/permission_uma_util.h"
32 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" 31 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h"
33 #include "chrome/browser/permissions/permission_util.h" 32 #include "chrome/browser/permissions/permission_util.h"
34 #else 33 #else
35 #include "chrome/browser/permissions/permission_request_manager.h" 34 #include "chrome/browser/permissions/permission_request_manager.h"
36 #endif // BUILDFLAG(ANDROID_JAVA_UI) 35 #endif // defined(OS_ANDROID)
37 36
38 #if BUILDFLAG(ANDROID_JAVA_UI) 37 #if defined(OS_ANDROID)
39 namespace { 38 namespace {
40 // Callback for the permission update infobar when the site and Chrome 39 // Callback for the permission update infobar when the site and Chrome
41 // permissions are mismatched on Android. 40 // permissions are mismatched on Android.
42 void OnPermissionConflictResolved( 41 void OnPermissionConflictResolved(
43 std::unique_ptr<MediaStreamDevicesController> controller, 42 std::unique_ptr<MediaStreamDevicesController> controller,
44 bool allowed) { 43 bool allowed) {
45 if (allowed) 44 if (allowed)
46 controller->PermissionGranted(); 45 controller->PermissionGranted();
47 else 46 else
48 controller->ForcePermissionDeniedTemporarily(); 47 controller->ForcePermissionDeniedTemporarily();
49 } 48 }
50 } // namespace 49 } // namespace
51 50
52 #endif // BUILDFLAG(ANDROID_JAVA_UI) 51 #endif // defined(OS_ANDROID)
53 52
54 using content::BrowserThread; 53 using content::BrowserThread;
55 54
56 struct PermissionBubbleMediaAccessHandler::PendingAccessRequest { 55 struct PermissionBubbleMediaAccessHandler::PendingAccessRequest {
57 PendingAccessRequest(const content::MediaStreamRequest& request, 56 PendingAccessRequest(const content::MediaStreamRequest& request,
58 const content::MediaResponseCallback& callback) 57 const content::MediaResponseCallback& callback)
59 : request(request), callback(callback) {} 58 : request(request), callback(callback) {}
60 ~PendingAccessRequest() {} 59 ~PendingAccessRequest() {}
61 60
62 // TODO(gbillock): make the MediaStreamDevicesController owned by 61 // TODO(gbillock): make the MediaStreamDevicesController owned by
(...skipping 11 matching lines...) Expand all
74 notifications_registrar_.Add(this, 73 notifications_registrar_.Add(this,
75 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 74 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
76 content::NotificationService::AllSources()); 75 content::NotificationService::AllSources());
77 } 76 }
78 77
79 PermissionBubbleMediaAccessHandler::~PermissionBubbleMediaAccessHandler() {} 78 PermissionBubbleMediaAccessHandler::~PermissionBubbleMediaAccessHandler() {}
80 79
81 bool PermissionBubbleMediaAccessHandler::SupportsStreamType( 80 bool PermissionBubbleMediaAccessHandler::SupportsStreamType(
82 const content::MediaStreamType type, 81 const content::MediaStreamType type,
83 const extensions::Extension* extension) { 82 const extensions::Extension* extension) {
84 #if BUILDFLAG(ANDROID_JAVA_UI) 83 #if defined(OS_ANDROID)
85 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE || 84 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE ||
86 type == content::MEDIA_DEVICE_AUDIO_CAPTURE || 85 type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
87 type == content::MEDIA_DESKTOP_VIDEO_CAPTURE; 86 type == content::MEDIA_DESKTOP_VIDEO_CAPTURE;
88 #else 87 #else
89 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE || 88 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE ||
90 type == content::MEDIA_DEVICE_AUDIO_CAPTURE; 89 type == content::MEDIA_DEVICE_AUDIO_CAPTURE;
91 #endif 90 #endif
92 } 91 }
93 92
94 bool PermissionBubbleMediaAccessHandler::CheckMediaAccessPermission( 93 bool PermissionBubbleMediaAccessHandler::CheckMediaAccessPermission(
(...skipping 15 matching lines...) Expand all
110 return permission.GetPermissionStatus(&unused) == CONTENT_SETTING_ALLOW; 109 return permission.GetPermissionStatus(&unused) == CONTENT_SETTING_ALLOW;
111 } 110 }
112 111
113 void PermissionBubbleMediaAccessHandler::HandleRequest( 112 void PermissionBubbleMediaAccessHandler::HandleRequest(
114 content::WebContents* web_contents, 113 content::WebContents* web_contents,
115 const content::MediaStreamRequest& request, 114 const content::MediaStreamRequest& request,
116 const content::MediaResponseCallback& callback, 115 const content::MediaResponseCallback& callback,
117 const extensions::Extension* extension) { 116 const extensions::Extension* extension) {
118 DCHECK_CURRENTLY_ON(BrowserThread::UI); 117 DCHECK_CURRENTLY_ON(BrowserThread::UI);
119 118
120 #if BUILDFLAG(ANDROID_JAVA_UI) 119 #if defined(OS_ANDROID)
121 if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE && 120 if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE &&
122 !base::FeatureList::IsEnabled( 121 !base::FeatureList::IsEnabled(
123 chrome::android::kUserMediaScreenCapturing)) { 122 chrome::android::kUserMediaScreenCapturing)) {
124 // If screen capturing isn't enabled on Android, we'll use "invalid state" 123 // If screen capturing isn't enabled on Android, we'll use "invalid state"
125 // as result, same as on desktop. 124 // as result, same as on desktop.
126 callback.Run(content::MediaStreamDevices(), 125 callback.Run(content::MediaStreamDevices(),
127 content::MEDIA_DEVICE_INVALID_STATE, nullptr); 126 content::MEDIA_DEVICE_INVALID_STATE, nullptr);
128 return; 127 return;
129 } 128 }
130 #endif // BUILDFLAG(ANDROID_JAVA_UI) 129 #endif // defined(OS_ANDROID)
131 130
132 RequestsQueue& queue = pending_requests_[web_contents]; 131 RequestsQueue& queue = pending_requests_[web_contents];
133 queue.push_back(PendingAccessRequest(request, callback)); 132 queue.push_back(PendingAccessRequest(request, callback));
134 133
135 // If this is the only request then show the infobar. 134 // If this is the only request then show the infobar.
136 if (queue.size() == 1) 135 if (queue.size() == 1)
137 ProcessQueuedAccessRequest(web_contents); 136 ProcessQueuedAccessRequest(web_contents);
138 } 137 }
139 138
140 void PermissionBubbleMediaAccessHandler::ProcessQueuedAccessRequest( 139 void PermissionBubbleMediaAccessHandler::ProcessQueuedAccessRequest(
141 content::WebContents* web_contents) { 140 content::WebContents* web_contents) {
142 DCHECK_CURRENTLY_ON(BrowserThread::UI); 141 DCHECK_CURRENTLY_ON(BrowserThread::UI);
143 142
144 std::map<content::WebContents*, RequestsQueue>::iterator it = 143 std::map<content::WebContents*, RequestsQueue>::iterator it =
145 pending_requests_.find(web_contents); 144 pending_requests_.find(web_contents);
146 145
147 if (it == pending_requests_.end() || it->second.empty()) { 146 if (it == pending_requests_.end() || it->second.empty()) {
148 // Don't do anything if the tab was closed. 147 // Don't do anything if the tab was closed.
149 return; 148 return;
150 } 149 }
151 150
152 DCHECK(!it->second.empty()); 151 DCHECK(!it->second.empty());
153 152
154 const content::MediaStreamRequest request = it->second.front().request; 153 const content::MediaStreamRequest request = it->second.front().request;
155 #if BUILDFLAG(ANDROID_JAVA_UI) 154 #if defined(OS_ANDROID)
156 if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) { 155 if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) {
157 ScreenCaptureInfoBarDelegateAndroid::Create( 156 ScreenCaptureInfoBarDelegateAndroid::Create(
158 web_contents, request, 157 web_contents, request,
159 base::Bind(&PermissionBubbleMediaAccessHandler::OnAccessRequestResponse, 158 base::Bind(&PermissionBubbleMediaAccessHandler::OnAccessRequestResponse,
160 base::Unretained(this), web_contents)); 159 base::Unretained(this), web_contents));
161 return; 160 return;
162 } 161 }
163 #endif 162 #endif
164 163
165 std::unique_ptr<MediaStreamDevicesController> controller( 164 std::unique_ptr<MediaStreamDevicesController> controller(
166 new MediaStreamDevicesController( 165 new MediaStreamDevicesController(
167 web_contents, request, 166 web_contents, request,
168 base::Bind( 167 base::Bind(
169 &PermissionBubbleMediaAccessHandler::OnAccessRequestResponse, 168 &PermissionBubbleMediaAccessHandler::OnAccessRequestResponse,
170 base::Unretained(this), web_contents))); 169 base::Unretained(this), web_contents)));
171 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo()) { 170 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo()) {
172 #if BUILDFLAG(ANDROID_JAVA_UI) 171 #if defined(OS_ANDROID)
173 // If either audio or video was previously allowed and Chrome no longer has 172 // If either audio or video was previously allowed and Chrome no longer has
174 // the necessary permissions, show a infobar to attempt to address this 173 // the necessary permissions, show a infobar to attempt to address this
175 // mismatch. 174 // mismatch.
176 std::vector<ContentSettingsType> content_settings_types; 175 std::vector<ContentSettingsType> content_settings_types;
177 if (controller->IsAllowedForAudio()) 176 if (controller->IsAllowedForAudio())
178 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 177 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
179 178
180 if (controller->IsAllowedForVideo()) { 179 if (controller->IsAllowedForVideo()) {
181 content_settings_types.push_back( 180 content_settings_types.push_back(
182 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); 181 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
183 } 182 }
184 if (!content_settings_types.empty() && 183 if (!content_settings_types.empty() &&
185 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar( 184 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar(
186 web_contents, content_settings_types)) { 185 web_contents, content_settings_types)) {
187 PermissionUpdateInfoBarDelegate::Create( 186 PermissionUpdateInfoBarDelegate::Create(
188 web_contents, content_settings_types, 187 web_contents, content_settings_types,
189 base::Bind(&OnPermissionConflictResolved, base::Passed(&controller))); 188 base::Bind(&OnPermissionConflictResolved, base::Passed(&controller)));
190 } 189 }
191 #endif 190 #endif
192 return; 191 return;
193 } 192 }
194 193
195 #if BUILDFLAG(ANDROID_JAVA_UI) 194 #if defined(OS_ANDROID)
196 PermissionUmaUtil::RecordPermissionPromptShown( 195 PermissionUmaUtil::RecordPermissionPromptShown(
197 controller->GetPermissionRequestType(), 196 controller->GetPermissionRequestType(),
198 PermissionUtil::GetGestureType(request.user_gesture)); 197 PermissionUtil::GetGestureType(request.user_gesture));
199 if (PermissionDialogDelegate::ShouldShowDialog(request.user_gesture)) { 198 if (PermissionDialogDelegate::ShouldShowDialog(request.user_gesture)) {
200 PermissionDialogDelegate::CreateMediaStreamDialog( 199 PermissionDialogDelegate::CreateMediaStreamDialog(
201 web_contents, request.user_gesture, std::move(controller)); 200 web_contents, request.user_gesture, std::move(controller));
202 } else { 201 } else {
203 MediaStreamInfoBarDelegateAndroid::Create( 202 MediaStreamInfoBarDelegateAndroid::Create(
204 web_contents, request.user_gesture, std::move(controller)); 203 web_contents, request.user_gesture, std::move(controller));
205 } 204 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 275
277 void PermissionBubbleMediaAccessHandler::Observe( 276 void PermissionBubbleMediaAccessHandler::Observe(
278 int type, 277 int type,
279 const content::NotificationSource& source, 278 const content::NotificationSource& source,
280 const content::NotificationDetails& details) { 279 const content::NotificationDetails& details) {
281 DCHECK_CURRENTLY_ON(BrowserThread::UI); 280 DCHECK_CURRENTLY_ON(BrowserThread::UI);
282 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type); 281 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type);
283 282
284 pending_requests_.erase(content::Source<content::WebContents>(source).ptr()); 283 pending_requests_.erase(content::Source<content::WebContents>(source).ptr());
285 } 284 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698