-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRemoteTypes.cs
279 lines (228 loc) · 7.71 KB
/
RemoteTypes.cs
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
271
272
273
274
275
276
277
278
279
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading.Tasks;
namespace crdebug.RemoteTypes {
public struct PageLoadEventArgs {
public object timestamp;
}
public struct NavigateResult {
public string frameId;
public string errorText;
}
public struct NodeId {
public int? nodeId;
public int? backendNodeId;
public NodeId (int? nodeId, int? backendNodeId) {
this.nodeId = nodeId;
this.backendNodeId = backendNodeId;
}
public static implicit operator bool (NodeId id) {
return ((id.nodeId ?? 0) != 0) || ((id.backendNodeId ?? 0) != 0);
}
}
public class Node {
internal int depth;
public int nodeId;
public int? backendNodeId;
public int? parentId;
public NodeId Id {
get {
return new NodeId(nodeId, backendNodeId);
}
}
public NodeId? ParentId {
get {
if (parentId.HasValue)
return new NodeId(parentId.Value, null);
return null;
}
}
public string nodeName, localName, nodeValue;
public string publicId, systemId, name, value;
public int childNodeCount;
public Node[] children;
public string[] attributes;
public IEnumerable<KeyValuePair<string, string>> Attributes {
get {
if (attributes == null)
yield break;
for (int i = 0, n = attributes.Length; i < n; i += 2)
yield return new KeyValuePair<string, string>(attributes[i], attributes[i + 1]);
}
}
public override string ToString () {
return $"{nodeName} #{nodeId}";
}
public string GetAttribute (string name) {
return Attributes.FirstOrDefault(a => string.Equals(a.Key, name, StringComparison.OrdinalIgnoreCase)).Value;
}
}
public struct BoxModel {
public NodeId Id;
public int[] content, padding, border, margin;
public int width, height;
internal ExceptionDispatchInfo Exception;
public int ContentLeft {
get {
if (!Id)
return 0;
if (Exception != null)
Exception.Throw();
return content[0];
}
}
public int ContentTop {
get {
if (!Id)
return 0;
if (Exception != null)
Exception.Throw();
return content[1];
}
}
public int ContentRight {
get {
if (!Id)
return 0;
if (Exception != null)
Exception.Throw();
return content[2];
}
}
public int ContentBottom {
get {
if (!Id)
return 0;
if (Exception != null)
Exception.Throw();
return content[5];
}
}
public static implicit operator bool (BoxModel model) {
return (model.Id.nodeId != 0) && (model.content != null) && (model.content.Length >= 6) && (model.Exception == null);
}
}
public class PropertyDescriptor : IDisposable {
public string name;
public bool configurable, enumerable, wasThrown, isOwn, writable;
public RemoteObject value, get, set, symbol;
public void Dispose () {
value?.Dispose();
get?.Dispose();
set?.Dispose();
symbol?.Dispose();
}
}
public class RemoteObjectGroup : IDisposable {
public bool IsDisposed { get; internal set; }
public DebugClient Client { get; internal set; }
public string objectGroup;
public RemoteObjectGroup (DebugClient client, string objectGroup) {
Client = client;
this.objectGroup = objectGroup;
}
public void Dispose () {
if (IsDisposed)
return;
if (Client == null)
return;
IsDisposed = true;
Client.QueueSend("Runtime.releaseObjectGroup", new { objectGroup });
}
}
public class RemoteObject : IDisposable {
public bool IsDisposed { get; internal set; }
public DebugClient Client { get; internal set; }
public RemoteObjectGroup Group;
public string type, subtype, className, description, unserializableValue, objectId;
public object value;
public void Dispose () {
// Not necessary to dispose primitive types, probably
if (type != "object")
return;
if (Group != null) {
Group.Dispose();
return;
}
if (IsDisposed)
return;
if (objectId == null) {
IsDisposed = true;
return;
}
if (Client == null)
return;
IsDisposed = true;
Client.QueueSend("Runtime.releaseObject", new { objectId });
}
public override string ToString () {
switch (type) {
case "string":
return $"string '{value.ToString()}'";
default:
return $"remote {className}";
}
}
}
public class ExceptionDetails {
public int exceptionId, lineNumber, columnNumber;
public string text, url;
public RemoteObject exception;
}
public class Frame {
public string id, parentId, loaderId, name, url, securityOrigin, mimeType, unreachableUrl;
}
public class Request {
public string requestId, frameId;
public string url, urlFragment, method, postData, referrerPolicy;
public bool hasPostData, isLinkPreload;
public RemoteObject headers;
public Frame Frame;
}
public class Response {
public string requestId;
public string url, statusText, headersText, mimeType, requestHeadersText, remoteIPAddress, protocol;
public bool connectionReused, fromDiskCache, fromServiceWorker, fromPrefetchCache;
public int status, remotePort;
public RemoteObject headers, requestHeaders;
public Request Request;
}
public class TabInfo {
public string description;
public string devtoolsFrontendUrl;
public string id;
public string title;
public string type;
public string url;
public string websocketDebuggerUrl;
}
public struct DOMRect {
public double x, y, width, height;
}
public struct LayoutMetrics {
public struct LayoutViewport {
public int pageX, pageY;
public int clientWidth, clientHeight;
}
public struct VisualViewport {
public double offsetX, offsetY;
public double pageX, pageY;
public double clientWidth, clientHeight;
public double scale, zoom;
}
public LayoutViewport layoutViewport;
public VisualViewport visualViewport;
public DOMRect contentSize;
// HACK: You basically are guaranteed to need this because it's not encoded in any of
// the above structures.
public double devicePixelRatio;
}
public class ScreencastFrameMetadata {
public double offsetTop, pageScaleFactor;
public double deviceWidth, deviceHeight;
public double scrollOffsetX, scrollOffsetY;
};
}