Diff
Modified: trunk/LayoutTests/ChangeLog (248735 => 248736)
--- trunk/LayoutTests/ChangeLog 2019-08-15 19:13:21 UTC (rev 248735)
+++ trunk/LayoutTests/ChangeLog 2019-08-15 19:16:04 UTC (rev 248736)
@@ -1,3 +1,13 @@
+2019-08-15 Devin Rousso <[email protected]>
+
+ Web Inspector: support `console.screenshot` with detached <canvas>
+ https://bugs.webkit.org/show_bug.cgi?id=200723
+
+ Reviewed by Joseph Pecoraro.
+
+ * inspector/console/console-screenshot.html:
+ * inspector/console/console-screenshot-expected.txt:
+
2019-08-15 Sihui Liu <[email protected]>
Some improvements on web storage
Modified: trunk/LayoutTests/inspector/console/console-screenshot-expected.txt (248735 => 248736)
--- trunk/LayoutTests/inspector/console/console-screenshot-expected.txt 2019-08-15 19:13:21 UTC (rev 248735)
+++ trunk/LayoutTests/inspector/console/console-screenshot-expected.txt 2019-08-15 19:16:04 UTC (rev 248736)
@@ -2,6 +2,7 @@
CONSOLE MESSAGE: [object HTMLDivElement]
CONSOLE MESSAGE: [object HTMLImageElement]
CONSOLE MESSAGE: [object HTMLPictureElement]
+CONSOLE MESSAGE: [object HTMLCanvasElement]
CONSOLE MESSAGE: [object HTMLDivElement]
CONSOLE MESSAGE: [object ImageData]
CONSOLE MESSAGE: [object ImageBitmap]
@@ -39,6 +40,12 @@
PASS: The image width should be 2px.
PASS: The image height should be 2px.
+-- Running test case: console.screenshot.Node.DetachedScreenshotable.Canvas
+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.Node.DetachedNonScreenshotable
PASS: Could not capture screenshot
Modified: trunk/LayoutTests/inspector/console/console-screenshot.html (248735 => 248736)
--- trunk/LayoutTests/inspector/console/console-screenshot.html 2019-08-15 19:13:21 UTC (rev 248735)
+++ trunk/LayoutTests/inspector/console/console-screenshot.html 2019-08-15 19:16:04 UTC (rev 248736)
@@ -31,6 +31,18 @@
});
}
+function testHTMLCanvasElement() {
+ let canvas = document.createElement("canvas");
+ canvas.width = 2;
+ canvas.height = 2;
+
+ let context = canvas.getContext("2d");
+ context.fillStyle = "red";
+ context.fillRect(0, 0, 2, 2);
+
+ console.screenshot(canvas);
+}
+
function testImageBitmap() {
// 2x2 red square
let image = document.createElement("img");
@@ -104,6 +116,18 @@
});
addTest({
+ name: "console.screenshot.Node.DetachedScreenshotable.Canvas",
+ _expression_: `testHTMLCanvasElement()`,
+ 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.Node.DetachedNonScreenshotable",
_expression_: `console.screenshot(createDetachedTest())`,
shouldError: true,
Modified: trunk/Source/WebCore/ChangeLog (248735 => 248736)
--- trunk/Source/WebCore/ChangeLog 2019-08-15 19:13:21 UTC (rev 248735)
+++ trunk/Source/WebCore/ChangeLog 2019-08-15 19:16:04 UTC (rev 248736)
@@ -1,3 +1,14 @@
+2019-08-15 Devin Rousso <[email protected]>
+
+ Web Inspector: support `console.screenshot` with detached <canvas>
+ https://bugs.webkit.org/show_bug.cgi?id=200723
+
+ Reviewed by Joseph Pecoraro.
+
+ * page/PageConsoleClient.cpp:
+ (WebCore::snapshotCanvas): Added.
+ (WebCore::PageConsoleClient::screenshot):
+
2019-08-15 Sihui Liu <[email protected]>
Some improvements on web storage
Modified: trunk/Source/WebCore/page/PageConsoleClient.cpp (248735 => 248736)
--- trunk/Source/WebCore/page/PageConsoleClient.cpp 2019-08-15 19:13:21 UTC (rev 248735)
+++ trunk/Source/WebCore/page/PageConsoleClient.cpp 2019-08-15 19:16:04 UTC (rev 248736)
@@ -281,6 +281,26 @@
}
}
+static Optional<String> snapshotCanvas(HTMLCanvasElement& canvasElement, CanvasRenderingContext& canvasRenderingContext)
+{
+#if ENABLE(WEBGL)
+ if (is<WebGLRenderingContextBase>(canvasRenderingContext))
+ downcast<WebGLRenderingContextBase>(canvasRenderingContext).setPreventBufferClearForInspector(true);
+#endif
+
+ auto result = canvasElement.toDataURL("image/png"_s);
+
+#if ENABLE(WEBGL)
+ if (is<WebGLRenderingContextBase>(canvasRenderingContext))
+ downcast<WebGLRenderingContextBase>(canvasRenderingContext).setPreventBufferClearForInspector(false);
+#endif
+
+ if (!result.hasException())
+ return result.releaseReturnValue().string;
+
+ return WTF::nullopt;
+}
+
void PageConsoleClient::screenshot(JSC::ExecState* state, Ref<ScriptArguments>&& arguments)
{
String dataURL;
@@ -321,13 +341,22 @@
videoElement.paintCurrentFrameInContext(snapshot->context(), FloatRect(0, 0, videoWidth, videoHeight));
}
#endif
+ else if (is<HTMLCanvasElement>(node)) {
+ auto& canvasElement = downcast<HTMLCanvasElement>(*node);
+ if (auto* canvasRenderingContext = canvasElement.renderingContext()) {
+ if (auto result = snapshotCanvas(canvasElement, *canvasRenderingContext))
+ dataURL = result.value();
+ }
+ }
}
- if (!snapshot)
- snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node);
+ if (dataURL.isEmpty()) {
+ if (!snapshot)
+ snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node);
- if (snapshot)
- dataURL = snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes);
+ if (snapshot)
+ dataURL = snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes);
+ }
}
} else if (auto* imageData = JSImageData::toWrapped(state->vm(), possibleTarget)) {
target = possibleTarget;
@@ -350,20 +379,8 @@
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;
+ if (auto result = snapshotCanvas(downcast<HTMLCanvasElement>(canvas), *context))
+ dataURL = result.value();
}
}