mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 20:07:30 +09:00
ported from mozilla: Bug 1384493 - LoadStyleLink and LoadInlineStyle should use correct referrer policy. r=heycam (53e3c926ff)
This commit is contained in:
parent
b694e41119
commit
d0c0a7d8d2
8 changed files with 56 additions and 24 deletions
|
|
@ -472,6 +472,7 @@ nsContentSink::ProcessLinkHeader(const nsAString& aLinkData)
|
||||||
nsAutoString media;
|
nsAutoString media;
|
||||||
nsAutoString anchor;
|
nsAutoString anchor;
|
||||||
nsAutoString crossOrigin;
|
nsAutoString crossOrigin;
|
||||||
|
nsAutoString referrerPolicy;
|
||||||
nsAutoString destination;
|
nsAutoString destination;
|
||||||
|
|
||||||
crossOrigin.SetIsVoid(true);
|
crossOrigin.SetIsVoid(true);
|
||||||
|
|
@ -660,6 +661,15 @@ nsContentSink::ProcessLinkHeader(const nsAString& aLinkData)
|
||||||
destination = value;
|
destination = value;
|
||||||
destination.StripWhitespace();
|
destination.StripWhitespace();
|
||||||
}
|
}
|
||||||
|
} else if (attr.LowerCaseEqualsLiteral("referrerpolicy")) {
|
||||||
|
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#referrer-policy-attribute
|
||||||
|
// Specs says referrer policy attribute is an enumerated attribute,
|
||||||
|
// case insensitive and includes the empty string
|
||||||
|
// We will parse the value with AttributeReferrerPolicyFromString
|
||||||
|
// later, which will handle parsing it as an enumerated attribute.
|
||||||
|
if (referrerPolicy.IsEmpty()) {
|
||||||
|
referrerPolicy = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -673,7 +683,7 @@ nsContentSink::ProcessLinkHeader(const nsAString& aLinkData)
|
||||||
rv = ProcessLink(anchor, href, rel,
|
rv = ProcessLink(anchor, href, rel,
|
||||||
// prefer RFC 5987 variant over non-I18zed version
|
// prefer RFC 5987 variant over non-I18zed version
|
||||||
titleStar.IsEmpty() ? title : titleStar,
|
titleStar.IsEmpty() ? title : titleStar,
|
||||||
type, media, crossOrigin, destination);
|
type, media, crossOrigin, referrerPolicy, destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
href.Truncate();
|
href.Truncate();
|
||||||
|
|
@ -682,6 +692,7 @@ nsContentSink::ProcessLinkHeader(const nsAString& aLinkData)
|
||||||
type.Truncate();
|
type.Truncate();
|
||||||
media.Truncate();
|
media.Truncate();
|
||||||
anchor.Truncate();
|
anchor.Truncate();
|
||||||
|
referrerPolicy.Truncate();
|
||||||
crossOrigin.SetIsVoid(true);
|
crossOrigin.SetIsVoid(true);
|
||||||
destination.Truncate();
|
destination.Truncate();
|
||||||
|
|
||||||
|
|
@ -696,7 +707,7 @@ nsContentSink::ProcessLinkHeader(const nsAString& aLinkData)
|
||||||
rv = ProcessLink(anchor, href, rel,
|
rv = ProcessLink(anchor, href, rel,
|
||||||
// prefer RFC 5987 variant over non-I18zed version
|
// prefer RFC 5987 variant over non-I18zed version
|
||||||
titleStar.IsEmpty() ? title : titleStar,
|
titleStar.IsEmpty() ? title : titleStar,
|
||||||
type, media, crossOrigin, destination);
|
type, media, crossOrigin, referrerPolicy, destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
|
@ -708,6 +719,7 @@ nsContentSink::ProcessLink(const nsSubstring& aAnchor, const nsSubstring& aHref,
|
||||||
const nsSubstring& aRel, const nsSubstring& aTitle,
|
const nsSubstring& aRel, const nsSubstring& aTitle,
|
||||||
const nsSubstring& aType, const nsSubstring& aMedia,
|
const nsSubstring& aType, const nsSubstring& aMedia,
|
||||||
const nsSubstring& aCrossOrigin,
|
const nsSubstring& aCrossOrigin,
|
||||||
|
const nsAString& aReferrerPolicy,
|
||||||
const nsSubstring& aDestination)
|
const nsSubstring& aDestination)
|
||||||
{
|
{
|
||||||
uint32_t linkTypes =
|
uint32_t linkTypes =
|
||||||
|
|
@ -749,7 +761,7 @@ nsContentSink::ProcessLink(const nsSubstring& aAnchor, const nsSubstring& aHref,
|
||||||
|
|
||||||
bool isAlternate = linkTypes & nsStyleLinkElement::eALTERNATE;
|
bool isAlternate = linkTypes & nsStyleLinkElement::eALTERNATE;
|
||||||
return ProcessStyleLink(nullptr, aHref, isAlternate, aTitle, aType,
|
return ProcessStyleLink(nullptr, aHref, isAlternate, aTitle, aType,
|
||||||
aMedia);
|
aMedia, aReferrerPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
|
@ -758,7 +770,8 @@ nsContentSink::ProcessStyleLink(nsIContent* aElement,
|
||||||
bool aAlternate,
|
bool aAlternate,
|
||||||
const nsSubstring& aTitle,
|
const nsSubstring& aTitle,
|
||||||
const nsSubstring& aType,
|
const nsSubstring& aType,
|
||||||
const nsSubstring& aMedia)
|
const nsSubstring& aMedia,
|
||||||
|
const nsSubstring& aReferrerPolicy)
|
||||||
{
|
{
|
||||||
if (aAlternate && aTitle.IsEmpty()) {
|
if (aAlternate && aTitle.IsEmpty()) {
|
||||||
// alternates must have title return without error, for now
|
// alternates must have title return without error, for now
|
||||||
|
|
@ -797,13 +810,18 @@ nsContentSink::ProcessStyleLink(nsIContent* aElement,
|
||||||
("nsContentSink::ProcessStyleLink, integrity=%s",
|
("nsContentSink::ProcessStyleLink, integrity=%s",
|
||||||
NS_ConvertUTF16toUTF8(integrity).get()));
|
NS_ConvertUTF16toUTF8(integrity).get()));
|
||||||
}
|
}
|
||||||
|
mozilla::net::ReferrerPolicy referrerPolicy =
|
||||||
|
mozilla::net::AttributeReferrerPolicyFromString(aReferrerPolicy);
|
||||||
|
if (referrerPolicy == net::RP_Unset) {
|
||||||
|
referrerPolicy = mDocument->GetReferrerPolicy();
|
||||||
|
}
|
||||||
|
|
||||||
// If this is a fragment parser, we don't want to observe.
|
// If this is a fragment parser, we don't want to observe.
|
||||||
// We don't support CORS for processing instructions
|
// We don't support CORS for processing instructions
|
||||||
bool isAlternate;
|
bool isAlternate;
|
||||||
bool isExplicitlyEnabled;
|
bool isExplicitlyEnabled;
|
||||||
rv = mCSSLoader->LoadStyleLink(aElement, url, aTitle, aMedia, aAlternate,
|
rv = mCSSLoader->LoadStyleLink(aElement, url, aTitle, aMedia, aAlternate,
|
||||||
CORS_NONE, mDocument->GetReferrerPolicy(),
|
CORS_NONE, referrerPolicy,
|
||||||
integrity, mRunsToCompletion ? nullptr : this,
|
integrity, mRunsToCompletion ? nullptr : this,
|
||||||
&isAlternate, &isExplicitlyEnabled);
|
&isAlternate, &isExplicitlyEnabled);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,7 @@ protected:
|
||||||
const nsSubstring& aHref, const nsSubstring& aRel,
|
const nsSubstring& aHref, const nsSubstring& aRel,
|
||||||
const nsSubstring& aTitle, const nsSubstring& aType,
|
const nsSubstring& aTitle, const nsSubstring& aType,
|
||||||
const nsSubstring& aMedia, const nsSubstring& aCrossOrigin,
|
const nsSubstring& aMedia, const nsSubstring& aCrossOrigin,
|
||||||
|
const nsSubstring& aReferrerPolicy,
|
||||||
const nsSubstring& aDestination);
|
const nsSubstring& aDestination);
|
||||||
|
|
||||||
virtual nsresult ProcessStyleLink(nsIContent* aElement,
|
virtual nsresult ProcessStyleLink(nsIContent* aElement,
|
||||||
|
|
@ -161,7 +162,8 @@ protected:
|
||||||
bool aAlternate,
|
bool aAlternate,
|
||||||
const nsSubstring& aTitle,
|
const nsSubstring& aTitle,
|
||||||
const nsSubstring& aType,
|
const nsSubstring& aType,
|
||||||
const nsSubstring& aMedia);
|
const nsSubstring& aMedia,
|
||||||
|
const nsSubstring& aReferrerPolicy);
|
||||||
|
|
||||||
void PrefetchOrPreloadHref(const nsAString &aHref,
|
void PrefetchOrPreloadHref(const nsAString &aHref,
|
||||||
nsINode *aSource,
|
nsINode *aSource,
|
||||||
|
|
|
||||||
|
|
@ -411,6 +411,16 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
||||||
|
|
||||||
bool doneLoading = false;
|
bool doneLoading = false;
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
|
// Load the link's referrerpolicy attribute. If the link does not provide a
|
||||||
|
// referrerpolicy attribute, ignore this and use the document's referrer
|
||||||
|
// policy
|
||||||
|
|
||||||
|
net::ReferrerPolicy referrerPolicy = GetLinkReferrerPolicy();
|
||||||
|
if (referrerPolicy == net::RP_Unset) {
|
||||||
|
referrerPolicy = doc->GetReferrerPolicy();
|
||||||
|
}
|
||||||
|
|
||||||
if (isInline) {
|
if (isInline) {
|
||||||
nsAutoString text;
|
nsAutoString text;
|
||||||
if (!nsContentUtils::GetNodeTextContent(thisContent, false, text, fallible)) {
|
if (!nsContentUtils::GetNodeTextContent(thisContent, false, text, fallible)) {
|
||||||
|
|
@ -429,7 +439,7 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
||||||
|
|
||||||
// Parse the style sheet.
|
// Parse the style sheet.
|
||||||
rv = doc->CSSLoader()->
|
rv = doc->CSSLoader()->
|
||||||
LoadInlineStyle(thisContent, text, mLineNumber, title, media,
|
LoadInlineStyle(thisContent, text, mLineNumber, title, media, referrerPolicy,
|
||||||
scopeElement, aObserver, &doneLoading, &isAlternate, &isExplicitlyEnabled);
|
scopeElement, aObserver, &doneLoading, &isAlternate, &isExplicitlyEnabled);
|
||||||
} else {
|
} else {
|
||||||
nsAutoString integrity;
|
nsAutoString integrity;
|
||||||
|
|
@ -440,15 +450,6 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
||||||
NS_ConvertUTF16toUTF8(integrity).get()));
|
NS_ConvertUTF16toUTF8(integrity).get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if referrer attributes are enabled in preferences, load the link's referrer
|
|
||||||
// attribute. If the link does not provide a referrer attribute, ignore this
|
|
||||||
// and use the document's referrer policy
|
|
||||||
|
|
||||||
net::ReferrerPolicy referrerPolicy = GetLinkReferrerPolicy();
|
|
||||||
if (referrerPolicy == net::RP_Unset) {
|
|
||||||
referrerPolicy = doc->GetReferrerPolicy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXXbz clone the URI here to work around content policies modifying URIs.
|
// XXXbz clone the URI here to work around content policies modifying URIs.
|
||||||
nsCOMPtr<nsIURI> clonedURI;
|
nsCOMPtr<nsIURI> clonedURI;
|
||||||
uri->Clone(getter_AddRefs(clonedURI));
|
uri->Clone(getter_AddRefs(clonedURI));
|
||||||
|
|
|
||||||
|
|
@ -655,7 +655,8 @@ nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
|
||||||
bool aAlternate,
|
bool aAlternate,
|
||||||
const nsSubstring& aTitle,
|
const nsSubstring& aTitle,
|
||||||
const nsSubstring& aType,
|
const nsSubstring& aType,
|
||||||
const nsSubstring& aMedia)
|
const nsSubstring& aMedia,
|
||||||
|
const nsSubstring& aReferrerPolicy)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
mPrettyPrintXML = false;
|
mPrettyPrintXML = false;
|
||||||
|
|
@ -714,7 +715,7 @@ nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
|
||||||
|
|
||||||
// Let nsContentSink deal with css.
|
// Let nsContentSink deal with css.
|
||||||
rv = nsContentSink::ProcessStyleLink(aElement, aHref, aAlternate,
|
rv = nsContentSink::ProcessStyleLink(aElement, aHref, aAlternate,
|
||||||
aTitle, aType, aMedia);
|
aTitle, aType, aMedia, aReferrerPolicy);
|
||||||
|
|
||||||
// nsContentSink::ProcessStyleLink handles the bookkeeping here wrt
|
// nsContentSink::ProcessStyleLink handles the bookkeeping here wrt
|
||||||
// pending sheets.
|
// pending sheets.
|
||||||
|
|
@ -1261,7 +1262,9 @@ nsXMLContentSink::HandleProcessingInstruction(const char16_t *aTarget,
|
||||||
return DidProcessATokenImpl();
|
return DidProcessATokenImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = ProcessStyleLink(node, href, isAlternate, title, type, media);
|
// <?xml-stylesheet?> processing instructions don't have a referrerpolicy
|
||||||
|
// pseudo-attribute, so we pass in an empty string
|
||||||
|
rv = ProcessStyleLink(node, href, isAlternate, title, type, media, EmptyString());
|
||||||
return NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
return NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,8 @@ protected:
|
||||||
bool aAlternate,
|
bool aAlternate,
|
||||||
const nsSubstring& aTitle,
|
const nsSubstring& aTitle,
|
||||||
const nsSubstring& aType,
|
const nsSubstring& aType,
|
||||||
const nsSubstring& aMedia) override;
|
const nsSubstring& aMedia,
|
||||||
|
const nsSubstring& aReferrerPolicy) override;
|
||||||
|
|
||||||
nsresult LoadXSLStyleSheet(nsIURI* aUrl);
|
nsresult LoadXSLStyleSheet(nsIURI* aUrl);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,9 @@ protected:
|
||||||
bool aAlternate,
|
bool aAlternate,
|
||||||
const nsSubstring& aTitle,
|
const nsSubstring& aTitle,
|
||||||
const nsSubstring& aType,
|
const nsSubstring& aType,
|
||||||
const nsSubstring& aMedia) override;
|
const nsSubstring& aMedia,
|
||||||
|
const nsSubstring& aReferrerPolicy) override;
|
||||||
|
|
||||||
nsresult LoadXSLStyleSheet(nsIURI* aUrl);
|
nsresult LoadXSLStyleSheet(nsIURI* aUrl);
|
||||||
void StartLayout();
|
void StartLayout();
|
||||||
|
|
||||||
|
|
@ -332,7 +334,8 @@ nsXMLFragmentContentSink::ProcessStyleLink(nsIContent* aElement,
|
||||||
bool aAlternate,
|
bool aAlternate,
|
||||||
const nsSubstring& aTitle,
|
const nsSubstring& aTitle,
|
||||||
const nsSubstring& aType,
|
const nsSubstring& aType,
|
||||||
const nsSubstring& aMedia)
|
const nsSubstring& aMedia,
|
||||||
|
const nsSubstring& aReferrerPolicy)
|
||||||
{
|
{
|
||||||
// don't process until moved to document
|
// don't process until moved to document
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
||||||
|
|
@ -1941,6 +1941,7 @@ Loader::LoadInlineStyle(nsIContent* aElement,
|
||||||
uint32_t aLineNumber,
|
uint32_t aLineNumber,
|
||||||
const nsAString& aTitle,
|
const nsAString& aTitle,
|
||||||
const nsAString& aMedia,
|
const nsAString& aMedia,
|
||||||
|
ReferrerPolicy aReferrerPolicy,
|
||||||
Element* aScopeElement,
|
Element* aScopeElement,
|
||||||
nsICSSLoaderObserver* aObserver,
|
nsICSSLoaderObserver* aObserver,
|
||||||
bool* aCompleted,
|
bool* aCompleted,
|
||||||
|
|
@ -1964,11 +1965,12 @@ Loader::LoadInlineStyle(nsIContent* aElement,
|
||||||
|
|
||||||
// Since we're not planning to load a URI, no need to hand a principal to the
|
// Since we're not planning to load a URI, no need to hand a principal to the
|
||||||
// load data or to CreateSheet(). Also, OK to use CORS_NONE for the CORS
|
// load data or to CreateSheet(). Also, OK to use CORS_NONE for the CORS
|
||||||
// mode and mDocument's ReferrerPolicy.
|
// mode.
|
||||||
|
|
||||||
StyleSheetState state;
|
StyleSheetState state;
|
||||||
RefPtr<StyleSheet> sheet;
|
RefPtr<StyleSheet> sheet;
|
||||||
nsresult rv = CreateSheet(nullptr, aElement, nullptr, eAuthorSheetFeatures,
|
nsresult rv = CreateSheet(nullptr, aElement, nullptr, eAuthorSheetFeatures,
|
||||||
CORS_NONE, mDocument->GetReferrerPolicy(),
|
CORS_NONE, aReferrerPolicy,
|
||||||
EmptyString(), // no inline integrity checks
|
EmptyString(), // no inline integrity checks
|
||||||
false, false, aTitle, state, aIsAlternate,
|
false, false, aTitle, state, aIsAlternate,
|
||||||
&sheet);
|
&sheet);
|
||||||
|
|
|
||||||
|
|
@ -224,6 +224,7 @@ public:
|
||||||
* @param aLineNumber the line number at which the stylesheet data started.
|
* @param aLineNumber the line number at which the stylesheet data started.
|
||||||
* @param aTitle the title of the sheet.
|
* @param aTitle the title of the sheet.
|
||||||
* @param aMedia the media string for the sheet.
|
* @param aMedia the media string for the sheet.
|
||||||
|
* @param aReferrerPolicy the referrer policy for loading the sheet.
|
||||||
* @param aObserver the observer to notify when the load completes.
|
* @param aObserver the observer to notify when the load completes.
|
||||||
* May be null.
|
* May be null.
|
||||||
* @param [out] aCompleted whether parsing of the sheet completed.
|
* @param [out] aCompleted whether parsing of the sheet completed.
|
||||||
|
|
@ -237,6 +238,7 @@ public:
|
||||||
uint32_t aLineNumber,
|
uint32_t aLineNumber,
|
||||||
const nsAString& aTitle,
|
const nsAString& aTitle,
|
||||||
const nsAString& aMedia,
|
const nsAString& aMedia,
|
||||||
|
ReferrerPolicy aReferrerPolicy,
|
||||||
mozilla::dom::Element* aScopeElement,
|
mozilla::dom::Element* aScopeElement,
|
||||||
nsICSSLoaderObserver* aObserver,
|
nsICSSLoaderObserver* aObserver,
|
||||||
bool* aCompleted,
|
bool* aCompleted,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue