Chromium Code Reviews| Index: content/browser/media/capture/web_contents_tracker.cc |
| diff --git a/content/browser/media/capture/web_contents_tracker.cc b/content/browser/media/capture/web_contents_tracker.cc |
| index a9e161f1ce3fcf2ce299734fb103d805ea574eb5..a72c7bef800faceba4a5f399d7113a1aae17fbc6 100644 |
| --- a/content/browser/media/capture/web_contents_tracker.cc |
| +++ b/content/browser/media/capture/web_contents_tracker.cc |
| @@ -44,6 +44,7 @@ void WebContentsTracker::Stop() { |
| DCHECK(task_runner_->BelongsToCurrentThread()); |
| callback_.Reset(); |
| + resize_callback_.Reset(); |
| if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| WebContentsObserver::Observe(NULL); |
| @@ -78,6 +79,31 @@ RenderWidgetHost* WebContentsTracker::GetTargetRenderWidgetHost() const { |
| return rwh; |
| } |
| +void WebContentsTracker::SetResizeChangeCallback( |
| + const ChangeCallback& callback) { |
| + DCHECK(!task_runner_.get() || task_runner_->BelongsToCurrentThread()); |
| + resize_callback_ = callback; |
| +} |
| + |
| +namespace { |
| + |
| +// In debug builds, map a non-null RenderWidgetHost pointer to an invalid |
| +// non-null pointer. This causes the app to crash if a client of |
| +// WebContentsTracker later attempts to dereference the pointer when it should |
| +// not. See comments for ChangeCallback in the header file. |
| +RenderWidgetHost* InvalidatePointerInDebugBuilds(RenderWidgetHost* rwh) { |
|
Wez
2015/05/15 00:55:42
See my other comments on how to avoid the need for
miu
2015/05/15 21:14:01
Acknowledged.
|
| +#ifndef NDEBUG |
| + if (rwh) |
| + return static_cast<RenderWidgetHost*>(nullptr) + 1; |
| + else |
| + return nullptr; |
| +#else |
| + return rwh; |
| +#endif |
| +} |
| + |
| +} // namespace |
| + |
| void WebContentsTracker::OnPossibleTargetChange(bool force_callback_run) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| @@ -93,7 +119,9 @@ void WebContentsTracker::OnPossibleTargetChange(bool force_callback_run) { |
| } else { |
| task_runner_->PostTask( |
| FROM_HERE, |
| - base::Bind(&WebContentsTracker::MaybeDoCallback, this, rwh)); |
| + base::Bind(&WebContentsTracker::MaybeDoCallback, |
| + this, |
| + InvalidatePointerInDebugBuilds(rwh))); |
| } |
| } |
| @@ -102,6 +130,15 @@ void WebContentsTracker::MaybeDoCallback(RenderWidgetHost* rwh) { |
| if (!callback_.is_null()) |
| callback_.Run(rwh); |
| + if (rwh) |
| + MaybeDoResizeCallback(rwh); |
| +} |
| + |
| +void WebContentsTracker::MaybeDoResizeCallback(RenderWidgetHost* rwh) { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + |
| + if (!resize_callback_.is_null()) |
| + resize_callback_.Run(rwh); |
| } |
| void WebContentsTracker::StartObservingWebContents(int render_process_id, |
| @@ -128,6 +165,25 @@ void WebContentsTracker::RenderFrameHostChanged(RenderFrameHost* old_host, |
| OnPossibleTargetChange(false); |
| } |
| +void WebContentsTracker::MainFrameWasResized(bool width_changed) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + RenderWidgetHost* const rwh = GetTargetRenderWidgetHost(); |
| + if (!rwh) |
| + return; |
| + |
| + if (task_runner_->BelongsToCurrentThread()) { |
| + MaybeDoResizeCallback(rwh); |
| + } else { |
| + task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&WebContentsTracker::MaybeDoResizeCallback, |
| + this, |
| + InvalidatePointerInDebugBuilds(rwh))); |
| + } |
| + |
| +} |
| + |
| void WebContentsTracker::WebContentsDestroyed() { |
| Observe(NULL); |
| OnPossibleTargetChange(false); |