Remember device orientation permission for the duration of the browsing session
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Apr 2019 17:03:59 +0000 (17:03 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Apr 2019 17:03:59 +0000 (17:03 +0000)
commit990d573cd83df95fd32fb5d542451d9d436a1d07
treef88fb16e134ec2a93d0b7e95ebc27c19fdcf2a4c
parent1abf836c8f4e89dc1682d8207395ac4e0c0b5fbd
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244382 268f45cc-cd09-0410-ab3c-d52691b4dbfc
34 files changed:
LayoutTests/fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt
LayoutTests/fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/DeviceOrientationAndMotionAccessController.cpp
Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h
Source/WebCore/dom/DeviceOrientationOrMotionEvent.cpp
Source/WebCore/dom/DeviceOrientationOrMotionPermissionState.h
Source/WebCore/loader/DocumentLoader.h
Source/WebCore/page/ChromeClient.h
Source/WebCore/page/DOMWindow.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebsitePoliciesData.cpp
Source/WebKit/Shared/WebsitePoliciesData.h
Source/WebKit/Sources.txt
Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp
Source/WebKit/UIProcess/API/APIWebsitePolicies.h
Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp
Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h
Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.h [new file with mode: 0644]
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/DeviceOrientation.mm
Tools/WebKitTestRunner/TestController.cpp