bug 866304 DialogUI "modals" cleanup patch. Removes the "modals" portions of DialogUI. Converts the crash reporter prompt to use nsIPromptService.confirmEx instead of DialogUI.importModal. r=mbrubeck
☠☠ backed out by 20aa76d088a9 ☠ ☠
authorTim Abraldes <tabraldes@mozilla.com>
Mon, 05 Aug 2013 23:29:55 -0700
changeset 141535 14434d2b75b9360a37247269a3a7f0f0230ad92c
parent 141534 e0061be20d1e7266027f23f3bcda54f1977ae5ad
child 141536 8d0fa17572ad197cdb293b901fb5ff6b4d22bcd7
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmbrubeck
bugs866304
milestone26.0a1
bug 866304 DialogUI "modals" cleanup patch. Removes the "modals" portions of DialogUI. Converts the crash reporter prompt to use nsIPromptService.confirmEx instead of DialogUI.importModal. r=mbrubeck The crash reporter prompt is the only consumer of DialogUI.importModal and related code. The "modals" concept that DialogUI implements should go away in favor of tab-modal dialogs and tab-agnostic notifications (e.g. flyouts). I don't think that the crash reporter prompt should be a tab modal dialog; I'd prefer to see it become an about: page or perhaps a flyout. Making it a tab-modal prompt was just the easiest thing to do in this set of patches.
browser/metro/base/content/browser-ui.js
browser/metro/locales/jar.mn
--- a/browser/metro/base/content/browser-ui.js
+++ b/browser/metro/base/content/browser-ui.js
@@ -260,26 +260,50 @@ var BrowserUI = {
     let lastCrashID = this.lastCrashID;
     if (!lastCrashID || !lastCrashID.length) {
       return;
     }
     let shouldReport = Services.prefs.getBoolPref("app.crashreporter.autosubmit");
     let didPrompt = Services.prefs.getBoolPref("app.crashreporter.prompted");
 
     if (!shouldReport && !didPrompt) {
-      // We have a crash to submit, we haven't prompted for approval yet,
-      // and the auto-submit pref is false, prompt. The dialog will call
-      // startupCrashCheck again if the user approves.
+      let crashBundle = Services.strings.createBundle("chrome://browser/locale/crashprompt.properties");
+      let title = crashBundle.GetStringFromName("crashprompt.dialog.title");
+      let acceptbutton = crashBundle.GetStringFromName("crashprompt.dialog.acceptbutton");
+      let refusebutton = crashBundle.GetStringFromName("crashprompt.dialog.refusebutton");
+      let bodyText = crashBundle.GetStringFromName("crashprompt.dialog.statement1");
+
+      let buttonPressed =
+            Services.prompt.confirmEx(
+                window,
+                title,
+                bodyText,
+                Ci.nsIPrompt.BUTTON_POS_0 * Ci.nsIPrompt.BUTTON_TITLE_IS_STRING
+              + Ci.nsIPrompt.BUTTON_POS_1 * Ci.nsIPrompt.BUTTON_TITLE_IS_STRING
+              + Ci.nsIPrompt.BUTTON_POS_1_DEFAULT,
+                acceptbutton,
+                refusebutton,
+                null,
+                null,
+                { value: false });
+
       Services.prefs.setBoolPref("app.crashreporter.prompted", true);
-      DialogUI.importModal(document, "chrome://browser/content/prompt/crash.xul");
-      return;
+
+      if (buttonPressed == 0) {
+        Services.prefs.setBoolPref('app.crashreporter.autosubmit', true);
+        BrowserUI.crashReportingPrefChanged(true);
+        shouldReport = true;
+      } else {
+        Services.prefs.setBoolPref('app.crashreporter.autosubmit', false);
+        BrowserUI.crashReportingPrefChanged(false);
+      }
     }
 
     // We've already prompted, return if the user doesn't want to report.
-    if (!shouldReport && didPrompt) {
+    if (!shouldReport) {
       return;
     }
 
     Util.dumpLn("Submitting last crash id:", lastCrashID);
     try {
       this.CrashSubmit.submit(lastCrashID);
     } catch (ex) {
       Util.dumpLn(ex);
@@ -729,21 +753,16 @@ var BrowserUI = {
     }
 
     // Check open popups
     if (DialogUI._popup) {
       DialogUI._hidePopup();
       return;
     }
 
-    // Check open modal elements
-    if (DialogUI.modals.length > 0) {
-      return;
-    }
-
     // Check open panel
     if (PanelUI.isVisible) {
       PanelUI.hide();
       return;
     }
 
     // Check content helper
     if (FindHelperUI.isActive) {
@@ -1310,76 +1329,16 @@ var PanelUI = {
 var DialogUI = {
   _popup: null,
 
   init: function() {
     window.addEventListener("mousedown", this, true);
   },
 
   /*******************************************
-   * Modal popups
-   */
-
-  get modals() {
-    return document.getElementsByClassName("modal-block");
-  },
-
-  importModal: function importModal(aParent, aSrc, aArguments) {
-  // load the dialog with a synchronous XHR
-    let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
-    xhr.open("GET", aSrc, false);
-    xhr.overrideMimeType("text/xml");
-    xhr.send(null);
-    if (!xhr.responseXML)
-      return null;
-
-    let currentNode;
-    let nodeIterator = xhr.responseXML.createNodeIterator(xhr.responseXML, NodeFilter.SHOW_TEXT, null, false);
-    while (!!(currentNode = nodeIterator.nextNode())) {
-      let trimmed = currentNode.nodeValue.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
-      if (!trimmed.length)
-        currentNode.parentNode.removeChild(currentNode);
-    }
-
-    let doc = xhr.responseXML.documentElement;
-
-    let dialog  = null;
-
-    // we need to insert before context-container if we want allow pasting (using
-    //  the context menu) into dialogs
-    let contentMenuContainer = document.getElementById("context-container");
-    let parentNode = contentMenuContainer.parentNode;
-
-    // emit DOMWillOpenModalDialog event
-    let event = document.createEvent("Events");
-    event.initEvent("DOMWillOpenModalDialog", true, false);
-    let dispatcher = aParent || getBrowser();
-    dispatcher.dispatchEvent(event);
-
-    // create a full-screen semi-opaque box as a background or reuse
-    // the existing one.
-    let back = document.getElementById("dialog-modal-block");
-    if (!back) {
-      back = document.createElement("box");
-    } else {
-      while (back.hasChildNodes()) {
-        back.removeChild(back.firstChild);
-      }
-    }
-    back.setAttribute("class", "modal-block");
-    back.setAttribute("id", "dialog-modal-block");
-    dialog = back.appendChild(document.importNode(doc, true));
-    parentNode.insertBefore(back, contentMenuContainer);
-
-    dialog.arguments = aArguments;
-    dialog.parent = aParent;
-    return dialog;
-  },
-
-  /*******************************************
    * Popups
    */
 
   pushPopup: function pushPopup(aPanel, aElements, aParent) {
     this._hidePopup();
     this._popup =  { "panel": aPanel,
                      "elements": (aElements instanceof Array) ? aElements : [aElements] };
     this._dispatchPopupChanged(true, aPanel);
--- a/browser/metro/locales/jar.mn
+++ b/browser/metro/locales/jar.mn
@@ -15,17 +15,16 @@
   locale/browser/config.dtd               (%chrome/config.dtd)
   locale/browser/preferences.dtd          (%chrome/preferences.dtd)
   locale/browser/aboutPanel.dtd           (%chrome/aboutPanel.dtd)
   locale/browser/checkbox.dtd             (%chrome/checkbox.dtd)
   locale/browser/sync.dtd                 (%chrome/sync.dtd)
   locale/browser/sync.properties          (%chrome/sync.properties)
   locale/browser/passwordmgr.properties   (%chrome/passwordmgr.properties)
   locale/browser/phishing.dtd             (%chrome/phishing.dtd)
-  locale/browser/crashprompt.dtd          (%chrome/crashprompt.dtd)
   locale/browser/aboutAddons.dtd          (%chrome/aboutAddons.dtd)
 
 @AB_CD@.jar:
 % locale browser @AB_CD@ %locale/browser/
   locale/browser/bookmarks.json           (bookmarks.json)
 
 #
 # Browser jar resources