зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1639392 - Merge nsIStyleSheetLinkingElement and nsStyleLinkElement, and call it LinkStyle. r=jwatt
Which is the spec term. nsIStyleSheetLinkingElement is even more confusing since it may not be an element at all (see: processing instructions). Differential Revision: https://phabricator.services.mozilla.com/D76071
This commit is contained in:
Родитель
2f903c4542
Коммит
c3b7227771
|
@ -15,7 +15,6 @@
|
|||
#include "nsIURL.h"
|
||||
#include "nsIURIMutator.h"
|
||||
#include "nsISizeOf.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
|
||||
#include "nsEscape.h"
|
||||
#include "nsGkAtoms.h"
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* stylesheets (<style>, <link>, processing instructions, etc).
|
||||
*/
|
||||
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "mozilla/dom/LinkStyle.h"
|
||||
|
||||
#include "mozilla/StyleSheet.h"
|
||||
#include "mozilla/StyleSheetInlines.h"
|
||||
|
@ -31,10 +31,10 @@
|
|||
#include "nsStyleUtil.h"
|
||||
#include "nsQueryObject.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
nsStyleLinkElement::SheetInfo::SheetInfo(
|
||||
LinkStyle::SheetInfo::SheetInfo(
|
||||
const Document& aDocument, nsIContent* aContent,
|
||||
already_AddRefed<nsIURI> aURI,
|
||||
already_AddRefed<nsIPrincipal> aTriggeringPrincipal,
|
||||
|
@ -62,20 +62,15 @@ nsStyleLinkElement::SheetInfo::SheetInfo(
|
|||
"Integrity only applies to <link>");
|
||||
}
|
||||
|
||||
nsStyleLinkElement::SheetInfo::~SheetInfo() = default;
|
||||
LinkStyle::SheetInfo::~SheetInfo() = default;
|
||||
|
||||
nsStyleLinkElement::nsStyleLinkElement()
|
||||
: mUpdatesEnabled(true),
|
||||
mLineNumber(1),
|
||||
mColumnNumber(1) {}
|
||||
LinkStyle::LinkStyle()
|
||||
: mUpdatesEnabled(true), mLineNumber(1), mColumnNumber(1) {}
|
||||
|
||||
nsStyleLinkElement::~nsStyleLinkElement() {
|
||||
nsStyleLinkElement::SetStyleSheet(nullptr);
|
||||
}
|
||||
LinkStyle::~LinkStyle() { LinkStyle::SetStyleSheet(nullptr); }
|
||||
|
||||
void nsStyleLinkElement::GetTitleAndMediaForElement(const Element& aSelf,
|
||||
nsString& aTitle,
|
||||
nsString& aMedia) {
|
||||
void LinkStyle::GetTitleAndMediaForElement(const Element& aSelf,
|
||||
nsString& aTitle, nsString& aMedia) {
|
||||
// Only honor title as stylesheet name for elements in the document (that is,
|
||||
// ignore for Shadow DOM), per [1] and [2]. See [3].
|
||||
//
|
||||
|
@ -96,8 +91,7 @@ void nsStyleLinkElement::GetTitleAndMediaForElement(const Element& aSelf,
|
|||
nsContentUtils::ASCIIToLower(aMedia);
|
||||
}
|
||||
|
||||
bool nsStyleLinkElement::IsCSSMimeTypeAttributeForStyleElement(
|
||||
const Element& aSelf) {
|
||||
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
|
||||
|
@ -107,74 +101,47 @@ bool nsStyleLinkElement::IsCSSMimeTypeAttributeForStyleElement(
|
|||
return type.IsEmpty() || type.LowerCaseEqualsLiteral("text/css");
|
||||
}
|
||||
|
||||
void nsStyleLinkElement::Unlink() {
|
||||
nsStyleLinkElement::SetStyleSheet(nullptr);
|
||||
}
|
||||
void LinkStyle::Unlink() { LinkStyle::SetStyleSheet(nullptr); }
|
||||
|
||||
void nsStyleLinkElement::Traverse(nsCycleCollectionTraversalCallback& cb) {
|
||||
nsStyleLinkElement* tmp = this;
|
||||
void LinkStyle::Traverse(nsCycleCollectionTraversalCallback& cb) {
|
||||
LinkStyle* tmp = this;
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleSheet);
|
||||
}
|
||||
|
||||
void nsStyleLinkElement::SetStyleSheet(StyleSheet* aStyleSheet) {
|
||||
void LinkStyle::SetStyleSheet(StyleSheet* aStyleSheet) {
|
||||
if (mStyleSheet) {
|
||||
mStyleSheet->SetOwningNode(nullptr);
|
||||
}
|
||||
|
||||
mStyleSheet = aStyleSheet;
|
||||
if (mStyleSheet) {
|
||||
nsCOMPtr<nsINode> node = do_QueryObject(this);
|
||||
if (node) {
|
||||
mStyleSheet->SetOwningNode(node);
|
||||
}
|
||||
mStyleSheet->SetOwningNode(&AsContent());
|
||||
}
|
||||
}
|
||||
|
||||
void nsStyleLinkElement::SetEnableUpdates(bool aEnableUpdates) {
|
||||
mUpdatesEnabled = aEnableUpdates;
|
||||
}
|
||||
|
||||
void nsStyleLinkElement::GetCharset(nsAString& aCharset) {
|
||||
aCharset.Truncate();
|
||||
}
|
||||
|
||||
/* virtual */
|
||||
void nsStyleLinkElement::SetLineNumber(uint32_t aLineNumber) {
|
||||
mLineNumber = aLineNumber;
|
||||
}
|
||||
|
||||
/* virtual */
|
||||
uint32_t nsStyleLinkElement::GetLineNumber() { return mLineNumber; }
|
||||
|
||||
/* virtual */
|
||||
void nsStyleLinkElement::SetColumnNumber(uint32_t aColumnNumber) {
|
||||
mColumnNumber = aColumnNumber;
|
||||
}
|
||||
|
||||
/* virtual */
|
||||
uint32_t nsStyleLinkElement::GetColumnNumber() { return mColumnNumber; }
|
||||
void LinkStyle::GetCharset(nsAString& aCharset) { aCharset.Truncate(); }
|
||||
|
||||
static uint32_t ToLinkMask(const nsAString& aLink) {
|
||||
// Keep this in sync with sRelValues in HTMLLinkElement.cpp
|
||||
if (aLink.EqualsLiteral("prefetch"))
|
||||
return nsStyleLinkElement::ePREFETCH;
|
||||
return LinkStyle::ePREFETCH;
|
||||
else if (aLink.EqualsLiteral("dns-prefetch"))
|
||||
return nsStyleLinkElement::eDNS_PREFETCH;
|
||||
return LinkStyle::eDNS_PREFETCH;
|
||||
else if (aLink.EqualsLiteral("stylesheet"))
|
||||
return nsStyleLinkElement::eSTYLESHEET;
|
||||
return LinkStyle::eSTYLESHEET;
|
||||
else if (aLink.EqualsLiteral("next"))
|
||||
return nsStyleLinkElement::eNEXT;
|
||||
return LinkStyle::eNEXT;
|
||||
else if (aLink.EqualsLiteral("alternate"))
|
||||
return nsStyleLinkElement::eALTERNATE;
|
||||
return LinkStyle::eALTERNATE;
|
||||
else if (aLink.EqualsLiteral("preconnect"))
|
||||
return nsStyleLinkElement::ePRECONNECT;
|
||||
return LinkStyle::ePRECONNECT;
|
||||
else if (aLink.EqualsLiteral("preload"))
|
||||
return nsStyleLinkElement::ePRELOAD;
|
||||
return LinkStyle::ePRELOAD;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes) {
|
||||
uint32_t LinkStyle::ParseLinkTypes(const nsAString& aTypes) {
|
||||
uint32_t linkMask = 0;
|
||||
nsAString::const_iterator start, done;
|
||||
aTypes.BeginReading(start);
|
||||
|
@ -207,29 +174,23 @@ uint32_t nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes) {
|
|||
return linkMask;
|
||||
}
|
||||
|
||||
Result<nsStyleLinkElement::Update, nsresult>
|
||||
nsStyleLinkElement::UpdateStyleSheet(nsICSSLoaderObserver* aObserver) {
|
||||
Result<LinkStyle::Update, nsresult> LinkStyle::UpdateStyleSheet(
|
||||
nsICSSLoaderObserver* aObserver) {
|
||||
return DoUpdateStyleSheet(nullptr, nullptr, aObserver, ForceUpdate::No);
|
||||
}
|
||||
|
||||
Result<nsStyleLinkElement::Update, nsresult>
|
||||
nsStyleLinkElement::UpdateStyleSheetInternal(Document* aOldDocument,
|
||||
ShadowRoot* aOldShadowRoot,
|
||||
ForceUpdate aForceUpdate) {
|
||||
Result<LinkStyle::Update, nsresult> LinkStyle::UpdateStyleSheetInternal(
|
||||
Document* aOldDocument, ShadowRoot* aOldShadowRoot,
|
||||
ForceUpdate aForceUpdate) {
|
||||
return DoUpdateStyleSheet(aOldDocument, aOldShadowRoot, nullptr,
|
||||
aForceUpdate);
|
||||
}
|
||||
|
||||
Result<nsStyleLinkElement::Update, nsresult>
|
||||
nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument,
|
||||
ShadowRoot* aOldShadowRoot,
|
||||
nsICSSLoaderObserver* aObserver,
|
||||
ForceUpdate aForceUpdate) {
|
||||
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
|
||||
// All instances of nsStyleLinkElement should implement nsIContent.
|
||||
MOZ_ASSERT(thisContent);
|
||||
|
||||
if (thisContent->IsInSVGUseShadowTree()) {
|
||||
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{};
|
||||
|
@ -254,7 +215,7 @@ nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument,
|
|||
SetStyleSheet(nullptr);
|
||||
}
|
||||
|
||||
Document* doc = thisContent->GetComposedDoc();
|
||||
Document* doc = thisContent.GetComposedDoc();
|
||||
|
||||
// Loader could be null during unlink, see bug 1425866.
|
||||
if (!doc || !doc->CSSLoader() || !doc->CSSLoader()->GetEnabled()) {
|
||||
|
@ -279,8 +240,8 @@ nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument,
|
|||
}
|
||||
|
||||
if (mStyleSheet) {
|
||||
if (thisContent->IsInShadowTree()) {
|
||||
ShadowRoot* containingShadow = thisContent->GetContainingShadow();
|
||||
if (thisContent.IsInShadowTree()) {
|
||||
ShadowRoot* containingShadow = thisContent.GetContainingShadow();
|
||||
// Could be null only during unlink.
|
||||
if (MOZ_LIKELY(containingShadow)) {
|
||||
containingShadow->RemoveStyleSheet(*mStyleSheet);
|
||||
|
@ -289,7 +250,7 @@ nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument,
|
|||
doc->RemoveStyleSheet(*mStyleSheet);
|
||||
}
|
||||
|
||||
nsStyleLinkElement::SetStyleSheet(nullptr);
|
||||
LinkStyle::SetStyleSheet(nullptr);
|
||||
}
|
||||
|
||||
if (!info) {
|
||||
|
@ -303,17 +264,17 @@ nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument,
|
|||
|
||||
if (info->mIsInline) {
|
||||
nsAutoString text;
|
||||
if (!nsContentUtils::GetNodeTextContent(thisContent, false, text,
|
||||
if (!nsContentUtils::GetNodeTextContent(&thisContent, false, text,
|
||||
fallible)) {
|
||||
return Err(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(thisContent->NodeInfo()->NameAtom() != nsGkAtoms::link,
|
||||
MOZ_ASSERT(thisContent.NodeInfo()->NameAtom() != nsGkAtoms::link,
|
||||
"<link> is not 'inline', and needs different CSP checks");
|
||||
MOZ_ASSERT(thisContent->IsElement());
|
||||
MOZ_ASSERT(thisContent.IsElement());
|
||||
nsresult rv = NS_OK;
|
||||
if (!nsStyleUtil::CSPAllowsInlineStyle(
|
||||
thisContent->AsElement(), doc, info->mTriggeringPrincipal,
|
||||
thisContent.AsElement(), doc, info->mTriggeringPrincipal,
|
||||
mLineNumber, mColumnNumber, text, &rv)) {
|
||||
if (NS_FAILED(rv)) {
|
||||
return Err(rv);
|
||||
|
@ -325,13 +286,13 @@ nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument,
|
|||
return doc->CSSLoader()->LoadInlineStyle(*info, text, mLineNumber,
|
||||
aObserver);
|
||||
}
|
||||
if (thisContent->IsElement()) {
|
||||
if (thisContent.IsElement()) {
|
||||
nsAutoString integrity;
|
||||
thisContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::integrity,
|
||||
integrity);
|
||||
thisContent.AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::integrity,
|
||||
integrity);
|
||||
if (!integrity.IsEmpty()) {
|
||||
MOZ_LOG(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug,
|
||||
("nsStyleLinkElement::DoUpdateStyleSheet, integrity=%s",
|
||||
("LinkStyle::DoUpdateStyleSheet, integrity=%s",
|
||||
NS_ConvertUTF16toUTF8(integrity).get()));
|
||||
}
|
||||
}
|
||||
|
@ -344,3 +305,6 @@ nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument,
|
|||
}
|
||||
return resultOrError;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,287 @@
|
|||
/* -*- 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/. */
|
||||
#ifndef mozilla_dom_LinkStyle_h
|
||||
#define mozilla_dom_LinkStyle_h
|
||||
|
||||
#include "nsINode.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/StyleSheet.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
class nsIContent;
|
||||
class nsICSSLoaderObserver;
|
||||
class nsIPrincipal;
|
||||
class nsIURI;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace dom {
|
||||
|
||||
class Document;
|
||||
class ShadowRoot;
|
||||
|
||||
// https://drafts.csswg.org/cssom/#the-linkstyle-interface
|
||||
class LinkStyle {
|
||||
public:
|
||||
enum class ForceUpdate : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class Completed : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class HasAlternateRel : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class IsAlternate : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class IsInline : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class IsExplicitlyEnabled : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class MediaMatched : uint8_t {
|
||||
Yes,
|
||||
No,
|
||||
};
|
||||
|
||||
struct Update {
|
||||
private:
|
||||
bool mWillNotify;
|
||||
bool mIsAlternate;
|
||||
bool mMediaMatched;
|
||||
|
||||
public:
|
||||
Update() : mWillNotify(false), mIsAlternate(false), mMediaMatched(false) {}
|
||||
|
||||
Update(Completed aCompleted, IsAlternate aIsAlternate,
|
||||
MediaMatched aMediaMatched)
|
||||
: mWillNotify(aCompleted == Completed::No),
|
||||
mIsAlternate(aIsAlternate == IsAlternate::Yes),
|
||||
mMediaMatched(aMediaMatched == MediaMatched::Yes) {}
|
||||
|
||||
bool WillNotify() const { return mWillNotify; }
|
||||
|
||||
bool ShouldBlock() const {
|
||||
if (!mWillNotify) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !mIsAlternate && mMediaMatched;
|
||||
}
|
||||
};
|
||||
|
||||
static LinkStyle* FromNode(nsINode& aNode) { return aNode.AsLinkStyle(); }
|
||||
static const LinkStyle* FromNode(const nsINode& aNode) {
|
||||
return aNode.AsLinkStyle();
|
||||
}
|
||||
|
||||
static LinkStyle* FromNodeOrNull(nsINode* aNode) {
|
||||
return aNode ? FromNode(*aNode) : nullptr;
|
||||
}
|
||||
|
||||
static const LinkStyle* FromNodeOrNull(const nsINode* aNode) {
|
||||
return aNode ? FromNode(*aNode) : nullptr;
|
||||
}
|
||||
|
||||
enum RelValue {
|
||||
ePREFETCH = 0x00000001,
|
||||
eDNS_PREFETCH = 0x00000002,
|
||||
eSTYLESHEET = 0x00000004,
|
||||
eNEXT = 0x00000008,
|
||||
eALTERNATE = 0x00000010,
|
||||
ePRECONNECT = 0x00000020,
|
||||
// NOTE: 0x40 is unused
|
||||
ePRELOAD = 0x00000080
|
||||
};
|
||||
|
||||
// The return value is a bitwise or of 0 or more RelValues.
|
||||
static uint32_t ParseLinkTypes(const nsAString& aTypes);
|
||||
|
||||
void UpdateStyleSheetInternal() {
|
||||
Unused << UpdateStyleSheetInternal(nullptr, nullptr);
|
||||
}
|
||||
|
||||
struct MOZ_STACK_CLASS SheetInfo {
|
||||
nsIContent* mContent;
|
||||
// FIXME(emilio): do these really need to be strong refs?
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
|
||||
// The principal of the scripted caller that initiated the load, if
|
||||
// available. Otherwise null.
|
||||
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
||||
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
|
||||
mozilla::CORSMode mCORSMode;
|
||||
nsString mTitle;
|
||||
nsString mMedia;
|
||||
nsString mIntegrity;
|
||||
nsString mNonce;
|
||||
|
||||
bool mHasAlternateRel;
|
||||
bool mIsInline;
|
||||
IsExplicitlyEnabled mIsExplicitlyEnabled;
|
||||
|
||||
SheetInfo(const mozilla::dom::Document&, nsIContent*,
|
||||
already_AddRefed<nsIURI> aURI,
|
||||
already_AddRefed<nsIPrincipal> aTriggeringPrincipal,
|
||||
already_AddRefed<nsIReferrerInfo> aReferrerInfo,
|
||||
mozilla::CORSMode, const nsAString& aTitle,
|
||||
const nsAString& aMedia, const nsAString& aIntegrity,
|
||||
const nsAString& aNonce, HasAlternateRel, IsInline,
|
||||
IsExplicitlyEnabled);
|
||||
|
||||
~SheetInfo();
|
||||
};
|
||||
|
||||
virtual nsIContent& AsContent() = 0;
|
||||
virtual Maybe<SheetInfo> GetStyleSheetInfo() = 0;
|
||||
|
||||
/**
|
||||
* Used to make the association between a style sheet and
|
||||
* the element that linked it to the document.
|
||||
*
|
||||
* @param aStyleSheet the style sheet associated with this
|
||||
* element.
|
||||
*/
|
||||
void SetStyleSheet(StyleSheet* aStyleSheet);
|
||||
|
||||
/**
|
||||
* Tells this element to update the stylesheet.
|
||||
*
|
||||
* @param aObserver observer to notify once the stylesheet is loaded.
|
||||
* This will be passed to the CSSLoader
|
||||
*/
|
||||
Result<Update, nsresult> UpdateStyleSheet(nsICSSLoaderObserver*);
|
||||
|
||||
/**
|
||||
* Tells this element whether to update the stylesheet when the
|
||||
* element's properties change.
|
||||
*
|
||||
* @param aEnableUpdates update on changes or not.
|
||||
*/
|
||||
void SetEnableUpdates(bool aEnableUpdates) {
|
||||
mUpdatesEnabled = aEnableUpdates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the charset that the element claims the style sheet is in.
|
||||
* Can return empty string to indicate that we have no charset
|
||||
* information.
|
||||
*
|
||||
* @param aCharset the charset
|
||||
*/
|
||||
virtual void GetCharset(nsAString& aCharset);
|
||||
|
||||
// This doesn't entirely belong here since they only make sense for
|
||||
// some types of linking elements, but it's a better place than
|
||||
// anywhere else.
|
||||
void SetLineNumber(uint32_t aLineNumber) { mLineNumber = aLineNumber; }
|
||||
|
||||
/**
|
||||
* Get the line number, as previously set by SetLineNumber.
|
||||
*
|
||||
* @return the line number of this element; or 1 if no line number
|
||||
* was set
|
||||
*/
|
||||
uint32_t GetLineNumber() const { return mLineNumber; }
|
||||
|
||||
// This doesn't entirely belong here since they only make sense for
|
||||
// some types of linking elements, but it's a better place than
|
||||
// anywhere else.
|
||||
void SetColumnNumber(uint32_t aColumnNumber) {
|
||||
mColumnNumber = aColumnNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column number, as previously set by SetColumnNumber.
|
||||
*
|
||||
* @return the column number of this element; or 1 if no column number
|
||||
* was set
|
||||
*/
|
||||
uint32_t GetColumnNumber() const { return mColumnNumber; }
|
||||
|
||||
StyleSheet* GetSheet() const { return mStyleSheet; }
|
||||
|
||||
protected:
|
||||
LinkStyle();
|
||||
virtual ~LinkStyle();
|
||||
|
||||
// Gets a suitable title and media for SheetInfo out of an element, which
|
||||
// needs to be `this`.
|
||||
//
|
||||
// NOTE(emilio): Needs nsString instead of nsAString because of
|
||||
// CompressWhitespace.
|
||||
static void GetTitleAndMediaForElement(const mozilla::dom::Element&,
|
||||
nsString& aTitle, nsString& aMedia);
|
||||
|
||||
// Returns whether the type attribute specifies the text/css type for style
|
||||
// elements.
|
||||
static bool IsCSSMimeTypeAttributeForStyleElement(const Element&);
|
||||
|
||||
// CC methods
|
||||
void Unlink();
|
||||
void Traverse(nsCycleCollectionTraversalCallback& cb);
|
||||
|
||||
/**
|
||||
* @param aOldDocument should be non-null only if we're updating because we
|
||||
* removed the node from the document.
|
||||
* @param aOldShadowRoot should be non-null only if we're updating because we
|
||||
* removed the node from a shadow tree.
|
||||
* @param aForceUpdate true will force the update even if the URI has not
|
||||
* changed. This should be used in cases when something
|
||||
* about the content that affects the resulting sheet
|
||||
* changed but the URI may not have changed.
|
||||
*
|
||||
* TODO(emilio): Should probably pass a single DocumentOrShadowRoot.
|
||||
*/
|
||||
Result<Update, nsresult> UpdateStyleSheetInternal(
|
||||
Document* aOldDocument, ShadowRoot* aOldShadowRoot,
|
||||
ForceUpdate = ForceUpdate::No);
|
||||
|
||||
/**
|
||||
* @param aOldDocument should be non-null only if we're updating because we
|
||||
* removed the node from the document.
|
||||
* @param aOldShadowRoot The ShadowRoot that used to contain the style.
|
||||
* Passed as a parameter because on an update, the node
|
||||
* is removed from the tree before the sheet is removed
|
||||
* from the ShadowRoot.
|
||||
* @param aForceUpdate true will force the update even if the URI has not
|
||||
* changed. This should be used in cases when something
|
||||
* about the content that affects the resulting sheet
|
||||
* changed but the URI may not have changed.
|
||||
*/
|
||||
Result<Update, nsresult> DoUpdateStyleSheet(Document* aOldDocument,
|
||||
ShadowRoot* aOldShadowRoot,
|
||||
nsICSSLoaderObserver*,
|
||||
ForceUpdate);
|
||||
|
||||
RefPtr<mozilla::StyleSheet> mStyleSheet;
|
||||
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
||||
bool mUpdatesEnabled;
|
||||
uint32_t mLineNumber;
|
||||
uint32_t mColumnNumber;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_LinkStyle_h
|
|
@ -10,7 +10,6 @@
|
|||
#include "mozilla/dom/DocumentFragment.h"
|
||||
#include "ChildIterator.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsWindowSizes.h"
|
||||
#include "mozilla/dom/DirectionalityUtils.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
|
|
|
@ -85,7 +85,6 @@ EXPORTS += [
|
|||
'nsIScriptContext.h',
|
||||
'nsIScriptGlobalObject.h',
|
||||
'nsIScriptObjectPrincipal.h',
|
||||
'nsIStyleSheetLinkingElement.h',
|
||||
'nsJSEnvironment.h',
|
||||
'nsJSUtils.h',
|
||||
'nsLineBreaker.h',
|
||||
|
@ -103,7 +102,6 @@ EXPORTS += [
|
|||
'nsStubDocumentObserver.h',
|
||||
'nsStubMutationObserver.h',
|
||||
'nsStyledElement.h',
|
||||
'nsStyleLinkElement.h',
|
||||
'nsTextFragment.h',
|
||||
'nsTraversal.h',
|
||||
'nsTreeSanitizer.h',
|
||||
|
@ -197,6 +195,7 @@ EXPORTS.mozilla.dom += [
|
|||
'ImageTracker.h',
|
||||
'IntlUtils.h',
|
||||
'Link.h',
|
||||
'LinkStyle.h',
|
||||
'Location.h',
|
||||
'LocationBase.h',
|
||||
'MaybeCrossOriginObject.h',
|
||||
|
@ -317,6 +316,7 @@ UNIFIED_SOURCES += [
|
|||
'InProcessBrowserChildMessageManager.cpp',
|
||||
'IntlUtils.cpp',
|
||||
'Link.cpp',
|
||||
'LinkStyle.cpp',
|
||||
'Location.cpp',
|
||||
'LocationBase.cpp',
|
||||
'MaybeCrossOriginObject.cpp',
|
||||
|
@ -377,7 +377,6 @@ UNIFIED_SOURCES += [
|
|||
'nsStubDocumentObserver.cpp',
|
||||
'nsStubMutationObserver.cpp',
|
||||
'nsStyledElement.cpp',
|
||||
'nsStyleLinkElement.cpp',
|
||||
'nsSyncLoadService.cpp',
|
||||
'nsTextFragment.cpp',
|
||||
'nsTextNode.cpp',
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
#include "mozilla/StaticPrefs_browser.h"
|
||||
#include "mozilla/StaticPrefs_content.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "mozilla/dom/MutationObservers.h"
|
||||
#include "mozilla/dom/LinkStyle.h"
|
||||
#include "mozilla/css/Loader.h"
|
||||
#include "mozilla/dom/MutationObservers.h"
|
||||
#include "mozilla/dom/SRILogHelper.h"
|
||||
#include "mozilla/StoragePrincipalHelper.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsILoadContext.h"
|
||||
#include "nsIPrefetchService.h"
|
||||
|
@ -629,7 +629,7 @@ nsresult nsContentSink::ProcessLinkFromHeader(
|
|||
const nsAString& aSrcset, const nsAString& aSizes, const nsAString& aType,
|
||||
const nsAString& aMedia, const nsAString& aCrossOrigin,
|
||||
const nsAString& aReferrerPolicy, const nsAString& aAs) {
|
||||
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(aRel);
|
||||
uint32_t linkTypes = LinkStyle::ParseLinkTypes(aRel);
|
||||
|
||||
// The link relation may apply to a different resource, specified
|
||||
// in the anchor parameter. For the link relations supported so far,
|
||||
|
@ -641,31 +641,30 @@ nsresult nsContentSink::ProcessLinkFromHeader(
|
|||
|
||||
if (nsContentUtils::PrefetchPreloadEnabled(mDocShell)) {
|
||||
// prefetch href if relation is "next" or "prefetch"
|
||||
if ((linkTypes & nsStyleLinkElement::eNEXT) ||
|
||||
(linkTypes & nsStyleLinkElement::ePREFETCH)) {
|
||||
if ((linkTypes & LinkStyle::eNEXT) || (linkTypes & LinkStyle::ePREFETCH)) {
|
||||
PrefetchHref(aHref, aAs, aType, aMedia);
|
||||
}
|
||||
|
||||
if (!aHref.IsEmpty() && (linkTypes & nsStyleLinkElement::eDNS_PREFETCH)) {
|
||||
if (!aHref.IsEmpty() && (linkTypes & LinkStyle::eDNS_PREFETCH)) {
|
||||
PrefetchDNS(aHref);
|
||||
}
|
||||
|
||||
if (!aHref.IsEmpty() && (linkTypes & nsStyleLinkElement::ePRECONNECT)) {
|
||||
if (!aHref.IsEmpty() && (linkTypes & LinkStyle::ePRECONNECT)) {
|
||||
Preconnect(aHref, aCrossOrigin);
|
||||
}
|
||||
|
||||
if (linkTypes & nsStyleLinkElement::ePRELOAD) {
|
||||
if (linkTypes & LinkStyle::ePRELOAD) {
|
||||
PreloadHref(aHref, aAs, aType, aMedia, aIntegrity, aSrcset, aSizes,
|
||||
aCrossOrigin, aReferrerPolicy);
|
||||
}
|
||||
}
|
||||
|
||||
// is it a stylesheet link?
|
||||
if (!(linkTypes & nsStyleLinkElement::eSTYLESHEET)) {
|
||||
if (!(linkTypes & LinkStyle::eSTYLESHEET)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool isAlternate = linkTypes & nsStyleLinkElement::eALTERNATE;
|
||||
bool isAlternate = linkTypes & LinkStyle::eALTERNATE;
|
||||
return ProcessStyleLinkFromHeader(aHref, isAlternate, aTitle, aIntegrity,
|
||||
aType, aMedia, aReferrerPolicy);
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@ template <typename T>
|
|||
class InclusiveAncestorsOfTypeIterator;
|
||||
template <typename T>
|
||||
class InclusiveFlatTreeAncestorsOfTypeIterator;
|
||||
class LinkStyle;
|
||||
class MutationObservers;
|
||||
template <typename T>
|
||||
class Optional;
|
||||
|
@ -509,6 +510,13 @@ class nsINode : public mozilla::dom::EventTarget {
|
|||
|
||||
virtual bool IsTextControlElement() const { return false; }
|
||||
|
||||
// Returns non-null if this element subclasses `LinkStyle`.
|
||||
virtual const mozilla::dom::LinkStyle* AsLinkStyle() const { return nullptr; }
|
||||
mozilla::dom::LinkStyle* AsLinkStyle() {
|
||||
return const_cast<mozilla::dom::LinkStyle*>(
|
||||
static_cast<const nsINode*>(this)->AsLinkStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this node as an Element. Should only be used for nodes
|
||||
* for which IsElement() is true. This is defined inline in Element.h.
|
||||
|
|
|
@ -1,186 +0,0 @@
|
|||
/* -*- 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/. */
|
||||
#ifndef nsIStyleSheetLinkingElement_h__
|
||||
#define nsIStyleSheetLinkingElement_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "mozilla/StyleSheet.h"
|
||||
#include "mozilla/Result.h"
|
||||
|
||||
class nsIContent;
|
||||
class nsICSSLoaderObserver;
|
||||
class nsIPrincipal;
|
||||
class nsIURI;
|
||||
|
||||
#define NS_ISTYLESHEETLINKINGELEMENT_IID \
|
||||
{ \
|
||||
0xa8b79f3b, 0x9d18, 0x4f9c, { \
|
||||
0xb1, 0xaa, 0x8c, 0x9b, 0x1b, 0xaa, 0xac, 0xad \
|
||||
} \
|
||||
}
|
||||
|
||||
class nsIStyleSheetLinkingElement : public nsISupports {
|
||||
public:
|
||||
enum class ForceUpdate : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class Completed : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class HasAlternateRel : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class IsAlternate : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class IsInline : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class IsExplicitlyEnabled : uint8_t {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
enum class MediaMatched : uint8_t {
|
||||
Yes,
|
||||
No,
|
||||
};
|
||||
|
||||
struct Update {
|
||||
private:
|
||||
bool mWillNotify;
|
||||
bool mIsAlternate;
|
||||
bool mMediaMatched;
|
||||
|
||||
public:
|
||||
Update() : mWillNotify(false), mIsAlternate(false), mMediaMatched(false) {}
|
||||
|
||||
Update(Completed aCompleted, IsAlternate aIsAlternate,
|
||||
MediaMatched aMediaMatched)
|
||||
: mWillNotify(aCompleted == Completed::No),
|
||||
mIsAlternate(aIsAlternate == IsAlternate::Yes),
|
||||
mMediaMatched(aMediaMatched == MediaMatched::Yes) {}
|
||||
|
||||
bool WillNotify() const { return mWillNotify; }
|
||||
|
||||
bool ShouldBlock() const {
|
||||
if (!mWillNotify) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !mIsAlternate && mMediaMatched;
|
||||
}
|
||||
};
|
||||
|
||||
struct MOZ_STACK_CLASS SheetInfo {
|
||||
nsIContent* mContent;
|
||||
// FIXME(emilio): do these really need to be strong refs?
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
|
||||
// The principal of the scripted caller that initiated the load, if
|
||||
// available. Otherwise null.
|
||||
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
||||
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
|
||||
mozilla::CORSMode mCORSMode;
|
||||
nsString mTitle;
|
||||
nsString mMedia;
|
||||
nsString mIntegrity;
|
||||
nsString mNonce;
|
||||
|
||||
bool mHasAlternateRel;
|
||||
bool mIsInline;
|
||||
IsExplicitlyEnabled mIsExplicitlyEnabled;
|
||||
|
||||
SheetInfo(const mozilla::dom::Document&, nsIContent*,
|
||||
already_AddRefed<nsIURI> aURI,
|
||||
already_AddRefed<nsIPrincipal> aTriggeringPrincipal,
|
||||
already_AddRefed<nsIReferrerInfo> aReferrerInfo,
|
||||
mozilla::CORSMode, const nsAString& aTitle,
|
||||
const nsAString& aMedia, const nsAString& aIntegrity,
|
||||
const nsAString& aNonce, HasAlternateRel, IsInline,
|
||||
IsExplicitlyEnabled);
|
||||
|
||||
~SheetInfo();
|
||||
};
|
||||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLESHEETLINKINGELEMENT_IID)
|
||||
|
||||
/**
|
||||
* Used to make the association between a style sheet and
|
||||
* the element that linked it to the document.
|
||||
*
|
||||
* @param aStyleSheet the style sheet associated with this
|
||||
* element.
|
||||
*/
|
||||
virtual void SetStyleSheet(mozilla::StyleSheet* aStyleSheet) = 0;
|
||||
|
||||
/**
|
||||
* Tells this element to update the stylesheet.
|
||||
*
|
||||
* @param aObserver observer to notify once the stylesheet is loaded.
|
||||
* This will be passed to the CSSLoader
|
||||
*/
|
||||
virtual mozilla::Result<Update, nsresult> UpdateStyleSheet(
|
||||
nsICSSLoaderObserver* aObserver) = 0;
|
||||
|
||||
/**
|
||||
* Tells this element whether to update the stylesheet when the
|
||||
* element's properties change.
|
||||
*
|
||||
* @param aEnableUpdates update on changes or not.
|
||||
*/
|
||||
virtual void SetEnableUpdates(bool aEnableUpdates) = 0;
|
||||
|
||||
/**
|
||||
* Gets the charset that the element claims the style sheet is in.
|
||||
* Can return empty string to indicate that we have no charset
|
||||
* information.
|
||||
*
|
||||
* @param aCharset the charset
|
||||
*/
|
||||
virtual void GetCharset(nsAString& aCharset) = 0;
|
||||
|
||||
// This doesn't entirely belong here since they only make sense for
|
||||
// some types of linking elements, but it's a better place than
|
||||
// anywhere else.
|
||||
virtual void SetLineNumber(uint32_t aLineNumber) = 0;
|
||||
|
||||
/**
|
||||
* Get the line number, as previously set by SetLineNumber.
|
||||
*
|
||||
* @return the line number of this element; or 1 if no line number
|
||||
* was set
|
||||
*/
|
||||
virtual uint32_t GetLineNumber() = 0;
|
||||
|
||||
// This doesn't entirely belong here since they only make sense for
|
||||
// some types of linking elements, but it's a better place than
|
||||
// anywhere else.
|
||||
virtual void SetColumnNumber(uint32_t aColumnNumber) = 0;
|
||||
|
||||
/**
|
||||
* Get the column number, as previously set by SetColumnNumber.
|
||||
*
|
||||
* @return the column number of this element; or 1 if no column number
|
||||
* was set
|
||||
*/
|
||||
virtual uint32_t GetColumnNumber() = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleSheetLinkingElement,
|
||||
NS_ISTYLESHEETLINKINGELEMENT_IID)
|
||||
|
||||
#endif // nsILinkingElement_h__
|
|
@ -1,140 +0,0 @@
|
|||
/* -*- 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).
|
||||
*/
|
||||
|
||||
#ifndef nsStyleLinkElement_h___
|
||||
#define nsStyleLinkElement_h___
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/CORSMode.h"
|
||||
#include "mozilla/StyleSheetInlines.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
class nsIURI;
|
||||
|
||||
namespace mozilla {
|
||||
class CSSStyleSheet;
|
||||
namespace dom {
|
||||
class Document;
|
||||
class ShadowRoot;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
class nsStyleLinkElement : public nsIStyleSheetLinkingElement {
|
||||
template <typename V, typename E>
|
||||
using Result = mozilla::Result<V, E>;
|
||||
|
||||
public:
|
||||
nsStyleLinkElement();
|
||||
virtual ~nsStyleLinkElement();
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override = 0;
|
||||
|
||||
mozilla::StyleSheet* GetSheet() const { return mStyleSheet; }
|
||||
|
||||
// nsIStyleSheetLinkingElement
|
||||
void SetStyleSheet(mozilla::StyleSheet* aStyleSheet) final;
|
||||
|
||||
Result<Update, nsresult> UpdateStyleSheet(nsICSSLoaderObserver*) final;
|
||||
|
||||
void SetEnableUpdates(bool aEnableUpdates) final;
|
||||
void GetCharset(nsAString& aCharset) override;
|
||||
|
||||
void SetLineNumber(uint32_t aLineNumber) final;
|
||||
uint32_t GetLineNumber() final;
|
||||
void SetColumnNumber(uint32_t aColumnNumber) final;
|
||||
uint32_t GetColumnNumber() final;
|
||||
|
||||
enum RelValue {
|
||||
ePREFETCH = 0x00000001,
|
||||
eDNS_PREFETCH = 0x00000002,
|
||||
eSTYLESHEET = 0x00000004,
|
||||
eNEXT = 0x00000008,
|
||||
eALTERNATE = 0x00000010,
|
||||
ePRECONNECT = 0x00000020,
|
||||
// NOTE: 0x40 is unused
|
||||
ePRELOAD = 0x00000080
|
||||
};
|
||||
|
||||
// The return value is a bitwise or of 0 or more RelValues.
|
||||
static uint32_t ParseLinkTypes(const nsAString& aTypes);
|
||||
|
||||
void UpdateStyleSheetInternal() {
|
||||
mozilla::Unused << UpdateStyleSheetInternal(nullptr, nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @param aOldDocument should be non-null only if we're updating because we
|
||||
* removed the node from the document.
|
||||
* @param aOldShadowRoot should be non-null only if we're updating because we
|
||||
* removed the node from a shadow tree.
|
||||
* @param aForceUpdate true will force the update even if the URI has not
|
||||
* changed. This should be used in cases when something
|
||||
* about the content that affects the resulting sheet
|
||||
* changed but the URI may not have changed.
|
||||
*
|
||||
* TODO(emilio): Should probably pass a single DocumentOrShadowRoot.
|
||||
*/
|
||||
Result<Update, nsresult> UpdateStyleSheetInternal(
|
||||
mozilla::dom::Document* aOldDocument,
|
||||
mozilla::dom::ShadowRoot* aOldShadowRoot, ForceUpdate = ForceUpdate::No);
|
||||
|
||||
// Gets a suitable title and media for SheetInfo out of an element, which
|
||||
// needs to be `this`.
|
||||
//
|
||||
// NOTE(emilio): Needs nsString instead of nsAString because of
|
||||
// CompressWhitespace.
|
||||
static void GetTitleAndMediaForElement(const mozilla::dom::Element&,
|
||||
nsString& aTitle, nsString& aMedia);
|
||||
|
||||
// Returns whether the type attribute specifies the text/css type for style
|
||||
// elements.
|
||||
static bool IsCSSMimeTypeAttributeForStyleElement(
|
||||
const mozilla::dom::Element&);
|
||||
|
||||
virtual mozilla::Maybe<SheetInfo> GetStyleSheetInfo() = 0;
|
||||
|
||||
// CC methods
|
||||
void Unlink();
|
||||
void Traverse(nsCycleCollectionTraversalCallback& cb);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @param aOldDocument should be non-null only if we're updating because we
|
||||
* removed the node from the document.
|
||||
* @param aOldShadowRoot The ShadowRoot that used to contain the style.
|
||||
* Passed as a parameter because on an update, the node
|
||||
* is removed from the tree before the sheet is removed
|
||||
* from the ShadowRoot.
|
||||
* @param aForceUpdate true will force the update even if the URI has not
|
||||
* changed. This should be used in cases when something
|
||||
* about the content that affects the resulting sheet
|
||||
* changed but the URI may not have changed.
|
||||
*/
|
||||
mozilla::Result<Update, nsresult> DoUpdateStyleSheet(
|
||||
mozilla::dom::Document* aOldDocument,
|
||||
mozilla::dom::ShadowRoot* aOldShadowRoot, nsICSSLoaderObserver* aObserver,
|
||||
ForceUpdate);
|
||||
|
||||
RefPtr<mozilla::StyleSheet> mStyleSheet;
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
||||
bool mUpdatesEnabled;
|
||||
uint32_t mLineNumber;
|
||||
uint32_t mColumnNumber;
|
||||
};
|
||||
|
||||
#endif /* nsStyleLinkElement_h___ */
|
|
@ -26,11 +26,9 @@
|
|||
#include "mozilla/dom/Document.h"
|
||||
#include "nsINode.h"
|
||||
#include "nsIPrefetchService.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsWindowSizes.h"
|
||||
#include "nsIContentPolicy.h"
|
||||
|
@ -73,21 +71,20 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLLinkElement)
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLLinkElement,
|
||||
nsGenericHTMLElement)
|
||||
tmp->nsStyleLinkElement::Traverse(cb);
|
||||
tmp->LinkStyle::Traverse(cb);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRelList)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSizes)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLLinkElement,
|
||||
nsGenericHTMLElement)
|
||||
tmp->nsStyleLinkElement::Unlink();
|
||||
tmp->LinkStyle::Unlink();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRelList)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSizes)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLLinkElement,
|
||||
nsGenericHTMLElement,
|
||||
nsIStyleSheetLinkingElement, Link)
|
||||
nsGenericHTMLElement, Link)
|
||||
|
||||
NS_IMPL_ELEMENT_CLONE(HTMLLinkElement)
|
||||
|
||||
|
@ -396,13 +393,13 @@ void HTMLLinkElement::GetLinkTarget(nsAString& aTarget) {
|
|||
|
||||
static const DOMTokenListSupportedToken sSupportedRelValues[] = {
|
||||
// Keep this and the one below in sync with ToLinkMask in
|
||||
// nsStyleLinkElement.cpp.
|
||||
// LinkStyle.cpp.
|
||||
// "preload" must come first because it can be disabled.
|
||||
"preload", "prefetch", "dns-prefetch", "stylesheet", "next",
|
||||
"alternate", "preconnect", "icon", "search", nullptr};
|
||||
|
||||
static const DOMTokenListSupportedToken sSupportedRelValuesWithManifest[] = {
|
||||
// Keep this in sync with ToLinkMask in nsStyleLinkElement.cpp.
|
||||
// Keep this in sync with ToLinkMask in LinkStyle.cpp.
|
||||
// "preload" and "manifest" must come first because they can be disabled.
|
||||
"preload", "manifest", "prefetch", "dns-prefetch", "stylesheet", "next",
|
||||
"alternate", "preconnect", "icon", "search", nullptr};
|
||||
|
@ -431,7 +428,7 @@ already_AddRefed<nsIURI> HTMLLinkElement::GetHrefURI() const {
|
|||
return GetHrefURIForAnchors();
|
||||
}
|
||||
|
||||
Maybe<nsStyleLinkElement::SheetInfo> HTMLLinkElement::GetStyleSheetInfo() {
|
||||
Maybe<LinkStyle::SheetInfo> HTMLLinkElement::GetStyleSheetInfo() {
|
||||
nsAutoString rel;
|
||||
GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
|
||||
uint32_t linkTypes = ParseLinkTypes(rel);
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/Link.h"
|
||||
#include "mozilla/dom/LinkStyle.h"
|
||||
#include "mozilla/WeakPtr.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "nsDOMTokenList.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -22,7 +22,7 @@ namespace dom {
|
|||
// NOTE(emilio): If we stop inheriting from Link, we need to remove the
|
||||
// IsHTMLElement(nsGkAtoms::link) checks in Link.cpp.
|
||||
class HTMLLinkElement final : public nsGenericHTMLElement,
|
||||
public nsStyleLinkElement,
|
||||
public LinkStyle,
|
||||
public Link {
|
||||
public:
|
||||
explicit HTMLLinkElement(
|
||||
|
@ -206,7 +206,9 @@ class HTMLLinkElement final : public nsGenericHTMLElement,
|
|||
static bool IsCSSMimeTypeAttributeForLinkElement(
|
||||
const mozilla::dom::Element&);
|
||||
|
||||
// nsStyleLinkElement
|
||||
// LinkStyle
|
||||
nsIContent& AsContent() final { return *this; }
|
||||
const LinkStyle* AsLinkStyle() const final { return this; }
|
||||
Maybe<SheetInfo> GetStyleSheetInfo() final;
|
||||
|
||||
RefPtr<nsDOMTokenList> mRelList;
|
||||
|
|
|
@ -30,17 +30,16 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLStyleElement)
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLStyleElement,
|
||||
nsGenericHTMLElement)
|
||||
tmp->nsStyleLinkElement::Traverse(cb);
|
||||
tmp->LinkStyle::Traverse(cb);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLStyleElement,
|
||||
nsGenericHTMLElement)
|
||||
tmp->nsStyleLinkElement::Unlink();
|
||||
tmp->LinkStyle::Unlink();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLStyleElement,
|
||||
nsGenericHTMLElement,
|
||||
nsIStyleSheetLinkingElement,
|
||||
nsIMutationObserver)
|
||||
|
||||
NS_IMPL_ELEMENT_CLONE(HTMLStyleElement)
|
||||
|
@ -163,7 +162,7 @@ void HTMLStyleElement::SetTextContentInternal(const nsAString& aTextContent,
|
|||
Unused << UpdateStyleSheetInternal(nullptr, nullptr);
|
||||
}
|
||||
|
||||
Maybe<nsStyleLinkElement::SheetInfo> HTMLStyleElement::GetStyleSheetInfo() {
|
||||
Maybe<LinkStyle::SheetInfo> HTMLStyleElement::GetStyleSheetInfo() {
|
||||
if (!IsCSSMimeTypeAttributeForStyleElement(*this)) {
|
||||
return Nothing();
|
||||
}
|
||||
|
|
|
@ -8,15 +8,15 @@
|
|||
#define mozilla_dom_HTMLStyleElement_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/LinkStyle.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "nsStubMutationObserver.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class HTMLStyleElement final : public nsGenericHTMLElement,
|
||||
public nsStyleLinkElement,
|
||||
public LinkStyle,
|
||||
public nsStubMutationObserver {
|
||||
public:
|
||||
explicit HTMLStyleElement(
|
||||
|
@ -71,6 +71,8 @@ class HTMLStyleElement final : public nsGenericHTMLElement,
|
|||
protected:
|
||||
virtual ~HTMLStyleElement();
|
||||
|
||||
nsIContent& AsContent() final { return *this; }
|
||||
const LinkStyle* AsLinkStyle() const final { return this; }
|
||||
Maybe<SheetInfo> GetStyleSheetInfo() final;
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,11 +48,9 @@
|
|||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsNameSpaceManager.h"
|
||||
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsError.h"
|
||||
#include "nsContentPolicyUtils.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
|
||||
#include "nsLayoutCID.h"
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "nsIContent.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsHTMLParts.h"
|
||||
#include "nsCRT.h"
|
||||
#include "mozilla/StyleSheetInlines.h"
|
||||
|
@ -26,7 +25,6 @@
|
|||
#include "mozilla/Logging.h"
|
||||
#include "nsRect.h"
|
||||
#include "nsIScriptElement.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsIChannel.h"
|
||||
|
@ -344,6 +342,8 @@ nsresult PrototypeDocumentContentSink::CreateAndInsertPI(
|
|||
|
||||
nsresult rv;
|
||||
if (aProtoPI->mTarget.EqualsLiteral("xml-stylesheet")) {
|
||||
MOZ_ASSERT(LinkStyle::FromNode(*node),
|
||||
"XML Stylesheet node does not implement LinkStyle!");
|
||||
auto* pi = static_cast<XMLStylesheetProcessingInstruction*>(node.get());
|
||||
rv = InsertXMLStylesheetPI(aProtoPI, aParent, aBeforeThis, pi);
|
||||
} else {
|
||||
|
@ -368,8 +368,7 @@ nsresult PrototypeDocumentContentSink::InsertXMLStylesheetPI(
|
|||
aPINode->OverrideBaseURI(mCurrentPrototype->GetURI());
|
||||
|
||||
rv = aParent->InsertChildBefore(
|
||||
aPINode->AsContent(), aBeforeThis ? aBeforeThis->AsContent() : nullptr,
|
||||
false);
|
||||
aPINode, aBeforeThis ? aBeforeThis->AsContent() : nullptr, false);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
aPINode->SetEnableUpdates(true);
|
||||
|
@ -454,12 +453,11 @@ nsresult PrototypeDocumentContentSink::ResumeWalkInternal() {
|
|||
element->NodeInfo()->Equals(nsGkAtoms::style, kNameSpaceID_SVG)) {
|
||||
// XXX sucks that we have to do this -
|
||||
// see bug 370111
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle =
|
||||
do_QueryInterface(element);
|
||||
NS_ASSERTION(ssle,
|
||||
auto* linkStyle = LinkStyle::FromNode(*element);
|
||||
NS_ASSERTION(linkStyle,
|
||||
"<html:style> doesn't implement "
|
||||
"nsIStyleSheetLinkingElement?");
|
||||
Unused << ssle->UpdateStyleSheet(nullptr);
|
||||
Unused << linkStyle->UpdateStyleSheet(nullptr);
|
||||
}
|
||||
}
|
||||
// Now pop the context stack back up to the parent
|
||||
|
|
|
@ -27,19 +27,18 @@ JSObject* SVGStyleElement::WrapNode(JSContext* aCx,
|
|||
|
||||
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(SVGStyleElement,
|
||||
SVGStyleElementBase,
|
||||
nsIStyleSheetLinkingElement,
|
||||
nsIMutationObserver)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(SVGStyleElement)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGStyleElement,
|
||||
SVGStyleElementBase)
|
||||
tmp->nsStyleLinkElement::Traverse(cb);
|
||||
tmp->LinkStyle::Traverse(cb);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGStyleElement,
|
||||
SVGStyleElementBase)
|
||||
tmp->nsStyleLinkElement::Unlink();
|
||||
tmp->LinkStyle::Unlink();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -172,7 +171,7 @@ void SVGStyleElement::SetTitle(const nsAString& aTitle, ErrorResult& rv) {
|
|||
//----------------------------------------------------------------------
|
||||
// nsStyleLinkElement methods
|
||||
|
||||
Maybe<nsStyleLinkElement::SheetInfo> SVGStyleElement::GetStyleSheetInfo() {
|
||||
Maybe<LinkStyle::SheetInfo> SVGStyleElement::GetStyleSheetInfo() {
|
||||
if (!IsCSSMimeTypeAttributeForStyleElement(*this)) {
|
||||
return Nothing();
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#define mozilla_dom_SVGStyleElement_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/LinkStyle.h"
|
||||
#include "SVGElement.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "nsStubMutationObserver.h"
|
||||
|
||||
nsresult NS_NewSVGStyleElement(
|
||||
|
@ -21,8 +21,8 @@ namespace dom {
|
|||
typedef SVGElement SVGStyleElementBase;
|
||||
|
||||
class SVGStyleElement final : public SVGStyleElementBase,
|
||||
public nsStyleLinkElement,
|
||||
public nsStubMutationObserver {
|
||||
public nsStubMutationObserver,
|
||||
public LinkStyle {
|
||||
protected:
|
||||
friend nsresult(::NS_NewSVGStyleElement(
|
||||
nsIContent** aResult,
|
||||
|
@ -76,7 +76,9 @@ class SVGStyleElement final : public SVGStyleElementBase,
|
|||
// completely optimized away.
|
||||
inline nsresult Init() { return NS_OK; }
|
||||
|
||||
// nsStyleLinkElement overrides
|
||||
// LinkStyle overrides
|
||||
nsIContent& AsContent() final { return *this; }
|
||||
const LinkStyle* AsLinkStyle() const final { return this; }
|
||||
Maybe<SheetInfo> GetStyleSheetInfo() final;
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "mozilla/dom/LinkStyle.h"
|
||||
#include "mozilla/dom/ProcessingInstruction.h"
|
||||
#include "mozilla/dom/ProcessingInstructionBinding.h"
|
||||
#include "mozilla/dom/XMLStylesheetProcessingInstruction.h"
|
||||
|
@ -57,9 +58,12 @@ ProcessingInstruction::ProcessingInstruction(
|
|||
|
||||
ProcessingInstruction::~ProcessingInstruction() = default;
|
||||
|
||||
// If you add nsIStyleSheetLinkingElement here, make sure we actually
|
||||
// implement the nsStyleLinkElement methods.
|
||||
NS_IMPL_ISUPPORTS_INHERITED0(ProcessingInstruction, CharacterData)
|
||||
StyleSheet* ProcessingInstruction::GetSheet() const {
|
||||
if (const auto* linkStyle = LinkStyle::FromNode(*this)) {
|
||||
return linkStyle->GetSheet();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSObject* ProcessingInstruction::WrapNode(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
|
@ -82,16 +86,6 @@ already_AddRefed<CharacterData> ProcessingInstruction::CloneDataNode(
|
|||
return do_AddRef(new (nim) ProcessingInstruction(ni.forget(), data));
|
||||
}
|
||||
|
||||
Maybe<nsStyleLinkElement::SheetInfo>
|
||||
ProcessingInstruction::GetStyleSheetInfo() {
|
||||
MOZ_ASSERT_UNREACHABLE(
|
||||
"XMLStylesheetProcessingInstruction should override "
|
||||
"this and we don't try to do stylesheet stuff. In "
|
||||
"particular, we do not implement "
|
||||
"nsIStyleSheetLinkingElement");
|
||||
return Nothing();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
void ProcessingInstruction::List(FILE* out, int32_t aIndent) const {
|
||||
int32_t index;
|
||||
|
|
|
@ -10,25 +10,23 @@
|
|||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/CharacterData.h"
|
||||
#include "nsAString.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
|
||||
class nsIPrincipal;
|
||||
class nsIURI;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class StyleSheet;
|
||||
|
||||
namespace dom {
|
||||
|
||||
class ProcessingInstruction : public CharacterData, public nsStyleLinkElement {
|
||||
class ProcessingInstruction : public CharacterData {
|
||||
public:
|
||||
ProcessingInstruction(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
||||
const nsAString& aData);
|
||||
|
||||
// nsISupports. We need to declare QI, because nsStyleLinkElement
|
||||
// has a pure-virtual QI.
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
virtual already_AddRefed<CharacterData> CloneDataNode(
|
||||
mozilla::dom::NodeInfo* aNodeInfo, bool aCloneText) const override;
|
||||
dom::NodeInfo* aNodeInfo, bool aCloneText) const override;
|
||||
|
||||
#ifdef DEBUG
|
||||
virtual void List(FILE* out, int32_t aIndent) const override;
|
||||
|
@ -38,6 +36,9 @@ class ProcessingInstruction : public CharacterData, public nsStyleLinkElement {
|
|||
|
||||
// WebIDL API
|
||||
void GetTarget(nsAString& aTarget) { aTarget = NodeName(); }
|
||||
// This is the WebIDL API for LinkStyle, even though only
|
||||
// XMLStylesheetProcessingInstruction actually implements LinkStyle.
|
||||
StyleSheet* GetSheet() const;
|
||||
|
||||
NS_IMPL_FROMNODE_HELPER(ProcessingInstruction, IsProcessingInstruction())
|
||||
|
||||
|
@ -56,11 +57,7 @@ class ProcessingInstruction : public CharacterData, public nsStyleLinkElement {
|
|||
*/
|
||||
bool GetAttrValue(nsAtom* aName, nsAString& aValue);
|
||||
|
||||
virtual JSObject* WrapNode(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
// nsStyleLinkElement overrides, because we can't leave them pure virtual.
|
||||
Maybe<SheetInfo> GetStyleSheetInfo() override;
|
||||
JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -13,20 +13,19 @@ namespace dom {
|
|||
|
||||
// nsISupports implementation
|
||||
|
||||
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(XMLStylesheetProcessingInstruction,
|
||||
ProcessingInstruction,
|
||||
nsIStyleSheetLinkingElement)
|
||||
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(
|
||||
XMLStylesheetProcessingInstruction, ProcessingInstruction)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(XMLStylesheetProcessingInstruction)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(
|
||||
XMLStylesheetProcessingInstruction, ProcessingInstruction)
|
||||
tmp->nsStyleLinkElement::Traverse(cb);
|
||||
tmp->LinkStyle::Traverse(cb);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(
|
||||
XMLStylesheetProcessingInstruction, ProcessingInstruction)
|
||||
tmp->nsStyleLinkElement::Unlink();
|
||||
tmp->LinkStyle::Unlink();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
XMLStylesheetProcessingInstruction::~XMLStylesheetProcessingInstruction() =
|
||||
|
@ -64,7 +63,7 @@ void XMLStylesheetProcessingInstruction::SetNodeValueInternal(
|
|||
}
|
||||
}
|
||||
|
||||
// nsStyleLinkElement
|
||||
// LinkStyle
|
||||
|
||||
void XMLStylesheetProcessingInstruction::GetCharset(nsAString& aCharset) {
|
||||
if (!GetAttrValue(nsGkAtoms::charset, aCharset)) {
|
||||
|
@ -76,7 +75,7 @@ void XMLStylesheetProcessingInstruction::OverrideBaseURI(nsIURI* aNewBaseURI) {
|
|||
mOverriddenBaseURI = aNewBaseURI;
|
||||
}
|
||||
|
||||
Maybe<nsStyleLinkElement::SheetInfo>
|
||||
Maybe<LinkStyle::SheetInfo>
|
||||
XMLStylesheetProcessingInstruction::GetStyleSheetInfo() {
|
||||
// xml-stylesheet PI is special only in prolog
|
||||
if (!nsContentUtils::InProlog(this)) {
|
||||
|
|
|
@ -9,14 +9,15 @@
|
|||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "mozilla/dom/LinkStyle.h"
|
||||
#include "mozilla/dom/ProcessingInstruction.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class XMLStylesheetProcessingInstruction final : public ProcessingInstruction {
|
||||
class XMLStylesheetProcessingInstruction final : public ProcessingInstruction,
|
||||
public LinkStyle {
|
||||
public:
|
||||
XMLStylesheetProcessingInstruction(
|
||||
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
||||
|
@ -32,10 +33,8 @@ class XMLStylesheetProcessingInstruction final : public ProcessingInstruction {
|
|||
nsGkAtoms::xml_stylesheet),
|
||||
aData) {}
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// CC
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XMLStylesheetProcessingInstruction,
|
||||
ProcessingInstruction)
|
||||
|
||||
|
@ -56,7 +55,7 @@ class XMLStylesheetProcessingInstruction final : public ProcessingInstruction {
|
|||
*/
|
||||
void OverrideBaseURI(nsIURI* aNewBaseURI);
|
||||
|
||||
// nsStyleLinkElement
|
||||
// LinkStyle
|
||||
void GetCharset(nsAString& aCharset) override;
|
||||
|
||||
virtual void SetData(const nsAString& aData,
|
||||
|
@ -73,6 +72,8 @@ class XMLStylesheetProcessingInstruction final : public ProcessingInstruction {
|
|||
|
||||
nsCOMPtr<nsIURI> mOverriddenBaseURI;
|
||||
|
||||
nsIContent& AsContent() final { return *this; }
|
||||
const LinkStyle* AsLinkStyle() const final { return this; }
|
||||
Maybe<SheetInfo> GetStyleSheetInfo() final;
|
||||
|
||||
already_AddRefed<CharacterData> CloneDataNode(
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "nsIContent.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsHTMLParts.h"
|
||||
#include "nsCRT.h"
|
||||
#include "mozilla/StyleSheetInlines.h"
|
||||
|
@ -27,7 +26,6 @@
|
|||
#include "mozilla/Logging.h"
|
||||
#include "nsRect.h"
|
||||
#include "nsIScriptElement.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsIChannel.h"
|
||||
|
@ -499,14 +497,13 @@ nsresult nsXMLContentSink::CreateElement(
|
|||
if (aNodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML) ||
|
||||
aNodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_XHTML) ||
|
||||
aNodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_SVG)) {
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(content));
|
||||
if (ssle) {
|
||||
if (auto* linkStyle = LinkStyle::FromNode(*content)) {
|
||||
if (aFromParser) {
|
||||
ssle->SetEnableUpdates(false);
|
||||
linkStyle->SetEnableUpdates(false);
|
||||
}
|
||||
if (!aNodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML)) {
|
||||
ssle->SetLineNumber(aFromParser ? aLineNumber : 0);
|
||||
ssle->SetColumnNumber(aFromParser ? aColumnNumber : 0);
|
||||
linkStyle->SetLineNumber(aFromParser ? aLineNumber : 0);
|
||||
linkStyle->SetColumnNumber(aFromParser ? aColumnNumber : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -576,11 +573,10 @@ nsresult nsXMLContentSink::CloseElement(nsIContent* aContent) {
|
|||
} else if (nodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML) ||
|
||||
nodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_XHTML) ||
|
||||
nodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_SVG)) {
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aContent));
|
||||
if (ssle) {
|
||||
ssle->SetEnableUpdates(true);
|
||||
if (auto* linkStyle = LinkStyle::FromNode(*aContent)) {
|
||||
linkStyle->SetEnableUpdates(true);
|
||||
auto updateOrError =
|
||||
ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this);
|
||||
linkStyle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this);
|
||||
if (updateOrError.isErr()) {
|
||||
rv = updateOrError.unwrapErr();
|
||||
} else if (updateOrError.unwrap().ShouldBlock() && !mRunsToCompletion) {
|
||||
|
@ -1164,10 +1160,9 @@ nsXMLContentSink::HandleProcessingInstruction(const char16_t* aTarget,
|
|||
RefPtr<ProcessingInstruction> node =
|
||||
NS_NewXMLProcessingInstruction(mNodeInfoManager, target, data);
|
||||
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle =
|
||||
do_QueryInterface(ToSupports(node));
|
||||
if (ssle) {
|
||||
ssle->SetEnableUpdates(false);
|
||||
auto* linkStyle = LinkStyle::FromNode(*node);
|
||||
if (linkStyle) {
|
||||
linkStyle->SetEnableUpdates(false);
|
||||
mPrettyPrintXML = false;
|
||||
}
|
||||
|
||||
|
@ -1175,12 +1170,12 @@ nsXMLContentSink::HandleProcessingInstruction(const char16_t* aTarget,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
DidAddContent();
|
||||
|
||||
if (ssle) {
|
||||
if (linkStyle) {
|
||||
// This is an xml-stylesheet processing instruction... but it might not be
|
||||
// a CSS one if the type is set to something else.
|
||||
ssle->SetEnableUpdates(true);
|
||||
linkStyle->SetEnableUpdates(true);
|
||||
auto updateOrError =
|
||||
ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this);
|
||||
linkStyle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this);
|
||||
if (updateOrError.isErr()) {
|
||||
return updateOrError.unwrapErr();
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "nsNameSpaceManager.h"
|
||||
#include "txStringUtils.h"
|
||||
#include "txURIUtils.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsIDocumentTransformer.h"
|
||||
#include "mozilla/StyleSheetInlines.h"
|
||||
#include "mozilla/css/Loader.h"
|
||||
|
@ -289,11 +288,9 @@ nsresult txMozillaXMLOutput::endElement() {
|
|||
|
||||
if (mCreatingNewDocument) {
|
||||
// Handle all sorts of stylesheets
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle =
|
||||
do_QueryInterface(mCurrentNode);
|
||||
if (ssle) {
|
||||
ssle->SetEnableUpdates(true);
|
||||
auto updateOrError = ssle->UpdateStyleSheet(mNotifier);
|
||||
if (auto* linkStyle = LinkStyle::FromNode(*mCurrentNode)) {
|
||||
linkStyle->SetEnableUpdates(true);
|
||||
auto updateOrError = linkStyle->UpdateStyleSheet(mNotifier);
|
||||
if (mNotifier && updateOrError.isOk() &&
|
||||
updateOrError.unwrap().ShouldBlock()) {
|
||||
mNotifier->AddPendingStylesheet();
|
||||
|
@ -352,20 +349,20 @@ nsresult txMozillaXMLOutput::processingInstruction(const nsString& aTarget,
|
|||
nsCOMPtr<nsIContent> pi =
|
||||
NS_NewXMLProcessingInstruction(mNodeInfoManager, aTarget, aData);
|
||||
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle;
|
||||
LinkStyle* linkStyle = nullptr;
|
||||
if (mCreatingNewDocument) {
|
||||
ssle = do_QueryInterface(pi);
|
||||
if (ssle) {
|
||||
ssle->SetEnableUpdates(false);
|
||||
linkStyle = LinkStyle::FromNode(*pi);
|
||||
if (linkStyle) {
|
||||
linkStyle->SetEnableUpdates(false);
|
||||
}
|
||||
}
|
||||
|
||||
rv = mCurrentNode->AppendChildTo(pi, true);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (ssle) {
|
||||
ssle->SetEnableUpdates(true);
|
||||
auto updateOrError = ssle->UpdateStyleSheet(mNotifier);
|
||||
if (linkStyle) {
|
||||
linkStyle->SetEnableUpdates(true);
|
||||
auto updateOrError = linkStyle->UpdateStyleSheet(mNotifier);
|
||||
if (mNotifier && updateOrError.isOk() &&
|
||||
updateOrError.unwrap().ShouldBlock()) {
|
||||
mNotifier->AddPendingStylesheet();
|
||||
|
@ -497,10 +494,8 @@ nsresult txMozillaXMLOutput::startElementInternal(nsAtom* aPrefix,
|
|||
|
||||
if (mCreatingNewDocument) {
|
||||
// Handle all sorts of stylesheets
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle =
|
||||
do_QueryInterface(mOpenedElement);
|
||||
if (ssle) {
|
||||
ssle->SetEnableUpdates(false);
|
||||
if (auto* linkStyle = LinkStyle::FromNodeOrNull(mOpenedElement)) {
|
||||
linkStyle->SetEnableUpdates(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "gfxTextRun.h"
|
||||
#include "nsArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsIContentInlines.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "ChildIterator.h"
|
||||
|
@ -269,19 +268,14 @@ uint32_t InspectorUtils::GetRelativeRuleLine(GlobalObject& aGlobal,
|
|||
// a 0 lineNumber.
|
||||
StyleSheet* sheet = aRule.GetStyleSheet();
|
||||
if (sheet && lineNumber != 0) {
|
||||
nsINode* owningNode = sheet->GetOwnerNode();
|
||||
if (owningNode) {
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> link =
|
||||
do_QueryInterface(owningNode);
|
||||
if (link) {
|
||||
// Check for underflow, which is one indication that we're
|
||||
// trying to remap an already relative lineNumber.
|
||||
uint32_t linkLineIndex0 = link->GetLineNumber() - 1;
|
||||
if (linkLineIndex0 > lineNumber) {
|
||||
lineNumber = 0;
|
||||
} else {
|
||||
lineNumber -= linkLineIndex0;
|
||||
}
|
||||
if (auto* link = LinkStyle::FromNodeOrNull(sheet->GetOwnerNode())) {
|
||||
// Check for underflow, which is one indication that we're
|
||||
// trying to remap an already relative lineNumber.
|
||||
uint32_t linkLineIndex0 = link->GetLineNumber() - 1;
|
||||
if (linkLineIndex0 > lineNumber) {
|
||||
lineNumber = 0;
|
||||
} else {
|
||||
lineNumber -= linkLineIndex0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
#include "nsIClassOfService.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsMimeTypes.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsICSSLoaderObserver.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsGkAtoms.h"
|
||||
|
@ -274,12 +273,14 @@ namespace css {
|
|||
********************************/
|
||||
NS_IMPL_ISUPPORTS(SheetLoadData, nsIRunnable, nsIThreadObserver)
|
||||
|
||||
SheetLoadData::SheetLoadData(
|
||||
Loader* aLoader, const nsAString& aTitle, nsIURI* aURI, StyleSheet* aSheet,
|
||||
bool aSyncLoad, nsIStyleSheetLinkingElement* aOwningElement,
|
||||
IsAlternate aIsAlternate, MediaMatched aMediaMatches, IsPreload aIsPreload,
|
||||
nsICSSLoaderObserver* aObserver, nsIPrincipal* aLoaderPrincipal,
|
||||
nsIReferrerInfo* aReferrerInfo, nsINode* aRequestingNode)
|
||||
SheetLoadData::SheetLoadData(Loader* aLoader, const nsAString& aTitle,
|
||||
nsIURI* aURI, StyleSheet* aSheet, bool aSyncLoad,
|
||||
nsINode* aOwningNode, IsAlternate aIsAlternate,
|
||||
MediaMatched aMediaMatches, IsPreload aIsPreload,
|
||||
nsICSSLoaderObserver* aObserver,
|
||||
nsIPrincipal* aLoaderPrincipal,
|
||||
nsIReferrerInfo* aReferrerInfo,
|
||||
nsINode* aRequestingNode)
|
||||
: mLoader(aLoader),
|
||||
mTitle(aTitle),
|
||||
mEncoding(nullptr),
|
||||
|
@ -302,12 +303,14 @@ SheetLoadData::SheetLoadData(
|
|||
mBlockResourceTiming(false),
|
||||
mLoadFailed(false),
|
||||
mIsPreload(aIsPreload),
|
||||
mOwningElement(aOwningElement),
|
||||
mOwningNode(aOwningNode),
|
||||
mObserver(aObserver),
|
||||
mLoaderPrincipal(aLoaderPrincipal),
|
||||
mReferrerInfo(aReferrerInfo),
|
||||
mRequestingNode(aRequestingNode),
|
||||
mPreloadEncoding(nullptr) {
|
||||
MOZ_ASSERT(!mOwningNode || dom::LinkStyle::FromNode(*mOwningNode),
|
||||
"Must implement LinkStyle");
|
||||
MOZ_ASSERT(mLoader, "Must have a loader!");
|
||||
}
|
||||
|
||||
|
@ -339,7 +342,7 @@ SheetLoadData::SheetLoadData(Loader* aLoader, nsIURI* aURI, StyleSheet* aSheet,
|
|||
mBlockResourceTiming(false),
|
||||
mLoadFailed(false),
|
||||
mIsPreload(IsPreload::No),
|
||||
mOwningElement(nullptr),
|
||||
mOwningNode(nullptr),
|
||||
mObserver(aObserver),
|
||||
mLoaderPrincipal(aLoaderPrincipal),
|
||||
mReferrerInfo(aReferrerInfo),
|
||||
|
@ -381,7 +384,7 @@ SheetLoadData::SheetLoadData(
|
|||
mBlockResourceTiming(false),
|
||||
mLoadFailed(false),
|
||||
mIsPreload(aIsPreload),
|
||||
mOwningElement(nullptr),
|
||||
mOwningNode(nullptr),
|
||||
mObserver(aObserver),
|
||||
mLoaderPrincipal(aLoaderPrincipal),
|
||||
mReferrerInfo(aReferrerInfo),
|
||||
|
@ -439,8 +442,8 @@ void SheetLoadData::FireLoadEvent(nsIThreadInternal* aThread) {
|
|||
aThread->RemoveObserver(this);
|
||||
|
||||
// Now fire the event
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(mOwningElement);
|
||||
NS_ASSERTION(node, "How did that happen???");
|
||||
nsCOMPtr<nsINode> node = mOwningNode;
|
||||
MOZ_ASSERT(node, "How did that happen???");
|
||||
|
||||
nsContentUtils::DispatchTrustedEvent(
|
||||
node->OwnerDoc(), node,
|
||||
|
@ -452,7 +455,7 @@ void SheetLoadData::FireLoadEvent(nsIThreadInternal* aThread) {
|
|||
}
|
||||
|
||||
void SheetLoadData::ScheduleLoadEventIfNeeded() {
|
||||
if (!mOwningElement) {
|
||||
if (!mOwningNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -794,9 +797,9 @@ NotNull<const Encoding*> SheetLoadData::DetermineNonBOMEncoding(
|
|||
|
||||
// Now try the charset on the <link> or processing instruction
|
||||
// that loaded us
|
||||
if (mOwningElement) {
|
||||
if (mOwningNode) {
|
||||
nsAutoString label16;
|
||||
mOwningElement->GetCharset(label16);
|
||||
LinkStyle::FromNode(*mOwningNode)->GetCharset(label16);
|
||||
encoding = Encoding::ForLabel(label16);
|
||||
if (encoding) {
|
||||
return WrapNotNull(encoding);
|
||||
|
@ -898,10 +901,9 @@ nsresult SheetLoadData::VerifySheetReadyToParse(nsresult aStatus,
|
|||
aStatus)) {
|
||||
if (Document* doc = mLoader->GetDocument()) {
|
||||
for (SheetLoadData* data = this; data; data = data->mNext) {
|
||||
// mOwningElement may be null but AddBlockTrackingNode can cope
|
||||
nsCOMPtr<nsIContent> content =
|
||||
do_QueryInterface(data->mOwningElement);
|
||||
doc->AddBlockedNodeByClassifier(content);
|
||||
// mOwningNode may be null but AddBlockTrackingNode can cope
|
||||
doc->AddBlockedNodeByClassifier(
|
||||
nsIContent::FromNodeOrNull(data->mOwningNode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1251,10 +1253,8 @@ void Loader::InsertSheetInTree(StyleSheet& aSheet,
|
|||
aLinkingContent->IsInShadowTree(),
|
||||
"Why would we insert it anywhere?");
|
||||
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> linkingElement =
|
||||
do_QueryInterface(aLinkingContent);
|
||||
if (linkingElement) {
|
||||
linkingElement->SetStyleSheet(&aSheet);
|
||||
if (auto* linkStyle = LinkStyle::FromNodeOrNull(aLinkingContent)) {
|
||||
linkStyle->SetStyleSheet(&aSheet);
|
||||
}
|
||||
|
||||
ShadowRoot* shadow =
|
||||
|
@ -1940,6 +1940,7 @@ Result<Loader::LoadSheetResult, nsresult> Loader::LoadInlineStyle(
|
|||
const SheetInfo& aInfo, const nsAString& aBuffer, uint32_t aLineNumber,
|
||||
nsICSSLoaderObserver* aObserver) {
|
||||
LOG(("css::Loader::LoadInlineStyle"));
|
||||
MOZ_ASSERT(aInfo.mContent);
|
||||
|
||||
if (!mEnabled) {
|
||||
LOG_WARN((" Not enabled"));
|
||||
|
@ -1950,9 +1951,8 @@ Result<Loader::LoadSheetResult, nsresult> Loader::LoadInlineStyle(
|
|||
return Err(NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> owningElement(
|
||||
do_QueryInterface(aInfo.mContent));
|
||||
NS_ASSERTION(owningElement, "Element is not a style linking element!");
|
||||
MOZ_ASSERT(LinkStyle::FromNodeOrNull(aInfo.mContent),
|
||||
"Element is not a style linking element!");
|
||||
|
||||
// Since we're not planning to load a URI, no need to hand a principal to the
|
||||
// load data or to CreateSheet().
|
||||
|
@ -2013,7 +2013,7 @@ Result<Loader::LoadSheetResult, nsresult> Loader::LoadInlineStyle(
|
|||
completed = Completed::Yes;
|
||||
} else {
|
||||
auto data = MakeRefPtr<SheetLoadData>(
|
||||
this, aInfo.mTitle, nullptr, sheet, false, owningElement, isAlternate,
|
||||
this, aInfo.mTitle, nullptr, sheet, false, aInfo.mContent, isAlternate,
|
||||
matched, IsPreload::No, aObserver, nullptr, aInfo.mReferrerInfo,
|
||||
aInfo.mContent);
|
||||
data->mLineNumber = aLineNumber;
|
||||
|
@ -2105,20 +2105,16 @@ Result<Loader::LoadSheetResult, nsresult> Loader::LoadStyleLink(
|
|||
|
||||
InsertSheetInTree(*sheet, aInfo.mContent);
|
||||
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> owningElement(
|
||||
do_QueryInterface(aInfo.mContent));
|
||||
// We may get here with no content for Link: headers for example.
|
||||
MOZ_ASSERT(!!owningElement == !!aInfo.mContent,
|
||||
"If there is any node, it should be an "
|
||||
"nsIStyleSheetLinkingElement");
|
||||
|
||||
MOZ_ASSERT(!aInfo.mContent || LinkStyle::FromNode(*aInfo.mContent),
|
||||
"If there is any node, it should be a LinkStyle");
|
||||
auto data = MakeRefPtr<SheetLoadData>(
|
||||
this, aInfo.mTitle, aInfo.mURI, sheet, syncLoad, owningElement,
|
||||
this, aInfo.mTitle, aInfo.mURI, sheet, syncLoad, aInfo.mContent,
|
||||
isAlternate, matched, IsPreload::No, aObserver, principal,
|
||||
aInfo.mReferrerInfo, context);
|
||||
if (state == SheetState::Complete) {
|
||||
LOG((" Sheet already complete: 0x%p", sheet.get()));
|
||||
if (aObserver || !mObservers.IsEmpty() || owningElement) {
|
||||
if (aObserver || !mObservers.IsEmpty() || aInfo.mContent) {
|
||||
rv = PostLoadEvent(std::move(data));
|
||||
if (NS_FAILED(rv)) {
|
||||
return Err(rv);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/CORSMode.h"
|
||||
#include "mozilla/dom/LinkStyle.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/StyleSheet.h"
|
||||
|
@ -23,7 +24,6 @@
|
|||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsDataHashtable.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsRefPtrHashtable.h"
|
||||
#include "nsStringFwd.h"
|
||||
#include "nsTArray.h"
|
||||
|
@ -91,14 +91,14 @@ class Loader final {
|
|||
using ReferrerPolicy = dom::ReferrerPolicy;
|
||||
|
||||
public:
|
||||
typedef nsIStyleSheetLinkingElement::Completed Completed;
|
||||
typedef nsIStyleSheetLinkingElement::HasAlternateRel HasAlternateRel;
|
||||
typedef nsIStyleSheetLinkingElement::IsAlternate IsAlternate;
|
||||
typedef nsIStyleSheetLinkingElement::IsInline IsInline;
|
||||
typedef nsIStyleSheetLinkingElement::IsExplicitlyEnabled IsExplicitlyEnabled;
|
||||
typedef nsIStyleSheetLinkingElement::MediaMatched MediaMatched;
|
||||
typedef nsIStyleSheetLinkingElement::Update LoadSheetResult;
|
||||
typedef nsIStyleSheetLinkingElement::SheetInfo SheetInfo;
|
||||
using Completed = dom::LinkStyle::Completed;
|
||||
using HasAlternateRel = dom::LinkStyle::HasAlternateRel;
|
||||
using IsAlternate = dom::LinkStyle::IsAlternate;
|
||||
using IsInline = dom::LinkStyle::IsInline;
|
||||
using IsExplicitlyEnabled = dom::LinkStyle::IsExplicitlyEnabled;
|
||||
using MediaMatched = dom::LinkStyle::MediaMatched;
|
||||
using LoadSheetResult = dom::LinkStyle::Update;
|
||||
using SheetInfo = dom::LinkStyle::SheetInfo;
|
||||
|
||||
Loader();
|
||||
// aDocGroup is used for dispatching SheetLoadData in PostLoadEvent(). It
|
||||
|
|
|
@ -36,8 +36,8 @@ static_assert(eAuthorSheetFeatures == 0 && eUserSheetFeatures == 1 &&
|
|||
"in SheetLoadData::mParsingMode");
|
||||
|
||||
class SheetLoadData final : public nsIRunnable, public nsIThreadObserver {
|
||||
using MediaMatched = nsIStyleSheetLinkingElement::MediaMatched;
|
||||
using IsAlternate = nsIStyleSheetLinkingElement::IsAlternate;
|
||||
using MediaMatched = dom::LinkStyle::MediaMatched;
|
||||
using IsAlternate = dom::LinkStyle::IsAlternate;
|
||||
using IsPreload = Loader::IsPreload;
|
||||
using UseSystemPrincipal = Loader::UseSystemPrincipal;
|
||||
|
||||
|
@ -47,8 +47,7 @@ class SheetLoadData final : public nsIRunnable, public nsIThreadObserver {
|
|||
public:
|
||||
// Data for loading a sheet linked from a document
|
||||
SheetLoadData(Loader* aLoader, const nsAString& aTitle, nsIURI* aURI,
|
||||
StyleSheet* aSheet, bool aSyncLoad,
|
||||
nsIStyleSheetLinkingElement* aOwningElement,
|
||||
StyleSheet* aSheet, bool aSyncLoad, nsINode* aOwningNode,
|
||||
IsAlternate aIsAlternate, MediaMatched aMediaMatched,
|
||||
IsPreload aIsPreload, nsICSSLoaderObserver* aObserver,
|
||||
nsIPrincipal* aLoaderPrincipal, nsIReferrerInfo* aReferrerInfo,
|
||||
|
@ -186,9 +185,9 @@ class SheetLoadData final : public nsIRunnable, public nsIThreadObserver {
|
|||
// which causes a false positive warning here.
|
||||
const IsPreload mIsPreload;
|
||||
|
||||
// This is the element that imported the sheet. Needed to get the
|
||||
// charset set on it and to fire load/error events.
|
||||
const nsCOMPtr<nsIStyleSheetLinkingElement> mOwningElement;
|
||||
// This is the node that imported the sheet. Needed to get the charset set on
|
||||
// it, and to fire load/error events. Must implement LinkStyle.
|
||||
const nsCOMPtr<nsINode> mOwningNode;
|
||||
|
||||
// The observer that wishes to be notified of load completion
|
||||
const nsCOMPtr<nsICSSLoaderObserver> mObserver;
|
||||
|
|
|
@ -1255,11 +1255,8 @@ void StyleSheet::ReparseSheet(const nsACString& aInput, ErrorResult& aRv) {
|
|||
Inner().mChildren.Clear();
|
||||
|
||||
uint32_t lineNumber = 1;
|
||||
if (mOwningNode) {
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> link = do_QueryInterface(mOwningNode);
|
||||
if (link) {
|
||||
lineNumber = link->GetLineNumber();
|
||||
}
|
||||
if (auto* linkStyle = LinkStyle::FromNodeOrNull(mOwningNode)) {
|
||||
lineNumber = linkStyle->GetLineNumber();
|
||||
}
|
||||
|
||||
// Notify to the stylesets about the old rules going away.
|
||||
|
|
|
@ -7,9 +7,10 @@
|
|||
#include "nsHtml5DocumentBuilder.h"
|
||||
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "mozilla/dom/LinkStyle.h"
|
||||
#include "nsNameSpaceManager.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
|
||||
using mozilla::dom::LinkStyle;
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHtml5DocumentBuilder, nsContentSink,
|
||||
mOwnedElements)
|
||||
|
@ -47,8 +48,8 @@ void nsHtml5DocumentBuilder::SetDocumentCharsetAndSource(
|
|||
}
|
||||
|
||||
void nsHtml5DocumentBuilder::UpdateStyleSheet(nsIContent* aElement) {
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aElement));
|
||||
if (!ssle) {
|
||||
auto* linkStyle = LinkStyle::FromNode(*aElement);
|
||||
if (!linkStyle) {
|
||||
MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled,
|
||||
"Node didn't QI to style, but SVG wasn't disabled.");
|
||||
return;
|
||||
|
@ -63,10 +64,10 @@ void nsHtml5DocumentBuilder::UpdateStyleSheet(nsIContent* aElement) {
|
|||
return;
|
||||
}
|
||||
|
||||
ssle->SetEnableUpdates(true);
|
||||
linkStyle->SetEnableUpdates(true);
|
||||
|
||||
auto updateOrError =
|
||||
ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this);
|
||||
linkStyle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this);
|
||||
|
||||
if (updateOrError.isOk() && updateOrError.unwrap().ShouldBlock() &&
|
||||
!mRunsToCompletion) {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "mozilla/dom/Comment.h"
|
||||
#include "mozilla/dom/DocumentType.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/LinkStyle.h"
|
||||
#include "mozilla/dom/HTMLFormElement.h"
|
||||
#include "mozilla/dom/HTMLImageElement.h"
|
||||
#include "mozilla/dom/HTMLTemplateElement.h"
|
||||
|
@ -31,13 +32,13 @@
|
|||
#include "nsINode.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsIScriptElement.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsTextNode.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
using mozilla::dom::Document;
|
||||
|
||||
/**
|
||||
|
@ -456,9 +457,8 @@ nsIContent* nsHtml5TreeOperation::CreateHTMLElement(
|
|||
aBuilder->HoldElement(newElement.forget());
|
||||
|
||||
if (MOZ_UNLIKELY(aName == nsGkAtoms::style || aName == nsGkAtoms::link)) {
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(newContent));
|
||||
if (ssle) {
|
||||
ssle->SetEnableUpdates(false);
|
||||
if (auto* linkStyle = dom::LinkStyle::FromNode(*newContent)) {
|
||||
linkStyle->SetEnableUpdates(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -483,9 +483,8 @@ nsIContent* nsHtml5TreeOperation::CreateHTMLElement(
|
|||
aBuilder->HoldElement(newElement.forget());
|
||||
|
||||
if (MOZ_UNLIKELY(aName == nsGkAtoms::style || aName == nsGkAtoms::link)) {
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(newContent));
|
||||
if (ssle) {
|
||||
ssle->SetEnableUpdates(false);
|
||||
if (auto* linkStyle = dom::LinkStyle::FromNode(*newContent)) {
|
||||
linkStyle->SetEnableUpdates(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -531,9 +530,8 @@ nsIContent* nsHtml5TreeOperation::CreateSVGElement(
|
|||
aBuilder->HoldElement(newElement.forget());
|
||||
|
||||
if (MOZ_UNLIKELY(aName == nsGkAtoms::style)) {
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(newContent));
|
||||
if (ssle) {
|
||||
ssle->SetEnableUpdates(false);
|
||||
if (auto* linkStyle = dom::LinkStyle::FromNode(*newContent)) {
|
||||
linkStyle->SetEnableUpdates(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -991,9 +989,8 @@ nsresult nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
|
|||
|
||||
nsresult operator()(const opSetStyleLineNumber& aOperation) {
|
||||
nsIContent* node = *(aOperation.mContent);
|
||||
nsCOMPtr<nsIStyleSheetLinkingElement> ssle = do_QueryInterface(node);
|
||||
if (ssle) {
|
||||
ssle->SetLineNumber(aOperation.mLineNumber);
|
||||
if (auto* linkStyle = dom::LinkStyle::FromNode(*node)) {
|
||||
linkStyle->SetLineNumber(aOperation.mLineNumber);
|
||||
} else {
|
||||
MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled,
|
||||
"Node didn't QI to style, but SVG wasn't disabled.");
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include "nsINode.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "mozilla/AsyncEventDispatcher.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
|
Загрузка…
Ссылка в новой задаче