FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
WebKit/Source/WebCore/workers/WorkerConsoleClient.cpp at main · WebKit/WebKit · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
WebKit
/
WebKit
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10.1k
Code
Pull requests
2.6k
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
WebKit
/
Source
/
WebCore
/
workers
/
WorkerConsoleClient.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
270 lines (234 loc) · 11.7 KB
Breadcrumbs
WebKit
/
Source
/
WebCore
/
workers
/
WorkerConsoleClient.cpp
Copy path
File metadata and controls
270 lines (234 loc) · 11.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
* Copyright (C) 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#
include
"
config.h
"
#
include
"
WorkerConsoleClient.h
"
#
include
"
ImageBitmap.h
"
#
include
"
ImageBitmapRenderingContext.h
"
#
include
"
ImageBuffer.h
"
#
include
"
ImageData.h
"
#
include
"
ImageUtilities.h
"
#
include
"
InspectorCanvas.h
"
#
include
"
InspectorInstrumentation.h
"
#
include
"
IntRect.h
"
#
include
"
JSDOMGlobalObject.h
"
#
include
"
JSGPUDevice.h
"
#
include
"
JSImageBitmap.h
"
#
include
"
JSImageBitmapRenderingContext.h
"
#
include
"
JSImageData.h
"
#
include
"
WorkerGlobalScope.h
"
#
include
<
JavaScriptCore/ConsoleMessage.h
>
#
include
<
JavaScriptCore/JSCInlines.h
>
#
include
<
JavaScriptCore/ScriptArguments.h
>
#
include
<
JavaScriptCore/ScriptCallStack.h
>
#
include
<
JavaScriptCore/ScriptCallStackFactory.h
>
#
include
<
JavaScriptCore/StrongInlines.h
>
#
include
<
wtf/TZoneMallocInlines.h
>
#
include
<
wtf/text/WTFString.h
>
#
if
ENABLE(OFFSCREEN_CANVAS)
#
include
"
JSOffscreenCanvas.h
"
#
include
"
JSOffscreenCanvasRenderingContext2D.h
"
#
include
"
OffscreenCanvas.h
"
#
include
"
OffscreenCanvasRenderingContext2D.h
"
#
endif
#
if
ENABLE(WEBGL)
#
include
"
JSWebGL2RenderingContext.h
"
#
include
"
JSWebGLRenderingContext.h
"
#
include
"
WebGL2RenderingContext.h
"
#
include
"
WebGLRenderingContext.h
"
#
endif
namespace
WebCore
{
using
namespace
Inspector
;
WTF_MAKE_TZONE_ALLOCATED_IMPL
(WorkerConsoleClient);
WorkerConsoleClient::WorkerConsoleClient
(WorkerOrWorkletGlobalScope& globalScope)
: m_globalScope(globalScope)
{
}
WorkerConsoleClient::~WorkerConsoleClient
() =
default
;
void
WorkerConsoleClient::messageWithTypeAndLevel
(MessageType type, MessageLevel level,
JSC
::JSGlobalObject* exec, Ref<Inspector::ScriptArguments>&& arguments)
{
String messageText;
arguments->
getFirstArgumentAsString
(messageText);
auto
message = makeUnique<Inspector::ConsoleMessage>(MessageSource::ConsoleAPI, type, level, messageText, arguments.
copyRef
(), exec);
auto
url = message->
url
();
auto
line = message->
line
();
auto
column = message->
column
();
protect
(m_globalScope.
get
())->
addConsoleMessage
(
WTF::move
(message));
auto
* domGlobalObject = dynamicDowncast<JSDOMGlobalObject>(exec);
if
(level == MessageLevel::Error && domGlobalObject && domGlobalObject->
hasScriptErrorCallbacks
())
domGlobalObject->
invokeScriptErrorCallbacks
(messageText, url, line, column);
}
void
WorkerConsoleClient::count
(
JSC
::JSGlobalObject* exec,
const
String& label)
{
//
FIXME: <https://webkit.org/b/217724> Add support for WorkletGlobalScope.
if
(RefPtr worker = dynamicDowncast<WorkerGlobalScope>(m_globalScope.
get
()))
InspectorInstrumentation::consoleCount
(*worker, exec, label);
}
void
WorkerConsoleClient::countReset
(
JSC
::JSGlobalObject* exec,
const
String& label)
{
//
FIXME: <https://webkit.org/b/217724> Add support for WorkletGlobalScope.
if
(RefPtr worker = dynamicDowncast<WorkerGlobalScope>(m_globalScope.
get
()))
InspectorInstrumentation::consoleCountReset
(*worker, exec, label);
}
void
WorkerConsoleClient::time
(
JSC
::JSGlobalObject* exec,
const
String& label)
{
//
FIXME: <https://webkit.org/b/217724> Add support for WorkletGlobalScope.
if
(RefPtr worker = dynamicDowncast<WorkerGlobalScope>(m_globalScope.
get
()))
InspectorInstrumentation::startConsoleTiming
(*worker, exec, label);
}
void
WorkerConsoleClient::timeLog
(
JSC
::JSGlobalObject* exec,
const
String& label, Ref<ScriptArguments>&& arguments)
{
//
FIXME: <https://webkit.org/b/217724> Add support for WorkletGlobalScope.
if
(RefPtr worker = dynamicDowncast<WorkerGlobalScope>(m_globalScope.
get
()))
InspectorInstrumentation::logConsoleTiming
(*worker, exec, label,
WTF::move
(arguments));
}
void
WorkerConsoleClient::timeEnd
(
JSC
::JSGlobalObject* exec,
const
String& label)
{
//
FIXME: <https://webkit.org/b/217724> Add support for WorkletGlobalScope.
if
(RefPtr worker = dynamicDowncast<WorkerGlobalScope>(m_globalScope.
get
()))
InspectorInstrumentation::stopConsoleTiming
(*worker, exec, label);
}
void
WorkerConsoleClient::profile
(
JSC
::JSGlobalObject*,
const
String& title)
{
//
FIXME: <https://webkit.org/b/217724> Add support for WorkletGlobalScope.
if
(RefPtr worker = dynamicDowncast<WorkerGlobalScope>(m_globalScope.
get
()))
InspectorInstrumentation::startProfiling
(*worker, title);
}
void
WorkerConsoleClient::profileEnd
(
JSC
::JSGlobalObject*,
const
String& title)
{
//
FIXME: <https://webkit.org/b/217724> Add support for WorkletGlobalScope.
if
(RefPtr worker = dynamicDowncast<WorkerGlobalScope>(m_globalScope.
get
()))
InspectorInstrumentation::stopProfiling
(*worker, title);
}
void
WorkerConsoleClient::takeHeapSnapshot
(
JSC
::JSGlobalObject*,
const
String& title)
{
//
FIXME: <https://webkit.org/b/217724> Add support for WorkletGlobalScope.
if
(RefPtr worker = dynamicDowncast<WorkerGlobalScope>(m_globalScope.
get
()))
InspectorInstrumentation::takeHeapSnapshot
(*worker, title);
}
void
WorkerConsoleClient::timeStamp
(
JSC
::JSGlobalObject*, Ref<ScriptArguments>&& arguments)
{
//
FIXME: <https://webkit.org/b/217724> Add support for WorkletGlobalScope.
if
(RefPtr worker = dynamicDowncast<WorkerGlobalScope>(m_globalScope.
get
()))
InspectorInstrumentation::consoleTimeStamp
(*worker,
WTF::move
(arguments));
}
static
JSC
::JSObject*
objectArgumentAt
(ScriptArguments& arguments,
unsigned
index)
{
return
arguments.
argumentCount
() > index ? arguments.
argumentAt
(index).
getObject
() :
nullptr
;
}
static
RefPtr<CanvasRenderingContext>
canvasRenderingContext
(
JSC
::
VM
& vm,
JSC
::JSValue target)
{
#
if
ENABLE(OFFSCREEN_CANVAS)
if
(RefPtr canvas =
JSOffscreenCanvas::toWrapped
(vm, target))
return
canvas->
renderingContext
();
if
(RefPtr context =
JSOffscreenCanvasRenderingContext2D::toWrapped
(vm, target))
return
context;
#
endif
if
(RefPtr context =
JSImageBitmapRenderingContext::toWrapped
(vm, target))
return
context;
#
if
ENABLE(WEBGL)
if
(RefPtr context =
JSWebGLRenderingContext::toWrapped
(vm, target))
return
context;
if
(RefPtr context =
JSWebGL2RenderingContext::toWrapped
(vm, target))
return
context;
#
endif
return
nullptr
;
}
void
WorkerConsoleClient::record
(
JSC
::JSGlobalObject* lexicalGlobalObject, Ref<ScriptArguments>&& arguments)
{
if
(!
InspectorInstrumentation::hasFrontends
())
[[likely]]
return
;
if
(
auto
* target =
objectArgumentAt
(arguments,
0
)) {
JSC
::
VM
& vm = lexicalGlobalObject->
vm
();
if
(RefPtr context =
canvasRenderingContext
(vm, target))
InspectorInstrumentation::consoleStartRecordingCanvas
(*context, *lexicalGlobalObject,
objectArgumentAt
(arguments,
1
));
else
if
(RefPtr device =
JSGPUDevice::toWrapped
(vm, target))
InspectorInstrumentation::consoleStartRecordingCanvas
(*device, *lexicalGlobalObject,
objectArgumentAt
(arguments,
1
));
}
}
void
WorkerConsoleClient::recordEnd
(
JSC
::JSGlobalObject* lexicalGlobalObject, Ref<ScriptArguments>&& arguments)
{
if
(!
InspectorInstrumentation::hasFrontends
())
[[likely]]
return
;
if
(
auto
* target =
objectArgumentAt
(arguments,
0
)) {
JSC
::
VM
& vm = lexicalGlobalObject->
vm
();
if
(RefPtr context =
canvasRenderingContext
(vm, target))
InspectorInstrumentation::consoleStopRecordingCanvas
(*context);
else
if
(RefPtr device =
JSGPUDevice::toWrapped
(vm, target))
InspectorInstrumentation::consoleStopRecordingCanvas
(*device);
}
}
void
WorkerConsoleClient::screenshot
(
JSC
::JSGlobalObject* lexicalGlobalObject, Ref<ScriptArguments>&& arguments)
{
//
FIXME: <https://webkit.org/b/217724> Add support for WorkletGlobalScope.
if
(!is<WorkerGlobalScope>(m_globalScope))
return
;
JSC
::
VM
& vm = lexicalGlobalObject->
vm
();
String dataURL;
JSC
::JSValue target;
auto
timestamp =
WallTime::now
();
if
(arguments->
argumentCount
()) {
auto
possibleTarget = arguments->
argumentAt
(
0
);
if
(RefPtr imageData =
JSImageData::toWrapped
(vm, possibleTarget)) {
target = possibleTarget;
if
(
InspectorInstrumentation::hasFrontends
())
[[unlikely]]
{
if
(RefPtr imageBuffer =
ImageBuffer::create
(imageData->
size
(), RenderingMode::Unaccelerated, RenderingPurpose::Unspecified,
/*
scale
*/
1
,
DestinationColorSpace::SRGB
(), PixelFormat::
BGRA8
)) {
imageBuffer->
putPixelBuffer
(imageData->
byteArrayPixelBuffer
().
get
(),
IntRect
(
IntPoint
(), imageData->
size
()));
dataURL =
encodeDataURL
(
WTF::move
(imageBuffer),
"
image/png
"
_s);
}
}
}
else
if
(RefPtr imageBitmap =
JSImageBitmap::toWrapped
(vm, possibleTarget)) {
target = possibleTarget;
if
(
InspectorInstrumentation::hasFrontends
())
[[unlikely]]
{
if
(RefPtr imageBuffer = imageBitmap->
buffer
())
dataURL =
encodeDataURL
(
WTF::move
(imageBuffer),
"
image/png
"
_s);
}
}
else
if
(RefPtr context =
canvasRenderingContext
(vm, possibleTarget)) {
target = possibleTarget;
if
(
InspectorInstrumentation::hasFrontends
())
[[unlikely]]
{
if
(
auto
result =
InspectorCanvas::getContentAsDataURL
(*context))
dataURL = result.
value
();
}
}
else
{
String base64;
if
(possibleTarget.
getString
(lexicalGlobalObject, base64) && base64.
length
() >
5
&&
startsWithLettersIgnoringASCIICase
(base64,
"
data:
"
_s)) {
target = possibleTarget;
dataURL = base64;
}
}
}
if
(
InspectorInstrumentation::hasFrontends
())
[[unlikely]]
{
if
(dataURL.
isEmpty
()) {
InspectorInstrumentation::addMessageToConsole
(
protect
(
globalScope
()), makeUnique<Inspector::ConsoleMessage>(MessageSource::ConsoleAPI, MessageType::Image, MessageLevel::Error,
"
Could not capture screenshot
"
_s,
WTF::move
(arguments)));
return
;
}
}
Vector<
JSC
::Strong<
JSC
::Unknown>> adjustedArguments;
adjustedArguments.
reserveInitialCapacity
(arguments->
argumentCount
() + !target);
adjustedArguments.
append
({ vm, target ? target :
JSC::jsNontrivialString
(vm,
"
Viewport
"
_s) });
for
(
size_t
i = (!target ?
0
:
1
); i < arguments->
argumentCount
(); ++i)
adjustedArguments.
append
({ vm, arguments->
argumentAt
(i) });
InspectorInstrumentation::addMessageToConsole
(
protect
(
globalScope
()), makeUnique<Inspector::ConsoleMessage>(MessageSource::ConsoleAPI, MessageType::Image, MessageLevel::Log, dataURL,
ScriptArguments::create
(lexicalGlobalObject,
WTF::move
(adjustedArguments)), lexicalGlobalObject,
/*
requestIdentifier
*/
0
, timestamp));
}
}
//
namespace WebCore
Back
|
FazBrowse Home
|
New Git URL