Bug 1664952, move the pointer lock warning handling into a separate actor that applies to subframes, and move origin determination into parent, r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D90888
This commit is contained in:
Neil Deakin 2020-09-22 08:51:57 +00:00
Родитель 4e1c3a4561
Коммит 4273f86002
7 изменённых файлов: 117 добавлений и 46 удалений

Просмотреть файл

@ -46,16 +46,6 @@ class BrowserTabChild extends JSWindowActorChild {
this.handledFirstPaint = true;
this.sendAsyncMessage("Browser:FirstPaint", {});
break;
case "MozDOMPointerLock:Entered":
this.sendAsyncMessage("PointerLock:Entered", {
originNoSuffix: event.target.nodePrincipal.originNoSuffix,
});
break;
case "MozDOMPointerLock:Exited":
this.sendAsyncMessage("PointerLock:Exited");
break;
}
}

Просмотреть файл

@ -39,15 +39,6 @@ class BrowserTabParent extends JSWindowActorParent {
gBrowser.ownerGlobal.RedirectLoad(browser, message.data);
break;
}
case "PointerLock:Entered": {
browser.ownerGlobal.PointerLock.entered(message.data.originNoSuffix);
break;
}
case "PointerLock:Exited":
browser.ownerGlobal.PointerLock.exited();
break;
}
}
}

Просмотреть файл

@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = ["PointerLockChild"];
class PointerLockChild extends JSWindowActorChild {
handleEvent(event) {
switch (event.type) {
case "MozDOMPointerLock:Entered":
this.sendAsyncMessage("PointerLock:Entered");
break;
case "MozDOMPointerLock:Exited":
this.sendAsyncMessage("PointerLock:Exited");
break;
}
}
}

Просмотреть файл

@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = ["PointerLockParent"];
class PointerLockParent extends JSWindowActorParent {
receiveMessage(message) {
let browser = this.manager.browsingContext.top.embedderElement;
switch (message.name) {
case "PointerLock:Entered": {
browser.ownerGlobal.PointerLock.entered(
this.manager.documentPrincipal.originNoSuffix
);
break;
}
case "PointerLock:Exited": {
browser.ownerGlobal.PointerLock.exited();
break;
}
}
}
}

Просмотреть файл

@ -74,6 +74,8 @@ FINAL_TARGET_FILES.actors += [
'PageStyleParent.jsm',
'PluginChild.jsm',
'PluginParent.jsm',
'PointerLockChild.jsm',
'PointerLockParent.jsm',
'PromptParent.jsm',
'RefreshBlockerChild.jsm',
'RefreshBlockerParent.jsm',

Просмотреть файл

@ -312,8 +312,6 @@ let JSWINDOWACTORS = {
events: {
DOMWindowCreated: {},
MozAfterPaint: {},
"MozDOMPointerLock:Entered": {},
"MozDOMPointerLock:Exited": {},
},
},
@ -555,6 +553,22 @@ let JSWINDOWACTORS = {
allFrames: true,
},
PointerLock: {
parent: {
moduleURI: "resource:///actors/PointerLockParent.jsm",
},
child: {
moduleURI: "resource:///actors/PointerLockChild.jsm",
events: {
"MozDOMPointerLock:Entered": {},
"MozDOMPointerLock:Exited": {},
},
},
messageManagerGroups: ["browsers"],
allFrames: true,
},
Prompt: {
parent: {
moduleURI: "resource:///actors/PromptParent.jsm",

Просмотреть файл

@ -5,41 +5,70 @@
"use strict";
const TEST_URL =
"data:text/html,<body onpointerdown='this.requestPointerLock()' style='width: 100px; height: 100px;'></body>";
const BODY_URL =
"<body onpointerdown='this.requestPointerLock()' style='width: 100px; height: 100px;'></body>";
const TEST_URL = "data:text/html," + BODY_URL;
const FRAME_TEST_URL =
'data:text/html,<body><iframe src="http://example.org/document-builder.sjs?html=' +
encodeURI(BODY_URL) +
'"></iframe></body>';
// Make sure the pointerlock warning is shown and exited with the escape key
add_task(async function show_pointerlock_warning_escape() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
let urls = [TEST_URL, FRAME_TEST_URL];
for (let url of urls) {
info("Pointerlock warning test for " + url);
let warning = document.getElementById("pointerlock-warning");
let warningShownPromise = BrowserTestUtils.waitForAttribute(
"onscreen",
warning,
"true"
);
await BrowserTestUtils.synthesizeMouse("body", 4, 4, {}, tab.linkedBrowser);
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
await warningShownPromise;
let warning = document.getElementById("pointerlock-warning");
let warningShownPromise = BrowserTestUtils.waitForAttribute(
"onscreen",
warning,
"true"
);
ok(true, "Pointerlock warning shown");
let expectedWarningText;
let warningHiddenPromise = BrowserTestUtils.waitForAttribute(
"hidden",
warning,
"true"
);
EventUtils.synthesizeKey("KEY_Escape");
await warningHiddenPromise;
let bc = tab.linkedBrowser.browsingContext;
if (bc.children.length) {
// use the subframe if it exists
bc = bc.children[0];
expectedWarningText = "example.org";
} else {
expectedWarningText = "This document";
}
expectedWarningText +=
" has control of your pointer. Press Esc to take back control.";
ok(true, "Pointerlock warning hidden");
await BrowserTestUtils.synthesizeMouse("body", 4, 4, {}, bc);
// Pointerlock should be released after escape is pressed.
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
Assert.equal(content.document.pointerLockElement, null);
});
await warningShownPromise;
await BrowserTestUtils.removeTab(tab);
ok(true, "Pointerlock warning shown");
let warningHiddenPromise = BrowserTestUtils.waitForAttribute(
"hidden",
warning,
"true"
);
is(warning.innerText, expectedWarningText, "Warning text");
EventUtils.synthesizeKey("KEY_Escape");
await warningHiddenPromise;
ok(true, "Pointerlock warning hidden");
// Pointerlock should be released after escape is pressed.
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
Assert.equal(content.document.pointerLockElement, null);
});
await BrowserTestUtils.removeTab(tab);
}
});
/*