From 359a4a2069cb4547109d8acf51d7839e0709f3d4 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Fri, 7 Jun 2024 16:25:36 +0200 Subject: [PATCH 1/3] Issue #2524 - Implement smart granularity for canvas poisoning. User-configurable time interval between 1s and 8h. Default 5 minutes. Resolves #2524 --- dom/canvas/CanvasRenderingContext2D.cpp | 15 +++++++++++---- modules/libpref/init/all.js | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index a7d937fd3c..60078a8fcb 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -2094,7 +2094,10 @@ CanvasRenderingContext2D::GetInputStream(const char* aMimeType, bool PoisonData = Preferences::GetBool("canvas.poisondata",false); if (PoisonData) { - srand(time(NULL)); + int PoisonInterval = Preferences::GetInt("canvas.poisondata.interval", 300); + PoisonInterval = (PoisonInterval < 1) ? 1 : (PoisonInterval > 28800) ? 28800 : PoisonInterval; + unsigned int epoch = time(nullptr); + srand(epoch / PoisonInterval); // Image buffer is always a packed BGRA array (BGRX -> BGR[FF]) // so always 4-byte pixels. // GetImageBuffer => SurfaceToPackedBGRA [=> ConvertBGRXToBGRA] @@ -5775,9 +5778,13 @@ CanvasRenderingContext2D::GetImageDataArray(JSContext* aCx, MOZ_ASSERT(aWidth && aHeight); - bool PoisonData = Preferences::GetBool("canvas.poisondata",false); - if (PoisonData) - srand(time(NULL)); + bool PoisonData = Preferences::GetBool("canvas.poisondata", false); + if (PoisonData) { + int PoisonInterval = Preferences::GetInt("canvas.poisondata.interval", 300); + PoisonInterval = (PoisonInterval < 1) ? 1 : (PoisonInterval > 28800) ? 28800 : PoisonInterval; + unsigned int epoch = time(nullptr); + srand(epoch / PoisonInterval); + } CheckedInt len = CheckedInt(aWidth) * aHeight * 4; if (!len.isValid()) { diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 682000aaf2..56c82aa1d9 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4305,6 +4305,9 @@ pref("canvas.image.cache.limit", 0); // Allow track-fobics to deliberately poison canvas data for // toDataURL() and getImageData() pref("canvas.poisondata", false); +// Rotate randomness of data poisoning every n seconds. Default 5 minutes. +// Valid range [1..28800] (1s-8h). +pref("canvas.poisondata.interval", 300); // WebGL prefs pref("gl.msaa-level", 2); From 5c06335c5b51d49fb4ff0a8e57e605005cf52eb7 Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Fri, 29 Mar 2024 21:25:31 +0800 Subject: [PATCH 2/3] Issue #2522 - Part 1: Alias small, large, and dynamic viewport units to base viewport --- layout/style/nsCSSParser.cpp | 30 +++++++++++++++++++++++++++--- layout/style/nsCSSValue.cpp | 25 +++++++++++++++++++++++++ layout/style/nsCSSValue.h | 13 +++++++++++++ layout/style/nsRuleNode.cpp | 20 ++++++++++++++++---- 4 files changed, 81 insertions(+), 7 deletions(-) diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 2cb6e3ec13..1f4c04ec9f 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -7758,6 +7758,18 @@ const UnitInfo UnitData[] = { { STR_WITH_LEN("vh"), eCSSUnit_ViewportHeight, VARIANT_LENGTH }, { STR_WITH_LEN("vmin"), eCSSUnit_ViewportMin, VARIANT_LENGTH }, { STR_WITH_LEN("vmax"), eCSSUnit_ViewportMax, VARIANT_LENGTH }, + { STR_WITH_LEN("svw"), eCSSUnit_SmallViewportWidth, VARIANT_LENGTH }, + { STR_WITH_LEN("svh"), eCSSUnit_SmallViewportHeight, VARIANT_LENGTH }, + { STR_WITH_LEN("svmin"), eCSSUnit_SmallViewportMin, VARIANT_LENGTH }, + { STR_WITH_LEN("svmax"), eCSSUnit_SmallViewportMax, VARIANT_LENGTH }, + { STR_WITH_LEN("lvw"), eCSSUnit_LargeViewportWidth, VARIANT_LENGTH }, + { STR_WITH_LEN("lvh"), eCSSUnit_LargeViewportHeight, VARIANT_LENGTH }, + { STR_WITH_LEN("lvmin"), eCSSUnit_LargeViewportMin, VARIANT_LENGTH }, + { STR_WITH_LEN("lvmax"), eCSSUnit_LargeViewportMax, VARIANT_LENGTH }, + { STR_WITH_LEN("dvw"), eCSSUnit_DynamicViewportWidth, VARIANT_LENGTH }, + { STR_WITH_LEN("dvh"), eCSSUnit_DynamicViewportHeight, VARIANT_LENGTH }, + { STR_WITH_LEN("dvmin"), eCSSUnit_DynamicViewportMin, VARIANT_LENGTH }, + { STR_WITH_LEN("dvmax"), eCSSUnit_DynamicViewportMax, VARIANT_LENGTH }, { STR_WITH_LEN("pc"), eCSSUnit_Pica, VARIANT_LENGTH }, { STR_WITH_LEN("q"), eCSSUnit_Quarter, VARIANT_LENGTH }, { STR_WITH_LEN("deg"), eCSSUnit_Degree, VARIANT_ANGLE }, @@ -7797,10 +7809,22 @@ CSSParserImpl::TranslateDimension(nsCSSValue& aValue, } if (!mViewportUnitsEnabled && - (eCSSUnit_ViewportWidth == units || + (eCSSUnit_ViewportWidth == units || eCSSUnit_ViewportHeight == units || - eCSSUnit_ViewportMin == units || - eCSSUnit_ViewportMax == units)) { + eCSSUnit_ViewportMin == units || + eCSSUnit_ViewportMax == units || + eCSSUnit_SmallViewportWidth == units || + eCSSUnit_SmallViewportHeight == units || + eCSSUnit_SmallViewportMin == units || + eCSSUnit_SmallViewportMax == units || + eCSSUnit_LargeViewportWidth == units || + eCSSUnit_LargeViewportHeight == units || + eCSSUnit_LargeViewportMin == units || + eCSSUnit_LargeViewportMax == units || + eCSSUnit_DynamicViewportWidth == units || + eCSSUnit_DynamicViewportHeight == units || + eCSSUnit_DynamicViewportMin == units || + eCSSUnit_DynamicViewportMax == units)) { // Viewport units aren't allowed right now, probably because we're // inside an @page declaration. Fail. return false; diff --git a/layout/style/nsCSSValue.cpp b/layout/style/nsCSSValue.cpp index 40d804b028..79c2b39d1e 100644 --- a/layout/style/nsCSSValue.cpp +++ b/layout/style/nsCSSValue.cpp @@ -2002,6 +2002,19 @@ nsCSSValue::AppendToString(nsCSSPropertyID aProperty, nsAString& aResult, case eCSSUnit_ViewportMin: aResult.AppendLiteral("vmin"); break; case eCSSUnit_ViewportMax: aResult.AppendLiteral("vmax"); break; + case eCSSUnit_SmallViewportWidth: aResult.AppendLiteral("svw"); break; + case eCSSUnit_SmallViewportHeight: aResult.AppendLiteral("svh"); break; + case eCSSUnit_SmallViewportMin: aResult.AppendLiteral("svmin"); break; + case eCSSUnit_SmallViewportMax: aResult.AppendLiteral("svmax"); break; + case eCSSUnit_LargeViewportWidth: aResult.AppendLiteral("lvw"); break; + case eCSSUnit_LargeViewportHeight: aResult.AppendLiteral("lvh"); break; + case eCSSUnit_LargeViewportMin: aResult.AppendLiteral("lvmin"); break; + case eCSSUnit_LargeViewportMax: aResult.AppendLiteral("lvmax"); break; + case eCSSUnit_DynamicViewportWidth: aResult.AppendLiteral("dvw"); break; + case eCSSUnit_DynamicViewportHeight: aResult.AppendLiteral("dvh"); break; + case eCSSUnit_DynamicViewportMin: aResult.AppendLiteral("dvmin"); break; + case eCSSUnit_DynamicViewportMax: aResult.AppendLiteral("dvmax"); break; + case eCSSUnit_EM: aResult.AppendLiteral("em"); break; case eCSSUnit_XHeight: aResult.AppendLiteral("ex"); break; case eCSSUnit_Char: aResult.AppendLiteral("ch"); break; @@ -2175,6 +2188,18 @@ nsCSSValue::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const case eCSSUnit_ViewportHeight: case eCSSUnit_ViewportMin: case eCSSUnit_ViewportMax: + case eCSSUnit_SmallViewportWidth: + case eCSSUnit_SmallViewportHeight: + case eCSSUnit_SmallViewportMin: + case eCSSUnit_SmallViewportMax: + case eCSSUnit_LargeViewportWidth: + case eCSSUnit_LargeViewportHeight: + case eCSSUnit_LargeViewportMin: + case eCSSUnit_LargeViewportMax: + case eCSSUnit_DynamicViewportWidth: + case eCSSUnit_DynamicViewportHeight: + case eCSSUnit_DynamicViewportMin: + case eCSSUnit_DynamicViewportMax: case eCSSUnit_EM: case eCSSUnit_XHeight: case eCSSUnit_Char: diff --git a/layout/style/nsCSSValue.h b/layout/style/nsCSSValue.h index 1721cc8ee6..c0b3b0cac7 100644 --- a/layout/style/nsCSSValue.h +++ b/layout/style/nsCSSValue.h @@ -534,6 +534,19 @@ enum nsCSSUnit { eCSSUnit_ViewportMin = 702, // (float) smaller of ViewportWidth and ViewportHeight eCSSUnit_ViewportMax = 703, // (float) larger of ViewportWidth and ViewportHeight + eCSSUnit_SmallViewportWidth = 704, // (float) 1% of the width of the small viewport + eCSSUnit_SmallViewportHeight = 705, // (float) 1% of the height of the small viewport + eCSSUnit_SmallViewportMin = 706, // (float) smaller of SmallViewportWidth and SmallViewportHeight + eCSSUnit_SmallViewportMax = 707, // (float) larger of SmallViewportWidth and SmallViewportHeight + eCSSUnit_LargeViewportWidth = 708, // (float) 1% of the width of the large viewport + eCSSUnit_LargeViewportHeight = 709, // (float) 1% of the height of the large viewport + eCSSUnit_LargeViewportMin = 710, // (float) smaller of LargeViewportWidth and LargeViewportHeight + eCSSUnit_LargeViewportMax = 711, // (float) larger of LargeViewportWidth and LargeViewportHeight + eCSSUnit_DynamicViewportWidth = 712, // (float) 1% of the width of the dynamic viewport + eCSSUnit_DynamicViewportHeight = 713, // (float) 1% of the height of the dynamic viewport + eCSSUnit_DynamicViewportMin = 714, // (float) smaller of DynamicViewportWidth and DynamicViewportHeight + eCSSUnit_DynamicViewportMax = 715, // (float) larger of DynamicViewportWidth and DynamicViewportHeight + // Font relative measure eCSSUnit_EM = 800, // (float) == current font size eCSSUnit_XHeight = 801, // (float) distance from top of lower case x to baseline diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 1bba07ce6b..fdd0c687f4 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -511,20 +511,32 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue, // and allows us not to need an additional code path, in exchange // for an increased cost to dynamic changes to the viewport size // when viewport units are in use. - case eCSSUnit_ViewportWidth: { + case eCSSUnit_ViewportWidth: + case eCSSUnit_SmallViewportWidth: + case eCSSUnit_LargeViewportWidth: + case eCSSUnit_DynamicViewportWidth: { nscoord viewportWidth = CalcViewportUnitsScale(aPresContext).width; return ScaleViewportCoordTrunc(aValue, viewportWidth); } - case eCSSUnit_ViewportHeight: { + case eCSSUnit_ViewportHeight: + case eCSSUnit_SmallViewportHeight: + case eCSSUnit_LargeViewportHeight: + case eCSSUnit_DynamicViewportHeight: { nscoord viewportHeight = CalcViewportUnitsScale(aPresContext).height; return ScaleViewportCoordTrunc(aValue, viewportHeight); } - case eCSSUnit_ViewportMin: { + case eCSSUnit_ViewportMin: + case eCSSUnit_SmallViewportMin: + case eCSSUnit_LargeViewportMin: + case eCSSUnit_DynamicViewportMin: { nsSize vuScale(CalcViewportUnitsScale(aPresContext)); nscoord viewportMin = min(vuScale.width, vuScale.height); return ScaleViewportCoordTrunc(aValue, viewportMin); } - case eCSSUnit_ViewportMax: { + case eCSSUnit_ViewportMax: + case eCSSUnit_SmallViewportMax: + case eCSSUnit_LargeViewportMax: + case eCSSUnit_DynamicViewportMax: { nsSize vuScale(CalcViewportUnitsScale(aPresContext)); nscoord viewportMax = max(vuScale.width, vuScale.height); return ScaleViewportCoordTrunc(aValue, viewportMax); From 2ba31f4e9789836031cd89181750ef4804142fdf Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Sun, 9 Jun 2024 19:12:43 +0800 Subject: [PATCH 3/3] Issue #2522 - Part 2: Implement support for logical viewport units --- layout/style/nsCSSParser.cpp | 18 +++++++++++++++++- layout/style/nsCSSValue.cpp | 17 +++++++++++++++++ layout/style/nsCSSValue.h | 10 ++++++++++ layout/style/nsRuleNode.cpp | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 1f4c04ec9f..de425eacb7 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -7770,6 +7770,14 @@ const UnitInfo UnitData[] = { { STR_WITH_LEN("dvh"), eCSSUnit_DynamicViewportHeight, VARIANT_LENGTH }, { STR_WITH_LEN("dvmin"), eCSSUnit_DynamicViewportMin, VARIANT_LENGTH }, { STR_WITH_LEN("dvmax"), eCSSUnit_DynamicViewportMax, VARIANT_LENGTH }, + { STR_WITH_LEN("vb"), eCSSUnit_ViewportBlock, VARIANT_LENGTH }, + { STR_WITH_LEN("vi"), eCSSUnit_ViewportInline, VARIANT_LENGTH }, + { STR_WITH_LEN("svb"), eCSSUnit_SmallViewportBlock, VARIANT_LENGTH }, + { STR_WITH_LEN("svi"), eCSSUnit_SmallViewportInline, VARIANT_LENGTH }, + { STR_WITH_LEN("lvb"), eCSSUnit_LargeViewportBlock, VARIANT_LENGTH }, + { STR_WITH_LEN("lvi"), eCSSUnit_LargeViewportInline, VARIANT_LENGTH }, + { STR_WITH_LEN("dvb"), eCSSUnit_DynamicViewportBlock, VARIANT_LENGTH }, + { STR_WITH_LEN("dvi"), eCSSUnit_DynamicViewportInline, VARIANT_LENGTH }, { STR_WITH_LEN("pc"), eCSSUnit_Pica, VARIANT_LENGTH }, { STR_WITH_LEN("q"), eCSSUnit_Quarter, VARIANT_LENGTH }, { STR_WITH_LEN("deg"), eCSSUnit_Degree, VARIANT_ANGLE }, @@ -7824,7 +7832,15 @@ CSSParserImpl::TranslateDimension(nsCSSValue& aValue, eCSSUnit_DynamicViewportWidth == units || eCSSUnit_DynamicViewportHeight == units || eCSSUnit_DynamicViewportMin == units || - eCSSUnit_DynamicViewportMax == units)) { + eCSSUnit_DynamicViewportMax == units || + eCSSUnit_ViewportBlock == units || + eCSSUnit_ViewportInline == units || + eCSSUnit_SmallViewportInline == units || + eCSSUnit_SmallViewportBlock == units || + eCSSUnit_LargeViewportBlock == units || + eCSSUnit_LargeViewportInline == units || + eCSSUnit_DynamicViewportBlock == units || + eCSSUnit_DynamicViewportInline == units )) { // Viewport units aren't allowed right now, probably because we're // inside an @page declaration. Fail. return false; diff --git a/layout/style/nsCSSValue.cpp b/layout/style/nsCSSValue.cpp index 79c2b39d1e..db2374c68f 100644 --- a/layout/style/nsCSSValue.cpp +++ b/layout/style/nsCSSValue.cpp @@ -2015,6 +2015,15 @@ nsCSSValue::AppendToString(nsCSSPropertyID aProperty, nsAString& aResult, case eCSSUnit_DynamicViewportMin: aResult.AppendLiteral("dvmin"); break; case eCSSUnit_DynamicViewportMax: aResult.AppendLiteral("dvmax"); break; + case eCSSUnit_ViewportBlock: aResult.AppendLiteral("vb"); break; + case eCSSUnit_ViewportInline: aResult.AppendLiteral("vi"); break; + case eCSSUnit_SmallViewportBlock: aResult.AppendLiteral("svb"); break; + case eCSSUnit_SmallViewportInline: aResult.AppendLiteral("svi"); break; + case eCSSUnit_LargeViewportBlock: aResult.AppendLiteral("lvb"); break; + case eCSSUnit_LargeViewportInline: aResult.AppendLiteral("lvi"); break; + case eCSSUnit_DynamicViewportBlock: aResult.AppendLiteral("dvb"); break; + case eCSSUnit_DynamicViewportInline: aResult.AppendLiteral("dvi"); break; + case eCSSUnit_EM: aResult.AppendLiteral("em"); break; case eCSSUnit_XHeight: aResult.AppendLiteral("ex"); break; case eCSSUnit_Char: aResult.AppendLiteral("ch"); break; @@ -2200,6 +2209,14 @@ nsCSSValue::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const case eCSSUnit_DynamicViewportHeight: case eCSSUnit_DynamicViewportMin: case eCSSUnit_DynamicViewportMax: + case eCSSUnit_ViewportBlock: + case eCSSUnit_ViewportInline: + case eCSSUnit_SmallViewportBlock: + case eCSSUnit_SmallViewportInline: + case eCSSUnit_LargeViewportBlock: + case eCSSUnit_LargeViewportInline: + case eCSSUnit_DynamicViewportBlock: + case eCSSUnit_DynamicViewportInline: case eCSSUnit_EM: case eCSSUnit_XHeight: case eCSSUnit_Char: diff --git a/layout/style/nsCSSValue.h b/layout/style/nsCSSValue.h index c0b3b0cac7..7d0556046b 100644 --- a/layout/style/nsCSSValue.h +++ b/layout/style/nsCSSValue.h @@ -547,6 +547,16 @@ enum nsCSSUnit { eCSSUnit_DynamicViewportMin = 714, // (float) smaller of DynamicViewportWidth and DynamicViewportHeight eCSSUnit_DynamicViewportMax = 715, // (float) larger of DynamicViewportWidth and DynamicViewportHeight + // Logical viewport units + eCSSUnit_ViewportBlock = 716, // (float) 1% of the size of the initial containing block in the box's block axis + eCSSUnit_ViewportInline = 717, // (float) 1% of the size of the initial containing block in the box's inline axis + eCSSUnit_SmallViewportBlock = 718, // (float) 1% of the size of the small viewport in the box's block axis + eCSSUnit_SmallViewportInline = 719, // (float) 1% of the size of the small viewport in the box's inline axis + eCSSUnit_LargeViewportBlock = 720, // (float) 1% of the size of the large viewport in the box's block axis + eCSSUnit_LargeViewportInline = 721, // (float) 1% of the size of the small viewport in the box's inline axis + eCSSUnit_DynamicViewportBlock = 722, // (float) 1% of the size of the dynamic viewport in the box's block axis + eCSSUnit_DynamicViewportInline = 723, // (float) 1% of the size of the small viewport in the box's inline axis + // Font relative measure eCSSUnit_EM = 800, // (float) == current font size eCSSUnit_XHeight = 801, // (float) distance from top of lower case x to baseline diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index fdd0c687f4..349669959c 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -541,6 +541,40 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue, nscoord viewportMax = max(vuScale.width, vuScale.height); return ScaleViewportCoordTrunc(aValue, viewportMax); } + case eCSSUnit_ViewportBlock: + case eCSSUnit_SmallViewportBlock: + case eCSSUnit_LargeViewportBlock: + case eCSSUnit_DynamicViewportBlock: { + // Assume non-vertical writing mode if the style context is unavailable. + if (aStyleContext) { + WritingMode wm(aStyleContext); + bool vertical = wm.IsVertical(); + aConditions.SetWritingModeDependency(wm.GetBits()); + if (vertical) { + nscoord viewportWidth = CalcViewportUnitsScale(aPresContext).width; + return ScaleViewportCoordTrunc(aValue, viewportWidth); + } + } + nscoord viewportHeight = CalcViewportUnitsScale(aPresContext).height; + return ScaleViewportCoordTrunc(aValue, viewportHeight); + } + case eCSSUnit_ViewportInline: + case eCSSUnit_SmallViewportInline: + case eCSSUnit_LargeViewportInline: + case eCSSUnit_DynamicViewportInline: { + // Assume non-vertical writing mode if the style context is unavailable. + if (aStyleContext) { + WritingMode wm(aStyleContext); + bool vertical = wm.IsVertical(); + aConditions.SetWritingModeDependency(wm.GetBits()); + if (vertical) { + nscoord viewportHeight = CalcViewportUnitsScale(aPresContext).height; + return ScaleViewportCoordTrunc(aValue, viewportHeight); + } + } + nscoord viewportWidth = CalcViewportUnitsScale(aPresContext).width; + return ScaleViewportCoordTrunc(aValue, viewportWidth); + } // While we could deal with 'rem' units correctly by simply not // caching any data that uses them in the rule tree, it's valuable // to store them in the rule tree (for faster dynamic changes of