Bug 1412681 - Fix NSS dialogs. r=snorp, a=lizzard
authorJim Chen <nchen@mozilla.com>
Mon, 30 Oct 2017 22:48:58 -0400
changeset 435273 784563523bf73f5dc9302c74259159a0f8dc9c21
parent 435272 3060bafa83a95d96b237569037cfe7a9ed5f56e0
child 435274 e237798beee2978c576eefac1a7e2f15c2ec4893
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, lizzard
bugs1412681
milestone57.0
Bug 1412681 - Fix NSS dialogs. r=snorp, a=lizzard The context object for NSS dialogs apparently won't give us a window, so we have to fall back to the active window. MozReview-Commit-ID: 4cHpcE8oggL
mobile/android/components/NSSDialogService.js
mobile/android/modules/Prompt.jsm
--- a/mobile/android/components/NSSDialogService.js
+++ b/mobile/android/components/NSSDialogService.js
@@ -51,19 +51,24 @@ NSSDialogs.prototype = {
       this.bundle =
         Services.strings.createBundle("chrome://browser/locale/pippki.properties");
     }
     let escapedArgList = Array.from(argList, x => this.escapeHTML(x));
     return this.bundle.formatStringFromName(aName, escapedArgList,
                                             escapedArgList.length);
   },
 
-  getPrompt: function(aTitle, aText, aButtons, aWindow) {
+  getPrompt: function(aTitle, aText, aButtons, aCtx) {
+    let win = null;
+    try {
+      win = aCtx.getInterface(Ci.nsIDOMWindow);
+    } catch (e) {
+    }
     return new Prompt({
-      window: aWindow,
+      window: win,
       title: aTitle,
       text: aText,
       buttons: aButtons,
     });
   },
 
   showPrompt: function(aPrompt) {
     let response = null;
@@ -198,20 +203,20 @@ NSSDialogs.prototype = {
     detailLines.push(this.formatString("clientAuthAsk.issuedBy",
                                        [cert.issuerName]));
     detailLines.push(this.formatString("clientAuthAsk.storedOn",
                                        [cert.tokenName]));
 
     return detailLines.join("<br/>");
   },
 
-  viewCertDetails: function(details, window) {
+  viewCertDetails: function(details, ctx) {
     let p = this.getPrompt(this.getString("clientAuthAsk.message3"),
                     "",
-                    [ this.getString("nssdialogs.ok.label") ], window);
+                    [ this.getString("nssdialogs.ok.label") ], ctx);
     p.addLabel({ label: details });
     this.showPrompt(p);
   },
 
   chooseCertificate: function(ctx, hostname, port, organization, issuerOrg,
                               certList, selectedIndex) {
     let rememberSetting =
       Services.prefs.getBoolPref("security.remember_cert_checkbox_default_setting");
--- a/mobile/android/modules/Prompt.jsm
+++ b/mobile/android/modules/Prompt.jsm
@@ -15,31 +15,23 @@ XPCOMUtils.defineLazyModuleGetters(this,
 });
 
 this.EXPORTED_SYMBOLS = ["Prompt", "DoorHanger"];
 
 function log(msg) {
   Services.console.logStringMessage(msg);
 }
 
-function getRootWindow(win) {
-  // Get the root xul window.
-  return win.QueryInterface(Ci.nsIInterfaceRequestor)
-            .getInterface(Ci.nsIDocShell).QueryInterface(Ci.nsIDocShellTreeItem)
-            .rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor)
-            .getInterface(Ci.nsIDOMWindow);
-}
-
 function Prompt(aOptions) {
   this.window = "window" in aOptions ? aOptions.window : null;
 
   this.msg = { async: true };
 
   if (this.window) {
-    let window = getRootWindow(this.window);
+    let window = GeckoViewUtils.getChromeWindow(this.window);
     var tab = window &&
               window.BrowserApp &&
               window.BrowserApp.getTabForWindow(this.window);
     if (tab) {
       this.msg.tabId = tab.id;
     }
   }
 
@@ -253,17 +245,17 @@ Prompt.prototype = {
 var DoorHanger = {
   _getTabId: function(aWindow, aBrowserApp) {
       let tab = aBrowserApp.getTabForWindow(aWindow.top) ||
                 aBrowserApp.selectedTab;
       return tab ? tab.id : -1;
   },
 
   show: function(aWindow, aMessage, aValue, aButtons, aOptions, aCategory) {
-    let chromeWin = getRootWindow(aWindow);
+    let chromeWin = GeckoViewUtils.getChromeWindow(aWindow);
     if (chromeWin.NativeWindow && chromeWin.NativeWindow.doorhanger) {
       // We're dealing with browser.js.
       return chromeWin.NativeWindow.doorhanger.show(
           aMessage, aValue, aButtons, this._getTabId(aWindow, chromeWin.BrowserApp),
           aOptions, aCategory);
     }
 
     // We're dealing with GeckoView (e.g. custom tabs).
@@ -286,17 +278,17 @@ var DoorHanger = {
       category: aCategory,
     }).then(response => {
       // Pass the value of the optional checkbox to the callback
       callbacks[response.callback](response.checked, response.inputs);
     });
   },
 
   hide: function(aWindow, aValue) {
-    let chromeWin = getRootWindow(aWindow);
+    let chromeWin = GeckoViewUtils.getChromeWindow(aWindow);
     if (chromeWin.NativeWindow && chromeWin.NativeWindow.doorhanger) {
       // We're dealing with browser.js.
       return chromeWin.NativeWindow.doorhanger.hide(
           aValue, this._getTabId(aWindow, chromeWin.BrowserApp));
     }
 
     EventDispatcher.for(chromeWin).sendRequest({
       type: "Doorhanger:Remove",