Bug 1560485 - Use a pref instead of DOM storage for name typed into the new account provisioner. r=BenB
authorJorg K <jorgk@jorgk.com>
Fri, 21 Jun 2019 14:16:42 +0200
changeset 35915 705abdff6892967ed4532a5cddb358fc3da9e4d0
parent 35914 e9bc2e1580a08c373d4e5cc40802ccd3c71d06c1
child 35916 ff3f3dc92e3a2a9ab271d571c58ca9ccbbaec23c
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersBenB
bugs1560485
Bug 1560485 - Use a pref instead of DOM storage for name typed into the new account provisioner. r=BenB
mail/app/profile/all-thunderbird.js
mail/components/newmailaccount/content/accountProvisioner.js
mail/test/mozmill/newmailaccount/test-newmailaccount.js
--- a/mail/app/profile/all-thunderbird.js
+++ b/mail/app/profile/all-thunderbird.js
@@ -413,19 +413,16 @@ pref("mail.phishing.detection.ipaddresse
 pref("mail.phishing.detection.mismatched_hosts", true);
 pref("mail.phishing.detection.disallow_form_actions", true);
 
 pref("browser.safebrowsing.reportPhishURL", "https://%LOCALE%.phish-report.mozilla.com/?hl=%LOCALE%");
 
 // prevent status-bar spoofing even if people are foolish enough to turn on JS
 pref("dom.disable_window_status_change",          true);
 
-// Disable client ID checking when creating storage (see bug 1557233).
-pref("dom.storage.client_validation", false);
-
 // If a message is opened using Enter or a double click, what should we do?
 // 0 - open it in a new window
 // 1 - open it in an existing window
 // 2 - open it in a new tab
 pref("mail.openMessageBehavior", 2);
 pref("mail.openMessageBehavior.version", 0);
 // If messages or folders are opened using the context menu or a middle click,
 // should we open them in the foreground or in the background?
@@ -691,16 +688,17 @@ pref("layers.acceleration.disabled", tru
 // and direct2d support on Windows.
 pref("gfx.direct2d.disabled", true);
 #endif
 
 // Account provisioner.
 pref("mail.provider.providerList", "https://broker.thunderbird.net/provider/list");
 pref("mail.provider.suggestFromName", "https://broker.thunderbird.net/provider/suggest");
 pref("mail.provider.enabled", true);
+pref("mail.provider.realname", "");
 
 // Developer Tools related preferences
 pref("devtools.debugger.log", false);
 pref("devtools.chrome.enabled", true);
 pref("devtools.debugger.remote-enabled", true);
 pref("devtools.selfxss.count", 5);
 
 pref("mail.chat.enabled", true);
--- a/mail/components/newmailaccount/content/accountProvisioner.js
+++ b/mail/components/newmailaccount/content/accountProvisioner.js
@@ -20,30 +20,16 @@ var stringBundle = new StringBundle("chr
 
 var RETRY_TIMEOUT = 5000; // 5 seconds
 var CONNECTION_TIMEOUT = 15000; // 15 seconds
 
 function isAccel(event) {
   return AppConstants.platform == "macosx" ? event.metaKey : event.ctrlKey;
 }
 
-/**
- * Get fixed localstorage.
- *
- * @param {String} page The page to get the localstorage for.
- * @return {nsIDOMStorage} The localstorage for this page.
- */
-function getLocalStorage() {
-  var url = "https://accountprovisioner.thunderbird.invalid";
-
-  var uri = Services.io.newURI(url);
-  var principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
-  return Services.domStorageManager.createStorage(null, principal, principal, url);
-}
-
 var MAX_SMALL_ADDRESSES = 2;
 
 var storedData = {};
 
 function splitName(str) {
   let i = str.lastIndexOf(" ");
   if (i >= 1)
     return [str.substring(0, i), str.substring(i + 1)];
@@ -74,17 +60,16 @@ function insertHTMLReplacement(aTextCont
  * tracks / maintains window state throughout the Account Provisioner workflow.
  */
 var EmailAccountProvisioner = {
 
   _inited: false,
   _loadingProviders: false,
   _loadedProviders: false,
   _loadProviderRetryId: null,
-  _storage: null,
   providers: {},
   _someProvidersChecked: false,
   // These get passed in when creating the Account Provisioner window.
   NewMailAccount: window.arguments[0].NewMailAccount,
   NewComposeMessage: window.arguments[0].NewComposeMessage,
   openAddonsMgr: window.arguments[0].openAddonsMgr,
   msgWindow: window.arguments[0].msgWindow,
 
@@ -198,22 +183,22 @@ var EmailAccountProvisioner = {
       MsgAccountManager(null, account.incomingServer);
     });
 
     document.getElementById("window").style.display = "none";
     document.getElementById("successful_account").style.display = "block";
   },
 
   /**
-   * Save the name inputted in the search field to localstorage, so we can
+   * Save the name entered into the search field to a pref, so we can
    * reconstitute it on respawn later.
    */
   saveName() {
     let name = document.getElementById("name").value.trim();
-    this.storage.setItem("name", name);
+    Services.prefs.setStringPref("mail.provider.realname", name);
   },
 
   onSearchInputOrProvidersChanged(event) {
     let emptyName = document.getElementById("name").value == "";
     EmailAccountProvisioner.searchButtonEnabled(!emptyName &&
       EmailAccountProvisioner.someProvidersChecked);
   },
 
@@ -272,19 +257,18 @@ var EmailAccountProvisioner = {
     EmailAccountProvisioner.tryToPopulateProviderList();
 
     // Link the keypress function to the name field so that we can enable and
     // disable the search button.
     let nameElement = document.getElementById("name");
     nameElement.addEventListener("keyup",
       EmailAccountProvisioner.onSearchInputOrProvidersChanged);
 
-    // If we have a name stored in local storage from an earlier session,
-    // populate the search field with it.
-    let name = EmailAccountProvisioner.storage.getItem("name") ||
+    // If we have a name stored, populate the search field with it.
+    let name = Services.prefs.getStringPref("mail.provider.realname") ||
                nameElement.value;
     if (!name && "@mozilla.org/userinfo;1" in Cc) {
       name = Cc["@mozilla.org/userinfo;1"].getService(Ci.nsIUserInfo).fullname;
     }
     nameElement.value = name;
     EmailAccountProvisioner.saveName();
 
     // Pretend like we've typed something into the search input to set the
@@ -987,18 +971,13 @@ var EmailAccountProvisioner = {
     let element = document.getElementById("cannotConnectMessage");
     element.style.display = "none";
     element.textContent = "";
     this.searchEnabled(true);
     gLog.info("Email Account Provisioner is in online mode.");
   },
 };
 
-
-XPCOMUtils.defineLazyGetter(EmailAccountProvisioner, "storage", function() {
-  return getLocalStorage();
-});
-
 window.addEventListener("online",
                         EmailAccountProvisioner.tryToPopulateProviderList);
 
 document.addEventListener("DOMContentLoaded",
                           EmailAccountProvisioner.init);
--- a/mail/test/mozmill/newmailaccount/test-newmailaccount.js
+++ b/mail/test/mozmill/newmailaccount/test-newmailaccount.js
@@ -1197,28 +1197,17 @@ function subtest_provider_language_wildc
   close_dialog_immediately(aController);
 }
 
 /**
  * Tests that the search button is disabled if we start up the Account
  * Provisioner, and we have no search in the input.
  */
 function test_search_button_disabled_if_no_query_on_init() {
-  // We have to do a little bit of gymnastics to access the local storage
-  // for the accountProvisioner dialog...
-  let url = "https://accountprovisioner.thunderbird.invalid";
-  let dsm = Services.domStorageManager;
-
-  let uri = Services.io.newURI(url);
-  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
-  let storage = dsm.createStorage(null, principal, principal, url);
-
-  // Ok, got it. Now let's blank out the name.
-  storage.setItem("name", "");
-
+  Services.prefs.setStringPref("mail.provider.realname", "");
   plan_for_modal_dialog("AccountCreation",
                         subtest_search_button_enabled_state_on_init);
   open_provisioner_window();
   wait_for_modal_dialog("AccountCreation");
 }
 
 /**
  * Test that if we try to open the Account Provisioner dialog when an