Backed out changeset 848221b2e156 (bug 1620402) for causing several test failures.

CLOSED TREE
This commit is contained in:
Cosmin Sabou 2020-03-30 11:35:20 +03:00
Родитель 34f632706d
Коммит 2db886518c
4 изменённых файлов: 35 добавлений и 64 удалений

Просмотреть файл

@ -27,9 +27,6 @@
#include "mozilla/dom/StorageUtils.h"
#include "mozilla/dom/StorageUtils.h"
#include "nsIURL.h"
#include "nsEffectiveTLDService.h"
#include "nsIURIMutator.h"
#include "mozilla/StaticPrefs_permissions.h"
#include "nsIURIMutator.h"
#include "prnetdb.h"
@ -1028,49 +1025,6 @@ BasePrincipal::GetLocalStorageQuotaKey(nsACString& aKey) {
return NS_OK;
}
NS_IMETHODIMP
BasePrincipal::GetNextSubDomainPrincipal(
nsIPrincipal** aNextSubDomainPrincipal) {
nsCOMPtr<nsIURI> uri;
nsresult rv = GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv) || !uri) {
return NS_ERROR_FAILURE;
}
nsAutoCString host;
rv = uri->GetHost(host);
if (NS_FAILED(rv) || host.IsEmpty()) {
return NS_ERROR_FAILURE;
}
nsCString subDomain;
rv = nsEffectiveTLDService::GetInstance()->GetNextSubDomain(host, subDomain);
if (NS_FAILED(rv) || subDomain.IsEmpty()) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIURI> subDomainURI;
rv = NS_MutateURI(uri).SetHost(subDomain).Finalize(subDomainURI);
if (NS_FAILED(rv) || !subDomainURI) {
return NS_ERROR_FAILURE;
}
// Copy the attributes over
mozilla::OriginAttributes attrs = OriginAttributesRef();
if (!StaticPrefs::permissions_isolateBy_userContext()) {
// Disable userContext for permissions.
attrs.StripAttributes(mozilla::OriginAttributes::STRIP_USER_CONTEXT_ID);
}
RefPtr<nsIPrincipal> principal =
mozilla::BasePrincipal::CreateContentPrincipal(subDomainURI, attrs);
if (!principal) {
return NS_ERROR_FAILURE;
}
principal.forget(aNextSubDomainPrincipal);
return NS_OK;
}
NS_IMETHODIMP
BasePrincipal::GetStorageOriginKey(nsACString& aOriginKey) {

Просмотреть файл

@ -157,9 +157,6 @@ class BasePrincipal : public nsJSPrincipals {
NS_IMETHOD GetIsScriptAllowedByPolicy(
bool* aIsScriptAllowedByPolicy) override;
NS_IMETHOD GetStorageOriginKey(nsACString& aOriginKey) override;
NS_IMETHOD GetNextSubDomainPrincipal(
nsIPrincipal** aNextSubDomainPrincipal) override;
nsresult ToJSON(nsACString& aJSON);
static already_AddRefed<BasePrincipal> FromJSON(const nsACString& aJSON);
// Method populates a passed Json::Value with serializable fields

Просмотреть файл

@ -475,13 +475,6 @@ interface nsIPrincipal : nsISerializable
*/
boolean isL10nAllowed(in nsIURI aDocumentURI);
/**
* Returns a nsIPrincipal, with one less Subdomain Segment
* Returns `nullptr` if there are no more segments to remove.
*/
[infallible] readonly attribute nsIPrincipal nextSubDomainPrincipal;
/**
* Returns if the principal is for an IP address.
*/

Просмотреть файл

@ -300,6 +300,38 @@ already_AddRefed<nsIURI> GetNextSubDomainURI(nsIURI* aURI) {
return uri.forget();
}
// This function produces a nsIPrincipal which is identical to the current
// nsIPrincipal, except that it has one less subdomain segment. It returns
// `nullptr` if there are no more segments to remove.
already_AddRefed<nsIPrincipal> GetNextSubDomainPrincipal(
nsIPrincipal* aPrincipal) {
nsCOMPtr<nsIURI> uri;
nsresult rv = aPrincipal->GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv) || !uri) {
return nullptr;
}
// Create a new principal which is identical to the current one, but with the
// new host
nsCOMPtr<nsIURI> newURI = GetNextSubDomainURI(uri);
if (!newURI) {
return nullptr;
}
// Copy the attributes over
mozilla::OriginAttributes attrs = aPrincipal->OriginAttributesRef();
if (!StaticPrefs::permissions_isolateBy_userContext()) {
// Disable userContext for permissions.
attrs.StripAttributes(mozilla::OriginAttributes::STRIP_USER_CONTEXT_ID);
}
nsCOMPtr<nsIPrincipal> principal =
mozilla::BasePrincipal::CreateContentPrincipal(newURI, attrs);
return principal.forget();
}
class MOZ_STACK_CLASS UpgradeHostToOriginHelper {
public:
virtual nsresult Insert(const nsACString& aOrigin, const nsCString& aType,
@ -2401,8 +2433,7 @@ nsPermissionManager::GetPermissionHashKey(nsIPrincipal* aPrincipal,
// If aExactHostMatch wasn't true, we can check if the base domain has a
// permission entry.
if (!aExactHostMatch) {
nsCOMPtr<nsIPrincipal> principal;
aPrincipal->GetNextSubDomainPrincipal(getter_AddRefs(principal));
nsCOMPtr<nsIPrincipal> principal = GetNextSubDomainPrincipal(aPrincipal);
if (principal) {
return GetPermissionHashKey(principal, aType, aExactHostMatch);
}
@ -3252,7 +3283,6 @@ nsPermissionManager::GetAllKeysForPrincipal(nsIPrincipal* aPrincipal) {
nsTArray<std::pair<nsCString, nsCString>> pairs;
nsCOMPtr<nsIPrincipal> prin = aPrincipal;
nsresult rv = NS_OK;
while (prin) {
// Add the pair to the list
std::pair<nsCString, nsCString>* pair =
@ -3262,12 +3292,9 @@ nsPermissionManager::GetAllKeysForPrincipal(nsIPrincipal* aPrincipal) {
GetKeyForPrincipal(prin, false, pair->first);
Unused << GetOriginFromPrincipal(prin, false, pair->second);
nsCOMPtr<nsIPrincipal> subDomainPrin;
// Get the next subdomain principal and loop back around.
rv = prin->GetNextSubDomainPrincipal(getter_AddRefs(subDomainPrin));
if (NS_SUCCEEDED(rv)) {
prin = subDomainPrin;
}
prin = GetNextSubDomainPrincipal(prin);
}
MOZ_ASSERT(pairs.Length() >= 1,