Bug 989197 - Reload error pages showing captive portal UI when the portal is freed. r=MattN draft
authorNihanth Subramanya <nhnt11@gmail.com>
Mon, 21 Nov 2016 08:00:14 +0530
changeset 445729 2ee90f0916abf9dc4ffd86cac6ed0c057c77e62f
parent 445728 d4140978bff4fd271c8fe2f69d756b01bae2814c
child 445730 241919a42172ba81195d7ac907f29fef1693ec35
push id37596
push usernhnt11@gmail.com
push dateWed, 30 Nov 2016 05:50:58 +0000
reviewersMattN
bugs989197
milestone53.0a1
Bug 989197 - Reload error pages showing captive portal UI when the portal is freed. r=MattN MozReview-Commit-ID: FJLTu5S3d6j
browser/base/content/aboutNetError.xhtml
browser/base/content/browser.js
browser/base/content/content.js
--- a/browser/base/content/aboutNetError.xhtml
+++ b/browser/base/content/aboutNetError.xhtml
@@ -378,16 +378,22 @@
                 .addEventListener("click", () => {
           let event = new CustomEvent("AboutNetErrorOpenCaptivePortal", {bubbles:true});
           document.dispatchEvent(event);
         });
 
         setupAdvancedButton(true);
 
         addDomainErrorLinks();
+
+        // 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;
         for (let host of document.querySelectorAll(".hostname")) {
           host.textContent = document.location.hostname;
         }
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2735,29 +2735,46 @@ var BrowserOnClick = {
     mm.addMessageListener("Browser:SiteBlockedError", this);
     mm.addMessageListener("Browser:EnableOnlineMode", this);
     mm.addMessageListener("Browser:SendSSLErrorReport", this);
     mm.addMessageListener("Browser:SetSSLErrorReportAuto", 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() {
     let mm = window.messageManager;
     mm.removeMessageListener("Browser:CertExceptionError", this);
     mm.removeMessageListener("Browser:SiteBlockedError", this);
     mm.removeMessageListener("Browser:EnableOnlineMode", this);
     mm.removeMessageListener("Browser:SendSSLErrorReport", this);
     mm.removeMessageListener("Browser:SetSSLErrorReportAuto", this);
     mm.removeMessageListener("Browser:ResetSSLPreferences", this);
     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;
+    }
   },
 
   handleEvent: function(event) {
     if (!event.isTrusted || // Don't trust synthetic events
         event.button == 2) {
       return;
     }
 
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -259,16 +259,17 @@ function getSerializedSecurityInfo(docSh
               .QueryInterface(Ci.nsISerializable);
 
   return serhelper.serializeToString(securityInfo);
 }
 
 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);
   },
 
   get isAboutNetError() {
@@ -283,16 +284,19 @@ var AboutNetAndCertErrorListener = {
     if (!this.isAboutCertError && !this.isAboutNetError) {
       return;
     }
 
     switch (msg.name) {
       case "CertErrorDetails":
         this.onCertErrorDetails(msg);
         break;
+      case "Browser:CaptivePortalFreed":
+        this.onCaptivePortalFreed(msg);
+        break;
     }
   },
 
   onCertErrorDetails(msg) {
     let div = content.document.getElementById("certificateErrorText");
     div.textContent = msg.data.info;
     let learnMoreLink = content.document.getElementById("learnMoreLink");
     let baseURL = Services.urlFormatter.formatURLPref("app.support.baseURL");
@@ -335,16 +339,20 @@ var AboutNetAndCertErrorListener = {
               .style.display = "block";
           }
         }
         learnMoreLink.href = baseURL  + "time-errors";
         break;
     }
   },
 
+  onCaptivePortalFreed(msg) {
+    content.dispatchEvent(new content.CustomEvent("AboutNetErrorCaptivePortalFreed"));
+  },
+
   handleEvent: function(aEvent) {
     if (!this.isAboutNetError && !this.isAboutCertError) {
       return;
     }
 
     switch (aEvent.type) {
     case "AboutNetErrorLoad":
       this.onPageLoad(aEvent);