From 1b39a985694fccefcad4d4200c35360f7cf8c643 Mon Sep 17 00:00:00 2001 From: Michael Kaply Date: Mon, 22 Jul 2019 21:54:56 +0000 Subject: [PATCH] Bug 1558866 - Use a list of chrome URLs to block. r=jaws,Gijs Differential Revision: https://phabricator.services.mozilla.com/D34933 --HG-- extra : moz-landing-system : lando --- .../enterprisepolicies/Policies.jsm | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/browser/components/enterprisepolicies/Policies.jsm b/browser/components/enterprisepolicies/Policies.jsm index 95cf73714f6b..91daa77eba1d 100644 --- a/browser/components/enterprisepolicies/Policies.jsm +++ b/browser/components/enterprisepolicies/Policies.jsm @@ -1599,15 +1599,31 @@ function installAddonFromURL(url, extensionID) { }); } -let gChromeURLSBlocked = false; +let gBlockedChromePages = []; -// If any about page is blocked, we block the loading of all -// chrome:// URLs in the browser window. function blockAboutPage(manager, feature, neededOnContentProcess = false) { + if (!gBlockedChromePages.length) { + addChromeURLBlocker(); + } manager.disallowFeature(feature, neededOnContentProcess); - if (!gChromeURLSBlocked) { - blockAllChromeURLs(); - gChromeURLSBlocked = true; + let splitURL = Services.io + .newChannelFromURI( + Services.io.newURI(feature), + null, + Services.scriptSecurityManager.getSystemPrincipal(), + null, + 0, + Ci.nsIContentPolicy.TYPE_OTHER + ) + .URI.spec.split("/"); + // about:debugging uses index.html for a filename, so we need to rely + // on more than just the filename. + let fileName = + splitURL[splitURL.length - 2] + "/" + splitURL[splitURL.length - 1]; + gBlockedChromePages.push(fileName); + if (feature == "about:config") { + // Hide old page until it is removed + gBlockedChromePages.push("config.xul"); } } @@ -1619,8 +1635,9 @@ let ChromeURLBlockPolicy = { contentType == Ci.nsIContentPolicy.TYPE_DOCUMENT && loadInfo.loadingContext && loadInfo.loadingContext.baseURI == AppConstants.BROWSER_CHROME_URL && - contentLocation.host != "mochitests" && - contentLocation.host != "devtools" + gBlockedChromePages.some(function(fileName) { + return contentLocation.filePath.endsWith(fileName); + }) ) { return Ci.nsIContentPolicy.REJECT_REQUEST; } @@ -1638,7 +1655,7 @@ let ChromeURLBlockPolicy = { }, }; -function blockAllChromeURLs() { +function addChromeURLBlocker() { let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); registrar.registerFactory( ChromeURLBlockPolicy.classID,