From 0d7f83d8d30cf0561ebb5de57642d2a8372b91da Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Fri, 31 Mar 2023 15:56:20 +0100 Subject: [PATCH] WIP keyboard-lock mock implementation See also: https://github.com/WebKit/standards-positions/issues/182 --- Source/WebCore/CMakeLists.txt | 4 ++ Source/WebCore/Headers.cmake | 2 + .../Modules/keyboard-lock/Keyboard.cpp | 66 ++++++++++++++++++ .../WebCore/Modules/keyboard-lock/Keyboard.h | 58 ++++++++++++++++ .../Modules/keyboard-lock/Keyboard.idl | 35 ++++++++++ .../keyboard-lock/Navigator+Keyboard.idl | 8 +++ .../keyboard-lock/NavigatorKeyboard.cpp | 69 +++++++++++++++++++ .../Modules/keyboard-lock/NavigatorKeyboard.h | 51 ++++++++++++++ Source/WebCore/Sources.txt | 2 + .../WebCore/bindings/js/WebCoreBuiltinNames.h | 2 + 10 files changed, 297 insertions(+) create mode 100644 Source/WebCore/Modules/keyboard-lock/Keyboard.cpp create mode 100644 Source/WebCore/Modules/keyboard-lock/Keyboard.h create mode 100644 Source/WebCore/Modules/keyboard-lock/Keyboard.idl create mode 100644 Source/WebCore/Modules/keyboard-lock/Navigator+Keyboard.idl create mode 100644 Source/WebCore/Modules/keyboard-lock/NavigatorKeyboard.cpp create mode 100644 Source/WebCore/Modules/keyboard-lock/NavigatorKeyboard.h diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt index 06cdf53c16128..34064acc30af3 100644 --- a/Source/WebCore/CMakeLists.txt +++ b/Source/WebCore/CMakeLists.txt @@ -41,6 +41,7 @@ set(WebCore_PRIVATE_INCLUDE_DIRECTORIES "${WEBCORE_DIR}/Modules/indexeddb/client" "${WEBCORE_DIR}/Modules/indexeddb/server" "${WEBCORE_DIR}/Modules/indexeddb/shared" + "${WEBCORE_DIR}/Modules/keyboard-lock" "${WEBCORE_DIR}/Modules/mediacapabilities" "${WEBCORE_DIR}/Modules/mediacontrols" "${WEBCORE_DIR}/Modules/mediarecorder" @@ -351,6 +352,9 @@ set(WebCore_NON_SVG_IDL_FILES Modules/indexeddb/IDBVersionChangeEvent.idl Modules/indexeddb/WindowOrWorkerGlobalScope+IndexedDatabase.idl + Modules/keyboard-lock/Navigator+Keyboard.idl + Modules/keyboard-lock/Keyboard.idl + Modules/mediacapabilities/AudioConfiguration.idl Modules/mediacapabilities/ColorGamut.idl Modules/mediacapabilities/HdrMetadataType.idl diff --git a/Source/WebCore/Headers.cmake b/Source/WebCore/Headers.cmake index c6342ba108723..fe48a7eaf9ca8 100644 --- a/Source/WebCore/Headers.cmake +++ b/Source/WebCore/Headers.cmake @@ -258,6 +258,8 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS Modules/indexeddb/shared/IDBResultData.h Modules/indexeddb/shared/IDBTransactionInfo.h + Modules/keyboard-lock/Keyboard.h + Modules/mediarecorder/MediaRecorderProvider.h Modules/mediasource/SampleMap.h diff --git a/Source/WebCore/Modules/keyboard-lock/Keyboard.cpp b/Source/WebCore/Modules/keyboard-lock/Keyboard.cpp new file mode 100644 index 0000000000000..f917c6c700bc1 --- /dev/null +++ b/Source/WebCore/Modules/keyboard-lock/Keyboard.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2021 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "Keyboard.h" + +#include "JSDOMPromiseDeferred.h" +#include "NotImplemented.h" +#include + +namespace WebCore { + +WTF_MAKE_ISO_ALLOCATED_IMPL(Keyboard); + +Ref Keyboard::create(NavigatorBase& navigator) +{ + return adoptRef(*new Keyboard(navigator)); +} + +Keyboard::Keyboard(NavigatorBase& navigator) + : m_navigator(navigator) +{ +} + +NavigatorBase* Keyboard::navigator() +{ + return m_navigator.get(); +} + +Keyboard::~Keyboard() = default; + +void Keyboard::lock(const std::optional>& keyCodes, DOMPromiseDeferred&& promise) +{ + UNUSED_PARAM(keyCodes); + notImplemented(); + promise.resolve(); +} + +void Keyboard::unlock() +{ + notImplemented(); +} + +} // namespace WebCore diff --git a/Source/WebCore/Modules/keyboard-lock/Keyboard.h b/Source/WebCore/Modules/keyboard-lock/Keyboard.h new file mode 100644 index 0000000000000..12d2a47c3dbfc --- /dev/null +++ b/Source/WebCore/Modules/keyboard-lock/Keyboard.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2021 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "IDLTypes.h" +#include +#include + +namespace WTF { +class String; +} + +namespace WebCore { + +class NavigatorBase; + +template class DOMPromiseDeferred; + +class Keyboard : public RefCounted { + WTF_MAKE_ISO_ALLOCATED(Keyboard); +public: + static Ref create(NavigatorBase&); + ~Keyboard(); + + NavigatorBase* navigator(); + void lock(const std::optional>& keyCodes, DOMPromiseDeferred&& promise); + void unlock(); + +private: + explicit Keyboard(NavigatorBase&); + + WeakPtr m_navigator; +}; + +} // namespace WebCore diff --git a/Source/WebCore/Modules/keyboard-lock/Keyboard.idl b/Source/WebCore/Modules/keyboard-lock/Keyboard.idl new file mode 100644 index 0000000000000..5dfe2e3296265 --- /dev/null +++ b/Source/WebCore/Modules/keyboard-lock/Keyboard.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2021 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +// https://wicg.github.io/keyboard-lock/#keyboard-interface + +[ + EnabledBySetting=PermissionsAPIEnabled, + GenerateIsReachable=ReachableFromNavigator, + Exposed=Window +] interface Keyboard { + Promise lock(optional sequence keyCodes = []); + undefined unlock(); +}; diff --git a/Source/WebCore/Modules/keyboard-lock/Navigator+Keyboard.idl b/Source/WebCore/Modules/keyboard-lock/Navigator+Keyboard.idl new file mode 100644 index 0000000000000..27f39a8ec6423 --- /dev/null +++ b/Source/WebCore/Modules/keyboard-lock/Navigator+Keyboard.idl @@ -0,0 +1,8 @@ + +// https://wicg.github.io/keyboard-lock/#navigator-interface + +[ + ImplementedBy=NavigatorKeyboard +] partial interface Navigator { + [SecureContext, SameObject] readonly attribute Keyboard keyboard; +}; diff --git a/Source/WebCore/Modules/keyboard-lock/NavigatorKeyboard.cpp b/Source/WebCore/Modules/keyboard-lock/NavigatorKeyboard.cpp new file mode 100644 index 0000000000000..0602186374206 --- /dev/null +++ b/Source/WebCore/Modules/keyboard-lock/NavigatorKeyboard.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2021 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "NavigatorKeyboard.h" + +#include "Navigator.h" +#include "Keyboard.h" + +namespace WebCore { + +NavigatorKeyboard::NavigatorKeyboard(Navigator& navigator) + : m_navigator(navigator) +{ +} + +Keyboard& NavigatorKeyboard::keyboard(Navigator& navigator) +{ + return NavigatorKeyboard::from(navigator).keyboard(); +} + +Keyboard& NavigatorKeyboard::keyboard() +{ + if (!m_keyboard) + m_keyboard = Keyboard::create(m_navigator); + + return *m_keyboard; +} + +NavigatorKeyboard& NavigatorKeyboard::from(Navigator& navigator) +{ + auto* supplement = static_cast(Supplement::from(&navigator, supplementName())); + if (!supplement) { + auto newSupplement = makeUnique(navigator); + supplement = newSupplement.get(); + provideTo(&navigator, supplementName(), WTFMove(newSupplement)); + } + + return *supplement; +} + +const char* NavigatorKeyboard::supplementName() +{ + return "NavigatorKeyboard"; +} + +} // namespace WebCore diff --git a/Source/WebCore/Modules/keyboard-lock/NavigatorKeyboard.h b/Source/WebCore/Modules/keyboard-lock/NavigatorKeyboard.h new file mode 100644 index 0000000000000..3685dfe08c00f --- /dev/null +++ b/Source/WebCore/Modules/keyboard-lock/NavigatorKeyboard.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2021 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "Supplementable.h" + +namespace WebCore { + +class Navigator; +class Keyboard; + +class NavigatorKeyboard final : public Supplement { + WTF_MAKE_FAST_ALLOCATED; +public: + explicit NavigatorKeyboard(Navigator&); + + static Keyboard& keyboard(Navigator&); + Keyboard& keyboard(); + +private: + static NavigatorKeyboard& from(Navigator&); + static const char* supplementName(); + + RefPtr m_keyboard; + Navigator& m_navigator; +}; + +} diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt index beba91e92e8df..7276f9d0f68a6 100644 --- a/Source/WebCore/Sources.txt +++ b/Source/WebCore/Sources.txt @@ -163,6 +163,8 @@ Modules/indexeddb/shared/IDBResourceIdentifier.cpp Modules/indexeddb/shared/IDBResultData.cpp Modules/indexeddb/shared/IDBTransactionInfo.cpp Modules/indexeddb/shared/IndexKey.cpp +Modules/keyboard-lock/Keyboard.cpp +Modules/keyboard-lock/NavigatorKeyboard.cpp Modules/mediacapabilities/MediaCapabilities.cpp Modules/mediacapabilities/NavigatorMediaCapabilities.cpp Modules/mediacapabilities/WorkerNavigatorMediaCapabilities.cpp diff --git a/Source/WebCore/bindings/js/WebCoreBuiltinNames.h b/Source/WebCore/bindings/js/WebCoreBuiltinNames.h index 9dd8961100cc0..b8e94a3a7086b 100644 --- a/Source/WebCore/bindings/js/WebCoreBuiltinNames.h +++ b/Source/WebCore/bindings/js/WebCoreBuiltinNames.h @@ -241,6 +241,7 @@ namespace WebCore { macro(InputEvent) \ macro(IntersectionObserver) \ macro(IntersectionObserverEntry) \ + macro(Keyboard) \ macro(KeyframeEffect) \ macro(Lock) \ macro(LockManager) \ @@ -269,6 +270,7 @@ namespace WebCore { macro(MockRTCRtpTransform) \ macro(NavigationPreloadManager) \ macro(NavigatorCredentials) \ + macro(NavigatorKeyboard) \ macro(NavigatorMediaDevices) \ macro(NavigatorPermissions) \ macro(NavigatorUserMedia) \