2020-04-03 18:10:20 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-03 18:10:20 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-05-25 13:55:46 +01:00
|
|
|
#include <LibJS/Runtime/Array.h>
|
2020-04-18 13:18:06 +02:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2020-04-03 18:10:20 +02:00
|
|
|
#include <LibWeb/Bindings/NavigatorObject.h>
|
2020-06-01 20:42:50 +02:00
|
|
|
#include <LibWeb/Loader/ResourceLoader.h>
|
2020-04-03 18:10:20 +02:00
|
|
|
|
|
|
|
|
namespace Web {
|
|
|
|
|
namespace Bindings {
|
|
|
|
|
|
2020-06-20 17:28:13 +02:00
|
|
|
NavigatorObject::NavigatorObject(JS::GlobalObject& global_object)
|
2020-06-23 17:21:53 +02:00
|
|
|
: Object(*global_object.object_prototype())
|
2020-04-03 18:10:20 +02:00
|
|
|
{
|
2020-06-20 17:28:13 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-22 17:50:18 +02:00
|
|
|
void NavigatorObject::initialize(JS::GlobalObject& global_object)
|
2020-06-20 17:28:13 +02:00
|
|
|
{
|
2020-07-22 17:50:18 +02:00
|
|
|
auto& heap = this->heap();
|
2021-10-22 01:34:06 +03:00
|
|
|
auto* languages = MUST(JS::Array::create(global_object, 0));
|
2020-07-22 17:50:18 +02:00
|
|
|
languages->indexed_properties().append(js_string(heap, "en-US"));
|
2020-05-25 13:55:46 +01:00
|
|
|
|
2021-07-05 15:03:31 +03:00
|
|
|
// FIXME: All of these should be in Navigator's prototype and be native accessors
|
2021-07-06 02:15:08 +03:00
|
|
|
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);
|
2021-10-02 23:52:27 +01:00
|
|
|
define_direct_property("language", languages->get_without_side_effects(0), attr);
|
2021-07-06 02:15:08 +03:00
|
|
|
define_direct_property("languages", languages, attr);
|
|
|
|
|
define_direct_property("platform", js_string(heap, "SerenityOS"), attr);
|
|
|
|
|
define_direct_property("product", js_string(heap, "Gecko"), attr);
|
2020-05-21 12:58:57 +02:00
|
|
|
|
2021-10-31 08:35:06 -04:00
|
|
|
define_native_accessor("userAgent", user_agent_getter, {}, JS::Attribute::Configurable | JS::Attribute::Enumerable);
|
|
|
|
|
define_native_accessor("cookieEnabled", cookie_enabled_getter, {}, JS::Attribute::Configurable | JS::Attribute::Enumerable);
|
2021-09-26 19:14:19 +02:00
|
|
|
|
|
|
|
|
// FIXME: Reflect actual connectivity status.
|
|
|
|
|
define_direct_property("onLine", JS::Value(true), attr);
|
2020-04-03 18:10:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigatorObject::~NavigatorObject()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-31 08:35:06 -04:00
|
|
|
JS_DEFINE_NATIVE_FUNCTION(NavigatorObject::user_agent_getter)
|
2020-05-21 12:58:57 +02:00
|
|
|
{
|
2020-09-27 18:36:49 +02:00
|
|
|
return JS::js_string(vm, ResourceLoader::the().user_agent());
|
2020-04-03 18:10:20 +02:00
|
|
|
}
|
2020-05-21 12:58:57 +02:00
|
|
|
|
2021-10-31 08:35:06 -04:00
|
|
|
JS_DEFINE_NATIVE_FUNCTION(NavigatorObject::cookie_enabled_getter)
|
2021-10-02 13:50:40 +01:00
|
|
|
{
|
|
|
|
|
// No way of disabling cookies right now :^)
|
|
|
|
|
return JS::Value(true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 12:58:57 +02:00
|
|
|
}
|
|
|
|
|
|
2020-04-03 18:10:20 +02:00
|
|
|
}
|