Hardcode some system colors to avoid fingerprinting exposure.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Aug 2018 19:07:42 +0000 (19:07 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Aug 2018 19:07:42 +0000 (19:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188203
rdar://problem/42781630

Reviewed by Tim Horton.

Source/WebCore:

Passes existing tests with the hardcoded blue system appearance.

* rendering/RenderTheme.h:
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::systemColor const):
Adds special handling for some system colors. Fixes -apple-system-selected-text-background
to match the real selection color by using blendWithWhite().

LayoutTests:

* fast/css/apple-system-control-colors-expected.txt: Updated.
* fast/css/test-setting-canvas-color.html: Fixed for colors with alpha.
* platform/mac-highsierra/fast/css/apple-system-control-colors-expected.txt:
* platform/mac-sierra/fast/css/apple-system-control-colors-expected.txt: Updated.
* platform/mac/TestExpectations: Removed fast/css/test-setting-canvas-color.html.
* platform/mac/fast/css/apple-system-control-colors-expected.txt: Updated.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234466 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/css/apple-system-control-colors-expected.txt
LayoutTests/fast/css/test-setting-canvas-color.html
LayoutTests/platform/mac-highsierra/fast/css/apple-system-control-colors-expected.txt
LayoutTests/platform/mac-sierra/fast/css/apple-system-control-colors-expected.txt
LayoutTests/platform/mac/TestExpectations
LayoutTests/platform/mac/fast/css/apple-system-control-colors-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderTheme.h
Source/WebCore/rendering/RenderThemeMac.mm

index f520ffc..6df5854 100644 (file)
@@ -1,3 +1,18 @@
+2018-08-01  Timothy Hatcher  <timothy@apple.com>
+
+        Hardcode some system colors to avoid fingerprinting exposure.
+        https://bugs.webkit.org/show_bug.cgi?id=188203
+        rdar://problem/42781630
+
+        Reviewed by Tim Horton.
+
+        * fast/css/apple-system-control-colors-expected.txt: Updated.
+        * fast/css/test-setting-canvas-color.html: Fixed for colors with alpha.
+        * platform/mac-highsierra/fast/css/apple-system-control-colors-expected.txt:
+        * platform/mac-sierra/fast/css/apple-system-control-colors-expected.txt: Updated.
+        * platform/mac/TestExpectations: Removed fast/css/test-setting-canvas-color.html.
+        * platform/mac/fast/css/apple-system-control-colors-expected.txt: Updated.
+
 2018-08-01  Alicia Boya GarcĂ­a  <aboya@igalia.com>
 
         [GTK] Unreviewed test gardening
index bfdf270..427a7a8 100644 (file)
@@ -9,7 +9,7 @@
 -apple-system-unemphasized-selected-content-background : rgb(212, 212, 212)
 -apple-system-selected-text : rgb(0, 0, 0)
 -apple-system-unemphasized-selected-text : rgb(0, 0, 0)
--apple-system-selected-text-background : rgb(181, 213, 255)
+-apple-system-selected-text-background : rgba(128, 188, 254, 0.6)
 -apple-system-unemphasized-selected-text-background : rgb(212, 212, 212)
 -apple-system-placeholder-text : rgba(0, 0, 0, 0.247059)
 -apple-system-find-highlight-background : rgb(255, 255, 0)
index bfc684c..6434cc8 100644 (file)
@@ -21,7 +21,7 @@ function shouldSuccessfullyParse(color) {
     ctx.fillStyle = "#f00";
     ctx.fillStyle = color;
     // Check that there is no red.
-    if (ctx.fillStyle.match(/^#(?!(FF0000|ff0000|f00)$)/))
+    if (ctx.fillStyle.match(/^#(?!(FF0000|ff0000|f00)$)/) || ctx.fillStyle !== "rgb(255, 0, 0)")
         testPassed("Setting color to " + color + " was successfully set.");
     else
         testFailed("Setting color to " + color + " was not set but should!");
@@ -31,7 +31,7 @@ function shouldNotSuccessfullyParse(color) {
     ctx.fillStyle = "#0f0";
     ctx.fillStyle = color;
     // Check that the color is still green.
-    if (ctx.fillStyle.match(/^#(00FF00|00ff00|0f0)$/))
+    if (ctx.fillStyle.match(/^#(00FF00|00ff00|0f0)$/) || ctx.fillStyle === "rgb(0, 255, 0)")
         testPassed("Setting color to " + color + " was not set (as expected).");
     else
         testFailed("Setting color to " + color + " was successfully set but should not!");
index bfdf270..8c144e3 100644 (file)
@@ -2,14 +2,14 @@
 -apple-system-text-background : rgb(255, 255, 255)
 -apple-system-control-background : rgb(255, 255, 255)
 -apple-system-alternate-selected-text : rgb(255, 255, 255)
--apple-system-control-accent : rgb(0, 105, 217)
+-apple-system-control-accent : rgb(0, 122, 255)
 -apple-system-even-alternating-content-background : rgb(255, 255, 255)
 -apple-system-odd-alternating-content-background : rgb(245, 245, 245)
--apple-system-selected-content-background : rgb(0, 105, 217)
+-apple-system-selected-content-background : rgb(0, 99, 225)
 -apple-system-unemphasized-selected-content-background : rgb(212, 212, 212)
 -apple-system-selected-text : rgb(0, 0, 0)
 -apple-system-unemphasized-selected-text : rgb(0, 0, 0)
--apple-system-selected-text-background : rgb(181, 213, 255)
+-apple-system-selected-text-background : rgba(128, 188, 254, 0.6)
 -apple-system-unemphasized-selected-text-background : rgb(212, 212, 212)
 -apple-system-placeholder-text : rgba(0, 0, 0, 0.247059)
 -apple-system-find-highlight-background : rgb(255, 255, 0)
index bfdf270..8c144e3 100644 (file)
@@ -2,14 +2,14 @@
 -apple-system-text-background : rgb(255, 255, 255)
 -apple-system-control-background : rgb(255, 255, 255)
 -apple-system-alternate-selected-text : rgb(255, 255, 255)
--apple-system-control-accent : rgb(0, 105, 217)
+-apple-system-control-accent : rgb(0, 122, 255)
 -apple-system-even-alternating-content-background : rgb(255, 255, 255)
 -apple-system-odd-alternating-content-background : rgb(245, 245, 245)
--apple-system-selected-content-background : rgb(0, 105, 217)
+-apple-system-selected-content-background : rgb(0, 99, 225)
 -apple-system-unemphasized-selected-content-background : rgb(212, 212, 212)
 -apple-system-selected-text : rgb(0, 0, 0)
 -apple-system-unemphasized-selected-text : rgb(0, 0, 0)
--apple-system-selected-text-background : rgb(181, 213, 255)
+-apple-system-selected-text-background : rgba(128, 188, 254, 0.6)
 -apple-system-unemphasized-selected-text-background : rgb(212, 212, 212)
 -apple-system-placeholder-text : rgba(0, 0, 0, 0.247059)
 -apple-system-find-highlight-background : rgb(255, 255, 0)
index 208080d..8e3d395 100644 (file)
@@ -1794,9 +1794,6 @@ webkit.org/b/187393 imported/w3c/web-platform-tests/2dcontext/imagebitmap/create
 
 [ Mojave+ ] http/tests/cookies/same-site [ Pass ]
 
-# <rdar://problem/39118706> REGRESSION (Mojave): LayoutTest fast/css/test-setting-canvas-color.html is failing
-[ Mojave+ ] fast/css/test-setting-canvas-color.html [ Failure ]
-
 # <rdar://problem/36639117> REGRESSION (Mojave): LayoutTest svg/custom/subpaths-moveto-only-rendering.svg is failing
 [ Mojave+ ] svg/custom/subpaths-moveto-only-rendering.svg [ Failure ]
 
index 28c4ac6..f913ab6 100644 (file)
@@ -9,7 +9,7 @@
 -apple-system-unemphasized-selected-content-background : rgb(220, 220, 220)
 -apple-system-selected-text : rgb(0, 0, 0)
 -apple-system-unemphasized-selected-text : rgb(0, 0, 0)
--apple-system-selected-text-background : rgb(179, 215, 255)
+-apple-system-selected-text-background : rgba(128, 188, 254, 0.6)
 -apple-system-unemphasized-selected-text-background : rgb(220, 220, 220)
 -apple-system-placeholder-text : rgba(0, 0, 0, 0.247059)
 -apple-system-find-highlight-background : rgb(255, 255, 0)
index e031c72..b6b5f17 100644 (file)
@@ -1,3 +1,19 @@
+2018-08-01  Timothy Hatcher  <timothy@apple.com>
+
+        Hardcode some system colors to avoid fingerprinting exposure.
+        https://bugs.webkit.org/show_bug.cgi?id=188203
+        rdar://problem/42781630
+
+        Reviewed by Tim Horton.
+
+        Passes existing tests with the hardcoded blue system appearance.
+
+        * rendering/RenderTheme.h:
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::systemColor const):
+        Adds special handling for some system colors. Fixes -apple-system-selected-text-background
+        to match the real selection color by using blendWithWhite().
+
 2018-08-01  Eric Carlson  <eric.carlson@apple.com>
 
         [iOS] Remove the delay before setting audio session category added in r233535
index 84d282d..5ef5bfc 100644 (file)
@@ -413,6 +413,10 @@ protected:
         Color systemLinkColor;
         Color systemActiveLinkColor;
         Color systemVisitedLinkColor;
+        Color systemFocusRingColor;
+        Color systemControlAccentColor;
+        Color systemSelectedTextBackgroundColor;
+        Color systemSelectedContentBackgroundColor;
 
         Color activeSelectionBackgroundColor;
         Color inactiveSelectionBackgroundColor;
index 37665fd..06c0c68 100644 (file)
@@ -550,7 +550,7 @@ Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::O
     auto& cache = colorCache(options);
 
     if (useSystemAppearance) {
-        // Only use NSColor for links when the system appearance is desired.
+        // Special handling for links and other system colors when the system appearance is desired.
         auto systemAppearanceColor = [] (Color& color, SEL selector) -> Color {
             if (!color.isValid()) {
                 auto systemColor = wtfObjcMsgSend<NSColor *>([NSColor class], selector);
@@ -561,15 +561,48 @@ Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::O
         };
 
         switch (cssValueID) {
+        // Web views that want system appearance get the system version of link colors, which differ from the HTML spec.
         case CSSValueWebkitLink:
             if (forVisitedLink)
                 return systemAppearanceColor(cache.systemVisitedLinkColor, @selector(systemPurpleColor));
             return systemAppearanceColor(cache.systemLinkColor, @selector(linkColor));
+
         case CSSValueWebkitActivelink:
             // FIXME: Use a semantic system color for this, instead of systemRedColor. <rdar://problem/39256684>
             return systemAppearanceColor(cache.systemActiveLinkColor, @selector(systemRedColor));
+
+        // The following colors would expose user appearance preferences to the web, and could be used for fingerprinting.
+        // These should only be available when the web view is wanting the system appearance.
+        case CSSValueWebkitFocusRingColor:
+        case CSSValueActiveborder:
+            return systemAppearanceColor(cache.systemFocusRingColor, @selector(keyboardFocusIndicatorColor));
+
+        case CSSValueAppleSystemControlAccent:
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+            return systemAppearanceColor(cache.systemControlAccentColor, @selector(controlAccentColor));
+#else
+            return systemAppearanceColor(cache.systemControlAccentColor, @selector(alternateSelectedControlColor));
+#endif
+
+        case CSSValueAppleSystemSelectedContentBackground:
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+            return systemAppearanceColor(cache.systemSelectedContentBackgroundColor, @selector(selectedContentBackgroundColor));
+#else
+            return systemAppearanceColor(cache.systemSelectedContentBackgroundColor, @selector(alternateSelectedControlColor));
+#endif
+
+        case CSSValueAppleSystemSelectedTextBackground:
+        case CSSValueHighlight:
+            // Can't use systemAppearanceColor() since blendWithWhite() needs called before caching as a semantic color.
+            if (!cache.systemSelectedTextBackgroundColor.isValid()) {
+                Color systemColor = semanticColorFromNSColor([NSColor selectedTextBackgroundColor]);
+                cache.systemSelectedTextBackgroundColor = Color(systemColor.blendWithWhite().rgb(), Color::Semantic);
+            }
+
+            return cache.systemSelectedTextBackgroundColor;
+
         default:
-            // Handle non-link colors below, with the regular cache.
+            // Handle other system colors below, that don't need special system appearance handling.
             break;
         }
     } else if (forVisitedLink && cssValueID == CSSValueWebkitLink) {
@@ -580,11 +613,9 @@ Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::O
 
     ASSERT(!forVisitedLink);
 
-    return cache.systemStyleColors.ensure(cssValueID, [this, cssValueID, options] () -> Color {
+    return cache.systemStyleColors.ensure(cssValueID, [this, cssValueID, options, &localAppearance] () -> Color {
         auto selectCocoaColor = [cssValueID] () -> SEL {
             switch (cssValueID) {
-            case CSSValueActiveborder:
-                return @selector(keyboardFocusIndicatorColor);
             case CSSValueActivecaption:
                 return @selector(windowFrameTextColor);
             case CSSValueAppworkspace:
@@ -599,8 +630,6 @@ Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::O
                 return @selector(textColor);
             case CSSValueGraytext:
                 return @selector(disabledControlTextColor);
-            case CSSValueHighlight:
-                return @selector(selectedTextBackgroundColor);
             case CSSValueHighlighttext:
                 return @selector(selectedTextColor);
             case CSSValueInactiveborder:
@@ -625,8 +654,6 @@ Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::O
                 return @selector(highlightColor);
             case CSSValueThreedlightshadow:
                 return @selector(controlLightHighlightColor);
-            case CSSValueWebkitFocusRingColor:
-                return @selector(keyboardFocusIndicatorColor);
             case CSSValueWindow:
                 return @selector(windowBackgroundColor);
             case CSSValueWindowframe:
@@ -641,18 +668,6 @@ Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::O
                 return @selector(controlBackgroundColor);
             case CSSValueAppleSystemAlternateSelectedText:
                 return @selector(alternateSelectedControlTextColor);
-            case CSSValueAppleSystemControlAccent:
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
-                return @selector(controlAccentColor);
-#else
-                return @selector(alternateSelectedControlColor);
-#endif
-            case CSSValueAppleSystemSelectedContentBackground:
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
-                return @selector(selectedContentBackgroundColor);
-#else
-                return @selector(alternateSelectedControlColor);
-#endif
             case CSSValueAppleSystemUnemphasizedSelectedContentBackground:
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
                 return @selector(unemphasizedSelectedContentBackgroundColor);
@@ -667,8 +682,6 @@ Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::O
 #else
                 return @selector(textColor);
 #endif
-            case CSSValueAppleSystemSelectedTextBackground:
-                return @selector(selectedTextBackgroundColor);
             case CSSValueAppleSystemUnemphasizedSelectedTextBackground:
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
                 return @selector(unemphasizedSelectedTextBackgroundColor);
@@ -748,6 +761,31 @@ Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::O
         case CSSValueMenu:
             return menuBackgroundColor();
 
+        case CSSValueWebkitFocusRingColor:
+        case CSSValueActiveborder:
+            // Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting.
+            if (localAppearance.usingDarkAppearance())
+                return Color(0x4C1AA9FF, Color::Semantic);
+            return Color(0x3F0067F4, Color::Semantic);
+
+        case CSSValueAppleSystemControlAccent:
+            // Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting.
+            // Same color in light and dark appearances.
+            return Color(0xFF007AFF, Color::Semantic);
+
+        case CSSValueAppleSystemSelectedContentBackground:
+            // Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting.
+            if (localAppearance.usingDarkAppearance())
+                return Color(0xFF0058D0, Color::Semantic);
+            return Color(0xFF0063E1, Color::Semantic);
+
+        case CSSValueHighlight:
+        case CSSValueAppleSystemSelectedTextBackground:
+            // Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting.
+            if (localAppearance.usingDarkAppearance())
+                return Color(0xCC0F3C6E, Color::Semantic);
+            return Color(0x9980BCFE, Color::Semantic);
+
 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
         case CSSValueAppleSystemFindHighlightBackground:
             return platformActiveTextSearchHighlightColor(options);