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

Unified Diff: chrome/browser/media/media_capture_devices_dispatcher.cc

Issue 364123002: [Cross-Site Isolation] Migrate entire MediaStream verticals to be per-RenderFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improved/Stabilized tab capture API impl, plus RFID fixes in desktop capture and speech recog. Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/media_capture_devices_dispatcher.cc
diff --git a/chrome/browser/media/media_capture_devices_dispatcher.cc b/chrome/browser/media/media_capture_devices_dispatcher.cc
index 136139a4d68ce254809c377c010face81becb097..751b1dd4bd4b3d15408d6f2146c98edf95e846c0 100644
--- a/chrome/browser/media/media_capture_devices_dispatcher.cc
+++ b/chrome/browser/media/media_capture_devices_dispatcher.cc
@@ -36,6 +36,7 @@
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/media_stream_request.h"
#include "extensions/common/constants.h"
@@ -192,6 +193,15 @@ scoped_ptr<content::MediaStreamUI> GetDevicesForDesktopCapture(
return ui.Pass();
}
+// Returns the WebContents instance that contains the RenderFrameHost referenced
+// by the given |request|.
+content::WebContents* GetWebContentsFromRequest(
+ const content::MediaStreamRequest& request) {
+ return content::WebContents::FromRenderFrameHost(
+ content::RenderFrameHost::FromID(request.render_process_id,
+ request.render_frame_id));
+}
+
#if defined(AUDIO_STREAM_MONITORING)
AudioStreamMonitor* AudioStreamMonitorFromRenderFrame(
@@ -394,11 +404,22 @@ void MediaCaptureDevicesDispatcher::ProcessDesktopCaptureAccessRequest(
// The extension name that the stream is registered with.
std::string original_extension_name;
// Resolve DesktopMediaID for the specified device id.
- content::DesktopMediaID media_id =
- GetDesktopStreamsRegistry()->RequestMediaForStreamId(
- request.requested_video_device_id, request.render_process_id,
- request.render_view_id, request.security_origin,
- &original_extension_name);
+ content::DesktopMediaID media_id;
+ // TODO(miu): Replace "main RenderFrame" IDs with the request's actual
+ // RenderFrame IDs once the desktop capture extension API implementation is
+ // fixed. http://crbug.com/304341
+ content::WebContents* const web_contents_for_stream =
+ GetWebContentsFromRequest(request);
+ content::RenderFrameHost* const main_frame = web_contents_for_stream ?
+ web_contents_for_stream->GetMainFrame() : NULL;
+ if (main_frame) {
+ media_id = GetDesktopStreamsRegistry()->RequestMediaForStreamId(
+ request.requested_video_device_id,
+ main_frame->GetProcess()->GetID(),
+ main_frame->GetRoutingID(),
ncarter (slow) 2014/07/11 22:32:24 This ultimately should be request.render_process_i
miu 2014/07/12 03:16:29 See TODO(miu) comment about 10 lines above. ;-)
ncarter (slow) 2014/07/14 17:51:05 Ah got it now. I'd seen the TODO but it hadn't qui
+ request.security_origin,
+ &original_extension_name);
+ }
// Received invalid device id.
if (media_id.type == content::DesktopMediaID::TYPE_NONE) {
@@ -545,9 +566,8 @@ void MediaCaptureDevicesDispatcher::ProcessTabCaptureAccessRequest(
callback.Run(devices, content::MEDIA_DEVICE_INVALID_STATE, ui.Pass());
return;
}
- bool tab_capture_allowed =
- tab_capture_registry->VerifyRequest(request.render_process_id,
- request.render_view_id);
+ const bool tab_capture_allowed = tab_capture_registry->VerifyRequest(
+ GetWebContentsFromRequest(request), extension->id());
if (request.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE &&
tab_capture_allowed &&
@@ -804,18 +824,18 @@ void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() {
void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
int render_process_id,
- int render_view_id,
+ int render_frame_id,
int page_request_id,
const GURL& security_origin,
- const content::MediaStreamDevice& device,
+ content::MediaStreamType stream_type,
content::MediaRequestState state) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(
&MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread,
- base::Unretained(this), render_process_id, render_view_id,
- page_request_id, security_origin, device, state));
+ base::Unretained(this), render_process_id, render_frame_id,
+ page_request_id, security_origin, stream_type, state));
}
void MediaCaptureDevicesDispatcher::OnAudioStreamPlaying(
@@ -877,17 +897,17 @@ void MediaCaptureDevicesDispatcher::NotifyVideoDevicesChangedOnUIThread() {
void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread(
int render_process_id,
- int render_view_id,
+ int render_frame_id,
int page_request_id,
const GURL& security_origin,
- const content::MediaStreamDevice& device,
+ content::MediaStreamType stream_type,
content::MediaRequestState state) {
// Track desktop capture sessions. Tracking is necessary to avoid unbalanced
// session counts since not all requests will reach MEDIA_REQUEST_STATE_DONE,
// but they will all reach MEDIA_REQUEST_STATE_CLOSING.
- if (device.type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) {
+ if (stream_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) {
if (state == content::MEDIA_REQUEST_STATE_DONE) {
- DesktopCaptureSession session = { render_process_id, render_view_id,
+ DesktopCaptureSession session = { render_process_id, render_frame_id,
page_request_id };
desktop_capture_sessions_.push_back(session);
} else if (state == content::MEDIA_REQUEST_STATE_CLOSING) {
@@ -896,7 +916,7 @@ void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread(
it != desktop_capture_sessions_.end();
++it) {
if (it->render_process_id == render_process_id &&
- it->render_view_id == render_view_id &&
+ it->render_frame_id == render_frame_id &&
it->page_request_id == page_request_id) {
desktop_capture_sessions_.erase(it);
break;
@@ -914,7 +934,7 @@ void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread(
for (RequestsQueue::iterator it = queue.begin();
it != queue.end(); ++it) {
if (it->request.render_process_id == render_process_id &&
- it->request.render_view_id == render_view_id &&
+ it->request.render_frame_id == render_frame_id &&
it->request.page_request_id == page_request_id) {
queue.erase(it);
found = true;
@@ -927,7 +947,7 @@ void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread(
}
#if defined(OS_CHROMEOS)
- if (IsOriginForCasting(security_origin) && IsVideoMediaType(device.type)) {
+ if (IsOriginForCasting(security_origin) && IsVideoMediaType(stream_type)) {
// Notify ash that casting state has changed.
if (state == content::MEDIA_REQUEST_STATE_DONE) {
ash::Shell::GetInstance()->OnCastingSessionStartedOrStopped(true);
@@ -939,8 +959,8 @@ void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread(
FOR_EACH_OBSERVER(Observer, observers_,
OnRequestUpdate(render_process_id,
- render_view_id,
- device,
+ render_frame_id,
+ stream_type,
state));
}

Powered by Google App Engine
This is Rietveld 408576698