Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow RemoteContextHelper to open windows from remote contexts #48159

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// META: title=RemoteContextHelper with defaults
// META: script=/common/dispatcher/dispatcher.js
// META: script=/common/get-host-info.sub.js
// META: script=/common/utils.js
// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js
// META: script=./resources/test-helper.js

'use strict';

promise_test(async t => {
const rcHelper = new RemoteContextHelper();
const main = await rcHelper.addWindow();
const childWindow = await main.addWindow();
await assertSimplestScriptRuns(childWindow);
await assertOriginIsAsExpected(childWindow, location.origin);
});
Original file line number Diff line number Diff line change
Expand Up @@ -320,19 +320,29 @@
url.searchParams.append('pipe', formattedHeaders.join('|'));
}

function windowExecutorCreator({target = '_blank', features} = {}) {
return (url, documentContent) => {
if (url && url.substring(0, 5) == 'data:') {
throw new TypeError('Windows cannot use data: URLs.');
}

function windowExecutorCreator(
{ target = '_blank', features } = {}, remoteContextWrapper) {
let openWindow = (url, target, features, documentContent) => {
const w = window.open(url, target, features);
if (documentContent) {
w.document.open();
w.document.write(documentContent);
w.document.close();
}
};

return (url, documentContent) => {
if (url && url.substring(0, 5) == 'data:') {
throw new TypeError('Windows cannot use data: URLs.');
}

if (remoteContextWrapper) {
return remoteContextWrapper.executeScript(
openWindow, [url, target, features, documentContent]);
} else {
openWindow(url, target, features, documentContent);
}
};
}

function elementExecutorCreator(
Expand Down Expand Up @@ -527,6 +537,23 @@
});
}

/**
* Opens a window from the remote context. @see createContext for
* @param {RemoteContextConfig|object} [extraConfig]
* @param {Object} [options]
* @param {string} [options.target] Passed to `window.open` as the
* 2nd argument
* @param {string} [options.features] Passed to `window.open` as the
* 3rd argument
* @returns {Promise<RemoteContextWrapper>} The remote context.
*/
addWindow(extraConfig, options) {
return this.helper.createContext({
executorCreator: windowExecutorCreator(options, this),
extraConfig,
});
}

/**
* Adds a dedicated worker to the current document.
* @param {string|null} [globalVariable] The name of the global variable to
Expand Down