Bug 1536454 - Part 2 - Add modificationTime attribute to nsIPermission.idl. r=Ehsan a=pascalc
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 18 Apr 2019 13:43:10 +0000
changeset 526332 fbe79e8981f7a1894ffcbc24ffa6457e48c24869
parent 526331 f71a18e81a6989dfd853195cb5abd0de7df068fa
child 526333 fe7f1569e8d65649f12ebe8f5e2be87b01ea97c0
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan, pascalc
bugs1536454
milestone67.0
Bug 1536454 - Part 2 - Add modificationTime attribute to nsIPermission.idl. r=Ehsan a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D26943
extensions/cookie/nsPermission.cpp
extensions/cookie/nsPermission.h
extensions/cookie/nsPermissionManager.cpp
extensions/cookie/nsPermissionManager.h
netwerk/base/nsIPermission.idl
netwerk/cookie/CookieSettings.cpp
--- a/extensions/cookie/nsPermission.cpp
+++ b/extensions/cookie/nsPermission.cpp
@@ -11,37 +11,37 @@
 
 // nsPermission Implementation
 
 NS_IMPL_CLASSINFO(nsPermission, nullptr, 0, {0})
 NS_IMPL_ISUPPORTS_CI(nsPermission, nsIPermission)
 
 nsPermission::nsPermission(nsIPrincipal* aPrincipal, const nsACString& aType,
                            uint32_t aCapability, uint32_t aExpireType,
-                           int64_t aExpireTime)
+                           int64_t aExpireTime, int64_t aModificationTime)
     : mPrincipal(aPrincipal),
       mType(aType),
       mCapability(aCapability),
       mExpireType(aExpireType),
-      mExpireTime(aExpireTime) {}
+      mExpireTime(aExpireTime),
+      mModificationTime(aModificationTime) {}
 
