Bug 1276705 - rm IE/safari settings importers, r=dolske draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 14 Nov 2016 13:04:06 +0000
changeset 439807 cabd279ce1ab225a8cba7e18cc18469b97e4380b
parent 439734 51750761f2c61c64cf0553f6cb5fefd4999d3bc0
child 537263 e8d47f14b1b79df6468474632ef66161555df912
push id36103
push usergijskruitbosch@gmail.com
push dateWed, 16 Nov 2016 17:21:07 +0000
reviewersdolske
bugs1276705
milestone53.0a1
Bug 1276705 - rm IE/safari settings importers, r=dolske MozReview-Commit-ID: 2YcaxJkbTwj
browser/components/migration/IEProfileMigrator.js
browser/components/migration/SafariProfileMigrator.js
--- a/browser/components/migration/IEProfileMigrator.js
+++ b/browser/components/migration/IEProfileMigrator.js
@@ -334,153 +334,28 @@ IE7FormPasswords.prototype = {
       results.push(currentResult);
       // move to the next login item
       currentLoginItemPointer = currentLoginItemPointer.increment();
     }
     return results;
   },
 };
 
-function Settings() {
-}
-
-Settings.prototype = {
-  type: MigrationUtils.resourceTypes.SETTINGS,
-
-  get exists() {
-    return true;
-  },
-
-  migrate: function S_migrate(aCallback) {
-    // Converts from yes/no to a boolean.
-    let yesNoToBoolean = v => v == "yes";
-
-    // Converts source format like "en-us,ar-kw;q=0.7,ar-om;q=0.3" into
-    // destination format like "en-us, ar-kw, ar-om".
-    // Final string is sorted by quality (q=) param.
-    function parseAcceptLanguageList(v) {
-      return v.match(/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/gi)
-              .sort(function(a, b) {
-                let qA = parseFloat(a.split(";q=")[1]) || 1.0;
-                let qB = parseFloat(b.split(";q=")[1]) || 1.0;
-                return qB - qA;
-              })
-              .map(a => a.split(";")[0]);
-    }
-
-    // For reference on some of the available IE Registry settings:
-    //  * http://msdn.microsoft.com/en-us/library/cc980058%28v=prot.13%29.aspx
-    //  * http://msdn.microsoft.com/en-us/library/cc980059%28v=prot.13%29.aspx
-
-    // Note that only settings exposed in our UI should be migrated.
-
-    this._set("Software\\Microsoft\\Internet Explorer\\International",
-              "AcceptLanguage",
-              "intl.accept_languages",
-              parseAcceptLanguageList);
-    // TODO (bug 745853): For now, only x-western font is translated.
-    this._set("Software\\Microsoft\\Internet Explorer\\International\\Scripts\\3",
-              "IEFixedFontName",
-              "font.name.monospace.x-western");
-    this._set(kMainKey,
-              "Use FormSuggest",
-              "browser.formfill.enable",
-              yesNoToBoolean);
-    this._set(kMainKey,
-              "FormSuggest Passwords",
-              "signon.rememberSignons",
-              yesNoToBoolean);
-    this._set(kMainKey,
-              "Anchor Underline",
-              "browser.underline_anchors",
-              yesNoToBoolean);
-    this._set(kMainKey,
-              "Display Inline Images",
-              "permissions.default.image",
-              v => yesNoToBoolean(v) ? 1 : 2);
-    this._set(kMainKey,
-              "Move System Caret",
-              "accessibility.browsewithcaret",
-              yesNoToBoolean);
-    this._set("Software\\Microsoft\\Internet Explorer\\Settings",
-              "Always Use My Colors",
-              "browser.display.document_color_use",
-              v => (!v ? 0 : 2));
-    this._set("Software\\Microsoft\\Internet Explorer\\Settings",
-              "Always Use My Font Face",
-              "browser.display.use_document_fonts",
-              v => !v);
-    this._set(kMainKey,
-              "SmoothScroll",
-              "general.smoothScroll",
-              Boolean);
-    this._set("Software\\Microsoft\\Internet Explorer\\TabbedBrowsing\\",
-              "WarnOnClose",
-              "browser.tabs.warnOnClose",
-              Boolean);
-    this._set("Software\\Microsoft\\Internet Explorer\\TabbedBrowsing\\",
-              "OpenInForeground",
-              "browser.tabs.loadInBackground",
-              v => !v);
-
-    aCallback(true);
-  },
-
-  /**
-   * Reads a setting from the Registry and stores the converted result into
-   * the appropriate Firefox preference.
-   *
-   * @param aPath
-   *        Registry path under HKCU.
-   * @param aKey
-   *        Name of the key.
-   * @param aPref
-   *        Firefox preference.
-   * @param [optional] aTransformFn
-   *        Conversion function from the Registry format to the pref format.
-   */
-  _set: function S__set(aPath, aKey, aPref, aTransformFn) {
-    let value = WindowsRegistry.readRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
-                                           aPath, aKey);
-    // Don't import settings that have never been flipped.
-    if (value === undefined)
-      return;
-
-    if (aTransformFn)
-      value = aTransformFn(value);
-
-    switch (typeof value) {
-      case "string":
-        Services.prefs.setCharPref(aPref, value);
-        break;
-      case "number":
-        Services.prefs.setIntPref(aPref, value);
-        break;
-      case "boolean":
-        Services.prefs.setBoolPref(aPref, value);
-        break;
-      default:
-        throw new Error("Unexpected value type: " + (typeof value));
-    }
-  }
-};
-
 function IEProfileMigrator()
 {
   this.wrappedJSObject = this; // export this to be able to use it in the unittest.
 }
 
 IEProfileMigrator.prototype = Object.create(MigratorPrototype);
 
 IEProfileMigrator.prototype.getResources = function IE_getResources() {
   let resources = [
     MSMigrationUtils.getBookmarksMigrator(),
     new History(),
     MSMigrationUtils.getCookiesMigrator(),
-    new Settings(),
   ];
   // Only support the form password migrator for Windows XP to 7.
   if (AppConstants.isPlatformAndVersionAtMost("win", "6.1")) {
     resources.push(new IE7FormPasswords());
   }
   let windowsVaultFormPasswordsMigrator =
     MSMigrationUtils.getWindowsVaultFormPasswordsMigrator();
   windowsVaultFormPasswordsMigrator.name = "IEVaultFormPasswords";
--- a/browser/components/migration/SafariProfileMigrator.js
+++ b/browser/components/migration/SafariProfileMigrator.js
@@ -308,203 +308,16 @@ MainPreferencesPropertyList.prototype = 
     binaryStream.setInputStream(inputStream);
     let bytes = binaryStream.readByteArray(inputStream.available());
     this._dict = PropertyListUtils._readFromArrayBufferSync(
       new Uint8Array(bytes).buffer);
     return this._dict;
   }
 };
 
