Commit b17cb9e0 authored by Kashav Madan's avatar Kashav Madan
Browse files

Bug 1586050 - Don't blow away progress listeners when switching between local...

Bug 1586050 - Don't blow away progress listeners when switching between local and remote processes, r=kmag

Whenever we do a process switch, the <browser> gets a new WebProgress instance.
When that happens, we currently handle transferring listeners from one
RemoteWebProgress instance to another, but not from a local to remote, or vice
versa. This patch changes that by tracking listeners added to the <browser> and
manually re-adding them after a process switch occurs.

Differential Revision: https://phabricator.services.mozilla.com/D48233

--HG--
extra : moz-landing-system : lando
parent 53c2adf4
......@@ -80,6 +80,10 @@
this.mIconURL = null;
this.lastURI = null;
// Track progress listeners added to this <browser>. These need to persist
// between calls to destroy().
this.progressListeners = [];
this.addEventListener(
"keypress",
event => {
......@@ -1059,11 +1063,40 @@
if (!aNotifyMask) {
aNotifyMask = Ci.nsIWebProgress.NOTIFY_ALL;
}
this.progressListeners.push({
weakListener: Cu.getWeakReference(aListener),
mask: aNotifyMask,
});
this.webProgress.addProgressListener(aListener, aNotifyMask);
}
removeProgressListener(aListener) {
this.webProgress.removeProgressListener(aListener);
// Remove aListener from our progress listener list, and clear out dead
// weak references while we're at it.
this.progressListeners = this.progressListeners.filter(
({ weakListener }) =>
weakListener.get() && weakListener.get() !== aListener
);
}
/**
* Move the previously-tracked web progress listeners to this <browser>'s
* current WebProgress.
*/
restoreProgressListeners() {
let listeners = this.progressListeners;
this.progressListeners = [];
for (let { weakListener, mask } of listeners) {
let listener = weakListener.get();
if (listener) {
this.addProgressListener(listener, mask);
}
}
}
onPageHide(aEvent) {
......@@ -1268,6 +1301,13 @@
this._remoteWebProgress = this._remoteWebProgressManager.topLevelWebProgress;
if (!oldManager) {
// If we didn't have a manager, then we're transitioning from local to
// remote. Add all listeners from the previous <browser> to the new
// RemoteWebProgress.
this.restoreProgressListeners();
}
this.messageManager.loadFrameScript(
"chrome://global/content/browser-child.js",
true
......@@ -1332,10 +1372,12 @@
}
if (!this.isRemoteBrowser) {
// If we've transitioned from remote to non-remote, we'll give up trying to
// keep the web progress listeners persisted during the transition.
delete this._remoteWebProgressManager;
delete this._remoteWebProgress;
// If we've transitioned from remote to non-remote, we no longer need
// our RemoteWebProgress or its associated manager, but we'll need to
// add the progress listeners to the new non-remote WebProgress.
this._remoteWebProgressManager = null;
this._remoteWebProgress = null;
this.restoreProgressListeners();
this.addEventListener("pagehide", this.onPageHide, true);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment