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>
|
2022-04-05 17:54:04 -03:00
|
|
|
#include <LibWeb/Bindings/NavigatorPrototype.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 {
|
|
|
|
|
|
2022-08-15 20:20:49 -03:00
|
|
|
NavigatorObject::NavigatorObject(JS::Realm& realm)
|
2022-09-03 13:43:24 -03:00
|
|
|
: Object(verify_cast<HTML::Window>(realm.global_object()).cached_web_prototype("Navigator"))
|
2020-04-03 13:10:20 -03:00
|
|
|
{
|
2020-06-20 12:28:13 -03:00
|
|
|
}
|
|
|
|
|
|
2022-08-15 20:20:49 -03:00
|
|
|
void NavigatorObject::initialize(JS::Realm& realm)
|
2020-06-20 12:28:13 -03:00
|
|
|
{
|
2020-07-22 12:50:18 -03:00
|
|
|
auto& heap = this->heap();
|
2022-08-15 20:20:49 -03:00
|
|
|
auto* languages = MUST(JS::Array::create(realm, 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);
|
2021-10-02 19:52:27 -03:00
|
|
|
define_direct_property("language", languages->get_without_side_effects(0), attr);
|
2021-07-05 20: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 07:58:57 -03:00
|
|
|
|
2022-08-22 17:47:35 -03:00
|
|
|
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);
|
2021-09-26 14:14:19 -03:00
|
|
|
|
2022-08-22 17:47:35 -03:00
|
|
|
define_native_function(realm, "javaEnabled", java_enabled, 0, JS::Attribute::Configurable | JS::Attribute::Enumerable);
|
2022-03-26 07:49:31 -03:00
|
|
|
|
2021-09-26 14:14:19 -03:00
|
|
|
// FIXME: Reflect actual connectivity status.
|
|
|
|
|
define_direct_property("onLine", JS::Value(true), attr);
|
2020-04-03 13:10:20 -03:00
|
|
|
}
|
|
|
|
|
|
2021-10-31 09:35:06 -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
|
|
|
|
2021-10-31 09:35:06 -03:00
|
|
|
JS_DEFINE_NATIVE_FUNCTION(NavigatorObject::cookie_enabled_getter)
|
2021-10-02 09:50:40 -03:00
|
|
|
{
|
|
|
|
|
// No way of disabling cookies right now :^)
|
|
|
|
|
return JS::Value(true);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-26 07:49:31 -03:00
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 07:58:57 -03:00
|
|
|
}
|
|
|
|
|
|
2020-04-03 13:10:20 -03:00
|
|
|
}
|