-function Preferences(aMainPreferencesPropertyListInstance) {
-  this._mainPreferencesPropertyList = aMainPreferencesPropertyListInstance;
-}
-Preferences.prototype = {
-  type: MigrationUtils.resourceTypes.SETTINGS,
-
-  migrate: function MPR_migrate(aCallback) {
-    this._mainPreferencesPropertyList.read(aDict => {
-      Task.spawn(function* () {
-        if (!aDict)
-          throw new Error("Could not read preferences file");
-
-        this._dict = aDict;
-
-        let invert = webkitVal => !webkitVal;
-        this._set("AutoFillPasswords", "signon.rememberSignons");
-        this._set("OpenNewTabsInFront", "browser.tabs.loadInBackground", invert);
-        this._set("WebKitJavaScriptCanOpenWindowsAutomatically",
-                   "dom.disable_open_during_load", invert);
-
-        // layout.spellcheckDefault is a boolean stored as a number.
-        this._set("WebContinuousSpellCheckingEnabled",
-                  "layout.spellcheckDefault", Number);
-
-        // Auto-load images
-        // Firefox has an elaborate set of Image preferences. The correlation is:
-        // Mode:                            Safari    Firefox
-        // Blocked                          FALSE     2
-        // Allowed                          TRUE      1
-        // Allowed, originating site only   --        3
-        this._set("WebKitDisplayImagesKey", "permissions.default.image",
-                  webkitVal => webkitVal ? 1 : 2);
-
-        this._migrateFontSettings();
-        yield this._migrateDownloadsFolder();
-      }.bind(this)).then(() => aCallback(true), ex => {
-        Cu.reportError(ex);
-        aCallback(false);
-      }).catch(Cu.reportError);
-    });
-  },
-
-  /**
-   * Attempts to migrates a preference from Safari.  Returns whether the preference
-   * has been migrated.
-   * @param aSafariKey
-   *        The dictionary key for the preference of Safari.
-   * @param aMozPref
-   *        The gecko/firefox preference to which aSafariKey should be migrated
-   * @param [optional] aConvertFunction(aSafariValue)
-   *        a function that converts the safari-preference value to the
-   *        appropriate value for aMozPref.  If it's not passed, then the
-   *        Safari value is set as is.
-   *        If aConvertFunction returns undefined, then aMozPref is not set
-   *        at all.
-   * @return whether or not aMozPref was set.
-   */
-  _set: function MPR_set(aSafariKey, aMozPref, aConvertFunction) {
-    if (this._dict.has(aSafariKey)) {
-      let safariVal = this._dict.get(aSafariKey);
-      let mozVal = aConvertFunction !== undefined ?
-                   aConvertFunction(safariVal) : safariVal;
-      switch (typeof mozVal) {
-        case "string":
-          Services.prefs.setCharPref(aMozPref, mozVal);
-          break;
-        case "number":
-          Services.prefs.setIntPref(aMozPref, mozVal);
-          break;
-        case "boolean":
-          Services.prefs.setBoolPref(aMozPref, mozVal);
-          break;
-        case "undefined":
-          return false;
-        default:
-          throw new Error("Unexpected value type: " + (typeof mozVal));
-      }
-    }
-    return true;
-  },
-
-  // Fonts settings are quite problematic for migration, for a couple of
-  // reasons:
-  // (a) Every font preference in Gecko is set for a particular language.
-  //     In Safari, each font preference applies to all languages.
-  // (b) The current underlying implementation of nsIFontEnumerator cannot
-  //     really tell you anything about a font: no matter what language or type
-  //     you try to enumerate with EnumerateFonts, you get an array of all
-  //     fonts in the systems (This also breaks our fonts dialog).
-  // (c) In Gecko, each langauge has a distinct serif and sans-serif font
-  //     preference.  Safari has only one default font setting.  It seems that
-  //     it checks if it's a serif or sans serif font, and when a site
-  //     explicitly asks to use serif/sans-serif font, it uses the default font
-  //     only if it applies to this type.
-  // (d) The solution of guessing the lang-group out of the default charset (as
-  //     done in the old Safari migrator) can only work when:
-  //     (1) The default charset preference is set.
-  //     (2) It's not a unicode charset.
-  // For now, we use the language implied by the system locale as the
-  // lang-group. The only exception is minimal font size, which is an
-  // accessibility preference in Safari (under the Advanced tab). If it is set,
-  // we set it for all languages.
-  // As for the font type of the default font (serif/sans-serif), the default
-  // type for the given language is used (set in font.default.LANGGROUP).
-  _migrateFontSettings: function MPR__migrateFontSettings() {
-    // If "Never use font sizes smaller than [ ] is set", migrate it for all
-    // languages.
-    if (this._dict.has("WebKitMinimumFontSize")) {
-      let minimumSize = this._dict.get("WebKitMinimumFontSize");
-      if (typeof minimumSize == "number") {
-        let prefs = Services.prefs.getChildList("font.minimum-size");
-        for (let pref of prefs) {
-          Services.prefs.setIntPref(pref, minimumSize);
-        }
-      }
-      else {
-        Cu.reportError("WebKitMinimumFontSize was set to an invalid value: " +
-                       minimumSize);
-      }
-    }
-
-    // In theory, the lang group could be "x-unicode". This will result
-    // in setting the fonts for "Other Languages".
-    let lang = this._getLocaleLangGroup();
-
-    let anySet = false;
-    let fontType = Services.prefs.getCharPref("font.default." + lang);
-    anySet |= this._set("WebKitFixedFont", "font.name.monospace." + lang);
-    anySet |= this._set("WebKitDefaultFixedFontSize", "font.size.fixed." + lang);
-    anySet |= this._set("WebKitStandardFont",
-                        "font.name." + fontType + "." + lang);
-    anySet |= this._set("WebKitDefaultFontSize", "font.size.variable." + lang);
-
-    // If we set font settings for a particular language, we'll also set the
-    // fonts dialog to open with the fonts settings for that langauge.
-    if (anySet)
-      Services.prefs.setCharPref("font.language.group", lang);
-  },
-
-  // Get the language group for the system locale.
-  _getLocaleLangGroup: function MPR__getLocaleLangGroup() {
-    let locale = Services.locale.getLocaleComponentForUserAgent();
-
-    // See nsLanguageAtomService::GetLanguageGroup
-    let localeLangGroup = "x-unicode";
-    let bundle = Services.strings.createBundle(
-      "resource://gre/res/langGroups.properties");
-    try {
-      localeLangGroup = bundle.GetStringFromName(locale);
-    }
-    catch (ex) {
-      let hyphenAt = locale.indexOf("-");
-      if (hyphenAt != -1) {
-        try {
-          localeLangGroup = bundle.GetStringFromName(locale.substr(0, hyphenAt));
-        }
-        catch (ex2) { }
-      }
-    }
-    return localeLangGroup;
-  },
-
-  _migrateDownloadsFolder: Task.async(function* () {
-    if (!this._dict.has("DownloadsPath"))
-      return;
-
-    let downloadsFolder = FileUtils.File(this._dict.get("DownloadsPath"));
-
-    // If the download folder is set to the Desktop or to ~/Downloads, set the
-    // folderList pref appropriately so that "Desktop"/Downloads is shown with
-    // pretty name in the preferences dialog.
-    let folderListVal = 2;
-    if (downloadsFolder.equals(FileUtils.getDir("Desk", []))) {
-      folderListVal = 0;
-    }
-    else {
-      let systemDownloadsPath = yield Downloads.getSystemDownloadsDirectory();
-      let systemDownloadsFolder = FileUtils.File(systemDownloadsPath);
-      if (downloadsFolder.equals(systemDownloadsFolder))
-        folderListVal = 1;
-    }
-    Services.prefs.setIntPref("browser.download.folderList", folderListVal);
-    Services.prefs.setComplexValue("browser.download.dir", Ci.nsILocalFile,
-                                   downloadsFolder);
-  }),
-};
-
 function SearchStrings(aMainPreferencesPropertyListInstance) {
   this._mainPreferencesPropertyList = aMainPreferencesPropertyListInstance;
 }
 SearchStrings.prototype = {
   type: MigrationUtils.resourceTypes.OTHERDATA,
 
   migrate: function SS_migrate(aCallback) {
     this._mainPreferencesPropertyList.read(MigrationUtils.wrapMigrateFunction(
@@ -521,49 +334,16 @@ SearchStrings.prototype = {
                             value: searchString}));
             FormHistory.update(changes);
           }
         }
       }.bind(this), aCallback));
   }
 };
 
