Bug 1536454 - Part 2 - Add modificationTime attribute to nsIPermission.idl. r=Ehsan
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 18 Apr 2019 13:43:10 +0000
changeset 470076 c4beb7256d16cf3f18739fd20dad8411f4a99092
parent 470075 565279f288410f563f7871360a1d53d8e3f60dd9
child 470077 8c6ec5c528ff0d21865a3d22c743dc21b6061614
push id35888
push useraiakab@mozilla.com
push dateFri, 19 Apr 2019 09:47:45 +0000
treeherdermozilla-central@0160424142d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1536454
milestone68.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 1536454 - Part 2 - Add modificationTime attribute to nsIPermission.idl. r=Ehsan 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,22 +11,23 @@
 
 // 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<nsIPrincipal> nsPermission::ClonePrincipalForPermission(
     nsIPrincipal* aPrincipal) {
   MOZ_ASSERT(aPrincipal);
 
   mozilla::OriginAttributes attrs = aPrincipal->OriginAttributesRef();
   attrs.StripAttributes(mozilla::OriginAttributes::STRIP_USER_CONTEXT_ID |
                         mozilla::OriginAttributes::STRIP_FIRST_PARTY_DOMAIN);
@@ -37,29 +38,28 @@ already_AddRefed<nsIPrincipal> nsPermiss
 
   nsCOMPtr<nsIURI> uri;
   rv = NS_NewURI(getter_AddRefs(uri), originNoSuffix);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
   return mozilla::BasePrincipal::CreateCodebasePrincipal(uri, attrs);
 }
 
-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 =
       nsPermission::ClonePrincipalForPermission(aPrincipal);
   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;
@@ -85,16 +85,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,34 +12,34 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 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);
 
   // This method creates a new nsIPrincipal with a stripped OriginAttributes (no
   // userContextId, and no FirstPartyDomain) and a codebase equal to the origin
   // of 'aPrincipal'.
   static already_AddRefed<nsIPrincipal> ClonePrincipalForPermission(
       nsIPrincipal* aPrincipal);
 
  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
@@ -1870,17 +1870,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;
@@ -1908,17 +1908,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;
@@ -1965,17 +1965,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.)
@@ -2014,17 +2014,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;
 }
 
@@ -2357,19 +2357,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(
@@ -2604,17 +2604,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;
@@ -2650,17 +2651,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));
@@ -2764,19 +2766,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
@@ -468,16 +468,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;
 }
 
@@ -193,18 +193,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(
@@ -227,18 +228,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);
     }
   }