Navigator.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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).release_allocated_value_but_fixme_should_propagate_errors();
  18. }
  19. Navigator::Navigator(JS::Realm& realm)
  20. : PlatformObject(realm)
  21. {
  22. }
  23. Navigator::~Navigator() = default;
  24. JS::ThrowCompletionOr<void> Navigator::initialize(JS::Realm& realm)
  25. {
  26. MUST_OR_THROW_OOM(Base::initialize(realm));
  27. set_prototype(&Bindings::ensure_web_prototype<Bindings::NavigatorPrototype>(realm, "Navigator"));
  28. return {};
  29. }
  30. // https://w3c.github.io/webdriver/#dfn-webdriver
  31. bool Navigator::webdriver() const
  32. {
  33. // Returns true if webdriver-active flag is set, false otherwise.
  34. // NOTE: The NavigatorAutomationInformation interface should not be exposed on WorkerNavigator.
  35. auto const& window = verify_cast<HTML::Window>(HTML::current_global_object());
  36. return window.page()->is_webdriver_active();
  37. }
  38. }