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

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

Issue 2123863004: ScreenCapture for Android phase1, part II (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adopt base::Feature instead of switches Created 4 years, 3 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" 14 #include "chrome/common/features.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "components/content_settings/core/browser/host_content_settings_map.h" 16 #include "components/content_settings/core/browser/host_content_settings_map.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_types.h" 19 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 21
22 #if BUILDFLAG(ANDROID_JAVA_UI) 22 #if BUILDFLAG(ANDROID_JAVA_UI)
23 #include <vector> 23 #include <vector>
24 24
25 #include "base/bind.h" 25 #include "base/bind.h"
26 #include "base/bind_helpers.h" 26 #include "base/bind_helpers.h"
27 #include "chrome/browser/android/chrome_feature_list.h"
27 #include "chrome/browser/media/webrtc/media_stream_infobar_delegate_android.h" 28 #include "chrome/browser/media/webrtc/media_stream_infobar_delegate_android.h"
28 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" 29 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h"
29 #else 30 #else
30 #include "chrome/browser/permissions/permission_request_manager.h" 31 #include "chrome/browser/permissions/permission_request_manager.h"
31 #endif // BUILDFLAG(ANDROID_JAVA_UI) 32 #endif // BUILDFLAG(ANDROID_JAVA_UI)
32 33
33 #if BUILDFLAG(ANDROID_JAVA_UI) 34 #if BUILDFLAG(ANDROID_JAVA_UI)
34 namespace { 35 namespace {
35 // Callback for the permission update infobar when the site and Chrome 36 // Callback for the permission update infobar when the site and Chrome
36 // permissions are mismatched on Android. 37 // permissions are mismatched on Android.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 71 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
71 content::NotificationService::AllSources()); 72 content::NotificationService::AllSources());
72 } 73 }
73 74
74 PermissionBubbleMediaAccessHandler::~PermissionBubbleMediaAccessHandler() { 75 PermissionBubbleMediaAccessHandler::~PermissionBubbleMediaAccessHandler() {
75 } 76 }
76 77
77 bool PermissionBubbleMediaAccessHandler::SupportsStreamType( 78 bool PermissionBubbleMediaAccessHandler::SupportsStreamType(
78 const content::MediaStreamType type, 79 const content::MediaStreamType type,
79 const extensions::Extension* extension) { 80 const extensions::Extension* extension) {
81 #if BUILDFLAG(ANDROID_JAVA_UI)
82 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE ||
83 type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
84 type == content::MEDIA_DESKTOP_VIDEO_CAPTURE;
85 #else
80 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE || 86 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE ||
81 type == content::MEDIA_DEVICE_AUDIO_CAPTURE; 87 type == content::MEDIA_DEVICE_AUDIO_CAPTURE;
88 #endif
82 } 89 }
83 90
84 bool PermissionBubbleMediaAccessHandler::CheckMediaAccessPermission( 91 bool PermissionBubbleMediaAccessHandler::CheckMediaAccessPermission(
85 content::WebContents* web_contents, 92 content::WebContents* web_contents,
86 const GURL& security_origin, 93 const GURL& security_origin,
87 content::MediaStreamType type, 94 content::MediaStreamType type,
88 const extensions::Extension* extension) { 95 const extensions::Extension* extension) {
89 Profile* profile = 96 Profile* profile =
90 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 97 Profile::FromBrowserContext(web_contents->GetBrowserContext());
91 ContentSettingsType content_settings_type = 98 ContentSettingsType content_settings_type =
92 type == content::MEDIA_DEVICE_AUDIO_CAPTURE 99 type == content::MEDIA_DEVICE_AUDIO_CAPTURE
93 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC 100 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
94 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; 101 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA;
95 102
96 MediaPermission permission(content_settings_type, security_origin, 103 MediaPermission permission(content_settings_type, security_origin,
97 web_contents->GetLastCommittedURL().GetOrigin(), profile); 104 web_contents->GetLastCommittedURL().GetOrigin(), profile);
98 content::MediaStreamRequestResult unused; 105 content::MediaStreamRequestResult unused;
99 return permission.GetPermissionStatus(&unused) == CONTENT_SETTING_ALLOW; 106 return permission.GetPermissionStatus(&unused) == CONTENT_SETTING_ALLOW;
100 } 107 }
101 108
102 void PermissionBubbleMediaAccessHandler::HandleRequest( 109 void PermissionBubbleMediaAccessHandler::HandleRequest(
103 content::WebContents* web_contents, 110 content::WebContents* web_contents,
104 const content::MediaStreamRequest& request, 111 const content::MediaStreamRequest& request,
105 const content::MediaResponseCallback& callback, 112 const content::MediaResponseCallback& callback,
106 const extensions::Extension* extension) { 113 const extensions::Extension* extension) {
107 DCHECK_CURRENTLY_ON(BrowserThread::UI); 114 DCHECK_CURRENTLY_ON(BrowserThread::UI);
108 115
116 #if BUILDFLAG(ANDROID_JAVA_UI)
117 if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE &&
118 !base::FeatureList::IsEnabled(
119 chrome::android::kUserMediaScreenCapturing)) {
120 // If screen capturing isn't enabled on Android, we'll use "invalid state"
121 // as result, same as on desktop.
122 callback.Run(content::MediaStreamDevices(),
123 content::MEDIA_DEVICE_INVALID_STATE, nullptr);
124 return;
125 }
126 #endif // BUILDFLAG(ANDROID_JAVA_UI)
127
109 RequestsQueue& queue = pending_requests_[web_contents]; 128 RequestsQueue& queue = pending_requests_[web_contents];
110 queue.push_back(PendingAccessRequest(request, callback)); 129 queue.push_back(PendingAccessRequest(request, callback));
111 130
112 // If this is the only request then show the infobar. 131 // If this is the only request then show the infobar.
113 if (queue.size() == 1) 132 if (queue.size() == 1)
114 ProcessQueuedAccessRequest(web_contents); 133 ProcessQueuedAccessRequest(web_contents);
115 } 134 }
116 135
117 void PermissionBubbleMediaAccessHandler::ProcessQueuedAccessRequest( 136 void PermissionBubbleMediaAccessHandler::ProcessQueuedAccessRequest(
118 content::WebContents* web_contents) { 137 content::WebContents* web_contents) {
119 DCHECK_CURRENTLY_ON(BrowserThread::UI); 138 DCHECK_CURRENTLY_ON(BrowserThread::UI);
120 139
121 std::map<content::WebContents*, RequestsQueue>::iterator it = 140 std::map<content::WebContents*, RequestsQueue>::iterator it =
122 pending_requests_.find(web_contents); 141 pending_requests_.find(web_contents);
123 142
124 if (it == pending_requests_.end() || it->second.empty()) { 143 if (it == pending_requests_.end() || it->second.empty()) {
125 // Don't do anything if the tab was closed. 144 // Don't do anything if the tab was closed.
126 return; 145 return;
127 } 146 }
128 147
129 DCHECK(!it->second.empty()); 148 DCHECK(!it->second.empty());
130 149
131 std::unique_ptr<MediaStreamDevicesController> controller( 150 std::unique_ptr<MediaStreamDevicesController> controller(
tsergeant 2016/09/13 05:06:23 If you added a new InfoBarDelegate class, you woul
braveyao 2016/09/15 21:29:31 Done.
132 new MediaStreamDevicesController( 151 new MediaStreamDevicesController(
133 web_contents, it->second.front().request, 152 web_contents, it->second.front().request,
134 base::Bind( 153 base::Bind(
135 &PermissionBubbleMediaAccessHandler::OnAccessRequestResponse, 154 &PermissionBubbleMediaAccessHandler::OnAccessRequestResponse,
136 base::Unretained(this), web_contents))); 155 base::Unretained(this), web_contents)));
137 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo()) { 156 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo() &&
157 !controller->IsAskingForScreenCapture()) {
138 #if BUILDFLAG(ANDROID_JAVA_UI) 158 #if BUILDFLAG(ANDROID_JAVA_UI)
139 // If either audio or video was previously allowed and Chrome no longer has 159 // If either audio or video was previously allowed and Chrome no longer has
140 // the necessary permissions, show a infobar to attempt to address this 160 // the necessary permissions, show a infobar to attempt to address this
141 // mismatch. 161 // mismatch.
142 std::vector<ContentSettingsType> content_settings_types; 162 std::vector<ContentSettingsType> content_settings_types;
143 if (controller->IsAllowedForAudio()) 163 if (controller->IsAllowedForAudio())
144 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 164 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
145 165
146 if (controller->IsAllowedForVideo()) { 166 if (controller->IsAllowedForVideo()) {
147 content_settings_types.push_back( 167 content_settings_types.push_back(
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 255
236 void PermissionBubbleMediaAccessHandler::Observe( 256 void PermissionBubbleMediaAccessHandler::Observe(
237 int type, 257 int type,
238 const content::NotificationSource& source, 258 const content::NotificationSource& source,
239 const content::NotificationDetails& details) { 259 const content::NotificationDetails& details) {
240 DCHECK_CURRENTLY_ON(BrowserThread::UI); 260 DCHECK_CURRENTLY_ON(BrowserThread::UI);
241 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type); 261 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type);
242 262
243 pending_requests_.erase(content::Source<content::WebContents>(source).ptr()); 263 pending_requests_.erase(content::Source<content::WebContents>(source).ptr());
244 } 264 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698