diff --git a/extensions/cookie/nsPermission.cpp b/extensions/cookie/nsPermission.cpp index 34e569d99c89..f0c8e784184c 100644 --- a/extensions/cookie/nsPermission.cpp +++ b/extensions/cookie/nsPermission.cpp @@ -16,12 +16,13 @@ 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::ClonePrincipalForPermission( nsIPrincipal* aPrincipal) { @@ -42,11 +43,9 @@ already_AddRefed nsPermission::ClonePrincipalForPermission( return mozilla::BasePrincipal::CreateCodebasePrincipal(uri, attrs); } -already_AddRefed nsPermission::Create(nsIPrincipal* aPrincipal, - const nsACString& aType, - uint32_t aCapability, - uint32_t aExpireType, - int64_t aExpireTime) { +already_AddRefed 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 principal = @@ -54,7 +53,8 @@ already_AddRefed nsPermission::Create(nsIPrincipal* aPrincipal, NS_ENSURE_TRUE(principal, nullptr); RefPtr permission = - new nsPermission(principal, aType, aCapability, aExpireType, aExpireTime); + new nsPermission(principal, aType, aCapability, aExpireType, aExpireTime, + aModificationTime); return permission.forget(); } @@ -89,6 +89,12 @@ nsPermission::GetExpireTime(int64_t* aExpireTime) { 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) { diff --git a/extensions/cookie/nsPermission.h b/extensions/cookie/nsPermission.h index dcc50cb17f4b..4bbb4ad20445 100644 --- a/extensions/cookie/nsPermission.h +++ b/extensions/cookie/nsPermission.h @@ -17,11 +17,9 @@ class nsPermission : public nsIPermission { NS_DECL_ISUPPORTS NS_DECL_NSIPERMISSION - static already_AddRefed Create(nsIPrincipal* aPrincipal, - const nsACString& aType, - uint32_t aCapability, - uint32_t aExpireType, - int64_t aExpireTime); + static already_AddRefed 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 @@ -31,7 +29,8 @@ class nsPermission : public nsIPermission { 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(){}; @@ -40,6 +39,7 @@ class nsPermission : public nsIPermission { uint32_t mCapability; uint32_t mExpireType; int64_t mExpireTime; + int64_t mModificationTime; }; #endif // nsPermission_h__ diff --git a/extensions/cookie/nsPermissionManager.cpp b/extensions/cookie/nsPermissionManager.cpp index 46eb7a57afa7..369c29eca3d7 100644 --- a/extensions/cookie/nsPermissionManager.cpp +++ b/extensions/cookie/nsPermissionManager.cpp @@ -1875,7 +1875,7 @@ nsresult nsPermissionManager::AddInternal( if (aNotifyOperation == eNotify) { NotifyObserversWithPermission(aPrincipal, mTypeArray[typeIndex], aPermission, aExpireType, aExpireTime, - u"added"); + aModificationTime, u"added"); } break; @@ -1913,7 +1913,7 @@ nsresult nsPermissionManager::AddInternal( 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. @@ -1970,7 +1970,7 @@ nsresult nsPermissionManager::AddInternal( if (aNotifyOperation == eNotify) { NotifyObserversWithPermission(aPrincipal, mTypeArray[typeIndex], aPermission, aExpireType, aExpireTime, - u"changed"); + aModificationTime, u"changed"); } break; @@ -2019,7 +2019,7 @@ nsresult nsPermissionManager::AddInternal( if (aNotifyOperation == eNotify) { NotifyObserversWithPermission(aPrincipal, mTypeArray[typeIndex], aPermission, aExpireType, aExpireTime, - u"changed"); + aModificationTime, u"changed"); } } break; @@ -2362,9 +2362,9 @@ nsPermissionManager::GetPermissionObject(nsIPrincipal* aPrincipal, NS_ENSURE_SUCCESS(rv, rv); PermissionEntry& perm = entry->GetPermissions()[idx]; - nsCOMPtr r = - nsPermission::Create(principal, mTypeArray[perm.mType], perm.mPermission, - perm.mExpireType, perm.mExpireTime); + nsCOMPtr r = nsPermission::Create( + principal, mTypeArray[perm.mType], perm.mPermission, perm.mExpireType, + perm.mExpireTime, perm.mModificationTime); if (NS_WARN_IF(!r)) { return NS_ERROR_FAILURE; } @@ -2609,7 +2609,8 @@ NS_IMETHODIMP nsPermissionManager::GetAllWithTypePrefix( RefPtr 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; } @@ -2655,7 +2656,8 @@ nsPermissionManager::GetAllForPrincipal(nsIPrincipal* aPrincipal, nsCOMPtr 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; } @@ -2769,9 +2771,11 @@ nsresult nsPermissionManager::RemoveAllFromMemory() { // 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 permission = nsPermission::Create( - aPrincipal, aType, aPermission, aExpireType, aExpireTime); + uint32_t aExpireType, int64_t aExpireTime, int64_t aModificationTime, + const char16_t* aData) { + nsCOMPtr permission = + nsPermission::Create(aPrincipal, aType, aPermission, aExpireType, + aExpireTime, aModificationTime); if (permission) NotifyObservers(permission, aData); } diff --git a/extensions/cookie/nsPermissionManager.h b/extensions/cookie/nsPermissionManager.h index f919dcdd47ed..8f766c164d06 100644 --- a/extensions/cookie/nsPermissionManager.h +++ b/extensions/cookie/nsPermissionManager.h @@ -473,6 +473,7 @@ class nsPermissionManager final : public nsIPermissionManager, 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); diff --git a/netwerk/base/nsIPermission.idl b/netwerk/base/nsIPermission.idl index c5ddd90fe5ef..cd938958f234 100644 --- a/netwerk/base/nsIPermission.idl +++ b/netwerk/base/nsIPermission.idl @@ -50,6 +50,12 @@ interface nsIPermission : nsISupports */ 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. * diff --git a/netwerk/cookie/CookieSettings.cpp b/netwerk/cookie/CookieSettings.cpp index 6e1996b7d0f7..13981fc75a25 100644 --- a/netwerk/cookie/CookieSettings.cpp +++ b/netwerk/cookie/CookieSettings.cpp @@ -144,7 +144,7 @@ CookieSettings::CookiePermission(nsIPrincipal* aPrincipal, // race conditions. nsCOMPtr 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); } @@ -198,8 +198,9 @@ void CookieSettings::Serialize(CookieSettingsArgs& aData) { continue; } - nsCOMPtr permission = nsPermission::Create( - principal, NS_LITERAL_CSTRING("cookie"), data.cookiePermission(), 0, 0); + nsCOMPtr permission = + nsPermission::Create(principal, NS_LITERAL_CSTRING("cookie"), + data.cookiePermission(), 0, 0, 0); if (NS_WARN_IF(!permission)) { continue; } @@ -232,8 +233,9 @@ void CookieSettings::Merge(const CookieSettingsArgs& aData) { continue; } - nsCOMPtr permission = nsPermission::Create( - principal, NS_LITERAL_CSTRING("cookie"), data.cookiePermission(), 0, 0); + nsCOMPtr permission = + nsPermission::Create(principal, NS_LITERAL_CSTRING("cookie"), + data.cookiePermission(), 0, 0, 0); if (NS_WARN_IF(!permission)) { continue; }