Title: [247802] trunk
Revision
247802
Author
[email protected]
Date
2019-07-24 17:21:34 -0700 (Wed, 24 Jul 2019)

Log Message

Web Inspector: support `console.screenshot` with subclasses of CanvasRenderingContext
https://bugs.webkit.org/show_bug.cgi?id=199305

Reviewed by Joseph Pecoraro.

Source/WebCore:

Test: inspector/console/console-screenshot.html

* page/PageConsoleClient.cpp:
(WebCore::canvasRenderingContext):
(WebCore::PageConsoleClient::record):
(WebCore::PageConsoleClient::recordEnd):
(WebCore::PageConsoleClient::screenshot):

LayoutTests:

* inspector/console/console-screenshot.html:
* inspector/console/console-screenshot-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (247801 => 247802)


--- trunk/LayoutTests/ChangeLog	2019-07-25 00:10:51 UTC (rev 247801)
+++ trunk/LayoutTests/ChangeLog	2019-07-25 00:21:34 UTC (rev 247802)
@@ -1,3 +1,13 @@
+2019-07-24  Devin Rousso  <[email protected]>
+
+        Web Inspector: support `console.screenshot` with subclasses of CanvasRenderingContext
+        https://bugs.webkit.org/show_bug.cgi?id=199305
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/console/console-screenshot.html:
+        * inspector/console/console-screenshot-expected.txt:
+
 2019-07-24  Tim Horton  <[email protected]>
 
         Daring Fireball long press highlights are unnecessarily inflated due to false illegibility

Modified: trunk/LayoutTests/inspector/console/console-screenshot-expected.txt (247801 => 247802)


--- trunk/LayoutTests/inspector/console/console-screenshot-expected.txt	2019-07-25 00:10:51 UTC (rev 247801)
+++ trunk/LayoutTests/inspector/console/console-screenshot-expected.txt	2019-07-25 00:21:34 UTC (rev 247802)
@@ -1,6 +1,7 @@
 CONSOLE MESSAGE: [object HTMLDivElement]
 CONSOLE MESSAGE: [object HTMLDivElement]
 CONSOLE MESSAGE: [object HTMLDivElement]
+CONSOLE MESSAGE: [object CanvasRenderingContext2D]
 CONSOLE MESSAGE: Viewport
 CONSOLE MESSAGE: Viewport
 Tests for the console.screenshot API.
@@ -22,6 +23,12 @@
 -- Running test case: console.screenshot.Node.DetachedNonScreenshotable
 PASS: Could not capture screenshot
 
+-- Running test case: console.screenshot.CanvasRenderingContext2D
+PASS: The added message should be an image.
+PASS: The image should not be empty.
+PASS: The image width should be 2px.
+PASS: The image height should be 2px.
+
 -- Running test case: console.screenshot.NonScreenshotableTarget
 PASS: The added message should be an image.
 PASS: The image should not be empty.

Modified: trunk/LayoutTests/inspector/console/console-screenshot.html (247801 => 247802)


--- trunk/LayoutTests/inspector/console/console-screenshot.html	2019-07-25 00:10:51 UTC (rev 247801)
+++ trunk/LayoutTests/inspector/console/console-screenshot.html	2019-07-25 00:21:34 UTC (rev 247802)
@@ -11,6 +11,13 @@
     return div;
 }
 
