Merge remote-tracking branch 'origin/tracking' into custom

This commit is contained in:
roytam1 2025-05-14 14:36:05 +08:00
commit e72f8a3a81
140 changed files with 1117 additions and 466 deletions

View file

@ -74,6 +74,7 @@ void
AnonymousContent::SetAttributeForElement(const nsAString& aElementId,
const nsAString& aName,
const nsAString& aValue,
nsIPrincipal* aSubjectPrincipal,
ErrorResult& aRv)
{
Element* element = GetElementById(aElementId);
@ -82,7 +83,7 @@ AnonymousContent::SetAttributeForElement(const nsAString& aElementId,
return;
}
element->SetAttribute(aName, aValue, aRv);
element->SetAttribute(aName, aValue, aSubjectPrincipal, aRv);
}
void

View file

@ -42,6 +42,7 @@ public:
void SetAttributeForElement(const nsAString& aElementId,
const nsAString& aName,
const nsAString& aValue,
nsIPrincipal* aSubjectPrincipal,
ErrorResult& aRv);
void GetAttributeForElement(const nsAString& aElementId,

View file

@ -174,7 +174,7 @@ Attr::GetValue(nsAString& aValue)
}
void
Attr::SetValue(const nsAString& aValue, ErrorResult& aRv)
Attr::SetValue(const nsAString& aValue, nsIPrincipal* aTriggeringPrincipal, ErrorResult& aRv)
{
Element* element = GetElement();
if (!element) {
@ -187,6 +187,7 @@ Attr::SetValue(const nsAString& aValue, ErrorResult& aRv)
nameAtom,
mNodeInfo->GetPrefixAtom(),
aValue,
aTriggeringPrincipal,
true);
}
@ -194,7 +195,7 @@ NS_IMETHODIMP
Attr::SetValue(const nsAString& aValue)
{
ErrorResult rv;
SetValue(aValue, rv);
SetValue(aValue, nullptr, rv);
return rv.StealNSResult();
}

View file

@ -84,9 +84,13 @@ public:
virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
// XPCOM GetName() is OK
// XPCOM GetValue() is OK
void SetValue(const nsAString& aValue, ErrorResult& aRv);
void GetValue(nsString& val, nsIPrincipal&)
{
GetValue(val);
}
void SetValue(const nsAString& aValue, nsIPrincipal* aTriggeringPrincipal, ErrorResult& aRv);
bool Specified() const;

View file

@ -69,13 +69,10 @@ public:
virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
// nsIContent
nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAString& aValue, bool aNotify)
{
return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
}
using nsIContent::SetAttr;
virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override
{
return NS_OK;

View file

@ -1254,6 +1254,7 @@ Element::ToggleAttribute(const nsAString& aName,
void
Element::SetAttribute(const nsAString& aName,
const nsAString& aValue,
nsIPrincipal* aTriggeringPrincipal,
ErrorResult& aError)
{
aError = nsContentUtils::CheckQName(aName, false);
@ -1269,12 +1270,12 @@ Element::SetAttribute(const nsAString& aName,
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
aError = SetAttr(kNameSpaceID_None, nameAtom, aValue, true);
aError = SetAttr(kNameSpaceID_None, nameAtom, aValue, aTriggeringPrincipal, true);
return;
}
aError = SetAttr(name->NamespaceID(), name->LocalName(), name->GetPrefix(),
aValue, true);
aValue, aTriggeringPrincipal, true);
return;
}
@ -1357,6 +1358,7 @@ void
Element::SetAttributeNS(const nsAString& aNamespaceURI,
const nsAString& aQualifiedName,
const nsAString& aValue,
nsIPrincipal* aTriggeringPrincipal,
ErrorResult& aError)
{
RefPtr<mozilla::dom::NodeInfo> ni;
@ -1370,7 +1372,7 @@ Element::SetAttributeNS(const nsAString& aNamespaceURI,
}
aError = SetAttr(ni->NamespaceID(), ni->NameAtom(), ni->GetPrefixAtom(),
aValue, true);
aValue, aTriggeringPrincipal, true);
}
void
@ -2419,6 +2421,7 @@ Element::SetSingleClassFromParser(nsIAtom* aSingleClassName)
nullptr, // prefix
nullptr, // old value
value,
nullptr, // subject principal
static_cast<uint8_t>(nsIDOMMutationEvent::ADDITION),
false, // hasListeners
false, // notify
@ -2430,6 +2433,7 @@ Element::SetSingleClassFromParser(nsIAtom* aSingleClassName)
nsresult
Element::SetAttr(int32_t aNamespaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
// Keep this in sync with SetParsedAttr below and SetSingleClassFromParser
@ -2489,7 +2493,8 @@ Element::SetAttr(int32_t aNamespaceID, nsIAtom* aName,
return SetAttrAndNotify(aNamespaceID, aName, aPrefix,
oldValueSet ? &oldValue : nullptr,
attrValue, modType, hasListeners, aNotify,
attrValue, aSubjectPrincipal, modType,
hasListeners, aNotify,
kCallAfterSetAttr, document, updateBatch);
}
@ -2534,7 +2539,7 @@ Element::SetParsedAttr(int32_t aNamespaceID, nsIAtom* aName,
mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);
return SetAttrAndNotify(aNamespaceID, aName, aPrefix,
oldValueSet ? &oldValue : nullptr,
aParsedValue, modType, hasListeners, aNotify,
aParsedValue, nullptr, modType, hasListeners, aNotify,
kCallAfterSetAttr, document, updateBatch);
}
@ -2544,6 +2549,7 @@ Element::SetAttrAndNotify(int32_t aNamespaceID,
nsIAtom* aPrefix,
const nsAttrValue* aOldValue,
nsAttrValue& aParsedValue,
nsIPrincipal* aSubjectPrincipal,
uint8_t aModType,
bool aFireMutation,
bool aNotify,
@ -2650,7 +2656,7 @@ Element::SetAttrAndNotify(int32_t aNamespaceID,
if (aCallAfterSetAttr) {
rv = AfterSetAttr(aNamespaceID, aName, &valueForAfterSetAttr, oldValue,
aNotify);
aSubjectPrincipal, aNotify);
NS_ENSURE_SUCCESS(rv, rv);
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::dir) {
@ -2946,7 +2952,7 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
}
rv = AfterSetAttr(aNameSpaceID, aName, nullptr, &oldValue, aNotify);
rv = AfterSetAttr(aNameSpaceID, aName, nullptr, &oldValue, nullptr, aNotify);
NS_ENSURE_SUCCESS(rv, rv);
UpdateState(aNotify);
@ -4047,9 +4053,16 @@ Element::GetReferrerPolicyAsEnum()
if (Preferences::GetBool("network.http.enablePerElementReferrer", true) &&
IsHTMLElement()) {
const nsAttrValue* referrerValue = GetParsedAttr(nsGkAtoms::referrerpolicy);
if (referrerValue && referrerValue->Type() == nsAttrValue::eEnum) {
return net::ReferrerPolicy(referrerValue->GetEnumValue());
}
return ReferrerPolicyFromAttr(referrerValue);
}
return net::RP_Unset;
}
net::ReferrerPolicy
Element::ReferrerPolicyFromAttr(const nsAttrValue* aValue)
{
if (aValue && aValue->Type() == nsAttrValue::eEnum) {
return net::ReferrerPolicy(aValue->GetEnumValue());
}
return net::RP_Unset;
}

