1+ import * as inspectorCommandTypes from "./InspectorBackendCommands.ios" ;
2+ var inspectorCommands : typeof inspectorCommandTypes = require ( "./InspectorBackendCommands" ) ;
3+
4+ import * as debuggerDomains from "./debugger" ;
5+
6+ declare var __inspectorTimestamp ;
7+
8+ const frameId = "NativeScriptMainFrameIdentifier" ;
9+ const loaderId = "Loader Identifier" ;
10+
11+ var resources_datas = [ ] ;
12+
13+ var documentTypeByMimeType = {
14+ "text/xml" : "Document" ,
15+ "text/plain" : "Document" ,
16+ "text/html" : "Document" ,
17+ "application/xml" : "Document" ,
18+ "application/xhtml+xml" : "Document" ,
19+ "text/css" : "Stylesheet" ,
20+ "text/javascript" : "Script" ,
21+ "text/ecmascript" : "Script" ,
22+ "application/javascript" : "Script" ,
23+ "application/ecmascript" : "Script" ,
24+ "application/x-javascript" : "Script" ,
25+ "application/json" : "Script" ,
26+ "application/x-json" : "Script" ,
27+ "text/x-javascript" : "Script" ,
28+ "text/x-json" : "Script" ,
29+ "text/typescript" : "Script"
30+ }
31+
32+ export class Request {
33+
34+ private _resourceType : string ;
35+ private _data : any ;
36+ private _mimeType : string ;
37+
38+ constructor ( private _networkDomainDebugger : NetworkDomainDebugger , private _requestID : string ) {
39+ }
40+
41+ get mimeType ( ) : string {
42+ return this . _mimeType ;
43+ }
44+
45+ set mimeType ( value : string ) {
46+ if ( this . _mimeType !== value ) {
47+ this . _mimeType = value ;
48+
49+ var resourceType = "Other" ;
50+
51+ if ( this . _mimeType in documentTypeByMimeType ) {
52+ resourceType = documentTypeByMimeType [ this . _mimeType ] ;
53+ }
54+
55+ if ( this . _mimeType . indexOf ( "image/" ) !== - 1 ) {
56+ resourceType = "Image" ;
57+ }
58+
59+ if ( this . _mimeType . indexOf ( "font/" ) !== - 1 ) {
60+ resourceType = "Font" ;
61+ }
62+
63+ this . _resourceType = resourceType ;
64+ }
65+ }
66+
67+ get requestID ( ) : string {
68+ return this . _requestID ;
69+ }
70+
71+ get hasTextContent ( ) : boolean {
72+ return [ "Document" , "Stylesheet" , "Script" , "XHR" ] . indexOf ( this . _resourceType ) !== - 1 ;
73+ }
74+
75+ get data ( ) : any {
76+ return this . _data ;
77+ }
78+
79+ set data ( value : any ) {
80+ if ( this . _data !== value ) {
81+ this . _data = value ;
82+ }
83+ }
84+
85+ get resourceType ( ) {
86+ return this . _resourceType ;
87+ }
88+
89+ set resourceType ( value : string ) {
90+ if ( this . _resourceType !== value ) {
91+ this . _resourceType = value ;
92+ }
93+ }
94+
95+ public responseReceived ( response : inspectorCommandTypes . NetworkDomain . Response ) : void {
96+ if ( this . _networkDomainDebugger . enabled ) {
97+ this . _networkDomainDebugger . events . responseReceived ( this . requestID , frameId , loaderId , __inspectorTimestamp ( ) , < any > this . resourceType , response ) ;
98+ }
99+ }
100+
101+ public loadingFinished ( ) : void {
102+ if ( this . _networkDomainDebugger . enabled ) {
103+ this . _networkDomainDebugger . events . loadingFinished ( this . requestID , __inspectorTimestamp ( ) ) ;
104+ }
105+ }
106+
107+ public requestWillBeSent ( request : inspectorCommandTypes . NetworkDomain . Request ) : void {
108+ if ( this . _networkDomainDebugger . enabled ) {
109+ this . _networkDomainDebugger . events . requestWillBeSent ( this . requestID , frameId , loaderId , request . url , request , __inspectorTimestamp ( ) , { type : 'Script' } ) ;
110+ }
111+ }
112+ }
113+
114+ @inspectorCommands . DomainDispatcher ( "Network" )
115+ export class NetworkDomainDebugger implements inspectorCommandTypes . NetworkDomain . NetworkDomainDispatcher {
116+ private _enabled : boolean ;
117+ public events : inspectorCommandTypes . NetworkDomain . NetworkFrontend ;
118+
119+ constructor ( dispatchMessage : ( message : String ) => void ) {
120+ this . events = new inspectorCommands . NetworkDomain . NetworkFrontend ( dispatchMessage ) ;
121+ }
122+
123+ get enabled ( ) : boolean {
124+ return this . _enabled ;
125+ }
126+
127+ /**
128+ * Enables network tracking, network events will now be delivered to the client.
129+ */
130+ enable ( ) : void {
131+ if ( debuggerDomains . network ) {
132+ throw new Error ( "One NetworkDomainDebugger may be enabled at a time." ) ;
133+ } else {
134+ debuggerDomains . network = this ;
135+ }
136+ this . _enabled = true ;
137+ }
138+
139+ /**
140+ * Disables network tracking, prevents network events from being sent to the client.
141+ */
142+ disable ( ) : void {
143+ if ( debuggerDomains . network === this ) {
144+ debuggerDomains . network = null ;
145+ }
146+ this . _enabled = false ;
147+ }
148+
149+ /**
150+ * Specifies whether to always send extra HTTP headers with the requests from this page.
151+ */
152+ setExtraHTTPHeaders ( params : inspectorCommandTypes . NetworkDomain . SetExtraHTTPHeadersMethodArguments ) : void {
153+ //
154+ }
155+
156+ /**
157+ * Returns content served for the given request.
158+ */
159+ getResponseBody ( params : inspectorCommandTypes . NetworkDomain . GetResponseBodyMethodArguments ) : { body : string , base64Encoded : boolean } {
160+ var resource_data = resources_datas [ params . requestId ] ;
161+ var body = resource_data . hasTextContent ? NSString . alloc ( ) . initWithDataEncoding ( resource_data . data , 4 ) . toString ( ) :
162+ resource_data . data . base64EncodedStringWithOptions ( 0 ) ;
163+
164+ if ( resource_data ) {
165+ return {
166+ body : body ,
167+ base64Encoded : ! resource_data . hasTextContent
168+ } ;
169+ }
170+ }
171+
172+ /**
173+ * Tells whether clearing browser cache is supported.
174+ */
175+ canClearBrowserCache ( ) : { result : boolean } {
176+ return {
177+ result : false
178+ } ;
179+ }
180+
181+ /**
182+ * Clears browser cache.
183+ */
184+ clearBrowserCache ( ) : void {
185+ //
186+ }
187+
188+ /**
189+ * Tells whether clearing browser cookies is supported.
190+ */
191+ canClearBrowserCookies ( ) : { result : boolean } {
192+ return {
193+ result : false
194+ } ;
195+ }
196+
197+ /**
198+ * Clears browser cookies.
199+ */
200+ clearBrowserCookies ( ) : void {
201+ //
202+ }
203+
204+ /**
205+ * Toggles ignoring cache for each request. If <code>true</code>, cache will not be used.
206+ */
207+ setCacheDisabled ( params : inspectorCommandTypes . NetworkDomain . SetCacheDisabledMethodArguments ) : void {
208+ //
209+ }
210+
211+ /**
212+ * Loads a resource in the context of a frame on the inspected page without cross origin checks.
213+ */
214+ loadResource ( params : inspectorCommandTypes . NetworkDomain . LoadResourceMethodArguments ) : { content : string , mimeType : string , status : number } {
215+ return {
216+ content : "" ,
217+ mimeType : "" ,
218+ status : 200
219+ }
220+ }
221+
222+ public static idSequence : number = 0 ;
223+ create ( ) : Request {
224+ let id = ( ++ NetworkDomainDebugger . idSequence ) . toString ( ) ;
225+ let resourceData = new Request ( this , id ) ;
226+ resources_datas [ id ] = resourceData ;
227+ return resourceData ;
228+ }
229+ }
0 commit comments