| Index: content/browser/renderer_host/media/web_contents_capture_util.cc
|
| diff --git a/content/browser/renderer_host/media/web_contents_capture_util.cc b/content/browser/renderer_host/media/web_contents_capture_util.cc
|
| index 46b73766e0a7f43adddf7a47e2e61268fc21b3cc..59947cd7cb951195e1f39d5619a69573ac24bfb2 100644
|
| --- a/content/browser/renderer_host/media/web_contents_capture_util.cc
|
| +++ b/content/browser/renderer_host/media/web_contents_capture_util.cc
|
| @@ -5,9 +5,16 @@
|
| #include "content/browser/renderer_host/media/web_contents_capture_util.h"
|
|
|
| #include "base/basictypes.h"
|
| +#include "base/message_loop_proxy.h"
|
| #include "base/string_number_conversions.h"
|
| #include "base/string_piece.h"
|
| #include "base/string_util.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/render_process_host.h"
|
| +#include "content/public/browser/render_view_host.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +
|
| +namespace content {
|
|
|
| namespace {
|
|
|
| @@ -15,13 +22,13 @@ const char kVirtualDeviceScheme[] = "virtual-media-stream://";
|
|
|
| } // namespace
|
|
|
| -namespace content {
|
| -
|
| +// static
|
| std::string WebContentsCaptureUtil::AppendWebContentsDeviceScheme(
|
| const std::string& device_id) {
|
| return kVirtualDeviceScheme + device_id;
|
| }
|
|
|
| +// static
|
| std::string WebContentsCaptureUtil::StripWebContentsDeviceScheme(
|
| const std::string& device_id) {
|
| return (IsWebContentsDeviceId(device_id) ?
|
| @@ -29,11 +36,13 @@ std::string WebContentsCaptureUtil::StripWebContentsDeviceScheme(
|
| device_id);
|
| }
|
|
|
| +// static
|
| bool WebContentsCaptureUtil::IsWebContentsDeviceId(
|
| const std::string& device_id) {
|
| return StartsWithASCII(device_id, kVirtualDeviceScheme, true);
|
| }
|
|
|
| +// static
|
| bool WebContentsCaptureUtil::ExtractTabCaptureTarget(
|
| const std::string& device_id_param,
|
| int* render_process_id,
|
| @@ -56,4 +65,91 @@ bool WebContentsCaptureUtil::ExtractTabCaptureTarget(
|
| base::StringToInt(component2, render_view_id));
|
| }
|
|
|
| +WebContentsTracker::WebContentsTracker() {}
|
| +
|
| +WebContentsTracker::~WebContentsTracker() {
|
| + DCHECK(!web_contents()) << "BUG: Still observering!";
|
| +}
|
| +
|
| +void WebContentsTracker::Start(int render_process_id, int render_view_id,
|
| + const ChangeCallback& callback) {
|
| + DCHECK(!message_loop_ || message_loop_->BelongsToCurrentThread());
|
| +
|
| + message_loop_ = base::MessageLoopProxy::current();
|
| + DCHECK(message_loop_);
|
| + callback_ = callback;
|
| +
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&WebContentsTracker::LookUpAndObserveWebContents, this,
|
| + render_process_id, render_view_id));
|
| +}
|
| +
|
| +void WebContentsTracker::Stop() {
|
| + DCHECK(message_loop_->BelongsToCurrentThread());
|
| +
|
| + callback_.Reset();
|
| +
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&WebContentsTracker::Observe, this,
|
| + static_cast<WebContents*>(NULL)));
|
| +}
|
| +
|
| +void WebContentsTracker::OnWebContentsChangeEvent() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| +
|
| + WebContents* const wc = web_contents();
|
| + RenderViewHost* const rvh = wc ? wc->GetRenderViewHost() : NULL;
|
| + RenderProcessHost* const rph = rvh ? rvh->GetProcess() : NULL;
|
| +
|
| + const int render_process_id = rph ? rph->GetID() : MSG_ROUTING_NONE;
|
| + const int render_view_id = rvh ? rvh->GetRoutingID() : MSG_ROUTING_NONE;
|
| +
|
| + message_loop_->PostTask(FROM_HERE,
|
| + base::Bind(&WebContentsTracker::MaybeDoCallback, this,
|
| + render_process_id, render_view_id));
|
| +}
|
| +
|
| +void WebContentsTracker::MaybeDoCallback(int render_process_id,
|
| + int render_view_id) {
|
| + DCHECK(message_loop_->BelongsToCurrentThread());
|
| +
|
| + if (!callback_.is_null())
|
| + callback_.Run(render_process_id, render_view_id);
|
| +}
|
| +
|
| +void WebContentsTracker::LookUpAndObserveWebContents(int render_process_id,
|
| + int render_view_id) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| +
|
| + RenderViewHost* const rvh =
|
| + RenderViewHost::FromID(render_process_id, render_view_id);
|
| + DVLOG_IF(1, !rvh) << "RenderViewHost::FromID("
|
| + << render_process_id << ", " << render_view_id
|
| + << ") returned NULL.";
|
| + Observe(rvh ? WebContents::FromRenderViewHost(rvh) : NULL);
|
| + DVLOG_IF(1, !web_contents())
|
| + << "WebContents::FromRenderViewHost(" << rvh << ") returned NULL.";
|
| +
|
| + OnWebContentsChangeEvent();
|
| +}
|
| +
|
| +void WebContentsTracker::RenderViewReady() {
|
| + OnWebContentsChangeEvent();
|
| +}
|
| +
|
| +void WebContentsTracker::AboutToNavigateRenderView(RenderViewHost* rvh) {
|
| + OnWebContentsChangeEvent();
|
| +}
|
| +
|
| +void WebContentsTracker::DidNavigateMainFrame(
|
| + const LoadCommittedDetails& details, const FrameNavigateParams& params) {
|
| + OnWebContentsChangeEvent();
|
| +}
|
| +
|
| +void WebContentsTracker::WebContentsDestroyed(WebContents* web_contents) {
|
| + OnWebContentsChangeEvent();
|
| +}
|
| +
|
| } // namespace content
|
|
|