зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1363541 - Modernize the PermissionManager - part 1 - nsPermission to mozilla::Permission, r=timhuang
Differential Revision: https://phabricator.services.mozilla.com/D69963 --HG-- rename : extensions/permissions/nsPermission.cpp => extensions/permissions/Permission.cpp rename : extensions/permissions/nsPermission.h => extensions/permissions/Permission.h extra : moz-landing-system : lando
This commit is contained in:
Родитель
a52ec9b166
Коммит
23b424cd70
|
@ -209,7 +209,7 @@
|
|||
# include "signaling/src/peerconnection/WebrtcGlobalChild.h"
|
||||
#endif
|
||||
|
||||
#include "nsPermission.h"
|
||||
#include "mozilla/Permission.h"
|
||||
#include "nsPermissionManager.h"
|
||||
|
||||
#include "PermissionMessageUtils.h"
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
#include "mozilla/dom/PermissionStatus.h"
|
||||
|
||||
#include "mozilla/AsyncEventDispatcher.h"
|
||||
#include "mozilla/Permission.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "PermissionObserver.h"
|
||||
#include "PermissionUtils.h"
|
||||
#include "nsPermission.h"
|
||||
#include "PermissionDelegateHandler.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -105,7 +105,7 @@ already_AddRefed<nsIPrincipal> PermissionStatus::GetPrincipal() const {
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal =
|
||||
nsPermission::ClonePrincipalForPermission(doc->NodePrincipal());
|
||||
Permission::ClonePrincipalForPermission(doc->NodePrincipal());
|
||||
NS_ENSURE_TRUE(principal, nullptr);
|
||||
|
||||
return principal.forget();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsPermission.h"
|
||||
#include "mozilla/Permission.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "nsIEffectiveTLDService.h"
|
||||
|
@ -12,12 +12,14 @@
|
|||
#include "mozilla/BasePrincipal.h"
|
||||
#include "mozilla/StaticPrefs_permissions.h"
|
||||
|
||||
// nsPermission Implementation
|
||||
namespace mozilla {
|
||||
|
||||
NS_IMPL_CLASSINFO(nsPermission, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(nsPermission, nsIPermission)
|
||||
// Permission Implementation
|
||||
|
||||
nsPermission::nsPermission(nsIPrincipal* aPrincipal, const nsACString& aType,
|
||||
NS_IMPL_CLASSINFO(Permission, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(Permission, nsIPermission)
|
||||
|
||||
Permission::Permission(nsIPrincipal* aPrincipal, const nsACString& aType,
|
||||
uint32_t aCapability, uint32_t aExpireType,
|
||||
int64_t aExpireTime, int64_t aModificationTime)
|
||||
: mPrincipal(aPrincipal),
|
||||
|
@ -27,7 +29,7 @@ nsPermission::nsPermission(nsIPrincipal* aPrincipal, const nsACString& aType,
|
|||
mExpireTime(aExpireTime),
|
||||
mModificationTime(aModificationTime) {}
|
||||
|
||||
already_AddRefed<nsIPrincipal> nsPermission::ClonePrincipalForPermission(
|
||||
already_AddRefed<nsIPrincipal> Permission::ClonePrincipalForPermission(
|
||||
nsIPrincipal* aPrincipal) {
|
||||
MOZ_ASSERT(aPrincipal);
|
||||
|
||||
|
@ -47,68 +49,67 @@ already_AddRefed<nsIPrincipal> nsPermission::ClonePrincipalForPermission(
|
|||
return mozilla::BasePrincipal::CreateContentPrincipal(uri, attrs);
|
||||
}
|
||||
|
||||
already_AddRefed<nsPermission> nsPermission::Create(
|
||||
already_AddRefed<Permission> Permission::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);
|
||||
Permission::ClonePrincipalForPermission(aPrincipal);
|
||||
NS_ENSURE_TRUE(principal, nullptr);
|
||||
|
||||
RefPtr<nsPermission> permission =
|
||||
new nsPermission(principal, aType, aCapability, aExpireType, aExpireTime,
|
||||
RefPtr<Permission> permission =
|
||||
new Permission(principal, aType, aCapability, aExpireType, aExpireTime,
|
||||
aModificationTime);
|
||||
return permission.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPermission::GetPrincipal(nsIPrincipal** aPrincipal) {
|
||||
Permission::GetPrincipal(nsIPrincipal** aPrincipal) {
|
||||
nsCOMPtr<nsIPrincipal> copy = mPrincipal;
|
||||
copy.forget(aPrincipal);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPermission::GetType(nsACString& aType) {
|
||||
Permission::GetType(nsACString& aType) {
|
||||
aType = mType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPermission::GetCapability(uint32_t* aCapability) {
|
||||
Permission::GetCapability(uint32_t* aCapability) {
|
||||
*aCapability = mCapability;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPermission::GetExpireType(uint32_t* aExpireType) {
|
||||
Permission::GetExpireType(uint32_t* aExpireType) {
|
||||
*aExpireType = mExpireType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPermission::GetExpireTime(int64_t* aExpireTime) {
|
||||
Permission::GetExpireTime(int64_t* aExpireTime) {
|
||||
*aExpireTime = mExpireTime;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPermission::GetModificationTime(int64_t* aModificationTime) {
|
||||
Permission::GetModificationTime(int64_t* aModificationTime) {
|
||||
*aModificationTime = mModificationTime;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPermission::Matches(nsIPrincipal* aPrincipal, bool aExactHost,
|
||||
bool* aMatches) {
|
||||
Permission::Matches(nsIPrincipal* aPrincipal, bool aExactHost, bool* aMatches) {
|
||||
NS_ENSURE_ARG_POINTER(aPrincipal);
|
||||
NS_ENSURE_ARG_POINTER(aMatches);
|
||||
|
||||
*aMatches = false;
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal =
|
||||
nsPermission::ClonePrincipalForPermission(aPrincipal);
|
||||
Permission::ClonePrincipalForPermission(aPrincipal);
|
||||
if (!principal) {
|
||||
*aMatches = false;
|
||||
return NS_OK;
|
||||
|
@ -118,7 +119,7 @@ nsPermission::Matches(nsIPrincipal* aPrincipal, bool aExactHost,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPermission::MatchesPrincipalForPermission(nsIPrincipal* aPrincipal,
|
||||
Permission::MatchesPrincipalForPermission(nsIPrincipal* aPrincipal,
|
||||
bool aExactHost, bool* aMatches) {
|
||||
NS_ENSURE_ARG_POINTER(aPrincipal);
|
||||
NS_ENSURE_ARG_POINTER(aMatches);
|
||||
|
@ -207,9 +208,8 @@ nsPermission::MatchesPrincipalForPermission(nsIPrincipal* aPrincipal,
|
|||
if (NS_FAILED(rv)) {
|
||||
if (rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
|
||||
return NS_OK;
|
||||
} else {
|
||||
return rv;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ nsPermission::MatchesPrincipalForPermission(nsIPrincipal* aPrincipal,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPermission::MatchesURI(nsIURI* aURI, bool aExactHost, bool* aMatches) {
|
||||
Permission::MatchesURI(nsIURI* aURI, bool aExactHost, bool* aMatches) {
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
|
||||
mozilla::OriginAttributes attrs;
|
||||
|
@ -228,3 +228,5 @@ nsPermission::MatchesURI(nsIURI* aURI, bool aExactHost, bool* aMatches) {
|
|||
|
||||
return Matches(principal, aExactHost, aMatches);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
|
@ -3,22 +3,24 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef nsPermission_h__
|
||||
#define nsPermission_h__
|
||||
#ifndef mozilla_Permission_h
|
||||
#define mozilla_Permission_h
|
||||
|
||||
#include "nsIPermission.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsPermission : public nsIPermission {
|
||||
class Permission : public nsIPermission {
|
||||
public:
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPERMISSION
|
||||
|
||||
static already_AddRefed<nsPermission> Create(
|
||||
static already_AddRefed<Permission> Create(
|
||||
nsIPrincipal* aPrincipal, const nsACString& aType, uint32_t aCapability,
|
||||
uint32_t aExpireType, int64_t aExpireTime, int64_t aModificationTime);
|
||||
|
||||
|
@ -28,11 +30,11 @@ class nsPermission : public nsIPermission {
|
|||
nsIPrincipal* aPrincipal);
|
||||
|
||||
protected:
|
||||
nsPermission(nsIPrincipal* aPrincipal, const nsACString& aType,
|
||||
Permission(nsIPrincipal* aPrincipal, const nsACString& aType,
|
||||
uint32_t aCapability, uint32_t aExpireType, int64_t aExpireTime,
|
||||
int64_t aModificationTime);
|
||||
|
||||
virtual ~nsPermission(){};
|
||||
virtual ~Permission() = default;
|
||||
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
nsCString mType;
|
||||
|
@ -42,4 +44,6 @@ class nsPermission : public nsIPermission {
|
|||
int64_t mModificationTime;
|
||||
};
|
||||
|
||||
#endif // nsPermission_h__
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_Permission_h
|
|
@ -14,9 +14,13 @@ EXPORTS += [
|
|||
'PermissionDelegateHandler.h',
|
||||
]
|
||||
|
||||
EXPORTS.mozilla += [
|
||||
'Permission.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'nsPermission.cpp',
|
||||
'nsPermissionManager.cpp',
|
||||
'Permission.cpp',
|
||||
'PermissionDelegateHandler.cpp',
|
||||
]
|
||||
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
#include "mozilla/ContentBlockingUserInteraction.h"
|
||||
#include "mozilla/ContentPrincipal.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/Permission.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "nsPermissionManager.h"
|
||||
#include "nsPermission.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsTArray.h"
|
||||
|
@ -2338,7 +2338,7 @@ nsPermissionManager::GetPermissionObject(nsIPrincipal* aPrincipal,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PermissionEntry& perm = entry->GetPermissions()[idx];
|
||||
nsCOMPtr<nsIPermission> r = nsPermission::Create(
|
||||
nsCOMPtr<nsIPermission> r = Permission::Create(
|
||||
principal, mTypeArray[perm.mType], perm.mPermission, perm.mExpireType,
|
||||
perm.mExpireTime, perm.mModificationTime);
|
||||
if (NS_WARN_IF(!r)) {
|
||||
|
@ -2567,7 +2567,7 @@ NS_IMETHODIMP nsPermissionManager::GetAllWithTypePrefix(
|
|||
continue;
|
||||
}
|
||||
|
||||
RefPtr<nsIPermission> permission = nsPermission::Create(
|
||||
RefPtr<nsIPermission> permission = Permission::Create(
|
||||
principal, mTypeArray[permEntry.mType], permEntry.mPermission,
|
||||
permEntry.mExpireType, permEntry.mExpireTime,
|
||||
permEntry.mModificationTime);
|
||||
|
@ -2663,7 +2663,7 @@ nsPermissionManager::GetAllForPrincipal(
|
|||
index++;
|
||||
}
|
||||
|
||||
RefPtr<nsIPermission> permission = nsPermission::Create(
|
||||
RefPtr<nsIPermission> permission = Permission::Create(
|
||||
aPrincipal, mTypeArray[perm.mType], perm.mPermission,
|
||||
perm.mExpireType, perm.mExpireTime, perm.mModificationTime);
|
||||
if (NS_WARN_IF(!permission)) {
|
||||
|
@ -2674,7 +2674,7 @@ nsPermissionManager::GetAllForPrincipal(
|
|||
}
|
||||
|
||||
for (const auto& perm : strippedPerms) {
|
||||
RefPtr<nsIPermission> permission = nsPermission::Create(
|
||||
RefPtr<nsIPermission> permission = Permission::Create(
|
||||
aPrincipal, mTypeArray[perm.mType], perm.mPermission, perm.mExpireType,
|
||||
perm.mExpireTime, perm.mModificationTime);
|
||||
if (NS_WARN_IF(!permission)) {
|
||||
|
@ -2795,7 +2795,7 @@ void nsPermissionManager::NotifyObserversWithPermission(
|
|||
uint32_t aExpireType, int64_t aExpireTime, int64_t aModificationTime,
|
||||
const char16_t* aData) {
|
||||
nsCOMPtr<nsIPermission> permission =
|
||||
nsPermission::Create(aPrincipal, aType, aPermission, aExpireType,
|
||||
Permission::Create(aPrincipal, aType, aPermission, aExpireType,
|
||||
aExpireTime, aModificationTime);
|
||||
if (permission) NotifyObservers(permission, aData);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "nsTHashtable.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsPermission.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsCOMArray.h"
|
||||
|
@ -23,6 +22,7 @@
|
|||
#include "nsRefPtrHashtable.h"
|
||||
#include "mozilla/BasePrincipal.h"
|
||||
#include "mozilla/ExpandedPrincipal.h"
|
||||
#include "mozilla/Permission.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "mozilla/Variant.h"
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "mozilla/dom/BrowsingContext.h"
|
||||
#include "mozilla/net/CookieJarSettings.h"
|
||||
#include "mozilla/net/NeckoChannelParams.h"
|
||||
#include "mozilla/Permission.h"
|
||||
#include "mozilla/SchedulerGroup.h"
|
||||
#include "mozilla/StaticPrefs_network.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
@ -17,7 +18,6 @@
|
|||
#if defined(MOZ_THUNDERBIRD) || defined(MOZ_SUITE)
|
||||
# include "nsIProtocolHandler.h"
|
||||
#endif
|
||||
#include "nsPermission.h"
|
||||
#include "nsPermissionManager.h"
|
||||
#include "nsICookieService.h"
|
||||
|
||||
|
@ -185,7 +185,7 @@ CookieJarSettings::CookiePermission(nsIPrincipal* aPrincipal,
|
|||
// Let's see if we know this permission.
|
||||
if (!mCookiePermissions.IsEmpty()) {
|
||||
nsCOMPtr<nsIPrincipal> principal =
|
||||
nsPermission::ClonePrincipalForPermission(aPrincipal);
|
||||
Permission::ClonePrincipalForPermission(aPrincipal);
|
||||
if (NS_WARN_IF(!principal)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ CookieJarSettings::CookiePermission(nsIPrincipal* aPrincipal,
|
|||
// Let's store the permission, also if the result is UNKNOWN in order to avoid
|
||||
// race conditions.
|
||||
|
||||
nsCOMPtr<nsIPermission> permission = nsPermission::Create(
|
||||
nsCOMPtr<nsIPermission> permission = Permission::Create(
|
||||
aPrincipal, NS_LITERAL_CSTRING("cookie"), *aCookiePermission, 0, 0, 0);
|
||||
if (permission) {
|
||||
mCookiePermissions.AppendElement(permission);
|
||||
|
@ -292,7 +292,7 @@ void CookieJarSettings::Serialize(CookieJarSettingsArgs& aData) {
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIPermission> permission =
|
||||
nsPermission::Create(principal, NS_LITERAL_CSTRING("cookie"),
|
||||
Permission::Create(principal, NS_LITERAL_CSTRING("cookie"),
|
||||
data.cookiePermission(), 0, 0, 0);
|
||||
if (NS_WARN_IF(!permission)) {
|
||||
continue;
|
||||
|
@ -353,7 +353,7 @@ void CookieJarSettings::Merge(const CookieJarSettingsArgs& aData) {
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIPermission> permission =
|
||||
nsPermission::Create(principal, NS_LITERAL_CSTRING("cookie"),
|
||||
Permission::Create(principal, NS_LITERAL_CSTRING("cookie"),
|
||||
data.cookiePermission(), 0, 0, 0);
|
||||
if (NS_WARN_IF(!permission)) {
|
||||
continue;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
prefs: [dom.security.secFetch.enabled:true]
|
||||
lsan-allowed: [Alloc, Create, Malloc, Realloc, mozilla::BasePrincipal::CreateContentPrincipal, mozilla::ContentPrincipal::Init, mozilla::dom::DocGroup::Create, mozilla::WeakPtr, mozilla::dom::HTMLLinkElement::TryDNSPrefetchOrPreconnectOrPrefetchOrPreloadOrPrerender, mozilla::net::CookieSettings::Create, mozilla::net::nsStandardURL::TemplatedMutator, nsNodeSupportsWeakRefTearoff::GetWeakReference, nsPermission::Create, nsPrefetchService::Preload]
|
||||
lsan-allowed: [Alloc, Create, Malloc, Realloc, mozilla::BasePrincipal::CreateContentPrincipal, mozilla::ContentPrincipal::Init, mozilla::dom::DocGroup::Create, mozilla::WeakPtr, mozilla::dom::HTMLLinkElement::TryDNSPrefetchOrPreconnectOrPrefetchOrPreloadOrPrerender, mozilla::net::CookieSettings::Create, mozilla::net::nsStandardURL::TemplatedMutator, nsNodeSupportsWeakRefTearoff::GetWeakReference, mozilla::Permission::Create, nsPrefetchService::Preload]
|
||||
leak-threshold: [tab:51200]
|
||||
|
|
Загрузка…
Ссылка в новой задаче