Bug 1694698 - Reject pointer lock request if the active tab is changed; r=smaug
authorEdgar Chen <echen@mozilla.com>
Tue, 16 Mar 2021 14:50:05 +0000
changeset 571417 f6a25854b70b6e3e951b80bc474fd704422859a4
parent 571416 85c7bc87fa253397e853923d66df5bac69fb318b
child 571418 433c7dae3ffffa38b4de6ecaa46b5bc871a0f413
push id38291
push userncsoregi@mozilla.com
push dateTue, 16 Mar 2021 21:48:55 +0000
treeherdermozilla-central@0d51fdccaa96 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1694698
milestone88.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1694698 - Reject pointer lock request if the active tab is changed; r=smaug Differential Revision: https://phabricator.services.mozilla.com/D107275
dom/ipc/BrowserParent.cpp
--- a/dom/ipc/BrowserParent.cpp
+++ b/dom/ipc/BrowserParent.cpp
@@ -4118,20 +4118,31 @@ mozilla::ipc::IPCResult BrowserParent::R
   aResolve(!isFxrWindow);
 #else
   aResolve(true);
 #endif
 
   return IPC_OK();
 }
 
+static BrowserParent* GetTopLevelBrowserParent(BrowserParent* aBrowserParent) {
+  MOZ_ASSERT(aBrowserParent);
+  BrowserParent* parent = aBrowserParent;
+  while (BrowserBridgeParent* bridge = parent->GetBrowserBridgeParent()) {
+    parent = bridge->Manager();
+  }
+  return parent;
+}
+
 mozilla::ipc::IPCResult BrowserParent::RecvRequestPointerLock(
     RequestPointerLockResolver&& aResolve) {
   nsCString error;
-  if (!PointerLockManager::SetLockedRemoteTarget(this)) {
+  if (sTopLevelWebFocus != GetTopLevelBrowserParent(this)) {
+    error = "PointerLockDeniedNotFocused";
+  } else if (!PointerLockManager::SetLockedRemoteTarget(this)) {
     error = "PointerLockDeniedInUse";
   } else {
     PointerEventHandler::ReleaseAllPointerCaptureRemoteTarget();
   }
   aResolve(error);
   return IPC_OK();
 }