Bug 526555: ProfileManager does not delete profiles [r=mark.finkle]
authorFabrice Desré <fabrice.desre@gmail.com>
Fri, 13 Nov 2009 00:09:38 -0500
changeset 65791 53c78900130d06eaee3dfa5620013f8f81ec18e5
parent 65790 62802ec0300e2926ff412a8a8c0869e164c09c41
child 65792 891669bec2344ace481c11d693b1379619d3e3cc
push idunknown
push userunknown
push dateunknown
reviewersmark.finkle
bugs526555
Bug 526555: ProfileManager does not delete profiles [r=mark.finkle]
mobile/chrome/content/prompt/select.xul
mobile/components/promptService.js
--- a/mobile/chrome/content/prompt/select.xul
+++ b/mobile/chrome/content/prompt/select.xul
@@ -5,21 +5,21 @@
       onload="document.getElementById('prompt-select-list').focus()"
       onclose="this.PromptHelper.onCloseSelect(this)"
       script="chrome://browser/content/prompt/prompt.js">
   <keyset>
     <key keycode="VK_RETURN" command="cmd_ok"/>
     <key keycode="VK_ESCAPE" command="cmd_cancel"/>
   </keyset>
   <commandset>
-    <command id="cmd_ok" oncommand="document.getElementById('prompt-alert-dialog').PromptHelper.closeSelect(true)"/>
-    <command id="cmd_cancel" oncommand="document.getElementById('prompt-alert-dialog').PromptHelper.closeSelect(false)"/>
+    <command id="cmd_ok" oncommand="document.getElementById('prompt-select-dialog').PromptHelper.closeSelect(true)"/>
+    <command id="cmd_cancel" oncommand="document.getElementById('prompt-select-dialog').PromptHelper.closeSelect(false)"/>
   </commandset>
   <label id="prompt-select-title"/>
   <scrollbox orient="vertical" class="prompt-message">
     <description id="prompt-select-message"/>
   </scrollbox>
   <menulist id="prompt-select-list" class="button-dark"/>
   <hbox pack="center" id="prompt-prompt-button-box" class="prompt-buttons">
-    <button class="button-dark" label="&ok.label;" command="cmd_ok;"/>
+    <button class="button-dark" label="&ok.label;" command="cmd_ok"/>
     <button class="button-dark" label="&cancel.label;" command="cmd_cancel"/>
   </hbox>
 </dialog>
