Skip to content

Commit 5c51961

Browse files
authored
browser(firefox-stable): cherry pick recent changes from browser_patches/firefox (#6409)
1 parent 14ebcfd commit 5c51961

File tree

7 files changed

+112
-133
lines changed

7 files changed

+112
-133
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1244
2-
Changed: [email protected] Tue 20 Apr 2021 04:48:52 PM PDT
1+
1245
2+
Changed: [email protected] Tue May 4 16:09:13 PDT 2021

browser_patches/firefox-stable/juggler/TargetRegistry.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ class PageTarget {
504504
// Exclude address bar and navigation control from the video.
505505
const rect = this.linkedBrowser().getBoundingClientRect();
506506
const devicePixelRatio = this._window.devicePixelRatio;
507-
const videoSessionId = screencast.startVideoRecording(docShell, file, width, height, scale || 0, devicePixelRatio * rect.top);
507+
const viewport = this._viewportSize || this._browserContext.defaultViewportSize || {width: 0, height: 0};
508+
const videoSessionId = screencast.startVideoRecording(docShell, file, width, height, viewport.width, viewport.height, scale || 0, devicePixelRatio * rect.top);
508509
this._screencastInfo = { videoSessionId, file };
509510
this.emit(PageTarget.Events.ScreencastStarted);
510511
}

browser_patches/firefox-stable/juggler/content/FrameTree.js

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class FrameTree {
2323
this._browsingContextGroup.__jugglerFrameTrees = new Set();
2424
this._browsingContextGroup.__jugglerFrameTrees.add(this);
2525
this._scriptsToEvaluateOnNewDocument = new Map();
26+
this._isolatedWorlds = new Map();
2627

2728
this._webSocketEventService = Cc[
2829
"@mozilla.org/websocketevent/service;1"
@@ -72,6 +73,25 @@ class FrameTree {
7273
return this._runtime;
7374
}
7475

76+
addScriptToEvaluateOnNewDocument(script, worldName) {
77+
const scriptId = helper.generateId();
78+
if (worldName) {
79+
this._isolatedWorlds.set(scriptId, {script, worldName});
80+
for (const frame of this.frames())
81+
frame.createIsolatedWorld(worldName);
82+
} else {
83+
this._scriptsToEvaluateOnNewDocument.set(scriptId, script);
84+
}
85+
return {scriptId};
86+
}
87+
88+
removeScriptToEvaluateOnNewDocument(scriptId) {
89+
if (this._isolatedWorlds.has(scriptId))
90+
this._isolatedWorlds.delete(scriptId);
91+
else
92+
this._scriptsToEvaluateOnNewDocument.delete(scriptId);
93+
}
94+
7595
_frameForWorker(workerDebugger) {
7696
if (workerDebugger.type !== Ci.nsIWorkerDebugger.TYPE_DEDICATED)
7797
return null;
@@ -86,7 +106,6 @@ class FrameTree {
86106
if (!frame)
87107
return;
88108
frame._onGlobalObjectCleared();
89-
this.emit(FrameTree.Events.GlobalObjectCreated, { frame, window });
90109
}
91110

92111
_onWorkerCreated(workerDebugger) {
@@ -129,16 +148,6 @@ class FrameTree {
129148
return true;
130149
}
131150

132-
addScriptToEvaluateOnNewDocument(script) {
133-
const scriptId = helper.generateId();
134-
this._scriptsToEvaluateOnNewDocument.set(scriptId, script);
135-
return scriptId;
136-
}
137-
138-
removeScriptToEvaluateOnNewDocument(scriptId) {
139-
this._scriptsToEvaluateOnNewDocument.delete(scriptId);
140-
}
141-
142151
addBinding(name, script) {
143152
this._bindings.set(name, script);
144153
for (const frame of this.frames())
@@ -291,7 +300,6 @@ FrameTree.Events = {
291300
BindingCalled: 'bindingcalled',
292301
FrameAttached: 'frameattached',
293302
FrameDetached: 'framedetached',
294-
GlobalObjectCreated: 'globalobjectcreated',
295303
WorkerCreated: 'workercreated',
296304
WorkerDestroyed: 'workerdestroyed',
297305
WebSocketCreated: 'websocketcreated',
@@ -330,6 +338,9 @@ class Frame {
330338
this._textInputProcessor = null;
331339
this._executionContext = null;
332340

341+
this._isolatedWorlds = new Map();
342+
this._initialNavigationDone = false;
343+
333344
this._webSocketListenerInnerWindowId = 0;
334345
// WebSocketListener calls frameReceived event before webSocketOpened.
335346
// To avoid this, serialize event reporting.
@@ -415,7 +426,36 @@ class Frame {
415426
};
416427
}
417428

429+
createIsolatedWorld(name) {
430+
const principal = [this.domWindow()]; // extended principal
431+
const sandbox = Cu.Sandbox(principal, {
432+
sandboxPrototype: this.domWindow(),
433+
wantComponents: false,
434+
wantExportHelpers: false,
435+
wantXrays: true,
436+
});
437+
const world = this._runtime.createExecutionContext(this.domWindow(), sandbox, {
438+
frameId: this.id(),
439+
name,
440+
});
441+
this._isolatedWorlds.set(world.id(), world);
442+
return world;
443+
}
444+
445+
unsafeObject(objectId) {
446+
const contexts = [this.executionContext(), ...this._isolatedWorlds.values()];
447+
for (const context of contexts) {
448+
const result = context.unsafeObject(objectId);
449+
if (result)
450+
return result.object;
451+
}
452+
throw new Error('Cannot find object with id = ' + objectId);
453+
}
454+
418455
dispose() {
456+
for (const world of this._isolatedWorlds.values())
457+
this._runtime.destroyExecutionContext(world);
458+
this._isolatedWorlds.clear();
419459
if (this._executionContext)
420460
this._runtime.destroyExecutionContext(this._executionContext);
421461
this._executionContext = null;
@@ -458,6 +498,19 @@ class Frame {
458498
dump(`ERROR: ${e.message}\n${e.stack}\n`);
459499
}
460500
}
501+
502+
for (const world of this._isolatedWorlds.values())
503+
this._runtime.destroyExecutionContext(world);
504+
this._isolatedWorlds.clear();
505+
for (const {script, worldName} of this._frameTree._isolatedWorlds.values()) {
506+
const context = worldName ? this.createIsolatedWorld(worldName) : this.executionContext();
507+
try {
508+
let result = context.evaluateScript(script);
509+
if (result && result.objectId)
510+
context.disposeObject(result.objectId);
511+
} catch (e) {
512+
}
513+
}
461514
}
462515

463516
executionContext() {

0 commit comments

Comments
 (0)