mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1781201 - Stop using GetInfoFromPrincipal in the parent; r=hsingh
Quota clients should use GetInfoFromValidatedPrinciplaInfo in the parent because that method will eventually generate unique anonymous origins for private browsing. This patch also moves some calls from the main thread to the PBackground thread because GetInfoFromValidatedPrinciplaInfo can run on any thread. Differential Revision: https://phabricator.services.mozilla.com/D176871
This commit is contained in:
parent
f28c9ada6b
commit
0d54e75ac3
12
dom/cache/Context.cpp
vendored
12
dom/cache/Context.cpp
vendored
@ -18,6 +18,7 @@
|
||||
#include "mozilla/dom/quota/DirectoryLock.h"
|
||||
#include "mozilla/dom/quota/QuotaManager.h"
|
||||
#include "mozilla/dom/quota/ResultExtensions.h"
|
||||
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
||||
#include "mozIStorageConnection.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIRunnable.h"
|
||||
@ -215,6 +216,7 @@ class Context::QuotaInitRunnable final : public nsIRunnable,
|
||||
SafeRefPtr<Action> mInitAction;
|
||||
nsCOMPtr<nsIEventTarget> mInitiatingEventTarget;
|
||||
nsresult mResult;
|
||||
Maybe<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
|
||||
Maybe<CacheDirectoryMetadata> mDirectoryMetadata;
|
||||
RefPtr<DirectoryLock> mDirectoryLock;
|
||||
State mState;
|
||||
@ -326,10 +328,11 @@ Context::QuotaInitRunnable::Run() {
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal = mManager->GetManagerId().Principal();
|
||||
|
||||
QM_TRY_UNWRAP(auto principalMetadata,
|
||||
QuotaManager::GetInfoFromPrincipal(principal));
|
||||
mozilla::ipc::PrincipalInfo principalInfo;
|
||||
QM_TRY(
|
||||
MOZ_TO_RESULT(PrincipalToPrincipalInfo(principal, &principalInfo)));
|
||||
|
||||
mDirectoryMetadata.emplace(std::move(principalMetadata));
|
||||
mPrincipalInfo.emplace(std::move(principalInfo));
|
||||
|
||||
mState = STATE_CREATE_QUOTA_MANAGER;
|
||||
|
||||
@ -354,6 +357,9 @@ Context::QuotaInitRunnable::Run() {
|
||||
break;
|
||||
}
|
||||
|
||||
mDirectoryMetadata.emplace(
|
||||
QuotaManager::GetInfoFromValidatedPrincipalInfo(*mPrincipalInfo));
|
||||
|
||||
QM_TRY(QuotaManager::EnsureCreated(), QM_PROPAGATE,
|
||||
[&resolver](const auto rv) { resolver->Resolve(rv); });
|
||||
|
||||
|
@ -14633,14 +14633,6 @@ nsresult FactoryOp::Open() {
|
||||
}
|
||||
}
|
||||
|
||||
const DatabaseMetadata& metadata = mCommonParams.metadata();
|
||||
|
||||
QuotaManager::GetStorageId(metadata.persistenceType(),
|
||||
mOriginMetadata.mOrigin, Client::IDB, mDatabaseId);
|
||||
|
||||
mDatabaseId.Append('*');
|
||||
mDatabaseId.Append(NS_ConvertUTF16toUTF8(metadata.name()));
|
||||
|
||||
MOZ_ASSERT(permission == PermissionValue::kPermissionAllowed);
|
||||
|
||||
mState = State::FinishOpen;
|
||||
@ -14846,30 +14838,16 @@ Result<PermissionValue, nsresult> FactoryOp::CheckPermission(
|
||||
mChromeWriteAccessAllowed = true;
|
||||
}
|
||||
|
||||
if (State::Initial == mState) {
|
||||
mOriginMetadata = {QuotaManager::GetInfoForChrome(), persistenceType};
|
||||
|
||||
MOZ_ASSERT(QuotaManager::IsOriginInternal(mOriginMetadata.mOrigin));
|
||||
|
||||
mEnforcingQuota = false;
|
||||
}
|
||||
|
||||
return PermissionValue::kPermissionAllowed;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo);
|
||||
|
||||
QM_TRY_INSPECT(const auto& principal,
|
||||
PrincipalInfoToPrincipal(principalInfo));
|
||||
|
||||
QM_TRY_UNWRAP(auto principalMetadata,
|
||||
QuotaManager::GetInfoFromPrincipal(principal));
|
||||
|
||||
QM_TRY_INSPECT(
|
||||
const auto& permission,
|
||||
([persistenceType, &origin = principalMetadata.mOrigin,
|
||||
&principal =
|
||||
*principal]() -> mozilla::Result<PermissionValue, nsresult> {
|
||||
([persistenceType,
|
||||
origin = QuotaManager::GetOriginFromValidatedPrincipalInfo(
|
||||
principalInfo)]() -> mozilla::Result<PermissionValue, nsresult> {
|
||||
if (persistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||
if (QuotaManager::IsOriginInternal(origin)) {
|
||||
return PermissionValue::kPermissionAllowed;
|
||||
@ -14879,13 +14857,6 @@ Result<PermissionValue, nsresult> FactoryOp::CheckPermission(
|
||||
return PermissionValue::kPermissionAllowed;
|
||||
})());
|
||||
|
||||
if (permission != PermissionValue::kPermissionDenied &&
|
||||
State::Initial == mState) {
|
||||
mOriginMetadata = {std::move(principalMetadata), persistenceType};
|
||||
|
||||
mEnforcingQuota = persistenceType != PERSISTENCE_TYPE_PERSISTENT;
|
||||
}
|
||||
|
||||
return permission;
|
||||
}
|
||||
|
||||
@ -14942,7 +14913,7 @@ bool FactoryOp::CheckAtLeastOneAppHasPermission(
|
||||
nsresult FactoryOp::FinishOpen() {
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(mState == State::FinishOpen);
|
||||
MOZ_ASSERT(!mOriginMetadata.mOrigin.IsEmpty());
|
||||
MOZ_ASSERT(mOriginMetadata.mOrigin.IsEmpty());
|
||||
MOZ_ASSERT(!mDirectoryLock);
|
||||
|
||||
if (NS_WARN_IF(QuotaClient::IsShuttingDownOnBackgroundThread()) ||
|
||||
@ -14951,11 +14922,35 @@ nsresult FactoryOp::FinishOpen() {
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
QM_TRY(QuotaManager::EnsureCreated());
|
||||
const PrincipalInfo& principalInfo = mCommonParams.principalInfo();
|
||||
|
||||
const PersistenceType persistenceType =
|
||||
mCommonParams.metadata().persistenceType();
|
||||
MOZ_ASSERT(mOriginMetadata.mPersistenceType == persistenceType);
|
||||
const DatabaseMetadata& metadata = mCommonParams.metadata();
|
||||
|
||||
const PersistenceType persistenceType = metadata.persistenceType();
|
||||
|
||||
if (principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
|
||||
mOriginMetadata = {QuotaManager::GetInfoForChrome(), persistenceType};
|
||||
|
||||
MOZ_ASSERT(QuotaManager::IsOriginInternal(mOriginMetadata.mOrigin));
|
||||
|
||||
mEnforcingQuota = false;
|
||||
} else {
|
||||
MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo);
|
||||
|
||||
mOriginMetadata = {
|
||||
QuotaManager::GetInfoFromValidatedPrincipalInfo(principalInfo),
|
||||
persistenceType};
|
||||
|
||||
mEnforcingQuota = persistenceType != PERSISTENCE_TYPE_PERSISTENT;
|
||||
}
|
||||
|
||||
QuotaManager::GetStorageId(persistenceType, mOriginMetadata.mOrigin,
|
||||
Client::IDB, mDatabaseId);
|
||||
|
||||
mDatabaseId.Append('*');
|
||||
mDatabaseId.Append(NS_ConvertUTF16toUTF8(metadata.name()));
|
||||
|
||||
QM_TRY(QuotaManager::EnsureCreated());
|
||||
|
||||
QuotaManager* const quotaManager = QuotaManager::Get();
|
||||
MOZ_ASSERT(quotaManager);
|
||||
@ -14964,7 +14959,7 @@ nsresult FactoryOp::FinishOpen() {
|
||||
// XXX: For what reason?
|
||||
QM_TRY_UNWRAP(
|
||||
mDatabaseFilePath,
|
||||
([this, quotaManager]() -> mozilla::Result<nsString, nsresult> {
|
||||
([this, metadata, quotaManager]() -> mozilla::Result<nsString, nsresult> {
|
||||
QM_TRY_INSPECT(const auto& dbFile,
|
||||
quotaManager->GetOriginDirectory(mOriginMetadata));
|
||||
|
||||
@ -14972,8 +14967,7 @@ nsresult FactoryOp::FinishOpen() {
|
||||
NS_LITERAL_STRING_FROM_CSTRING(IDB_DIRECTORY_NAME))));
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(dbFile->Append(
|
||||
GetDatabaseFilenameBase(mCommonParams.metadata().name()) +
|
||||
kSQLiteSuffix)));
|
||||
GetDatabaseFilenameBase(metadata.name()) + kSQLiteSuffix)));
|
||||
|
||||
QM_TRY_RETURN(
|
||||
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString, dbFile, GetPath));
|
||||
|
@ -145,7 +145,7 @@ class Connection final : public PBackgroundSDBConnectionParent {
|
||||
PersistenceType GetPersistenceType() const { return mPersistenceType; }
|
||||
|
||||
const PrincipalInfo& GetPrincipalInfo() const {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
return mPrincipalInfo;
|
||||
}
|
||||
@ -1081,24 +1081,6 @@ nsresult OpenOp::Open() {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
PersistenceType persistenceType = GetConnection()->GetPersistenceType();
|
||||
|
||||
const PrincipalInfo& principalInfo = GetConnection()->GetPrincipalInfo();
|
||||
|
||||
if (principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
|
||||
mOriginMetadata = {QuotaManager::GetInfoForChrome(), persistenceType};
|
||||
} else {
|
||||
MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo);
|
||||
|
||||
QM_TRY_INSPECT(const auto& principal,
|
||||
PrincipalInfoToPrincipal(principalInfo));
|
||||
|
||||
QM_TRY_UNWRAP(auto principalMetadata,
|
||||
QuotaManager::GetInfoFromPrincipal(principal));
|
||||
|
||||
mOriginMetadata = {std::move(principalMetadata), persistenceType};
|
||||
}
|
||||
|
||||
mState = State::FinishOpen;
|
||||
MOZ_ALWAYS_SUCCEEDS(OwningEventTarget()->Dispatch(this, NS_DISPATCH_NORMAL));
|
||||
|
||||
@ -1107,7 +1089,7 @@ nsresult OpenOp::Open() {
|
||||
|
||||
nsresult OpenOp::FinishOpen() {
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(!mOriginMetadata.mOrigin.IsEmpty());
|
||||
MOZ_ASSERT(mOriginMetadata.mOrigin.IsEmpty());
|
||||
MOZ_ASSERT(!mDirectoryLock);
|
||||
MOZ_ASSERT(mState == State::FinishOpen);
|
||||
|
||||
@ -1116,6 +1098,20 @@ nsresult OpenOp::FinishOpen() {
|
||||
return NS_ERROR_ABORT;
|
||||
}
|
||||
|
||||
const PrincipalInfo& principalInfo = GetConnection()->GetPrincipalInfo();
|
||||
|
||||
PersistenceType persistenceType = GetConnection()->GetPersistenceType();
|
||||
|
||||
if (principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
|
||||
mOriginMetadata = {QuotaManager::GetInfoForChrome(), persistenceType};
|
||||
} else {
|
||||
MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo);
|
||||
|
||||
mOriginMetadata = {
|
||||
QuotaManager::GetInfoFromValidatedPrincipalInfo(principalInfo),
|
||||
persistenceType};
|
||||
}
|
||||
|
||||
if (gOpenConnections) {
|
||||
for (const auto& connection : *gOpenConnections) {
|
||||
if (connection->Origin() == mOriginMetadata.mOrigin &&
|
||||
|
Loading…
Reference in New Issue
Block a user