Backed out changeset 4757e1fd407f (bug 1594781) for failing wpt at iframe_sandbox_popups_escaping-1.html on a CLOSED TREE

This commit is contained in:
Andreea Pavel 2019-11-20 07:26:52 +02:00
parent 398c2356ca
commit f12302bb4f
4 changed files with 45 additions and 66 deletions

View File

@ -24,8 +24,6 @@
#include "mozilla/dom/BlobURLProtocolHandler.h"
#include "mozilla/dom/ChromeUtils.h"
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/Components.h"
#include "nsIURIFixup.h"
#include "json/json.h"
#include "nsSerializationHelper.h"
@ -311,17 +309,6 @@ BasePrincipal::EqualsConsideringDomain(nsIPrincipal* aOther, bool* aResult) {
return NS_OK;
}
NS_IMETHODIMP
BasePrincipal::EqualsURI(nsIURI* aOtherURI, bool* aResult) {
*aResult = false;
nsCOMPtr<nsIURI> prinURI;
nsresult rv = GetURI(getter_AddRefs(prinURI));
if (NS_FAILED(rv) || !prinURI) {
return NS_OK;
}
return prinURI->EqualsExceptRef(aOtherURI, aResult);
}
NS_IMETHODIMP
BasePrincipal::Subsumes(nsIPrincipal* aOther, bool* aResult) {
NS_ENSURE_ARG_POINTER(aOther);
@ -447,30 +434,6 @@ BasePrincipal::GetAsciiSpec(nsACString& aSpec) {
return prinURI->GetAsciiSpec(aSpec);
}
NS_IMETHODIMP
BasePrincipal::GetExposablePrePath(nsACString& aPrepath) {
aPrepath.Truncate();
nsCOMPtr<nsIURI> prinURI;
nsresult rv = GetURI(getter_AddRefs(prinURI));
if (NS_FAILED(rv) || !prinURI) {
return NS_OK;
}
nsCOMPtr<nsIURIFixup> fixup(components::URIFixup::Service());
nsCOMPtr<nsIURIFixup> urifixup = services::GetURIFixup();
if (NS_WARN_IF(!urifixup)) {
return NS_OK;
}
nsCOMPtr<nsIURI> fixedURI;
rv = fixup->CreateExposableURI(prinURI, getter_AddRefs(fixedURI));
if (NS_FAILED(rv) || NS_WARN_IF(!fixedURI)) {
return NS_OK;
}
return fixedURI->GetDisplayPrePath(aPrepath);
}
NS_IMETHODIMP
BasePrincipal::GetIsSystemPrincipal(bool* aResult) {
*aResult = IsSystemPrincipal();

View File

@ -104,7 +104,6 @@ class BasePrincipal : public nsJSPrincipals {
NS_IMETHOD GetOriginNoSuffix(nsACString& aOrigin) final;
NS_IMETHOD Equals(nsIPrincipal* other, bool* _retval) final;
NS_IMETHOD EqualsConsideringDomain(nsIPrincipal* other, bool* _retval) final;
NS_IMETHOD EqualsURI(nsIURI* aOtherURI, bool* _retval) override;
NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval) final;
NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other,
bool* _retval) final;
@ -124,7 +123,6 @@ class BasePrincipal : public nsJSPrincipals {
NS_IMETHOD GetOriginAttributes(JSContext* aCx,
JS::MutableHandle<JS::Value> aVal) final;
NS_IMETHOD GetAsciiSpec(nsACString& aSpec) override;
NS_IMETHOD GetExposablePrePath(nsACString& aResult) override;
NS_IMETHOD GetOriginSuffix(nsACString& aOriginSuffix) final;
NS_IMETHOD GetIsInIsolatedMozBrowserElement(
bool* aIsInIsolatedMozBrowserElement) final;

View File

@ -66,11 +66,6 @@ interface nsIPrincipal : nsISerializable
DECL_FAST_INLINE_HELPER(EqualsConsideringDomain)
%}
/*
* Returns whether the Principals URI is equal to the other URI
*/
boolean EqualsURI(in nsIURI aOtherURI);
/**
* Returns a hash value for the principal.
*/
@ -214,11 +209,6 @@ interface nsIPrincipal : nsISerializable
*/
readonly attribute ACString AsciiSpec;
/* Returns the Pre Path of the Principals URI with
* user:pass stripped for privacy and spoof prevention
*/
readonly attribute ACString ExposablePrePath;
/**
* Checks if the Principal's URI Scheme matches with the parameter
*

View File

@ -3622,9 +3622,7 @@ Maybe<CSSIntSize> nsGlobalWindowOuter::GetRDMDeviceSize(
// Bug 1576256: This does not work for cross-process subframes.
const Document* topInProcessContentDoc =
aDocument.GetTopLevelContentDocument();
BrowsingContext* bc = topInProcessContentDoc
? topInProcessContentDoc->GetBrowsingContext()
: nullptr;
BrowsingContext* bc = topInProcessContentDoc ? topInProcessContentDoc->GetBrowsingContext() : nullptr;
if (bc && bc->InRDMPane()) {
nsIDocShell* docShell = topInProcessContentDoc->GetDocShell();
if (docShell) {
@ -4586,13 +4584,34 @@ void nsGlobalWindowOuter::MakeScriptDialogTitle(
// Try to get a host from the running principal -- this will do the
// right thing for javascript: and data: documents.
nsAutoCString prepath;
nsresult rv = aSubjectPrincipal->GetExposablePrePath(prepath);
if (NS_SUCCEEDED(rv) && !prepath.IsEmpty()) {
NS_ConvertUTF8toUTF16 ucsPrePath(prepath);
nsContentUtils::FormatLocalizedString(
aOutTitle, nsContentUtils::eCOMMON_DIALOG_PROPERTIES,
"ScriptDlgHeading", ucsPrePath);
nsCOMPtr<nsIURI> uri;
nsresult rv = aSubjectPrincipal->GetURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(rv) && uri) {
// remove user:pass for privacy and spoof prevention
nsCOMPtr<nsIURIFixup> fixup(components::URIFixup::Service());
if (fixup) {
nsCOMPtr<nsIURI> fixedURI;
rv = fixup->CreateExposableURI(uri, getter_AddRefs(fixedURI));
if (NS_SUCCEEDED(rv) && fixedURI) {
nsAutoCString host;
fixedURI->GetHost(host);
if (!host.IsEmpty()) {
// if this URI has a host we'll show it. For other
// schemes (e.g. file:) we fall back to the localized
// generic string
nsAutoCString prepath;
fixedURI->GetDisplayPrePath(prepath);
NS_ConvertUTF8toUTF16 ucsPrePath(prepath);
nsContentUtils::FormatLocalizedString(
aOutTitle, nsContentUtils::eCOMMON_DIALOG_PROPERTIES,
"ScriptDlgHeading", ucsPrePath);
}
}
}
}
if (aOutTitle.IsEmpty()) {
@ -5576,9 +5595,13 @@ bool nsGlobalWindowOuter::SameLoadingURI(Document* aDoc, nsIChannel* aChannel) {
// return false
return false;
}
nsCOMPtr<nsIURI> channelLoadingURI;
channelLoadingPrincipal->GetURI(getter_AddRefs(channelLoadingURI));
if (!channelLoadingURI) {
return false;
}
bool equals = false;
nsresult rv = channelLoadingPrincipal->EqualsURI(docURI, &equals);
nsresult rv = docURI->EqualsExceptRef(channelLoadingURI, &equals);
return NS_SUCCEEDED(rv) && equals;
}
@ -5856,11 +5879,14 @@ bool nsGlobalWindowOuter::GatherPostMessageData(
return false;
}
if (callerPrin->GetIsContentPrincipal()) {
nsCOMPtr<nsIURI> callerOuterURI;
if (NS_FAILED(callerPrin->GetURI(getter_AddRefs(callerOuterURI)))) {
return false;
}
if (callerOuterURI) {
// if the principal has a URI, use that to generate the origin
nsAutoCString asciiOrigin;
callerPrin->GetOrigin(asciiOrigin);
aOrigin = NS_ConvertUTF8toUTF16(asciiOrigin);
nsContentUtils::GetUTFOrigin(callerPrin, aOrigin);
} else if (callerInnerWin) {
if (!*aCallerDocumentURI) {
return false;
@ -5937,11 +5963,13 @@ bool nsGlobalWindowOuter::GetPrincipalForPostMessage(
auto principal = BasePrincipal::Cast(GetPrincipal());
if (attrs != principal->OriginAttributesRef()) {
nsCOMPtr<nsIURI> targetURI;
nsAutoCString targetURL;
nsAutoCString sourceOrigin;
nsAutoCString targetOrigin;
if (NS_FAILED(principal->GetAsciiSpec(targetURL)) ||
if (NS_FAILED(principal->GetURI(getter_AddRefs(targetURI))) ||
NS_FAILED(targetURI->GetAsciiSpec(targetURL)) ||
NS_FAILED(principal->GetOrigin(targetOrigin)) ||
NS_FAILED(aSubjectPrincipal.GetOrigin(sourceOrigin))) {
NS_WARNING("Failed to get source and target origins");