-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[macOS] drawFocusIfNeeded() should not expose the user's system accen…
…t color https://bugs.webkit.org/show_bug.cgi?id=260102 rdar://105554669 Reviewed by Tim Nguyen. On macOS, `drawFocusIfNeeded()` currently exposes the user's system accent color via `RenderTheme::focusRingColor()`. To mitigate fingerprinting risk due to this API for users that have chosen a non-default system accent color, we make `RenderTheme::focusRingColor()` respect the given `UseSystemAppearance` state by returning the default system focus ring color on macOS, in the case where that option is absent. As a result, this means that quirks-mode webpages that use `-webkit-focus-ring-color` will also no longer be able to determine the user's accent color. This aligns with existing behavior for the "activeborder" CSS value. Tests: fast/canvas/do-not-expose-non-default-focus-ring-color.html fast/css/mac/focus-ring-color-should-not-expose-accent-color.html * LayoutTests/TestExpectations: * LayoutTests/fast/canvas/do-not-expose-non-default-focus-ring-color-expected.html: Added. * LayoutTests/fast/canvas/do-not-expose-non-default-focus-ring-color.html: Added. * LayoutTests/fast/canvas/resources/do-not-expose-non-default-focus-ring-color.js: Added. (paintIntoSwatch): Add a test to verify that accent colors can't be read back using canvas 2D; to test this, we render a simple focus ring to a 2D canvas, use `getImageData` to read it back, and verify that the average non-transparent pixel values in the resulting image data match even when the accent color is different (customized using the new `UIScriptController` hook below). * LayoutTests/fast/css/mac/focus-ring-color-should-not-expose-accent-color-expected-mismatch.html: Added. * LayoutTests/fast/css/mac/focus-ring-color-should-not-expose-accent-color.html: Added. Add another test to verify that accent colors (1) are not directly leaked through the use of the `-webkit-focus-ring-color` CSS property, and (2) enabling system appearance is sufficient to expose the real focus ring color again. * LayoutTests/platform/mac-wk2/TestExpectations: * LayoutTests/resources/ui-helper.js: (window.UIHelper.isMac): (window.UIHelper.setAppAccentColor): * Source/WebCore/PAL/pal/spi/ios/UIKitSPI.h: Drive-by fix: remove an unnecessary UIKit SPI method declaraction. * Source/WebCore/rendering/RenderElement.cpp: (WebCore::RenderElement::paintFocusRing const): Set `UseSystemAppearance` here to ensure that focus rings still paint with the correct appearance. * Source/WebCore/rendering/RenderImage.cpp: (WebCore::RenderImage::paintAreaElementFocusRing): Set `UseSystemAppearance` here to ensure that focus rings still paint with the correct appearance. * Source/WebCore/rendering/RenderThemeIOS.mm: (WebCore::RenderThemeIOS::systemFocusRingColor): * Source/WebCore/rendering/RenderThemeMac.mm: (WebCore::defaultFocusRingColor): (WebCore::RenderThemeMac::platformFocusRingColor const): This is the main fix — pull the hard-coded value for the focus ring color out into a separate helper function, which we use in `platformFocusRingColor` if `UseSystemAppearance` is unset. (WebCore::RenderThemeMac::systemColor const): * Source/WebCore/testing/Internals.cpp: (WebCore::Internals::focusRingColor): * Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl: * Tools/TestRunnerShared/UIScriptContext/UIScriptController.h: (WTR::UIScriptController::setAppAccentColor): Add a `UIScriptController` hook to set a custom accent color, using `-_setAccentColor:`. This is reset to the default value (computed upon initializing the test runner and stored in `m_defaultAppAccentColor`) between test runs. * Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * Tools/WebKitTestRunner/InjectedBundle/TestRunner.h: (WTR::TestRunner::isMac const): * Tools/WebKitTestRunner/TestController.h: * Tools/WebKitTestRunner/mac/TestControllerMac.mm: (WTR::TestController::platformInitialize): (WTR::TestController::platformResetStateToConsistentValues): * Tools/WebKitTestRunner/mac/UIScriptControllerMac.h: * Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm: (WTR::UIScriptControllerMac::setAppAccentColor): Canonical link: https://commits.webkit.org/266881@main
- Loading branch information
Showing
22 changed files
with
303 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
LayoutTests/fast/canvas/do-not-expose-non-default-focus-ring-color-expected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!DOCTYPE html> <!-- webkit-test-runner [ runSingly=true ] --> | ||
<html> | ||
<head> | ||
<script src="../../resources/ui-helper.js"></script> | ||
<style> | ||
html { | ||
font-size: 16px; | ||
} | ||
|
||
canvas { | ||
width: 20px; | ||
height: 20px; | ||
opacity: 0; | ||
} | ||
|
||
#swatch { | ||
width: 160px; | ||
height: 100px; | ||
line-height: 100px; | ||
color: white; | ||
text-align: center; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p> | ||
Your system accent color should not be directly exposed: | ||
<div id="swatch"></div> | ||
</p> | ||
<canvas width="40" height="40" style="border: 1px solid lightgray;"> | ||
<button tabindex="0"></button> | ||
</canvas> | ||
<script src="./resources/do-not-expose-non-default-focus-ring-color.js"></script> | ||
<script> | ||
if (window.testRunner) | ||
testRunner.waitUntilDone(); | ||
|
||
(async function() { | ||
if (window.testRunner) | ||
await UIHelper.setAppAccentColor(0, 100, 255); | ||
|
||
paintIntoSwatch(); | ||
|
||
if (window.testRunner) | ||
testRunner.notifyDone(); | ||
})(); | ||
</script> | ||
</body> | ||
</html> |
52 changes: 52 additions & 0 deletions
52
LayoutTests/fast/canvas/do-not-expose-non-default-focus-ring-color.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!DOCTYPE html> <!-- webkit-test-runner [ runSingly=true ] --> | ||
<html> | ||
<head> | ||
<script src="../../resources/ui-helper.js"></script> | ||
<style> | ||
html { | ||
font-size: 16px; | ||
} | ||
|
||
canvas { | ||
width: 20px; | ||
height: 20px; | ||
opacity: 0; | ||
} | ||
|
||
#swatch { | ||
width: 160px; | ||
height: 100px; | ||
line-height: 100px; | ||
color: white; | ||
text-align: center; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p> | ||
<!-- To manually run this test, set a non-default system accent color, open this test page, and | ||
verify that the accent color isn't directly revealed to the page by checking the output in | ||
the color swatch below --> | ||
Your system accent color should not be directly exposed: | ||
<div id="swatch"></div> | ||
</p> | ||
<canvas width="40" height="40" style="border: 1px solid lightgray;"> | ||
<button tabindex="0"></button> | ||
</canvas> | ||
<script src="./resources/do-not-expose-non-default-focus-ring-color.js"></script> | ||
<script> | ||
if (window.testRunner) | ||
testRunner.waitUntilDone(); | ||
|
||
(async function () { | ||
if (window.testRunner) | ||
await UIHelper.setAppAccentColor(255, 100, 50); | ||
|
||
paintIntoSwatch(); | ||
|
||
if (window.testRunner) | ||
testRunner.notifyDone(); | ||
})(); | ||
</script> | ||
</body> | ||
</html> |
48 changes: 48 additions & 0 deletions
48
LayoutTests/fast/canvas/resources/do-not-expose-non-default-focus-ring-color.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
function paintIntoSwatch() { | ||
const canvas = document.querySelector("canvas"); | ||
const context = canvas.getContext("2d"); | ||
context.save(); | ||
context.clearRect(0, 0, 40, 40); | ||
|
||
const button = canvas.querySelector("button"); | ||
context.beginPath(); | ||
context.rect(10, 10, 20, 20); | ||
button.focus(); | ||
context.drawFocusIfNeeded(button); | ||
button.blur(); | ||
|
||
context.restore(); | ||
|
||
let averageRed = 0; | ||
let averageGreen = 0; | ||
let averageBlue = 0; | ||
let pixelCount = 0; | ||
|
||
const imageData = context.getImageData(0, 0, canvas.width, canvas.height).data; | ||
for (let row = 0; row < 40; row++) { | ||
for (let column = 0; column < 40; column++) { | ||
const byteOffset = 4 * (row * 40 + column); | ||
const alphaComponent = imageData.at(byteOffset + 3); | ||
if (!alphaComponent) | ||
continue; | ||
|
||
const redComponent = imageData.at(byteOffset); | ||
const greenComponent = imageData.at(byteOffset + 1); | ||
const blueComponent = imageData.at(byteOffset + 2); | ||
|
||
averageRed += redComponent; | ||
averageGreen += greenComponent; | ||
averageBlue += blueComponent; | ||
pixelCount++; | ||
} | ||
} | ||
|
||
averageRed /= pixelCount; | ||
averageGreen /= pixelCount; | ||
averageBlue /= pixelCount; | ||
|
||
const colorComponents = `${Math.round(averageRed)}, ${Math.round(averageGreen)}, ${Math.round(averageBlue)}`; | ||
const swatch = document.getElementById("swatch"); | ||
swatch.textContent = colorComponents; | ||
swatch.style.backgroundColor = `rgb(${colorComponents})`; | ||
} |
41 changes: 41 additions & 0 deletions
41
...Tests/fast/css/mac/focus-ring-color-should-not-expose-accent-color-expected-mismatch.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<html> <!-- webkit-test-runner [ runSingly=true ] --> | ||
<head> | ||
<script src="../../../resources/ui-helper.js"></script> | ||
<style> | ||
body { | ||
font-family: system-ui; | ||
} | ||
|
||
#focus-ring { | ||
border-radius: 4px; | ||
margin: 4px; | ||
width: 200px; | ||
height: 200px; | ||
font-size: 16px; | ||
text-align: center; | ||
line-height: 200px; | ||
color: white; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="focus-ring"></div> | ||
<script> | ||
function runTest() { | ||
let container = document.getElementById("focus-ring"); | ||
container.style.backgroundColor = "-webkit-focus-ring-color"; | ||
container.textContent = getComputedStyle(container).backgroundColor; | ||
} | ||
|
||
if (window.testRunner) { | ||
testRunner.waitUntilDone(); | ||
(async function() { | ||
await UIHelper.setAppAccentColor(230, 110, 2); | ||
internals.setUseSystemAppearance(true); | ||
runTest(); | ||
testRunner.notifyDone(); | ||
})(); | ||
} else | ||
runTest(); | ||
</script> | ||
</html> |
41 changes: 41 additions & 0 deletions
41
LayoutTests/fast/css/mac/focus-ring-color-should-not-expose-accent-color.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<html> <!-- webkit-test-runner [ runSingly=true ] --> | ||
<head> | ||
<script src="../../../resources/ui-helper.js"></script> | ||
<style> | ||
body { | ||
font-family: system-ui; | ||
} | ||
|
||
#focus-ring { | ||
border-radius: 4px; | ||
margin: 4px; | ||
width: 200px; | ||
height: 200px; | ||
font-size: 16px; | ||
text-align: center; | ||
line-height: 200px; | ||
color: white; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="focus-ring"></div> | ||
<script> | ||
function runTest() { | ||
let container = document.getElementById("focus-ring"); | ||
container.style.backgroundColor = "-webkit-focus-ring-color"; | ||
container.textContent = getComputedStyle(container).backgroundColor; | ||
} | ||
|
||
if (window.testRunner) { | ||
testRunner.waitUntilDone(); | ||
(async function() { | ||
await UIHelper.setAppAccentColor(230, 110, 2); | ||
internals.setUseSystemAppearance(false); | ||
runTest(); | ||
testRunner.notifyDone(); | ||
})(); | ||
} else | ||
runTest(); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.