Bug 1442271 - Cookie imports fail on newer versions of Chrome r=Gijs
authorTrishul <trishul.goel@gmail.com>
Tue, 21 May 2019 12:40:22 +0000
changeset 474805 350f7249407d5156f831562b38807111790e8e74
parent 474804 96306b575252ae9f2914a5ca3c92f84356031a94
child 474806 b0583bec17687ad56b05a4216f2ba6787e361306
push id36046
push useraiakab@mozilla.com
push dateTue, 21 May 2019 21:45:52 +0000
treeherdermozilla-central@257f2c96cef5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1442271
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1442271 - Cookie imports fail on newer versions of Chrome r=Gijs DB field name is changed in chrome, so matching that. Cookie imports fail on newer versions of Chrome Differential Revision: https://phabricator.services.mozilla.com/D31976
browser/components/migration/ChromeProfileMigrator.jsm
--- a/browser/components/migration/ChromeProfileMigrator.jsm
+++ b/browser/components/migration/ChromeProfileMigrator.jsm
@@ -283,19 +283,34 @@ async function GetCookiesResource(aProfi
   let cookiesPath = OS.Path.join(aProfileFolder, "Cookies");
   if (!(await OS.File.exists(cookiesPath)))
     return null;
 
   return {
     type: MigrationUtils.resourceTypes.COOKIES,
 
     async migrate(aCallback) {
+      // Get columns names and set is_sceure, is_httponly fields accordingly.
+      let columns = await MigrationUtils.getRowsFromDBWithoutLocks(cookiesPath, "Chrome cookies",
+        `PRAGMA table_info(cookies)`).catch(ex => {
+          Cu.reportError(ex);
+          aCallback(false);
+        });
+      // If the promise was rejected we will have already called aCallback,
+      // so we can just return here.
+      if (!columns) {
+        return;
+      }
+      columns = columns.map(c => c.getResultByName("name"));
+      let isHttponly = columns.includes("is_httponly") ? "is_httponly" : "httponly";
+      let isSecure = columns.includes("is_secure") ? "is_secure" : "secure";
+
       // We don't support decrypting cookies yet so only import plaintext ones.
       let rows = await MigrationUtils.getRowsFromDBWithoutLocks(cookiesPath, "Chrome cookies",
-       `SELECT host_key, name, value, path, expires_utc, secure, httponly, encrypted_value
+       `SELECT host_key, name, value, path, expires_utc, ${isSecure}, ${isHttponly}, encrypted_value
         FROM cookies
         WHERE length(encrypted_value) = 0`).catch(ex => {
           Cu.reportError(ex);
           aCallback(false);
         });
       // If the promise was rejected we will have already called aCallback,
       // so we can just return here.
       if (!rows) {
@@ -311,18 +326,18 @@ async function GetCookiesResource(aProfi
 
         try {
           let expiresUtc = ChromeMigrationUtils.chromeTimeToDate(
             row.getResultByName("expires_utc")) / 1000;
           Services.cookies.add(host_key,
                                row.getResultByName("path"),
                                row.getResultByName("name"),
                                row.getResultByName("value"),
-                               row.getResultByName("secure"),
-                               row.getResultByName("httponly"),
+                               row.getResultByName(isSecure),
+                               row.getResultByName(isHttponly),
                                false,
                                parseInt(expiresUtc),
                                {},
                                Ci.nsICookie2.SAMESITE_UNSET);
         } catch (e) {
           Cu.reportError(e);
         }
       }