Bug 931900 - Make null value parameter handling match Desktop. r=margaret
authorWes Johnston <wjohnston@mozilla.com>
Wed, 19 Feb 2014 13:17:33 -0800
changeset 170012 547342061dc33fe675b0c77247e995eb80fbe6dd
parent 170011 dcdf818049ee0e449702fe4e09caac326fb46cad
child 170013 9a30d2ed15978b06f5cb78c5fa3551f1f3e70870
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersmargaret
bugs931900
milestone30.0a1
Bug 931900 - Make null value parameter handling match Desktop. r=margaret
mobile/android/components/PromptService.js
--- a/mobile/android/components/PromptService.js
+++ b/mobile/android/components/PromptService.js
@@ -134,16 +134,32 @@ InternalPrompt.prototype = {
         label: PromptUtils.cleanUpLabel(aCheckMsg),
         checked: aCheckState.value
       });
     }
 
     return aPrompt;
   },
 
+  addTextbox: function(prompt, value, autofocus, hint) {
+    prompt.addTextbox({
+      value: (value !== null) ? value : "",
+      autofocus: autofocus,
+      hint: hint
+    });
+  },
+
+  addPassword: function(prompt, value, autofocus, hint) {
+    prompt.addPassword({
+      value: (value !== null) ? value : "",
+      autofocus: autofocus,
+      hint: hint
+    });
+  },
+
   /* Shows a native prompt, and then spins the event loop for this thread while we wait
    * for a response
    */
   showPrompt: function showPrompt(aPrompt) {
     if (this._domWin) {
       PromptUtils.fireDialogEvent(this._domWin, "DOMWillOpenModalDialog");
       let winUtils = this._domWin.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
       winUtils.enterModalState();
@@ -283,61 +299,48 @@ InternalPrompt.prototype = {
     if (aCheckState && data.button > -1)
       aCheckState.value = data.checkbox0 == "true";
     return data.button;
   },
 
   nsIPrompt_prompt: function nsIPrompt_prompt(aTitle, aText, aValue, aCheckMsg, aCheckState) {
     let p = this._getPrompt(aTitle, aText, null, aCheckMsg, aCheckState);
     p.setHint("prompt");
-    p.addTextbox({
-      value: aValue.value,
-      autofocus: true
-    });
+    this.addTextbox(p, aValue.value, true);
     this.addCheckbox(p, aCheckMsg, aCheckState);
     let data = this.showPrompt(p);
 
     let ok = data.button == 0;
     if (aCheckState && data.button > -1)
       aCheckState.value = data.checkbox0 == "true";
     if (ok)
       aValue.value = data.textbox0;
     return ok;
   },
 
   nsIPrompt_promptPassword: function nsIPrompt_promptPassword(
       aTitle, aText, aPassword, aCheckMsg, aCheckState) {
     let p = this._getPrompt(aTitle, aText, null);
-    p.addPassword({
-      value: aPassword.value || "",
-      autofocus: true,
-      hint: PromptUtils.getLocaleString("password", "passwdmgr")
-    });
+    this.addPassword(p, aPassword.value, true, PromptUtils.getLocaleString("password", "passwdmgr"));
     this.addCheckbox(p, aCheckMsg, aCheckState);
     let data = this.showPrompt(p);
 
     let ok = data.button == 0;
     if (aCheckState && data.button > -1)
       aCheckState.value = data.checkbox0 == "true";
     if (ok)
       aPassword.value = data.password0;
     return ok;
   },
 
   nsIPrompt_promptUsernameAndPassword: function nsIPrompt_promptUsernameAndPassword(
       aTitle, aText, aUsername, aPassword, aCheckMsg, aCheckState) {
     let p = this._getPrompt(aTitle, aText, null);
-    p.addTextbox({
-      value: aUsername.value,
-      autofocus: true,
-      hint: PromptUtils.getLocaleString("username", "passwdmgr")
-    }).addPassword({
-      value: aPassword.value,
-      hint: PromptUtils.getLocaleString("password", "passwdmgr")
-    });
+    this.addTextbox(p, aUsername.value, true, PromptUtils.getLocaleString("username", "passwdmgr"));
+    this.addPassword(p, aPassword.value, true, PromptUtils.getLocaleString("password", "passwdmgr"));
     this.addCheckbox(p, aCheckMsg, aCheckState);
     let data = this.showPrompt(p);
 
     let ok = data.button == 0;
     if (aCheckState && data.button > -1)
       aCheckState.value = data.checkbox0 == "true";
     if (ok) {
       aUsername.value = data.textbox0;