@@ -34,6 +34,18 @@ 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+
3749 this . get_window_contexts = function ( type )
3850 {
3951 type = ( type || this . CONTEXT_TYPE_MAIN ) ;
@@ -78,26 +90,16 @@ cls.NetworkLoggerService = function()
7890
7991 var data = new cls . DocumentManager [ "1.0" ] . AboutToLoadDocument ( msg ) ;
8092
81- // For abouttoloaddocument, the context is always of type CONTEXT_TYPE_LOGGER.
93+ // For this event, the context is always of type CONTEXT_TYPE_LOGGER.
94+ // That needs to be static here, because a new context will be created if it doesn't exist.
8295 var ctx = this . get_request_context ( this . CONTEXT_TYPE_LOGGER , true ) ;
96+
97+ // Without a parentDocumentID, this event means "unload" for the old content of this windowID.
8398 if ( ! data . parentDocumentID )
84- {
85- // This basically means "unload" for that windowID, potentially
86- // existing data for that windowID needs to be cleared now.
8799 ctx . remove_window_context ( data . windowID ) ;
88- }
89100
90- var window_context = ctx . get_window_context ( data . windowID ) ;
91- if ( ! window_context )
92- {
93- var window_context = new cls . NetworkLoggerService . WindowContext ( data . windowID , this , ctx ) ;
94- ctx . window_contexts . push ( window_context ) ;
95- if ( ! data . parentDocumentID )
96- {
97- window_context . saw_main_document = true ;
98- }
99- ctx . post_on_context_or_service ( "window-context-added" , { "window-context" : window_context } ) ;
100- }
101+ var window_context = ctx . get_window_context ( data . windowID , true ) ;
102+ window_context . saw_main_document = ! data . parentDocumentID ;
101103 } ;
102104 this . _on_abouttoloaddocument_bound = this . _on_abouttoloaddocument . bind ( this , this . _on_abouttoloaddocument_bound ) ;
103105
@@ -382,9 +384,8 @@ cls.NetworkLoggerService = function()
382384 }
383385 // Post update message from here. This is only needed when the generic updating per event is paused.
384386 if ( this . is_paused )
385- {
386387 ctx . post_on_context_or_service ( "resource-update" , { id : event . resourceID } ) ;
387- }
388+
388389 } ;
389390
390391 this . init ( ) ;
@@ -578,17 +579,6 @@ cls.RequestContextPrototype = function()
578579
579580 this . update = function ( eventname , event )
580581 {
581- if ( event . windowID )
582- {
583- var matching_window_context = this . get_window_context ( event . windowID ) ;
584- if ( ! matching_window_context )
585- {
586- var window_context = new cls . NetworkLoggerService . WindowContext ( event . windowID , this . _service , this ) ;
587- this . window_contexts . push ( window_context ) ;
588- this . post_on_context_or_service ( "window-context-added" , { "window-context" : window_context } ) ;
589- }
590- }
591-
592582 var res_id = event . resourceID ;
593583 var logger_entries = this . get_entries_with_res_id ( res_id ) ;
594584 if ( ! logger_entries . length && eventname !== "urlload" )
@@ -634,7 +624,7 @@ cls.RequestContextPrototype = function()
634624 logger_entry = new cls . NetworkLoggerEntry ( id , event . resourceID , event . documentID , this . get_starttime ( ) ) ;
635625 this . _logger_entries . push ( logger_entry ) ;
636626 // Store the id in the list of entries in the window_context
637- var window_context = this . get_window_context ( event . windowID ) ;
627+ var window_context = ( event . windowID && this . get_window_context ( event . windowID , true ) ) ;
638628 window_context . entry_ids . push ( id ) ;
639629 }
640630 logger_entry . request_id = event . requestID ;
@@ -715,11 +705,6 @@ cls.RequestContextPrototype = function()
715705 }
716706 } ;
717707
718- this . get_window_context = function ( window_id )
719- {
720- return this . window_contexts . filter ( helpers . eq ( "id" , window_id ) ) [ 0 ] ;
721- } ;
722-
723708 this . send_request = function ( url , requestdata )
724709 {
725710 var windowid = window . window_manager_data . get_debug_context ( ) ;
0 commit comments