Bug 1331477 - Migrate mail remote content exceptions in SeaMonkey. r=IanN a=IanN
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Sun, 22 Jan 2017 18:09:12 +0100
changeset 24100 c789fe71e02c0b1396da5e8c5c1107a1598dfad4
parent 24099 8ea39bd5a173bdcf509b274056c2c1ebd1fb79d3
child 24101 0ac5cccaad09773d8c5be2ddd345643e9c450cac
push id1973
push userclokep@gmail.com
push dateMon, 23 Jan 2017 21:55:50 +0000
treeherdercomm-aurora@9b85bcae26a8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN, IanN
bugs1331477
Bug 1331477 - Migrate mail remote content exceptions in SeaMonkey. r=IanN a=IanN
suite/common/src/nsSuiteGlue.js
--- a/suite/common/src/nsSuiteGlue.js
+++ b/suite/common/src/nsSuiteGlue.js
@@ -348,16 +348,17 @@ SuiteGlue.prototype = {
                              "_blank", "chrome,centerscreen,modal,resizable=no", null);
     }
     this._copyDefaultProfileFiles();
   },
 
   // profile startup handler (contains profile initialization routines)
   _onProfileStartup: function()
   {
+    this._migrateUI();
     this._updatePrefs();
     this._migrateDownloadPrefs();
     migrateMailnews(); // mailnewsMigrator.js
 
     Sanitizer.checkSettings();
     Sanitizer.doPendingSanitize();
 
     if (Services.prefs.prefHasUserValue("privacy.sanitize.didShutdownSanitize")) {
@@ -369,16 +370,82 @@ SuiteGlue.prototype = {
 
     this._setUpUserAgentOverrides();
 
     var timer = Components.classes["@mozilla.org/timer;1"]
                           .createInstance(Components.interfaces.nsITimer);
     timer.init(this, 3000, timer.TYPE_ONE_SHOT);
   },
 
+  _migrateUI: function()
+  {
+    const UI_VERSION = 1;
+
+    // If the pref is not set this is a new or pre SeaMonkey 2.50 profile.
+    // We can't tell so we just run migration with version 0.
+    let currentUIVersion = 0;
+
+    if (Services.prefs.prefHasUserValue("suite.migration.version")) {
+      currentUIVersion = Services.prefs.getIntPref("suite.migration.version");
+    }
+
+    if (currentUIVersion >= UI_VERSION)
+      return;
+
+    // Migrate remote content exceptions for email addresses which are
+    // encoded as chrome URIs.
+    if (currentUIVersion < 1) {
+      let permissionsDB =
+        Services.dirsvc.get("ProfD", Components.interfaces.nsILocalFile);
+      permissionsDB.append("permissions.sqlite");
+      let db = Services.storage.openDatabase(permissionsDB);
+
+      let statement = db.createStatement(
+        "select origin, permission from moz_perms where " +
+        // Avoid 'like' here which needs to be escaped.
+        "  substr(origin, 1, 28) = 'chrome://messenger/content/?';");
+
+      try {
+        while (statement.executeStep()) {
+          let origin = statement.getUTF8String(0);
+          let permission = statement.getInt32(1);
+          Services.console.logStringMessage("Mail-Image-Perm Mig: " + origin);
+          Services.perms.remove(
+            Services.io.newURI(origin), "image");
+          origin = origin.replace("chrome://messenger/content/?",
+                                  "chrome://messenger/content/");
+          Services.perms.add(
+            Services.io.newURI(origin), "image", permission);
+        }
+      } catch (ex) {
+        throw ex;
+      } finally {
+        statement.finalize();
+      }
+
+      // Sadly we still need to clear the database manually. Experiments
+      // showed that the permissions manager deletes only one record.
+      db.beginTransactionAs(Components.interfaces.mozIStorageConnection.TRANSACTION_EXCLUSIVE);
+
+      try {
+        db.executeSimpleSQL("delete from moz_perms where " +
+             "  substr(origin, 1, 28) = 'chrome://messenger/content/?';");
+        db.commitTransaction();
+      } catch (ex) {
+        db.rollbackTransaction();
+        throw ex;
+      } finally {
+        db.close();
+      }
+    }
+
+    // Update the migration version.
+    Services.prefs.setIntPref("suite.migration.version", UI_VERSION);
+  },
+
   // Copies additional profile files from the default profile tho the current profile.
   // Only files not covered by the regular profile creation process.
   // Currently only the userchrome examples.
   _copyDefaultProfileFiles: function()
   {
     // Copy default chrome example files if they do not exist in the current profile.
     var profileDir = Services.dirsvc.get("ProfD", Components.interfaces.nsILocalFile);
     profileDir.append("chrome");