2020-04-03 13:10:20 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-03 13:10:20 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-05-25 09:55:46 -03:00
|
|
|
#include <LibJS/Runtime/Array.h>
|
2020-04-18 08:18:06 -03:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2020-04-03 13:10:20 -03:00
|
|
|
#include <LibWeb/Bindings/NavigatorObject.h>
|
2020-06-01 15:42:50 -03:00
|
|
|
#include <LibWeb/Loader/ResourceLoader.h>
|
2020-04-03 13:10:20 -03:00
|
|
|
|
|
|
|
|
namespace Web {
|
|
|
|
|
namespace Bindings {
|
|
|
|
|
|
2020-06-20 12:28:13 -03:00
|
|
|
NavigatorObject::NavigatorObject(JS::GlobalObject& global_object)
|
2020-06-23 12:21:53 -03:00
|
|
|
: Object(*global_object.object_prototype())
|
2020-04-03 13:10:20 -03:00
|
|
|
{
|
2020-06-20 12:28:13 -03:00
|
|
|
}
|
|
|
|
|
|
2020-07-22 12:50:18 -03:00
|
|
|
void NavigatorObject::initialize(JS::GlobalObject& global_object)
|
2020-06-20 12:28:13 -03:00
|
|
|
{
|
2020-07-22 12:50:18 -03:00
|
|
|
auto& heap = this->heap();
|
2021-07-03 19:36:44 -03:00
|
|
|
auto* languages = JS::Array::create(global_object, 0);
|
2020-07-22 12:50:18 -03:00
|
|
|
languages->indexed_properties().append(js_string(heap, "en-US"));
|
2020-05-25 09:55:46 -03:00
|
|
|
|
2021-07-05 09:03:31 -03:00
|
|
|
// FIXME: All of these should be in Navigator's prototype and be native accessors
|
2021-07-05 20: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);
|
|
|
|
|
define_direct_property("language", languages->get(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);
|
2020-05-21 07:58:57 -03:00
|
|
|
|
2021-07-05 19:12:54 -03:00
|
|
|
define_native_accessor("userAgent", user_agent_getter, {}, JS::Attribute::Configurable | JS::Attribute::Enumerable);
|
2020-04-03 13:10:20 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigatorObject::~NavigatorObject()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-05 09:03:31 -03:00
|
|
|
JS_DEFINE_NATIVE_FUNCTION(NavigatorObject::user_agent_getter)
|
2020-05-21 07:58:57 -03:00
|
|
|
{
|
2020-09-27 13:36:49 -03:00
|
|
|
return JS::js_string(vm, ResourceLoader::the().user_agent());
|
2020-04-03 13:10:20 -03:00
|
|
|
}
|
2020-05-21 07:58:57 -03:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-03 13:10:20 -03:00
|
|
|
}
|