Title: [277123] trunk
Revision
277123
Author
[email protected]
Date
2021-05-06 14:26:23 -0700 (Thu, 06 May 2021)

Log Message

Sampled Page Top Color: don't snapshot if the hit test location is a canvas
https://bugs.webkit.org/show_bug.cgi?id=225418

Reviewed by Tim Horton.

Source/WebCore:

Tests: SampledPageTopColor.HitTestHTMLCanvasWithoutRenderingContext
       SampledPageTopColor.HitTestHTMLCanvasWithRenderingContext

* dom/Document.cpp:
(WebCore::isValidPageSampleLocation):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/SampledPageTopColor.mm:
(TEST.SampledPageTopColor.HitTestHTMLCanvasWithoutRenderingContext): Added.
(TEST.SampledPageTopColor.HitTestHTMLCanvasWithRenderingContext): Added.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277122 => 277123)


--- trunk/Source/WebCore/ChangeLog	2021-05-06 21:16:51 UTC (rev 277122)
+++ trunk/Source/WebCore/ChangeLog	2021-05-06 21:26:23 UTC (rev 277123)
@@ -1,3 +1,16 @@
+2021-05-06  Devin Rousso  <[email protected]>
+
+        Sampled Page Top Color: don't snapshot if the hit test location is a canvas
+        https://bugs.webkit.org/show_bug.cgi?id=225418
+
+        Reviewed by Tim Horton.
+
+        Tests: SampledPageTopColor.HitTestHTMLCanvasWithoutRenderingContext
+               SampledPageTopColor.HitTestHTMLCanvasWithRenderingContext
+
+        * dom/Document.cpp:
+        (WebCore::isValidPageSampleLocation):
+
 2021-05-06  Jer Noble  <[email protected]>
 
         REGRESSION (r276870): ASSERTION FAILED: !m_impl || !m_shouldEnableAssertions || m_impl->wasConstructedOnMainThread() == isMainThread() under WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer

Modified: trunk/Source/WebCore/dom/Document.cpp (277122 => 277123)


--- trunk/Source/WebCore/dom/Document.cpp	2021-05-06 21:16:51 UTC (rev 277122)
+++ trunk/Source/WebCore/dom/Document.cpp	2021-05-06 21:26:23 UTC (rev 277123)
@@ -3894,6 +3894,11 @@
         if (renderer->style().hasTransitions() || renderer->style().hasAnimations())
             return false;
 
+        // Skip `<canvas>` but only if they've been drawn into. Guess this by seeing if there's already
+        // a `CanvasRenderingContext`, which is only created by _javascript_.
+        if (is<HTMLCanvasElement>(node) && downcast<HTMLCanvasElement>(node).renderingContext())
+            return false;
+
         // Skip 3rd-party `<iframe>` as the content likely won't match the rest of the page.
         if (is<HTMLIFrameElement>(node) && !areRegistrableDomainsEqual(downcast<HTMLIFrameElement>(node).location(), document.url()))
             return false;

Modified: trunk/Tools/ChangeLog (277122 => 277123)


--- trunk/Tools/ChangeLog	2021-05-06 21:16:51 UTC (rev 277122)
+++ trunk/Tools/ChangeLog	2021-05-06 21:26:23 UTC (rev 277123)
@@ -1,3 +1,14 @@
+2021-05-06  Devin Rousso  <[email protected]>
+
+        Sampled Page Top Color: don't snapshot if the hit test location is a canvas
+        https://bugs.webkit.org/show_bug.cgi?id=225418
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/SampledPageTopColor.mm:
+        (TEST.SampledPageTopColor.HitTestHTMLCanvasWithoutRenderingContext): Added.
+        (TEST.SampledPageTopColor.HitTestHTMLCanvasWithRenderingContext): Added.
+
 2021-05-06  Jonathan Bedard  <[email protected]>
 
         [webkit-patch] setup-git-clone uses master instead of main

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SampledPageTopColor.mm (277122 => 277123)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SampledPageTopColor.mm	2021-05-06 21:16:51 UTC (rev 277122)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SampledPageTopColor.mm	2021-05-06 21:26:23 UTC (rev 277123)
@@ -293,6 +293,24 @@
     EXPECT_NULL([webView _sampledPageTopColor]);
 }
 
+TEST(SampledPageTopColor, HitTestHTMLCanvasWithoutRenderingContext)
+{
+    auto webView = createWebViewWithSampledPageTopColorMaxDifference(5);
+    EXPECT_NULL([webView _sampledPageTopColor]);
+
+    waitForSampledPageTopColorToChangeForHTML(webView.get(), @"<body style='margin: 0'><canvas style='width: 100%; height: 100%; background-color: red'></canvas>Test");
+    EXPECT_EQ(WebCore::Color([webView _sampledPageTopColor].CGColor), WebCore::Color::red);
+}
+
+TEST(SampledPageTopColor, HitTestHTMLCanvasWithRenderingContext)
+{
+    auto webView = createWebViewWithSampledPageTopColorMaxDifference(5);
+    EXPECT_NULL([webView _sampledPageTopColor]);
+
+    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:@"<body style='margin: 0'><canvas style='width: 100%; height: 100%; background-color: red'></canvas>Test<script>document.querySelector('canvas').getContext('2d')</script>"];
+    EXPECT_NULL([webView _sampledPageTopColor]);
+}
+
 TEST(SampledPageTopColor, HitTestCSSBackgroundImage)
 {
     auto webView = createWebViewWithSampledPageTopColorMaxDifference(5);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to