forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebinspector.ios.ts
More file actions
229 lines (190 loc) · 6.59 KB
/
webinspector.ios.ts
File metadata and controls
229 lines (190 loc) · 6.59 KB
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
import * as inspectorCommandTypes from "./InspectorBackendCommands.ios";
var inspectorCommands: typeof inspectorCommandTypes = require("./InspectorBackendCommands");
import * as debuggerDomains from "./debugger";
declare var __inspectorTimestamp;
const frameId = "NativeScriptMainFrameIdentifier";
const loaderId = "Loader Identifier";
var resources_datas = [];
var documentTypeByMimeType = {
"text/xml": "Document",
"text/plain": "Document",
"text/html": "Document",
"application/xml": "Document",
"application/xhtml+xml": "Document",
"text/css": "Stylesheet",
"text/javascript": "Script",
"text/ecmascript": "Script",
"application/javascript": "Script",
"application/ecmascript": "Script",
"application/x-javascript": "Script",
"application/json": "Script",
"application/x-json": "Script",
"text/x-javascript": "Script",
"text/x-json": "Script",
"text/typescript": "Script"
}
export class Request {
private _resourceType: string;
private _data: any;
private _mimeType: string;
constructor(private _networkDomainDebugger: NetworkDomainDebugger, private _requestID: string) {
}
get mimeType(): string {
return this._mimeType;
}
set mimeType(value: string) {
if (this._mimeType !== value) {
this._mimeType = value;
var resourceType = "Other";
if (this._mimeType in documentTypeByMimeType) {
resourceType = documentTypeByMimeType[this._mimeType];
}
if(this._mimeType.indexOf("image/") !== -1) {
resourceType = "Image";
}
if (this._mimeType.indexOf("font/") !== -1) {
resourceType = "Font";
}
this._resourceType = resourceType;
}
}
get requestID(): string {
return this._requestID;
}
get hasTextContent(): boolean {
return [ "Document", "Stylesheet", "Script", "XHR" ].indexOf(this._resourceType) !== -1;
}
get data(): any {
return this._data;
}
set data(value: any) {
if (this._data !== value) {
this._data = value;
}
}
get resourceType() {
return this._resourceType;
}
set resourceType(value: string) {
if (this._resourceType !== value) {
this._resourceType = value;
}
}
public responseReceived(response: inspectorCommandTypes.NetworkDomain.Response): void {
if (this._networkDomainDebugger.enabled) {
this._networkDomainDebugger.events.responseReceived(this.requestID, frameId, loaderId, __inspectorTimestamp(), <any>this.resourceType, response);
}
}
public loadingFinished(): void {
if (this._networkDomainDebugger.enabled) {
this._networkDomainDebugger.events.loadingFinished(this.requestID, __inspectorTimestamp());
}
}
public requestWillBeSent(request: inspectorCommandTypes.NetworkDomain.Request): void {
if (this._networkDomainDebugger.enabled) {
this._networkDomainDebugger.events.requestWillBeSent(this.requestID, frameId, loaderId, request.url, request, __inspectorTimestamp(), { type: 'Script' });
}
}
}
@inspectorCommands.DomainDispatcher("Network")
export class NetworkDomainDebugger implements inspectorCommandTypes.NetworkDomain.NetworkDomainDispatcher {
private _enabled: boolean;
public events: inspectorCommandTypes.NetworkDomain.NetworkFrontend;
constructor(dispatchMessage: (message: String) => void) {
this.events = new inspectorCommands.NetworkDomain.NetworkFrontend(dispatchMessage);
}
get enabled(): boolean {
return this._enabled;
}
/**
* Enables network tracking, network events will now be delivered to the client.
*/
enable(): void {
if (debuggerDomains.network) {
throw new Error("One NetworkDomainDebugger may be enabled at a time.");
} else {
debuggerDomains.network = this;
}
this._enabled = true;
}
/**
* Disables network tracking, prevents network events from being sent to the client.
*/
disable(): void {
if (debuggerDomains.network === this) {
debuggerDomains.network = null;
}
this._enabled = false;
}
/**
* Specifies whether to always send extra HTTP headers with the requests from this page.
*/
setExtraHTTPHeaders(params: inspectorCommandTypes.NetworkDomain.SetExtraHTTPHeadersMethodArguments): void {
//
}
/**
* Returns content served for the given request.
*/
getResponseBody(params: inspectorCommandTypes.NetworkDomain.GetResponseBodyMethodArguments): { body: string, base64Encoded: boolean } {
var resource_data = resources_datas[params.requestId];
var body = resource_data.hasTextContent ? NSString.alloc().initWithDataEncoding(resource_data.data, 4).toString() :
resource_data.data.base64EncodedStringWithOptions(0);
if(resource_data) {
return {
body: body,
base64Encoded: !resource_data.hasTextContent
};
}
}
/**
* Tells whether clearing browser cache is supported.
*/
canClearBrowserCache(): { result: boolean } {
return {
result: false
};
}
/**
* Clears browser cache.
*/
clearBrowserCache(): void {
//
}
/**
* Tells whether clearing browser cookies is supported.
*/
canClearBrowserCookies(): { result: boolean } {
return {
result: false
};
}
/**
* Clears browser cookies.
*/
clearBrowserCookies(): void {
//
}
/**
* Toggles ignoring cache for each request. If <code>true</code>, cache will not be used.
*/
setCacheDisabled(params: inspectorCommandTypes.NetworkDomain.SetCacheDisabledMethodArguments): void {
//
}
/**
* Loads a resource in the context of a frame on the inspected page without cross origin checks.
*/
loadResource(params: inspectorCommandTypes.NetworkDomain.LoadResourceMethodArguments): { content: string, mimeType: string, status: number } {
return {
content: "",
mimeType: "",
status: 200
}
}
public static idSequence: number = 0;
create(): Request {
let id = (++NetworkDomainDebugger.idSequence).toString();
let resourceData = new Request(this, id);
resources_datas[id] = resourceData;
return resourceData;
}
}