mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 11:57:32 +09:00
Issue #2736 - Part 12: Re-work style <link> href attribute.
Use subject principal as triggering principal in style <link> "href" attribute.
This commit is contained in:
parent
dde21838de
commit
60ad5b2ffd
14 changed files with 51 additions and 29 deletions
|
|
@ -820,7 +820,8 @@ nsContentSink::ProcessStyleLink(nsIContent* aElement,
|
||||||
// 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, nullptr /* triggeringPrincipal */,
|
||||||
|
aTitle, aMedia, aAlternate,
|
||||||
CORS_NONE, referrerPolicy,
|
CORS_NONE, referrerPolicy,
|
||||||
integrity, mRunsToCompletion ? nullptr : this,
|
integrity, mRunsToCompletion ? nullptr : this,
|
||||||
&isAlternate, &isExplicitlyEnabled);
|
&isAlternate, &isExplicitlyEnabled);
|
||||||
|
|
|
||||||
|
|
@ -224,8 +224,7 @@ nsStyleLinkElement::UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
|
||||||
{
|
{
|
||||||
if (aForceReload) {
|
if (aForceReload) {
|
||||||
// We remove this stylesheet from the cache to load a new version.
|
// We remove this stylesheet from the cache to load a new version.
|
||||||
nsCOMPtr<nsIContent> thisContent;
|
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
|
||||||
CallQueryInterface(this, getter_AddRefs(thisContent));
|
|
||||||
nsCOMPtr<nsIDocument> doc = thisContent->IsInShadowTree() ?
|
nsCOMPtr<nsIDocument> doc = thisContent->IsInShadowTree() ?
|
||||||
thisContent->OwnerDoc() : thisContent->GetUncomposedDoc();
|
thisContent->OwnerDoc() : thisContent->GetUncomposedDoc();
|
||||||
if (doc && doc->CSSLoader()->GetEnabled() &&
|
if (doc && doc->CSSLoader()->GetEnabled() &&
|
||||||
|
|
@ -306,11 +305,10 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
||||||
{
|
{
|
||||||
*aWillNotify = false;
|
*aWillNotify = false;
|
||||||
|
|
||||||
nsCOMPtr<nsIContent> thisContent;
|
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
|
||||||
CallQueryInterface(this, getter_AddRefs(thisContent));
|
|
||||||
|
|
||||||
// All instances of nsStyleLinkElement should implement nsIContent.
|
// All instances of nsStyleLinkElement should implement nsIContent.
|
||||||
NS_ENSURE_TRUE(thisContent, NS_ERROR_FAILURE);
|
MOZ_ASSERT(thisContent);
|
||||||
|
|
||||||
if (thisContent->IsInAnonymousSubtree() &&
|
if (thisContent->IsInAnonymousSubtree() &&
|
||||||
thisContent->IsAnonymousContentInSVGUseSubtree()) {
|
thisContent->IsAnonymousContentInSVGUseSubtree()) {
|
||||||
|
|
@ -362,7 +360,8 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInline;
|
bool isInline;
|
||||||
nsCOMPtr<nsIURI> uri = GetStyleSheetURL(&isInline);
|
nsCOMPtr<nsIPrincipal> triggeringPrincipal;
|
||||||
|
nsCOMPtr<nsIURI> uri = GetStyleSheetURL(&isInline, getter_AddRefs(triggeringPrincipal));
|
||||||
|
|
||||||
if (!aForceUpdate && mStyleSheet && !isInline && uri) {
|
if (!aForceUpdate && mStyleSheet && !isInline && uri) {
|
||||||
nsIURI* oldURI = mStyleSheet->GetSheetURI();
|
nsIURI* oldURI = mStyleSheet->GetSheetURI();
|
||||||
|
|
@ -455,8 +454,8 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
||||||
uri->Clone(getter_AddRefs(clonedURI));
|
uri->Clone(getter_AddRefs(clonedURI));
|
||||||
NS_ENSURE_TRUE(clonedURI, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(clonedURI, NS_ERROR_OUT_OF_MEMORY);
|
||||||
rv = doc->CSSLoader()->
|
rv = doc->CSSLoader()->
|
||||||
LoadStyleLink(thisContent, clonedURI, title, media, isAlternate,
|
LoadStyleLink(thisContent, clonedURI, triggeringPrincipal, title, media,
|
||||||
GetCORSMode(), referrerPolicy, integrity,
|
isAlternate, GetCORSMode(), referrerPolicy, integrity,
|
||||||
aObserver, &isAlternate, &isExplicitlyEnabled);
|
aObserver, &isAlternate, &isExplicitlyEnabled);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
// Don't propagate LoadStyleLink() errors further than this, since some
|
// Don't propagate LoadStyleLink() errors further than this, since some
|
||||||
|
|
@ -486,8 +485,7 @@ nsStyleLinkElement::UpdateStyleSheetScopedness(bool aIsNowScoped)
|
||||||
|
|
||||||
CSSStyleSheet* sheet = mStyleSheet->AsConcrete();
|
CSSStyleSheet* sheet = mStyleSheet->AsConcrete();
|
||||||
|
|
||||||
nsCOMPtr<nsIContent> thisContent;
|
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
|
||||||
CallQueryInterface(this, getter_AddRefs(thisContent));
|
|
||||||
|
|
||||||
Element* oldScopeElement = sheet->GetScopeElement();
|
Element* oldScopeElement = sheet->GetScopeElement();
|
||||||
Element* newScopeElement = aIsNowScoped ?
|
Element* newScopeElement = aIsNowScoped ?
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ protected:
|
||||||
|
|
||||||
void UpdateStyleSheetScopedness(bool aIsNowScoped);
|
void UpdateStyleSheetScopedness(bool aIsNowScoped);
|
||||||
|
|
||||||
virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) = 0;
|
virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) = 0;
|
||||||
virtual void GetStyleSheetInfo(nsAString& aTitle,
|
virtual void GetStyleSheetInfo(nsAString& aTitle,
|
||||||
nsAString& aType,
|
nsAString& aType,
|
||||||
nsAString& aMedia,
|
nsAString& aMedia,
|
||||||
|
|
@ -140,6 +140,7 @@ private:
|
||||||
|
|
||||||
RefPtr<mozilla::StyleSheet> mStyleSheet;
|
RefPtr<mozilla::StyleSheet> mStyleSheet;
|
||||||
protected:
|
protected:
|
||||||
|
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
||||||
bool mDontLoadStyle;
|
bool mDontLoadStyle;
|
||||||
bool mUpdatesEnabled;
|
bool mUpdatesEnabled;
|
||||||
uint32_t mLineNumber;
|
uint32_t mLineNumber;
|
||||||
|
|
|
||||||
|
|
@ -374,6 +374,12 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::href) {
|
||||||
|
mTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
|
||||||
|
this, aValue ? aValue->GetStringValue() : EmptyString(),
|
||||||
|
aSubjectPrincipal);
|
||||||
|
}
|
||||||
|
|
||||||
if (aValue) {
|
if (aValue) {
|
||||||
if (aNameSpaceID == kNameSpaceID_None &&
|
if (aNameSpaceID == kNameSpaceID_None &&
|
||||||
(aName == nsGkAtoms::href ||
|
(aName == nsGkAtoms::href ||
|
||||||
|
|
@ -520,14 +526,20 @@ HTMLLinkElement::GetHrefURI() const
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<nsIURI>
|
already_AddRefed<nsIURI>
|
||||||
HTMLLinkElement::GetStyleSheetURL(bool* aIsInline)
|
HTMLLinkElement::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
|
||||||
{
|
{
|
||||||
*aIsInline = false;
|
*aIsInline = false;
|
||||||
|
*aTriggeringPrincipal = nullptr;
|
||||||
|
|
||||||
nsAutoString href;
|
nsAutoString href;
|
||||||
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
|
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
|
||||||
if (href.IsEmpty()) {
|
if (href.IsEmpty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
|
||||||
|
prin.forget(aTriggeringPrincipal);
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri = Link::GetURI();
|
nsCOMPtr<nsIURI> uri = Link::GetURI();
|
||||||
return uri.forget();
|
return uri.forget();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,10 +88,14 @@ public:
|
||||||
// WebIDL
|
// WebIDL
|
||||||
bool Disabled() const;
|
bool Disabled() const;
|
||||||
void SetDisabled(bool aDisabled, ErrorResult& aRv);
|
void SetDisabled(bool aDisabled, ErrorResult& aRv);
|
||||||
// XPCOM GetHref is fine.
|
|
||||||
void SetHref(const nsAString& aHref, ErrorResult& aRv)
|
void GetHref(nsString& aValue, nsIPrincipal&)
|
||||||
{
|
{
|
||||||
SetHTMLAttr(nsGkAtoms::href, aHref, aRv);
|
GetHref(aValue);
|
||||||
|
}
|
||||||
|
void SetHref(const nsAString& aHref, nsIPrincipal& aTriggeringPrincipal, ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
SetHTMLAttr(nsGkAtoms::href, aHref, aTriggeringPrincipal, aRv);
|
||||||
}
|
}
|
||||||
void GetCrossOrigin(nsAString& aResult)
|
void GetCrossOrigin(nsAString& aResult)
|
||||||
{
|
{
|
||||||
|
|
@ -189,7 +193,7 @@ protected:
|
||||||
virtual ~HTMLLinkElement();
|
virtual ~HTMLLinkElement();
|
||||||
|
|
||||||
// nsStyleLinkElement
|
// nsStyleLinkElement
|
||||||
virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) override;
|
virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) override;
|
||||||
virtual void GetStyleSheetInfo(nsAString& aTitle,
|
virtual void GetStyleSheetInfo(nsAString& aTitle,
|
||||||
nsAString& aType,
|
nsAString& aType,
|
||||||
nsAString& aMedia,
|
nsAString& aMedia,
|
||||||
|
|
|
||||||
|
|
@ -214,9 +214,10 @@ HTMLStyleElement::SetInnerHTML(const nsAString& aInnerHTML,
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<nsIURI>
|
already_AddRefed<nsIURI>
|
||||||
HTMLStyleElement::GetStyleSheetURL(bool* aIsInline)
|
HTMLStyleElement::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
|
||||||
{
|
{
|
||||||
*aIsInline = true;
|
*aIsInline = true;
|
||||||
|
*aTriggeringPrincipal = nullptr;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual ~HTMLStyleElement();
|
virtual ~HTMLStyleElement();
|
||||||
|
|
||||||
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) override;
|
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) override;
|
||||||
void GetStyleSheetInfo(nsAString& aTitle,
|
void GetStyleSheetInfo(nsAString& aTitle,
|
||||||
nsAString& aType,
|
nsAString& aType,
|
||||||
nsAString& aMedia,
|
nsAString& aMedia,
|
||||||
|
|
|
||||||
|
|
@ -260,9 +260,10 @@ SVGStyleElement::SetTitle(const nsAString& aTitle, ErrorResult& rv)
|
||||||
// nsStyleLinkElement methods
|
// nsStyleLinkElement methods
|
||||||
|
|
||||||
already_AddRefed<nsIURI>
|
already_AddRefed<nsIURI>
|
||||||
SVGStyleElement::GetStyleSheetURL(bool* aIsInline)
|
SVGStyleElement::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
|
||||||
{
|
{
|
||||||
*aIsInline = true;
|
*aIsInline = true;
|
||||||
|
*aTriggeringPrincipal = nullptr;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
// nsStyleLinkElement overrides
|
// nsStyleLinkElement overrides
|
||||||
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) override;
|
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) override;
|
||||||
|
|
||||||
void GetStyleSheetInfo(nsAString& aTitle,
|
void GetStyleSheetInfo(nsAString& aTitle,
|
||||||
nsAString& aType,
|
nsAString& aType,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
interface HTMLLinkElement : HTMLElement {
|
interface HTMLLinkElement : HTMLElement {
|
||||||
[CEReactions, SetterThrows, Pure]
|
[CEReactions, SetterThrows, Pure]
|
||||||
attribute boolean disabled;
|
attribute boolean disabled;
|
||||||
[CEReactions, SetterThrows, Pure]
|
[CEReactions, NeedsSubjectPrincipal, SetterThrows, Pure]
|
||||||
attribute DOMString href;
|
attribute DOMString href;
|
||||||
[CEReactions, SetterThrows, Pure]
|
[CEReactions, SetterThrows, Pure]
|
||||||
attribute DOMString? crossOrigin;
|
attribute DOMString? crossOrigin;
|
||||||
|
|
|
||||||
|
|
@ -103,9 +103,10 @@ XMLStylesheetProcessingInstruction::OverrideBaseURI(nsIURI* aNewBaseURI)
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<nsIURI>
|
already_AddRefed<nsIURI>
|
||||||
XMLStylesheetProcessingInstruction::GetStyleSheetURL(bool* aIsInline)
|
XMLStylesheetProcessingInstruction::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
|
||||||
{
|
{
|
||||||
*aIsInline = false;
|
*aIsInline = false;
|
||||||
|
*aTriggeringPrincipal = nullptr;
|
||||||
|
|
||||||
nsAutoString href;
|
nsAutoString href;
|
||||||
if (!GetAttrValue(nsGkAtoms::href, href)) {
|
if (!GetAttrValue(nsGkAtoms::href, href)) {
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ protected:
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> mOverriddenBaseURI;
|
nsCOMPtr<nsIURI> mOverriddenBaseURI;
|
||||||
|
|
||||||
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) override;
|
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) override;
|
||||||
void GetStyleSheetInfo(nsAString& aTitle,
|
void GetStyleSheetInfo(nsAString& aTitle,
|
||||||
nsAString& aType,
|
nsAString& aType,
|
||||||
nsAString& aMedia,
|
nsAString& aMedia,
|
||||||
|
|
|
||||||
|
|
@ -2015,6 +2015,7 @@ Loader::LoadInlineStyle(nsIContent* aElement,
|
||||||
nsresult
|
nsresult
|
||||||
Loader::LoadStyleLink(nsIContent* aElement,
|
Loader::LoadStyleLink(nsIContent* aElement,
|
||||||
nsIURI* aURL,
|
nsIURI* aURL,
|
||||||
|
nsIPrincipal* aTriggeringPrincipal,
|
||||||
const nsAString& aTitle,
|
const nsAString& aTitle,
|
||||||
const nsAString& aMedia,
|
const nsAString& aMedia,
|
||||||
bool aHasAlternateRel,
|
bool aHasAlternateRel,
|
||||||
|
|
@ -2044,11 +2045,9 @@ Loader::LoadStyleLink(nsIContent* aElement,
|
||||||
nsIPrincipal* loadingPrincipal = aElement ? aElement->NodePrincipal()
|
nsIPrincipal* loadingPrincipal = aElement ? aElement->NodePrincipal()
|
||||||
: mDocument->NodePrincipal();
|
: mDocument->NodePrincipal();
|
||||||
|
|
||||||
//SHOULD BE:
|
nsIPrincipal* principal = aTriggeringPrincipal ? aTriggeringPrincipal
|
||||||
//nsIPrincipal* principal = aTriggeringPrincipal ? aTriggeringPrincipal
|
: loadingPrincipal;
|
||||||
// : loadingPrincipal;
|
|
||||||
nsIPrincipal* principal = loadingPrincipal;
|
|
||||||
|
|
||||||
nsISupports* context = aElement;
|
nsISupports* context = aElement;
|
||||||
if (!context) {
|
if (!context) {
|
||||||
context = mDocument;
|
context = mDocument;
|
||||||
|
|
|
||||||
|
|
@ -254,6 +254,9 @@ public:
|
||||||
*
|
*
|
||||||
* @param aElement the element linking to the the stylesheet. May be null.
|
* @param aElement the element linking to the the stylesheet. May be null.
|
||||||
* @param aURL the URL of the sheet.
|
* @param aURL the URL of the sheet.
|
||||||
|
* @param aTriggeringPrincipal the triggering principal for the load. May be
|
||||||
|
* null, in which case the NodePrincipal() of the element (or
|
||||||
|
* document if aElement is null) should be used.
|
||||||
* @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 aHasAlternateRel whether the rel for this link included
|
* @param aHasAlternateRel whether the rel for this link included
|
||||||
|
|
@ -269,6 +272,7 @@ public:
|
||||||
*/
|
*/
|
||||||
nsresult LoadStyleLink(nsIContent* aElement,
|
nsresult LoadStyleLink(nsIContent* aElement,
|
||||||
nsIURI* aURL,
|
nsIURI* aURL,
|
||||||
|
nsIPrincipal* aTriggeringPrincipal,
|
||||||
const nsAString& aTitle,
|
const nsAString& aTitle,
|
||||||
const nsAString& aMedia,
|
const nsAString& aMedia,
|
||||||
bool aHasAlternateRel,
|
bool aHasAlternateRel,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue