mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00
LibWeb: Implement 'Is secure context' AO
This commit is contained in:
parent
5d86eae119
commit
4baf0a4486
2 changed files with 33 additions and 0 deletions
|
@ -13,7 +13,9 @@
|
||||||
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
|
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
|
||||||
#include <LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h>
|
#include <LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h>
|
||||||
#include <LibWeb/HTML/Window.h>
|
#include <LibWeb/HTML/Window.h>
|
||||||
|
#include <LibWeb/HTML/WorkerGlobalScope.h>
|
||||||
#include <LibWeb/Page/Page.h>
|
#include <LibWeb/Page/Page.h>
|
||||||
|
#include <LibWeb/SecureContexts/AbstractOperations.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
@ -391,4 +393,34 @@ JS::Object& relevant_global_object(JS::Object const& object)
|
||||||
return relevant_realm(object).global_object();
|
return relevant_realm(object).global_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/webappapis.html#secure-context
|
||||||
|
bool is_secure_context(Environment const& environment)
|
||||||
|
{
|
||||||
|
// 1. If environment is an environment settings object, then:
|
||||||
|
if (is<EnvironmentSettingsObject>(environment)) {
|
||||||
|
// 1. Let global be environment's global object.
|
||||||
|
// FIXME: Add a const global_object() getter to ESO
|
||||||
|
auto& global = static_cast<EnvironmentSettingsObject&>(const_cast<Environment&>(environment)).global_object();
|
||||||
|
|
||||||
|
// 2. If global is a WorkerGlobalScope, then:
|
||||||
|
if (is<WorkerGlobalScope>(global)) {
|
||||||
|
// FIXME: 1. If global's owner set[0]'s relevant settings object is a secure context, then return true.
|
||||||
|
// NOTE: We only need to check the 0th item since they will necessarily all be consistent.
|
||||||
|
|
||||||
|
// 2. Return false.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: 3. If global is a WorkletGlobalScope, then return true.
|
||||||
|
// NOTE: Worklets can only be created in secure contexts.
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. If the result of Is url potentially trustworthy? given environment's top-level creation URL is "Potentially Trustworthy", then return true.
|
||||||
|
if (SecureContexts::is_url_potentially_trustworthy(environment.top_level_creation_url) == SecureContexts::Trustworthiness::PotentiallyTrustworthy)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// 3. Return false.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,5 +143,6 @@ JS::Realm& relevant_realm(JS::Object const&);
|
||||||
EnvironmentSettingsObject& relevant_settings_object(JS::Object const&);
|
EnvironmentSettingsObject& relevant_settings_object(JS::Object const&);
|
||||||
EnvironmentSettingsObject& relevant_settings_object(DOM::Node const&);
|
EnvironmentSettingsObject& relevant_settings_object(DOM::Node const&);
|
||||||
JS::Object& relevant_global_object(JS::Object const&);
|
JS::Object& relevant_global_object(JS::Object const&);
|
||||||
|
[[nodiscard]] bool is_secure_context(Environment const&);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue