Skip to content

Commit f4c6db8

Browse files
author
Daniel Herzog
committed
Fixed bug where GetResource was called more than once for a ResourceID, could cause infinite updates of a view; Some renaming and refactoring
1 parent 9067ec9 commit f4c6db8

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

src/network/network_details_templates.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ templates.details = function(entry, left_val, do_raw)
3535
"handler", "resize-request-detail"
3636
],
3737
["div",
38-
templates._details_content(entry, do_raw),
38+
this._details_content(entry, do_raw),
3939
"data-object-id", String(entry.id),
4040
"class", "entry-details"
4141
],
@@ -46,13 +46,13 @@ templates.details = function(entry, left_val, do_raw)
4646

4747
templates._details_content = function(entry, do_raw)
4848
{
49-
var responsecode = entry.last_responsecode;
49+
var responsecode = entry.current_responsecode;
5050
if (responsecode && responsecode in cls.ResourceUtil.http_status_codes)
5151
responsecode = responsecode + " " + cls.ResourceUtil.http_status_codes[responsecode];
5252

5353
// todo: not really pretty
5454
if (!this["_requests_responses_" + do_raw])
55-
this["_requests_responses_" + do_raw] = templates.requests_responses.bind(this, do_raw);
55+
this["_requests_responses_" + do_raw] = this.requests_responses.bind(this, do_raw);
5656

5757
var requests_responses = entry.requests_responses.map(this["_requests_responses_" + do_raw])
5858

@@ -77,10 +77,10 @@ templates._details_content = function(entry, do_raw)
7777
["td",
7878
entry.touched_network && responsecode ? String(responsecode) : ui_strings.S_RESOURCE_ALL_NOT_APPLICABLE
7979
],
80-
"data-spec", "http#" + entry.last_responsecode
80+
"data-spec", "http#" + entry.current_responsecode
8181
]
8282
],
83-
entry.touched_network ? [] : templates.did_not_touch_network(entry),
83+
entry.touched_network ? [] : this.did_not_touch_network(entry),
8484
requests_responses
8585
]
8686
);
@@ -91,7 +91,7 @@ templates.did_not_touch_network = function(entry)
9191
var data = cls.ResourceManager["1.2"].UrlLoad.URLType.DATA;
9292
return (
9393
["tbody",
94-
templates._wrap_col_or_row( // Todo: Alternatively put into a headline, as these otherwise say "Request" here.
94+
this._wrap_col_or_row( // Todo: Alternatively put into a headline, as these otherwise say "Request" here.
9595
["p", entry.urltype === data ? ui_strings.S_NETWORK_NOT_REQUESTED
9696
: ui_strings.S_NETWORK_SERVED_FROM_CACHE])
9797
]);
@@ -100,11 +100,11 @@ templates.did_not_touch_network = function(entry)
100100
templates.requests_responses = function(do_raw, request_response, index, requests_responses)
101101
{
102102
var is_last = index == requests_responses.length - 1;
103-
var template_func = templates._response;
103+
var template_func = this._response;
104104
if (request_response instanceof cls.NetworkLoggerRequest)
105-
template_func = templates._request;
105+
template_func = this._request;
106106

107-
return template_func(request_response, is_last, do_raw);
107+
return template_func.call(this, request_response, is_last, do_raw);
108108
};
109109

110110
templates._request = function(request, is_last, do_raw)
@@ -118,8 +118,8 @@ templates._request = function(request, is_last, do_raw)
118118
templates._response = function(response, is_last, do_raw)
119119
{
120120
return [
121-
templates._response_headers(response, do_raw),
122-
templates._response_body(response, do_raw, is_last)
121+
this._response_headers(response, do_raw),
122+
this._response_body(response, do_raw, is_last)
123123
]
124124
};
125125

@@ -174,12 +174,12 @@ templates._request_headers = function(req, do_raw)
174174
{
175175
var tokens = [];
176176
var tokenizer = new cls.HTTPHeaderTokenizer();
177-
tokenizer.tokenize(req.request_headers_raw, templates._token_receiver.bind(this, tokens));
177+
tokenizer.tokenize(req.request_headers_raw, this._token_receiver.bind(this, tokens));
178178
req.header_tokens = tokens;
179179
}
180180
if (req.header_tokens.length)
181181
{
182-
var map_func = templates._make_header_template_func(true);
182+
var map_func = this._make_header_template_func(true);
183183
return [
184184
["h2", ui_strings.S_NETWORK_REQUEST_DETAIL_REQUEST_TITLE],
185185
["pre", req.header_tokens.map(map_func), "class", "mono"]
@@ -214,10 +214,10 @@ templates._request_headers = function(req, do_raw)
214214
["span", parts[2] + " "]
215215
];
216216
}
217-
ret.extend(templates.headers_list(req.request_headers, firstline));
217+
ret.extend(this.headers_list(req.request_headers, firstline));
218218
}
219219
}
220-
return ["tbody", ret.map(templates._wrap_col_or_row)];
220+
return ["tbody", ret.map(this._wrap_col_or_row)];
221221
};
222222

