Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(593)

Unified Diff: content/browser/web_contents/web_contents_impl.cc

Issue 1980133002: Implement pointer lock API for out-of-process iframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 {

Powered by Google App Engine
This is Rietveld 408576698