2020-06-03 02:51:13 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
|
|
|
|
const {FrameTree} = ChromeUtils.import('chrome://juggler/content/content/FrameTree.js');
|
|
|
|
const {SimpleChannel} = ChromeUtils.import('chrome://juggler/content/SimpleChannel.js');
|
|
|
|
const {PageAgent} = ChromeUtils.import('chrome://juggler/content/content/PageAgent.js');
|
|
|
|
|
2023-01-23 22:29:48 +03:00
|
|
|
const browsingContextToAgents = new Map();
|
2020-06-03 02:51:13 +03:00
|
|
|
const helper = new Helper();
|
2023-01-23 22:29:48 +03:00
|
|
|
|
|
|
|
function initialize(browsingContext, docShell, actor) {
|
|
|
|
if (browsingContext.parent) {
|
|
|
|
// For child frames, return agents from the main frame.
|
|
|
|
return browsingContextToAgents.get(browsingContext.top);
|
|
|
|
}
|
|
|
|
|
|
|
|
let data = browsingContextToAgents.get(browsingContext);
|
|
|
|
if (data) {
|
|
|
|
// Rebind from one main frame actor to another one.
|
|
|
|
data.channel.bindToActor(actor);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = { channel: undefined, pageAgent: undefined, frameTree: undefined, failedToOverrideTimezone: false };
|
|
|
|
browsingContextToAgents.set(browsingContext, data);
|
|
|
|
|
|
|
|
const applySetting = {
|
|
|
|
geolocation: (geolocation) => {
|
|
|
|
if (geolocation) {
|
|
|
|
docShell.setGeolocationOverride({
|
|
|
|
coords: {
|
|
|
|
latitude: geolocation.latitude,
|
|
|
|
longitude: geolocation.longitude,
|
|
|
|
accuracy: geolocation.accuracy,
|
|
|
|
altitude: NaN,
|
|
|
|
altitudeAccuracy: NaN,
|
|
|
|
heading: NaN,
|
|
|
|
speed: NaN,
|
|
|
|
},
|
|
|
|
address: null,
|
|
|
|
timestamp: Date.now()
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
docShell.setGeolocationOverride(null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onlineOverride: (onlineOverride) => {
|
|
|
|
if (!onlineOverride) {
|
|
|
|
docShell.onlineOverride = Ci.nsIDocShell.ONLINE_OVERRIDE_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
docShell.onlineOverride = onlineOverride === 'online' ?
|
|
|
|
Ci.nsIDocShell.ONLINE_OVERRIDE_ONLINE : Ci.nsIDocShell.ONLINE_OVERRIDE_OFFLINE;
|
|
|
|
},
|
|
|
|
|
|
|
|
bypassCSP: (bypassCSP) => {
|
|
|
|
docShell.bypassCSPEnabled = bypassCSP;
|
|
|
|
},
|
|
|
|
|
|
|
|
timezoneId: (timezoneId) => {
|
|
|
|
data.failedToOverrideTimezone = !docShell.overrideTimezone(timezoneId);
|
|
|
|
},
|
|
|
|
|
|
|
|
locale: (locale) => {
|
|
|
|
docShell.languageOverride = locale;
|
|
|
|
},
|
|
|
|
|
|
|
|
scrollbarsHidden: (hidden) => {
|
|
|
|
data.frameTree.setScrollbarsHidden(hidden);
|
|
|
|
},
|
|
|
|
|
|
|
|
javaScriptDisabled: (javaScriptDisabled) => {
|
|
|
|
data.frameTree.setJavaScriptDisabled(javaScriptDisabled);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const contextCrossProcessCookie = Services.cpmm.sharedData.get('juggler:context-cookie-' + browsingContext.originAttributes.userContextId) || { initScripts: [], bindings: [], settings: {} };
|
|
|
|
const pageCrossProcessCookie = Services.cpmm.sharedData.get('juggler:page-cookie-' + browsingContext.browserId) || { initScripts: [], bindings: [], interceptFileChooserDialog: false };
|
|
|
|
|
2020-06-03 02:51:13 +03:00
|
|
|
// Enforce focused state for all top level documents.
|
|
|
|
docShell.overrideHasFocus = true;
|
2020-11-06 04:53:22 +03:00
|
|
|
docShell.forceActiveState = true;
|
2023-01-23 22:29:48 +03:00
|
|
|
docShell.disallowBFCache = true;
|
|
|
|
data.frameTree = new FrameTree(docShell);
|
|
|
|
for (const [name, value] of Object.entries(contextCrossProcessCookie.settings)) {
|
2020-06-03 02:51:13 +03:00
|
|
|
if (value !== undefined)
|
|
|
|
applySetting[name](value);
|
|
|
|
}
|
2023-01-23 22:29:48 +03:00
|
|
|
for (const { worldName, name, script } of [...contextCrossProcessCookie.bindings, ...pageCrossProcessCookie.bindings])
|
|
|
|
data.frameTree.addBinding(worldName, name, script);
|
|
|
|
data.frameTree.setInitScripts([...contextCrossProcessCookie.initScripts, ...pageCrossProcessCookie.initScripts]);
|
|
|
|
data.channel = SimpleChannel.createForActor(actor);
|
|
|
|
data.pageAgent = new PageAgent(data.channel, data.frameTree);
|
|
|
|
docShell.fileInputInterceptionEnabled = !!pageCrossProcessCookie.interceptFileChooserDialog;
|
|
|
|
|
|
|
|
data.channel.register('', {
|
2022-02-15 07:32:12 +03:00
|
|
|
setInitScripts(scripts) {
|
2023-01-23 22:29:48 +03:00
|
|
|
data.frameTree.setInitScripts(scripts);
|
2020-06-03 02:51:13 +03:00
|
|
|
},
|
|
|
|
|
2021-05-11 19:27:39 +03:00
|
|
|
addBinding({worldName, name, script}) {
|
2023-01-23 22:29:48 +03:00
|
|
|
data.frameTree.addBinding(worldName, name, script);
|
2020-06-03 02:51:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
applyContextSetting({name, value}) {
|
|
|
|
applySetting[name](value);
|
|
|
|
},
|
|
|
|
|
2023-01-23 22:29:48 +03:00
|
|
|
setInterceptFileChooserDialog(enabled) {
|
|
|
|
docShell.fileInputInterceptionEnabled = !!enabled;
|
|
|
|
},
|
|
|
|
|
2020-06-03 02:51:13 +03:00
|
|
|
ensurePermissions() {
|
|
|
|
// noop, just a rountrip.
|
|
|
|
},
|
|
|
|
|
|
|
|
hasFailedToOverrideTimezone() {
|
2023-01-23 22:29:48 +03:00
|
|
|
return data.failedToOverrideTimezone;
|
2020-06-03 02:51:13 +03:00
|
|
|
},
|
|
|
|
|
2021-03-03 05:52:19 +03:00
|
|
|
async awaitViewportDimensions({width, height, deviceSizeIsPageSize}) {
|
|
|
|
docShell.deviceSizeIsPageSize = deviceSizeIsPageSize;
|
2020-06-03 02:51:13 +03:00
|
|
|
const win = docShell.domWindow;
|
|
|
|
if (win.innerWidth === width && win.innerHeight === height)
|
|
|
|
return;
|
|
|
|
await new Promise(resolve => {
|
|
|
|
const listener = helper.addEventListener(win, 'resize', () => {
|
|
|
|
if (win.innerWidth === width && win.innerHeight === height) {
|
|
|
|
helper.removeListeners([listener]);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
dispose() {
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-01-23 22:29:48 +03:00
|
|
|
return data;
|
2020-06-03 02:51:13 +03:00
|
|
|
}
|
|
|
|
|
2023-01-23 22:29:48 +03:00
|
|
|
var EXPORTED_SYMBOLS = ['initialize'];
|
|
|
|
this.initialize = initialize;
|