/* * Copyright (c) 2022, Andrew Kaster * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include namespace Web::HTML { WebIDL::ExceptionOr> Navigator::create(JS::Realm& realm) { return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm)); } Navigator::Navigator(JS::Realm& realm) : PlatformObject(realm) { } Navigator::~Navigator() = default; JS::ThrowCompletionOr Navigator::initialize(JS::Realm& realm) { MUST_OR_THROW_OOM(Base::initialize(realm)); set_prototype(&Bindings::ensure_web_prototype(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::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::current_global_object()); return window.page()->is_webdriver_active(); } void Navigator::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); visitor.visit(m_mime_type_array); visitor.visit(m_plugin_array); } JS::ThrowCompletionOr> Navigator::mime_types() { if (!m_mime_type_array) m_mime_type_array = TRY(heap().allocate(realm(), realm())); return *m_mime_type_array; } JS::ThrowCompletionOr> Navigator::plugins() { if (!m_plugin_array) m_plugin_array = TRY(heap().allocate(realm(), realm())); return *m_plugin_array; } }