View file

@ -542,12 +542,7 @@ public:
already_AddRefed<mozilla::dom::NodeInfo>
GetExistingAttrNameFromQName(const nsAString& aStr) const;
MOZ_ALWAYS_INLINE // Avoid a crashy hook from Avast 10 Beta (Bug 1058131)
nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAString& aValue, bool aNotify)
{
return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
}
using nsIContent::SetAttr;
/**
* Helper for SetAttr/SetParsedAttr. This method will return true if aNotify
@ -610,7 +605,8 @@ public:
nsresult SetSingleClassFromParser(nsIAtom* aSingleClassName);
virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsIAtom* aPrefix,
const nsAString& aValue, bool aNotify) override;
const nsAString& aValue, nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
// aParsedValue receives the old value of the attribute. That's useful if
// either the input or output value of aParsedValue is StoresOwnData.
nsresult SetParsedAttr(int32_t aNameSpaceID, nsIAtom* aName, nsIAtom* aPrefix,
@ -783,11 +779,18 @@ public:
bool ToggleAttribute(const nsAString& aName, const Optional<bool>& aForce,
ErrorResult& aError);
void SetAttribute(const nsAString& aName, const nsAString& aValue,
ErrorResult& aError);
nsIPrincipal* aTriggeringPrincipal, ErrorResult& aError);
void SetAttributeNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName,
const nsAString& aValue,
nsIPrincipal* aTriggeringPrincipal,
ErrorResult& aError);
void SetAttribute(const nsAString& aName, const nsAString& aValue,
ErrorResult& aError)
{
SetAttribute(aName, aValue, nullptr, aError);
}
void RemoveAttribute(const nsAString& aName,
ErrorResult& aError);
void RemoveAttributeNS(const nsAString& aNamespaceURI,
@ -1232,6 +1235,11 @@ public:
aError = SetAttr(kNameSpaceID_None, aAttr, aValue, true);
}
void SetAttr(nsIAtom* aAttr, const nsAString& aValue, nsIPrincipal& aTriggeringPrincipal, ErrorResult& aError)
{
aError = nsIContent::SetAttr(kNameSpaceID_None, aAttr, aValue, &aTriggeringPrincipal, true);
}
/**
* Set a content attribute via a reflecting nullable string IDL
* attribute (e.g. a CORS attribute). If DOMStringIsNull(aValue),
@ -1257,6 +1265,7 @@ public:
float FontSizeInflation();
net::ReferrerPolicy GetReferrerPolicyAsEnum();
net::ReferrerPolicy ReferrerPolicyFromAttr(const nsAttrValue* aValue);
/*
* Helpers for .dataset. This is implemented on Element, though only some
@ -1309,6 +1318,14 @@ protected:
* @param aParsedValue parsed new value of attribute. Replaced by the
* old value of the attribute. This old value is only
* useful if either it or the new value is StoresOwnData.
* @param aMaybeScriptedPrincipal
* the principal of the scripted caller responsible for
* setting the attribute, or null if no scripted caller
* can be determined. A null value here does not
* guarantee that there is no scripted caller, but a
* non-null value does guarantee that a scripted caller
* with the given principal is directly responsible for
* the attribute change.
* @param aModType nsIDOMMutationEvent::MODIFICATION or ADDITION. Only
* needed if aFireMutation or aNotify is true.
* @param aFireMutation should mutation-events be fired?
@ -1321,6 +1338,7 @@ protected:
nsIAtom* aPrefix,
const nsAttrValue* aOldValue,
nsAttrValue& aParsedValue,
nsIPrincipal* aMaybeScriptedPrincipal,
uint8_t aModType,
bool aFireMutation,
bool aNotify,
@ -1412,13 +1430,21 @@ protected:
* the attr was not previously set. This argument may not have the
* correct value for SVG elements, or other cases in which the
* attribute value doesn't store its own data
* @param aMaybeScriptedPrincipal the principal of the scripted caller
* responsible for setting the attribute, or null if no scripted caller
* can be determined, or the attribute is being unset. A null value
* here does not guarantee that there is no scripted caller, but a
* non-null value does guarantee that a scripted caller with the given
* principal is directly responsible for the attribute change.
* @param aNotify Whether we plan to notify document observers.
*/
// Note that this is inlined so that when subclasses call it it gets
// inlined. Those calls don't go through a vtable.
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify)
{
return NS_OK;
}
@ -1801,7 +1827,7 @@ NS_IMETHOD SetAttribute(const nsAString& name, \
const nsAString& value) override \
{ \
mozilla::ErrorResult rv; \
Element::SetAttribute(name, value, rv); \
Element::SetAttribute(name, value, nullptr, rv); \
return rv.StealNSResult(); \
} \
NS_IMETHOD SetAttributeNS(const nsAString& namespaceURI, \
@ -1809,22 +1835,22 @@ NS_IMETHOD SetAttributeNS(const nsAString& namespaceURI, \
const nsAString& value) final override \
{ \
mozilla::ErrorResult rv; \
Element::SetAttributeNS(namespaceURI, qualifiedName, value, rv); \
return rv.StealNSResult(); \
Element::SetAttributeNS(namespaceURI, qualifiedName, value, nullptr, rv); \
return rv.StealNSResult(); \
} \
using Element::RemoveAttribute; \
NS_IMETHOD RemoveAttribute(const nsAString& name) final override \
{ \
mozilla::ErrorResult rv; \
RemoveAttribute(name, rv); \
return rv.StealNSResult(); \
return rv.StealNSResult(); \
} \
NS_IMETHOD RemoveAttributeNS(const nsAString& namespaceURI, \
const nsAString& localName) final override \
{ \
mozilla::ErrorResult rv; \
Element::RemoveAttributeNS(namespaceURI, localName, rv); \
return rv.StealNSResult(); \
return rv.StealNSResult(); \
} \
using Element::HasAttribute; \
NS_IMETHOD HasAttribute(const nsAString& name, \
@ -1860,7 +1886,7 @@ NS_IMETHOD SetAttributeNode(nsIDOMAttr* newAttr, \
mozilla::ErrorResult rv; \
mozilla::dom::Attr* attr = static_cast<mozilla::dom::Attr*>(newAttr); \
*_retval = Element::SetAttributeNode(*attr, rv).take(); \
return rv.StealNSResult(); \
return rv.StealNSResult(); \
} \
NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* oldAttr, \
nsIDOMAttr** _retval) final override \
@ -1871,7 +1897,7 @@ NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* oldAttr, \
mozilla::ErrorResult rv; \
mozilla::dom::Attr* attr = static_cast<mozilla::dom::Attr*>(oldAttr); \
*_retval = Element::RemoveAttributeNode(*attr, rv).take(); \
return rv.StealNSResult(); \
return rv.StealNSResult(); \
} \
NS_IMETHOD GetAttributeNodeNS(const nsAString& namespaceURI, \
const nsAString& localName, \
@ -1887,7 +1913,7 @@ NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* newAttr, \
mozilla::ErrorResult rv; \
mozilla::dom::Attr* attr = static_cast<mozilla::dom::Attr*>(newAttr); \
*_retval = Element::SetAttributeNodeNS(*attr, rv).take(); \
return rv.StealNSResult(); \
return rv.StealNSResult(); \
} \
NS_IMETHOD GetElementsByTagName(const nsAString& name, \
nsIDOMHTMLCollection** _retval) final \
@ -2055,7 +2081,7 @@ NS_IMETHOD ReleaseCapture(void) final override \
NS_IMETHOD MozRequestFullScreen(void) final override \
{ \
mozilla::ErrorResult rv; \
Element::RequestFullscreen(rv); \
Element::RequestFullscreen(rv); \
return rv.StealNSResult(); \
} \
NS_IMETHOD MozRequestPointerLock(void) final override \

