Issue #2736 - Part 5: Re-work img <srcset> attribute.

Use subject principal as triggering principal in <img> "srcset" attribute.
This commit is contained in:
Moonchild 2025-04-28 19:15:02 +02:00 committed by roytam1
commit 2bdb9f3d85
5 changed files with 69 additions and 16 deletions

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;