Skip to content

Commit a8e8ca4

Browse files
author
p01
committed
first WIP of a Resource Manager organized by type of resources
1 parent 8fcf6cb commit a8e8ca4

File tree

9 files changed

+318
-58
lines changed

9 files changed

+318
-58
lines changed

src/build-application/build_resource_manager_1_0.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
window.app.builders.ResourceManager["1.0"] = function(service)
44
{
5+
// p01 WIP resource views
6+
new cls.ResourceTestView('resource_tree_view','Tree View');
7+
//new cls.ResourceTestView('resource_search', 'Search');
8+
9+
510
new cls.ResourceManagerAllView('resource_all', ui_strings.M_VIEW_LABEL_ALL_RESOURCES, 'scroll resource-manager', '', '');
611
//new cls.ResourceManagerFontView('resource_fonts', "Fonts", 'scroll', '', '');
712
//new cls.ResourceManagerImageView('resource_images', "Images", 'scroll', '', '');

src/client-en.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ window.load_screen_timeout = window.setTimeout(function()
479479
<script src="./resource-manager/resourcemanager.1.0.events.onresponsefinished.js"/>
480480
<script src="./resource-manager/documentmanager.1.0.events.onabouttoloaddocument.js"/>
481481

482+
<script src="./resource-manager/resource_test_view.js"/>
483+
482484

483485
<script src="./network/network_service.js"/>
484486
<script src="./network/network_view.js"/>

src/client/client.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,16 @@ ui_framework.layouts.network_rough_layout =
580580

581581
ui_framework.layouts.resource_rough_layout =
582582
{
583-
dir: 'v',
584-
width: 1000,
585-
height: 1000,
586-
children: [ { height: 1000, tabbar: { id: "resources", tabs: ['resource_all'] } } ]
583+
dir:'h', width:1000,height:700,
584+
children:
585+
[
586+
{
587+
width: 700, tabbar: { id:'resources_tree', tabs: ['resource_tree_view'] }
588+
},
589+
{
590+
width: 300, tabbar: { id: "resources", tabs: ['resource_all'], _is_hidden: true }
591+
}
592+
]
587593
};
588594

589595
ui_framework.layouts.utils_rough_layout =

src/resource-manager/resource_all_view.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ cls.ResourceManagerAllView = function(id, name, container_class, html, default_h
5656

5757
this._render_main_view = function(container)
5858
{
59+
container.clearAndRender(
60+
['div',
61+
['p', "let's deprecate this view please..."],
62+
'class', 'info-box'
63+
]
64+
);
65+
return;
66+
5967
var ctx = this._service.get_resource_context();
6068
if (ctx && ctx.resources.length)
6169
{
@@ -157,7 +165,11 @@ cls.ResourceManagerAllView = function(id, name, container_class, html, default_h
157165
},
158166
host: {
159167
label: ui_strings.S_RESOURCE_ALL_TABLE_COLUMN_HOST,
160-
getter: function(res) { return res.urltype == 4 ? res.human_url : cls.ResourceUtil.url_host(res.url) },
168+
getter: function(res) { return (
169+
170+
[res.frameID, cls.ResourceManagerService.instance._frames[res.frameID].parentFrameID]
171+
172+
)+' > '+(res.urltype == 4 ? res.human_url : cls.ResourceUtil.url_host(res.url)) },
161173
},
162174
path: {
163175
label: ui_strings.S_RESOURCE_ALL_TABLE_COLUMN_PATH,
@@ -196,13 +208,13 @@ cls.ResourceManagerAllView = function(id, name, container_class, html, default_h
196208
{
197209
this._loading = true;
198210
this._table = null;
199-
this.update();
211+
// this.update();
200212
}.bind(this);
201213

202214
this._on_documentloaded_bound = function()
203215
{
204216
this._loading = false;
205-
this.update();
217+
// this.update();
206218
}.bind(this);
207219

208220
var eh = window.eventHandlers;

src/resource-manager/resource_service.js

Lines changed: 102 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,66 +10,76 @@ cls.ResourceManagerService = function(view)
1010
}
1111
cls.ResourceManagerService.instance = this;
1212

13-
this._current_context = null;
1413
this._view = view;
14+
this._context = null;
1515

1616
this._enable_content_tracking = function()
1717
{
1818
this._res_service.requestSetResponseMode(null, [[3, 1]]);
19-
}
19+
};
2020

2121
this._on_abouttoloaddocument_bound = function(msg)
2222
{
2323
var data = new cls.DocumentManager["1.0"].AboutToLoadDocument(msg);
24-
// if not a top resource, just ignore. This usually means it's an iframe
25-
if (data.parentDocumentID) { return; }
26-
this._current_context = new cls.ResourceContext();
24+
if (!data.parentFrameID)
25+
{
26+
this._context = new cls.ResourceContext(data);
27+
}
28+
if (this._context)
29+
{
30+
this._context.update("abouttoloaddocument", data);
31+
}
2732
}.bind(this);
2833

2934
this._on_urlload_bound = function(msg)
3035
{
31-
if (!this._current_context) { return; }
36+
if (!this._context){ return; }
37+
3238
var data = new cls.ResourceManager["1.0"].UrlLoad(msg);
39+
//bail if we get dupes. Why do we get dupes? fixme
40+
//if (data.resourceID in this._current_document.resourcemap) { return }
3341

34-
//bail if we get dupes. Why do we get dupes? fixme
35-
//if (data.resourceID in this._current_document.resourcemap) { return }
36-
this._current_context.update("urlload", data);
42+
this._context.update("urlload", data);
43+
this._view.update();
3744
}.bind(this);
3845

3946
this._on_urlredirect_bound = function(msg)
4047
{
41-
if (!this._current_context) { return; }
48+
if (!this._context){ return; }
4249

4350
var data = new cls.ResourceManager["1.0"].UrlRedirect(msg);
4451
// a bit of cheating since further down we use .resouceID to determine
4552
// what resource the event applies to:
4653
data.resourceID = data.fromResourceID;
47-
this._current_context.update("urlredirect", data);
54+
this._context.update("urlredirect", data);
4855
}.bind(this);
4956

5057
this._on_urlfinished_bound = function(msg)
5158
{
52-
if (!this._current_context) { return; }
59+
if (!this._context){ return; }
60+
5361
var data = new cls.ResourceManager["1.0"].UrlFinished(msg);
54-
this._current_context.update("urlfinished", data);
62+
this._context.update("urlfinished", data);
5563
}.bind(this);
5664

5765
this._on_response_bound = function(msg)
5866
{
59-
if (!this._current_context) { return; }
67+
if (!this._context){ return; }
68+
6069
var data = new cls.ResourceManager["1.0"].Response(msg);
61-
this._current_context.update("response", data);
70+
this._context.update("response", data);
6271
}.bind(this);
6372

6473
this._on_debug_context_selected_bound = function()
6574
{
66-
this._current_context = null;
75+
this._context = null;
6776
this._view.update();
6877
}.bind(this);
6978

7079
this.init = function()
7180
{
7281
this._res_service = window.services['resource-manager'];
82+
7383
this._res_service.addListener("urlload", this._on_urlload_bound);
7484
this._res_service.addListener("response", this._on_response_bound);
7585
this._res_service.addListener("urlredirect", this._on_urlredirect_bound);
@@ -81,7 +91,7 @@ cls.ResourceManagerService = function(view)
8191

8292
this.get_resource_context = function()
8393
{
84-
return this._current_context;
94+
return this._context;
8595
};
8696

8797
/**
@@ -96,9 +106,14 @@ cls.ResourceManagerService = function(view)
96106

97107
this.get_resource_for_id = function(id)
98108
{
99-
if (this._current_context)
109+
if (this._topFrameID)
100110
{
101-
return this._current_context.get_resource(id);
111+
for (var i in this._frames)
112+
{
113+
var res = this._current_context.get_resource(id);
114+
if (res){ return res; }
115+
}
116+
//return this._current_context.get_resource(id);
102117
}
103118
return null;
104119
};
@@ -118,44 +133,67 @@ cls.ResourceManagerService = function(view)
118133
var tag = window.tagManager.set_callback(null, callback);
119134
const MAX_PAYLOAD_SIZE = 10 * 1000 * 1000; // allow payloads of about 10 mb.
120135
this._res_service.requestGetResource(tag, [rid, [typecode, 1, MAX_PAYLOAD_SIZE]]);
121-
}
136+
};
122137

123138
this.init();
124139
};
125140

126-
127-
cls.ResourceContext = function()
141+
cls.ResourceContext = function(data)
128142
{
129-
this.resources = [];
143+
// this.resources = [];
144+
this.resourcesDict = {};
145+
this.frames = {};
130146

131147
this.update = function(eventname, event)
132148
{
133-
var res = this.get_resource(event.resourceID);
149+
if (eventname == "abouttoloaddocument")
150+
{
151+
var frame = event;
152+
frame.closed = !!event.parentFrameID;
153+
frame.groups = { markup: {closed:true,ids:{}}, css: {closed:true,ids:{}}, script: {closed:true,ids:{}}, image: {closed:true,ids:{}}, other: {closed:true,ids:{}} };
154+
this.frames[ event.frameID ] = frame;
155+
return;
156+
}
134157

158+
var res = this.get_resource(event.resourceID);
135159
if (eventname == "urlload" && !res)
136160
{
137161
res = new cls.Resource(event.resourceID);
138-
this.resources.push(res);
162+
res.frameID = event.frameID;
163+
// this.resources.push(res);
164+
this.resourcesDict[ res.id ] = res;
139165
}
140166
else if (!res)
141167
{
142168
// ignoring. Never saw an urlload, or it's allready invalidated
143-
return
169+
return;
144170
}
145171

146172
res.update(eventname, event);
147173

148174
if (res.invalid)
149175
{
150-
this.resources.splice(this.resources.indexOf(res), 1);
176+
delete this.resourcesDict[ res.id ];
177+
// this.resources.splice(this.resources.indexOf(res), 1);
178+
}
179+
else if (eventname == "urlfinished")
180+
{
181+
// push the resourceID into the proper group
182+
var frame = this.frames[res.frameID];
183+
var type = res.type;
184+
if (!frame.groups[type]){ type='other'; }
185+
186+
//if (frame.groups[type].ids.indexOf( res.id )==-1)
187+
frame.groups[type].ids[ res.id ]=1;
151188
}
152189
}
153190

154191
this.get_resource = function(id)
155192
{
156-
return this.resources.filter(function(e) { return e.id == id; })[0];
193+
return this.resourcesDict[ id ];
194+
// return this.resources.filter(function(e) { return e.id == id; })[0];
157195
};
158-
196+
/*
159197
this.get_resources_for_types = function()
160198
{
161199
var types = Array.prototype.slice.call(arguments, 0);
@@ -169,46 +207,56 @@ cls.ResourceContext = function()
169207
var filterfun = function(e) { return mimes.indexOf(e.mime) > -1; };
170208
return this.resources.filter(filterfun);
171209
};
172-
210+
/*
173211
this.get_resource_groups = function()
174212
{
175-
var imgs = this.get_resources_for_type("image");
176-
var stylesheets = this.get_resources_for_mime("text/css");
177-
var markup = this.get_resources_for_mime("text/html",
213+
return this._groups;
214+
var imgs = this.get_resources_for_types("image");
215+
var stylesheets = this.get_resources_for_mimes("text/css");
216+
var markup = this.get_resources_for_mimes("text/html",
178217
"application/xhtml+xml");
179-
var scripts = this.get_resources_for_mime("application/javascript",
218+
var scripts = this.get_resources_for_mimes("application/javascript",
180219
"text/javascript");
181220
182221
var known = [].concat(imgs, stylesheets, markup, scripts);
183222
var other = this.resources.filter(function(e) {
184223
return known.indexOf(e) == -1;
185224
});
186225
return {
187-
images: imgs, stylesheets: stylesheets, markup: markup,
226+
markup: markup, images: imgs, stylesheets: stylesheets,
188227
scripts: scripts, other: other
189228
}
190229
}
230+
*/
191231
}
192232

193233
cls.Resource = function(id)
194234
{
195-
this.id = id;
196-
this.finished = false;
197-
this.url = null;
198-
this.location = "No URL";
199-
this.result = null;
200-
this.mime = null;
201-
this.encoding = null;
202-
this.size = 0;
203-
this.type = null;
204-
this.urltype = null;
205-
this.invalid = false;
235+
this._init(id);
236+
}
237+
238+
var ResourcePrototype = function()
239+
{
240+
this._init = function(id)
241+
{
242+
this.id = id;
243+
this.finished = false;
244+
this.url = null;
245+
this.location = "No URL";
246+
this.result = null;
247+
this.mime = null;
248+
this.encoding = null;
249+
this.size = 0;
250+
this.type = null;
251+
this.urltype = null;
252+
this.invalid = false;
253+
}
206254

207255
this.update = function(eventname, eventdata)
208256
{
209257
if (eventname == "urlload")
210258
{
211-
this.url = eventdata.url;
259+
this.url = new URI( eventdata.url );
212260
this.urltype = eventdata.urlType;
213261
// fixme: complete list
214262
this.urltypeName = {0: "Unknown", 1: "HTTP", 2: "HTTPS", 3: "File", 4: "Data" }[eventdata.urlType];
@@ -218,7 +266,7 @@ cls.Resource = function(id)
218266
{
219267
if (!this.url)
220268
{
221-
this.url = eventdata.url;
269+
this.url = new URI( eventdata.url );
222270
}
223271
this.result = eventdata.result;
224272
this.mime = eventdata.mimeType;
@@ -259,7 +307,7 @@ cls.Resource = function(id)
259307
}
260308
else if (this.mime.toLowerCase() == "application/octet-stream")
261309
{
262-
this.type = cls.ResourceUtil.path_to_type(this.url);
310+
this.type = cls.ResourceUtil.path_to_type(this.url.filename);
263311
}
264312
else
265313
{
@@ -269,7 +317,6 @@ cls.Resource = function(id)
269317

270318
this._humanize_url = function()
271319
{
272-
this.human_url = this.url;
273320
if (this.urltype == 4) // data URI
274321
{
275322
if (this.type)
@@ -281,5 +328,10 @@ cls.Resource = function(id)
281328
this.human_url = "data URI";
282329
}
283330
}
331+
else
332+
{
333+
this.human_url = this.url.url;
334+
}
284335
}
285336
}
337+
cls.Resource.prototype = new ResourcePrototype();

0 commit comments

Comments
 (0)