2022-10-09 05:53:08 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
|
2022-10-13 00:52:58 +03:00
|
|
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
2022-10-09 05:53:08 +03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibJS/Heap/Heap.h>
|
|
|
|
#include <LibJS/Runtime/Realm.h>
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
|
|
#include <LibWeb/HTML/Navigator.h>
|
2022-10-13 00:52:58 +03:00
|
|
|
#include <LibWeb/HTML/Scripting/Environments.h>
|
|
|
|
#include <LibWeb/HTML/Window.h>
|
|
|
|
#include <LibWeb/Page/Page.h>
|
2022-10-09 05:53:08 +03:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2023-02-15 21:52:40 +03:00
|
|
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<Navigator>> Navigator::create(JS::Realm& realm)
|
2022-10-09 05:53:08 +03:00
|
|
|
{
|
2023-02-15 21:52:40 +03:00
|
|
|
return MUST_OR_THROW_OOM(realm.heap().allocate<Navigator>(realm, realm));
|
2022-10-09 05:53:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Navigator::Navigator(JS::Realm& realm)
|
|
|
|
: PlatformObject(realm)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Navigator::~Navigator() = default;
|
|
|
|
|
2023-01-28 20:33:35 +03:00
|
|
|
JS::ThrowCompletionOr<void> Navigator::initialize(JS::Realm& realm)
|
2023-01-10 14:28:20 +03:00
|
|
|
{
|
2023-01-28 20:33:35 +03:00
|
|
|
MUST_OR_THROW_OOM(Base::initialize(realm));
|
2023-01-10 14:28:20 +03:00
|
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::NavigatorPrototype>(realm, "Navigator"));
|
2023-01-28 20:33:35 +03:00
|
|
|
|
|
|
|
return {};
|
2023-01-10 14:28:20 +03:00
|
|
|
}
|
|
|
|
|
2022-10-13 00:52:58 +03:00
|
|
|
// https://w3c.github.io/webdriver/#dfn-webdriver
|
|
|
|
bool Navigator::webdriver() const
|
|
|
|
{
|
|
|
|
// Returns true if webdriver-active flag is set, false otherwise.
|
|
|
|
|
|
|
|
// NOTE: The NavigatorAutomationInformation interface should not be exposed on WorkerNavigator.
|
|
|
|
auto const& window = verify_cast<HTML::Window>(HTML::current_global_object());
|
|
|
|
return window.page()->is_webdriver_active();
|
|
|
|
}
|
|
|
|
|
2022-10-09 05:53:08 +03:00
|
|
|
}
|