From 74bd1d375d576358f56d92369f10c23baf10213c Mon Sep 17 00:00:00 2001 From: Fedor Date: Tue, 12 Mar 2019 19:35:44 +0300 Subject: [PATCH] Junk captive portal and directory ping --- application/basilisk/app/profile/basilisk.js | 3 - .../basilisk/base/content/aboutNetError.xhtml | 48 +- .../base/content/browser-captivePortal.js | 257 ---- application/basilisk/base/content/browser.js | 24 - application/basilisk/base/content/content.js | 17 - .../basilisk/base/content/global-scripts.inc | 1 - .../basilisk/base/content/newtab/newTab.js | 1 - .../basilisk/base/content/newtab/page.js | 2 - .../basilisk/base/content/newtab/sites.js | 15 +- application/basilisk/base/jar.mn | 1 - .../basilisk/components/nsBrowserGlue.js | 3 - .../basilisk/docs/DirectoryLinksProvider.rst | 278 ---- .../basilisk/installer/package-manifest.in | 3 - .../en-US/chrome/browser/browser.properties | 11 - .../en-US/chrome/overrides/netError.dtd | 7 - .../modules/DirectoryLinksProvider.jsm | 1255 ----------------- application/basilisk/modules/moz.build | 1 - .../basilisk/themes/shared/aboutNetError.css | 19 - .../components/preferences/advanced.xul | 12 - .../chrome/browser/preferences/advanced.dtd | 3 - .../en-US/chrome/overrides/netError.dtd | 7 - docshell/base/nsDocShell.cpp | 8 - dom/ipc/ContentChild.cpp | 20 +- dom/ipc/ContentChild.h | 1 - dom/ipc/ContentParent.cpp | 20 - dom/ipc/ContentParent.h | 1 - dom/ipc/PContent.ipdl | 3 +- media/webrtc/trunk/build/common.gypi | 11 +- .../trunk/peerconnection_client.target.mk | 2 - mobile/android/installer/package-manifest.in | 4 - modules/libpref/init/all.js | 14 - netwerk/base/CaptivePortalService.cpp | 366 ----- netwerk/base/CaptivePortalService.h | 70 - netwerk/base/moz.build | 3 - netwerk/base/nsICaptivePortalService.idl | 59 - netwerk/base/nsIOService.cpp | 102 -- netwerk/base/nsIOService.h | 7 - netwerk/build/nsNetCID.h | 11 - netwerk/build/nsNetModule.cpp | 10 - netwerk/protocol/http/nsHttpChannel.cpp | 8 - testing/profiles/prefs_general.js | 1 - .../CaptivePortalDetectComponents.manifest | 2 - .../components/captivedetect/captivedetect.js | 476 ------- toolkit/components/captivedetect/moz.build | 19 - .../nsICaptivePortalDetector.idl | 53 - .../captivedetect/test/unit/.eslintrc.js | 7 - .../captivedetect/test/unit/head_setprefs.js | 49 - .../captivedetect/test/unit/test_abort.js | 53 - .../test/unit/test_abort_during_user_login.js | 66 - .../test/unit/test_abort_ongoing_request.js | 72 - .../test/unit/test_abort_pending_request.js | 71 - .../test/unit/test_captive_portal_found.js | 67 - .../unit/test_captive_portal_found_303.js | 74 - .../unit/test_captive_portal_not_found.js | 52 - .../unit/test_captive_portal_not_found_404.js | 49 - .../test/unit/test_multiple_requests.js | 83 -- .../test/unit/test_user_cancel.js | 54 - .../captivedetect/test/unit/xpcshell.ini | 15 - toolkit/components/moz.build | 2 - 59 files changed, 6 insertions(+), 3947 deletions(-) delete mode 100644 application/basilisk/base/content/browser-captivePortal.js delete mode 100644 application/basilisk/docs/DirectoryLinksProvider.rst delete mode 100644 application/basilisk/modules/DirectoryLinksProvider.jsm delete mode 100644 netwerk/base/CaptivePortalService.cpp delete mode 100644 netwerk/base/CaptivePortalService.h delete mode 100644 netwerk/base/nsICaptivePortalService.idl delete mode 100644 toolkit/components/captivedetect/CaptivePortalDetectComponents.manifest delete mode 100644 toolkit/components/captivedetect/captivedetect.js delete mode 100644 toolkit/components/captivedetect/moz.build delete mode 100644 toolkit/components/captivedetect/nsICaptivePortalDetector.idl delete mode 100644 toolkit/components/captivedetect/test/unit/.eslintrc.js delete mode 100644 toolkit/components/captivedetect/test/unit/head_setprefs.js delete mode 100644 toolkit/components/captivedetect/test/unit/test_abort.js delete mode 100644 toolkit/components/captivedetect/test/unit/test_abort_during_user_login.js delete mode 100644 toolkit/components/captivedetect/test/unit/test_abort_ongoing_request.js delete mode 100644 toolkit/components/captivedetect/test/unit/test_abort_pending_request.js delete mode 100644 toolkit/components/captivedetect/test/unit/test_captive_portal_found.js delete mode 100644 toolkit/components/captivedetect/test/unit/test_captive_portal_found_303.js delete mode 100644 toolkit/components/captivedetect/test/unit/test_captive_portal_not_found.js delete mode 100644 toolkit/components/captivedetect/test/unit/test_captive_portal_not_found_404.js delete mode 100644 toolkit/components/captivedetect/test/unit/test_multiple_requests.js delete mode 100644 toolkit/components/captivedetect/test/unit/test_user_cancel.js delete mode 100644 toolkit/components/captivedetect/test/unit/xpcshell.ini diff --git a/application/basilisk/app/profile/basilisk.js b/application/basilisk/app/profile/basilisk.js index 24f1c582c..f9afa79f8 100644 --- a/application/basilisk/app/profile/basilisk.js +++ b/application/basilisk/app/profile/basilisk.js @@ -581,9 +581,6 @@ pref("mousewheel.with_win.action", 1); pref("browser.xul.error_pages.enabled", true); pref("browser.xul.error_pages.expert_bad_cert", false); -// Enable captive portal detection. -pref("network.captive-portal-service.enabled", true); - // If true, network link events will change the value of navigator.onLine pref("network.manage-offline-status", true); diff --git a/application/basilisk/base/content/aboutNetError.xhtml b/application/basilisk/base/content/aboutNetError.xhtml index 3296600c8..03f2bb81a 100644 --- a/application/basilisk/base/content/aboutNetError.xhtml +++ b/application/basilisk/base/content/aboutNetError.xhtml @@ -30,8 +30,6 @@ // e - the error code // s - custom CSS class to allow alternate styling/favicons // d - error description - // captive - "true" to indicate we're behind a captive portal. - // Any other value is ignored. // Note that this file uses document.documentURI to get // the URL (with the format from above). This is because @@ -59,10 +57,6 @@ return searchParams.get("d"); } - function isCaptive() { - return searchParams.get("captive") == "true"; - } - function retryThis(buttonEl) { // Note: The application may wish to handle switching off "offline mode" @@ -166,11 +160,6 @@ { var err = getErrorCode(); gIsCertError = (err == "nssBadCert"); - // Only worry about captive portals if this is a cert error. - let showCaptivePortalUI = isCaptive() && gIsCertError; - if (showCaptivePortalUI) { - err = "captivePortal"; - } // if it's an unknown error or there's no title or description // defined, get the generic message @@ -193,10 +182,7 @@ sd.textContent = getDescription(); } } - if (showCaptivePortalUI) { - initPageCaptivePortal(); - return; - } + if (gIsCertError) { initPageCertError(); return; @@ -289,29 +275,6 @@ addDomainErrorLink(); } - function initPageCaptivePortal() - { - document.body.className = "captiveportal"; - document.title = document.getElementById("captivePortalPageTitle").textContent; - - document.getElementById("openPortalLoginPageButton") - .addEventListener("click", () => { - let event = new CustomEvent("AboutNetErrorOpenCaptivePortal", {bubbles:true}); - document.dispatchEvent(event); - }); - - addAutofocus("openPortalLoginPageButton"); - setupAdvancedButton(true); - - addDomainErrorLink(); - - // When the portal is freed, an event is generated by the frame script - // that we can pick up and attempt to reload the original page. - window.addEventListener("AboutNetErrorCaptivePortalFreed", () => { - document.location.reload(); - }); - } - function initPageCertError() { document.body.className = "certerror"; document.title = document.getElementById("certErrorPageTitle").textContent; @@ -434,13 +397,11 @@ -

