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

Side by Side Diff: chrome/browser/media/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: UI tweaking and rebase Created 4 years, 4 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/permission_bubble_media_access_handler.h" 5 #include "chrome/browser/media/permission_bubble_media_access_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h"
9 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
10 #include "chrome/browser/media/media_permission.h" 11 #include "chrome/browser/media/media_permission.h"
11 #include "chrome/browser/media/media_stream_device_permissions.h" 12 #include "chrome/browser/media/media_stream_device_permissions.h"
12 #include "chrome/browser/media/media_stream_devices_controller.h" 13 #include "chrome/browser/media/media_stream_devices_controller.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/features.h" 15 #include "chrome/common/features.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "components/content_settings/core/browser/host_content_settings_map.h" 17 #include "components/content_settings/core/browser/host_content_settings_map.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_types.h" 20 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/content_switches.h"
21 23
22 #if BUILDFLAG(ANDROID_JAVA_UI) 24 #if BUILDFLAG(ANDROID_JAVA_UI)
23 #include <vector> 25 #include <vector>
24 26
25 #include "base/bind.h" 27 #include "base/bind.h"
26 #include "base/bind_helpers.h" 28 #include "base/bind_helpers.h"
27 #include "chrome/browser/media/media_stream_infobar_delegate_android.h" 29 #include "chrome/browser/media/media_stream_infobar_delegate_android.h"
28 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" 30 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h"
29 #else 31 #else
30 #include "chrome/browser/permissions/permission_request_manager.h" 32 #include "chrome/browser/permissions/permission_request_manager.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 72 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
71 content::NotificationService::AllSources()); 73 content::NotificationService::AllSources());
72 } 74 }
73 75
74 PermissionBubbleMediaAccessHandler::~PermissionBubbleMediaAccessHandler() { 76 PermissionBubbleMediaAccessHandler::~PermissionBubbleMediaAccessHandler() {
75 } 77 }
76 78
77 bool PermissionBubbleMediaAccessHandler::SupportsStreamType( 79 bool PermissionBubbleMediaAccessHandler::SupportsStreamType(
78 const content::MediaStreamType type, 80 const content::MediaStreamType type,
79 const extensions::Extension* extension) { 81 const extensions::Extension* extension) {
82 #if BUILDFLAG(ANDROID_JAVA_UI)
83 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE ||
84 type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
85 type == content::MEDIA_DESKTOP_VIDEO_CAPTURE;
86 #else
80 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE || 87 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE ||
81 type == content::MEDIA_DEVICE_AUDIO_CAPTURE; 88 type == content::MEDIA_DEVICE_AUDIO_CAPTURE;
89 #endif
82 } 90 }
83 91
84 bool PermissionBubbleMediaAccessHandler::CheckMediaAccessPermission( 92 bool PermissionBubbleMediaAccessHandler::CheckMediaAccessPermission(
85 content::WebContents* web_contents, 93 content::WebContents* web_contents,
86 const GURL& security_origin, 94 const GURL& security_origin,
87 content::MediaStreamType type, 95 content::MediaStreamType type,
88 const extensions::Extension* extension) { 96 const extensions::Extension* extension) {
89 Profile* profile = 97 Profile* profile =
90 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 98 Profile::FromBrowserContext(web_contents->GetBrowserContext());
91 ContentSettingsType content_settings_type = 99 ContentSettingsType content_settings_type =
92 type == content::MEDIA_DEVICE_AUDIO_CAPTURE 100 type == content::MEDIA_DEVICE_AUDIO_CAPTURE
93 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC 101 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
94 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; 102 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA;
95 103
96 MediaPermission permission(content_settings_type, security_origin, 104 MediaPermission permission(content_settings_type, security_origin,
97 web_contents->GetLastCommittedURL().GetOrigin(), profile); 105 web_contents->GetLastCommittedURL().GetOrigin(), profile);
98 content::MediaStreamRequestResult unused; 106 content::MediaStreamRequestResult unused;
99 return permission.GetPermissionStatus(&unused) == CONTENT_SETTING_ALLOW; 107 return permission.GetPermissionStatus(&unused) == CONTENT_SETTING_ALLOW;
100 } 108 }
101 109
102 void PermissionBubbleMediaAccessHandler::HandleRequest( 110 void PermissionBubbleMediaAccessHandler::HandleRequest(
103 content::WebContents* web_contents, 111 content::WebContents* web_contents,
104 const content::MediaStreamRequest& request, 112 const content::MediaStreamRequest& request,
105 const content::MediaResponseCallback& callback, 113 const content::MediaResponseCallback& callback,
106 const extensions::Extension* extension) { 114 const extensions::Extension* extension) {
107 DCHECK_CURRENTLY_ON(BrowserThread::UI); 115 DCHECK_CURRENTLY_ON(BrowserThread::UI);
108 116
117 #if BUILDFLAG(ANDROID_JAVA_UI)
gone 2016/08/10 19:04:03 Why are you using ANDROID_JAVA_UI instead of OS_AN
braveyao 2016/08/12 23:37:44 It's because only ANDROID_JAVA_UI is used in this
118 if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE &&
119 !base::CommandLine::ForCurrentProcess()->HasSwitch(
120 switches::kEnableUserMediaScreenCapturing)) {
121 // If screen capturing isn't enabled on Android, we'll use "invalid state"
122 // as result, same as on desktop.
123 callback.Run(content::MediaStreamDevices(),
124 content::MEDIA_DEVICE_INVALID_STATE, nullptr);
125 return;
126 }
127 #endif
128
109 RequestsQueue& queue = pending_requests_[web_contents]; 129 RequestsQueue& queue = pending_requests_[web_contents];
110 queue.push_back(PendingAccessRequest(request, callback)); 130 queue.push_back(PendingAccessRequest(request, callback));
111 131
112 // If this is the only request then show the infobar. 132 // If this is the only request then show the infobar.
113 if (queue.size() == 1) 133 if (queue.size() == 1)
114 ProcessQueuedAccessRequest(web_contents); 134 ProcessQueuedAccessRequest(web_contents);
115 } 135 }
116 136
117 void PermissionBubbleMediaAccessHandler::ProcessQueuedAccessRequest( 137 void PermissionBubbleMediaAccessHandler::ProcessQueuedAccessRequest(
118 content::WebContents* web_contents) { 138 content::WebContents* web_contents) {
119 DCHECK_CURRENTLY_ON(BrowserThread::UI); 139 DCHECK_CURRENTLY_ON(BrowserThread::UI);
120 140
121 std::map<content::WebContents*, RequestsQueue>::iterator it = 141 std::map<content::WebContents*, RequestsQueue>::iterator it =
122 pending_requests_.find(web_contents); 142 pending_requests_.find(web_contents);
123 143
124 if (it == pending_requests_.end() || it->second.empty()) { 144 if (it == pending_requests_.end() || it->second.empty()) {
125 // Don't do anything if the tab was closed. 145 // Don't do anything if the tab was closed.
126 return; 146 return;
127 } 147 }
128 148
129 DCHECK(!it->second.empty()); 149 DCHECK(!it->second.empty());
130 150
131 std::unique_ptr<MediaStreamDevicesController> controller( 151 std::unique_ptr<MediaStreamDevicesController> controller(
132 new MediaStreamDevicesController( 152 new MediaStreamDevicesController(
133 web_contents, it->second.front().request, 153 web_contents, it->second.front().request,
134 base::Bind( 154 base::Bind(
135 &PermissionBubbleMediaAccessHandler::OnAccessRequestResponse, 155 &PermissionBubbleMediaAccessHandler::OnAccessRequestResponse,
136 base::Unretained(this), web_contents))); 156 base::Unretained(this), web_contents)));
137 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo()) { 157 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo() &&
158 !controller->IsAskingForScreenCapture()) {
gone 2016/08/10 19:04:03 Why is this new check necessary? Nothing below (n
braveyao 2016/08/12 23:37:44 It's necessary. Otherwise a screen capture will sa
138 #if BUILDFLAG(ANDROID_JAVA_UI) 159 #if BUILDFLAG(ANDROID_JAVA_UI)
139 // If either audio or video was previously allowed and Chrome no longer has 160 // 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 161 // the necessary permissions, show a infobar to attempt to address this
141 // mismatch. 162 // mismatch.
142 std::vector<ContentSettingsType> content_settings_types; 163 std::vector<ContentSettingsType> content_settings_types;
143 if (controller->IsAllowedForAudio()) 164 if (controller->IsAllowedForAudio())
144 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 165 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
145 166
146 if (controller->IsAllowedForVideo()) { 167 if (controller->IsAllowedForVideo()) {
147 content_settings_types.push_back( 168 content_settings_types.push_back(
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 256
236 void PermissionBubbleMediaAccessHandler::Observe( 257 void PermissionBubbleMediaAccessHandler::Observe(
237 int type, 258 int type,
238 const content::NotificationSource& source, 259 const content::NotificationSource& source,
239 const content::NotificationDetails& details) { 260 const content::NotificationDetails& details) {
240 DCHECK_CURRENTLY_ON(BrowserThread::UI); 261 DCHECK_CURRENTLY_ON(BrowserThread::UI);
241 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type); 262 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type);
242 263
243 pending_requests_.erase(content::Source<content::WebContents>(source).ptr()); 264 pending_requests_.erase(content::Source<content::WebContents>(source).ptr());
244 } 265 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698