Bug 1330640 - migrate chrome URIs in moz_perms. r=mkmelin AURORA_BASE_20170123
authorJorg K <jorgk@jorgk.com>
Mon, 23 Jan 2017 07:50:18 +0100
changeset 27357 543431e0ab6980233762d197542fee80b031ee01
parent 27356 9fd1d897cd8bd55828948a90b3e45d4f0929959c
child 27358 2ac5275ae56f6910d431e97fee7779cb5ee16fba
push idunknown
push userunknown
push dateunknown
reviewersmkmelin
bugs1330640
Bug 1330640 - migrate chrome URIs in moz_perms. r=mkmelin
mail/base/modules/mailMigrator.js
--- a/mail/base/modules/mailMigrator.js
+++ b/mail/base/modules/mailMigrator.js
@@ -97,17 +97,17 @@ var MailMigrator = {
 
   /**
    * Determine if the UI has been upgraded in a way that requires us to reset
    * some user configuration.  If so, performs the resets.
    */
   _migrateUI: function() {
     // The code for this was ported from
     // mozilla/browser/components/nsBrowserGlue.js
-    const UI_VERSION = 13;
+    const UI_VERSION = 14;
     const MESSENGER_DOCURL = "chrome://messenger/content/messenger.xul";
     const UI_VERSION_PREF = "mail.ui-rdf.version";
     let currentUIVersion = 0;
 
     try {
       currentUIVersion = Services.prefs.getIntPref(UI_VERSION_PREF);
     } catch(ex) {}
 
@@ -315,16 +315,61 @@ var MailMigrator = {
 
       // Untangled starting in Paragraph mode from Enter key preference
       if (currentUIVersion < 13) {
         Services.prefs.setBoolPref("mail.compose.default_to_paragraph",
           Services.prefs.getBoolPref("editor.CR_creates_new_p"));
         Services.prefs.clearUserPref("editor.CR_creates_new_p");
       }
 
+      // Migrate remote content exceptions for email addresses which are
+      // encoded as chrome URIs.
+      if (currentUIVersion < 14) {
+        let permissionsDB =
+          Services.dirsvc.get("ProfD",Components.interfaces.nsILocalFile);
+        permissionsDB.append("permissions.sqlite");
+        let db = Services.storage.openDatabase(permissionsDB);
+
+        try {
+          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.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);
+            }
+          } finally {
+            statement.finalize();
+          }
+
+          // Sadly we still need to clear the database manually. Experiments
+          // showed that the permissions manager deleted 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(UI_VERSION_PREF, UI_VERSION);
 
     } catch(e) {
       Cu.reportError("Migrating from UI version " + currentUIVersion + " to " +
                      UI_VERSION + " failed. Error message was: " + e + " -- " +
                      "Will reattempt on next start.");
     }