@@ -219,18 +219,6 @@ cls.NetworkLoggerService = function()
219219 this . _res_service . requestSetResponseMode ( cls . TagManager . IGNORE_RESPONSE , resparg ) ;
220220 } . bind ( this ) ;
221221
222- this . get_body = function ( entry )
223- {
224- if ( ! this . _current_context )
225- return ;
226-
227- entry . called_get_body = true ;
228- var contentmode = cls . ResourceUtil . mime_to_content_mode ( entry . mime ) ;
229- var typecode = { datauri : 3 , string : 1 } [ contentmode ] || 1 ;
230- var tag = window . tagManager . set_callback ( this , this . _handle_get_resource , [ entry ] ) ;
231- this . _res_service . requestGetResource ( tag , [ entry . resource_id , [ typecode , 1 ] ] ) ;
232- } ;
233-
234222 this . get_resource_info = function ( resource_id )
235223 {
236224 // Returns a ResourceInfo based on the most recent Entry with that resource_id.
@@ -243,27 +231,6 @@ cls.NetworkLoggerService = function()
243231 return null ;
244232 } ;
245233
246- this . _handle_get_resource = function ( status , data , entry )
247- {
248- if ( ! this . _current_context )
249- return ;
250-
251- if ( status )
252- {
253- // the object passed to _current_context represents empty event_data. will set no_used_mimetype.
254- this . _current_context . update ( "responsebody" , { resourceID : entry . resource_id } ) ;
255- }
256- else
257- {
258- var msg = new cls . ResourceManager [ "1.2" ] . ResourceData ( data ) ;
259- this . _current_context . update ( "responsebody" , msg ) ;
260- }
261- // Post update message from here. This is only needed when the generic updating per event is paused.
262- if ( this . is_paused )
263- window . messages . post ( "network-resource-updated" , { id : entry . resource_id } ) ;
264-
265- } ;
266-
267234 this . get_request_context = function ( )
268235 {
269236 return this . _current_context ;
@@ -456,49 +423,37 @@ cls.RequestContextPrototype = function()
456423 return ;
457424 }
458425
459- // For responsebody, all entries with that resourceID need to be updated.
460- // Others are callbacks that belongs to the current (and last) entry of that resourceID.
461- if ( eventname === "responsebody" )
426+ var logger_entry = logger_entries . last ;
427+ if ( logger_entry && logger_entry . request_id )
462428 {
463- for ( var i = 0 , logger_entry ; logger_entry = logger_entries [ i ] ; i ++ )
429+ /*
430+ The same resource id can be loaded several times, but then the request id changes.
431+ It's not loaded multiple times in parallel though, so the following check would
432+ emit errors if that would happen. There is at least one NetworkLoggerEntry per
433+ resource ID, but several entries can refer to the same.
434+ Note: Retry events change the request id, but the Entry stays the same.
435+ */
436+ var changed_request_id = this . _event_changes_req_id ( event , logger_entry ) ;
437+ if ( changed_request_id )
464438 {
465- logger_entry . update ( eventname , event ) ;
439+ opera . postError ( ui_strings . S_DRAGONFLY_INFO_MESSAGE +
440+ " Unexpected change in requestID on " + eventname +
441+ ": Change from " + logger_entry . request_id + " to " +
442+ event . requestID + ", URL: " + logger_entry . human_url ) ;
466443 }
467444 }
468- else
469- {
470- var logger_entry = logger_entries . last ;
471- if ( logger_entry && logger_entry . request_id )
472- {
473- /*
474- The same resource id can be loaded several times, but then the request id changes.
475- It's not loaded multiple times in parallel though, so the following check would
476- emit errors if that would happen. There is at least one NetworkLoggerEntry per
477- resource ID, but several entries can refer to the same.
478- Note: Retry events change the request id, but the Entry stays the same.
479- */
480- var changed_request_id = this . _event_changes_req_id ( event , logger_entry ) ;
481- if ( changed_request_id )
482- {
483- opera . postError ( ui_strings . S_DRAGONFLY_INFO_MESSAGE +
484- " Unexpected change in requestID on " + eventname +
485- ": Change from " + logger_entry . request_id + " to " +
486- event . requestID + ", URL: " + logger_entry . human_url ) ;
487- }
488- }
489445
490- if ( eventname == "urlload" || changed_request_id )
491- {
492- var id = this . _get_uid ( ) ;
493- logger_entry = new cls . NetworkLoggerEntry ( id , event . resourceID , event . documentID , this . get_starttime ( ) ) ;
494- this . _logger_entries . push ( logger_entry ) ;
495- // Store the id in the list of entries in the window_context
496- var window_context = this . get_window_context ( event . windowID ) ;
497- window_context . entry_ids . push ( id ) ;
498- }
499- logger_entry . request_id = event . requestID ;
500- logger_entry . update ( eventname , event ) ;
446+ if ( eventname == "urlload" || changed_request_id )
447+ {
448+ var id = this . _get_uid ( ) ;
449+ logger_entry = new cls . NetworkLoggerEntry ( id , event . resourceID , event . documentID , this . get_starttime ( ) ) ;
450+ this . _logger_entries . push ( logger_entry ) ;
451+ // Store the id in the list of entries in the window_context
452+ var window_context = this . get_window_context ( event . windowID ) ;
453+ window_context . entry_ids . push ( id ) ;
501454 }
455+ logger_entry . request_id = event . requestID ;
456+ logger_entry . update ( eventname , event ) ;
502457
503458 if ( ! this . is_paused )
504459 window . messages . post ( "network-resource-updated" , { id : event . resourceID } ) ;
@@ -591,14 +546,15 @@ cls.NetworkLoggerEntry = function(id, resource_id, document_id, context_starttim
591546 this . current_responsecode = null ;
592547 this . error_in_current_response = false ;
593548 this . called_get_body = false ;
549+ this . get_body_unsuccessful = false ;
594550 this . _current_request = null ;
595551 this . _current_response = null ;
596552 this . _set_is_finished_on_responsefinished = false ;
597553} ;
598554
599555cls . NetworkLoggerEntryPrototype = function ( )
600556{
601- var unlisted_events = [ "responsebody" , " urlunload"] ;
557+ var unlisted_events = [ "urlunload" ] ;
602558
603559 var CLASSNAME_BLOCKED = "blocked" ;
604560 var CLASSNAME_REQUEST = "request" ;
@@ -885,17 +841,6 @@ cls.NetworkLoggerEntryPrototype = function()
885841 this . _guess_response_type ( ) ;
886842 } ;
887843
888- this . _update_event_responsebody = function ( event )
889- {
890- if ( ! this . _current_response )
891- {
892- // This should mean there wasn't a request, but it was fetched over GetResource.
893- this . _current_response = new cls . NetworkLoggerResponse ( this ) ;
894- this . requests_responses . push ( this . _current_response ) ;
895- }
896- this . _current_response . update_event_responsebody ( event ) ;
897- } ;
898-
899844 this . _update_event_urlredirect = function ( event )
900845 {
901846 // Workaround for CORE-47687
@@ -975,20 +920,58 @@ cls.NetworkLoggerEntryPrototype = function()
975920 this . events . push ( evt ) ;
976921 } ;
977922
978- this . check_to_request_body = function ( service )
923+ this . check_to_get_body = function ( )
979924 {
980- // Decide if body should be fetched, for when content-tracking is off or it's a cached request.
981- if (
925+ var should_get_body = (
982926 this . is_finished &&
983927 ! this . called_get_body &&
984928 ( ! this . _current_response || ! this . _current_response . responsebody ) &&
985- // When we have a response, but didn't see responsefinished, it means there's really no
929+ // When we have a response, but didn't see responsefinished, there really is no
986930 // responsebody. Don't attempt to fetch it.
987931 ( ! this . _current_response || this . _current_response . saw_responsefinished )
988- )
932+ ) ;
933+ // Todo: The exception for !saw_responsefinished is AFAIR so we don't fetch a wrong result like a
934+ // placeholder from Opera, but thee's currently no testcase for that.
935+ // We could also avoid it when this.is_unloaded, but seems there it will
936+ // just be unsuccessful and we handle that.
937+
938+ if ( should_get_body )
939+ {
940+ // Decide if body should be fetched, for when content-tracking is off or it's a cached request.
941+ this . called_get_body = true ;
942+ if ( this . _current_response )
943+ this . _current_response . update_called_get_body ( true ) ;
944+
945+ var contentmode = cls . ResourceUtil . mime_to_content_mode ( this . mime ) ;
946+ var typecode = { datauri : 3 , text : 1 } [ contentmode ] ;
947+ var tag = window . tagManager . set_callback ( this , this . _handle_get_resource ) ;
948+ var CONTENT_MODE_STRING = 1 ;
949+ window . services [ "resource-manager" ] . requestGetResource ( tag , [ this . resource_id , [ typecode , CONTENT_MODE_STRING ] ] ) ;
950+ }
951+ } ;
952+
953+ this . _handle_get_resource = function ( status , msg )
954+ {
955+ if ( ! this . _current_response )
956+ {
957+ // This means there wasn't a request, we add a "response" though because that's where that data lives.
958+ this . _current_response = new cls . NetworkLoggerResponse ( this ) ;
959+ this . requests_responses . push ( this . _current_response ) ;
960+ }
961+
962+ var SUCCESS = 0 ;
963+ if ( status == SUCCESS )
964+ {
965+ var data = new cls . ResourceManager [ "1.2" ] . ResourceData ( msg ) ;
966+ this . responsebody = data ;
967+ this . _current_response . update_responsebody ( data ) ;
968+ }
969+ else
989970 {
990- service . get_body ( this ) ;
971+ this . get_body_unsuccessful = true ;
972+ this . _current_response . update_get_body_unsuccessful ( true ) ;
991973 }
974+ window . messages . post ( "network-resource-updated" , { id : this . resource_id } ) ;
992975 } ;
993976
994977 this . __defineGetter__ ( "duration" , function ( )
@@ -1094,14 +1077,15 @@ cls.NetworkLoggerResponse = function(entry)
10941077 this . header_tokens = null ; // This is set from template code, when it's first needed
10951078 this . is_response = true ; // Simpler for recognizing than dealing with comparing the constructor
10961079 this . saw_responsefinished = false ;
1097- this . no_used_mimetype = false ;
10981080
10991081 // The following are duplicated from the entry to have them available directly on the response
11001082 this . logger_entry_type = entry . type ;
11011083 this . logger_entry_id = entry . id ;
11021084 this . logger_entry_mime = entry . mime ;
11031085 this . logger_entry_is_finished = entry . is_finished ;
11041086 this . logger_entry_touched_network = entry . touched_network ;
1087+ this . logger_entry_called_get_body = entry . called_get_body ;
1088+ this . logger_entry_get_body_unsuccessful = entry . get_body_unsuccessful ;
11051089} ;
11061090
11071091cls . NetworkLoggerResponsePrototype = function ( )
@@ -1126,22 +1110,18 @@ cls.NetworkLoggerResponsePrototype = function()
11261110 if ( event . data && event . data . content )
11271111 {
11281112 // event.data is of type ResourceData here.
1129- // From here, no_used_mimetype is not set to true when there is no mimeType.
1130- // A later call to get_resource will set it from update_event_responsebody.
11311113 this . responsebody = event . data ;
11321114 }
11331115 } ;
11341116
1135- this . update_event_responsebody = function ( event )
1117+ this . update_responsebody = function ( responsebody )
11361118 {
1137- // event.mimeType is the used mime type here.
1138- if ( ! event . mimeType ) { this . no_used_mimetype = true ; }
1139- this . responsebody = event ;
1119+ this . responsebody = responsebody ;
11401120 } ;
11411121
11421122 this . update_event_urlunload = function ( event )
11431123 {
1144- this . is_unloaded = true ;
1124+ this . is_unloaded = true ; // todo: check if we use that on the response?
11451125 } ;
11461126
11471127 // The following are to reflect changes that happened on Entry.
@@ -1156,6 +1136,16 @@ cls.NetworkLoggerResponsePrototype = function()
11561136 this . logger_entry_mime = mime ;
11571137 this . logger_entry_type = type ;
11581138 } ;
1139+
1140+ this . update_called_get_body = function ( called_get_body )
1141+ {
1142+ this . logger_entry_called_get_body = called_get_body ;
1143+ } ;
1144+
1145+ this . update_get_body_unsuccessful = function ( get_body_unsuccessful )
1146+ {
1147+ this . logger_entry_get_body_unsuccessful = get_body_unsuccessful ;
1148+ } ;
11591149} ;
11601150
11611151cls . NetworkLoggerResponse . prototype = new cls . NetworkLoggerResponsePrototype ( ) ;
0 commit comments