-already_AddRefed<nsPermission> nsPermission::Create(nsIPrincipal* aPrincipal,
-                                                    const nsACString& aType,
-                                                    uint32_t aCapability,
-                                                    uint32_t aExpireType,
-                                                    int64_t aExpireTime) {
+already_AddRefed<nsPermission> nsPermission::Create(
+    nsIPrincipal* aPrincipal, const nsACString& aType, uint32_t aCapability,
+    uint32_t aExpireType, int64_t aExpireTime, int64_t aModificationTime) {
   NS_ENSURE_TRUE(aPrincipal, nullptr);
   nsCOMPtr<nsIPrincipal> principal =
       mozilla::BasePrincipal::Cast(aPrincipal)
           ->CloneStrippingUserContextIdAndFirstPartyDomain();
 
   NS_ENSURE_TRUE(principal, nullptr);
 
   RefPtr<nsPermission> permission =
-      new nsPermission(principal, aType, aCapability, aExpireType, aExpireTime);
+      new nsPermission(principal, aType, aCapability, aExpireType, aExpireTime,
+                       aModificationTime);
   return permission.forget();
 }
 
 NS_IMETHODIMP
 nsPermission::GetPrincipal(nsIPrincipal** aPrincipal) {
   nsCOMPtr<nsIPrincipal> copy = mPrincipal;
   copy.forget(aPrincipal);
   return NS_OK;
@@ -67,16 +67,22 @@ nsPermission::GetExpireType(uint32_t* aE
 
 NS_IMETHODIMP
 nsPermission::GetExpireTime(int64_t* aExpireTime) {
   *aExpireTime = mExpireTime;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsPermission::GetModificationTime(int64_t* aModificationTime) {
+  *aModificationTime = mModificationTime;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsPermission::Matches(nsIPrincipal* aPrincipal, bool aExactHost,
                       bool* aMatches) {
   NS_ENSURE_ARG_POINTER(aPrincipal);
   NS_ENSURE_ARG_POINTER(aMatches);
 
   *aMatches = false;
 
   nsCOMPtr<nsIPrincipal> principal =
--- a/extensions/cookie/nsPermission.h
+++ b/extensions/cookie/nsPermission.h
@@ -12,28 +12,28 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 class nsPermission : public nsIPermission {
  public:
   // nsISupports
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPERMISSION
 
-  static already_AddRefed<nsPermission> Create(nsIPrincipal* aPrincipal,
-                                               const nsACString& aType,
-                                               uint32_t aCapability,
-                                               uint32_t aExpireType,
-                                               int64_t aExpireTime);
+  static already_AddRefed<nsPermission> Create(
+      nsIPrincipal* aPrincipal, const nsACString& aType, uint32_t aCapability,
+      uint32_t aExpireType, int64_t aExpireTime, int64_t aModificationTime);
 
  protected:
   nsPermission(nsIPrincipal* aPrincipal, const nsACString& aType,
-               uint32_t aCapability, uint32_t aExpireType, int64_t aExpireTime);
+               uint32_t aCapability, uint32_t aExpireType, int64_t aExpireTime,
+               int64_t aModificationTime);
 
   virtual ~nsPermission(){};
 
   nsCOMPtr<nsIPrincipal> mPrincipal;
   nsCString mType;
   uint32_t mCapability;
   uint32_t mExpireType;
   int64_t mExpireTime;
+  int64_t mModificationTime;
 };
 
 #endif  // nsPermission_h__
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -1883,17 +1883,17 @@ nsresult nsPermissionManager::AddInterna
       if (aDBOperation == eWriteToDB && IsPersistentExpire(aExpireType)) {
         UpdateDB(op, mStmtInsert, id, origin, aType, aPermission, aExpireType,
                  aExpireTime, aModificationTime);
       }
 
       if (aNotifyOperation == eNotify) {
         NotifyObserversWithPermission(aPrincipal, mTypeArray[typeIndex],
                                       aPermission, aExpireType, aExpireTime,
-                                      u"added");
+                                      aModificationTime, u"added");
       }
 
       break;
     }
 
     case eOperationRemoving: {
       PermissionEntry oldPermissionEntry = entry->GetPermissions()[index];
       id = oldPermissionEntry.mID;
@@ -1921,17 +1921,17 @@ nsresult nsPermissionManager::AddInterna
         // parameters.
         UpdateDB(op, mStmtDelete, id, EmptyCString(), EmptyCString(), 0,
                  nsIPermissionManager::EXPIRE_NEVER, 0, 0);
 
       if (aNotifyOperation == eNotify) {
         NotifyObserversWithPermission(
             aPrincipal, mTypeArray[typeIndex], oldPermissionEntry.mPermission,
             oldPermissionEntry.mExpireType, oldPermissionEntry.mExpireTime,
-            u"deleted");
+            oldPermissionEntry.mModificationTime, u"deleted");
       }
 
       // If there are no more permissions stored for that entry, clear it.
       if (entry->GetPermissions().IsEmpty()) {
         mPermissionTable.RemoveEntry(entry);
       }
 
       break;
@@ -1978,17 +1978,17 @@ nsresult nsPermissionManager::AddInterna
         // expireType/expireTime/modificationTime here. We pass dummy values for
         // all other parameters.
         UpdateDB(op, mStmtUpdate, id, EmptyCString(), EmptyCString(),
                  aPermission, aExpireType, aExpireTime, aModificationTime);
 
       if (aNotifyOperation == eNotify) {
         NotifyObserversWithPermission(aPrincipal, mTypeArray[typeIndex],
                                       aPermission, aExpireType, aExpireTime,
-                                      u"changed");
+                                      aModificationTime, u"changed");
       }
 
       break;
     }
     case eOperationReplacingDefault: {
       // this is handling the case when we have an existing permission
       // entry that was created as a "default" (and thus isn't in the DB) with
       // an explicit permission (that may include UNKNOWN_ACTION.)
@@ -2027,17 +2027,17 @@ nsresult nsPermissionManager::AddInterna
       if (aDBOperation == eWriteToDB && IsPersistentExpire(aExpireType)) {
         UpdateDB(eOperationAdding, mStmtInsert, id, origin, aType, aPermission,
                  aExpireType, aExpireTime, aModificationTime);
       }
 
       if (aNotifyOperation == eNotify) {
         NotifyObserversWithPermission(aPrincipal, mTypeArray[typeIndex],
                                       aPermission, aExpireType, aExpireTime,
-                                      u"changed");
+                                      aModificationTime, u"changed");
       }
 
     } break;
   }
 
   return NS_OK;
 }
 
