Skip to content

Commit d672813

Browse files
author
p01
committed
Review fixes
* no "loading" template * no "flash" template but a fallback one with a Show Resource link * reuse the NetworkEntry' .error_in_current_response * s/service/_resource_inspector in cls.ResourceTreeView and cls.ResourceDetailView * switch this.flat_list to a private variable in window.templates.resource_tree
1 parent 47a0b27 commit d672813

File tree

9 files changed

+60
-557
lines changed

9 files changed

+60
-557
lines changed

src/network/network_service.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,7 @@ cls.ResourceInfo = function(entry)
12971297
this.window_id = entry.window_id;
12981298
this.is_unloaded = entry.is_unloaded;
12991299
this.responsecode = entry.current_responsecode;
1300+
this.error_in_current_response = entry.error_in_current_response;
13001301

13011302
var last_response = entry.requests_responses && entry.requests_responses.last;
13021303
if (last_response && last_response.responsebody)

src/resource-manager/resource_detail_view.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ cls.ResourceDetailView = function(id, name, container_class, html, default_handl
133133

134134
this.data = data;
135135
this.resource = resource;
136-
this.service.highlight_resource(resource.uid);
136+
this._resource_inspector.highlight_resource(resource.uid);
137137
this.update();
138138

139139
return true;
@@ -147,13 +147,13 @@ cls.ResourceDetailView = function(id, name, container_class, html, default_handl
147147

148148
this._show_resource_by_key = function(key, data)
149149
{
150-
var service = this.service;
151-
var resource = service.get_resource(key) || service.get_resource_by_url(key);
150+
var inspector = this._resource_inspector;
151+
var resource = inspector.get_resource(key) || inspector.get_resource_by_url(key);
152152

153153
var url = resource ? resource.url : key;
154154

155155
if (!resource || !this._show_resource(resource, data))
156-
service.request_resource_data(url, this.show_resource.bind(this), data, resource);
156+
inspector.request_resource_data(url, this.show_resource.bind(this), data, resource);
157157
};
158158

159159
/*
@@ -180,7 +180,7 @@ cls.ResourceDetailView = function(id, name, container_class, html, default_handl
180180
this._init = function(id, name, container_class, html, default_handler, resource_inspector)
181181
{
182182
this.id = id;
183-
this.service = resource_inspector;
183+
this._resource_inspector = resource_inspector;
184184

185185
var messages = window.messages;
186186
messages.add_listener("debug-context-selected", this._on_debug_context_selected_bound);

src/resource-manager/resource_style.css

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@
5757
background-image: url("../ui-images/type_feed.png");
5858
}
5959

60-
.resource-type-flash
61-
{
62-
background-image: url("../ui-images/type_flash.png");
63-
}
64-
6560
.resource-type-font
6661
{
6762
background-image: url("../ui-images/type_font.png");
@@ -228,7 +223,7 @@
228223
.resource-detail-text-container,
229224
.resource-detail-image-container,
230225
.resource-detail-others-container,
231-
.resource-detail-flash-container
226+
.resource-detail-fallback-container
232227
{
233228
padding: 8px;
234229
}

src/resource-manager/resource_templates.js

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
77
var URL_MATCH_CONTEXT_SIZE = 10;
88
var DEPTH_IDENTATION = 18;
99
var DISTINGUISHER_MAX_LENGTH = 64;
10+
var flat_list;
1011

1112
this._get_short_distinguisher = function(url)
1213
{
13-
var name = url.filename || url.short_distinguisher || url;
14+
var name = url.short_distinguisher;
1415

1516
if (name.length > this.DISTINGUISHER_MAX_LENGTH)
1617
name = name.slice(0, this.DISTINGUISHER_MAX_LENGTH) + "…";
@@ -41,8 +42,6 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
4142

4243
this.update = function(context)
4344
{
44-
this.flat_list = [];
45-
4645
// expand all the pivots if there is a search_term
4746
if (context.search_term != "")
4847
Object.keys(context.collapsed).forEach(function(v) { context.collapsed[v] = false; });
@@ -57,12 +56,20 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
5756
context.resources.push(r);
5857
});
5958

59+
flat_list = [];
6060
this.windows(context);
61-
var tpl = ["div", ["ul", this.flat_list], "class", "resource-tree"];
62-
delete this.flat_list;
61+
var tpl = ["div", ["ul", flat_list], "class", "resource-tree"];
62+
flat_list = [];
63+
6364
return tpl;
6465
};
6566

67+
/*
68+
* The following template methods push their result to the private variable
69+
* `flat_list` in order to create a lightweight flat list of windows, documents,
70+
* groups, resources, ...
71+
*
72+
*/
6673
this.windows = function(context)
6774
{
6875
context.window_list.forEach(this.window.bind(this, context));
@@ -72,11 +79,11 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
7279
{
7380
var window_info = window.window_manager_data.get_window(w.id);
7481
if (!window_info)
75-
return [];
82+
return;
7683

7784
var extras = this._expander_extras(context, String(w.id));
7885

79-
this.flat_list.push(
86+
flat_list.push(
8087
["li",
8188
["h2",
8289
extras.tpl.button,
@@ -108,17 +115,16 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
108115

109116
if (resources.length > 0)
110117
{
111-
var depth = d.depth;
112-
var extras = this._expander_extras(context, d.pivot_id, depth);
118+
var extras = this._expander_extras(context, d.pivot_id, d.depth);
113119

114-
this.flat_list.push(
120+
flat_list.push(
115121
["li",
116122
["h2",
117123
extras.tpl.button,
118124
["span",
119125
this._get_short_distinguisher(d.url),
120126
"class", "resource-tree-document-label",
121-
"data-tooltip", " js-script-select",
127+
"data-tooltip", "kjs-script-select",
122128
"data-tooltip-text", d.original_url
123129
],
124130
" ",
@@ -132,7 +138,7 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
132138
].concat(extras.tpl.li)
133139
);
134140

135-
if (!extras.collapsed )
141+
if (!extras.collapsed)
136142
{
137143
if (resources.length)
138144
this.resource_groups(context, resources, d);
@@ -159,7 +165,7 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
159165
var depth = d.depth + 1;
160166
var extras = this._expander_extras(context, d.pivot_id + "_" + g, depth);
161167

162-
this.flat_list.push(
168+
flat_list.push(
163169
["li",
164170
["h2",
165171
extras.tpl.button,
@@ -194,21 +200,21 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
194200
{
195201
var pos_first = r.url.indexOf(search) - URL_MATCH_CONTEXT_SIZE;
196202
var pos_last = r.url.lastIndexOf(search) + URL_MATCH_CONTEXT_SIZE + search.length;
197-
var preffix = pos_first > 0 ? "…" : "";
203+
var prefix = pos_first > 0 ? "…" : "";
198204
var suffix = pos_last < r.url.length ? "…" : "";
199205

200-
partial_url_match = preffix + r.url.substring(pos_first, pos_last) + suffix;
206+
partial_url_match = prefix + r.url.substring(pos_first, pos_last) + suffix;
201207
}
202208

203-
this.flat_list.push(
209+
flat_list.push(
204210
["li",
205211
["h2",
206212
["span",
207213
partial_url_match || this._get_short_distinguisher(r),
208214
"class", "resource-tree-resource-label",
209215
"style", "margin-left:" + (1 + depth) * DEPTH_IDENTATION + "px;",
210216
"data-tooltip", "js-script-select",
211-
"data-tooltip-text", r.url
217+
"data-tooltip-text", r.short_distinguisher
212218
],
213219
" ",
214220
r.same_origin ? [] : ["span", r.host, "class", "resource-domain"],
@@ -232,14 +238,14 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
232238
if (!resource.data)
233239
return this.no_data_available(resource);
234240

235-
var specific_template = this[resource.type] ? resource.type : "text";
241+
var type = this[resource.type] ? resource.type : "fallback";
236242

237243
return(
238244
["div",
239245
this.overview(resource),
240246
["div",
241-
this[specific_template](resource, resource.data),
242-
"class", "resource-detail-" + specific_template + "-container"
247+
this[type](resource, resource.data),
248+
"class", "resource-detail-" + type + "-container"
243249
],
244250
"class", "resource-detail-container"
245251
]);
@@ -280,14 +286,13 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
280286

281287
this.overview = function(resource)
282288
{
283-
var info =
284-
{
289+
var info = {
285290
"response_code": resource.responsecode + " " + cls.ResourceUtil.http_status_codes[resource.responsecode],
286291
"size": resource.size || resource.data.contentLength || resource.data.content.length,
287292
"character_encoding": resource.encoding || resource.data.characterEncoding
288293
};
289294

290-
var is_error = resource.responsecode && ![200, 304].contains(resource.responsecode);
295+
var is_error = resource.error_in_current_response;
291296

292297
return (
293298
["div",
@@ -395,16 +400,15 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
395400
]);
396401
};
397402

398-
this.flash = function(resource)
403+
this.fallback = function(resource)
399404
{
400405
return(
401-
["object",
402-
["div",
403-
"Type not supported"
404-
],
405-
"type", resource.mimeType,
406-
"data", resource.data.content.stringData,
407-
"class", "resource-detail-flash"
406+
[
407+
"a",
408+
ui_strings.M_CONTEXTMENU_SHOW_RESOURCE,
409+
"href", resource.url,
410+
"target", "_blank",
411+
"class", "resource-detail-link"
408412
]);
409413
};
410414

src/resource-manager/resource_tree_view.js

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
1919
ui_strings.S_HTTP_LABEL_FILTER_OTHER
2020
];
2121

22-
this._loading = false;
23-
24-
this.service = resource_inspector;
22+
this._resource_inspector = resource_inspector;
2523

2624
this.get_group_order = function()
2725
{
@@ -33,26 +31,15 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
3331

3432
this.createView = function(container)
3533
{
36-
var ctx = this.service.get_resource_context();
37-
var target = container.firstElementChild;
38-
var scroll_top = target ? target.scrollTop : 0;
39-
var scroll_left = target ? target.scrollLeft : 0;
4034
var tpl;
35+
var ctx = this._resource_inspector.get_resource_context();
36+
var target = container.firstElementChild;
4137

4238
if (ctx)
4339
{
4440
ctx.search_term = this.search_term || "";
4541
tpl = templates.resource_tree.update(ctx);
4642
}
47-
else if (this._loading)
48-
{
49-
tpl = (
50-
["div",
51-
["p", ui_strings.S_RESOURCE_LOADING_PAGE],
52-
"class", "info-box"
53-
]
54-
);
55-
}
5643
else
5744
{
5845
tpl = (
@@ -67,13 +54,17 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
6754
);
6855
}
6956

70-
// only render the template if it has changed ( using its JSON representation as hash )
57+
// Exit if the template has not changed since last time ( using its JSON representation as hash )
7158
var tpl_JSON = JSON.stringify(tpl);
72-
if (!this.tpl_JSON || tpl_JSON.length != this.tpl_JSON.length || tpl_JSON != this.tpl_JSON)
73-
{
74-
container.clearAndRender(tpl);
75-
this.tpl_JSON = tpl_JSON;
76-
}
59+
if (tpl_JSON == this.tpl_JSON)
60+
return;
61+
62+
this.tpl_JSON = tpl_JSON;
63+
64+
var scroll_top = target ? target.scrollTop : 0;
65+
var scroll_left = target ? target.scrollLeft : 0;
66+
67+
container.clearAndRender(tpl);
7768

7869
target = container.firstElementChild;
7970
if (target)
@@ -93,39 +84,21 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
9384
container.clearAndRender(window.templates.disabled_view());
9485
};
9586

96-
this._on_abouttoloaddocument_bound = function()
97-
{
98-
this._loading = true;
99-
this.update();
100-
}.bind(this);
101-
102-
this._on_documentloaded_bound = function()
103-
{
104-
this._loading = false;
105-
this.update();
106-
}.bind(this);
107-
108-
this._on_debug_context_selected_bound = function()
109-
{
110-
this._loading = false;
111-
this.update();
112-
}.bind(this);
113-
11487
this._init = function()
11588
{
11689
this.id = id;
11790

11891
var messages = window.messages;
119-
messages.add_listener("debug-context-selected", this._on_debug_context_selected_bound);
92+
messages.add_listener("debug-context-selected", this.update);
12093

12194
var doc_service = window.services["document-manager"];
122-
doc_service.add_listener("abouttoloaddocument", this._on_abouttoloaddocument_bound);
123-
doc_service.add_listener("documentloaded", this._on_documentloaded_bound);
95+
doc_service.add_listener("abouttoloaddocument", this.update);
96+
doc_service.add_listener("documentloaded", this.update);
12497

12598
ActionHandlerInterface.apply(this);
12699
this._handlers = {
127-
"select-next-entry": this.service.highlight_next_resource_bound,
128-
"select-previous-entry": this.service.highlight_previous_resource_bound
100+
"select-next-entry": this._resource_inspector.highlight_next_resource_bound,
101+
"select-previous-entry": this._resource_inspector.highlight_previous_resource_bound
129102
};
130103
ActionBroker.get_instance().register_handler(this);
131104

src/scripts/uri.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ var URIPrototype = function(uri_prop_name)
5353
{
5454
if (!this._is_data_uri)
5555
{
56-
this.pathname;
5756
var pos = this.pathname.lastIndexOf("/");
5857
if (pos > -1)
5958
this._filename = this.pathname.slice(pos + 1);

test-scripts/resource-tree-view/data.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)