2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/*
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Copyright  ( c )  2023 ,  Andrew  Kaster  < akaster @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:14:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  Copyright  ( c )  2024 ,  Tim  Ledbetter  < timledbetter @ gmail . com > 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  SPDX - License - Identifier :  BSD - 2 - Clause 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-08 04:03:55 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibWeb/Bindings/PrincipalHostDefined.h> 
  
						 
					
						
							
								
									
										
										
										
											2025-05-18 14:11:56 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibWeb/HTML/DedicatedWorkerGlobalScope.h> 
  
						 
					
						
							
								
									
										
										
										
											2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# include  <LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibWeb/HTML/WorkerGlobalScope.h> 
  
						 
					
						
							
								
									
										
										
										
											2024-07-04 11:06:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibWeb/HighResolutionTime/TimeOrigin.h> 
  
						 
					
						
							
								
									
										
										
										
											2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								namespace  Web : : HTML  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-15 04:01:23 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								GC_DEFINE_ALLOCATOR ( WorkerEnvironmentSettingsObject ) ;  
						 
					
						
							
								
									
										
										
										
											2023-11-19 19:47:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:14:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// https://html.spec.whatwg.org/multipage/workers.html#set-up-a-worker-environment-settings-object
  
						 
					
						
							
								
									
										
										
										
											2024-11-15 04:01:23 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								GC : : Ref < WorkerEnvironmentSettingsObject >  WorkerEnvironmentSettingsObject : : setup ( GC : : Ref < Page >  page ,  NonnullOwnPtr < JS : : ExecutionContext >  execution_context ,  SerializedEnvironmentSettingsObject  const &  outside_settings ,  HighResolutionTime : : DOMHighResTimeStamp  unsafe_worker_creation_time )  
						 
					
						
							
								
									
										
										
										
											2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2024-07-04 11:06:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 1. Let inherited origin be outside settings's origin.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  inherited_origin  =  outside_settings . origin ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:14:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 2. Let realm be the value of execution context's Realm component.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    auto  realm  =  execution_context - > realm ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    VERIFY ( realm ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:14:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 3. Let worker global scope be realm's global object.
 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-21 09:12:05 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  worker  =  as < HTML : : WorkerGlobalScope > ( realm - > global_object ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:14:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 4. Let settings object be a new environment settings object whose algorithms are defined as follows:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // NOTE: See the functions defined for this class.
 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-07 10:08:14 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  settings_object  =  realm - > create < WorkerEnvironmentSettingsObject > ( move ( execution_context ) ,  worker ,  unsafe_worker_creation_time ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    settings_object - > target_browsing_context  =  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-04 11:06:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    settings_object - > m_origin  =  move ( inherited_origin ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:14:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // FIXME: 5. Set settings object's id to a new unique opaque string, creation URL to worker global scope's url, top-level creation URL to null, target browsing context to null, and active service worker to null.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-04 11:06:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 6. If worker global scope is a DedicatedWorkerGlobalScope object, then set settings object's top-level origin to outside settings's top-level origin.
 
							 
						 
					
						
							
								
									
										
										
										
											2025-05-18 14:11:56 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( is < DedicatedWorkerGlobalScope > ( worker ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-04 11:06:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        settings_object - > top_level_origin  =  outside_settings . top_level_origin ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:14:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // FIXME: 7. Otherwise, set settings object's top-level origin to an implementation-defined value.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 8. Set realm's [[HostDefined]] field to settings object.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-14 05:50:17 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  intrinsics  =  realm - > create < Bindings : : Intrinsics > ( * realm ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-26 21:02:28 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  host_defined  =  make < Bindings : : PrincipalHostDefined > ( settings_object ,  intrinsics ,  page ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    realm - > set_host_defined ( move ( host_defined ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Non-Standard: We cannot fully initialize worker object until *after* the we set up
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    //    the realm's [[HostDefined]] internal slot as the internal slot contains the web platform intrinsics
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    worker . initialize_web_interfaces ( { } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:14:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // 9. Return settings object.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  settings_object ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-23 18:51:03 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								URL : : URL  WorkerEnvironmentSettingsObject : : api_base_url ( )  const  
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:46:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Return worker global scope's url.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  m_global_scope - > url ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-23 18:51:03 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								URL : : Origin  WorkerEnvironmentSettingsObject : : origin ( )  const  
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:46:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // FIXME: Return a unique opaque origin if worker global scope's url's scheme is "data", and inherited origin otherwise.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  m_origin ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-25 14:30:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								GC : : Ref < PolicyContainer >  WorkerEnvironmentSettingsObject : : policy_container ( )  const  
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:46:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Return worker global scope's policy container.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  m_global_scope - > policy_container ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-23 18:51:03 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								CanUseCrossOriginIsolatedAPIs  WorkerEnvironmentSettingsObject : : cross_origin_isolated_capability ( )  const  
						 
					
						
							
								
									
										
										
										
											2024-05-23 11:46:41 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // FIXME: Return worker global scope's cross-origin isolated capability.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  CanUseCrossOriginIsolatedAPIs : : No ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-07 10:08:14 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								double  WorkerEnvironmentSettingsObject : : time_origin ( )  const  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Return the result of coarsening unsafeWorkerCreationTime with worker global scope's cross-origin isolated capability.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  HighResolutionTime : : coarsen_time ( m_unsafe_worker_creation_time ,  cross_origin_isolated_capability ( )  = =  CanUseCrossOriginIsolatedAPIs : : Yes ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-08 11:47:41 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								void  WorkerEnvironmentSettingsObject : : visit_edges ( JS : : Cell : : Visitor &  visitor )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Base : : visit_edges ( visitor ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    visitor . visit ( m_global_scope ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}