diff --git a/browser/base/content/tab-content.js b/browser/base/content/tab-content.js index 77b7cdeaec83..c4b4d96cd370 100644 --- a/browser/base/content/tab-content.js +++ b/browser/base/content/tab-content.js @@ -688,7 +688,76 @@ var DOMFullscreenHandler = { }; DOMFullscreenHandler.init(); +var RefreshBlocker = { + init() { + this._filter = Cc["@mozilla.org/appshell/component/browser-status-filter;1"] + .createInstance(Ci.nsIWebProgress); + this._filter.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_REFRESH); + + let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebProgress); + webProgress.addProgressListener(this._filter, Ci.nsIWebProgress.NOTIFY_REFRESH); + + addMessageListener("RefreshBlocker:Refresh", this); + }, + + uninit() { + let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebProgress); + webProgress.removeProgressListener(this._filter); + + this._filter.removeProgressListener(this); + this._filter = null; + + removeMessageListener("RefreshBlocker:Refresh", this); + }, + + onRefreshAttempted(aWebProgress, aURI, aDelay, aSameURI) { + if (Services.prefs.getBoolPref("accessibility.blockautorefresh")) { + let win = aWebProgress.DOMWindow; + let outerWindowID = win.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils) + .outerWindowID; + + sendAsyncMessage("RefreshBlocker:Blocked", { + URI: aURI.spec, + originCharset: aURI.originCharset, + delay: aDelay, + sameURI: aSameURI, + outerWindowID, + }); + + return false; + } + + return true; + }, + + receiveMessage(message) { + let data = message.data; + + if (message.name == "RefreshBlocker:Refresh") { + let win = Services.wm.getOuterWindowWithId(data.outerWindowID); + let refreshURI = win.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDocShell) + .QueryInterface(Ci.nsIRefreshURI); + + let URI = BrowserUtils.makeURI(data.URI, data.originCharset, null); + + refreshURI.forceRefreshURI(URI, data.delay, true); + } + }, + + QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener2, + Ci.nsIWebProgressListener, + Ci.nsISupportsWeakReference, + Ci.nsISupports]), +}; + +RefreshBlocker.init(); + ExtensionContent.init(this); addEventListener("unload", () => { ExtensionContent.uninit(this); + RefreshBlocker.uninit(); }); diff --git a/browser/base/content/tabbrowser.xml b/browser/base/content/tabbrowser.xml index 2677c1a4a4a7..9e7dea9b25da 100644 --- a/browser/base/content/tabbrowser.xml +++ b/browser/base/content/tabbrowser.xml @@ -4030,7 +4030,7 @@ @@ -4244,6 +4255,7 @@ } messageManager.addMessageListener("DOMWebNotificationClicked", this); messageManager.addMessageListener("DOMServiceWorkerFocusClient", this); + messageManager.addMessageListener("RefreshBlocker:Blocked", this); // To correctly handle keypresses for potential FindAsYouType, while // the tab's find bar is not yet initialized.