Changeset 248736 in webkit
- Timestamp:
- Aug 15, 2019, 12:16:04 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/inspector/console/console-screenshot-expected.txt (modified) (2 diffs)
-
LayoutTests/inspector/console/console-screenshot.html (modified) (2 diffs)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/page/PageConsoleClient.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r248734 r248736 1 2019-08-15 Devin Rousso <drousso@apple.com> 2 3 Web Inspector: support `console.screenshot` with detached <canvas> 4 https://bugs.webkit.org/show_bug.cgi?id=200723 5 6 Reviewed by Joseph Pecoraro. 7 8 * inspector/console/console-screenshot.html: 9 * inspector/console/console-screenshot-expected.txt: 10 1 11 2019-08-15 Sihui Liu <sihui_liu@apple.com> 2 12 -
trunk/LayoutTests/inspector/console/console-screenshot-expected.txt
r248688 r248736 3 3 CONSOLE MESSAGE: [object HTMLImageElement] 4 4 CONSOLE MESSAGE: [object HTMLPictureElement] 5 CONSOLE MESSAGE: [object HTMLCanvasElement] 5 6 CONSOLE MESSAGE: [object HTMLDivElement] 6 7 CONSOLE MESSAGE: [object ImageData] … … 35 36 36 37 -- Running test case: console.screenshot.Node.DetachedScreenshotable.Picture 38 PASS: The added message should be an image. 39 PASS: The image should not be empty. 40 PASS: The image width should be 2px. 41 PASS: The image height should be 2px. 42 43 -- Running test case: console.screenshot.Node.DetachedScreenshotable.Canvas 37 44 PASS: The added message should be an image. 38 45 PASS: The image should not be empty. -
trunk/LayoutTests/inspector/console/console-screenshot.html
r248688 r248736 30 30 console.screenshot(picture); 31 31 }); 32 } 33 34 function testHTMLCanvasElement() { 35 let canvas = document.createElement("canvas"); 36 canvas.width = 2; 37 canvas.height = 2; 38 39 let context = canvas.getContext("2d"); 40 context.fillStyle = "red"; 41 context.fillRect(0, 0, 2, 2); 42 43 console.screenshot(canvas); 32 44 } 33 45 … … 102 114 name: "console.screenshot.Node.DetachedScreenshotable.Picture", 103 115 expression: `testHTMLPictureElement()`, 116 }); 117 118 addTest({ 119 name: "console.screenshot.Node.DetachedScreenshotable.Canvas", 120 expression: `testHTMLCanvasElement()`, 121 async imageMessageAddedCallback(message) { 122 InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty."); 123 124 let img = await WI.ImageUtilities.promisifyLoad(message.messageText); 125 InspectorTest.expectEqual(img.width, 2, "The image width should be 2px."); 126 InspectorTest.expectEqual(img.height, 2, "The image height should be 2px."); 127 }, 104 128 }); 105 129 -
trunk/Source/WebCore/ChangeLog
r248734 r248736 1 2019-08-15 Devin Rousso <drousso@apple.com> 2 3 Web Inspector: support `console.screenshot` with detached <canvas> 4 https://bugs.webkit.org/show_bug.cgi?id=200723 5 6 Reviewed by Joseph Pecoraro. 7 8 * page/PageConsoleClient.cpp: 9 (WebCore::snapshotCanvas): Added. 10 (WebCore::PageConsoleClient::screenshot): 11 1 12 2019-08-15 Sihui Liu <sihui_liu@apple.com> 2 13 -
trunk/Source/WebCore/page/PageConsoleClient.cpp
r248688 r248736 282 282 } 283 283 284 static Optional<String> snapshotCanvas(HTMLCanvasElement& canvasElement, CanvasRenderingContext& canvasRenderingContext) 285 { 286 #if ENABLE(WEBGL) 287 if (is<WebGLRenderingContextBase>(canvasRenderingContext)) 288 downcast<WebGLRenderingContextBase>(canvasRenderingContext).setPreventBufferClearForInspector(true); 289 #endif 290 291 auto result = canvasElement.toDataURL("image/png"_s); 292 293 #if ENABLE(WEBGL) 294 if (is<WebGLRenderingContextBase>(canvasRenderingContext)) 295 downcast<WebGLRenderingContextBase>(canvasRenderingContext).setPreventBufferClearForInspector(false); 296 #endif 297 298 if (!result.hasException()) 299 return result.releaseReturnValue().string; 300 301 return WTF::nullopt; 302 } 303 284 304 void PageConsoleClient::screenshot(JSC::ExecState* state, Ref<ScriptArguments>&& arguments) 285 305 { … … 322 342 } 323 343 #endif 344 else if (is<HTMLCanvasElement>(node)) { 345 auto& canvasElement = downcast<HTMLCanvasElement>(*node); 346 if (auto* canvasRenderingContext = canvasElement.renderingContext()) { 347 if (auto result = snapshotCanvas(canvasElement, *canvasRenderingContext)) 348 dataURL = result.value(); 349 } 350 } 324 351 } 325 352 326 if (!snapshot) 327 snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node); 328 329 if (snapshot) 330 dataURL = snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes); 353 if (dataURL.isEmpty()) { 354 if (!snapshot) 355 snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node); 356 357 if (snapshot) 358 dataURL = snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes); 359 } 331 360 } 332 361 } else if (auto* imageData = JSImageData::toWrapped(state->vm(), possibleTarget)) { … … 351 380 target = possibleTarget; 352 381 if (UNLIKELY(InspectorInstrumentation::hasFrontends())) { 353 #if ENABLE(WEBGL) 354 if (is<WebGLRenderingContextBase>(context)) 355 downcast<WebGLRenderingContextBase>(context)->setPreventBufferClearForInspector(true); 356 #endif 357 358 auto result = downcast<HTMLCanvasElement>(canvas).toDataURL("image/png"_s); 359 360 #if ENABLE(WEBGL) 361 if (is<WebGLRenderingContextBase>(context)) 362 downcast<WebGLRenderingContextBase>(context)->setPreventBufferClearForInspector(false); 363 #endif 364 365 if (!result.hasException()) 366 dataURL = result.releaseReturnValue().string; 382 if (auto result = snapshotCanvas(downcast<HTMLCanvasElement>(canvas), *context)) 383 dataURL = result.value(); 367 384 } 368 385 }
Note:
See TracChangeset
for help on using the changeset viewer.