diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index c47f8d98b999..7fd34e426404 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -16673,7 +16673,7 @@ nsresult FactoryOp::CheckPermission( MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo); - IDB_TRY_VAR(auto principal, PrincipalInfoToPrincipal(principalInfo)); + IDB_TRY_VAR(const auto principal, PrincipalInfoToPrincipal(principalInfo)); nsCString suffix; nsCString group; @@ -16684,24 +16684,22 @@ nsresult FactoryOp::CheckPermission( return rv; } - PermissionRequestBase::PermissionValue permission; - - if (persistenceType == PERSISTENCE_TYPE_PERSISTENT) { - if (QuotaManager::IsOriginInternal(origin)) { - permission = PermissionRequestBase::kPermissionAllowed; - } else { + IDB_TRY_VAR(const auto permission, + ([persistenceType, &origin, &principal = *principal]() + -> mozilla::Result { + if (persistenceType == PERSISTENCE_TYPE_PERSISTENT) { + if (QuotaManager::IsOriginInternal(origin)) { + return PermissionRequestBase::kPermissionAllowed; + } #ifdef IDB_MOBILE - return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; + return Err(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR); #else - rv = PermissionRequestBase::GetCurrentPermission(principal, &permission); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } + return PermissionRequestBase::GetCurrentPermission(principal); #endif - } - } else { - permission = PermissionRequestBase::kPermissionAllowed; - } + } + return PermissionRequestBase::kPermissionAllowed; + })()); if (permission != PermissionRequestBase::kPermissionDenied && State::Initial == mState) { diff --git a/dom/indexedDB/PermissionRequestBase.cpp b/dom/indexedDB/PermissionRequestBase.cpp index 38b7bc533418..f9a5db4e7166 100644 --- a/dom/indexedDB/PermissionRequestBase.cpp +++ b/dom/indexedDB/PermissionRequestBase.cpp @@ -56,32 +56,25 @@ PermissionRequestBase::PermissionRequestBase(Element* aOwnerElement, PermissionRequestBase::~PermissionRequestBase() { AssertSanity(); } // static -nsresult PermissionRequestBase::GetCurrentPermission( - nsIPrincipal* aPrincipal, PermissionValue* aCurrentValue) { +Result +PermissionRequestBase::GetCurrentPermission(nsIPrincipal& aPrincipal) { AssertSanity(); - MOZ_ASSERT(aPrincipal); - MOZ_ASSERT(aCurrentValue); - nsCOMPtr permMan = GetPermissionManager(); - if (NS_WARN_IF(!permMan)) { - return NS_ERROR_FAILURE; - } + const nsCOMPtr permMan = GetPermissionManager(); + IDB_TRY(OkIf(permMan), Err(NS_ERROR_FAILURE)); - uint32_t intPermission; - nsresult rv = permMan->TestExactPermissionFromPrincipal( - aPrincipal, kPermissionString, &intPermission); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } + IDB_TRY_VAR(const uint32_t intPermission, + MOZ_TO_RESULT_INVOKE(permMan, TestExactPermissionFromPrincipal, + &aPrincipal, kPermissionString)); - PermissionValue permission = PermissionValueForIntPermission(intPermission); + const PermissionValue permission = + PermissionValueForIntPermission(intPermission); MOZ_ASSERT(permission == kPermissionAllowed || permission == kPermissionDenied || permission == kPermissionPrompt); - *aCurrentValue = permission; - return NS_OK; + return permission; } // static @@ -113,12 +106,8 @@ nsresult PermissionRequestBase::PromptIfNeeded(PermissionValue* aCurrentValue) { nsCOMPtr element = std::move(mOwnerElement); nsCOMPtr principal = std::move(mPrincipal); - PermissionValue currentValue; - nsresult rv = GetCurrentPermission(principal, ¤tValue); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - + IDB_TRY_VAR(const PermissionValue currentValue, + GetCurrentPermission(*principal)); MOZ_ASSERT(currentValue != kPermissionDefault); if (currentValue == kPermissionPrompt) { @@ -131,8 +120,8 @@ nsresult PermissionRequestBase::PromptIfNeeded(PermissionValue* aCurrentValue) { mOwnerElement = std::move(element); mPrincipal = std::move(principal); - rv = obsSvc->NotifyObservers(static_cast(this), - kPermissionPromptTopic, nullptr); + nsresult rv = obsSvc->NotifyObservers(static_cast(this), + kPermissionPromptTopic, nullptr); if (NS_WARN_IF(NS_FAILED(rv))) { // Finally release if we failed the prompt. mOwnerElement = nullptr; diff --git a/dom/indexedDB/PermissionRequestBase.h b/dom/indexedDB/PermissionRequestBase.h index 2d1ff1718f63..314f3ed9e2ae 100644 --- a/dom/indexedDB/PermissionRequestBase.h +++ b/dom/indexedDB/PermissionRequestBase.h @@ -41,8 +41,8 @@ class PermissionRequestBase : public nsIObserver, // This function will not actually prompt. It will never return // kPermissionDefault but will instead translate the permission manager value // into the correct value for the given type. - static nsresult GetCurrentPermission(nsIPrincipal* aPrincipal, - PermissionValue* aCurrentValue); + static Result GetCurrentPermission( + nsIPrincipal& aPrincipal); static PermissionValue PermissionValueForIntPermission( uint32_t aIntPermission);