mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:02:44 +00:00 
			
		
		
		
	LibWeb: Add 'is scripting enabled' concept to EnvironmentSettingsObject
This is now the source of truth for 'user enabled/disabled scripting', but it has to ask the window's page, which actually stores the setting. Also use this new functionality in two places where it was previously marked as a FIXME.
This commit is contained in:
		
							parent
							
								
									f60a2a1d80
								
							
						
					
					
						commit
						7bdbac7fd9
					
				
					 6 changed files with 42 additions and 4 deletions
				
			
		|  | @ -11,6 +11,7 @@ | |||
| #include <LibWeb/HTML/PromiseRejectionEvent.h> | ||||
| #include <LibWeb/HTML/Scripting/Environments.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| #include <LibWeb/Page/Page.h> | ||||
| 
 | ||||
| namespace Web::HTML { | ||||
| 
 | ||||
|  | @ -68,7 +69,9 @@ RunScriptDecision EnvironmentSettingsObject::can_run_script() | |||
|     if (is<Bindings::WindowObject>(global_object()) && !verify_cast<Bindings::WindowObject>(global_object()).impl().associated_document().is_fully_active()) | ||||
|         return RunScriptDecision::DoNotRun; | ||||
| 
 | ||||
|     // FIXME: 2. If scripting is disabled for settings, then return "do not run".
 | ||||
|     // 2. If scripting is disabled for settings, then return "do not run".
 | ||||
|     if (is_scripting_disabled()) | ||||
|         return RunScriptDecision::DoNotRun; | ||||
| 
 | ||||
|     // 3. Return "run".
 | ||||
|     return RunScriptDecision::Run; | ||||
|  | @ -234,6 +237,31 @@ void EnvironmentSettingsObject::notify_about_rejected_promises(Badge<EventLoop>) | |||
|     }); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-script
 | ||||
| bool EnvironmentSettingsObject::is_scripting_enabled() const | ||||
| { | ||||
|     // Scripting is enabled for an environment settings object settings when all of the following conditions are true:
 | ||||
|     // The user agent supports scripting.
 | ||||
|     // NOTE: This is always true in LibWeb :^)
 | ||||
| 
 | ||||
|     // The user has not disabled scripting for settings at this time. (User agents may provide users with the option to disable scripting globally, or in a finer-grained manner, e.g., on a per-origin basis, down to the level of individual environment settings objects.)
 | ||||
|     auto document = const_cast<EnvironmentSettingsObject&>(*this).responsible_document(); | ||||
|     VERIFY(document); | ||||
|     if (!document->window().page()->is_scripting_enabled()) | ||||
|         return false; | ||||
| 
 | ||||
|     // FIXME: Either settings's global object is not a Window object, or settings's global object's associated Document's active sandboxing flag set does not have its sandboxed scripts browsing context flag set.
 | ||||
| 
 | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-noscript
 | ||||
| bool EnvironmentSettingsObject::is_scripting_disabled() const | ||||
| { | ||||
|     // Scripting is disabled for an environment settings object when scripting is not enabled for it, i.e., when any of the above conditions are false.
 | ||||
|     return !is_scripting_enabled(); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#incumbent-settings-object
 | ||||
| EnvironmentSettingsObject& incumbent_settings_object() | ||||
| { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Linus Groh
						Linus Groh