| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 5 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "content/browser/frame_host/frame_tree_node.h" | 11 #include "content/browser/frame_host/frame_tree_node.h" |
| 12 #include "content/browser/frame_host/render_frame_host_delegate.h" | 12 #include "content/browser/frame_host/render_frame_host_delegate.h" |
| 13 #include "content/browser/frame_host/render_frame_host_impl.h" | 13 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 16 #include "media/capture/video/fake_video_capture_device.h" | 16 #include "media/capture/video/fake_video_capture_device.h" |
| 17 #include "url/gurl.h" |
| 18 #include "url/origin.h" |
| 17 | 19 |
| 18 namespace content { | 20 namespace content { |
| 19 | 21 |
| 22 namespace { |
| 23 |
| 24 GURL ConvertToGURL(const url::Origin& origin) { |
| 25 return origin.unique() ? GURL() : GURL(origin.Serialize()); |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 20 void SetAndCheckAncestorFlag(MediaStreamRequest* request) { | 30 void SetAndCheckAncestorFlag(MediaStreamRequest* request) { |
| 21 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 31 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 22 RenderFrameHostImpl* rfh = | 32 RenderFrameHostImpl* rfh = |
| 23 RenderFrameHostImpl::FromID(request->render_process_id, | 33 RenderFrameHostImpl::FromID(request->render_process_id, |
| 24 request->render_frame_id); | 34 request->render_frame_id); |
| 25 | 35 |
| 26 if (rfh == NULL) { | 36 if (rfh == NULL) { |
| 27 // RenderFrame destroyed before the request is handled? | 37 // RenderFrame destroyed before the request is handled? |
| 28 return; | 38 return; |
| 29 } | 39 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 196 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 187 | 197 |
| 188 response_callback_ = response_callback; | 198 response_callback_ = response_callback; |
| 189 BrowserThread::PostTask( | 199 BrowserThread::PostTask( |
| 190 BrowserThread::UI, FROM_HERE, | 200 BrowserThread::UI, FROM_HERE, |
| 191 base::Bind(&Core::RequestAccess, base::Unretained(core_.get()), | 201 base::Bind(&Core::RequestAccess, base::Unretained(core_.get()), |
| 192 base::Passed(&request))); | 202 base::Passed(&request))); |
| 193 } | 203 } |
| 194 | 204 |
| 195 void MediaStreamUIProxy::CheckAccess( | 205 void MediaStreamUIProxy::CheckAccess( |
| 196 const GURL& security_origin, | 206 const url::Origin& security_origin, |
| 197 MediaStreamType type, | 207 MediaStreamType type, |
| 198 int render_process_id, | 208 int render_process_id, |
| 199 int render_frame_id, | 209 int render_frame_id, |
| 200 const base::Callback<void(bool)>& callback) { | 210 const base::Callback<void(bool)>& callback) { |
| 201 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 211 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 202 | 212 |
| 203 BrowserThread::PostTaskAndReplyWithResult( | 213 BrowserThread::PostTaskAndReplyWithResult( |
| 204 BrowserThread::UI, | 214 BrowserThread::UI, FROM_HERE, |
| 205 FROM_HERE, | 215 base::Bind(&Core::CheckAccess, base::Unretained(core_.get()), |
| 206 base::Bind(&Core::CheckAccess, | 216 ConvertToGURL(security_origin), type, render_process_id, |
| 207 base::Unretained(core_.get()), | |
| 208 security_origin, | |
| 209 type, | |
| 210 render_process_id, | |
| 211 render_frame_id), | 217 render_frame_id), |
| 212 base::Bind(&MediaStreamUIProxy::OnCheckedAccess, | 218 base::Bind(&MediaStreamUIProxy::OnCheckedAccess, |
| 213 weak_factory_.GetWeakPtr(), | 219 weak_factory_.GetWeakPtr(), callback)); |
| 214 callback)); | |
| 215 } | 220 } |
| 216 | 221 |
| 217 void MediaStreamUIProxy::OnStarted(const base::Closure& stop_callback, | 222 void MediaStreamUIProxy::OnStarted(const base::Closure& stop_callback, |
| 218 const WindowIdCallback& window_id_callback) { | 223 const WindowIdCallback& window_id_callback) { |
| 219 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 224 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 220 | 225 |
| 221 stop_callback_ = stop_callback; | 226 stop_callback_ = stop_callback; |
| 222 | 227 |
| 223 // Owned by the PostTaskAndReply callback. | 228 // Owned by the PostTaskAndReply callback. |
| 224 gfx::NativeViewId* window_id = new gfx::NativeViewId(0); | 229 gfx::NativeViewId* window_id = new gfx::NativeViewId(0); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 BrowserThread::IO, FROM_HERE, | 348 BrowserThread::IO, FROM_HERE, |
| 344 base::Bind(&MediaStreamUIProxy::ProcessAccessRequestResponse, | 349 base::Bind(&MediaStreamUIProxy::ProcessAccessRequestResponse, |
| 345 weak_factory_.GetWeakPtr(), | 350 weak_factory_.GetWeakPtr(), |
| 346 devices_to_use, | 351 devices_to_use, |
| 347 devices_to_use.empty() ? | 352 devices_to_use.empty() ? |
| 348 MEDIA_DEVICE_NO_HARDWARE : | 353 MEDIA_DEVICE_NO_HARDWARE : |
| 349 MEDIA_DEVICE_OK)); | 354 MEDIA_DEVICE_OK)); |
| 350 } | 355 } |
| 351 | 356 |
| 352 void FakeMediaStreamUIProxy::CheckAccess( | 357 void FakeMediaStreamUIProxy::CheckAccess( |
| 353 const GURL& security_origin, | 358 const url::Origin& security_origin, |
| 354 MediaStreamType type, | 359 MediaStreamType type, |
| 355 int render_process_id, | 360 int render_process_id, |
| 356 int render_frame_id, | 361 int render_frame_id, |
| 357 const base::Callback<void(bool)>& callback) { | 362 const base::Callback<void(bool)>& callback) { |
| 358 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 363 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 359 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 364 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| 360 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 365 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
| 361 | 366 |
| 362 bool have_access = false; | 367 bool have_access = false; |
| 363 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 368 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 374 callback, | 379 callback, |
| 375 have_access)); | 380 have_access)); |
| 376 return; | 381 return; |
| 377 } | 382 } |
| 378 | 383 |
| 379 void FakeMediaStreamUIProxy::OnStarted( | 384 void FakeMediaStreamUIProxy::OnStarted( |
| 380 const base::Closure& stop_callback, | 385 const base::Closure& stop_callback, |
| 381 const WindowIdCallback& window_id_callback) {} | 386 const WindowIdCallback& window_id_callback) {} |
| 382 | 387 |
| 383 } // namespace content | 388 } // namespace content |
| OLD | NEW |