@@ -150,6 +150,7 @@ impl FeltClientThread {
150150 // Define an observer
151151 #[ xpcom( implement( nsIObserver) , nonatomic) ]
152152 struct Observer {
153+ profile_ready : Arc < AtomicBool > ,
153154 thread_stop : Arc < AtomicBool > ,
154155 notify_restart : Arc < AtomicBool > ,
155156 }
@@ -163,6 +164,10 @@ impl FeltClientThread {
163164 data : * const u16 ,
164165 ) -> nsresult {
165166 match unsafe { CStr :: from_ptr ( topic) . to_str ( ) } {
167+ Ok ( "profile-after-change" ) => {
168+ trace ! ( "FeltClientThread::start_thread::observe() profile-after-change" ) ;
169+ self . profile_ready . store ( true , Ordering :: Relaxed ) ;
170+ }
166171 Ok ( "xpcom-shutdown-threads" ) => {
167172 trace ! ( "FeltClientThread::start_thread::observe() xpcom-shutdown-threads" ) ;
168173 self . thread_stop . store ( true , Ordering :: Relaxed ) ;
@@ -213,24 +218,35 @@ impl FeltClientThread {
213218 trace ! ( "FeltClientThread::start_thread(): get observer service" ) ;
214219 let obssvc: RefPtr < nsIObserverService > = xpcom:: components:: Observer :: service ( ) . unwrap ( ) ;
215220
221+ let profile_after_change = CString :: new ( "profile-after-change" ) . unwrap ( ) ;
216222 let xpcom_shutdown = CString :: new ( "xpcom-shutdown-threads" ) . unwrap ( ) ;
217223 let quit_application = CString :: new ( "quit-application" ) . unwrap ( ) ;
218224
225+ let profile_ready = Arc :: new ( AtomicBool :: new ( false ) ) ;
219226 let thread_stop = Arc :: new ( AtomicBool :: new ( false ) ) ;
220227 let notify_restart = Arc :: new ( AtomicBool :: new ( false ) ) ;
221228 let observer = Observer :: allocate ( InitObserver {
229+ profile_ready : profile_ready. clone ( ) ,
222230 thread_stop : thread_stop. clone ( ) ,
223231 notify_restart : notify_restart. clone ( ) ,
224232 } ) ;
225233 let mut rv = unsafe {
234+ obssvc. AddObserver (
235+ observer. coerce :: < nsIObserver > ( ) ,
236+ profile_after_change. as_ptr ( ) ,
237+ false ,
238+ )
239+ } ;
240+ assert ! ( rv. succeeded( ) ) ;
241+
242+ rv = unsafe {
226243 obssvc. AddObserver (
227244 observer. coerce :: < nsIObserver > ( ) ,
228245 xpcom_shutdown. as_ptr ( ) ,
229246 false ,
230247 )
231248 } ;
232249 assert ! ( rv. succeeded( ) ) ;
233- trace ! ( "FeltClientThread::start_thread(): added observers" ) ;
234250
235251 rv = unsafe {
236252 obssvc. AddObserver (
@@ -240,8 +256,10 @@ impl FeltClientThread {
240256 )
241257 } ;
242258 assert ! ( rv. succeeded( ) ) ;
259+ trace ! ( "FeltClientThread::start_thread(): added observers" ) ;
243260
244261 let barrier = self . startup_ready . clone ( ) ;
262+ let profile_ready_internal = profile_ready. clone ( ) ;
245263 let thread_stop_internal = thread_stop. clone ( ) ;
246264 let notify_restart_internal = notify_restart. clone ( ) ;
247265 let mut felt_client = self . ipc_client . take ( ) ;
@@ -250,17 +268,31 @@ impl FeltClientThread {
250268 trace ! ( "FeltClientThread::start_thread(): felt_client thread runnable" ) ;
251269 trace ! ( "FeltClientThread::start_thread(): felt_client version OK" ) ;
252270 if let Some ( rx) = felt_client. rx . take ( ) {
271+ let mut pending_cookies: Vec < String > = Vec :: new ( ) ;
272+
253273 loop {
254274 if notify_restart_internal. load ( Ordering :: Relaxed ) {
255275 notify_restart_internal. store ( false , Ordering :: Relaxed ) ;
256276 trace ! ( "FeltClientThread::felt_client::ipc_loop(): restart notification required!" ) ;
257277 felt_client. notify_restart ( ) ;
258278 }
259279
280+ if pending_cookies. len ( ) > 0 && profile_ready_internal. load ( Ordering :: Relaxed ) {
281+ trace ! ( "FeltClientThread::felt_client::ipc_loop(): Profile ready! Start cookies injection!" ) ;
282+ while let Some ( one_cookie) = pending_cookies. pop ( ) {
283+ utils:: inject_one_cookie ( one_cookie) ;
284+ }
285+ trace ! ( "FeltClientThread::felt_client::ipc_loop(): Profile ready! Finished cookies injection!" ) ;
286+ }
287+
260288 match rx. try_recv_timeout ( Duration :: from_millis ( 250 ) ) {
261289 Ok ( FeltMessage :: Cookie ( felt_cookie) ) => {
262290 trace ! ( "FeltClientThread::felt_client::ipc_loop(): received cookie: {}" , felt_cookie. clone( ) ) ;
263- utils:: inject_one_cookie ( felt_cookie) ;
291+ if profile_ready_internal. load ( Ordering :: Relaxed ) {
292+ utils:: inject_one_cookie ( felt_cookie) ;
293+ } else {
294+ pending_cookies. push ( felt_cookie) ;
295+ }
264296 } ,
265297 Ok ( FeltMessage :: BoolPreference ( ( name, value) ) ) => {
266298 trace ! ( "FeltClientThread::felt_client::ipc_loop(): BoolPreference({}, {})" , name, value) ;
0 commit comments