mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 10:37:44 +00:00
LibWeb: Re-implement HTML::Navigator using IDL
Get rid of the bespoke NavigatorObject class and use the modern IDL strategies for creating platform objects to re-implement Navigator and its associcated mixin interfaces. While we're here, implement it in a way that brings WorkerNavigator up to spec :^)
This commit is contained in:
parent
14e1513077
commit
2d5bee256e
27 changed files with 343 additions and 208 deletions
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/NavigatorConstructor.h>
|
||||
#include <LibWeb/Bindings/NavigatorPrototype.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
NavigatorConstructor::NavigatorConstructor(JS::Realm& realm)
|
||||
: NativeFunction(*realm.intrinsics().function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
NavigatorConstructor::~NavigatorConstructor() = default;
|
||||
|
||||
JS::ThrowCompletionOr<JS::Value> NavigatorConstructor::call()
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "Navigator");
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::Object*> NavigatorConstructor::construct(FunctionObject&)
|
||||
{
|
||||
return vm().throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, "Navigator");
|
||||
}
|
||||
|
||||
void NavigatorConstructor::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
NativeFunction::initialize(realm);
|
||||
define_direct_property(vm.names.prototype, &cached_web_prototype(realm, "Navigator"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/NativeFunction.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
class NavigatorConstructor : public JS::NativeFunction {
|
||||
JS_OBJECT(NavigatorConstructor, JS::NativeFunction);
|
||||
|
||||
public:
|
||||
explicit NavigatorConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~NavigatorConstructor() override;
|
||||
|
||||
virtual JS::ThrowCompletionOr<JS::Value> call() override;
|
||||
virtual JS::ThrowCompletionOr<JS::Object*> construct(JS::FunctionObject& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
};
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/Array.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/NavigatorObject.h>
|
||||
#include <LibWeb/Bindings/NavigatorPrototype.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Bindings {
|
||||
|
||||
NavigatorObject::NavigatorObject(JS::Realm& realm)
|
||||
: Object(cached_web_prototype(realm, "Navigator"))
|
||||
{
|
||||
}
|
||||
|
||||
void NavigatorObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& heap = this->heap();
|
||||
auto* languages = MUST(JS::Array::create(realm, 0));
|
||||
languages->indexed_properties().append(js_string(heap, "en-US"));
|
||||
|
||||
// FIXME: All of these should be in Navigator's prototype and be native accessors
|
||||
u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
|
||||
define_direct_property("appCodeName", js_string(heap, "Mozilla"), attr);
|
||||
define_direct_property("appName", js_string(heap, "Netscape"), attr);
|
||||
define_direct_property("appVersion", js_string(heap, "4.0"), attr);
|
||||
define_direct_property("language", languages->get_without_side_effects(0), attr);
|
||||
define_direct_property("languages", languages, attr);
|
||||
define_direct_property("platform", js_string(heap, "SerenityOS"), attr);
|
||||
define_direct_property("product", js_string(heap, "Gecko"), attr);
|
||||
|
||||
define_native_accessor(realm, "userAgent", user_agent_getter, {}, JS::Attribute::Configurable | JS::Attribute::Enumerable);
|
||||
define_native_accessor(realm, "cookieEnabled", cookie_enabled_getter, {}, JS::Attribute::Configurable | JS::Attribute::Enumerable);
|
||||
|
||||
define_native_function(realm, "javaEnabled", java_enabled, 0, JS::Attribute::Configurable | JS::Attribute::Enumerable);
|
||||
|
||||
// FIXME: Reflect actual connectivity status.
|
||||
define_direct_property("onLine", JS::Value(true), attr);
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(NavigatorObject::user_agent_getter)
|
||||
{
|
||||
return JS::js_string(vm, ResourceLoader::the().user_agent());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(NavigatorObject::cookie_enabled_getter)
|
||||
{
|
||||
// No way of disabling cookies right now :^)
|
||||
return JS::Value(true);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-javaenabled
|
||||
JS_DEFINE_NATIVE_FUNCTION(NavigatorObject::java_enabled)
|
||||
{
|
||||
// The NavigatorPlugins mixin's javaEnabled() method steps are to return false.
|
||||
return JS::Value(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Bindings {
|
||||
|
||||
class NavigatorObject final : public JS::Object {
|
||||
JS_OBJECT(NavigatorObject, JS::Object);
|
||||
|
||||
public:
|
||||
NavigatorObject(JS::Realm&);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~NavigatorObject() override = default;
|
||||
|
||||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(user_agent_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(cookie_enabled_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(java_enabled);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
class NavigatorPrototype final : public JS::Object {
|
||||
JS_OBJECT(NavigatorPrototype, JS::Object);
|
||||
|
||||
public:
|
||||
explicit NavigatorPrototype(JS::Realm& realm)
|
||||
: JS::Object(*realm.intrinsics().object_prototype())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue