Skip to content

Commit ac02a6b

Browse files
authored
browser(firefox): issue Page.ready at the right time (#1462)
This covers new pages and popups. Special handling is needed for window.open() with no url.
1 parent 670ce7a commit ac02a6b

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

browser_patches/firefox/BUILD_NUMBER

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1046
1+
1047

browser_patches/firefox/patches/bootstrap.diff

+36-11
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ index 0000000000000000000000000000000000000000..ba34976ad05e7f5f1a99777f76ac08b1
18381838
+this.SimpleChannel = SimpleChannel;
18391839
diff --git a/juggler/TargetRegistry.js b/juggler/TargetRegistry.js
18401840
new file mode 100644
1841-
index 0000000000000000000000000000000000000000..eab73deee89cc7c8ab0a304f79126264de5c4f8e
1841+
index 0000000000000000000000000000000000000000..e438996fbc04d2eec36436b7e3007649ed088286
18421842
--- /dev/null
18431843
+++ b/juggler/TargetRegistry.js
18441844
@@ -0,0 +1,264 @@
@@ -1881,8 +1881,8 @@ index 0000000000000000000000000000000000000000..eab73deee89cc7c8ab0a304f79126264
18811881
+ this._mainWindow.gBrowser.tabContainer.addEventListener('TabOpen', event => {
18821882
+ const target = this._createTargetForTab(event.target);
18831883
+ // If we come here, content will have juggler script from the start,
1884-
+ // and we should wait for initial navigation, unless the tab was window.open'ed.
1885-
+ target._waitForInitialNavigation = !event.target.linkedBrowser.hasContentOpener;
1884+
+ // and we should wait for initial navigation.
1885+
+ target._waitForInitialNavigation = true;
18861886
+ // For pages created before we attach to them, we don't wait for initial
18871887
+ // navigation (target._waitForInitialNavigation is false by default).
18881888
+ });
@@ -2254,10 +2254,10 @@ index 0000000000000000000000000000000000000000..268fbc361d8053182bb6c27f626e853d
22542254
+
22552255
diff --git a/juggler/content/FrameTree.js b/juggler/content/FrameTree.js
22562256
new file mode 100644
2257-
index 0000000000000000000000000000000000000000..1197aec925e07a52c5802e09e9fd797b48091fd3
2257+
index 0000000000000000000000000000000000000000..13c3cd817b369ed012326b97d03ba6e123b84740
22582258
--- /dev/null
22592259
+++ b/juggler/content/FrameTree.js
2260-
@@ -0,0 +1,370 @@
2260+
@@ -0,0 +1,376 @@
22612261
+"use strict";
22622262
+const Ci = Components.interfaces;
22632263
+const Cr = Components.results;
@@ -2355,6 +2355,14 @@ index 0000000000000000000000000000000000000000..1197aec925e07a52c5802e09e9fd797b
23552355
+ return this._pageReady;
23562356
+ }
23572357
+
2358+
+ forcePageReady() {
2359+
+ if (this._pageReady)
2360+
+ return false;
2361+
+ this._pageReady = true;
2362+
+ this.emit(FrameTree.Events.PageReady);
2363+
+ return true;
2364+
+ }
2365+
+
23582366
+ addScriptToEvaluateOnNewDocument(script) {
23592367
+ this._scriptsToEvaluateOnNewDocument.push(script);
23602368
+ }
@@ -2423,10 +2431,8 @@ index 0000000000000000000000000000000000000000..1197aec925e07a52c5802e09e9fd797b
24232431
+ frame._lastCommittedNavigationId = navigationId;
24242432
+ frame._url = channel.URI.spec;
24252433
+ this.emit(FrameTree.Events.NavigationCommitted, frame);
2426-
+ if (frame === this._mainFrame && !this._pageReady) {
2427-
+ this._pageReady = true;
2428-
+ this.emit(FrameTree.Events.PageReady);
2429-
+ }
2434+
+ if (frame === this._mainFrame)
2435+
+ this.forcePageReady();
24302436
+ } else if (isStop && frame._pendingNavigationId && status) {
24312437
+ // Navigation is aborted.
24322438
+ const navigationId = frame._pendingNavigationId;
@@ -2698,10 +2704,10 @@ index 0000000000000000000000000000000000000000..be70ea364f9534bb3b344f64970366c3
26982704
+
26992705
diff --git a/juggler/content/PageAgent.js b/juggler/content/PageAgent.js
27002706
new file mode 100644
2701-
index 0000000000000000000000000000000000000000..fb207d8b39bee7c1365428a171f80c438097d2bb
2707+
index 0000000000000000000000000000000000000000..ccf881cfee36a1f47fbab880202cc72e7e98e387
27022708
--- /dev/null
27032709
+++ b/juggler/content/PageAgent.js
2704-
@@ -0,0 +1,945 @@
2710+
@@ -0,0 +1,964 @@
27052711
+"use strict";
27062712
+const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
27072713
+const Ci = Components.interfaces;
@@ -2990,6 +2996,7 @@ index 0000000000000000000000000000000000000000..fb207d8b39bee7c1365428a171f80c43
29902996
+ helper.on(this._frameTree, 'pageready', () => this._browserPage.emit('pageReady', {})),
29912997
+ helper.on(this._frameTree, 'workercreated', this._onWorkerCreated.bind(this)),
29922998
+ helper.on(this._frameTree, 'workerdestroyed', this._onWorkerDestroyed.bind(this)),
2999+
+ helper.addObserver(this._onWindowOpen.bind(this), 'webNavigation-createdNavigationTarget-from-js'),
29933000
+ ]);
29943001
+
29953002
+ if (this._frameTree.isPageReady())
@@ -3017,6 +3024,24 @@ index 0000000000000000000000000000000000000000..fb207d8b39bee7c1365428a171f80c43
30173024
+ });
30183025
+ }
30193026
+
3027+
+ _onWindowOpen(subject) {
3028+
+ if (!(subject instanceof Ci.nsIPropertyBag2))
3029+
+ return;
3030+
+ const props = subject.QueryInterface(Ci.nsIPropertyBag2);
3031+
+ const hasUrl = props.hasKey('url');
3032+
+ const createdDocShell = props.getPropertyAsInterface('createdTabDocShell', Ci.nsIDocShell);
3033+
+ if (!hasUrl && createdDocShell === this._docShell && this._frameTree.forcePageReady()) {
3034+
+ this._browserPage.emit('pageEventFired', {
3035+
+ frameId: this._frameTree.mainFrame().id(),
3036+
+ name: 'DOMContentLoaded',
3037+
+ });
3038+
+ this._browserPage.emit('pageEventFired', {
3039+
+ frameId: this._frameTree.mainFrame().id(),
3040+
+ name: 'load',
3041+
+ });
3042+
+ }
3043+
+ }
3044+
+
30203045
+ _setInterceptFileChooserDialog({enabled}) {
30213046
+ this._docShell.fileInputInterceptionEnabled = !!enabled;
30223047
+ }

0 commit comments

Comments
 (0)