From 5cb4464af64bacc275a3d9cdf067611a1446e37d Mon Sep 17 00:00:00 2001 From: Mike Conley Date: Fri, 5 Feb 2016 13:57:48 -0500 Subject: [PATCH] Bug 1055464 - Add RefreshBlocker to tab-content, and a listener in tabbrowser.xml. r=Mossop --HG-- extra : commitid : A2DWArd8dy6 extra : rebase_source : 209045482dab1455821892a7b5301487ccbbc963 extra : amend_source : 6c5fa1da07f7690a030db6d15033435a7b7e375d --- browser/base/content/tab-content.js | 69 +++++++++++++++++++++++++++++ browser/base/content/tabbrowser.xml | 54 +++++++++++++--------- 2 files changed, 102 insertions(+), 21 deletions(-) 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.