فهرست منبع

LibWeb: Define window.isSecureContext

Cameron Youell 2 سال پیش
والد
کامیت
204257526c
2فایلهای تغییر یافته به همراه10 افزوده شده و 0 حذف شده
  1. 9 0
      Userland/Libraries/LibWeb/HTML/Window.cpp
  2. 1 0
      Userland/Libraries/LibWeb/HTML/Window.h

+ 9 - 0
Userland/Libraries/LibWeb/HTML/Window.cpp

@@ -1137,6 +1137,7 @@ void Window::initialize_web_interfaces(Badge<WindowEnvironmentSettingsObject>)
     define_native_accessor(realm, "localStorage", local_storage_getter, {}, attr);
     define_native_accessor(realm, "sessionStorage", session_storage_getter, {}, attr);
     define_native_accessor(realm, "origin", origin_getter, {}, attr);
+    define_native_accessor(realm, "isSecureContext", is_secure_context_getter, {}, attr);
 
     // Legacy
     define_native_accessor(realm, "event", event_getter, event_setter, JS::Attribute::Enumerable);
@@ -1863,6 +1864,14 @@ JS_DEFINE_NATIVE_FUNCTION(Window::origin_getter)
     return JS::PrimitiveString::create(vm, impl->associated_document().origin().serialize());
 }
 
+// https://html.spec.whatwg.org/multipage/webappapis.html#dom-issecurecontext
+JS_DEFINE_NATIVE_FUNCTION(Window::is_secure_context_getter)
+{
+    auto* impl = TRY(impl_from(vm));
+    // The isSecureContext getter steps are to return true if this's relevant settings object is a secure context, or false otherwise.
+    return JS::Value(is_secure_context(impl->associated_document().relevant_settings_object()));
+}
+
 JS_DEFINE_NATIVE_FUNCTION(Window::local_storage_getter)
 {
     auto* impl = TRY(impl_from(vm));

+ 1 - 0
Userland/Libraries/LibWeb/HTML/Window.h

@@ -247,6 +247,7 @@ private:
     JS_DECLARE_NATIVE_FUNCTION(local_storage_getter);
     JS_DECLARE_NATIVE_FUNCTION(session_storage_getter);
     JS_DECLARE_NATIVE_FUNCTION(origin_getter);
+    JS_DECLARE_NATIVE_FUNCTION(is_secure_context_getter);
 
     JS_DECLARE_NATIVE_FUNCTION(open);
     JS_DECLARE_NATIVE_FUNCTION(alert);