Navigator.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. set_prototype(&Bindings::cached_web_prototype(realm, "Navigator"));
  23. }
  24. Navigator::~Navigator() = default;
  25. // https://w3c.github.io/webdriver/#dfn-webdriver
  26. bool Navigator::webdriver() const
  27. {
  28. // Returns true if webdriver-active flag is set, false otherwise.
  29. // NOTE: The NavigatorAutomationInformation interface should not be exposed on WorkerNavigator.
  30. auto const& window = verify_cast<HTML::Window>(HTML::current_global_object());
  31. return window.page()->is_webdriver_active();
  32. }
  33. }