--- a/mobile/components/promptService.js
+++ b/mobile/components/promptService.js
@@ -41,22 +41,24 @@ function promptService() {
   let bundleService = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService);
   this._bundle = bundleService.createBundle("chrome://global/locale/commonDialogs.properties");
 }
 
 promptService.prototype = {
   classDescription: "Mobile Prompt Service",
   contractID: "@mozilla.org/embedcomp/prompt-service;1",
   classID: Components.ID("{9a61149b-2276-4a0a-b79c-be994ad106cf}"),
+  
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptService, Ci.nsIPromptService2]),
  
   // helper function do get the current document
   getDocument: function() {
     let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
-    return wm.getMostRecentWindow("navigator:browser").document;
+    let win = wm.getMostRecentWindow("navigator:browser");
+    return win ? win.document : null;
   },
  
   // add a width style to prevent a element to grow larger 
   // than the screen width
   sizeElement: function(id, percent) {
     let elem = this.getDocument().getElementById(id);
     let screenW = this.getDocument().getElementById("main-window").getBoundingClientRect().width;
     elem.style.width = screenW * percent / 100 + "px"
@@ -75,68 +77,93 @@ promptService.prototype = {
                  parseInt(style.marginTop) +
                  parseInt(style.marginBottom);
 
     if (height > maxHeight)
       height = maxHeight;
     elem.parentNode.style.height = height + "px";
   },
   
-  openDialog: function(parent, src, params) {
+  openDialog: function(aParent, aSrc, aParams) {
     let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
     let browser = wm.getMostRecentWindow("navigator:browser");
-    return browser.importDialog(parent, src, params);
+    return browser.importDialog(aParent, aSrc, aParams);
+  },
+  
+  _getFallbackService: function() {
+    return Components.classesByID["{a2112d6a-0e28-421f-b46a-25c0B308cbd0}"]
+                     .getService(Ci.nsIPromptService);
   },
   
   alert: function(aParent, aTitle, aText) {
+    let doc = this.getDocument();
+    if (!doc) {
+      this._getFallbackService().alert(aParent, aTitle, aText);
+      return;
+    }
+    
     let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/alert.xul", null);
-    let doc = this.getDocument();
     doc.getElementById("prompt-alert-title").value = aTitle;
     doc.getElementById("prompt-alert-message").appendChild(doc.createTextNode(aText));
     this.sizeElement("prompt-alert-message", 80);
     this.sizeScrollableMsg("prompt-alert-message", 25);
     
     dialog.waitForClose();
   },
   
   alertCheck: function(aParent, aTitle, aText, aCheckMsg, aCheckState) {
+    let doc = this.getDocument();
+    if (!doc) {
+      this._getFallbackService().alertCheck(aParent, aTitle, aText, aCheckMsg, aCheckState);
+      return;
+    }
+    
     let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/alert.xul", aCheckState);
-    let doc = this.getDocument();
     doc.getElementById("prompt-alert-title").value = aTitle;
     doc.getElementById("prompt-alert-message").appendChild(doc.createTextNode(aText));
     this.sizeElement("prompt-alert-message", 80);
     this.sizeScrollableMsg("prompt-alert-message", 25);
     
     doc.getElementById("prompt-alert-checkbox").checked = aCheckState.value;
     this.setLabelForNode(doc.getElementById("prompt-alert-checkbox-msg"), aCheckMsg);
     this.sizeElement("prompt-alert-checkbox-msg", 50);
     doc.getElementById("prompt-alert-checkbox-box").removeAttribute("collapsed");
     
     dialog.waitForClose();
   },
   
   confirm: function(aParent, aTitle, aText) {
+    let doc = this.getDocument();
+    if (!doc) {
+      return this._getFallbackService().confirm(aParent, aTitle, aText);
+    }
+
     var params = new Object();
     params.result = false;
-    let doc = this.getDocument();
+
     let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/confirm.xul", params);
     doc.getElementById("prompt-confirm-title").value = aTitle;
     doc.getElementById("prompt-confirm-message").appendChild(doc.createTextNode(aText));
     this.sizeElement("prompt-confirm-message", 80);
     this.sizeScrollableMsg("prompt-confirm-message", 25);
     
     dialog.waitForClose();
     return params.result;
   },
   
   confirmCheck: function(aParent, aTitle, aText, aCheckMsg, aCheckState) {
+    let doc = this.getDocument();
+    if (!doc) {
+      return this._getFallbackService().confirmCheck(aParent, aTitle, aText, aCheckMsg, aCheckState);
+    }
+
     var params = new Object();
     params.result = false;
     params.checkbox = aCheckState;
-    let doc = this.getDocument();
+
     let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/confirm.xul", params);
     doc.getElementById("prompt-confirm-title").value = aTitle;
     doc.getElementById("prompt-confirm-message").appendChild(doc.createTextNode(aText));
     this.sizeElement("prompt-confirm-message", 80);
     this.sizeScrollableMsg("prompt-confirm-message", 25);
 
     doc.getElementById("prompt-confirm-checkbox").checked = aCheckState.value;
     this.setLabelForNode(doc.getElementById("prompt-confirm-checkbox-msg"), aCheckMsg);
@@ -190,24 +217,30 @@ promptService.prototype = {
     
     // XXXjag bug 325251
     // Need to set this after aNode.setAttribute("value", aLabel);
     if (accessKey)
       aNode.setAttribute("accesskey", accessKey);
   },
 
   confirmEx: function(aParent, aTitle, aText, aButtonFlags, aButton0,
-            aButton1, aButton2, aCheckMsg, aCheckState) {
+                      aButton1, aButton2, aCheckMsg, aCheckState) {
+    let doc = this.getDocument();
+    if (!doc) {
+      return this._getFallbackService().confirmEx(aParent, aTitle, aText, aButtonFlags, aButton0,
+            aButton1, aButton2, aCheckMsg, aCheckState);
+    }
+
     let numButtons = 0;
     let titles = [aButton0, aButton1, aButton2];
     
     var params = new Object();
     params.result = false;
     params.checkbox = aCheckState;
-    let doc = this.getDocument();
+
     let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/confirm.xul", params);
     doc.getElementById("prompt-confirm-title").value = aTitle;
     doc.getElementById("prompt-confirm-message").appendChild(doc.createTextNode(aText));
     this.sizeElement("prompt-confirm-message", 80);
     this.sizeScrollableMsg("prompt-confirm-message", 25);
 
     doc.getElementById("prompt-confirm-checkbox").checked = aCheckState.value;
     this.setLabelForNode(doc.getElementById("prompt-confirm-checkbox-msg"), aCheckMsg);
@@ -262,22 +295,27 @@ promptService.prototype = {
       aButtonFlags >>= 8;
     }
     
     dialog.waitForClose();
     return params.result;
   },
   
   commonPrompt : function(aParent, aTitle, aText, aValue, aCheckMsg, aCheckState, isPassword) {
+    let doc = this.getDocument();
+    if (!doc) {
+      throw "No document !";
+    }
+    
     var params = new Object();
     params.result = false;
     params.checkbox = aCheckState;
     params.value = aValue;
+    
     let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/prompt.xul", params);
-    let doc = this.getDocument();
     doc.getElementById("prompt-prompt-title").value = aTitle;
     doc.getElementById("prompt-prompt-message").appendChild(doc.createTextNode(aText));
     this.sizeElement("prompt-prompt-message", 80);
     this.sizeScrollableMsg("prompt-prompt-message", 25);
 
     doc.getElementById("prompt-prompt-checkbox").checked = aCheckState.value;
     this.setLabelForNode(doc.getElementById("prompt-prompt-checkbox-msg"), aCheckMsg);
     this.sizeElement("prompt-prompt-checkbox-msg", 50);
@@ -289,31 +327,44 @@ promptService.prototype = {
       doc.getElementById("prompt-prompt-textbox").type = "password";
     }
     
     dialog.waitForClose();
     return params.result;
   },
   
   prompt : function(aParent, aTitle, aText, aValue, aCheckMsg, aCheckState) {
-    return this.commonPrompt(aParent, aTitle, aText, aValue, aCheckMsg, aCheckState, false);
+    try {
+      return this.commonPrompt(aParent, aTitle, aText, aValue, aCheckMsg, aCheckState, false);
+    } catch(e) {
+      return this._getFallbackService().prompt(aParent, aTitle, aText, aValue, aCheckMsg, aCheckState);
+    }
   },
   
   promptPassword: function(aParent, aTitle, aText, aPassword, aCheckMsg, aCheckState) {
-    return this.commonPrompt(aParent, aTitle, aText, aPassword, aCheckMsg, aCheckState, true);
+    try {
+      return this.commonPrompt(aParent, aTitle, aText, aPassword, aCheckMsg, aCheckState, true);
+    } catch(e) {
+      return this._getFallbackService().promptPassword(aParent, aTitle, aText, aPassword, aCheckMsg, aCheckState);
+    }
   },
   
   promptUsernameAndPassword: function(aParent, aTitle, aText, aUsername, aPassword, aCheckMsg, aCheckState) {
+    let doc = this.getDocument();
+    if (!doc) {
+      return this._getFallbackService().promptUsernameAndPassword(aParent, aTitle, aText, aUsername, aPassword, aCheckMsg, aCheckState);
+    }
+
     var params = new Object();
     params.result = false;
     params.checkbox = aCheckState;
     params.user = aUsername;
     params.password = aPassword;
+
     let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/promptPassword.xul", params);
-    let doc = this.getDocument();
     doc.getElementById("prompt-password-title").value = aTitle;
     doc.getElementById("prompt-password-message").appendChild(doc.createTextNode(aText));
     this.sizeElement("prompt-password-message", 80);
     this.sizeScrollableMsg("prompt-password-message", 25);
     doc.getElementById("prompt-password-checkbox").checked = aCheckState.value;
     
     doc.getElementById("prompt-password-user").value = aUsername.value;
     doc.getElementById("prompt-password-password").value = aPassword.value;
@@ -420,21 +471,26 @@ promptService.prototype = {
   },
   
   asyncPromptAuth: function(aParent, aChannel, aCallback, aContext, aLevel, aAuthInfo, aCheckMsg, aCheckState) {
     // bug 514196
     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
   
   select: function(aParent, aTitle, aText, aCount, aSelectList, aOutSelection) {
+    let doc = this.getDocument();
+    if (!doc) {
+      return this._getFallbackService().select(aParent, aTitle, aText, aCount, aSelectList, aOutSelection);
+    }
+
     var params = new Object();
     params.result = false;
     params.selection = aOutSelection;
+
     let dialog = this.openDialog(aParent, "chrome://browser/content/prompt/select.xul", params);
-    let doc = this.getDocument();
     doc.getElementById("prompt-select-title").value = aTitle;
     doc.getElementById("prompt-select-message").appendChild(doc.createTextNode(aText));
     this.sizeElement("prompt-select-message", 80);
     this.sizeScrollableMsg("prompt-select-message", 25);
     
     let list = doc.getElementById("prompt-select-list");
     for (let i = 0; i < aCount; i++)
       list.appendItem(aSelectList[i], null, null);