@@ -34,23 +34,12 @@ cls.NetworkLoggerService = function()
3434 this . post ( "context-removed" , { "context_type" : type } ) ;
3535 } ;
3636
37- this . get_window_context = function ( window_id , force )
38- {
39- var window_context = this . window_contexts . filter ( helpers . eq ( "id" , window_id ) ) [ 0 ] ;
40- if ( ! window_context && force )
41- {
42- window_context = new cls . NetworkLoggerService . WindowContext ( window_id , this . _service , this ) ;
43- this . window_contexts . push ( window_context ) ;
44- this . post_on_context_or_service ( "window-context-added" , { "window-context" : window_context } ) ;
45- }
46- return window_context ;
47- } ;
48-
37+ // get_window_contexts means "of the main context" here (on the service). That's in line
38+ // with messages of the main context firing here instead of on the context.
4939 this . get_window_contexts = function ( type )
5040 {
51- type = ( type || this . CONTEXT_TYPE_MAIN ) ;
52- var ctx = this . get_request_context ( type ) ;
53- return ctx && ctx . window_contexts ;
41+ var ctx = this . get_request_context ( this . CONTEXT_TYPE_MAIN ) ;
42+ return ctx && ctx . get_window_contexts ( ) ;
5443 } ;
5544
5645 this . _queue_message = function ( listener , msg )
@@ -99,7 +88,9 @@ cls.NetworkLoggerService = function()
9988 ctx . remove_window_context ( data . windowID ) ;
10089
10190 var window_context = ctx . get_window_context ( data . windowID , true ) ;
102- window_context . saw_main_document = ! data . parentDocumentID ;
91+ if ( ! data . parentDocumentID )
92+ window_context . saw_main_document = true ;
93+
10394 } ;
10495 this . _on_abouttoloaddocument_bound = this . _on_abouttoloaddocument . bind ( this , this . _on_abouttoloaddocument_bound ) ;
10596
@@ -371,7 +362,7 @@ cls.NetworkLoggerService = function()
371362
372363 this . _handle_get_resource = function ( status , data , resource_id )
373364 {
374- var ctx = this . _contexts [ this . CONTEXT_TYPE_LOGGER ] ;
365+ var ctx = this . get_request_context ( this . CONTEXT_TYPE_LOGGER ) ;
375366 if ( status )
376367 {
377368 // the object passed to _current_context represents empty event_data. will set no_used_mimetype.
@@ -397,38 +388,31 @@ cls.NetworkLoggerService.WindowContext = function(window_id, service, context)
397388 this . _context = context ;
398389 this . id = window_id ;
399390 this . saw_main_document = false ;
391+ this . incomplete_warn_discarded = false ;
400392 this . entry_ids = [ ] ;
401393} ;
402394
403395cls . NetworkLoggerService . WindowContextPrototype = function ( )
404396{
397+ this . _filter_entries = function ( resource_ids , entry , index , entries )
398+ {
399+ // Skip an entry if an entry with the same resource_id is found further down the list.
400+ var same_resource_id = window . helpers . eq ( "resource_id" , entry . resource_id ) ;
401+ return this . entry_ids . contains ( entry . id ) &&
402+ ( ! resource_ids || resource_ids . contains ( entry . resource_id ) ) &&
403+ entries . slice ( index + 1 ) . filter ( same_resource_id ) . length == 0 ;
404+ }
405+
405406 this . get_resources = function ( resource_ids )
406407 {
407- // resource_ids
408- // An optional array of resource ids
409-
410- // Take all entries of the window-context's context, filter by what actually belongs
411- // to this window context.
412- var entries = this . _context . get_entries ( ) . filter ( function ( entry ) {
413- return this . entry_ids . contains ( entry . id ) &&
414- ( ! resource_ids || resource_ids . contains ( entry . id ) ) ;
415- } , this ) ;
416-
417- // Todo: can hopefully be made nicer.
418- var resource_ids_collected_resources = [ ] ;
419- var resources = [ ] ;
420- entries . forEach ( function ( entry ) {
421- var index_of_last_with_res_id = resource_ids_collected_resources . indexOf ( entry . resource_id ) ;
422- if ( index_of_last_with_res_id != - 1 )
423- {
424- // This is newer, remove the previous entry from resources.
425- resources . splice ( index_of_last_with_res_id , 1 ) ;
426- resource_ids_collected_resources . splice ( index_of_last_with_res_id , 1 ) ;
427- }
428- resources . push ( entry ) ;
429- resource_ids_collected_resources . push ( entry . resource_id ) ;
430- } ) ;
431- return resources . map ( function ( entry ) { return new cls . ResourceInfo ( entry ) } ) ;
408+ var filter_bound = this . _filter_entries . bind ( this , resource_ids ) ;
409+ var entries = this . _context . get_entries ( ) . filter ( filter_bound ) ;
410+ return entries . map ( function ( entry ) { return new cls . ResourceInfo ( entry ) } ) ;
411+ } ;
412+
413+ this . discard_incomplete_warning = function ( )
414+ {
415+ this . incomplete_warn_discarded = true ;
432416 } ;
433417} ;
434418
@@ -441,13 +425,13 @@ cls.RequestContext = function(service, is_main_context)
441425 "is_blacklist" : true
442426 } ;
443427 this . allocated_res_ids = [ ] ;
444- this . window_contexts = [ ] ;
445428 this . is_paused = false ;
446429 this . is_waiting_for_create_request = false ;
447430 this . _logger_entries = [ ] ;
448431 this . _filters = [ this . FILTER_ALLOW_ALL ] ;
449432 this . _is_main_context = is_main_context ;
450433 this . _service = service ;
434+ this . _window_contexts = [ ] ;
451435 this . _init ( ) ;
452436} ;
453437
@@ -653,6 +637,24 @@ cls.RequestContextPrototype = function()
653637 posting_object . post ( name , body ) ;
654638 } ;
655639
640+ this . get_window_contexts = function ( type )
641+ {
642+ return this . _window_contexts ;
643+ } ;
644+
645+ this . get_window_context = function ( window_id , force )
646+ {
647+ var helpers = window . helpers ;
648+ var window_context = this . _window_contexts . filter ( helpers . eq ( "id" , window_id ) ) [ 0 ] ;
649+ if ( ! window_context && force )
650+ {
651+ window_context = new cls . NetworkLoggerService . WindowContext ( window_id , this . _service , this ) ;
652+ this . _window_contexts . push ( window_context ) ;
653+ this . post_on_context_or_service ( "window-context-added" , { "window-context" : window_context } ) ;
654+ }
655+ return window_context ;
656+ } ;
657+
656658 this . remove_window_context = function ( window_id )
657659 {
658660 var window_context = this . get_window_context ( window_id ) ;
@@ -667,7 +669,7 @@ cls.RequestContextPrototype = function()
667669 ) ;
668670 }
669671 // Remove the window_context itself
670- this . window_contexts = this . window_contexts . filter (
672+ this . _window_contexts = this . _window_contexts . filter (
671673 function ( context ) {
672674 return window_id != context . id ;
673675 }
@@ -694,17 +696,6 @@ cls.RequestContextPrototype = function()
694696 }
695697 } ) ( ) ;
696698
697- this . discard_incomplete_warning = function ( window_id )
698- {
699- // Todo: Filter
700- for ( var i = 0 , window_context ; window_context = this . window_contexts [ i ] ; i ++ )
701- {
702- if ( window_context . id === window_id )
703- window_context . incomplete_warn_discarded = true ;
704-
705- }
706- } ;
707-
708699 this . send_request = function ( url , requestdata )
709700 {
710701 var windowid = window . window_manager_data . get_debug_context ( ) ;
@@ -1338,9 +1329,7 @@ cls.NetworkLoggerResponse.prototype = new cls.NetworkLoggerResponsePrototype();
13381329cls . ResourceInfo = function ( entry )
13391330{
13401331 this . url = entry . url ;
1341- this . id = entry . id ;
13421332 this . document_id = entry . document_id ;
13431333 this . type = entry . type ;
13441334 this . is_unloaded = entry . is_unloaded ;
1345- this . _entry = entry ; // dbg
13461335} ;
0 commit comments