WebKit Bugzilla
Attachment 373086 Details for
Bug 199305
: Web Inspector: support `console.screenshot` with subclasses of CanvasRenderingContext
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
199305.diff (text/plain), 6.27 KB, created by
Devin Rousso
on 2019-06-27 22:30:19 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Devin Rousso
Created:
2019-06-27 22:30:19 PDT
Size:
6.27 KB
patch
obsolete
>diff --git a/LayoutTests/inspector/console/console-screenshot-expected.txt b/LayoutTests/inspector/console/console-screenshot-expected.txt >index f50e78c5678..c4094d04e6b 100644 >--- a/LayoutTests/inspector/console/console-screenshot-expected.txt >+++ b/LayoutTests/inspector/console/console-screenshot-expected.txt >@@ -1,5 +1,6 @@ > CONSOLE MESSAGE: [object HTMLDivElement] > CONSOLE MESSAGE: test >+CONSOLE MESSAGE: [object CanvasRenderingContext2D] > CONSOLE MESSAGE: 42 > CONSOLE MESSAGE: Viewport > Tests for the console.screenshot API. >@@ -21,6 +22,12 @@ PASS: The image height should be 2px. > -- 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. >diff --git a/LayoutTests/inspector/console/console-screenshot.html b/LayoutTests/inspector/console/console-screenshot.html >index 04f6c6652db..f34714b0fd6 100644 >--- a/LayoutTests/inspector/console/console-screenshot.html >+++ b/LayoutTests/inspector/console/console-screenshot.html >@@ -11,6 +11,13 @@ function createDetachedTest() > 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"); >@@ -75,6 +82,18 @@ function test() > shouldError: true, > }); > >+ 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)`, >diff --git a/Source/WebCore/page/PageConsoleClient.cpp b/Source/WebCore/page/PageConsoleClient.cpp >index 3f43eb080a6..8d879a1fc6f 100644 >--- a/Source/WebCore/page/PageConsoleClient.cpp >+++ b/Source/WebCore/page/PageConsoleClient.cpp >@@ -222,12 +222,8 @@ static JSC::JSObject* objectArgumentAt(ScriptArguments& arguments, unsigned inde > 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)) >@@ -249,14 +245,18 @@ static CanvasRenderingContext* canvasRenderingContext(JSC::VM& vm, ScriptArgumen > > 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) >@@ -289,6 +289,28 @@ void PageConsoleClient::screenshot(JSC::ExecState* state, Ref<ScriptArguments>&& > if (auto snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node)) > dataURL = snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes); > captureAttempted = true; >+ } else if (auto* context = canvasRenderingContext(state->vm(), target)) { >+ auto& canvas = context->canvasBase(); >+ if (is<HTMLCanvasElement>(canvas)) { >+#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 >+ >+ captureAttempted = true; > } > } > >@@ -302,7 +324,7 @@ void PageConsoleClient::screenshot(JSC::ExecState* state, Ref<ScriptArguments>&& > dataURL = snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes); > } > >- if (dataURL.isEmpty()) { >+ if (dataURL.isEmpty() || dataURL == "data:,") { > addMessage(std::make_unique<Inspector::ConsoleMessage>(MessageSource::ConsoleAPI, MessageType::Image, MessageLevel::Error, "Could not capture screenshot"_s, WTFMove(arguments))); > return; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 199305
:
373086
|
374823
|
374835