223223
templates._response_headers = function(resp, do_raw)
@@ -231,12 +231,12 @@ templates._response_headers = function(resp, do_raw)
231231
{
232232
var tokens = [];
233233
var tokenizer = new cls.HTTPHeaderTokenizer();
234-
tokenizer.tokenize(resp.response_headers_raw, templates._token_receiver.bind(this, tokens));
234+
tokenizer.tokenize(resp.response_headers_raw, this._token_receiver.bind(this, tokens));
235235
resp.header_tokens = tokens;
236236
}
237237
if (resp.header_tokens.length)
238238
{
239-
var map_func = templates._make_header_template_func(false);
239+
var map_func = this._make_header_template_func(false);
240240
return [
241241
["h2", ui_strings.S_NETWORK_REQUEST_DETAIL_RESPONSE_TITLE],
242242
["pre", resp.header_tokens.map(map_func), "class", "mono"]
@@ -261,8 +261,8 @@ templates._response_headers = function(resp, do_raw)
261261
if (resp.logger_entry_touched_network)
262262
ret.push(["h2", ui_strings.S_NETWORK_REQUEST_DETAIL_RESPONSE_TITLE]);
263263

264-
ret.extend(templates.headers_list(resp.response_headers, firstline));
265-
return ["tbody", ret.map(templates._wrap_col_or_row)];
264+
ret.extend(this.headers_list(resp.response_headers, firstline));
265+
return ["tbody", ret.map(this._wrap_col_or_row)];
266266
};
267267

268268
templates.headers_list = function(headers, firstline, do_raw)
@@ -272,7 +272,7 @@ templates.headers_list = function(headers, firstline, do_raw)
272272
{
273273
map_func = function(header)
274274
{
275-
return templates._wrap_pre([["span", header.name + ":", "data-spec", "http#" + header.name], ["span", " " + header.value]]);
275+
return this._wrap_pre([["span", header.name + ":", "data-spec", "http#" + header.name], ["span", " " + header.value]]);
276276
};
277277
}
278278
else
@@ -296,7 +296,7 @@ templates._request_body = function(req, do_raw)
296296
if (req.requestbody == null)
297297
return [];
298298

299-
var ret = [templates._wrap_pre("\n")];
299+
var ret = [this._wrap_pre("\n")];
300300
if (req.requestbody.partList.length) // multipart
301301
{
302302
var use_raw_boundary = false;
@@ -308,7 +308,7 @@ templates._request_body = function(req, do_raw)
308308
if (use_raw_boundary && n === 0)
309309
ret.push(this._wrap_pre(req.boundary));
310310

311-
ret.extend(templates.headers_list(part.headerList, null, do_raw));
311+
ret.extend(this.headers_list(part.headerList, null, do_raw));
312312
ret.push(this._wrap_pre("\n"));
313313
if (part.content && part.content.stringData)
314314
ret.push(["pre", part.content.stringData, "class", "mono network-body"]);
@@ -370,13 +370,13 @@ templates._request_body = function(req, do_raw)
370370
if (do_raw)
371371
return ret;
372372
else
373-
return ["tbody", ret.map(templates._wrap_col_or_row)];
373+
return ["tbody", ret.map(this._wrap_col_or_row)];
374374
};
375375

376376

377377
templates._response_body = function(resp, do_raw, is_last)
378378
{
379-
var ret = [templates._wrap_pre("\n")]; // todo: no, then it's (really) empty there shouldn't be a separator either.
379+
var ret = [this._wrap_pre("\n")]; // todo: no, then it's (really) empty there shouldn't be a separator either.
380380

381381
var classname = "";
382382
if (resp.body_unavailable ||
@@ -422,7 +422,7 @@ templates._response_body = function(resp, do_raw, is_last)
422422
if (do_raw)
423423
return ret;
424424
else
425-
return ["tbody", ret.map(templates._wrap_col_or_row), "class", classname];
425+
return ["tbody", ret.map(this._wrap_col_or_row), "class", classname];
426426
};
427427

428428
})(window.templates.network);

