@@ -8,13 +8,24 @@ cls.NetworkLoggerService = function(view)
88 this . _on_abouttoloaddocument_bound = function ( msg )
99 {
1010 var data = new cls . DocumentManager [ "1.0" ] . AboutToLoadDocument ( msg ) ;
11- // if not a top resource, don't reset the context. This usually means it's an iframe or a redirect.
12- // todo: handle multiple top-runtimes
13- if ( data . parentDocumentID )
14- return ;
1511
16- this . _current_context = new cls . RequestContext ( ) ;
17- this . _current_context . saw_main_document_abouttoloaddocument = true ;
12+ if ( ! this . _current_context )
13+ this . _current_context = new cls . RequestContext ( ) ;
14+
15+ if ( ! data . parentDocumentID )
16+ {
17+ // This basically means "unload" for that windowID, potentially
18+ // existing data for that windowID needs to be cleared now.
19+ this . _current_context . remove_window_context ( data . windowID ) ;
20+ }
21+
22+ var window_context = this . _current_context . get_window_context ( data . windowID ) ;
23+ if ( ! window_context )
24+ {
25+ var window_context = new cls . NetworkLoggerService . WindowContext ( data . windowID ) ;
26+ this . _current_context . window_contexts . push ( window_context ) ;
27+ }
28+ window_context . saw_main_document_abouttoloaddocument = true ;
1829 } . bind ( this ) ;
1930
2031 this . _on_urlload_bound = function ( msg )
@@ -274,11 +285,18 @@ cls.NetworkLoggerService = function(view)
274285 this . init ( ) ;
275286} ;
276287
288+ cls . NetworkLoggerService . WindowContext = function ( window_id )
289+ {
290+ this . id = window_id ;
291+ this . saw_main_document_abouttoloaddocument = false ;
292+ }
277293
278294cls . RequestContext = function ( )
279295{
280296 this . _logger_entries = [ ] ;
281297 this . _filters = [ ] ;
298+ this . window_contexts = [ ] ;
299+ this . _entry_to_window_id_map = { } ; // todo: this should just be an array on a WindowContext ob
282300
283301 this . _init ( ) ;
284302} ;
@@ -410,6 +428,15 @@ cls.RequestContextPrototype = function()
410428
411429 this . update = function ( eventname , event )
412430 {
431+ if ( event . windowID )
432+ {
433+ var matching_window_context = this . get_window_context ( event . windowID ) ;
434+ if ( ! matching_window_context )
435+ {
436+ this . window_contexts . push ( new cls . NetworkLoggerService . WindowContext ( event . windowID ) ) ;
437+ }
438+ }
439+
413440 var logger_entries = this . get_entries_with_res_id ( event . resourceID ) ;
414441 if ( ! logger_entries . length && eventname !== "urlload" )
415442 {
@@ -453,6 +480,12 @@ cls.RequestContextPrototype = function()
453480 var id = this . _get_uid ( ) ;
454481 logger_entry = new cls . NetworkLoggerEntry ( id , event . resourceID , event . documentID , this . get_starttime ( ) ) ;
455482 this . _logger_entries . push ( logger_entry ) ;
483+ // Store the id in the list of entries per window_id
484+ var map = this . _entry_to_window_id_map ;
485+ if ( ! map [ event . windowID ] )
486+ map [ event . windowID ] = [ ] ;
487+
488+ map [ event . windowID ] . push ( id ) ;
456489 }
457490 logger_entry . last_requestID = event . requestID ;
458491 logger_entry . update ( eventname , event ) ;
@@ -463,6 +496,25 @@ cls.RequestContextPrototype = function()
463496
464497 } ;
465498
499+ this . remove_window_context = function ( window_id )
500+ {
501+ var ids_to_remove = this . _entry_to_window_id_map [ window_id ] ;
502+ if ( ids_to_remove && ids_to_remove . length )
503+ {
504+ this . _logger_entries = this . _logger_entries . filter ( function ( entry ) {
505+ return ! ids_to_remove . contains ( entry . id ) ;
506+ } ) ;
507+ }
508+ this . _entry_to_window_id_map [ event . windowID ] = [ ] ;
509+ // Remove the window_context itself
510+ this . window_contexts = this . window_contexts . filter (
511+ function ( win_context )
512+ {
513+ return win_context . id != window_id ;
514+ }
515+ ) ;
516+ } ;
517+
466518 this . get_entry_from_filtered = function ( id )
467519 {
468520 return this . get_entries_filtered ( ) . filter ( function ( e ) { return e . id == id ; } ) [ 0 ] ;
@@ -481,6 +533,20 @@ cls.RequestContextPrototype = function()
481533 return "uid-" + count ++ ;
482534 }
483535 } ) ( ) ;
536+
537+ this . discard_incomplete_warning = function ( window_id )
538+ {
539+ for ( var i = 0 , window_context ; window_context = this . window_contexts [ i ] ; i ++ )
540+ if ( window_context . id === window_id )
541+ window_context . incomplete_warn_discarded = true ;
542+
543+ } ;
544+
545+ this . get_window_context = function ( window_id )
546+ {
547+ return this . window_contexts . filter ( helpers . eq ( "id" , window_id ) ) [ 0 ] ;
548+ } ;
549+
484550} ;
485551
486552cls . RequestContext . prototype = new cls . RequestContextPrototype ( ) ;
@@ -1020,6 +1086,7 @@ cls.NetworkLoggerResponsePrototype = function()
10201086 {
10211087 if ( ! event . mimeType ) { this . body_unavailable = true ; }
10221088 this . responsebody = event ;
1089+ // todo: check how to distinguish body_unavailable and empty body.
10231090 } ;
10241091
10251092 this . _update_event_urlunload = function ( event )
0 commit comments