Bug 1919558 - Part 1: Convert host to origin before storing it as a DefaultEntry in the permission manager r=pbz,permissions-reviewers
This just simplifies the code for later use and should not change any behaviour beside the following: If `permissions.manager.defaultsUrl` is customized and contains a legacy `host` entry, removes the history lookup to determine known origins for a given host. Instead, only entries for http:// and https:// on the default ports will be added. This is because with the changes in this patch, `UpgradeHostToOriginAndInsert` is moved off the main thread, and a history lookup is only allowed on the main thread. Also rename `mDefaultEntries` to `mDefaultEntriesForImport` to better reflect what this array is actually for: Storing the defaults so that they can be (re-)imported into the permission manager, and not being the primary location where the default permissions are stored. Differential Revision: https://phabricator.services.mozilla.com/D222654
This commit is contained in:
@@ -403,8 +403,10 @@ nsresult UpgradeHostToOriginAndInsert(
|
|||||||
// subdomain of this host), and try to add it as a principal.
|
// subdomain of this host), and try to add it as a principal.
|
||||||
bool foundHistory = false;
|
bool foundHistory = false;
|
||||||
|
|
||||||
nsCOMPtr<nsINavHistoryService> histSrv =
|
nsCOMPtr<nsINavHistoryService> histSrv = nullptr;
|
||||||
do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID);
|
if (NS_IsMainThread()) {
|
||||||
|
histSrv = do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID);
|
||||||
|
}
|
||||||
|
|
||||||
if (histSrv) {
|
if (histSrv) {
|
||||||
nsCOMPtr<nsINavHistoryQuery> histQuery;
|
nsCOMPtr<nsINavHistoryQuery> histQuery;
|
||||||
@@ -3670,7 +3672,7 @@ void PermissionManager::ConsumeDefaultsInputStream(
|
|||||||
constexpr char kMatchTypeHost[] = "host";
|
constexpr char kMatchTypeHost[] = "host";
|
||||||
constexpr char kMatchTypeOrigin[] = "origin";
|
constexpr char kMatchTypeOrigin[] = "origin";
|
||||||
|
|
||||||
mDefaultEntries.Clear();
|
mDefaultEntriesForImport.Clear();
|
||||||
|
|
||||||
if (!aInputStream) {
|
if (!aInputStream) {
|
||||||
return;
|
return;
|
||||||
@@ -3714,24 +3716,37 @@ void PermissionManager::ConsumeDefaultsInputStream(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultEntry::Op op;
|
const nsCString& hostOrOrigin = lineArray[3];
|
||||||
|
const nsCString& type = lineArray[1];
|
||||||
|
|
||||||
if (lineArray[0].EqualsLiteral(kMatchTypeHost)) {
|
if (lineArray[0].EqualsLiteral(kMatchTypeHost)) {
|
||||||
op = DefaultEntry::eImportMatchTypeHost;
|
UpgradeHostToOriginAndInsert(
|
||||||
|
hostOrOrigin, type, permission, nsIPermissionManager::EXPIRE_NEVER, 0,
|
||||||
|
0,
|
||||||
|
[&](const nsACString& aOrigin, const nsCString& aType,
|
||||||
|
uint32_t aPermission, uint32_t aExpireType, int64_t aExpireTime,
|
||||||
|
int64_t aModificationTime) {
|
||||||
|
AddDefaultEntryForImport(aOrigin, aType, aPermission, aProofOfLock);
|
||||||
|
return NS_OK;
|
||||||
|
});
|
||||||
} else if (lineArray[0].EqualsLiteral(kMatchTypeOrigin)) {
|
} else if (lineArray[0].EqualsLiteral(kMatchTypeOrigin)) {
|
||||||
op = DefaultEntry::eImportMatchTypeOrigin;
|
AddDefaultEntryForImport(hostOrOrigin, type, permission, aProofOfLock);
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultEntry* entry = mDefaultEntries.AppendElement();
|
} while (isMore);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PermissionManager::AddDefaultEntryForImport(
|
||||||
|
const nsACString& aOrigin, const nsCString& aType, uint32_t aPermission,
|
||||||
|
const MonitorAutoLock& aProofOfLock) {
|
||||||
|
DefaultEntry* entry = mDefaultEntriesForImport.AppendElement();
|
||||||
MOZ_ASSERT(entry);
|
MOZ_ASSERT(entry);
|
||||||
|
|
||||||
entry->mOp = op;
|
entry->mPermission = aPermission;
|
||||||
entry->mPermission = permission;
|
entry->mOrigin = aOrigin;
|
||||||
entry->mHostOrOrigin = lineArray[3];
|
entry->mType = aType;
|
||||||
entry->mType = lineArray[1];
|
|
||||||
} while (isMore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImportLatestDefaults will import the latest default cookies read during the
|
// ImportLatestDefaults will import the latest default cookies read during the
|
||||||
@@ -3744,60 +3759,9 @@ nsresult PermissionManager::ImportLatestDefaults() {
|
|||||||
|
|
||||||
MonitorAutoLock lock(mMonitor);
|
MonitorAutoLock lock(mMonitor);
|
||||||
|
|
||||||
for (const DefaultEntry& entry : mDefaultEntries) {
|
for (const DefaultEntry& entry : mDefaultEntriesForImport) {
|
||||||
if (entry.mOp == DefaultEntry::eImportMatchTypeHost) {
|
|
||||||
// the import file format doesn't handle modification times, so we use
|
|
||||||
// 0, which AddInternal will convert to now()
|
|
||||||
int64_t modificationTime = 0;
|
|
||||||
|
|
||||||
rv = UpgradeHostToOriginAndInsert(
|
|
||||||
entry.mHostOrOrigin, entry.mType, entry.mPermission,
|
|
||||||
nsIPermissionManager::EXPIRE_NEVER, 0, modificationTime,
|
|
||||||
[&](const nsACString& aOrigin, const nsCString& aType,
|
|
||||||
uint32_t aPermission, uint32_t aExpireType, int64_t aExpireTime,
|
|
||||||
int64_t aModificationTime) {
|
|
||||||
nsCOMPtr<nsIPrincipal> principal;
|
nsCOMPtr<nsIPrincipal> principal;
|
||||||
nsresult rv =
|
rv = GetPrincipalFromOrigin(entry.mOrigin,
|
||||||
GetPrincipalFromOrigin(aOrigin, IsOAForceStripPermission(aType),
|
|
||||||
getter_AddRefs(principal));
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
rv =
|
|
||||||
AddInternal(principal, aType, aPermission,
|
|
||||||
cIDPermissionIsDefault, aExpireType, aExpireTime,
|
|
||||||
aModificationTime, PermissionManager::eDontNotify,
|
|
||||||
PermissionManager::eNoDBOperation, false, &aOrigin);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
if (StaticPrefs::permissions_isolateBy_privateBrowsing()) {
|
|
||||||
// Also import the permission for private browsing.
|
|
||||||
OriginAttributes attrs =
|
|
||||||
OriginAttributes(principal->OriginAttributesRef());
|
|
||||||
attrs.mPrivateBrowsingId = 1;
|
|
||||||
nsCOMPtr<nsIPrincipal> pbPrincipal =
|
|
||||||
BasePrincipal::Cast(principal)->CloneForcingOriginAttributes(
|
|
||||||
attrs);
|
|
||||||
|
|
||||||
rv = AddInternal(
|
|
||||||
pbPrincipal, aType, aPermission, cIDPermissionIsDefault,
|
|
||||||
aExpireType, aExpireTime, aModificationTime,
|
|
||||||
PermissionManager::eDontNotify,
|
|
||||||
PermissionManager::eNoDBOperation, false, &aOrigin);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
NS_WARNING("There was a problem importing a host permission");
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
MOZ_ASSERT(entry.mOp == DefaultEntry::eImportMatchTypeOrigin);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIPrincipal> principal;
|
|
||||||
rv = GetPrincipalFromOrigin(entry.mHostOrOrigin,
|
|
||||||
IsOAForceStripPermission(entry.mType),
|
IsOAForceStripPermission(entry.mType),
|
||||||
getter_AddRefs(principal));
|
getter_AddRefs(principal));
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
|
|||||||
@@ -620,23 +620,25 @@ class PermissionManager final : public nsIPermissionManager,
|
|||||||
|
|
||||||
// A single entry from the defaults URL.
|
// A single entry from the defaults URL.
|
||||||
struct DefaultEntry {
|
struct DefaultEntry {
|
||||||
DefaultEntry() : mOp(eImportMatchTypeHost), mPermission(0) {}
|
nsCString mOrigin;
|
||||||
|
|
||||||
enum Op {
|
|
||||||
eImportMatchTypeHost,
|
|
||||||
eImportMatchTypeOrigin,
|
|
||||||
};
|
|
||||||
|
|
||||||
Op mOp;
|
|
||||||
|
|
||||||
nsCString mHostOrOrigin;
|
|
||||||
nsCString mType;
|
nsCString mType;
|
||||||
uint32_t mPermission;
|
uint32_t mPermission = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// List of entries read from the default settings.
|
// List of entries read from the default settings.
|
||||||
// This array is protected by the monitor.
|
// This array is protected by the monitor.
|
||||||
nsTArray<DefaultEntry> mDefaultEntries;
|
nsTArray<DefaultEntry> mDefaultEntriesForImport;
|
||||||
|
// Adds a default permission entry to AddDefaultEntryForImport for given
|
||||||
|
// origin, type and value
|
||||||
|
void AddDefaultEntryForImport(const nsACString& aOrigin,
|
||||||
|
const nsCString& aType, uint32_t aPermission,
|
||||||
|
const MonitorAutoLock& aProofOfLock);
|
||||||
|
// Given a default entry, import it as a default permission (id = -1) into the
|
||||||
|
// permission manager without storing it to disk. If permission isolation for
|
||||||
|
// private browsing is enabled (which is the default), and the permission type
|
||||||
|
// is not exempt from it, this will also create a separate default permission
|
||||||
|
// for private browsing
|
||||||
|
nsresult ImportDefaultEntry(const DefaultEntry& aDefaultEntry);
|
||||||
|
|
||||||
nsresult Read(const MonitorAutoLock& aProofOfLock);
|
nsresult Read(const MonitorAutoLock& aProofOfLock);
|
||||||
void CompleteRead();
|
void CompleteRead();
|
||||||
|
|||||||
Reference in New Issue
Block a user