haikuwebkit/Source/WebCore/dom/DeviceOrientationOrMotionPe...

48 lines
1.9 KiB
C
Raw Permalink Normal View History

Add support for Device Orientation / Motion permission API https://bugs.webkit.org/show_bug.cgi?id=195329 <rdar://problem/47645367> Reviewed by Geoffrey Garen. Source/WebCore: Add support for Device Orientation / Motion permission API: - https://github.com/w3c/deviceorientation/issues/57 Pages can add event listeners for 'deviceorientation' / 'devicemotion' events but such events will not be fired until the page's JavaScript calls DeviceOrientationEvent.requestPermission() / DeviceMotionEvent.requestPermission() and the user grants the request. The feature is currently behind an experimental feature flag, off by default. Tests: fast/device-orientation/device-motion-request-permission-denied.html fast/device-orientation/device-motion-request-permission-granted.html fast/device-orientation/device-motion-request-permission-user-gesture.html fast/device-orientation/device-orientation-request-permission-denied.html fast/device-orientation/device-orientation-request-permission-granted.html fast/device-orientation/device-orientation-request-permission-user-gesture.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * dom/DeviceMotionEvent.h: * dom/DeviceMotionEvent.idl: * dom/DeviceOrientationAndMotionAccessController.cpp: Added. (WebCore::DeviceOrientationAndMotionAccessController::DeviceOrientationAndMotionAccessController): (WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess): (WebCore::DeviceOrientationAndMotionAccessController::setAccessState): * dom/DeviceOrientationAndMotionAccessController.h: Added. (WebCore::DeviceOrientationAndMotionAccessController::accessState const): * dom/DeviceOrientationEvent.h: * dom/DeviceOrientationEvent.idl: * dom/DeviceOrientationOrMotionEvent.cpp: Added. (WebCore::DeviceOrientationOrMotionEvent::requestPermission): * dom/DeviceOrientationOrMotionEvent.h: Added. * dom/DeviceOrientationOrMotionEvent.idl: Added. * dom/DeviceOrientationOrMotionPermissionState.h: Added. * dom/DeviceOrientationOrMotionPermissionState.idl: Added. * dom/Document.cpp: (WebCore::Document::deviceOrientationAndMotionAccessController): * dom/Document.h: * dom/Event.cpp: * dom/MessagePort.cpp: * dom/Microtasks.cpp: * page/ChromeClient.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::addEventListener): (WebCore::DOMWindow::deviceOrientationController const): (WebCore::DOMWindow::deviceMotionController const): (WebCore::DOMWindow::isAllowedToUseDeviceMotionOrientation const): (WebCore::DOMWindow::isAllowedToAddDeviceMotionOrientationListener const): (WebCore::DOMWindow::startListeningForDeviceOrientationIfNecessary): (WebCore::DOMWindow::stopListeningForDeviceOrientationIfNecessary): (WebCore::DOMWindow::startListeningForDeviceMotionIfNecessary): (WebCore::DOMWindow::stopListeningForDeviceMotionIfNecessary): (WebCore::DOMWindow::removeEventListener): (WebCore::DOMWindow::removeAllEventListeners): * page/DOMWindow.h: * page/DeviceController.cpp: (WebCore::DeviceController::hasDeviceEventListener const): * page/DeviceController.h: * page/Settings.yaml: Source/WebKit: Add support for Device Orientation / Motion permission API: - https://github.com/w3c/deviceorientation/issues/57 This adds new SPI to WKUIDelegatePrivate, until we can make this API. * Shared/WebPreferences.yaml: * UIProcess/API/APIUIClient.h: (API::UIClient::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/API/C/WKPage.cpp: (WKPageSetPageUIClient): * UIProcess/API/C/WKPageUIClient.h: * UIProcess/API/Cocoa/WKUIDelegate.h: * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: * UIProcess/Cocoa/UIDelegate.h: * UIProcess/Cocoa/UIDelegate.mm: (WebKit::UIDelegate::setDelegate): (WebKit::UIDelegate::UIClient::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::requestDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess): * WebProcess/WebCoreSupport/WebChromeClient.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::nextDeviceOrientationAndMotionPermissionCallbackID): (WebKit::WebPage::shouldAllowDeviceOrientationAndMotionAccess): (WebKit::WebPage::didReceiveDeviceOrientationAndMotionAccessDecision): * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/WebPage.messages.in: Tools: Add test infrastructure to help test the Device Orientation / Motion permission API. * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::setShouldAllowDeviceOrientationAndMotionAccess): * WebKitTestRunner/InjectedBundle/TestRunner.h: * WebKitTestRunner/TestController.cpp: (WTR::shouldAllowDeviceOrientationAndMotionAccess): (WTR::TestController::createWebViewWithOptions): (WTR::TestController::resetStateToConsistentValues): (WTR::TestController::handleDeviceOrientationAndMotionAccessRequest): * WebKitTestRunner/TestController.h: (WTR::TestController::setShouldAllowDeviceOrientationAndMotionAccess): * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): LayoutTests: Add layout test coverage. * TestExpectations: * fast/device-orientation/device-motion-request-permission-denied-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-denied.html: Added. * fast/device-orientation/device-motion-request-permission-granted-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-granted.html: Added. * fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-user-gesture.html: Added. * fast/device-orientation/device-orientation-request-permission-denied-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-denied.html: Added. * fast/device-orientation/device-orientation-request-permission-granted-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-granted.html: Added. * fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-user-gesture.html: Added. * http/tests/events/device-orientation-motion-non-secure-context.html: * http/tests/events/device-orientation-motion-secure-context-expected.txt: * http/tests/events/device-orientation-motion-secure-context.html: * platform/ios-wk2/TestExpectations: * platform/ios/http/tests/events/device-orientation-motion-non-secure-context-expected.txt: * platform/ios/http/tests/events/device-orientation-motion-secure-context-expected.txt: Canonical link: https://commits.webkit.org/209800@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242664 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-09 00:30:45 +00:00
/*
* Copyright (C) 2019 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:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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 THE COPYRIGHT HOLDERS ``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 THE COPYRIGHT OWNER OR
* 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
Remember device orientation permission for the duration of the browsing session https://bugs.webkit.org/show_bug.cgi?id=196992 <rdar://problem/49946067> Reviewed by Alex Christensen. Source/WebCore: Use DeviceOrientationOrMotionPermissionState type more consistently in the code base instead of bool or Optional<bool>. Added "Prompt" value to this enumeration which is the default state and which indicates we should ask the client. * WebCore.xcodeproj/project.pbxproj: * dom/DeviceOrientationAndMotionAccessController.cpp: (WebCore::DeviceOrientationAndMotionAccessController::DeviceOrientationAndMotionAccessController): (WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess): * dom/DeviceOrientationAndMotionAccessController.h: (WebCore::DeviceOrientationAndMotionAccessController::accessState const): * dom/DeviceOrientationOrMotionEvent.cpp: (WebCore::DeviceOrientationOrMotionEvent::requestPermission): * dom/DeviceOrientationOrMotionPermissionState.h: * loader/DocumentLoader.h: (WebCore::DocumentLoader::deviceOrientationAndMotionAccessState const): (WebCore::DocumentLoader::setDeviceOrientationAndMotionAccessState): * page/ChromeClient.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::isAllowedToAddDeviceMotionOrientationListener const): Source/WebKit: Implement caching of device orientation permission decisions on the WebDeviceOrientationAndMotionAccessController, which is owned by the WebsiteDataStore. This way, if we already prompted the user of a given origin, we will remember the previous decision for the duration of the session and not prompt again. * Shared/WebsitePoliciesData.cpp: (WebKit::WebsitePoliciesData::encode const): (WebKit::WebsitePoliciesData::decode): * Shared/WebsitePoliciesData.h: * UIProcess/API/APIWebsitePolicies.cpp: (API::WebsitePolicies::copy const): (API::WebsitePolicies::data): * UIProcess/API/APIWebsitePolicies.h: * UIProcess/API/Cocoa/WKWebpagePreferences.mm: (toDeviceOrientationOrMotionPermissionState): (-[WKWebpagePreferences _setDeviceOrientationAndMotionAccessPolicy:]): (toWKWebsiteDeviceOrientationAndMotionAccessPolicy): (-[WKWebpagePreferences _deviceOrientationAndMotionAccessPolicy]): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.cpp: Added. (WebKit::WebDeviceOrientationAndMotionAccessController::shouldAllowDeviceOrientationAndMotionAccess): (WebKit::WebDeviceOrientationAndMotionAccessController::deviceOrientationPermission const): * UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.h: Copied from Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h. * UIProcess/WebsiteData/WebsiteDataStore.h: (WebKit::WebsiteDataStore::deviceOrientationAndMotionAccessController): * WebKit.xcodeproj/project.pbxproj: * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess): * WebProcess/WebCoreSupport/WebChromeClient.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::shouldAllowDeviceOrientationAndMotionAccess): * WebProcess/WebPage/WebPage.h: Tools: Add API test coverage. * TestWebKitAPI/Tests/WebKitCocoa/DeviceOrientation.mm: (-[DeviceOrientationPermissionUIDelegate _webView:shouldAllowDeviceOrientationAndMotionAccessRequestedByFrame:decisionHandler:]): (TEST): Canonical link: https://commits.webkit.org/211268@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244382 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-04-17 17:03:59 +00:00
#include <wtf/EnumTraits.h>
Add support for Device Orientation / Motion permission API https://bugs.webkit.org/show_bug.cgi?id=195329 <rdar://problem/47645367> Reviewed by Geoffrey Garen. Source/WebCore: Add support for Device Orientation / Motion permission API: - https://github.com/w3c/deviceorientation/issues/57 Pages can add event listeners for 'deviceorientation' / 'devicemotion' events but such events will not be fired until the page's JavaScript calls DeviceOrientationEvent.requestPermission() / DeviceMotionEvent.requestPermission() and the user grants the request. The feature is currently behind an experimental feature flag, off by default. Tests: fast/device-orientation/device-motion-request-permission-denied.html fast/device-orientation/device-motion-request-permission-granted.html fast/device-orientation/device-motion-request-permission-user-gesture.html fast/device-orientation/device-orientation-request-permission-denied.html fast/device-orientation/device-orientation-request-permission-granted.html fast/device-orientation/device-orientation-request-permission-user-gesture.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * dom/DeviceMotionEvent.h: * dom/DeviceMotionEvent.idl: * dom/DeviceOrientationAndMotionAccessController.cpp: Added. (WebCore::DeviceOrientationAndMotionAccessController::DeviceOrientationAndMotionAccessController): (WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess): (WebCore::DeviceOrientationAndMotionAccessController::setAccessState): * dom/DeviceOrientationAndMotionAccessController.h: Added. (WebCore::DeviceOrientationAndMotionAccessController::accessState const): * dom/DeviceOrientationEvent.h: * dom/DeviceOrientationEvent.idl: * dom/DeviceOrientationOrMotionEvent.cpp: Added. (WebCore::DeviceOrientationOrMotionEvent::requestPermission): * dom/DeviceOrientationOrMotionEvent.h: Added. * dom/DeviceOrientationOrMotionEvent.idl: Added. * dom/DeviceOrientationOrMotionPermissionState.h: Added. * dom/DeviceOrientationOrMotionPermissionState.idl: Added. * dom/Document.cpp: (WebCore::Document::deviceOrientationAndMotionAccessController): * dom/Document.h: * dom/Event.cpp: * dom/MessagePort.cpp: * dom/Microtasks.cpp: * page/ChromeClient.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::addEventListener): (WebCore::DOMWindow::deviceOrientationController const): (WebCore::DOMWindow::deviceMotionController const): (WebCore::DOMWindow::isAllowedToUseDeviceMotionOrientation const): (WebCore::DOMWindow::isAllowedToAddDeviceMotionOrientationListener const): (WebCore::DOMWindow::startListeningForDeviceOrientationIfNecessary): (WebCore::DOMWindow::stopListeningForDeviceOrientationIfNecessary): (WebCore::DOMWindow::startListeningForDeviceMotionIfNecessary): (WebCore::DOMWindow::stopListeningForDeviceMotionIfNecessary): (WebCore::DOMWindow::removeEventListener): (WebCore::DOMWindow::removeAllEventListeners): * page/DOMWindow.h: * page/DeviceController.cpp: (WebCore::DeviceController::hasDeviceEventListener const): * page/DeviceController.h: * page/Settings.yaml: Source/WebKit: Add support for Device Orientation / Motion permission API: - https://github.com/w3c/deviceorientation/issues/57 This adds new SPI to WKUIDelegatePrivate, until we can make this API. * Shared/WebPreferences.yaml: * UIProcess/API/APIUIClient.h: (API::UIClient::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/API/C/WKPage.cpp: (WKPageSetPageUIClient): * UIProcess/API/C/WKPageUIClient.h: * UIProcess/API/Cocoa/WKUIDelegate.h: * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: * UIProcess/Cocoa/UIDelegate.h: * UIProcess/Cocoa/UIDelegate.mm: (WebKit::UIDelegate::setDelegate): (WebKit::UIDelegate::UIClient::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::requestDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess): * WebProcess/WebCoreSupport/WebChromeClient.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::nextDeviceOrientationAndMotionPermissionCallbackID): (WebKit::WebPage::shouldAllowDeviceOrientationAndMotionAccess): (WebKit::WebPage::didReceiveDeviceOrientationAndMotionAccessDecision): * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/WebPage.messages.in: Tools: Add test infrastructure to help test the Device Orientation / Motion permission API. * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::setShouldAllowDeviceOrientationAndMotionAccess): * WebKitTestRunner/InjectedBundle/TestRunner.h: * WebKitTestRunner/TestController.cpp: (WTR::shouldAllowDeviceOrientationAndMotionAccess): (WTR::TestController::createWebViewWithOptions): (WTR::TestController::resetStateToConsistentValues): (WTR::TestController::handleDeviceOrientationAndMotionAccessRequest): * WebKitTestRunner/TestController.h: (WTR::TestController::setShouldAllowDeviceOrientationAndMotionAccess): * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): LayoutTests: Add layout test coverage. * TestExpectations: * fast/device-orientation/device-motion-request-permission-denied-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-denied.html: Added. * fast/device-orientation/device-motion-request-permission-granted-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-granted.html: Added. * fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-user-gesture.html: Added. * fast/device-orientation/device-orientation-request-permission-denied-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-denied.html: Added. * fast/device-orientation/device-orientation-request-permission-granted-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-granted.html: Added. * fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-user-gesture.html: Added. * http/tests/events/device-orientation-motion-non-secure-context.html: * http/tests/events/device-orientation-motion-secure-context-expected.txt: * http/tests/events/device-orientation-motion-secure-context.html: * platform/ios-wk2/TestExpectations: * platform/ios/http/tests/events/device-orientation-motion-non-secure-context-expected.txt: * platform/ios/http/tests/events/device-orientation-motion-secure-context-expected.txt: Canonical link: https://commits.webkit.org/209800@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242664 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-09 00:30:45 +00:00
namespace WebCore {
Remember device orientation permission for the duration of the browsing session https://bugs.webkit.org/show_bug.cgi?id=196992 <rdar://problem/49946067> Reviewed by Alex Christensen. Source/WebCore: Use DeviceOrientationOrMotionPermissionState type more consistently in the code base instead of bool or Optional<bool>. Added "Prompt" value to this enumeration which is the default state and which indicates we should ask the client. * WebCore.xcodeproj/project.pbxproj: * dom/DeviceOrientationAndMotionAccessController.cpp: (WebCore::DeviceOrientationAndMotionAccessController::DeviceOrientationAndMotionAccessController): (WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess): * dom/DeviceOrientationAndMotionAccessController.h: (WebCore::DeviceOrientationAndMotionAccessController::accessState const): * dom/DeviceOrientationOrMotionEvent.cpp: (WebCore::DeviceOrientationOrMotionEvent::requestPermission): * dom/DeviceOrientationOrMotionPermissionState.h: * loader/DocumentLoader.h: (WebCore::DocumentLoader::deviceOrientationAndMotionAccessState const): (WebCore::DocumentLoader::setDeviceOrientationAndMotionAccessState): * page/ChromeClient.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::isAllowedToAddDeviceMotionOrientationListener const): Source/WebKit: Implement caching of device orientation permission decisions on the WebDeviceOrientationAndMotionAccessController, which is owned by the WebsiteDataStore. This way, if we already prompted the user of a given origin, we will remember the previous decision for the duration of the session and not prompt again. * Shared/WebsitePoliciesData.cpp: (WebKit::WebsitePoliciesData::encode const): (WebKit::WebsitePoliciesData::decode): * Shared/WebsitePoliciesData.h: * UIProcess/API/APIWebsitePolicies.cpp: (API::WebsitePolicies::copy const): (API::WebsitePolicies::data): * UIProcess/API/APIWebsitePolicies.h: * UIProcess/API/Cocoa/WKWebpagePreferences.mm: (toDeviceOrientationOrMotionPermissionState): (-[WKWebpagePreferences _setDeviceOrientationAndMotionAccessPolicy:]): (toWKWebsiteDeviceOrientationAndMotionAccessPolicy): (-[WKWebpagePreferences _deviceOrientationAndMotionAccessPolicy]): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.cpp: Added. (WebKit::WebDeviceOrientationAndMotionAccessController::shouldAllowDeviceOrientationAndMotionAccess): (WebKit::WebDeviceOrientationAndMotionAccessController::deviceOrientationPermission const): * UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.h: Copied from Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h. * UIProcess/WebsiteData/WebsiteDataStore.h: (WebKit::WebsiteDataStore::deviceOrientationAndMotionAccessController): * WebKit.xcodeproj/project.pbxproj: * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess): * WebProcess/WebCoreSupport/WebChromeClient.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::shouldAllowDeviceOrientationAndMotionAccess): * WebProcess/WebPage/WebPage.h: Tools: Add API test coverage. * TestWebKitAPI/Tests/WebKitCocoa/DeviceOrientation.mm: (-[DeviceOrientationPermissionUIDelegate _webView:shouldAllowDeviceOrientationAndMotionAccessRequestedByFrame:decisionHandler:]): (TEST): Canonical link: https://commits.webkit.org/211268@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244382 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-04-17 17:03:59 +00:00
enum class DeviceOrientationOrMotionPermissionState : uint8_t { Granted, Denied, Prompt };
}
namespace WTF {
template<> struct EnumTraits<WebCore::DeviceOrientationOrMotionPermissionState> {
using values = EnumValues<
WebCore::DeviceOrientationOrMotionPermissionState,
WebCore::DeviceOrientationOrMotionPermissionState::Granted,
WebCore::DeviceOrientationOrMotionPermissionState::Denied,
WebCore::DeviceOrientationOrMotionPermissionState::Prompt
>;
};
Add support for Device Orientation / Motion permission API https://bugs.webkit.org/show_bug.cgi?id=195329 <rdar://problem/47645367> Reviewed by Geoffrey Garen. Source/WebCore: Add support for Device Orientation / Motion permission API: - https://github.com/w3c/deviceorientation/issues/57 Pages can add event listeners for 'deviceorientation' / 'devicemotion' events but such events will not be fired until the page's JavaScript calls DeviceOrientationEvent.requestPermission() / DeviceMotionEvent.requestPermission() and the user grants the request. The feature is currently behind an experimental feature flag, off by default. Tests: fast/device-orientation/device-motion-request-permission-denied.html fast/device-orientation/device-motion-request-permission-granted.html fast/device-orientation/device-motion-request-permission-user-gesture.html fast/device-orientation/device-orientation-request-permission-denied.html fast/device-orientation/device-orientation-request-permission-granted.html fast/device-orientation/device-orientation-request-permission-user-gesture.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * dom/DeviceMotionEvent.h: * dom/DeviceMotionEvent.idl: * dom/DeviceOrientationAndMotionAccessController.cpp: Added. (WebCore::DeviceOrientationAndMotionAccessController::DeviceOrientationAndMotionAccessController): (WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess): (WebCore::DeviceOrientationAndMotionAccessController::setAccessState): * dom/DeviceOrientationAndMotionAccessController.h: Added. (WebCore::DeviceOrientationAndMotionAccessController::accessState const): * dom/DeviceOrientationEvent.h: * dom/DeviceOrientationEvent.idl: * dom/DeviceOrientationOrMotionEvent.cpp: Added. (WebCore::DeviceOrientationOrMotionEvent::requestPermission): * dom/DeviceOrientationOrMotionEvent.h: Added. * dom/DeviceOrientationOrMotionEvent.idl: Added. * dom/DeviceOrientationOrMotionPermissionState.h: Added. * dom/DeviceOrientationOrMotionPermissionState.idl: Added. * dom/Document.cpp: (WebCore::Document::deviceOrientationAndMotionAccessController): * dom/Document.h: * dom/Event.cpp: * dom/MessagePort.cpp: * dom/Microtasks.cpp: * page/ChromeClient.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::addEventListener): (WebCore::DOMWindow::deviceOrientationController const): (WebCore::DOMWindow::deviceMotionController const): (WebCore::DOMWindow::isAllowedToUseDeviceMotionOrientation const): (WebCore::DOMWindow::isAllowedToAddDeviceMotionOrientationListener const): (WebCore::DOMWindow::startListeningForDeviceOrientationIfNecessary): (WebCore::DOMWindow::stopListeningForDeviceOrientationIfNecessary): (WebCore::DOMWindow::startListeningForDeviceMotionIfNecessary): (WebCore::DOMWindow::stopListeningForDeviceMotionIfNecessary): (WebCore::DOMWindow::removeEventListener): (WebCore::DOMWindow::removeAllEventListeners): * page/DOMWindow.h: * page/DeviceController.cpp: (WebCore::DeviceController::hasDeviceEventListener const): * page/DeviceController.h: * page/Settings.yaml: Source/WebKit: Add support for Device Orientation / Motion permission API: - https://github.com/w3c/deviceorientation/issues/57 This adds new SPI to WKUIDelegatePrivate, until we can make this API. * Shared/WebPreferences.yaml: * UIProcess/API/APIUIClient.h: (API::UIClient::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/API/C/WKPage.cpp: (WKPageSetPageUIClient): * UIProcess/API/C/WKPageUIClient.h: * UIProcess/API/Cocoa/WKUIDelegate.h: * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: * UIProcess/Cocoa/UIDelegate.h: * UIProcess/Cocoa/UIDelegate.mm: (WebKit::UIDelegate::setDelegate): (WebKit::UIDelegate::UIClient::shouldAllowDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::requestDeviceOrientationAndMotionAccess): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess): * WebProcess/WebCoreSupport/WebChromeClient.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::nextDeviceOrientationAndMotionPermissionCallbackID): (WebKit::WebPage::shouldAllowDeviceOrientationAndMotionAccess): (WebKit::WebPage::didReceiveDeviceOrientationAndMotionAccessDecision): * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/WebPage.messages.in: Tools: Add test infrastructure to help test the Device Orientation / Motion permission API. * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::setShouldAllowDeviceOrientationAndMotionAccess): * WebKitTestRunner/InjectedBundle/TestRunner.h: * WebKitTestRunner/TestController.cpp: (WTR::shouldAllowDeviceOrientationAndMotionAccess): (WTR::TestController::createWebViewWithOptions): (WTR::TestController::resetStateToConsistentValues): (WTR::TestController::handleDeviceOrientationAndMotionAccessRequest): * WebKitTestRunner/TestController.h: (WTR::TestController::setShouldAllowDeviceOrientationAndMotionAccess): * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): LayoutTests: Add layout test coverage. * TestExpectations: * fast/device-orientation/device-motion-request-permission-denied-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-denied.html: Added. * fast/device-orientation/device-motion-request-permission-granted-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-granted.html: Added. * fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt: Added. * fast/device-orientation/device-motion-request-permission-user-gesture.html: Added. * fast/device-orientation/device-orientation-request-permission-denied-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-denied.html: Added. * fast/device-orientation/device-orientation-request-permission-granted-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-granted.html: Added. * fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt: Added. * fast/device-orientation/device-orientation-request-permission-user-gesture.html: Added. * http/tests/events/device-orientation-motion-non-secure-context.html: * http/tests/events/device-orientation-motion-secure-context-expected.txt: * http/tests/events/device-orientation-motion-secure-context.html: * platform/ios-wk2/TestExpectations: * platform/ios/http/tests/events/device-orientation-motion-non-secure-context-expected.txt: * platform/ios/http/tests/events/device-orientation-motion-secure-context-expected.txt: Canonical link: https://commits.webkit.org/209800@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242664 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-09 00:30:45 +00:00
}