11"use strict" ;
22
33window . templates || ( window . templates = { } ) ;
4+ window . templates . network || ( window . templates . network = { } ) ;
45
56( function ( templates ) {
67
7- templates . network_detail_row = function ( wrap )
8+ templates . _detail_row = function ( wrap )
89{
910 return [ "tr" , [ "td" , wrap , "colspan" , "2" ] ] ;
1011} ;
1112
12- templates . network_log_details = function ( entry , left_val )
13+ templates . details = function ( entry , left_val )
1314{
14- return [
15- "div" ,
15+ return (
16+ [ "div" ,
17+ [ "span" ,
1618 [ "span" ,
17- [ "span" ,
18- "class" , "close-request-detail" ,
19- "handler" , "close-request-detail" ,
20- "tabindex" , "1"
21- ] ,
22- "class" , "resize-request-detail" ,
23- "handler" , "resize-request-detail"
19+ "class" , "close-request-detail" ,
20+ "handler" , "close-request-detail" ,
21+ "tabindex" , "1"
2422 ] ,
25- templates . network_log_detail ( entry ) ,
26- "class" , "network-details-container" ,
27- "style" , "left:" + left_val + "px"
28- ] ;
23+ "class" , "resize-request-detail" ,
24+ "handler" , "resize-request-detail"
25+ ] ,
26+ templates . _detail ( entry ) ,
27+ "class" , "network-details-container" ,
28+ "style" , "left:" + left_val + "px"
29+ ] ) ;
2930} ;
3031
31- templates . network_log_detail = function ( entry )
32+ templates . _detail = function ( entry )
3233{
3334 var responsecode = entry . last_responsecode ;
3435 if ( responsecode && responsecode in cls . ResourceUtil . http_status_codes )
@@ -67,7 +68,7 @@ templates.did_not_touch_network = function(entry)
6768{
6869 var data = cls . ResourceManager [ "1.2" ] . UrlLoad . URLType . DATA ;
6970 return [ "tbody" ,
70- templates . network_detail_row ( // it would be kind of conistent to put this into a headline, as these otherwise say "Request", and it's clear they are not content. // ["h2",
71+ templates . _detail_row ( // it would be kind of conistent to put this into a headline, as these otherwise say "Request", and it's clear they are not content. // ["h2",
7172 entry . urltype === data ? ui_strings . S_NETWORK_NOT_REQUESTED
7273 : ui_strings . S_NETWORK_SERVED_FROM_CACHE )
7374 ] ;
@@ -76,33 +77,41 @@ templates.did_not_touch_network = function(entry)
7677templates . requests_responses = function ( request_response , index , requests_responses )
7778{
7879 var is_last = index == requests_responses . length - 1 ;
79- return request_response instanceof cls . NetworkLoggerRequest ?
80- ( [ templates . request_details ( request_response ) , templates . network_request_body ( request_response ) ] ) : templates . network_response ( request_response , is_last )
81- // todo: clean it up and make request one template like response.
80+ var template_func = templates . _response ;
81+ if ( request_response instanceof cls . NetworkLoggerRequest )
82+ template_func = templates . _request ;
83+
84+ return template_func ( request_response , is_last ) ;
85+ } ;
86+
87+ templates . _request = function ( request , is_last )
88+ {
89+ return [
90+ templates . _request_headers ( request ) ,
91+ templates . _request_body ( request )
92+ ]
8293} ;
8394
84- templates . network_response = function ( response , is_last )
95+ templates . _response = function ( response , is_last )
8596{
8697 return [
87- response . logger_entry_touched_network ?
88- templates . network_detail_row ( [ "h2" , ui_strings . S_NETWORK_REQUEST_DETAIL_RESPONSE_TITLE ] ) : [ ] ,
89- templates . response_details ( response ) ,
90- templates . network_response_body ( response , is_last )
98+ templates . _response_headers ( response ) ,
99+ templates . _response_body ( response , is_last )
91100 ]
92101} ;
93102
94- templates . request_details = function ( req )
103+ templates . _request_headers = function ( req )
95104{
96105 var tbody = [ "tbody" ] ;
97106
98107 if ( req . requestbody && req . requestbody . partList && req . requestbody . partList . length )
99- tbody . push ( templates . network_detail_row ( [ "h2" , ui_strings . S_NETWORK_MULTIPART_REQUEST_TITLE ] ) ) ;
108+ tbody . push ( templates . _detail_row ( [ "h2" , ui_strings . S_NETWORK_MULTIPART_REQUEST_TITLE ] ) ) ;
100109 else
101- tbody . push ( templates . network_detail_row ( [ "h2" , ui_strings . S_NETWORK_REQUEST_DETAIL_REQUEST_TITLE ] ) ) ;
110+ tbody . push ( templates . _detail_row ( [ "h2" , ui_strings . S_NETWORK_REQUEST_DETAIL_REQUEST_TITLE ] ) ) ;
102111
103112 if ( ! req . request_headers )
104113 {
105- tbody . push ( templates . network_detail_row ( ui_strings . S_NETWORK_REQUEST_NO_HEADERS_LABEL ) ) ;
114+ tbody . push ( templates . _detail_row ( ui_strings . S_NETWORK_REQUEST_NO_HEADERS_LABEL ) ) ;
106115 }
107116 else
108117 {
@@ -118,17 +127,19 @@ templates.request_details = function(req)
118127 [ "span" , parts [ 2 ] + " " ]
119128 ] ;
120129 }
121- tbody . extend ( templates . network_headers_list ( req . request_headers , firstline ) ) ;
130+ tbody . extend ( templates . headers_list ( req . request_headers , firstline ) ) ;
122131 }
123132 }
124133 return tbody ;
125134} ;
126135
127- templates . response_details = function ( resp )
136+ templates . _response_headers = function ( resp )
128137{
129- if ( ! resp . response_headers )
138+ if ( ! resp . response_headers ) // todo: we explicitely mention missing request headers but not missing response headers // ui_strings.S_NETWORK_REQUEST_NO_HEADERS_LABEL
130139 return [ ] ;
131140
141+ var tbody = [ "tbody" ] ;
142+
132143 var firstline ;
133144 var parts = resp . firstline . split ( " " , 2 ) ;
134145 if ( parts . length == 2 )
@@ -139,10 +150,15 @@ templates.response_details = function(resp)
139150 [ "span" , resp . firstline . slice ( parts [ 0 ] . length + parts [ 1 ] . length + 1 ) ]
140151 ] ;
141152 }
142- return [ "tbody" , templates . network_headers_list ( resp . response_headers , firstline ) ] ;
153+
154+ if ( resp . logger_entry_touched_network )
155+ tbody . push ( templates . _detail_row ( [ "h2" , ui_strings . S_NETWORK_REQUEST_DETAIL_RESPONSE_TITLE ] ) ) ;
156+
157+ tbody . push ( templates . headers_list ( resp . response_headers , firstline ) ) ;
158+ return tbody ;
143159} ;
144160
145- templates . network_headers_list = function ( headers , firstline )
161+ templates . headers_list = function ( headers , firstline )
146162{
147163 var lis = headers . map ( function ( header ) {
148164 return [ "tr" , [ "th" , header . name + ":" ] , [ "td" , header . value ] , "data-spec" , "http#" + header . name ] ;
@@ -155,12 +171,12 @@ templates.network_headers_list = function(headers, firstline)
155171 return lis ;
156172} ;
157173
158- templates . network_body_seperator = function ( )
174+ templates . body_seperator = function ( )
159175{
160176 return [ "pre" , " " , "class" , "mono" ] ;
161177} ;
162178
163- templates . network_request_body = function ( req )
179+ templates . _request_body = function ( req )
164180{
165181 if ( ! req . requestbody )
166182 {
@@ -173,14 +189,14 @@ templates.network_request_body = function(req)
173189 {
174190 for ( var n = 0 , part ; part = req . requestbody . partList [ n ] ; n ++ )
175191 {
176- cont . push ( templates . network_headers_list ( part . headerList ) ) ;
192+ cont . push ( templates . headers_list ( part . headerList ) ) ;
177193 if ( part . content && part . content . stringData )
178- cont . push ( templates . network_detail_row ( [ "pre" , part . content . stringData ] ) ) ;
194+ cont . push ( templates . _detail_row ( [ "pre" , part . content . stringData ] ) ) ;
179195 else
180- cont . push ( templates . network_detail_row ( [ "pre" , ui_strings . S_NETWORK_N_BYTE_BODY . replace ( "%s" , part . contentLength ) ] ) ) ;
196+ cont . push ( templates . _detail_row ( [ "pre" , ui_strings . S_NETWORK_N_BYTE_BODY . replace ( "%s" , part . contentLength ) ] ) ) ;
181197
182198 if ( n < req . requestbody . partList . length - 1 )
183- cont . push ( templates . network_detail_row ( [ "hr" ] ) ) ;
199+ cont . push ( templates . _detail_row ( [ "hr" ] ) ) ;
184200 }
185201 }
186202 else if ( req . requestbody . mimeType . startswith ( "application/x-www-form-urlencoded" ) )
@@ -233,21 +249,21 @@ templates.network_request_body = function(req)
233249 }
234250
235251 return [
236- templates . network_detail_row ( templates . network_body_seperator ( ) ) ,
252+ templates . _detail_row ( templates . body_seperator ( ) ) ,
237253 [ "tbody" , cont ]
238254 ] ;
239255} ;
240256
241257
242- templates . network_response_body = function ( resp , is_last )
258+ templates . _response_body = function ( resp , is_last )
243259{
244- var ret = [ templates . network_detail_row ( templates . network_body_seperator ( ) ) ] ;
260+ var ret = [ templates . _detail_row ( templates . body_seperator ( ) ) ] ;
245261 var classname = "" ;
246262 if ( resp . body_unavailable ||
247263 ! resp . responsebody && resp . is_unloaded )
248264 {
249265 classname = "network_info" ;
250- ret . push ( templates . network_detail_row ( ui_strings . S_NETWORK_REQUEST_DETAIL_NO_RESPONSE_BODY ) ) ;
266+ ret . push ( templates . _detail_row ( ui_strings . S_NETWORK_REQUEST_DETAIL_NO_RESPONSE_BODY ) ) ;
251267 }
252268 else
253269 {
@@ -256,7 +272,7 @@ templates.network_response_body = function(resp, is_last)
256272 if ( is_last && ! resp . logger_entry_is_finished )
257273 {
258274 classname = "network_info" ;
259- ret . push ( templates . network_detail_row ( ui_strings . S_NETWORK_REQUEST_DETAIL_BODY_UNFINISHED ) ) ;
275+ ret . push ( templates . _detail_row ( ui_strings . S_NETWORK_REQUEST_DETAIL_BODY_UNFINISHED ) ) ;
260276 }
261277 // else we're in the middle of getting it via GetResource, or there is in fact no responsebody.
262278 }
@@ -265,23 +281,23 @@ templates.network_response_body = function(resp, is_last)
265281 if ( [ "script" , "markup" , "css" , "text" ] . contains ( resp . logger_entry_type ) )
266282 {
267283 ret . push (
268- templates . network_detail_row (
284+ templates . _detail_row (
269285 [ "pre" , resp . responsebody . content . stringData , "class" , "network-body mono" ]
270286 )
271287 ) ;
272288 }
273289 else if ( resp . logger_entry_type == "image" )
274290 {
275291 ret . push (
276- templates . network_detail_row (
292+ templates . _detail_row (
277293 [ "img" , "src" , resp . responsebody . content . stringData , "class" , "network-body" ]
278294 )
279295 ) ;
280296 }
281297 else
282298 {
283299 ret . push (
284- templates . network_detail_row (
300+ templates . _detail_row (
285301 [ "span" , ui_strings . S_NETWORK_REQUEST_DETAIL_UNDISPLAYABLE_BODY_LABEL . replace ( "%s" , resp . logger_entry_mime ) ,
286302 "class" , "network-body" ]
287303 )
@@ -292,4 +308,4 @@ templates.network_response_body = function(resp, is_last)
292308 return [ "tbody" , ret , "class" , classname ] ;
293309} ;
294310
295- } ) ( window . templates ) ;
311+ } ) ( window . templates . network ) ;
0 commit comments