@@ -28,8 +28,16 @@ cls.CookieManager.Cookie = function(details, data)
2828 }
2929}
3030
31+ cls . CookieManager . Cookie . prototype = new function ( )
32+ {
33+ this . __defineGetter__ ( "rt_id" , function ( ) { return this . _rt_id ; } ) ;
34+ this . __defineSetter__ ( "rt_id" , function ( ) { } ) ;
35+ }
36+
3137cls . CookieManager . CookieDataBase = function ( )
3238{
39+ var SUCCESS = 0 ;
40+
3341 this . refetch = function ( ) { } ;
3442 this . remove_cookie = function ( objectref , callback ) { } ;
3543 this . remove_cookies = function ( cookies ) { } ;
@@ -41,15 +49,21 @@ cls.CookieManager.CookieDataBase = function()
4149
4250 this . refetch = function ( )
4351 {
44- this . _active_tab_count ++ ;
4552 this . cookie_list = [ ] ;
46- for ( var rt_id in this . _rts ) {
47- this . _request_location_object_id ( Number ( rt_id ) , this . _active_tab_count ) ;
53+ for ( var rt_id in this . _rts )
54+ {
55+ this . _request_location_object_id ( Number ( rt_id ) ) ;
4856 } ;
4957 } ;
5058
5159 this . get_cookies = function ( )
5260 {
61+ if ( ! this . _is_active )
62+ {
63+ this . _is_active = true ;
64+ if ( this . _last_on_active_tab_msg )
65+ this . _on_active_tab ( this . _last_on_active_tab_msg )
66+ }
5367 return this . cookie_list ;
5468 } ;
5569
@@ -131,29 +145,35 @@ cls.CookieManager.CookieDataBase = function()
131145
132146 this . _on_active_tab = function ( msg )
133147 {
134- this . _active_tab_count ++ ;
135- this . cookie_list = [ ] ;
136- for ( var i = 0 ; i < msg . runtimes_with_dom . length ; i ++ )
148+ if ( this . _is_active )
137149 {
138- var rt_id = msg . runtimes_with_dom [ i ] ;
139- if ( ! this . _rts [ rt_id ] )
150+ for ( var i = 0 , rt_id ; rt_id = msg . runtimes_with_dom [ i ] ; i ++ )
140151 {
141- this . _rts [ rt_id ] = { rt_id : rt_id } ;
142- }
143- this . _request_location_object_id ( rt_id , this . _active_tab_count ) ;
144- } ;
152+ if ( ! this . _rts [ rt_id ] )
153+ {
154+ this . _rts [ rt_id ] = { rt_id : rt_id } ;
155+ this . _request_location_object_id ( rt_id ) ;
156+ }
157+ } ;
145158
146- // cleanup runtimes directory
147- for ( var rt in this . _rts )
148- {
149- // rt is a string, rt_id is a number which can now be compared with what's in msg.runtimes_with_dom
150- var rt_id = this . _rts [ rt ] . rt_id ;
151- if ( msg . runtimes_with_dom . indexOf ( rt_id ) === - 1 )
159+ // cleanup runtimes directory
160+ for ( var rt in this . _rts )
152161 {
153- // runtime was not active and is to be removed from this._rts
154- delete this . _rts [ rt_id ] ;
162+ // rt is a string, rt_id is a number which can now be compared with what's in msg.runtimes_with_dom
163+ var rt_id = this . _rts [ rt ] . rt_id ;
164+ if ( msg . runtimes_with_dom . indexOf ( rt_id ) === - 1 )
165+ {
166+ // runtime was not active and is to be removed from this._rts
167+ delete this . _rts [ rt_id ] ;
168+ this . cookie_list = this . cookie_list . filter ( function ( cookie )
169+ {
170+ return ! ( cookie . rt_id == rt_id ) ;
171+ } ) ;
172+ }
155173 }
156174 }
175+ else
176+ this . _last_on_active_tab_msg = msg ;
157177 } ;
158178
159179 this . _on_profile_disabled = function ( msg )
@@ -165,24 +185,24 @@ cls.CookieManager.CookieDataBase = function()
165185 }
166186 } ;
167187
168- this . _request_location_object_id = function ( rt_id , active_tab_counter )
188+ this . _request_location_object_id = function ( rt_id )
169189 {
170190 var script = "location" ;
171- var tag = tagManager . set_callback ( this , this . _handle_location_object_id , [ rt_id , active_tab_counter ] ) ;
172- services [ 'ecmascript-debugger' ] . requestEval ( tag , [ rt_id , 0 , 0 , script ] ) ;
191+ var tag = tagManager . set_callback ( this , this . _handle_location_object_id , [ rt_id ] ) ;
192+ services [ 'ecmascript-debugger' ] . requestEval ( tag , [ rt_id , 0 , 0 , script ] ) ;
173193 } ;
174194
175- this . _handle_location_object_id = function ( status , message , rt_id , active_tab_counter )
195+ this . _handle_location_object_id = function ( status , message , rt_id )
176196 {
177197 const
178198 OBJECT_VALUE = 3 ,
179199 // within sub message ObjectValue
180200 OBJECT_ID = 0 ;
181201
182- if ( status === 0 && message [ OBJECT_VALUE ] )
202+ if ( status === SUCCESS && message [ OBJECT_VALUE ] )
183203 {
184204 var object_id = message [ OBJECT_VALUE ] [ OBJECT_ID ] ;
185- var tag = tagManager . set_callback ( this , this . _handle_location , [ rt_id , active_tab_counter ] ) ;
205+ var tag = tagManager . set_callback ( this , this . _handle_location , [ rt_id ] ) ;
186206 var command_details = [
187207 rt_id , // runtimeID
188208 [ // objectList
@@ -196,7 +216,7 @@ cls.CookieManager.CookieDataBase = function()
196216 }
197217 } ;
198218
199- this . _handle_location = function ( status , message , rt_id , active_tab_counter )
219+ this . _handle_location = function ( status , message , rt_id )
200220 {
201221 const
202222 OBJECT_CHAIN_LIST = 0 ,
@@ -241,8 +261,8 @@ cls.CookieManager.CookieDataBase = function()
241261 if ( rt . hostname )
242262 {
243263 var request_hostname = rt . hostname ;
244- var tag = tagManager . set_callback ( this , this . _handle_cookies , [ rt_id , active_tab_counter ] ) ;
245- services [ 'cookie-manager' ] . requestGetCookie ( tag , [ request_hostname , rt . pathname ] ) ;
264+ var tag = tagManager . set_callback ( this , this . _handle_cookies , [ rt_id ] ) ;
265+ services [ 'cookie-manager' ] . requestGetCookie ( tag , [ request_hostname , rt . pathname ] ) ;
246266 }
247267 else
248268 {
@@ -252,104 +272,103 @@ cls.CookieManager.CookieDataBase = function()
252272 }
253273 } ;
254274
255- this . _handle_cookies = function ( status , message , rt_id , active_tab_counter )
275+ this . _handle_cookies = function ( status , message , rt_id )
256276 {
257- if ( this . _active_tab_count === active_tab_counter )
277+ var rt = this . _rts [ rt_id ] ;
278+ if ( ! rt )
279+ throw "missing runtime in _handle_cookies" ;
280+
281+ if ( status === SUCCESS )
258282 {
259- var rt = this . _rts [ rt_id ] || { } ;
260- if ( status === 0 )
283+ const COOKIE = 0 ;
284+ if ( message . length > 0 )
261285 {
262- const COOKIE = 0 ;
263- if ( message . length > 0 )
286+ var cookies = message [ COOKIE ] ;
287+ for ( var i = 0 , cookie_info ; cookie_info = cookies [ i ] ; i ++ )
264288 {
265- var cookies = message [ COOKIE ] ;
266- for ( var i = 0 , cookie_info ; cookie_info = cookies [ i ] ; i ++ ) {
267- // workaround: GetCookie doesn't allow to specify protocol, requested in CORE-35925
268- var is_secure = cookie_info [ 5 ] ;
269- if ( is_secure && rt . protocol !== "https:" )
270- {
271- continue ;
272- }
273- this . cookie_list . push (
274- new cls . CookieManager . Cookie ( {
275- domain : cookie_info [ 0 ] ,
276- path : cookie_info [ 1 ] ,
277- name : cookie_info [ 2 ] ,
278- value : cookie_info [ 3 ] ,
279- expires : cookie_info [ 4 ] ,
280- isSecure : cookie_info [ 5 ] ,
281- isHTTPOnly : cookie_info [ 6 ] ,
289+ // workaround: GetCookie doesn't allow to specify protocol, requested in CORE-35925
290+ var is_secure = cookie_info [ 5 ] ;
291+ if ( is_secure && rt . protocol !== "https:" )
292+ {
293+ continue ;
294+ }
295+ this . cookie_list . push (
296+ new cls . CookieManager . Cookie ( {
297+ domain : cookie_info [ 0 ] ,
298+ path : cookie_info [ 1 ] ,
299+ name : cookie_info [ 2 ] ,
300+ value : cookie_info [ 3 ] ,
301+ expires : cookie_info [ 4 ] ,
302+ isSecure : cookie_info [ 5 ] ,
303+ isHTTPOnly : cookie_info [ 6 ] ,
282304
283- _rt_id : rt_id ,
284- _rt_hostname : rt . hostname ,
285- _rt_path : rt . pathname ,
286- _rt_protocol : rt . protocol
287- } , this )
288- )
289- } ;
290- }
291- else
292- {
293- // In case no cookies come back, check via JS (workaround for CORE-41145)
294- var script = "return document.cookie" ;
295- var tag = tagManager . set_callback ( this , this . _handle_js_retrieved_cookies , [ rt_id , active_tab_counter ] ) ;
296- services [ 'ecmascript-debugger' ] . requestEval ( tag , [ rt_id , 0 , 0 , script ] ) ;
297- }
305+ _rt_id : rt_id ,
306+ _rt_hostname : rt . hostname ,
307+ _rt_path : rt . pathname ,
308+ _rt_protocol : rt . protocol
309+ } , this )
310+ )
311+ } ;
312+ }
313+ else
314+ {
315+ // In case no cookies come back, check via JS (workaround for CORE-41145)
316+ var script = "return document.cookie" ;
317+ var tag = tagManager . set_callback ( this , this . _handle_js_retrieved_cookies , [ rt_id ] ) ;
318+ services [ 'ecmascript-debugger' ] . requestEval ( tag , [ rt_id , 0 , 0 , script ] ) ;
298319 }
299- // add a placeholder per runtime to make the group show up even if there were no cookies
300- this . cookie_list . push (
301- new cls . CookieManager . Cookie ( {
302- _is_runtime_placeholder : true ,
303- _rt_id : rt_id ,
304- _rt_protocol : rt . protocol ,
305- _rt_hostname : rt . hostname ,
306- _rt_path : rt . pathname
307- } , this )
308- ) ;
309- this . _view . update ( ) ;
310320 }
321+ // add a placeholder per runtime to make the group show up even if there were no cookies
322+ this . cookie_list . push (
323+ new cls . CookieManager . Cookie ( {
324+ _is_runtime_placeholder : true ,
325+ _rt_id : rt_id ,
326+ _rt_protocol : rt . protocol ,
327+ _rt_hostname : rt . hostname ,
328+ _rt_path : rt . pathname
329+ } , this )
330+ ) ;
331+ this . _view . update ( ) ;
311332 } ;
312333
313- this . _handle_js_retrieved_cookies = function ( status , message , rt_id , active_tab_counter )
334+ this . _handle_js_retrieved_cookies = function ( status , message , rt_id )
314335 {
315- if ( this . _active_tab_count === active_tab_counter )
336+ const STATUS = 0 ;
337+ const DATA = 2 ;
338+ if ( status === SUCCESS && message [ STATUS ] == "completed" )
316339 {
317- const STATUS = 0 ;
318- const DATA = 2 ;
319- if ( status === 0 && message [ STATUS ] == "completed" )
340+ var rt = this . _rts [ rt_id ] || { } ;
341+ var cookie_string = message [ DATA ] ;
342+ if ( cookie_string && cookie_string . length > 0 )
320343 {
321- var rt = this . _rts [ rt_id ] || { } ;
322- var cookie_string = message [ DATA ] ;
323- if ( cookie_string && cookie_string . length > 0 )
344+ var cookies = cookie_string . split ( '; ' ) ;
345+ for ( var i = 0 , cookie_info ; cookie_info = cookies [ i ] ; i ++ )
324346 {
325- var cookies = cookie_string . split ( '; ' ) ;
326- for ( var i = 0 , cookie_info ; cookie_info = cookies [ i ] ; i ++ )
327- {
328- var pos = cookie_info . indexOf ( '=' ) ;
329- var has_value = pos !== - 1 ;
330- this . cookie_list . push (
331- new cls . CookieManager . Cookie ( {
332- name : has_value ? cookie_info . slice ( 0 , pos ) : cookie_info ,
333- value : has_value ? decodeURIComponent ( cookie_info . slice ( pos + 1 ) ) : null ,
334- _rt_id : rt_id ,
335- _rt_protocol : rt . protocol ,
336- _rt_hostname : rt . hostname ,
337- _rt_path : rt . pathname
338- } , this )
339- ) ;
340- } ;
341- }
347+ var pos = cookie_info . indexOf ( '=' ) ;
348+ var has_value = pos !== - 1 ;
349+ this . cookie_list . push (
350+ new cls . CookieManager . Cookie ( {
351+ name : has_value ? cookie_info . slice ( 0 , pos ) : cookie_info ,
352+ value : has_value ? decodeURIComponent ( cookie_info . slice ( pos + 1 ) ) : null ,
353+ _rt_id : rt_id ,
354+ _rt_protocol : rt . protocol ,
355+ _rt_hostname : rt . hostname ,
356+ _rt_path : rt . pathname
357+ } , this )
358+ ) ;
359+ } ;
342360 }
343- this . _view . update ( ) ;
344361 }
362+ this . _view . update ( ) ;
345363 } ;
346364
347365 this . _init = function ( view )
348366 {
349367 this . _view = view ;
350368 this . cookie_list = [ ] ;
351369 this . _rts = { } ;
352- this . _active_tab_count = 0 ;
370+ this . _active_dom_rt_ids = [ ] ;
371+ this . _is_active = false ;
353372 window . messages . addListener ( 'active-tab' , this . _on_active_tab . bind ( this ) ) ;
354373 window . messages . addListener ( 'profile-disabled' , this . _on_profile_disabled . bind ( this ) ) ;
355374 } ;
0 commit comments