-// On OS X, the cookie-accept policy preference is stored in a separate
-// property list.
-function WebFoundationCookieBehavior(aWebFoundationFile) {
-  this._file = aWebFoundationFile;
-}
-WebFoundationCookieBehavior.prototype = {
-  type: MigrationUtils.resourceTypes.SETTINGS,
-
-  migrate: function WFPL_migrate(aCallback) {
-    PropertyListUtils.read(this._file, MigrationUtils.wrapMigrateFunction(
-      function migrateCookieBehavior(aDict) {
-        if (!aDict)
-          throw new Error("Could not read com.apple.WebFoundation.plist");
-
-        if (aDict.has("NSHTTPAcceptCookies")) {
-          // Setting                    Safari          Firefox
-          // Always Accept              always          0
-          // Accept from Originating    current page    1
-          // Never Accept               never           2
-          let acceptCookies = aDict.get("NSHTTPAcceptCookies");
-          let cookieValue = 0;
-          if (acceptCookies == "never") {
-            cookieValue = 2;
-          } else if (acceptCookies == "current page") {
-            cookieValue = 1;
-          }
-          Services.prefs.setIntPref("network.cookie.cookieBehavior",
-                                    cookieValue);
-        }
-      }.bind(this), aCallback));
-  }
-};
-
 function SafariProfileMigrator() {
 }
 
 SafariProfileMigrator.prototype = Object.create(MigratorPrototype);
 
 SafariProfileMigrator.prototype.getResources = function SM_getResources() {
   let profileDir = FileUtils.getDir("ULibDir", ["Safari"], false);
   if (!profileDir.exists())
@@ -584,24 +364,19 @@ SafariProfileMigrator.prototype.getResou
   // Mac versions of Safari.  Not surprisingly, they are stored in the same
   // format in both versions.  Surpsingly, only on Windows there is a
   // separate property list for it.  This code is used on mac too, because
   // Apple may fix this at some point.
   pushProfileFileResource("ReadingList.plist", Bookmarks);
 
   let prefs = this.mainPreferencesPropertyList;
   if (prefs) {
-    resources.push(new Preferences(prefs));
     resources.push(new SearchStrings(prefs));
   }
 
-  let wfFile = FileUtils.getFile("UsrPrfs", ["com.apple.WebFoundation.plist"]);
-  if (wfFile.exists())
-    resources.push(new WebFoundationCookieBehavior(wfFile));
-
   return resources;
 };
 
 SafariProfileMigrator.prototype.getLastUsedDate = function SM_getLastUsedDate() {
   let profileDir = FileUtils.getDir("ULibDir", ["Safari"], false);
   let datePromises = ["Bookmarks.plist", "History.plist"].map(file => {
     let path = OS.Path.join(profileDir.path, file);
     return OS.File.stat(path).catch(() => null).then(info => {