Skip to content

Commit f5c55cc

Browse files
author
p01
committed
Added a ResourceFrame class.
Make sure that resources loaded via the ResourceContext are bound to a frame. Added test for upper domains in the sameOrigin check.
1 parent e2152e8 commit f5c55cc

File tree

1 file changed

+51
-24
lines changed

1 file changed

+51
-24
lines changed

src/resource-manager/resource_service.js

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,38 @@ cls.ResourceRequest = function(url, callback,data)
331331
this._request_resource();
332332
}
333333

334+
cls.ResourceFrame = function( data )
335+
{
336+
this._init( data );
337+
}
338+
cls.ResourceFramePrototype = function()
339+
{
340+
this._init = function(data)
341+
{
342+
this.id = data.frameID;
343+
this.resourceID = data.resourceID;
344+
this.parentFrameID = data.parentFrameID;
345+
this.windowID = data.windowID;
346+
this.closed = !!data.parentFrameID;
347+
this.groups =
348+
{
349+
markup: new cls.ResourceGroup('markup','markup'),
350+
css: new cls.ResourceGroup('stylesheets','css'),
351+
script: new cls.ResourceGroup('scripts','script'),
352+
image: new cls.ResourceGroup('images','image'),
353+
font: new cls.ResourceGroup('fonts','font'),
354+
other: new cls.ResourceGroup('other','other')
355+
}
356+
}
357+
358+
this.update = function(eventname, event)
359+
{
360+
361+
}
362+
}
363+
364+
window.cls.ResourceFrame.prototype = new window.cls.ResourceFramePrototype();
365+
334366

335367
cls.ResourceContext = function(data)
336368
{
@@ -342,24 +374,13 @@ cls.ResourceContext = function(data)
342374
{
343375
if (eventname == "abouttoloaddocument")
344376
{
345-
var frame = event;
346-
frame.closed = !!event.parentFrameID;
347-
frame.groups =
348-
{
349-
markup: new cls.ResourceGroup('markup','markup'),
350-
css: new cls.ResourceGroup('stylesheets','css'),
351-
script: new cls.ResourceGroup('scripts','script'),
352-
image: new cls.ResourceGroup('images','image'),
353-
font: new cls.ResourceGroup('fonts','font'),
354-
other: new cls.ResourceGroup('other','other')
355-
}
356-
357-
this.frames[ event.frameID ] = frame;
377+
var frame = new cls.ResourceFrame(event);
378+
this.frames[ frame.id ] = frame;
358379
return;
359380
}
360381

361382
var res = this.get_resource(event.resourceID);
362-
if (eventname == "urlload" && !res)
383+
if (eventname == "urlload" && !res && this.frames[event.frameID])
363384
{
364385
res = new cls.Resource(event.resourceID);
365386
res.frameID = event.frameID;
@@ -370,27 +391,34 @@ cls.ResourceContext = function(data)
370391
{
371392
res.update(eventname, event);
372393

394+
var frame = this.frames[res.frameID];
395+
if (eventname == "urlload")
396+
{
397+
if (res.id == frame.resourceID)
398+
frame.resource = res;
399+
}
400+
373401
if (eventname == "urlfinished")
374402
{
375403
// push the resourceID into the proper group
376-
var frame = this.frames[res.frameID];
377-
if (frame)
404+
if (frame && frame.resource)
378405
{
379406
var type = res.type;
380407
if (!frame.groups[type]){ type='other'; }
381408

382409
frame.groups[type].push( res.id );
383410
this.resourcesUrlDict[ res.url ] = res.id;
384411

385-
// WIP: sameOrigin check
412+
// sameOrigin check
413+
// TODO: sameOrigin check for iframes
386414
res.sameOrigin = false;
387-
var frameResource = this.resourcesDict[ frame.resourceID ];
388-
if (frameResource.protocol==res.protocol &&
389-
(frameResource.host==res.host )) //|| frameResource.host.substr(res.host)))
390-
{
415+
if (frame.resource != null && frame.resource.protocol == res.protocol &&
416+
(
417+
frame.resource.host == res.host
418+
|| frame.resource.host.match(new RegExp('\\.' + res.host + '$')) != null
419+
)
420+
)
391421
res.sameOrigin = true;
392-
}
393-
394422

395423
}
396424
else
@@ -602,7 +630,6 @@ cls.ResourcePrototype = function()
602630
}
603631
};
604632

605-
606633
}
607634

608635
window.cls.ResourcePrototype.prototype = new URIPrototype("url");

0 commit comments

Comments
 (0)