mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-08-15 08:53:07 +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
|
||||
bool isAlternate;
|
||||
bool isExplicitlyEnabled;
|
||||
rv = mCSSLoader->LoadStyleLink(aElement, url, aTitle, aMedia, aAlternate,
|
||||
rv = mCSSLoader->LoadStyleLink(aElement, url, nullptr /* triggeringPrincipal */,
|
||||
aTitle, aMedia, aAlternate,
|
||||
CORS_NONE, referrerPolicy,
|
||||
integrity, mRunsToCompletion ? nullptr : this,
|
||||
&isAlternate, &isExplicitlyEnabled);
|
||||
|
|
|
|||
|
|
@ -224,8 +224,7 @@ nsStyleLinkElement::UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
|
|||
{
|
||||
if (aForceReload) {
|
||||
// We remove this stylesheet from the cache to load a new version.
|
||||
nsCOMPtr<nsIContent> thisContent;
|
||||
CallQueryInterface(this, getter_AddRefs(thisContent));
|
||||
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
|
||||
nsCOMPtr<nsIDocument> doc = thisContent->IsInShadowTree() ?
|
||||
thisContent->OwnerDoc() : thisContent->GetUncomposedDoc();
|
||||
if (doc && doc->CSSLoader()->GetEnabled() &&
|
||||
|
|
@ -306,11 +305,10 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
|||
{
|
||||
*aWillNotify = false;
|
||||
|
||||
nsCOMPtr<nsIContent> thisContent;
|
||||
CallQueryInterface(this, getter_AddRefs(thisContent));
|
||||
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
|
||||
|
||||
// All instances of nsStyleLinkElement should implement nsIContent.
|
||||
NS_ENSURE_TRUE(thisContent, NS_ERROR_FAILURE);
|
||||
MOZ_ASSERT(thisContent);
|
||||
|
||||
if (thisContent->IsInAnonymousSubtree() &&
|
||||
thisContent->IsAnonymousContentInSVGUseSubtree()) {
|
||||
|
|
@ -362,7 +360,8 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
|||
}
|
||||
|
||||
bool isInline;
|
||||
nsCOMPtr<nsIURI> uri = GetStyleSheetURL(&isInline);
|
||||
nsCOMPtr<nsIPrincipal> triggeringPrincipal;
|
||||
nsCOMPtr<nsIURI> uri = GetStyleSheetURL(&isInline, getter_AddRefs(triggeringPrincipal));
|
||||
|
||||
if (!aForceUpdate && mStyleSheet && !isInline && uri) {
|
||||
nsIURI* oldURI = mStyleSheet->GetSheetURI();
|
||||
|
|
@ -455,8 +454,8 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
|||
uri->Clone(getter_AddRefs(clonedURI));
|
||||
NS_ENSURE_TRUE(clonedURI, NS_ERROR_OUT_OF_MEMORY);
|
||||
rv = doc->CSSLoader()->
|
||||
LoadStyleLink(thisContent, clonedURI, title, media, isAlternate,
|
||||
GetCORSMode(), referrerPolicy, integrity,
|
||||
LoadStyleLink(thisContent, clonedURI, triggeringPrincipal, title, media,
|
||||
isAlternate, GetCORSMode(), referrerPolicy, integrity,
|
||||
aObserver, &isAlternate, &isExplicitlyEnabled);
|
||||
if (NS_FAILED(rv)) {
|
||||
// Don't propagate LoadStyleLink() errors further than this, since some
|
||||
|
|
@ -486,8 +485,7 @@ nsStyleLinkElement::UpdateStyleSheetScopedness(bool aIsNowScoped)
|
|||
|
||||
CSSStyleSheet* sheet = mStyleSheet->AsConcrete();
|
||||
|
||||
nsCOMPtr<nsIContent> thisContent;
|
||||
CallQueryInterface(this, getter_AddRefs(thisContent));
|
||||
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
|
||||
|
||||
Element* oldScopeElement = sheet->GetScopeElement();
|
||||
Element* newScopeElement = aIsNowScoped ?
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ protected:
|
|||
|
||||
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,
|
||||
nsAString& aType,
|
||||
nsAString& aMedia,
|
||||
|
|
@ -140,6 +140,7 @@ private:
|
|||
|
||||
RefPtr<mozilla::StyleSheet> mStyleSheet;
|
||||
protected:
|
||||
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
||||
bool mDontLoadStyle;
|
||||
bool mUpdatesEnabled;
|
||||
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 (aNameSpaceID == kNameSpaceID_None &&
|
||||
(aName == nsGkAtoms::href ||
|
||||
|
|
@ -520,14 +526,20 @@ HTMLLinkElement::GetHrefURI() const
|
|||
}
|
||||
|
||||
already_AddRefed<nsIURI>
|
||||
HTMLLinkElement::GetStyleSheetURL(bool* aIsInline)
|
||||
HTMLLinkElement::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
|
||||
{
|
||||
*aIsInline = false;
|
||||
*aTriggeringPrincipal = nullptr;
|
||||
|
||||
nsAutoString href;
|
||||
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
|
||||
if (href.IsEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
|
||||
prin.forget(aTriggeringPrincipal);
|
||||
|
||||
nsCOMPtr<nsIURI> uri = Link::GetURI();
|
||||
return uri.forget();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,10 +88,14 @@ public:
|
|||
// WebIDL
|
||||
bool Disabled() const;
|
||||
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)
|
||||
{
|
||||
|
|
@ -189,7 +193,7 @@ protected:
|
|||
virtual ~HTMLLinkElement();
|
||||
|
||||
// nsStyleLinkElement
|
||||
virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) override;
|
||||
virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) override;
|
||||
virtual void GetStyleSheetInfo(nsAString& aTitle,
|
||||
nsAString& aType,
|
||||
nsAString& aMedia,
|
||||
|
|
|
|||
|
|
@ -214,9 +214,10 @@ HTMLStyleElement::SetInnerHTML(const nsAString& aInnerHTML,
|
|||
}
|
||||
|
||||
already_AddRefed<nsIURI>
|
||||
HTMLStyleElement::GetStyleSheetURL(bool* aIsInline)
|
||||
HTMLStyleElement::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
|
||||
{
|
||||
*aIsInline = true;
|
||||
*aTriggeringPrincipal = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public:
|
|||
protected:
|
||||
virtual ~HTMLStyleElement();
|
||||
|
||||
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) override;
|
||||
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) override;
|
||||
void GetStyleSheetInfo(nsAString& aTitle,
|
||||
nsAString& aType,
|
||||
nsAString& aMedia,
|
||||
|
|
|
|||
|
|
@ -260,9 +260,10 @@ SVGStyleElement::SetTitle(const nsAString& aTitle, ErrorResult& rv)
|
|||
// nsStyleLinkElement methods
|
||||
|
||||
already_AddRefed<nsIURI>
|
||||
SVGStyleElement::GetStyleSheetURL(bool* aIsInline)
|
||||
SVGStyleElement::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
|
||||
{
|
||||
*aIsInline = true;
|
||||
*aTriggeringPrincipal = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ protected:
|
|||
}
|
||||
|
||||
// nsStyleLinkElement overrides
|
||||
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) override;
|
||||
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) override;
|
||||
|
||||
void GetStyleSheetInfo(nsAString& aTitle,
|
||||
nsAString& aType,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
interface HTMLLinkElement : HTMLElement {
|
||||
[CEReactions, SetterThrows, Pure]
|
||||
attribute boolean disabled;
|
||||
[CEReactions, SetterThrows, Pure]
|
||||
[CEReactions, NeedsSubjectPrincipal, SetterThrows, Pure]
|
||||
attribute DOMString href;
|
||||
[CEReactions, SetterThrows, Pure]
|
||||
attribute DOMString? crossOrigin;
|
||||
|
|
|
|||
|
|
@ -103,9 +103,10 @@ XMLStylesheetProcessingInstruction::OverrideBaseURI(nsIURI* aNewBaseURI)
|
|||
}
|
||||
|
||||
already_AddRefed<nsIURI>
|
||||
XMLStylesheetProcessingInstruction::GetStyleSheetURL(bool* aIsInline)
|
||||
XMLStylesheetProcessingInstruction::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
|
||||
{
|
||||
*aIsInline = false;
|
||||
*aTriggeringPrincipal = nullptr;
|
||||
|
||||
nsAutoString href;
|
||||
if (!GetAttrValue(nsGkAtoms::href, href)) {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ protected:
|
|||
|
||||
nsCOMPtr<nsIURI> mOverriddenBaseURI;
|
||||
|
||||
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) override;
|
||||
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) override;
|
||||
void GetStyleSheetInfo(nsAString& aTitle,
|
||||
nsAString& aType,
|
||||
nsAString& aMedia,
|
||||
|
|
|
|||
|
|
@ -2015,6 +2015,7 @@ Loader::LoadInlineStyle(nsIContent* aElement,
|
|||
nsresult
|
||||
Loader::LoadStyleLink(nsIContent* aElement,
|
||||
nsIURI* aURL,
|
||||
nsIPrincipal* aTriggeringPrincipal,
|
||||
const nsAString& aTitle,
|
||||
const nsAString& aMedia,
|
||||
bool aHasAlternateRel,
|
||||
|
|
@ -2044,11 +2045,9 @@ Loader::LoadStyleLink(nsIContent* aElement,
|
|||
nsIPrincipal* loadingPrincipal = aElement ? aElement->NodePrincipal()
|
||||
: mDocument->NodePrincipal();
|
||||
|
||||
//SHOULD BE:
|
||||
//nsIPrincipal* principal = aTriggeringPrincipal ? aTriggeringPrincipal
|
||||
// : loadingPrincipal;
|
||||
nsIPrincipal* principal = loadingPrincipal;
|
||||
|
||||
nsIPrincipal* principal = aTriggeringPrincipal ? aTriggeringPrincipal
|
||||
: loadingPrincipal;
|
||||
|
||||
nsISupports* context = aElement;
|
||||
if (!context) {
|
||||
context = mDocument;
|
||||
|
|
|
|||
|
|
@ -254,6 +254,9 @@ public:
|
|||
*
|
||||
* @param aElement the element linking to the the stylesheet. May be null.
|
||||
* @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 aMedia the media string for the sheet.
|
||||
* @param aHasAlternateRel whether the rel for this link included
|
||||
|
|
@ -269,6 +272,7 @@ public:
|
|||
*/
|
||||
nsresult LoadStyleLink(nsIContent* aElement,
|
||||
nsIURI* aURL,
|
||||
nsIPrincipal* aTriggeringPrincipal,
|
||||
const nsAString& aTitle,
|
||||
const nsAString& aMedia,
|
||||
bool aHasAlternateRel,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue