Bug 1286798 - Part 48: Add ParseOrigin() method to the quota manager; r=asuth draft
authorJan Varga <jan.varga@gmail.com>
Wed, 24 Oct 2018 06:59:10 +0200
changeset 481726 050bd30da968d942447f19eb1a9879e3ac1d89d7
parent 481725 cf3015b13f989acc8dd401d057b2458fe25067f9
child 481727 e2301860239fb3e343af4f53d73a06b306d3be7e
push id10
push userbugmail@asutherland.org
push dateSun, 18 Nov 2018 18:57:42 +0000
reviewersasuth
bugs1286798
milestone65.0a1
Bug 1286798 - Part 48: Add ParseOrigin() method to the quota manager; r=asuth
dom/quota/ActorsParent.cpp
dom/quota/QuotaManager.h
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -6097,16 +6097,41 @@ QuotaManager::AreOriginsEqualOnDisk(nsAC
   SanitizeOriginString(origin1Sanitized);
 
   nsCString origin2Sanitized(aOrigin2);
   SanitizeOriginString(origin2Sanitized);
 
   return origin1Sanitized == origin2Sanitized;
 }
 
+// static
+bool
+QuotaManager::ParseOrigin(const nsACString& aOrigin,
+                          nsCString& aSpec,
+                          OriginAttributes* aAttrs)
+{
+  MOZ_ASSERT(aAttrs);
+
+  if (aOrigin.Equals(kChromeOrigin)) {
+    aSpec = kChromeOrigin;
+    return true;
+  }
+
+  nsCString sanitizedOrigin(aOrigin);
+  SanitizeOriginString(sanitizedOrigin);
+
+  OriginParser::ResultType result =
+    OriginParser::ParseOrigin(sanitizedOrigin, aSpec, aAttrs);
+  if (NS_WARN_IF(result != OriginParser::ValidOrigin)) {
+    return false;
+  }
+
+  return true;
+}
+
 uint64_t
 QuotaManager::LockedCollectOriginsForEviction(
                                   uint64_t aMinSizeToBeFreed,
                                   nsTArray<RefPtr<DirectoryLockImpl>>& aLocks)
 {
   mQuotaMutex.AssertCurrentThreadOwns();
 
   RefPtr<CollectOriginsHelper> helper =
--- a/dom/quota/QuotaManager.h
+++ b/dom/quota/QuotaManager.h
@@ -27,16 +27,22 @@ class mozIStorageConnection;
 class nsIEventTarget;
 class nsIPrincipal;
 class nsIThread;
 class nsITimer;
 class nsIURI;
 class nsPIDOMWindowOuter;
 class nsIRunnable;
 
+namespace mozilla {
+
+class OriginAttributes;
+
+} // namespace mozilla
+
 BEGIN_QUOTA_NAMESPACE
 
 class DirectoryLockImpl;
 class GroupInfo;
 class GroupInfoPair;
 class OriginInfo;
 class OriginScope;
 class QuotaObject;
@@ -426,16 +432,21 @@ public:
 
   static void
   ChromeOrigin(nsACString& aOrigin);
 
   static bool
   AreOriginsEqualOnDisk(nsACString& aOrigin1,
                         nsACString& aOrigin2);
 
+  static bool
+  ParseOrigin(const nsACString& aOrigin,
+              nsCString& aSpec,
+              OriginAttributes* aAttrs);
+
 private:
   QuotaManager();
 
   virtual ~QuotaManager();
 
   nsresult
   Init(const nsAString& aBaseDirPath);