@@ -68,7 +68,7 @@ cls.ResourceManagerService = function(view, network_logger)
6868 if ( r && r . url == this . _suppress_updates_url )
6969 this . _suppress_uids [ msg . id ] = true ;
7070
71- // skip the update if it is about a suppressed uid
71+ // skip the update if it is about a suppressed uid
7272 if ( this . _suppress_uids [ msg . id ] )
7373 return ;
7474 }
@@ -78,24 +78,19 @@ cls.ResourceManagerService = function(view, network_logger)
7878 var ctx = { } ;
7979
8080 // get the order of the groups of resources
81- ctx . groupOrder = this . _view . get_group_order ( ) ;
81+ ctx . group_order = this . _view . get_group_order ( ) ;
8282
8383 // get list of window_contexts for which we saw the main_document
84- ctx . windowList = ( this . _network_logger . get_window_contexts ( ) || [ ] )
85- . filter ( function ( w ) {
86- return w . saw_main_document ;
87- } ) ;
84+ ctx . windowList = ( this . _network_logger . get_window_contexts ( ) || [ ] ) . filter ( function ( w ) {
85+ return w . saw_main_document ;
86+ } ) ;
8887
8988 if ( ctx . windowList . length )
9089 {
91- // get all the (non-suppressed) resources with content, sorted by uid
92- ctx . resourceList = ( this . _network_logger . get_resources ( ) || [ ] )
93- . filter ( function ( v ) {
94- return ! this . _suppress_uids . hasOwnProperty ( v . uid ) && v . responsecode != 204 ;
95- } , this )
96- . sort ( function ( a , b ) {
97- return a . uid > b . uid ? 1 : a . uid == b . uid ? 0 : - 1 ;
98- } ) ;
90+ // get all the (non-suppressed) resources with content
91+ ctx . resourceList = ( this . _network_logger . get_resources ( ) || [ ] ) . filter ( function ( v ) {
92+ return ! this . _suppress_uids . hasOwnProperty ( v . uid ) && v . responsecode != 204 ;
93+ } , this ) ;
9994
10095 ctx . document_resource_hash = { } ;
10196
@@ -110,71 +105,76 @@ cls.ResourceManagerService = function(view, network_logger)
110105 // set null_document_id flag,
111106 // augment the document objects,
112107 // set the default collapsed flags
113- ctx . documentList = this . _document_list
114- . filter ( function ( d , i , a ) {
115- var inContext = window_id_index . hasOwnProperty ( d . windowID ) ;
116-
117- if ( inContext )
108+ ctx . documentList = this . _document_list . filter ( function ( d , i , a ) {
109+ var inContext = window_id_index . hasOwnProperty ( d . windowID ) ;
110+
111+ if ( inContext )
112+ {
113+ if ( ! null_document_id && ! d . documentID )
114+ null_document_id = true ;
115+
116+ if ( d . resourceID != null )
117+ ctx . document_resource_hash [ d . resourceID ] = d . documentID ;
118+
119+ // populate document_id_index
120+ document_id_index [ d . documentID ] = i ;
121+
122+ // set depth, pivotID and sameOrigin
123+ var p = a [ document_id_index [ d . parentDocumentID ] ] || { pivotID :d . windowID , depth :0 } ;
124+ var id = p . pivotID + "_" + d . documentID ;
125+ d . depth = p . depth + 1 ;
126+ d . pivotID = id ;
127+ d . sameOrigin = cls . ResourceUtil . sameOrigin ( p . url , d . url ) ;
128+
129+ // set the default collapsed flag
130+ var hash = this . _collapsed_hash ;
131+ if ( ! hash . hasOwnProperty ( id ) )
118132 {
119- if ( ! null_document_id && ! d . documentID )
120- null_document_id = true ;
121-
122- if ( d . resourceID != null )
123- ctx . document_resource_hash [ d . resourceID ] = d . documentID ;
124-
125- // populate document_id_index
126- document_id_index [ d . documentID ] = i ;
127-
128- // set depth, pivotID and sameOrigin
129- var p = a [ document_id_index [ d . parentDocumentID ] ] || { pivotID :d . windowID , depth :0 } ;
130- var id = p . pivotID + "_" + d . documentID ;
131- d . depth = p . depth + 1 ;
132- d . pivotID = id ;
133- d . sameOrigin = cls . ResourceUtil . sameOrigin ( p . url , d . url ) ;
134-
135- // set the default collapsed flag
136- var hash = this . _collapsed_hash ;
137- if ( ! hash . hasOwnProperty ( id ) )
138- {
139- hash [ id ] = d . depth > 1 ;
140- ctx . groupOrder . forEach ( function ( g ) { hash [ id + "_" + g ] = true ; } ) ;
141- }
133+ hash [ id ] = d . depth > 1 ;
134+ ctx . group_order . forEach ( function ( g ) { hash [ id + "_" + g ] = true ; } ) ;
142135 }
136+ }
143137
144- return inContext ;
145- } , this ) ;
138+ return inContext ;
139+ } , this ) ;
146140
147141 var unknown_document_id = false ;
148142
149143 // set unknown_document_id flag,
150144 // assign top resource to the right document,
151145 // add group to each resource,
152146 // sameOrigin flag to each resource
153- ctx . resourceList
154- . forEach ( function ( r ) {
155- if ( ! unknown_document_id && ! document_id_index . hasOwnProperty ( r . document_id ) )
156- unknown_document_id = true ;
147+ // full_id ( pivot_ID + uid )
148+ ctx . resourceList . forEach ( function ( r ) {
149+ if ( ! unknown_document_id && ! document_id_index . hasOwnProperty ( r . document_id ) )
150+ unknown_document_id = true ;
151+
152+ // check if this is the top resource of a document
153+ var documentID = ctx . document_resource_hash [ r . resource_id ] ;
154+ if ( documentID != null && documentID != r . document_id )
155+ r . document_id = documentID ;
157156
158- // check if this is the top resource of a document
159- var documentID = ctx . document_resource_hash [ r . resource_id ] ;
160- if ( documentID != null && documentID != r . document_id )
161- r . document_id = documentID ;
157+ this . _populate_document_resources ( r ) ;
162158
163- this . _populate_document_resources ( r ) ;
159+ r . group = TYPE_GROUP_MAPPING [ r . type ] || TYPE_GROUP_MAPPING [ "*" ] ;
160+ var d = this . _document_list [ document_id_index [ r . document_id ] ] ;
161+ r . sameOrigin = cls . ResourceUtil . sameOrigin ( d && d . url , r ) ;
162+ r . full_id = ( d && d . pivotID ) + "_" + ctx . group_order . indexOf ( r . group ) + r . group + "_" + r . uid ;
164163
165- r . group = TYPE_GROUP_MAPPING [ r . type ] || TYPE_GROUP_MAPPING [ "*" ] ;
166- var d = this . _document_list [ document_id_index [ r . document_id ] ] ;
167- r . sameOrigin = cls . ResourceUtil . sameOrigin ( d && d . url , r ) ;
168- } , this ) ;
164+ } , this ) ;
165+
166+ // sort the resource by their full_id ( pivot + uid )
167+ ctx . resourceList = ctx . resourceList . sort ( function ( a , b ) {
168+ return a . full_uid > b . full_uid ? 1 : a . full_uid == b . full_uid ? 0 : - 1 ;
169+ } ) ;
169170
170171 // filter the list of window. Purge the ones with no documents
171- ctx . windowList = ctx . windowList
172- . filter ( function ( v ) {
173- return ctx . documentList
174- . some ( function ( w ) {
175- return v . id == w . windowID ;
176- } ) ;
172+ ctx . windowList = ctx . windowList . filter ( function ( v ) {
173+ return ctx . documentList . some ( function ( w ) {
174+ return v . id == w . windowID ;
177175 } ) ;
176+ } ) ;
177+
178178
179179 // request the list of documents if we have
180180 // an empty documentList
@@ -448,7 +448,7 @@ cls.ResourceRequest = function(url, callback, data, resourceInfo)
448448 {
449449 if ( status == SUCCESS && this . _retries < MAX_RETRIES )
450450 {
451- var resourceData = new cls . ResourceManager [ "1.2" ] . ResourceData ( message ) ;
451+ var resourceData = new cls . ResourceManager [ "1.2" ] . ResourceData ( message ) ;
452452 if ( resourceData . content )
453453 {
454454 // content -> mock a cls.NetworkLoggerEntry and instanciate a cls.ResourceInfo
0 commit comments