Chromium Code Reviews| Index: content/browser/web_contents/web_contents_impl.cc |
| diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc |
| index 5621f827b46d1f009ff3cb81d369fc9adbb12d02..a14fd7c12d1deca213695b9516f40b089d0d545f 100644 |
| --- a/content/browser/web_contents/web_contents_impl.cc |
| +++ b/content/browser/web_contents/web_contents_impl.cc |
| @@ -418,6 +418,7 @@ WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
| bluetooth_connected_device_count_(0), |
| virtual_keyboard_requested_(false), |
| page_scale_factor_is_one_(true), |
| + mouse_lock_widget_(nullptr), |
| loading_weak_factory_(this), |
| weak_factory_(this) { |
| frame_tree_.SetFrameRemoveListener( |
| @@ -1690,6 +1691,9 @@ void WebContentsImpl::RenderWidgetDeleted( |
| if (fullscreen_widget_had_focus_at_shutdown_) |
| view_->RestoreFocus(); |
| } |
| + |
| + if (mouse_lock_widget_ == render_widget_host) |
| + mouse_lock_widget_ = nullptr; |
| } |
| void WebContentsImpl::RenderWidgetGotFocus( |
| @@ -1888,20 +1892,31 @@ void WebContentsImpl::RequestToLockMouse( |
| RenderWidgetHostImpl* render_widget_host, |
| bool user_gesture, |
| bool last_unlocked_by_target) { |
| - if (render_widget_host != GetRenderViewHost()->GetWidget()) { |
| + if (mouse_lock_widget_) { |
| render_widget_host->GotResponseToLockMouseRequest(false); |
| return; |
| } |
| - if (delegate_) |
| + bool widget_in_frame_tree = false; |
| + for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| + if (node->current_frame_host()->GetRenderWidgetHost() == |
| + render_widget_host) { |
| + widget_in_frame_tree = true; |
| + break; |
| + } |
| + } |
| + |
| + if (widget_in_frame_tree && delegate_) { |
| + mouse_lock_widget_ = render_widget_host; |
| delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); |
| - else |
| - GotResponseToLockMouseRequest(false); |
| + } else |
|
nasko
2016/05/25 21:12:01
The else clause also needs {} if the if clause has
lfg
2016/05/31 21:13:20
Done.
|
| + render_widget_host->GotResponseToLockMouseRequest(false); |
| } |
| void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) { |
| - if (!RenderViewHostImpl::From(render_widget_host)) |
| - return; |
| + CHECK(mouse_lock_widget_); |
| + mouse_lock_widget_->SendMouseLockLost(); |
| + mouse_lock_widget_ = nullptr; |
| if (delegate_) |
| delegate_->LostMouseLock(); |
| @@ -2935,10 +2950,9 @@ bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) { |
| if (GetBrowserPluginGuest()) |
| return GetBrowserPluginGuest()->LockMouse(allowed); |
| - return GetRenderViewHost() |
| - ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest( |
| - allowed) |
| - : false; |
| + if (mouse_lock_widget_) |
| + return mouse_lock_widget_->GotResponseToLockMouseRequest(allowed); |
| + return false; |
| } |
| bool WebContentsImpl::HasOpener() const { |