| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/media/capture/web_contents_tracker.h" | 5 #include "content/browser/media/capture/web_contents_tracker.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/render_frame_host.h" |
| 9 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 11 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 | 15 |
| 15 WebContentsTracker::WebContentsTracker() {} | 16 WebContentsTracker::WebContentsTracker() {} |
| 16 | 17 |
| 17 WebContentsTracker::~WebContentsTracker() { | 18 WebContentsTracker::~WebContentsTracker() { |
| 18 DCHECK(!web_contents()) << "BUG: Still observering!"; | 19 DCHECK(!web_contents()) << "BUG: Still observering!"; |
| 19 } | 20 } |
| 20 | 21 |
| 21 void WebContentsTracker::Start(int render_process_id, int render_view_id, | 22 void WebContentsTracker::Start(int render_process_id, int main_render_frame_id, |
| 22 const ChangeCallback& callback) { | 23 const ChangeCallback& callback) { |
| 23 DCHECK(!message_loop_.get() || message_loop_->BelongsToCurrentThread()); | 24 DCHECK(!message_loop_.get() || message_loop_->BelongsToCurrentThread()); |
| 24 | 25 |
| 25 message_loop_ = base::MessageLoopProxy::current(); | 26 message_loop_ = base::MessageLoopProxy::current(); |
| 26 DCHECK(message_loop_.get()); | 27 DCHECK(message_loop_.get()); |
| 27 callback_ = callback; | 28 callback_ = callback; |
| 28 | 29 |
| 29 BrowserThread::PostTask( | 30 BrowserThread::PostTask( |
| 30 BrowserThread::UI, FROM_HERE, | 31 BrowserThread::UI, FROM_HERE, |
| 31 base::Bind(&WebContentsTracker::LookUpAndObserveWebContents, this, | 32 base::Bind(&WebContentsTracker::LookUpAndObserveWebContents, this, |
| 32 render_process_id, render_view_id)); | 33 render_process_id, main_render_frame_id)); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void WebContentsTracker::Stop() { | 36 void WebContentsTracker::Stop() { |
| 36 DCHECK(message_loop_->BelongsToCurrentThread()); | 37 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 37 | 38 |
| 38 callback_.Reset(); | 39 callback_.Reset(); |
| 39 | 40 |
| 40 BrowserThread::PostTask( | 41 BrowserThread::PostTask( |
| 41 BrowserThread::UI, FROM_HERE, | 42 BrowserThread::UI, FROM_HERE, |
| 42 base::Bind(&WebContentsTracker::Observe, this, | 43 base::Bind(&WebContentsTracker::Observe, this, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 | 61 |
| 61 void WebContentsTracker::MaybeDoCallback(int render_process_id, | 62 void WebContentsTracker::MaybeDoCallback(int render_process_id, |
| 62 int render_view_id) { | 63 int render_view_id) { |
| 63 DCHECK(message_loop_->BelongsToCurrentThread()); | 64 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 64 | 65 |
| 65 if (!callback_.is_null()) | 66 if (!callback_.is_null()) |
| 66 callback_.Run(render_process_id, render_view_id); | 67 callback_.Run(render_process_id, render_view_id); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void WebContentsTracker::LookUpAndObserveWebContents(int render_process_id, | 70 void WebContentsTracker::LookUpAndObserveWebContents(int render_process_id, |
| 70 int render_view_id) { | 71 int main_render_frame_id) { |
| 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 72 | 73 |
| 73 RenderViewHost* const rvh = | 74 Observe(WebContents::FromRenderFrameHost(RenderFrameHost::FromID( |
| 74 RenderViewHost::FromID(render_process_id, render_view_id); | 75 render_process_id, main_render_frame_id))); |
| 75 DVLOG_IF(1, !rvh) << "RenderViewHost::FromID(" | |
| 76 << render_process_id << ", " << render_view_id | |
| 77 << ") returned NULL."; | |
| 78 Observe(rvh ? WebContents::FromRenderViewHost(rvh) : NULL); | |
| 79 DVLOG_IF(1, !web_contents()) | 76 DVLOG_IF(1, !web_contents()) |
| 80 << "WebContents::FromRenderViewHost(" << rvh << ") returned NULL."; | 77 << "Could not find WebContents associated with main RenderFrameHost " |
| 78 << "referenced by render_process_id=" << render_process_id |
| 79 << ", routing_id=" << main_render_frame_id; |
| 81 | 80 |
| 82 OnWebContentsChangeEvent(); | 81 OnWebContentsChangeEvent(); |
| 83 } | 82 } |
| 84 | 83 |
| 85 void WebContentsTracker::RenderViewReady() { | 84 void WebContentsTracker::RenderViewReady() { |
| 86 OnWebContentsChangeEvent(); | 85 OnWebContentsChangeEvent(); |
| 87 } | 86 } |
| 88 | 87 |
| 89 void WebContentsTracker::AboutToNavigateRenderView(RenderViewHost* rvh) { | 88 void WebContentsTracker::AboutToNavigateRenderView(RenderViewHost* rvh) { |
| 90 OnWebContentsChangeEvent(); | 89 OnWebContentsChangeEvent(); |
| 91 } | 90 } |
| 92 | 91 |
| 93 void WebContentsTracker::DidNavigateMainFrame( | 92 void WebContentsTracker::DidNavigateMainFrame( |
| 94 const LoadCommittedDetails& details, const FrameNavigateParams& params) { | 93 const LoadCommittedDetails& details, const FrameNavigateParams& params) { |
| 95 OnWebContentsChangeEvent(); | 94 OnWebContentsChangeEvent(); |
| 96 } | 95 } |
| 97 | 96 |
| 98 void WebContentsTracker::WebContentsDestroyed() { | 97 void WebContentsTracker::WebContentsDestroyed() { |
| 99 OnWebContentsChangeEvent(); | 98 OnWebContentsChangeEvent(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 } // namespace content | 101 } // namespace content |
| OLD | NEW |