зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1532795: Part 5 - Support SpecialPowers.spawn on WindowProxy objects. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D35378 --HG-- extra : rebase_source : c69b88bd7142f70612c05e56e1a0d690b464ff99 extra : source : d5415970da5fd83eb870b397b8db7fdf6c57ad23
This commit is contained in:
Родитель
65f0f4700f
Коммит
c98e734fe6
|
@ -9,6 +9,8 @@
|
|||
|
||||
<iframe id="iframe"></iframe>
|
||||
|
||||
<span id="hello">World.</span>
|
||||
|
||||
<script>
|
||||
/* eslint-disable prettier/prettier */
|
||||
/* globals SpecialPowers, content */
|
||||
|
@ -26,7 +28,31 @@
|
|||
return elem.textContent;
|
||||
});
|
||||
|
||||
is(result, "Hello there.", "Got correct element text");
|
||||
is(result, "Hello there.", "Got correct element text from frame");
|
||||
|
||||
result = await SpecialPowers.spawn(frame, ["#hello"], selector => {
|
||||
return SpecialPowers.spawn(content.parent, [selector], selector => {
|
||||
let elem = content.document.querySelector(selector);
|
||||
return elem.textContent;
|
||||
});
|
||||
});
|
||||
|
||||
is(result, "World.", "Got correct element text from frame's window.parent");
|
||||
|
||||
result = await SpecialPowers.spawn(frame.contentWindow, ["#span"], selector => {
|
||||
let elem = content.document.querySelector(selector);
|
||||
return elem.textContent;
|
||||
});
|
||||
|
||||
is(result, "Hello there.", "Got correct element text from window proxy");
|
||||
|
||||
result = await SpecialPowers.spawn(SpecialPowers.getPrivilegedProps(frame, "browsingContext"),
|
||||
["#span"], selector => {
|
||||
let elem = content.document.querySelector(selector);
|
||||
return elem.textContent;
|
||||
});
|
||||
|
||||
is(result, "Hello there.", "Got correct element text from browsing context");
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -1448,18 +1448,19 @@ class SpecialPowersAPI extends JSWindowActorChild {
|
|||
* passed will be copied via structured clone, as will its return
|
||||
* value.
|
||||
*
|
||||
* @param {FrameLoaderOwner} frame
|
||||
* The frame in which to run the task. This may be any element
|
||||
* which implements the FrameLoaderOwner nterface, including
|
||||
* HTML <iframe> elements and XUL <browser> elements.
|
||||
* @param {BrowsingContext or FrameLoaderOwner or WindowProxy} target
|
||||
* The target in which to run the task. This may be any element
|
||||
* which implements the FrameLoaderOwner interface (including
|
||||
* HTML <iframe> elements and XUL <browser> elements) or a
|
||||
* WindowProxy (either in-process or remote).
|
||||
* @param {Array<any>} args
|
||||
* An array of arguments to pass to the task. All arguments
|
||||
* must be structured clone compatible, and will be cloned
|
||||
* before being passed to the task.
|
||||
* @param {function} task
|
||||
* The function to run in the context of the frame. The
|
||||
* The function to run in the context of the target. The
|
||||
* function will be stringified and re-evaluated in the context
|
||||
* of the frame's content window. It may return any structured
|
||||
* of the target's content window. It may return any structured
|
||||
* clone compatible value, or a Promise which resolves to the
|
||||
* same, which will be returned to the caller.
|
||||
*
|
||||
|
@ -1470,10 +1471,19 @@ class SpecialPowersAPI extends JSWindowActorChild {
|
|||
* in the cases where the task throws an error, though that may
|
||||
* change in the future.
|
||||
*/
|
||||
spawn(frame, args, task) {
|
||||
spawn(target, args, task) {
|
||||
let browsingContext;
|
||||
if (BrowsingContext.isInstance(target)) {
|
||||
browsingContext = target;
|
||||
} else if (Element.isInstance(target)) {
|
||||
browsingContext = target.browsingContext;
|
||||
} else {
|
||||
browsingContext = BrowsingContext.getFromWindow(target);
|
||||
}
|
||||
|
||||
let {caller} = Components.stack;
|
||||
return this.sendQuery("Spawn", {
|
||||
browsingContext: frame.browsingContext,
|
||||
browsingContext,
|
||||
args,
|
||||
task: String(task),
|
||||
caller: {
|
||||
|
|
Загрузка…
Ссылка в новой задаче