NavigatorObject.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/Array.h>
  7. #include <LibJS/Runtime/GlobalObject.h>
  8. #include <LibWeb/Bindings/NavigatorObject.h>
  9. #include <LibWeb/Loader/ResourceLoader.h>
  10. namespace Web {
  11. namespace Bindings {
  12. NavigatorObject::NavigatorObject(JS::GlobalObject& global_object)
  13. : Object(*global_object.object_prototype())
  14. {
  15. }
  16. void NavigatorObject::initialize(JS::GlobalObject& global_object)
  17. {
  18. auto& heap = this->heap();
  19. auto* languages = JS::Array::create(global_object, 0);
  20. languages->indexed_properties().append(js_string(heap, "en-US"));
  21. // FIXME: All of these should be in Navigator's prototype and be native accessors
  22. define_property("appCodeName", js_string(heap, "Mozilla"));
  23. define_property("appName", js_string(heap, "Netscape"));
  24. define_property("appVersion", js_string(heap, "4.0"));
  25. define_property("language", languages->get(0));
  26. define_property("languages", languages);
  27. define_property("platform", js_string(heap, "SerenityOS"));
  28. define_property("product", js_string(heap, "Gecko"));
  29. define_native_accessor("userAgent", user_agent_getter, {});
  30. }
  31. NavigatorObject::~NavigatorObject()
  32. {
  33. }
  34. JS_DEFINE_NATIVE_FUNCTION(NavigatorObject::user_agent_getter)
  35. {
  36. return JS::js_string(vm, ResourceLoader::the().user_agent());
  37. }
  38. }
  39. }