Bug 1286798 - Part 7: Teach QuotaManager's OriginParser to handle file://UNIVERSAL_FILE_URI_ORIGIN; r=asuth
authorJan Varga <jan.varga@gmail.com>
Thu, 29 Nov 2018 21:47:34 +0100
changeset 508005 d5f293542508df0e6c56623f30b2d13b218c617f
parent 508004 0b0a03cf7b64cc9cc6eff36c3ae7f56f010e944c
child 508006 1a6c4f6a6b5cad6d90e9489b480d2fdd5d6319aa
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1286798, 1340710
milestone65.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 1286798 - Part 7: Teach QuotaManager's OriginParser to handle file://UNIVERSAL_FILE_URI_ORIGIN; r=asuth See bug 1340710 which introduced this kind of URI.
dom/quota/ActorsParent.cpp
dom/quota/test/unit/test_specialOrigins.js
dom/quota/test/unit/xpcshell.ini
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -1736,17 +1736,17 @@ private:
   };
 
   enum State {
     eExpectingAppIdOrScheme,
     eExpectingInMozBrowser,
     eExpectingScheme,
     eExpectingEmptyToken1,
     eExpectingEmptyToken2,
-    eExpectingEmptyToken3,
+    eExpectingEmptyTokenOrUniversalFileOrigin,
     eExpectingHost,
     eExpectingPort,
     eExpectingEmptyTokenOrDriveLetterOrPathnameComponent,
     eExpectingEmptyTokenOrPathnameComponent,
     eComplete,
     eHandledTrailingSeparator
   };
 
@@ -1759,30 +1759,32 @@ private:
   nsCString mHost;
   Nullable<uint32_t> mPort;
   nsTArray<nsCString> mPathnameComponents;
   nsCString mHandledTokens;
 
   SchemeType mSchemeType;
   State mState;
   bool mInIsolatedMozBrowser;
+  bool mUniversalFileOrigin;
   bool mMaybeDriveLetter;
   bool mError;
 
 public:
   OriginParser(const nsACString& aOrigin,
                const OriginAttributes& aOriginAttributes)
     : mOrigin(aOrigin)
     , mOriginAttributes(aOriginAttributes)
     , mTokenizer(aOrigin, '+')
     , mAppId(kNoAppId)
     , mPort()
     , mSchemeType(eNone)
     , mState(eExpectingAppIdOrScheme)
     , mInIsolatedMozBrowser(false)
+    , mUniversalFileOrigin(false)
     , mMaybeDriveLetter(false)
     , mError(false)
   { }
 
   static ResultType
   ParseOrigin(const nsACString& aOrigin,
               nsCString& aSpec,
               OriginAttributes* aAttrs);
@@ -8486,21 +8488,27 @@ OriginParser::Parse(nsACString& aSpec, O
     *aAttrs = OriginAttributes(mAppId, mInIsolatedMozBrowser);
   }
 
   nsAutoCString spec(mScheme);
 
   if (mSchemeType == eFile) {
     spec.AppendLiteral("://");
 
-    for (uint32_t count = mPathnameComponents.Length(), index = 0;
-         index < count;
-         index++) {
-      spec.Append('/');
-      spec.Append(mPathnameComponents[index]);
+    if (mUniversalFileOrigin) {
+      MOZ_ASSERT(mPathnameComponents.Length() == 1);
+
+      spec.Append(mPathnameComponents[0]);
+    } else {
+      for (uint32_t count = mPathnameComponents.Length(), index = 0;
+           index < count;
+           index++) {
+        spec.Append('/');
+        spec.Append(mPathnameComponents[index]);
+      }
     }
 
     aSpec = spec;
 
     return ValidOrigin;
   }
 
   if (mSchemeType == eAbout) {
@@ -8658,38 +8666,49 @@ OriginParser::HandleToken(const nsDepend
       if (!aToken.IsEmpty()) {
         QM_WARNING("Expected the second empty token!");
 
         mError = true;
         return;
       }
 
       if (mSchemeType == eFile) {
-        mState = eExpectingEmptyToken3;
+        mState = eExpectingEmptyTokenOrUniversalFileOrigin;
       } else {
         mState = eExpectingHost;
       }
 
       return;
     }
 
-    case eExpectingEmptyToken3: {
+    case eExpectingEmptyTokenOrUniversalFileOrigin: {
       MOZ_ASSERT(mSchemeType == eFile);
 
-      if (!aToken.IsEmpty()) {
-        QM_WARNING("Expected the third empty token!");
-
-        mError = true;
+      if (aToken.IsEmpty()) {
+        mState = mTokenizer.hasMoreTokens()
+                   ? eExpectingEmptyTokenOrDriveLetterOrPathnameComponent
+                   : eComplete;
+
         return;
       }
 
-      mState = mTokenizer.hasMoreTokens()
-                 ? eExpectingEmptyTokenOrDriveLetterOrPathnameComponent
-                 : eComplete;
-
+      if (aToken.EqualsLiteral("UNIVERSAL_FILE_URI_ORIGIN")) {
+        mUniversalFileOrigin = true;
+
+        mPathnameComponents.AppendElement(aToken);
+
+        mState = eComplete;
+
+        return;
+      }
+
+      QM_WARNING("Expected the third empty token or "
+                 "UNIVERSAL_FILE_URI_ORIGIN!");
+
+      mError = true;
       return;
     }
 
     case eExpectingHost: {
       if (aToken.IsEmpty()) {
         QM_WARNING("Expected a host (not an empty string)!");
 
         mError = true;
new file mode 100644
--- /dev/null
+++ b/dom/quota/test/unit/test_specialOrigins.js
@@ -0,0 +1,44 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+async function testSteps()
+{
+  const origins = [
+    {
+      path: "storage/default/file+++UNIVERSAL_FILE_URI_ORIGIN",
+      url: "file:///Test/test.html",
+      persistence: "default"
+    },
+  ];
+
+  info("Setting pref");
+
+  SpecialPowers.setBoolPref("security.fileuri.strict_origin_policy", false);
+
+  info("Creating origin directories");
+
+  for (let origin of origins) {
+    let originDir = getRelativeFile(origin.path);
+    originDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
+  }
+
+  info("Initializing origin directories");
+
+  for (let origin of origins) {
+    let result;
+
+    try {
+      let request = initOrigin(getPrincipal(origin.url),
+                               origin.persistence);
+      result = await requestFinished(request);
+
+      ok(true, "Should not have thrown");
+    } catch(ex) {
+      ok(false, "Should not have thrown");
+    }
+
+    ok(!result, "Origin directory wasn't created");
+  }
+}
--- a/dom/quota/test/unit/xpcshell.ini
+++ b/dom/quota/test/unit/xpcshell.ini
@@ -31,13 +31,14 @@ support-files =
 [test_originAttributesUpgrade.js]
 [test_persist.js]
 [test_persist_eviction.js]
 [test_persist_globalLimit.js]
 [test_persist_groupLimit.js]
 [test_removeAppsUpgrade.js]
 [test_removeLocalStorage.js]
 [test_simpledb.js]
+[test_specialOrigins.js]
 [test_storagePersistentUpgrade.js]
 [test_storagePressure.js]
 [test_tempMetadataCleanup.js]
 [test_unknownFiles.js]
 [test_version2_1upgrade.js]