Diff
Modified: trunk/LayoutTests/ChangeLog (247813 => 247814)
--- trunk/LayoutTests/ChangeLog 2019-07-25 02:40:05 UTC (rev 247813)
+++ trunk/LayoutTests/ChangeLog 2019-07-25 03:35:03 UTC (rev 247814)
@@ -1,5 +1,15 @@
2019-07-24 Devin Rousso <[email protected]>
+ Web Inspector: support `console.screenshot` with detached Nodes that are graphical
+ https://bugs.webkit.org/show_bug.cgi?id=199309
+
+ Reviewed by Joseph Pecoraro.
+
+ * inspector/console/console-screenshot.html:
+ * inspector/console/console-screenshot-expected.txt:
+
+2019-07-24 Devin Rousso <[email protected]>
+
Web Inspector: support `console.screenshot` with ImageData and ImageBitmap
https://bugs.webkit.org/show_bug.cgi?id=199304
Modified: trunk/LayoutTests/inspector/console/console-screenshot-expected.txt (247813 => 247814)
--- trunk/LayoutTests/inspector/console/console-screenshot-expected.txt 2019-07-25 02:40:05 UTC (rev 247813)
+++ trunk/LayoutTests/inspector/console/console-screenshot-expected.txt 2019-07-25 03:35:03 UTC (rev 247814)
@@ -1,5 +1,7 @@
CONSOLE MESSAGE: [object HTMLDivElement]
CONSOLE MESSAGE: [object HTMLDivElement]
+CONSOLE MESSAGE: [object HTMLImageElement]
+CONSOLE MESSAGE: [object HTMLPictureElement]
CONSOLE MESSAGE: [object HTMLDivElement]
CONSOLE MESSAGE: [object ImageData]
CONSOLE MESSAGE: [object ImageBitmap]
@@ -22,6 +24,18 @@
PASS: The image width should be 2px.
PASS: The image height should be 2px.
+-- Running test case: console.screenshot.Node.DetachedScreenshotable.Image
+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.DetachedScreenshotable.Picture
+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 (247813 => 247814)
--- trunk/LayoutTests/inspector/console/console-screenshot.html 2019-07-25 02:40:05 UTC (rev 247813)
+++ trunk/LayoutTests/inspector/console/console-screenshot.html 2019-07-25 03:35:03 UTC (rev 247814)
@@ -11,6 +11,26 @@
return div;
}
+function testHTMLImageElement() {
+ // 2x2 red square
+ let image = document.createElement("img");
+ image.src = ""
+ image.addEventListener("load", async (event) => {
+ console.screenshot(image);
+ });
+}
+
+function testHTMLPictureElement() {
+ let picture = document.createElement("picture");
+
+ // 2x2 red square
+ let image = picture.appendChild(document.createElement("img"));
+ image.src = ""
+ image.addEventListener("load", async (event) => {
+ console.screenshot(picture);
+ });
+}
+
function testImageBitmap() {
// 2x2 red square
let image = document.createElement("img");
@@ -87,6 +107,30 @@
});
addTest({
+ name: "console.screenshot.Node.DetachedScreenshotable.Image",
+ _expression_: `testHTMLImageElement()`,
+ 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.DetachedScreenshotable.Picture",
+ _expression_: `testHTMLPictureElement()`,
+ 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 (247813 => 247814)
--- trunk/Source/WebCore/ChangeLog 2019-07-25 02:40:05 UTC (rev 247813)
+++ trunk/Source/WebCore/ChangeLog 2019-07-25 03:35:03 UTC (rev 247814)
@@ -1,3 +1,15 @@
+2019-07-24 Devin Rousso <[email protected]>
+
+ Web Inspector: support `console.screenshot` with detached Nodes that are graphical
+ https://bugs.webkit.org/show_bug.cgi?id=199309
+
+ Reviewed by Joseph Pecoraro.
+
+ Test: inspector/console/console-screenshot.html
+
+ * page/PageConsoleClient.cpp:
+ (WebCore::PageConsoleClient::screenshot):
+
2019-07-24 Saam Barati <[email protected]>
[WHLSL] Use bmalloc instead of system malloc for WHLSL data structures
Modified: trunk/Source/WebCore/page/PageConsoleClient.cpp (247813 => 247814)
--- trunk/Source/WebCore/page/PageConsoleClient.cpp 2019-07-25 02:40:05 UTC (rev 247813)
+++ trunk/Source/WebCore/page/PageConsoleClient.cpp 2019-07-25 03:35:03 UTC (rev 247814)
@@ -29,13 +29,19 @@
#include "config.h"
#include "PageConsoleClient.h"
+#include "CachedImage.h"
#include "CanvasRenderingContext2D.h"
#include "Chrome.h"
#include "ChromeClient.h"
#include "Document.h"
+#include "ElementChildIterator.h"
#include "Frame.h"
#include "FrameSnapshotting.h"
#include "HTMLCanvasElement.h"
+#include "HTMLImageElement.h"
+#include "HTMLPictureElement.h"
+#include "HTMLVideoElement.h"
+#include "Image.h"
#include "ImageBitmap.h"
#include "ImageBitmapRenderingContext.h"
#include "ImageBuffer.h"
@@ -285,7 +291,38 @@
if (auto* node = JSNode::toWrapped(state->vm(), possibleTarget)) {
target = possibleTarget;
if (UNLIKELY(InspectorInstrumentation::hasFrontends())) {
- if (auto snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node))
+ std::unique_ptr<ImageBuffer> snapshot;
+
+ // Only try to do something special for subclasses of Node if they're detached from the DOM tree.
+ if (!node->document().contains(node)) {
+ auto snapshotImageElement = [&snapshot] (HTMLImageElement& imageElement) {
+ if (auto* cachedImage = imageElement.cachedImage()) {
+ auto* image = cachedImage->image();
+ if (image && image != &Image::nullImage()) {
+ snapshot = ImageBuffer::create(image->size(), RenderingMode::Unaccelerated);
+ snapshot->context().drawImage(*image, FloatPoint(0, 0));
+ }
+ }
+ };
+
+ if (is<HTMLImageElement>(node))
+ snapshotImageElement(downcast<HTMLImageElement>(*node));
+ else if (is<HTMLPictureElement>(node)) {
+ if (auto* firstImage = childrenOfType<HTMLImageElement>(downcast<HTMLPictureElement>(*node)).first())
+ snapshotImageElement(*firstImage);
+ } else if (is<HTMLVideoElement>(node)) {
+ auto& videoElement = downcast<HTMLVideoElement>(*node);
+ unsigned videoWidth = videoElement.videoWidth();
+ unsigned videoHeight = videoElement.videoHeight();
+ snapshot = ImageBuffer::create(FloatSize(videoWidth, videoHeight), RenderingMode::Unaccelerated);
+ videoElement.paintCurrentFrameInContext(snapshot->context(), FloatRect(0, 0, videoWidth, videoHeight));
+ }
+ }
+
+ if (!snapshot)
+ snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node);
+
+ if (snapshot)
dataURL = snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes);
}
} else if (auto* imageData = JSImageData::toWrapped(state->vm(), possibleTarget)) {