ladybird/Userland/Libraries/LibWeb/HTML/Navigator.cpp
Luke Wilde 5e422bdae0 LibWeb: Move pdfViewerSupported's answer to Page
This will also be accessed by navigator.{plugins,mimeTypes} to
determine if they should expose any information.
2023-02-28 12:36:14 +01:00

57 lines
1.8 KiB
C++

/*
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* 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>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Page/Page.h>
namespace Web::HTML {
WebIDL::ExceptionOr<JS::NonnullGCPtr<Navigator>> Navigator::create(JS::Realm& realm)
{
return MUST_OR_THROW_OOM(realm.heap().allocate<Navigator>(realm, realm));
}
Navigator::Navigator(JS::Realm& realm)
: PlatformObject(realm)
{
}
Navigator::~Navigator() = default;
JS::ThrowCompletionOr<void> Navigator::initialize(JS::Realm& realm)
{
MUST_OR_THROW_OOM(Base::initialize(realm));
set_prototype(&Bindings::ensure_web_prototype<Bindings::NavigatorPrototype>(realm, "Navigator"));
return {};
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-pdfviewerenabled
bool Navigator::pdf_viewer_enabled() const
{
// The NavigatorPlugins mixin's pdfViewerEnabled getter steps are to return the user agent's PDF viewer supported.
// NOTE: THe NavigatorPlugins mixin should only be exposed on the Window object.
auto const& window = verify_cast<HTML::Window>(HTML::current_global_object());
return window.page()->pdf_viewer_supported();
}
// 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();
}
}