&generic.title;

-

&captivePortal.title;

&dnsNotFound.title;

&fileNotFound.title;

&fileAccessDenied.title;

@@ -470,7 +431,6 @@
&generic.longDesc;
-
&captivePortal.longDesc;
&dnsNotFound.longDesc;
&fileNotFound.longDesc;
&fileAccessDenied.longDesc;
@@ -529,12 +489,6 @@
-
- - -
- -
diff --git a/application/basilisk/base/content/browser-captivePortal.js b/application/basilisk/base/content/browser-captivePortal.js deleted file mode 100644 index c2e45c4ed..000000000 --- a/application/basilisk/base/content/browser-captivePortal.js +++ /dev/null @@ -1,257 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -XPCOMUtils.defineLazyServiceGetter(this, "cps", - "@mozilla.org/network/captive-portal-service;1", - "nsICaptivePortalService"); - -var CaptivePortalWatcher = { - /** - * This constant is chosen to be large enough for a portal recheck to complete, - * and small enough that the delay in opening a tab isn't too noticeable. - * Please see comments for _delayedCaptivePortalDetected for more details. - */ - PORTAL_RECHECK_DELAY_MS: Preferences.get("captivedetect.portalRecheckDelayMS", 500), - - // This is the value used to identify the captive portal notification. - PORTAL_NOTIFICATION_VALUE: "captive-portal-detected", - - // This holds a weak reference to the captive portal tab so that we - // don't leak it if the user closes it. - _captivePortalTab: null, - - /** - * If a portal is detected when we don't have focus, we first wait for focus - * and then add the tab if, after a recheck, the portal is still active. This - * is set to true while we wait so that in the unlikely event that we receive - * another notification while waiting, we don't do things twice. - */ - _delayedCaptivePortalDetectedInProgress: false, - - // In the situation above, this is set to true while we wait for the recheck. - // This flag exists so that tests can appropriately simulate a recheck. - _waitingForRecheck: false, - - get _captivePortalNotification() { - let nb = document.getElementById("high-priority-global-notificationbox"); - return nb.getNotificationWithValue(this.PORTAL_NOTIFICATION_VALUE); - }, - - get canonicalURL() { - return Services.prefs.getCharPref("captivedetect.canonicalURL"); - }, - - get _browserBundle() { - delete this._browserBundle; - return this._browserBundle = - Services.strings.createBundle("chrome://browser/locale/browser.properties"); - }, - - init() { - Services.obs.addObserver(this, "captive-portal-login", false); - Services.obs.addObserver(this, "captive-portal-login-abort", false); - Services.obs.addObserver(this, "captive-portal-login-success", false); - - if (cps.state == cps.LOCKED_PORTAL) { - // A captive portal has already been detected. - this._captivePortalDetected(); - - // Automatically open a captive portal tab if there's no other browser window. - let windows = Services.wm.getEnumerator("navigator:browser"); - if (windows.getNext() == window && !windows.hasMoreElements()) { - this.ensureCaptivePortalTab(); - } - } - - cps.recheckCaptivePortal(); - }, - - uninit() { - Services.obs.removeObserver(this, "captive-portal-login"); - Services.obs.removeObserver(this, "captive-portal-login-abort"); - Services.obs.removeObserver(this, "captive-portal-login-success"); - - - if (this._delayedCaptivePortalDetectedInProgress) { - Services.obs.removeObserver(this, "xul-window-visible"); - } - }, - - observe(aSubject, aTopic, aData) { - switch (aTopic) { - case "captive-portal-login": - this._captivePortalDetected(); - break; - case "captive-portal-login-abort": - case "captive-portal-login-success": - this._captivePortalGone(); - break; - case "xul-window-visible": - this._delayedCaptivePortalDetected(); - break; - } - }, - - _captivePortalDetected() { - if (this._delayedCaptivePortalDetectedInProgress) { - return; - } - - let win = RecentWindow.getMostRecentBrowserWindow(); - // If no browser window has focus, open and show the tab when we regain focus. - // This is so that if a different application was focused, when the user - // (re-)focuses a browser window, we open the tab immediately in that window - // so they can log in before continuing to browse. - if (win != Services.ww.activeWindow) { - this._delayedCaptivePortalDetectedInProgress = true; - Services.obs.addObserver(this, "xul-window-visible", false); - } - - this._showNotification(); - }, - - /** - * Called after we regain focus if we detect a portal while a browser window - * doesn't have focus. Triggers a portal recheck to reaffirm state, and adds - * the tab if needed after a short delay to allow the recheck to complete. - */ - _delayedCaptivePortalDetected() { - if (!this._delayedCaptivePortalDetectedInProgress) { - return; - } - - let win = RecentWindow.getMostRecentBrowserWindow(); - if (win != Services.ww.activeWindow) { - // The window that got focused was not a browser window. - return; - } - Services.obs.removeObserver(this, "xul-window-visible"); - this._delayedCaptivePortalDetectedInProgress = false; - - if (win != window) { - // Some other browser window got focus, we don't have to do anything. - return; - } - // Trigger a portal recheck. The user may have logged into the portal via - // another client, or changed networks. - cps.recheckCaptivePortal(); - this._waitingForRecheck = true; - let requestTime = Date.now(); - - let self = this; - Services.obs.addObserver(function observer() { - let time = Date.now() - requestTime; - Services.obs.removeObserver(observer, "captive-portal-check-complete"); - self._waitingForRecheck = false; - if (cps.state != cps.LOCKED_PORTAL) { - // We're free of the portal! - return; - } - - if (time <= self.PORTAL_RECHECK_DELAY_MS) { - // The amount of time elapsed since we requested a recheck (i.e. since - // the browser window was focused) was small enough that we can add and - // focus a tab with the login page with no noticeable delay. - self.ensureCaptivePortalTab(); - } - }, "captive-portal-check-complete", false); - }, - - _captivePortalGone() { - if (this._delayedCaptivePortalDetectedInProgress) { - Services.obs.removeObserver(this, "xul-window-visible"); - this._delayedCaptivePortalDetectedInProgress = false; - } - - this._removeNotification(); - }, - - handleEvent(aEvent) { - if (aEvent.type != "TabSelect" || !this._captivePortalTab || !this._captivePortalNotification) { - return; - } - - let tab = this._captivePortalTab.get(); - let n = this._captivePortalNotification; - if (!tab || !n) { - return; - } - - let doc = tab.ownerDocument; - let button = n.querySelector("button.notification-button"); - if (doc.defaultView.gBrowser.selectedTab == tab) { - button.style.visibility = "hidden"; - } else { - button.style.visibility = "visible"; - } - }, - - _showNotification() { - let buttons = [ - { - label: this._browserBundle.GetStringFromName("captivePortal.showLoginPage"), - callback: () => { - this.ensureCaptivePortalTab(); - - // Returning true prevents the notification from closing. - return true; - }, - isDefault: true, - }, - ]; - - let message = this._browserBundle.GetStringFromName("captivePortal.infoMessage2"); - - let closeHandler = (aEventName) => { - if (aEventName != "removed") { - return; - } - gBrowser.tabContainer.removeEventListener("TabSelect", this); - }; - - let nb = document.getElementById("high-priority-global-notificationbox"); - nb.appendNotification(message, this.PORTAL_NOTIFICATION_VALUE, "", - nb.PRIORITY_INFO_MEDIUM, buttons, closeHandler); - - gBrowser.tabContainer.addEventListener("TabSelect", this); - }, - - _removeNotification() { - let n = this._captivePortalNotification; - if (!n || !n.parentNode) { - return; - } - n.close(); - }, - - ensureCaptivePortalTab() { - let tab; - if (this._captivePortalTab) { - tab = this._captivePortalTab.get(); - } - - // If the tab is gone or going, we need to open a new one. - if (!tab || tab.closing || !tab.parentNode) { - tab = gBrowser.addTab(this.canonicalURL, { ownerTab: gBrowser.selectedTab }); - this._captivePortalTab = Cu.getWeakReference(tab); - } - - gBrowser.selectedTab = tab; - - let canonicalURI = makeURI(this.canonicalURL); - - // When we are no longer captive, close the tab if it's at the canonical URL. - let tabCloser = () => { - Services.obs.removeObserver(tabCloser, "captive-portal-login-abort"); - Services.obs.removeObserver(tabCloser, "captive-portal-login-success"); - if (!tab || tab.closing || !tab.parentNode || !tab.linkedBrowser || - !tab.linkedBrowser.currentURI.equalsExceptRef(canonicalURI)) { - return; - } - gBrowser.removeTab(tab); - } - Services.obs.addObserver(tabCloser, "captive-portal-login-abort", false); - Services.obs.addObserver(tabCloser, "captive-portal-login-success", false); - }, -}; diff --git a/application/basilisk/base/content/browser.js b/application/basilisk/base/content/browser.js index 336670fa0..45ff9bf0c 100644 --- a/application/basilisk/base/content/browser.js +++ b/application/basilisk/base/content/browser.js @@ -974,7 +974,6 @@ var gBrowserInit = { AboutPrivateBrowsingListener.init(); TrackingProtection.init(); RefreshBlocker.init(); - CaptivePortalWatcher.init(); let mm = window.getGroupMessageManager("browsers"); mm.loadFrameScript("chrome://browser/content/tab-content.js", true); @@ -1510,8 +1509,6 @@ var gBrowserInit = { RefreshBlocker.uninit(); - CaptivePortalWatcher.uninit(); - gMenuButtonUpdateBadge.uninit(); gMenuButtonBadgeManager.uninit(); @@ -2743,16 +2740,12 @@ var BrowserOnClick = { init: function () { let mm = window.messageManager; mm.addMessageListener("Browser:CertExceptionError", this); - mm.addMessageListener("Browser:OpenCaptivePortalPage", this); mm.addMessageListener("Browser:SiteBlockedError", this); mm.addMessageListener("Browser:EnableOnlineMode", this); mm.addMessageListener("Browser:ResetSSLPreferences", this); mm.addMessageListener("Browser:SSLErrorReportTelemetry", this); mm.addMessageListener("Browser:OverrideWeakCrypto", this); mm.addMessageListener("Browser:SSLErrorGoBack", this); - - Services.obs.addObserver(this, "captive-portal-login-abort", false); - Services.obs.addObserver(this, "captive-portal-login-success", false); }, uninit: function () { @@ -2764,20 +2757,6 @@ var BrowserOnClick = { mm.removeMessageListener("Browser:SSLErrorReportTelemetry", this); mm.removeMessageListener("Browser:OverrideWeakCrypto", this); mm.removeMessageListener("Browser:SSLErrorGoBack", this); - - Services.obs.removeObserver(this, "captive-portal-login-abort"); - Services.obs.removeObserver(this, "captive-portal-login-success"); - }, - - observe: function(aSubject, aTopic, aData) { - switch (aTopic) { - case "captive-portal-login-abort": - case "captive-portal-login-success": - // Broadcast when a captive portal is freed so that error pages - // can refresh themselves. - window.messageManager.broadcastAsyncMessage("Browser:CaptivePortalFreed"); - break; - } }, receiveMessage: function (msg) { @@ -2787,9 +2766,6 @@ var BrowserOnClick = { msg.data.isTopFrame, msg.data.location, msg.data.securityInfoAsString); break; - case "Browser:OpenCaptivePortalPage": - CaptivePortalWatcher.ensureCaptivePortalTab(); - break; case "Browser:SiteBlockedError": this.onAboutBlocked(msg.data.elementId, msg.data.reason, msg.data.isTopFrame, msg.data.location); diff --git a/application/basilisk/base/content/content.js b/application/basilisk/base/content/content.js index 5accbdf7b..55a97f133 100644 --- a/application/basilisk/base/content/content.js +++ b/application/basilisk/base/content/content.js @@ -264,9 +264,7 @@ function getSerializedSecurityInfo(docShell) { var AboutNetAndCertErrorListener = { init: function(chromeGlobal) { addMessageListener("CertErrorDetails", this); - addMessageListener("Browser:CaptivePortalFreed", this); chromeGlobal.addEventListener('AboutNetErrorLoad', this, false, true); - chromeGlobal.addEventListener('AboutNetErrorOpenCaptivePortal', this, false, true); chromeGlobal.addEventListener('AboutNetErrorSetAutomatic', this, false, true); chromeGlobal.addEventListener('AboutNetErrorOverride', this, false, true); chromeGlobal.addEventListener('AboutNetErrorResetPreferences', this, false, true); @@ -289,9 +287,6 @@ var AboutNetAndCertErrorListener = { case "CertErrorDetails": this.onCertErrorDetails(msg); break; - case "Browser:CaptivePortalFreed": - this.onCaptivePortalFreed(msg); - break; } }, @@ -338,10 +333,6 @@ var AboutNetAndCertErrorListener = { } }, - onCaptivePortalFreed(msg) { - content.dispatchEvent(new content.CustomEvent("AboutNetErrorCaptivePortalFreed")); - }, - handleEvent: function(aEvent) { if (!this.isAboutNetError && !this.isAboutCertError) { return; @@ -351,9 +342,6 @@ var AboutNetAndCertErrorListener = { case "AboutNetErrorLoad": this.onPageLoad(aEvent); break; - case "AboutNetErrorOpenCaptivePortal": - this.openCaptivePortalPage(aEvent); - break; case "AboutNetErrorSetAutomatic": this.onSetAutomatic(aEvent); break; @@ -384,11 +372,6 @@ var AboutNetAndCertErrorListener = { } }, - openCaptivePortalPage: function(evt) { - sendAsyncMessage("Browser:OpenCaptivePortalPage"); - }, - - onResetPreferences: function(evt) { sendAsyncMessage("Browser:ResetSSLPreferences"); }, diff --git a/application/basilisk/base/content/global-scripts.inc b/application/basilisk/base/content/global-scripts.inc index eef21e15e..7d0ef7995 100644 --- a/application/basilisk/base/content/global-scripts.inc +++ b/application/basilisk/base/content/global-scripts.inc @@ -11,7 +11,6 @@