Navigator.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
  3. * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibJS/Heap/Heap.h>
  8. #include <LibJS/Runtime/Realm.h>
  9. #include <LibWeb/Bindings/Intrinsics.h>
  10. #include <LibWeb/HTML/Navigator.h>
  11. #include <LibWeb/HTML/Scripting/Environments.h>
  12. #include <LibWeb/HTML/Window.h>
  13. #include <LibWeb/Page/Page.h>
  14. namespace Web::HTML {
  15. JS::NonnullGCPtr<Navigator> Navigator::create(JS::Realm& realm)
  16. {
  17. return realm.heap().allocate<Navigator>(realm, realm);
  18. }
  19. Navigator::Navigator(JS::Realm& realm)
  20. : PlatformObject(realm)
  21. {
  22. }
  23. Navigator::~Navigator() = default;
  24. void Navigator::initialize(JS::Realm& realm)
  25. {
  26. Base::initialize(realm);
  27. set_prototype(&Bindings::ensure_web_prototype<Bindings::NavigatorPrototype>(realm, "Navigator"));
  28. }
  29. // https://w3c.github.io/webdriver/#dfn-webdriver
  30. bool Navigator::webdriver() const
  31. {
  32. // Returns true if webdriver-active flag is set, false otherwise.
  33. // NOTE: The NavigatorAutomationInformation interface should not be exposed on WorkerNavigator.
  34. auto const& window = verify_cast<HTML::Window>(HTML::current_global_object());
  35. return window.page()->is_webdriver_active();
  36. }
  37. }