+function createCanvas2DTest() {
+    let canvas = document.createElement("canvas");
+    canvas.width = 2;
+    canvas.height = 2;
+    return canvas.getContext("2d");
+}
+
 function test()
 {
     let suite = InspectorTest.createAsyncSuite("console.screenshot");
@@ -76,6 +83,18 @@
     });
 
     addTest({
+        name: "console.screenshot.CanvasRenderingContext2D",
+        _expression_: `console.screenshot(createCanvas2DTest())`,
+        async imageMessageAddedCallback(message) {
+            InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
+
+            let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
+            InspectorTest.expectEqual(img.width, 2, "The image width should be 2px.");
+            InspectorTest.expectEqual(img.height, 2, "The image height should be 2px.");
+        },
+    });
+
+    addTest({
         name: "console.screenshot.NonScreenshotableTarget",
         _expression_: `console.screenshot(42)`,
         async imageMessageAddedCallback(message) {

Modified: trunk/Source/WebCore/ChangeLog (247801 => 247802)


--- trunk/Source/WebCore/ChangeLog	2019-07-25 00:10:51 UTC (rev 247801)
+++ trunk/Source/WebCore/ChangeLog	2019-07-25 00:21:34 UTC (rev 247802)
@@ -1,3 +1,18 @@
+2019-07-24  Devin Rousso  <[email protected]>
+
+        Web Inspector: support `console.screenshot` with subclasses of CanvasRenderingContext
+        https://bugs.webkit.org/show_bug.cgi?id=199305
+
+        Reviewed by Joseph Pecoraro.
+
+        Test: inspector/console/console-screenshot.html
+
+        * page/PageConsoleClient.cpp:
+        (WebCore::canvasRenderingContext):
+        (WebCore::PageConsoleClient::record):
+        (WebCore::PageConsoleClient::recordEnd):
+        (WebCore::PageConsoleClient::screenshot):
+
 2019-07-24  Youenn Fablet  <[email protected]>
 
         Remove MediaPlayerPrivate::supportsMuting()

Modified: trunk/Source/WebCore/page/PageConsoleClient.cpp (247801 => 247802)


--- trunk/Source/WebCore/page/PageConsoleClient.cpp	2019-07-25 00:10:51 UTC (rev 247801)
+++ trunk/Source/WebCore/page/PageConsoleClient.cpp	2019-07-25 00:21:34 UTC (rev 247802)
@@ -233,12 +233,8 @@
     return arguments.argumentCount() > index ? arguments.argumentAt(index).getObject() : nullptr;
 }
 
-static CanvasRenderingContext* canvasRenderingContext(JSC::VM& vm, ScriptArguments& arguments)
+static CanvasRenderingContext* canvasRenderingContext(JSC::VM& vm, JSC::JSValue target)
 {
-    auto* target = objectArgumentAt(arguments, 0);
-    if (!target)
-        return nullptr;
-
     if (auto* canvas = JSHTMLCanvasElement::toWrapped(vm, target))
         return canvas->renderingContext();
     if (auto* canvas = JSOffscreenCanvas::toWrapped(vm, target))
@@ -260,14 +256,18 @@
 
 void PageConsoleClient::record(JSC::ExecState* state, Ref<ScriptArguments>&& arguments)
 {
-    if (auto* context = canvasRenderingContext(state->vm(), arguments))
-        InspectorInstrumentation::consoleStartRecordingCanvas(*context, *state, objectArgumentAt(arguments, 1));
+    if (auto* target = objectArgumentAt(arguments, 0)) {
+        if (auto* context = canvasRenderingContext(state->vm(), target))
+            InspectorInstrumentation::consoleStartRecordingCanvas(*context, *state, objectArgumentAt(arguments, 1));
+    }
 }
 
 void PageConsoleClient::recordEnd(JSC::ExecState* state, Ref<ScriptArguments>&& arguments)
 {
-    if (auto* context = canvasRenderingContext(state->vm(), arguments))
-        InspectorInstrumentation::didFinishRecordingCanvasFrame(*context, true);
+    if (auto* target = objectArgumentAt(arguments, 0)) {
+        if (auto* context = canvasRenderingContext(state->vm(), target))
+            InspectorInstrumentation::didFinishRecordingCanvasFrame(*context, true);
+    }
 }
 
 void PageConsoleClient::screenshot(JSC::ExecState* state, Ref<ScriptArguments>&& arguments)
@@ -284,6 +284,29 @@
                 if (auto snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node))
                     dataURL = snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes);
             }
+        } else if (auto* context = canvasRenderingContext(state->vm(), possibleTarget)) {
+            auto& canvas = context->canvasBase();
+            if (is<HTMLCanvasElement>(canvas)) {
+                target = possibleTarget;
+                if (UNLIKELY(InspectorInstrumentation::hasFrontends())) {
+#if ENABLE(WEBGL)
+                    if (is<WebGLRenderingContextBase>(context))
+                        downcast<WebGLRenderingContextBase>(context)->setPreventBufferClearForInspector(true);
+#endif
+
+                    auto result = downcast<HTMLCanvasElement>(canvas).toDataURL("image/png"_s);
+
+#if ENABLE(WEBGL)
+                    if (is<WebGLRenderingContextBase>(context))
+                        downcast<WebGLRenderingContextBase>(context)->setPreventBufferClearForInspector(false);
+#endif
+
+                    if (!result.hasException())
+                        dataURL = result.releaseReturnValue().string;
+                }
+            }
+
+            // FIXME: <https://webkit.org/b/180833> Web Inspector: support OffscreenCanvas for Canvas related operations
         }
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to