Skip to content

Commit 346cd94

Browse files
author
p01
committed
clean up the documentList mangling, including the pivotIDs and expandCollapse
moved the TYPE_GROUP_MAPPING to a const replaced the last hardcoded strings with ui_strings
1 parent c248723 commit 346cd94

File tree

2 files changed

+204
-203
lines changed

2 files changed

+204
-203
lines changed

src/resource-manager/resource_service.js

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ cls.ResourceManagerService = function(view, network_logger)
1111
cls.ResourceManagerService.instance = this;
1212

1313
var THROTTLE_DELAY = 250;
14+
var TYPE_GROUP_MAPPING =
15+
{
16+
'markup':ui_strings.S_HTTP_LABEL_FILTER_MARKUP,
17+
'css':ui_strings.S_HTTP_LABEL_FILTER_STYLESHEETS,
18+
'script':ui_strings.S_HTTP_LABEL_FILTER_SCRIPTS,
19+
'image':ui_strings.S_HTTP_LABEL_FILTER_IMAGES,
20+
'font':ui_strings.S_HTTP_LABEL_FILTER_FONTS,
21+
'*':ui_strings.S_HTTP_LABEL_FILTER_OTHER
22+
};
23+
24+
1425

1526
this._view = view;
1627
this._network_logger = network_logger;
@@ -21,20 +32,12 @@ cls.ResourceManagerService = function(view, network_logger)
2132
delete this._tag_requestListDocuments;
2233
this._documentList = new cls.DocumentManager["1.0"].DocumentList(msg).documentList;
2334

24-
// use the URL class
25-
// populate this._documentURLHash
26-
this._documentURLHash = {};
2735
this._documentList.forEach(function(d)
2836
{
37+
// use the URL class
2938
d.url = new URI(d.url);
30-
this._documentURLHash[ d.documentID ] = d.url;
31-
},this);
39+
});
3240

33-
// sameOrigin as parentDocument ?
34-
this._documentList.forEach(function(d)
35-
{
36-
d.sameOrigin = cls.ResourceUtil.sameOrigin(this._documentURLHash[d.parentDocumentID], d.url);
37-
},this);
3841

3942
this._update({type:'_handle_listDocuments'});
4043
};
@@ -48,8 +51,10 @@ cls.ResourceManagerService = function(view, network_logger)
4851
this._populateDocumentResources = function(r)
4952
{
5053
var documentID = r.document_id;
54+
5155
if (!this._documentResources[documentID])
5256
this._documentResources[documentID]=[];
57+
5358
if (!this._documentResources[documentID].contains(r.id))
5459
this._documentResources[documentID].push(r.id);
5560
}
@@ -70,49 +75,47 @@ cls.ResourceManagerService = function(view, network_logger)
7075

7176
if (ctx.windowList && ctx.windowList.length)
7277
{
73-
var typeGroupMapping =
74-
{
75-
'markup':'markup',
76-
'css':'stylesheets',
77-
'script':'scripts',
78-
'image':'images',
79-
'font':'fonts',
80-
'*':'others'
81-
};
82-
8378
ctx.resourceList = [];
8479
ctx.documentResourceHash = {};
8580

8681
// get all the resources
82+
var windowID_index = {};
8783
ctx.windowList
88-
.forEach(function(w)
84+
.forEach(function(w,i)
8985
{
86+
windowID_index[w.id] = i;
87+
9088
// get resources of the current window
9189
var windowResources = w.get_resources();
92-
// filter out the resources that are unloaded
93-
windowResources
94-
.filter(function(r)
95-
{
96-
return !r.is_unloaded;
97-
});
90+
9891
// concat the result to flat list of resource
9992
ctx.resourceList = ctx.resourceList.concat( windowResources );
10093
});
10194

95+
96+
var documentID_index = {};
10297
// filter the documentId that belong in the windowIdList
10398
ctx.documentList = this._documentList
104-
.filter(function(d)
99+
.filter(function(d,i,a)
105100
{
106-
var inWindowContext = ctx.windowList
107-
.some( function(w)
101+
var inContext = windowID_index.hasOwnProperty(d.windowID);
102+
103+
if (inContext)
108104
{
109-
return w.id == d.windowID;
110-
});
105+
if (d.resourceID != null)
106+
ctx.documentResourceHash[ d.resourceID ] = d.documentID;
111107

112-
if (inWindowContext && d.resourceID != null)
113-
ctx.documentResourceHash[ d.resourceID ] = d.documentID;
108+
// populate documentID_index
109+
documentID_index[ d.documentID ] = i;
114110

115-
return inWindowContext;
111+
// set depth, pivotID and sameOrigin
112+
var p = a[ documentID_index[ d.parentDocumentID ] ]||{pivotID:d.windowID,depth:0};
113+
d.depth = p.depth+1;
114+
d.pivotID = p.pivotID+'_'+d.documentID;
115+
d.sameOrigin = cls.ResourceUtil.sameOrigin(p.url, d.url);
116+
}
117+
118+
return inContext;
116119
},this);
117120

118121
// assign top resource to the right document
@@ -131,8 +134,9 @@ cls.ResourceManagerService = function(view, network_logger)
131134
this._populateDocumentResources(r);
132135
}
133136

134-
r.group = typeGroupMapping[r.type]||typeGroupMapping['*'];
135-
r.sameOrigin = cls.ResourceUtil.sameOrigin(this._documentURLHash[r.document_id], r);
137+
r.group = TYPE_GROUP_MAPPING[r.type]||TYPE_GROUP_MAPPING['*'];
138+
var d = this._documentList[documentID_index[r.document_id]];
139+
r.sameOrigin = cls.ResourceUtil.sameOrigin(d&&d.url, r);
136140
},this);
137141

138142
// filter the list of window. Purge the ones with no documents
@@ -156,7 +160,7 @@ cls.ResourceManagerService = function(view, network_logger)
156160
ctx.resourceList
157161
.some(function(v)
158162
{
159-
return v.document_id && !this._documentURLHash[v.document_id];
163+
return v.document_id && !documentID_index[v.document_id];
160164
},this)
161165
||
162166
ctx.documentList
@@ -193,27 +197,23 @@ cls.ResourceManagerService = function(view, network_logger)
193197
if (!this._context)
194198
return;
195199

196-
var button = target.querySelector('.button-expand-collapse');
197200
var pivot = target.get_ancestor('[data-expand-collapse-id]');
198-
var pivots = [pivot];
199-
if (button && pivot)
201+
if (pivot)
200202
{
201203
var hash = this. _collapsedHash;
202204
var pivotID = pivot.getAttribute('data-expand-collapse-id');
205+
var pivotIDs = [pivotID];
203206
var collapsed = hash[pivotID] === true?false:true;
204207

205208
if (event.shiftKey)
206-
[].push.apply(pivots, pivot.querySelectorAll('[data-expand-collapse-id]'));
209+
pivotIDs.push.apply( pivotIDs, Object.keys(hash).filter( function(p)
210+
{
211+
return p.indexOf(pivotID+'_') == 0;
212+
}));
207213

208-
pivots.forEach(function(p)
209-
{
210-
var pivotID = p.getAttribute('data-expand-collapse-id');
211-
hash[pivotID] = collapsed;
212-
if (collapsed)
213-
p.classList.add('close');
214-
else
215-
p.classList.remove('close');
216-
});
214+
pivotIDs.forEach(function(p){ hash[p] = collapsed; });
215+
216+
this._view.update();
217217
}
218218
}.bind(this);
219219

0 commit comments

Comments
 (0)