View file

@ -115,7 +115,8 @@ ResponsiveImageSelector::~ResponsiveImageSelector()
// http://www.whatwg.org/specs/web-apps/current-work/#processing-the-image-candidates
bool
ResponsiveImageSelector::SetCandidatesFromSourceSet(const nsAString & aSrcSet)
ResponsiveImageSelector::SetCandidatesFromSourceSet(const nsAString & aSrcSet,
nsIPrincipal* aTriggeringPrincipal)
{
ClearSelectedCandidate();
@ -167,6 +168,8 @@ ResponsiveImageSelector::SetCandidatesFromSourceSet(const nsAString & aSrcSet)
ResponsiveImageCandidate candidate;
if (candidate.ConsumeDescriptors(iter, end)) {
candidate.SetURLSpec(urlStr);
candidate.SetTriggeringPrincipal(nsContentUtils::GetAttrTriggeringPrincipal(
Content(), urlStr, aTriggeringPrincipal));
AppendCandidateIfUnique(candidate);
}
}
@ -207,7 +210,8 @@ ResponsiveImageSelector::Document()
}
void
ResponsiveImageSelector::SetDefaultSource(const nsAString& aURLString)
ResponsiveImageSelector::SetDefaultSource(const nsAString& aURLString,
nsIPrincipal* aPrincipal)
{
ClearSelectedCandidate();
@ -219,6 +223,7 @@ ResponsiveImageSelector::SetDefaultSource(const nsAString& aURLString)
}
mDefaultSourceURL = aURLString;
mDefaultSourceTriggeringPrincipal = aPrincipal;
// Add new default to end of list
MaybeAppendDefaultCandidate();
@ -291,8 +296,9 @@ ResponsiveImageSelector::MaybeAppendDefaultCandidate()
ResponsiveImageCandidate defaultCandidate;
defaultCandidate.SetParameterDefault();
defaultCandidate.SetURLSpec(mDefaultSourceURL);
defaultCandidate.SetTriggeringPrincipal(mDefaultSourceTriggeringPrincipal);
// We don't use MaybeAppend since we want to keep this even if it can never
// match, as it may if the source set changes.
// match, because as it may match if the source set changes dynamically.
mCandidates.AppendElement(defaultCandidate);
}
@ -329,6 +335,17 @@ ResponsiveImageSelector::GetSelectedImageDensity()
return mCandidates[bestIndex].Density(this);
}
nsIPrincipal*
ResponsiveImageSelector::GetSelectedImageTriggeringPrincipal()
{
int bestIndex = GetSelectedCandidateIndex();
if (bestIndex < 0) {
return nullptr;
}
return mCandidates[bestIndex].TriggeringPrincipal();
}
bool
ResponsiveImageSelector::SelectImage(bool aReselect)
{
@ -457,8 +474,10 @@ ResponsiveImageCandidate::ResponsiveImageCandidate()
}
ResponsiveImageCandidate::ResponsiveImageCandidate(const nsAString& aURLString,
double aDensity)
double aDensity,
nsIPrincipal* aTriggeringPrincipal)
: mURLString(aURLString)
, mTriggeringPrincipal(aTriggeringPrincipal)
{
mType = eCandidateType_Density;
mValue.mDensity = aDensity;
@ -471,6 +490,12 @@ ResponsiveImageCandidate::SetURLSpec(const nsAString& aURLString)
mURLString = aURLString;
}
void
ResponsiveImageCandidate::SetTriggeringPrincipal(nsIPrincipal* aPrincipal)
{
mTriggeringPrincipal = aPrincipal;
}
void
ResponsiveImageCandidate::SetParameterAsComputedWidth(int32_t aWidth)
{
@ -717,6 +742,12 @@ ResponsiveImageCandidate::URLString() const
return mURLString;
}
nsIPrincipal*
ResponsiveImageCandidate::TriggeringPrincipal() const
{
return mTriggeringPrincipal;
}
double
ResponsiveImageCandidate::Density(ResponsiveImageSelector *aSelector) const
{

View file

@ -44,14 +44,16 @@ public:
// Given a srcset string, parse and replace current candidates (does not
// replace default source)
bool SetCandidatesFromSourceSet(const nsAString & aSrcSet);
bool SetCandidatesFromSourceSet(const nsAString & aSrcSet,
nsIPrincipal* aTriggeringPrincipal = nullptr);
// Fill the source sizes from a valid sizes descriptor. Returns false if
// descriptor is invalid.
bool SetSizesFromDescriptor(const nsAString & aSizesDescriptor);
// Set the default source, treated as the least-precedence 1.0 density source.
void SetDefaultSource(const nsAString& aURLString);
void SetDefaultSource(const nsAString& aURLString,
nsIPrincipal* aPrincipal = nullptr);
uint32_t NumCandidates(bool aIncludeDefault = true);
@ -69,6 +71,7 @@ public:
// Returns false if there is no selected image
bool GetSelectedImageURLSpec(nsAString& aResult);
double GetSelectedImageDensity();
nsIPrincipal* GetSelectedImageTriggeringPrincipal();
// Runs image selection now if necessary. If an image has already
// been choosen, takes no action unless aReselect is true.
@ -107,6 +110,7 @@ private:
nsCOMPtr<nsINode> mOwnerNode;
// The cached URL for default candidate.
nsString mDefaultSourceURL;
nsCOMPtr<nsIPrincipal> mDefaultSourceTriggeringPrincipal;
// If this array contains an eCandidateType_Default, it should be the last
// element, such that the Setters can preserve/replace it respectively.
nsTArray<ResponsiveImageCandidate> mCandidates;
@ -122,9 +126,11 @@ private:
class ResponsiveImageCandidate {
public:
ResponsiveImageCandidate();
ResponsiveImageCandidate(const nsAString& aURLString, double aDensity);
ResponsiveImageCandidate(const nsAString& aURLString, double aDensity,
nsIPrincipal* aTriggeringPrincipal = nullptr);
void SetURLSpec(const nsAString& aURLString);
void SetTriggeringPrincipal(nsIPrincipal* aPrincipal);
// Set this as a default-candidate. This behaves the same as density 1.0, but
// has a differing type such that it can be replaced by subsequent
// SetDefaultSource calls.
@ -147,6 +153,7 @@ public:
bool HasSameParameter(const ResponsiveImageCandidate & aOther) const;
const nsAString& URLString() const;
nsIPrincipal* TriggeringPrincipal() const;
// Compute and return the density relative to a selector.
double Density(ResponsiveImageSelector *aSelector) const;
@ -171,6 +178,7 @@ public:
private:
nsString mURLString;
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
eCandidateType mType;
union {
double mDensity;

View file

@ -1556,7 +1556,8 @@ WebSocketImpl::Init(JSContext* aCx,
int16_t shouldLoad = nsIContentPolicy::ACCEPT;
aRv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_WEBSOCKET,
uri,
aPrincipal,
aPrincipal, // loading principal
aPrincipal, // triggering principal
originDoc,
EmptyCString(),
nullptr,

View file

@ -152,7 +152,7 @@ NS_CP_ContentTypeName(uint32_t contentType)
return NS_ERROR_FAILURE; \
\
return policy-> action (contentType, contentLocation, requestOrigin, \
context, mimeType, extra, originPrincipal, \
context, mimeType, extra, triggeringPrincipal, \
decision); \
PR_END_MACRO
@ -160,7 +160,7 @@ NS_CP_ContentTypeName(uint32_t contentType)
#define CHECK_CONTENT_POLICY_WITH_SERVICE(action, _policy) \
PR_BEGIN_MACRO \
return _policy-> action (contentType, contentLocation, requestOrigin, \
context, mimeType, extra, originPrincipal, \
context, mimeType, extra, triggeringPrincipal, \
decision); \
PR_END_MACRO
@ -173,14 +173,18 @@ NS_CP_ContentTypeName(uint32_t contentType)
#define CHECK_PRINCIPAL_AND_DATA(action) \
nsCOMPtr<nsIURI> requestOrigin; \
PR_BEGIN_MACRO \
if (originPrincipal) { \
if (loadingPrincipal) { \
nsCOMPtr<nsIScriptSecurityManager> secMan = aSecMan; \
if (!secMan) { \
secMan = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID); \
} \
if (secMan) { \
bool isSystem; \
nsresult rv = secMan->IsSystemPrincipal(originPrincipal, \
/* We exempt most loads into any document with the system principal \
* from content policy checks, mostly as an optimization. Which means \
* that we need to apply this check to the loading principal, not the \
* principal that triggered the load. */ \
nsresult rv = secMan->IsSystemPrincipal(loadingPrincipal, \
&isSystem); \
NS_ENSURE_SUCCESS(rv, rv); \
if (isSystem && contentType != nsIContentPolicy::TYPE_DOCUMENT) { \
@ -203,31 +207,33 @@ NS_CP_ContentTypeName(uint32_t contentType)
dataPolicy-> action (externalType, contentLocation, \
requestOrigin, context, \
mimeType, extra, \
originPrincipal, decision); \
triggeringPrincipal, decision);\
} \
} \
} \
return NS_OK; \
} \
} \
nsresult rv = originPrincipal->GetURI(getter_AddRefs(requestOrigin)); \
nsresult rv = loadingPrincipal->GetURI(getter_AddRefs(requestOrigin)); \
NS_ENSURE_SUCCESS(rv, rv); \
} \
PR_END_MACRO
/**
* Alias for calling ShouldLoad on the content policy service. Parameters are
* the same as nsIContentPolicy::shouldLoad, except for the originPrincipal
* parameter, which should be non-null if possible, and the last two
* parameters, which can be used to pass in pointer to some useful services if
* the caller already has them. The origin URI to pass to shouldLoad will be
* the URI of originPrincipal, unless originPrincipal is null (in which case a
* null origin URI will be passed).
* the same as nsIContentPolicy::shouldLoad, except for the loadingPrincipal
* and triggeringPrincipal parameters (which should be non-null if possible,
* and have the same semantics as in LoadInfo), and the last two parameters,
* which can be used to pass in pointer to some useful services if the caller
* already has them. The origin URI to pass to shouldLoad will be the URI of
* loadingPrincipal, unless loadingPrincipal is null (in which case a null
* origin URI will be passed).
*/
inline nsresult
NS_CheckContentLoadPolicy(uint32_t contentType,
nsIURI *contentLocation,
nsIPrincipal *originPrincipal,
nsIPrincipal *loadingPrincipal,
nsIPrincipal *triggeringPrincipal,
nsISupports *context,
const nsACString &mimeType,
nsISupports *extra,
@ -244,17 +250,19 @@ NS_CheckContentLoadPolicy(uint32_t contentType,
/**
* Alias for calling ShouldProcess on the content policy service. Parameters
* are the same as nsIContentPolicy::shouldLoad, except for the originPrincipal
* parameter, which should be non-null if possible, and the last two
* parameters, which can be used to pass in pointer to some useful services if
* the caller already has them. The origin URI to pass to shouldLoad will be
* the URI of originPrincipal, unless originPrincipal is null (in which case a
* null origin URI will be passed).
* are the same as nsIContentPolicy::shouldLoad, except for the and
* triggeringPrincipal parameters (which should be non-null if possible, and
* have the same semantics as in nsLoadInfo), and the last parameter, which
* can be used to pass in a pointer to a useful service if the caller already
* has it. The origin URI to pass to shouldLoad will be the URI of
* loadingPrincipal, unless loadingPrincipal is null (in which case a null
* origin URI will be passed).
*/
inline nsresult
NS_CheckContentProcessPolicy(uint32_t contentType,
nsIURI *contentLocation,
nsIPrincipal *originPrincipal,
nsIPrincipal *loadingPrincipal,
nsIPrincipal *triggeringPrincipal,
nsISupports *context,
const nsACString &mimeType,
nsISupports *extra,

View file

@ -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);

View file

@ -199,6 +199,7 @@
#include "nsThreadUtils.h"
#include "nsUnicharUtilCIID.h"
#include "nsUnicodeProperties.h"
#include "nsURLHelper.h"
#include "nsViewManager.h"
#include "nsViewportInfo.h"
#include "nsWidgetsCID.h"
@ -2118,6 +2119,54 @@ nsContentUtils::CanCallerAccess(nsPIDOMWindowInner* aWindow)
return CanCallerAccess(SubjectPrincipal(), scriptObject->GetPrincipal());
}
// static
nsIPrincipal*
nsContentUtils::GetAttrTriggeringPrincipal(nsIContent* aContent, const nsAString& aAttrValue,
nsIPrincipal* aSubjectPrincipal)
{
nsIPrincipal* contentPrin = aContent ? aContent->NodePrincipal() : nullptr;
// If the subject principal is the same as the content principal, or no
// explicit subject principal was provided, we don't need to do any further
// checks. Just return the content principal.
if (contentPrin == aSubjectPrincipal || !aSubjectPrincipal) {
return contentPrin;
}
// If the attribute value is empty, it's not an absolute URL, so don't bother
// with more expensive checks.
if (!aAttrValue.IsEmpty() &&
IsAbsoluteURL(NS_ConvertUTF16toUTF8(aAttrValue))) {
return aSubjectPrincipal;
}
return contentPrin;
}
// static
bool
nsContentUtils::IsAbsoluteURL(const nsACString& aURL)
{
nsAutoCString scheme;
if (NS_FAILED(net_ExtractURLScheme(aURL, scheme))) {
// If we can't extract a scheme, it's not an absolute URL.
return false;
}
// If it parses as an absolute StandardURL, it's definitely an absolute URL,
// so no need to check with the IO service.
if (net_IsAbsoluteURL(aURL)) {
return true;
}
uint32_t flags;
if (NS_SUCCEEDED(sIOService->GetProtocolFlags(scheme.get(), &flags))) {
return flags & nsIProtocolHandler::URI_NORELATIVE;
}
return false;
}
//static
bool
nsContentUtils::InProlog(nsINode *aNode)
@ -3289,6 +3338,7 @@ nsContentUtils::CanLoadImage(nsIURI* aURI, nsISupports* aContext,
rv = NS_CheckContentLoadPolicy(aContentType,
aURI,
aLoadingPrincipal,
aLoadingPrincipal, // triggering principal
aContext,
EmptyCString(), //mime guess
nullptr, //extra
@ -8930,6 +8980,25 @@ nsContentUtils::StreamsEnabled(JSContext* aCx, JSObject* aObj)
return workerPrivate->StreamsEnabled();
}
// static
bool
nsContentUtils::CSPEnabled(JSContext* aCx, JSObject* aObj)
{
if (NS_IsMainThread()) {
return Preferences::GetBool("security.csp.enabled", true);
}
using namespace workers;
// Otherwise, check the pref via the WorkerPrivate
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
if (!workerPrivate) {
return false;
}
return workerPrivate->CSPEnabled();
}
// static
bool
nsContentUtils::IsNonSubresourceRequest(nsIChannel* aChannel)

View file

@ -526,6 +526,40 @@ public:
// aWindow can be either outer or inner window.
static bool CanCallerAccess(nsPIDOMWindowInner* aWindow);
/**
* Returns the triggering principal which should be used for the given URL
* attribute value with the given subject principal.
*
* If the attribute value is not an absolute URL, the subject principal will
* be ignored, and the node principal of aContent will be used instead.
* If aContent is non-null, this function will always return a principal.
* Otherewise, it may return null if aSubjectPrincipal is null or is rejected
* based on the attribute value.
*
* @param aContent The content on which the attribute is being set.
* @param aAttrValue The URL value of the attribute. For parsed attribute
* values, such as `srcset`, this function should be called separately
* for each URL value it contains.
* @param aSubjectPrincipal The subject principal of the scripted caller
* responsible for setting the attribute, or null if no scripted caller
* can be determined.
*/
static nsIPrincipal* GetAttrTriggeringPrincipal(nsIContent* aContent,
const nsAString& aAttrValue,
nsIPrincipal* aSubjectPrincipal);
/**
* Returns true if the given string is guaranteed to be treated as an absolute
* URL, rather than a relative URL. In practice, this means any complete URL
* as supported by nsStandardURL, or any string beginning with a valid scheme
* which is known to the IO service, and has the URI_NORELATIVE flag.
*
* If the URL may be treated as absolute in some cases, but relative in others
* (for instance, "http:foo", which can be either an absolute or relative URL,
* depending on the context), this function returns false.
*/
static bool IsAbsoluteURL(const nsACString& aURL);
/**
* GetDocumentFromCaller gets its document by looking at the last called
* function and finding the document that the function itself relates to.
@ -2764,6 +2798,8 @@ public:
static bool PushEnabled(JSContext* aCx, JSObject* aObj);
static bool CSPEnabled(JSContext* aCx, JSObject* aObj);
static bool StreamsEnabled(JSContext* aCx, JSObject* aObj);
static bool IsNonSubresourceRequest(nsIChannel* aChannel);

View file

@ -57,6 +57,7 @@
#include "nsView.h"
#include "GroupedSHistory.h"
#include "PartialSHistory.h"
#include "nsQueryObject.h"
#include "nsIURI.h"
#include "nsIURL.h"
@ -86,6 +87,7 @@
#include "mozilla/dom/Element.h"
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
#include "mozilla/layout/RenderFrameParent.h"
#include "nsGenericHTMLFrameElement.h"
#include "GeckoProfiler.h"
#include "jsapi.h"
@ -231,6 +233,7 @@ nsFrameLoader::LoadFrame()
NS_ENSURE_TRUE(mOwnerContent, NS_ERROR_NOT_INITIALIZED);
nsAutoString src;
nsCOMPtr<nsIPrincipal> principal;
bool isSrcdoc = mOwnerContent->IsHTMLElement(nsGkAtoms::iframe) &&
mOwnerContent->HasAttr(kNameSpaceID_None, nsGkAtoms::srcdoc);
@ -238,7 +241,7 @@ nsFrameLoader::LoadFrame()
src.AssignLiteral("about:srcdoc");
}
else {
GetURL(src);
GetURL(src, getter_AddRefs(principal));
src.Trim(" \t\n\r");
@ -279,7 +282,7 @@ nsFrameLoader::LoadFrame()
}
if (NS_SUCCEEDED(rv)) {
rv = LoadURI(uri);
rv = LoadURI(uri, principal);
}
if (NS_FAILED(rv)) {
@ -305,7 +308,7 @@ nsFrameLoader::FireErrorEvent()
}
NS_IMETHODIMP
nsFrameLoader::LoadURI(nsIURI* aURI)
nsFrameLoader::LoadURI(nsIURI* aURI, nsIPrincipal* aTriggeringPrincipal)
{
if (!aURI)
return NS_ERROR_INVALID_POINTER;
@ -313,13 +316,15 @@ nsFrameLoader::LoadURI(nsIURI* aURI)
nsCOMPtr<nsIDocument> doc = mOwnerContent->OwnerDoc();
nsresult rv = CheckURILoad(aURI);
nsresult rv = CheckURILoad(aURI, aTriggeringPrincipal);
NS_ENSURE_SUCCESS(rv, rv);
mURIToLoad = aURI;
mTriggeringPrincipal = aTriggeringPrincipal ? aTriggeringPrincipal : nullptr;
rv = doc->InitializeFrameLoader(this);
if (NS_FAILED(rv)) {
mURIToLoad = nullptr;
mTriggeringPrincipal = nullptr;
}
return rv;
}
@ -513,7 +518,7 @@ nsFrameLoader::ReallyStartLoadingInternal()
"MaybeCreateDocShell succeeded with a null mDocShell");
// Just to be safe, recheck uri.
rv = CheckURILoad(mURIToLoad);
rv = CheckURILoad(mURIToLoad, mTriggeringPrincipal);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
@ -527,7 +532,11 @@ nsFrameLoader::ReallyStartLoadingInternal()
// We'll use our principal, not that of the document loaded inside us. This
// is very important; needed to prevent XSS attacks on documents loaded in
// subframes!
loadInfo->SetTriggeringPrincipal(mOwnerContent->NodePrincipal());
if (mTriggeringPrincipal) {
loadInfo->SetTriggeringPrincipal(mTriggeringPrincipal);
} else {
loadInfo->SetTriggeringPrincipal(mOwnerContent->NodePrincipal());
}
nsCOMPtr<nsIURI> referrer;
@ -601,7 +610,7 @@ nsFrameLoader::ReallyStartLoadingInternal()
}
nsresult
nsFrameLoader::CheckURILoad(nsIURI* aURI)
nsFrameLoader::CheckURILoad(nsIURI* aURI, nsIPrincipal* aTriggeringPrincipal)
{
// Check for security. The fun part is trying to figure out what principals
// to use. The way I figure it, if we're doing a LoadFrame() accidentally
@ -620,7 +629,9 @@ nsFrameLoader::CheckURILoad(nsIURI* aURI)
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
// Get our principal
nsIPrincipal* principal = mOwnerContent->NodePrincipal();
nsIPrincipal* principal = (aTriggeringPrincipal ?
aTriggeringPrincipal :
mOwnerContent->NodePrincipal());
// Check if we are allowed to load absURL
nsresult rv =
@ -2191,7 +2202,7 @@ nsFrameLoader::MaybeCreateDocShell()
}
void
nsFrameLoader::GetURL(nsString& aURI)
nsFrameLoader::GetURL(nsString& aURI, nsIPrincipal** aTriggeringPrincipal)
{
aURI.Truncate();
@ -2199,6 +2210,10 @@ nsFrameLoader::GetURL(nsString& aURI)
mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::data, aURI);
} else {
mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::src, aURI);
if (RefPtr<nsGenericHTMLFrameElement> frame = do_QueryObject(mOwnerContent)) {
nsCOMPtr<nsIPrincipal> prin = frame->GetSrcTriggeringPrincipal();
prin.forget(aTriggeringPrincipal);
}
}
}

View file

@ -215,7 +215,7 @@ public:
*/
void ApplySandboxFlags(uint32_t sandboxFlags);
void GetURL(nsString& aURL);
void GetURL(nsString& aURL, nsIPrincipal** aTriggeringPrincipal);
// Properly retrieves documentSize of any subdocument type.
nsresult GetWindowDimensions(nsIntRect& aRect);
@ -264,7 +264,17 @@ private:
// Updates the subdocument position and size. This gets called only
// when we have our own in-process DocShell.
void UpdateBaseWindowPositionAndSize(nsSubDocumentFrame *aIFrame);
nsresult CheckURILoad(nsIURI* aURI);
/**
* Checks whether a load of the given URI should be allowed, and returns an
* error result if it should not.
*
* @param aURI The URI to check.
* @param aTriggeringPrincipal The triggering principal for the load. May be
* null, in which case the node principal of the owner content is used.
*/
nsresult CheckURILoad(nsIURI* aURI, nsIPrincipal* aTriggeringPrincipal);
void FireErrorEvent();
nsresult ReallyStartLoadingInternal();
@ -302,6 +312,7 @@ private:
nsCOMPtr<nsIDocShell> mDocShell;
nsCOMPtr<nsIURI> mURIToLoad;
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
mozilla::dom::Element* mOwnerContent; // WEAK
// After the frameloader has been removed from the DOM but before all of the

View file

@ -625,6 +625,7 @@ nsGenericDOMDataNode::GetChildren(uint32_t aFilter)
nsresult
nsGenericDOMDataNode::SetAttr(int32_t aNameSpaceID, nsIAtom* aAttr,
nsIAtom* aPrefix, const nsAString& aValue,
nsIPrincipal* aContentPrincipal,
bool aNotify)
{
return NS_OK;

View file

@ -117,13 +117,10 @@ public:
virtual already_AddRefed<nsINodeList> GetChildren(uint32_t aFilter) override;
nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAString& aValue, bool aNotify)
{
return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
}
using nsIContent::SetAttr;
virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
nsIAtom* aPrefix, const nsAString& aValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
bool aNotify) override;

View file

@ -363,6 +363,16 @@ public:
{
return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
}
nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsIAtom* aPrefix,
const nsAString& aValue, bool aNotify)
{
return SetAttr(aNameSpaceID, aName, aPrefix, aValue, nullptr, aNotify);
}
nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAString& aValue,
nsIPrincipal* aTriggeringPrincipal, bool aNotify)
{
return SetAttr(aNameSpaceID, aName, nullptr, aValue, aTriggeringPrincipal, aNotify);
}
/**
* Set attribute values. All attribute values are assumed to have a
@ -375,11 +385,18 @@ public:
* @param aName the name of the attribute
* @param aPrefix the prefix of the attribute
* @param aValue the value to set
* @param aMaybeScriptedPrincipal the principal of the scripted caller responsible
* for setting the attribute, or null if no scripted caller can be
* determined. A null value here does not guarantee that there is no
* scripted caller, but a non-null value does guarantee that a scripted
* caller with the given principal is directly responsible for the
* attribute change.
* @param aNotify specifies how whether or not the document should be
* notified of the attribute change.
*/
virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) = 0;
/**

View file

@ -34,8 +34,11 @@ interface nsIContentPolicy : nsIContentPolicyBase
* not be null
*
* @param aRequestOrigin OPTIONAL. the location of the resource that
* initiated this load request; can be null if
* inapplicable
* that is loading the request. This will generally
* be the URI of the loading principal for the
* resulting request (as determined by its
* LoadInfo), but may vary depending on the
* caller. Can be null if inapplicable.
*
* @param aContext OPTIONAL. the nsIDOMNode or nsIDOMWindow that
* initiated the request, or something that can QI
@ -55,8 +58,12 @@ interface nsIContentPolicy : nsIContentPolicyBase
* @param aRequestPrincipal an OPTIONAL argument, defines the principal that
* caused the load. This is optional only for
* non-gecko code: all gecko code should set this
* argument. For navigation events, this is
* the principal of the page that caused this load.
* argument. This should generally be the same as
* the triggering principal for the resulting
* request (as determined by its LoadInfo), but may
* vary depending on the caller. Sometimes it will
* be the loading principal or final channel
* principal instead.
*
* @return ACCEPT or REJECT_*
*

View file

@ -8,6 +8,7 @@
interface nsFrameLoader;
interface nsIDocShell;
interface nsIURI;
interface nsIPrincipal;
interface nsIFrame;
interface nsSubDocumentFrame;
interface nsIMessageSender;
@ -51,7 +52,7 @@ interface nsIFrameLoader : nsISupports
* Loads the specified URI in this frame. Behaves identically to loadFrame,
* except that this method allows specifying the URI to load.
*/
void loadURI(in nsIURI aURI);
void loadURI(in nsIURI aURI, [optional] in nsIPrincipal aTriggeringPrincipal);
/**
* Puts the frameloader in prerendering mode.

View file

@ -734,7 +734,8 @@ nsresult
nsImageLoadingContent::LoadImage(const nsAString& aNewURI,
bool aForce,
bool aNotify,
ImageLoadType aImageLoadType)
ImageLoadType aImageLoadType,
nsIPrincipal* aTriggeringPrincipal)
{
// First, get a document (needed for security checks and the like)
nsIDocument* doc = GetOurOwnerDoc();
@ -768,7 +769,8 @@ nsImageLoadingContent::LoadImage(const nsAString& aNewURI,
NS_TryToSetImmutable(imageURI);
return LoadImage(imageURI, aForce, aNotify, aImageLoadType, false, doc);
return LoadImage(imageURI, aForce, aNotify, aImageLoadType, false, doc,
nsIRequest::LOAD_NORMAL, aTriggeringPrincipal);
}
nsresult
@ -778,7 +780,8 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI,
ImageLoadType aImageLoadType,
bool aLoadStart,
nsIDocument* aDocument,
nsLoadFlags aLoadFlags)
nsLoadFlags aLoadFlags,
nsIPrincipal* aTriggeringPrincipal)
{
MOZ_ASSERT(!mIsStartingImageLoad, "some evil code is reentering LoadImage.");
if (mIsStartingImageLoad) {
@ -886,7 +889,7 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI,
nsresult rv = nsContentUtils::LoadImage(aNewURI,
thisNode,
aDocument,
aDocument->NodePrincipal(),
aTriggeringPrincipal ? aTriggeringPrincipal : aDocument->NodePrincipal(),
aDocument->GetDocumentURI(),
referrerPolicy,
this, loadFlags,

View file

@ -102,9 +102,12 @@ protected:
* @param aNotify If true, nsIDocumentObserver state change notifications
* will be sent as needed.
* @param aImageLoadType The ImageLoadType for this request
* @param aTriggeringPrincipal Optional parameter specifying the triggering
* principal to use for the image load
*/
nsresult LoadImage(const nsAString& aNewURI, bool aForce,
bool aNotify, ImageLoadType aImageLoadType);
bool aNotify, ImageLoadType aImageLoadType,
nsIPrincipal* aTriggeringPrincipal = nullptr);
/**
* ImageState is called by subclasses that are computing their content state.
@ -134,11 +137,23 @@ protected:
* This is purely a performance optimization.
* @param aLoadFlags Optional parameter specifying load flags to use for
* the image load
* @param aTriggeringPrincipal Optional parameter specifying the triggering
* principal to use for the image load
*/
nsresult LoadImage(nsIURI* aNewURI, bool aForce, bool aNotify,
ImageLoadType aImageLoadType, bool aLoadStart = true,
nsIDocument* aDocument = nullptr,
nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL);
nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL,
nsIPrincipal* aTriggeringPrincipal = nullptr);
// Simplified version to pass triggering principal with defaults otherwise.
nsresult LoadImage(nsIURI* aNewURI, bool aForce, bool aNotify,
ImageLoadType aImageLoadType,
nsIPrincipal* aTriggeringPrincipal)
{
return LoadImage(aNewURI, aForce, aNotify, aImageLoadType,
true, nullptr, nsIRequest::LOAD_NORMAL,
aTriggeringPrincipal);
}
/**
* helpers to get the document for this content (from the nodeinfo

View file

@ -1633,7 +1633,8 @@ nsObjectLoadingContent::CheckLoadPolicy(int16_t *aContentPolicy)
*aContentPolicy = nsIContentPolicy::ACCEPT;
nsresult rv = NS_CheckContentLoadPolicy(contentPolicyType,
mURI,
doc->NodePrincipal(),
doc->NodePrincipal(), // loading principal
doc->NodePrincipal(), // triggering principal
thisContent,
mContentType,
nullptr, //extra
@ -1684,7 +1685,8 @@ nsObjectLoadingContent::CheckProcessPolicy(int16_t *aContentPolicy)
nsresult rv =
NS_CheckContentProcessPolicy(objectType,
mURI ? mURI : mBaseURI,
doc->NodePrincipal(),
doc->NodePrincipal(), // loading principal
doc->NodePrincipal(), // triggering principal
static_cast<nsIImageLoadingContent*>(this),
mContentType,
nullptr, //extra

View file

@ -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 ?

View file

@ -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;

View file

@ -110,7 +110,8 @@ nsStyledElement::SetInlineStyleDeclaration(css::Declaration* aDeclaration,
nsIDocument* document = GetComposedDoc();
mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);
return SetAttrAndNotify(kNameSpaceID_None, nsGkAtoms::style, nullptr,
oldValueSet ? &oldValue : nullptr, attrValue, modType,
oldValueSet ? &oldValue : nullptr, attrValue,
nullptr, modType,
hasListeners, aNotify, kDontCallAfterSetAttr,
document, updateBatch);
}