/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* * A base class which implements nsIStyleSheetLinkingElement and can * be subclassed by various content nodes that want to load * stylesheets (<style>, <link>, processing instructions, etc).
*/
aSelf.GetAttr(nsGkAtoms::media, aMedia); // The HTML5 spec is formulated in terms of the CSSOM spec, which specifies // that media queries should be ASCII lowercased during serialization. // // FIXME(emilio): How does it matter? This is going to be parsed anyway, CSS // should take care of serializing it properly.
nsContentUtils::ASCIIToLower(aMedia);
}
bool LinkStyle::IsCSSMimeTypeAttributeForStyleElement(const Element& aSelf) { // Per // https://html.spec.whatwg.org/multipage/semantics.html#the-style-element:update-a-style-block // step 4, for style elements we should only accept empty and "text/css" type // attribute values.
nsAutoString type;
aSelf.GetAttr(nsGkAtoms::type, type); return type.IsEmpty() || type.LowerCaseEqualsLiteral("text/css");
}
Result<LinkStyle::Update, nsresult> LinkStyle::DoUpdateStyleSheet(
Document* aOldDocument, ShadowRoot* aOldShadowRoot,
nsICSSLoaderObserver* aObserver, ForceUpdate aForceUpdate) {
nsIContent& thisContent = AsContent(); if (thisContent.IsInSVGUseShadowTree()) { // Stylesheets in <use>-cloned subtrees are disabled until we figure out // how they should behave. return Update{};
}
if (mStyleSheet && (aOldDocument || aOldShadowRoot)) {
MOZ_ASSERT(!(aOldDocument && aOldShadowRoot), "ShadowRoot content is never in document, thus " "there should not be a old document and old " "ShadowRoot simultaneously.");
// We're removing the link element from the document or shadow tree, unload // the stylesheet. // // We want to do this even if updates are disabled, since otherwise a sheet // with a stale linking element pointer will be hanging around -- not good! if (mStyleSheet->IsComplete()) { if (aOldShadowRoot) {
aOldShadowRoot->RemoveStyleSheet(*mStyleSheet);
} else {
aOldDocument->RemoveStyleSheet(*mStyleSheet);
}
}
SetStyleSheet(nullptr);
}
Document* doc = thisContent.GetComposedDoc();
// Loader could be null during unlink, see bug 1425866. if (!doc || !doc->CSSLoader() || !doc->CSSLoader()->GetEnabled()) { return Update{};
}
// When static documents are created, stylesheets are cloned manually. if (!mUpdatesEnabled || doc->IsStaticDocument()) { return Update{};
}
Maybe<SheetInfo> info = GetStyleSheetInfo(); if (aForceUpdate == ForceUpdate::No && mStyleSheet && info &&
!info->mIsInline && info->mURI) { if (nsIURI* oldURI = mStyleSheet->GetSheetURI()) { bool equal;
nsresult rv = oldURI->Equals(info->mURI, &equal); if (NS_SUCCEEDED(rv) && equal) { return Update{};
}
}
}
if (mStyleSheet) { if (mStyleSheet->IsComplete()) { if (thisContent.IsInShadowTree()) {
ShadowRoot* containingShadow = thisContent.GetContainingShadow(); // Could be null only during unlink. if (MOZ_LIKELY(containingShadow)) {
containingShadow->RemoveStyleSheet(*mStyleSheet);
}
} else {
doc->RemoveStyleSheet(*mStyleSheet);
}
}
SetStyleSheet(nullptr);
}
if (!info) { return Update{};
}
if (!info->mURI && !info->mIsInline) { // If href is empty and this is not inline style then just bail return Update{};
}
if (info->mIsInline) {
nsAutoString text; if (!nsContentUtils::GetNodeTextContent(&thisContent, false, text,
fallible)) { return Err(NS_ERROR_OUT_OF_MEMORY);
}
MOZ_ASSERT(thisContent.NodeInfo()->NameAtom() != nsGkAtoms::link, " is not 'inline', and needs different CSP checks");
MOZ_ASSERT(thisContent.IsElement());
nsresult rv = NS_OK; if (!nsStyleUtil::CSPAllowsInlineStyle(
thisContent.AsElement(), doc, info->mTriggeringPrincipal,
mLineNumber, mColumnNumber, text, &rv)) { if (NS_FAILED(rv)) { return Err(rv);
} return Update{};
}
// Parse the style sheet. return doc->CSSLoader()->LoadInlineStyle(*info, text, aObserver);
} if (thisContent.IsElement()) {
nsAutoString integrity;
thisContent.AsElement()->GetAttr(nsGkAtoms::integrity, integrity); if (!integrity.IsEmpty()) {
MOZ_LOG(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug,
("LinkStyle::DoUpdateStyleSheet, integrity=%s",
NS_ConvertUTF16toUTF8(integrity).get()));
}
} auto resultOrError = doc->CSSLoader()->LoadStyleLink(*info, aObserver); if (resultOrError.isErr()) { // Don't propagate LoadStyleLink() errors further than this, since some // consumers (e.g. nsXMLContentSink) will completely abort on innocuous // things like a stylesheet load being blocked by the security system. return Update{};
} return resultOrError;
}
} // namespace mozilla::dom
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.