@@ -2351,19 +2351,19 @@ nsPermissionManager::GetPermissionObject
   }
 
   nsCOMPtr<nsIPrincipal> principal;
   nsresult rv = GetPrincipalFromOrigin(entry->GetKey()->mOrigin,
                                        getter_AddRefs(principal));
   NS_ENSURE_SUCCESS(rv, rv);
 
   PermissionEntry& perm = entry->GetPermissions()[idx];
-  nsCOMPtr<nsIPermission> r =
-      nsPermission::Create(principal, mTypeArray[perm.mType], perm.mPermission,
-                           perm.mExpireType, perm.mExpireTime);
+  nsCOMPtr<nsIPermission> r = nsPermission::Create(
+      principal, mTypeArray[perm.mType], perm.mPermission, perm.mExpireType,
+      perm.mExpireTime, perm.mModificationTime);
   if (NS_WARN_IF(!r)) {
     return NS_ERROR_FAILURE;
   }
   r.forget(aResult);
   return NS_OK;
 }
 
 nsresult nsPermissionManager::CommonTestPermissionInternal(
@@ -2598,17 +2598,18 @@ NS_IMETHODIMP nsPermissionManager::GetAl
       nsresult rv = GetPrincipalFromOrigin(entry->GetKey()->mOrigin,
                                            getter_AddRefs(principal));
       if (NS_FAILED(rv)) {
         continue;
       }
 
       RefPtr<nsIPermission> permission = nsPermission::Create(
           principal, mTypeArray[permEntry.mType], permEntry.mPermission,
-          permEntry.mExpireType, permEntry.mExpireTime);
+          permEntry.mExpireType, permEntry.mExpireTime,
+          permEntry.mModificationTime);
       if (NS_WARN_IF(!permission)) {
         continue;
       }
       aResult.AppendElement(std::move(permission));
     }
   }
 
   return NS_OK;
@@ -2644,17 +2645,18 @@ nsPermissionManager::GetAllForPrincipal(
     for (const auto& permEntry : entry->GetPermissions()) {
       // Only return custom permissions
       if (permEntry.mPermission == nsIPermissionManager::UNKNOWN_ACTION) {
         continue;
       }
 
       nsCOMPtr<nsIPermission> permission = nsPermission::Create(
           aPrincipal, mTypeArray[permEntry.mType], permEntry.mPermission,
-          permEntry.mExpireType, permEntry.mExpireTime);
+          permEntry.mExpireType, permEntry.mExpireTime,
+          permEntry.mModificationTime);
       if (NS_WARN_IF(!permission)) {
         continue;
       }
       array.AppendObject(permission);
     }
   }
 
   return NS_NewArrayEnumerator(aEnum, array, NS_GET_IID(nsIPermission));
@@ -2745,19 +2747,21 @@ nsresult nsPermissionManager::RemoveAllF
 
   return NS_OK;
 }
 
 // wrapper function for mangling (host,type,perm,expireType,expireTime)
 // set into an nsIPermission.
 void nsPermissionManager::NotifyObserversWithPermission(
     nsIPrincipal* aPrincipal, const nsACString& aType, uint32_t aPermission,
-    uint32_t aExpireType, int64_t aExpireTime, const char16_t* aData) {
-  nsCOMPtr<nsIPermission> permission = nsPermission::Create(
-      aPrincipal, aType, aPermission, aExpireType, aExpireTime);
+    uint32_t aExpireType, int64_t aExpireTime, int64_t aModificationTime,
+    const char16_t* aData) {
+  nsCOMPtr<nsIPermission> permission =
+      nsPermission::Create(aPrincipal, aType, aPermission, aExpireType,
+                           aExpireTime, aModificationTime);
   if (permission) NotifyObservers(permission, aData);
 }
 
 // notify observers that the permission list changed. there are four possible
 // values for aData:
 // "deleted" means a permission was deleted. aPermission is the deleted
 // permission. "added"   means a permission was added. aPermission is the added
 // permission. "changed" means a permission was altered. aPermission is the new
