Bug 1086958 - Back out change to default browser prompting for Beta 34. r=Gijs, a=lmandel
authorGavin Sharp <gavin@gavinsharp.com>
Tue, 21 Oct 2014 12:19:07 -0700
changeset 225802 d080a93fd9e1
parent 225801 b185e7a13e18
child 225803 d1de09f2d1b0
push id4022
push userryanvm@gmail.com
push date2014-10-24 13:16 +0000
treeherdermozilla-beta@78b9d7be1770 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, lmandel
bugs1086958
milestone34.0
Bug 1086958 - Back out change to default browser prompting for Beta 34. r=Gijs, a=lmandel
browser/components/nsBrowserGlue.js
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -787,17 +787,17 @@ BrowserGlue.prototype = {
         // so we can track whether we are the default.
         Services.telemetry.getHistogramById("BROWSER_IS_USER_DEFAULT")
                           .add(isDefault);
       }
       catch (ex) { /* Don't break the default prompt if telemetry is broken. */ }
 
       if (shouldCheck && !isDefault && !willRecoverSession) {
         Services.tm.mainThread.dispatch(function() {
-          DefaultBrowserCheck.prompt(this.getMostRecentBrowserWindow());
+          DefaultBrowserCheck.prompt(this.getMostRecentBrowserWindow(), shouldCheck);
         }.bind(this), Ci.nsIThread.DISPATCH_NORMAL);
       }
     }
   },
 
   _onQuitRequest: function BG__onQuitRequest(aCancelQuit, aQuitType) {
     // If user has already dismissed quit request, then do nothing
     if ((aCancelQuit instanceof Ci.nsISupportsPRBool) && aCancelQuit.data)
@@ -2122,24 +2122,16 @@ ContentPermissionPrompt.prototype = {
       this._promptPointerLock(request, autoAllow);
       break;
     }
   },
 
 };
 
 let DefaultBrowserCheck = {
-  get OPTIONPOPUP() { return "defaultBrowserNotificationPopup" },
-
-  closePrompt: function(aNode) {
-    if (this._notification) {
-      this._notification.close();
-    }
-  },
-
   setAsDefault: function() {
     let claimAllTypes = true;
 #ifdef XP_WIN
     try {
       // In Windows 8, the UI for selecting default protocol is much
       // nicer than the UI for setting file type associations. So we
       // only show the protocol association screen on Windows 8.
       // Windows 8 is version 6.2.
@@ -2147,104 +2139,40 @@ let DefaultBrowserCheck = {
       claimAllTypes = (parseFloat(version) < 6.2);
     } catch (ex) { }
 #endif
     try {
       ShellService.setDefaultBrowser(claimAllTypes, false);
     } catch (ex) {
       Cu.reportError(ex);
     }
-    this.closePrompt();
   },
 
-  _createPopup: function(win, bundle) {
-    let doc = win.document;
-    let popup = doc.createElement("menupopup");
-    popup.id = this.OPTIONPOPUP;
-
-    let notNowItem = doc.createElement("menuitem");
-    notNowItem.id = "defaultBrowserNotNow";
-    let label = bundle.getString("setDefaultBrowserNotNow.label");
-    notNowItem.setAttribute("label", label);
-    let accesskey = bundle.getString("setDefaultBrowserNotNow.accesskey");
-    notNowItem.setAttribute("accesskey", accesskey);
-    popup.appendChild(notNowItem);
-
-    let neverItem = doc.createElement("menuitem");
-    neverItem.id = "defaultBrowserNever";
-    let label = bundle.getString("setDefaultBrowserNever.label");
-    neverItem.setAttribute("label", label);
-    let accesskey = bundle.getString("setDefaultBrowserNever.accesskey");
-    neverItem.setAttribute("accesskey", accesskey);
-    popup.appendChild(neverItem);
-
-    popup.addEventListener("command", this);
-
-    let popupset = doc.getElementById("mainPopupSet");
-    popupset.appendChild(popup);
-  },
-
-  handleEvent: function(event) {
-    if (event.type == "command") {
-      if (event.target.id == "defaultBrowserNever") {
-        ShellService.shouldCheckDefaultBrowser = false;
-      }
-      this.closePrompt();
-    }
-  },
-
-  prompt: function(win) {
+  prompt: function(win, shouldCheck) {
     let brandBundle = win.document.getElementById("bundle_brand");
     let shellBundle = win.document.getElementById("bundle_shell");
 
     let brandShortName = brandBundle.getString("brandShortName");
     let promptMessage = shellBundle.getFormattedString("setDefaultBrowserMessage2",
                                                        [brandShortName]);
-
-    let confirmMessage = shellBundle.getFormattedString("setDefaultBrowserConfirm.label",
-                                                        [brandShortName]);
-    let confirmKey = shellBundle.getString("setDefaultBrowserConfirm.accesskey");
+    let checkboxLabel = shellBundle.getString("setDefaultBrowserNever.label");
 
-    let optionsMessage = shellBundle.getString("setDefaultBrowserOptions.label");
-    let optionsKey = shellBundle.getString("setDefaultBrowserOptions.accesskey");
-
-    let selectedBrowser = win.gBrowser.selectedBrowser;
-    let notificationBox = win.document.getElementById("high-priority-global-notificationbox");
-
-    this._createPopup(win, shellBundle);
+    let yesLabel = shellBundle.getFormattedString("setDefaultBrowserConfirm.label",
+                                                  [brandShortName]);
+    let notNowLabel = shellBundle.getString("setDefaultBrowserNotNow.label");
 
-    let buttons = [
-      {
-        label: confirmMessage,
-        accessKey: confirmKey,
-        callback: this.setAsDefault.bind(this)
-      },
-      {
-        label: optionsMessage,
-        accessKey: optionsKey,
-        popup: this.OPTIONPOPUP
-      }
-    ];
-
-
-    let iconPixels = win.devicePixelRatio > 1 ? "32" : "16";
-    let iconURL = "chrome://branding/content/icon" + iconPixels + ".png";
-    const priority = notificationBox.PRIORITY_WARNING_HIGH;
-    let callback = this._onNotificationEvent.bind(this);
-    this._notification = notificationBox.appendNotification(promptMessage, "default-browser",
-                                                            iconURL, priority, buttons,
-                                                            callback);
-    this._notification.persistence = -1;
-  },
-
-  _onNotificationEvent: function(eventType) {
-    if (eventType == "removed") {
-      let doc = this._notification.ownerDocument;
-      let popup = doc.getElementById(this.OPTIONPOPUP);
-      popup.removeEventListener("command", this);
-      popup.remove();
-      delete this._notification;
+    let ps = Services.prompt;
+    let dontAskAgain = { value: !shouldCheck };
+    let buttonFlags = (ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_0) +
+                      (ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_1) +
+                      ps.BUTTON_POS_0_DEFAULT;
+    let rv = ps.confirmEx(win, null, promptMessage, buttonFlags,
+                          yesLabel, notNowLabel, null, checkboxLabel, dontAskAgain);
+    if (rv == 0) {
+      this.setAsDefault();
+    } else if (dontAskAgain.value) {
+      ShellService.shouldCheckDefaultBrowser = false;
     }
   },
 };
 
 var components = [BrowserGlue, ContentPermissionPrompt];
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);