Add support for Device Orientation / Motion permission API
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Mar 2019 00:30:45 +0000 (00:30 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Mar 2019 00:30:45 +0000 (00:30 +0000)
commita02a43128ff599aef0e253a05589870be7133173
treeb82061f471123d20fa5e915a46d43915f19e59dc
parente0906184a31cace37ad482e75eccc51638d92099
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242664 268f45cc-cd09-0410-ab3c-d52691b4dbfc
76 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/device-orientation/device-motion-request-permission-denied-expected.txt [new file with mode: 0644]
LayoutTests/fast/device-orientation/device-motion-request-permission-denied.html [new file with mode: 0644]
LayoutTests/fast/device-orientation/device-motion-request-permission-granted-expected.txt [new file with mode: 0644]
LayoutTests/fast/device-orientation/device-motion-request-permission-granted.html [new file with mode: 0644]
LayoutTests/fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt [new file with mode: 0644]
LayoutTests/fast/device-orientation/device-motion-request-permission-user-gesture.html [new file with mode: 0644]
LayoutTests/fast/device-orientation/device-orientation-request-permission-denied-expected.txt [new file with mode: 0644]
LayoutTests/fast/device-orientation/device-orientation-request-permission-denied.html [new file with mode: 0644]
LayoutTests/fast/device-orientation/device-orientation-request-permission-granted-expected.txt [new file with mode: 0644]
LayoutTests/fast/device-orientation/device-orientation-request-permission-granted.html [new file with mode: 0644]
LayoutTests/fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt [new file with mode: 0644]
LayoutTests/fast/device-orientation/device-orientation-request-permission-user-gesture.html [new file with mode: 0644]
LayoutTests/http/tests/events/device-orientation-motion-non-secure-context.html
LayoutTests/http/tests/events/device-orientation-motion-secure-context-expected.txt
LayoutTests/http/tests/events/device-orientation-motion-secure-context.html
LayoutTests/platform/ios-wk2/TestExpectations
LayoutTests/platform/ios/http/tests/events/device-orientation-motion-non-secure-context-expected.txt
LayoutTests/platform/ios/http/tests/events/device-orientation-motion-secure-context-expected.txt
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources-input.xcfilelist
Source/WebCore/DerivedSources-output.xcfilelist
Source/WebCore/DerivedSources.make
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/DeviceMotionEvent.h
Source/WebCore/dom/DeviceMotionEvent.idl
Source/WebCore/dom/DeviceOrientationAndMotionAccessController.cpp [new file with mode: 0644]
Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h [new file with mode: 0644]
Source/WebCore/dom/DeviceOrientationEvent.h
Source/WebCore/dom/DeviceOrientationEvent.idl
Source/WebCore/dom/DeviceOrientationOrMotionEvent.cpp [new file with mode: 0644]
Source/WebCore/dom/DeviceOrientationOrMotionEvent.h [new file with mode: 0644]
Source/WebCore/dom/DeviceOrientationOrMotionEvent.idl [new file with mode: 0644]
Source/WebCore/dom/DeviceOrientationOrMotionPermissionState.h [new file with mode: 0644]
Source/WebCore/dom/DeviceOrientationOrMotionPermissionState.idl [new file with mode: 0644]
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Event.cpp
Source/WebCore/dom/MessagePort.cpp
Source/WebCore/dom/Microtasks.cpp
Source/WebCore/page/ChromeClient.h
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/DeviceController.cpp
Source/WebCore/page/DeviceController.h
Source/WebCore/page/Settings.yaml
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferences.yaml
Source/WebKit/Shared/WebPreferencesDefaultValues.cpp
Source/WebKit/Shared/WebPreferencesDefaultValues.h
Source/WebKit/UIProcess/API/APIUIClient.h
Source/WebKit/UIProcess/API/C/WKPage.cpp
Source/WebKit/UIProcess/API/C/WKPageUIClient.h
Source/WebKit/UIProcess/API/Cocoa/WKUIDelegate.h
Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit/UIProcess/Cocoa/VersionChecks.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestController.h
Tools/WebKitTestRunner/TestInvocation.cpp