--- a/extensions/cookie/nsPermissionManager.h
+++ b/extensions/cookie/nsPermissionManager.h
@@ -470,16 +470,17 @@ class nsPermissionManager final : public
   nsresult Import();
   nsresult ImportDefaults();
   nsresult _DoImport(nsIInputStream* inputStream, mozIStorageConnection* aConn);
   nsresult Read();
   void NotifyObserversWithPermission(nsIPrincipal* aPrincipal,
                                      const nsACString& aType,
                                      uint32_t aPermission, uint32_t aExpireType,
                                      int64_t aExpireTime,
+                                     int64_t aModificationTime,
                                      const char16_t* aData);
   void NotifyObservers(nsIPermission* aPermission, const char16_t* aData);
 
   // Finalize all statements, close the DB and null it.
   // if aRebuildOnSuccess, reinitialize database
   void CloseDB(bool aRebuildOnSuccess = false);
 
   nsresult RemoveAllInternal(bool aNotifyObservers);
--- a/netwerk/base/nsIPermission.idl
+++ b/netwerk/base/nsIPermission.idl
@@ -46,16 +46,22 @@ interface nsIPermission : nsISupports
 
     /**
      * The expiration time of the permission (milliseconds since Jan 1 1970
      * 0:00:00).
      */
     readonly attribute int64_t expireTime;
 
     /**
+     * The last modification time of the permission (milliseconds since Jan 1 1970
+     * 0:00:00).
+     */
+    readonly attribute int64_t modificationTime;
+
+    /**
      * Test whether a principal would be affected by this permission.
      *
      * @param principal  the principal to test
      * @param exactHost  If true, only the specific host will be matched,
      *                   @see nsIPermissionManager::testExactPermission.
      *                   If false, subdomains will also be searched,
      *                   @see nsIPermissionManager::testPermission.
      */
--- a/netwerk/cookie/CookieSettings.cpp
+++ b/netwerk/cookie/CookieSettings.cpp
@@ -139,17 +139,17 @@ CookieSettings::CookiePermission(nsIPrin
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Let's store the permission, also if the result is UNKNOWN in order to avoid
   // race conditions.
 
   nsCOMPtr<nsIPermission> permission = nsPermission::Create(
-      aPrincipal, NS_LITERAL_CSTRING("cookie"), *aCookiePermission, 0, 0);
+      aPrincipal, NS_LITERAL_CSTRING("cookie"), *aCookiePermission, 0, 0, 0);
   if (permission) {
     mCookiePermissions.AppendElement(permission);
   }
 
   mToBeMerged = true;
   return NS_OK;
 }
 
@@ -192,18 +192,19 @@ void CookieSettings::Serialize(CookieSet
   CookiePermissionList list;
   for (const CookiePermissionData& data : aData.cookiePermissions()) {
     nsCOMPtr<nsIPrincipal> principal =
         PrincipalInfoToPrincipal(data.principalInfo());
     if (NS_WARN_IF(!principal)) {
       continue;
     }
 
-    nsCOMPtr<nsIPermission> permission = nsPermission::Create(
-        principal, NS_LITERAL_CSTRING("cookie"), data.cookiePermission(), 0, 0);
+    nsCOMPtr<nsIPermission> permission =
+        nsPermission::Create(principal, NS_LITERAL_CSTRING("cookie"),
+                             data.cookiePermission(), 0, 0, 0);
     if (NS_WARN_IF(!permission)) {
       continue;
     }
 
     list.AppendElement(permission);
   }
 
   RefPtr<CookieSettings> cookieSettings = new CookieSettings(
@@ -226,18 +227,19 @@ void CookieSettings::Merge(const CookieS
 
   for (const CookiePermissionData& data : aData.cookiePermissions()) {
     nsCOMPtr<nsIPrincipal> principal =
         PrincipalInfoToPrincipal(data.principalInfo());
     if (NS_WARN_IF(!principal)) {
       continue;
     }
 
-    nsCOMPtr<nsIPermission> permission = nsPermission::Create(
-        principal, NS_LITERAL_CSTRING("cookie"), data.cookiePermission(), 0, 0);
+    nsCOMPtr<nsIPermission> permission =
+        nsPermission::Create(principal, NS_LITERAL_CSTRING("cookie"),
+                             data.cookiePermission(), 0, 0, 0);
     if (NS_WARN_IF(!permission)) {
       continue;
     }
 
     if (!mCookiePermissions.Contains(permission, comparator)) {
       mCookiePermissions.AppendElement(permission);
     }
   }