src/network/network_service.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ cls.NetworkLoggerService = function(view)
213213
return;
214214

215215
var entry = this._current_context.get_entry(itemid);
216-
entry.is_fetching_body = true;
216+
entry.called_get_body = true;
217217
var contentmode = cls.ResourceUtil.mime_to_content_mode(entry.mime);
218218
var typecode = {datauri: 3, string: 1}[contentmode] || 1;
219219
var tag = window.tagManager.set_callback(this, this._handle_get_resource, [update_callback, entry]);
@@ -225,7 +225,6 @@ cls.NetworkLoggerService = function(view)
225225
if (!this._current_context)
226226
return;
227227

228-
entry.is_fetching_body = false;
229228
if (status)
230229
{
231230
// the object passed to _current_context represents empty event_data. will set body_unavailable.
@@ -504,13 +503,13 @@ cls.NetworkLoggerEntry = function(id, resource_id, document_id, context_starttim
504503
this.starttime_relative = null;
505504
this.endtime = null;
506505
this.requests_responses = [];
507-
this.last_responsecode = null;
506+
this.current_responsecode = null;
508507
this.last_method = null;
509508
this.is_unloaded = false;
510509
this.is_finished = false;
511510
this.events = [];
512511
this.event_sequence = [];
513-
this.is_fetching_body = false;
512+
this.called_get_body = false;
514513
};
515514

516515
cls.NetworkLoggerEntryPrototype = function()
@@ -762,8 +761,8 @@ cls.NetworkLoggerEntryPrototype = function()
762761

763762
this._update_event_response = function(event)
764763
{
765-
this.last_responsecode = event.responseCode;
766-
this.error_in_last_response = /^[45]/.test(this.last_responsecode);
764+
this.current_responsecode = event.responseCode;
765+
this.error_in_current_response = /^[45]/.test(this.current_responsecode);
767766
this._current_response = new cls.NetworkLoggerResponse(this);
768767
this.requests_responses.push(this._current_response);
769768
this._current_response._update_event_response(event);
@@ -882,7 +881,7 @@ cls.NetworkLoggerEntryPrototype = function()
882881
this.events.push(evt);
883882
};
884883

885-
this.__defineGetter__("last_response_has_responsebody", function()
884+
this.__defineGetter__("current_response_has_responsebody", function()
886885
{
887886
return Boolean(this._current_response && this._current_response.responsebody);
888887
});

src/network/network_view.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler)
184184
if (entry)
185185
{
186186
// todo: it would be good if we knew if the whole context is finished. Better only to get_body then, less potential to disturb.
187-
if (entry.is_finished && !entry.last_response_has_responsebody && !entry.is_fetching_body)
187+
if (entry.is_finished && !entry.current_response_has_responsebody && !entry.called_get_body)
188188
this._service.get_body(entry.id, this.update_bound);
189189

190190
template = [template, this._render_details_view(entry)];
@@ -236,14 +236,14 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler)
236236
label: ui_strings.S_HTTP_LABEL_RESPONSECODE,
237237
headertooltip: ui_strings.S_HTTP_TOOLTIP_RESPONSECODE,
238238
renderer: function(entry) {
239-
return (entry.last_responsecode && String(entry.last_responsecode)) || "";
239+
return (entry.current_responsecode && String(entry.current_responsecode)) || "";
240240
},
241241
title_getter: function(entry, renderer) {
242-
if (cls.ResourceUtil.http_status_codes[entry.last_responsecode])
243-
return String(cls.ResourceUtil.http_status_codes[entry.last_responsecode]);
242+
if (cls.ResourceUtil.http_status_codes[entry.current_responsecode])
243+
return String(cls.ResourceUtil.http_status_codes[entry.current_responsecode]);
244244
return renderer(entry);
245245
},
246-
getter: function(entry) { return entry.last_responsecode || 0; }
246+
getter: function(entry) { return entry.current_responsecode || 0; }
247247
},
248248
mime: {
249249
label: ui_strings.S_RESOURCE_ALL_TABLE_COLUMN_MIME,

0 commit comments

Comments
 (0)