Diff
Modified: trunk/LayoutTests/fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt (244381 => 244382)
--- trunk/LayoutTests/fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/LayoutTests/fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt 2019-04-17 17:03:59 UTC (rev 244382)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 14: NotAllowedError: Requesting device orientation or motion access requires a user gesture
+CONSOLE MESSAGE: line 14: NotAllowedError: Requesting device orientation or motion access requires a user gesture to prompt
Tests that DeviceMotionEvent.requestPermission() requires a user gesture.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Modified: trunk/LayoutTests/fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt (244381 => 244382)
--- trunk/LayoutTests/fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/LayoutTests/fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt 2019-04-17 17:03:59 UTC (rev 244382)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 14: NotAllowedError: Requesting device orientation or motion access requires a user gesture
+CONSOLE MESSAGE: line 14: NotAllowedError: Requesting device orientation or motion access requires a user gesture to prompt
Tests that DeviceOrientationEvent.requestPermission() requires a user gesture.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Modified: trunk/Source/WebCore/ChangeLog (244381 => 244382)
--- trunk/Source/WebCore/ChangeLog 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebCore/ChangeLog 2019-04-17 17:03:59 UTC (rev 244382)
@@ -1,3 +1,31 @@
+2019-04-17 Chris Dumez <[email protected]>
+
+ 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.
+
+ 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):
+
2019-04-17 Rob Buis <[email protected]>
XMLHttpRequest has the wrong fallback encoding
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (244381 => 244382)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-04-17 17:03:59 UTC (rev 244382)
@@ -1204,7 +1204,7 @@
460BB6161D0A1BF000221812 /* Base64Utilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 460BB6141D0A1BEC00221812 /* Base64Utilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
460CBF361D4BCD0E0092E88E /* JSDOMWindowProperties.h in Headers */ = {isa = PBXBuildFile; fileRef = 460CBF341D4BCCFE0092E88E /* JSDOMWindowProperties.h */; };
460E3075222F4EFD009A0606 /* DeviceOrientationOrMotionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 461DA52A222F486F00D05A87 /* DeviceOrientationOrMotionEvent.h */; };
- 460E3077222F4F03009A0606 /* DeviceOrientationOrMotionPermissionState.h in Headers */ = {isa = PBXBuildFile; fileRef = 465EDD9F222F4EC300B46E16 /* DeviceOrientationOrMotionPermissionState.h */; };
+ 460E3077222F4F03009A0606 /* DeviceOrientationOrMotionPermissionState.h in Headers */ = {isa = PBXBuildFile; fileRef = 465EDD9F222F4EC300B46E16 /* DeviceOrientationOrMotionPermissionState.h */; settings = {ATTRIBUTES = (Private, ); }; };
46218ACB1F72D64E00574FBE /* DOMHighResTimeStamp.h in Headers */ = {isa = PBXBuildFile; fileRef = 46E016AD1F72D61E00282B2C /* DOMHighResTimeStamp.h */; settings = {ATTRIBUTES = (Private, ); }; };
463521AD2081092A00C28922 /* WindowProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 463521AA2081090B00C28922 /* WindowProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
463EB6231B8789E00096ED51 /* TagCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 463EB6211B8789CB0096ED51 /* TagCollection.h */; };
Modified: trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.cpp (244381 => 244382)
--- trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.cpp 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.cpp 2019-04-17 17:03:59 UTC (rev 244382)
@@ -43,56 +43,41 @@
: m_document(document)
{
ASSERT(&m_document.topDocument() == &m_document);
+
+ // Initial value is based on the per-site setting.
+ auto* frame = m_document.frame();
+ if (auto* documentLoader = frame ? frame->loader().documentLoader() : nullptr)
+ m_accessState = documentLoader->deviceOrientationAndMotionAccessState();
}
-void DeviceOrientationAndMotionAccessController::shouldAllowAccess(Function<void(ExceptionOr<bool> granted)>&& callback)
+void DeviceOrientationAndMotionAccessController::shouldAllowAccess(Function<void(DeviceOrientationOrMotionPermissionState)>&& callback)
{
- if (auto accessState = this->accessState())
- return callback(*accessState);
- ASSERT(m_document.frame());
-
- if (!UserGestureIndicator::processingUserGesture())
- return callback(Exception { NotAllowedError, "Requesting device orientation or motion access requires a user gesture"_s });
-
auto* page = m_document.page();
- if (!page)
- return callback(false);
+ auto* frame = m_document.frame();
+ if (!page || !frame)
+ return callback(DeviceOrientationOrMotionPermissionState::Denied);
- m_pendingRequests.append(WTFMove(callback));
- if (m_pendingRequests.size() > 1)
- return;
+ bool mayPrompt = UserGestureIndicator::processingUserGesture();
+ if (m_accessState != DeviceOrientationOrMotionPermissionState::Prompt)
+ return callback(m_accessState);
- page->chrome().client().shouldAllowDeviceOrientationAndMotionAccess(*m_document.frame(), [this, weakThis = makeWeakPtr(*this)](bool granted) mutable {
- if (weakThis)
- setAccessState(granted);
- });
-}
+ page->chrome().client().shouldAllowDeviceOrientationAndMotionAccess(*m_document.frame(), mayPrompt, [this, weakThis = makeWeakPtr(this), callback = WTFMove(callback)](DeviceOrientationOrMotionPermissionState permissionState) mutable {
+ if (!weakThis)
+ return;
-void DeviceOrientationAndMotionAccessController::setAccessState(bool granted)
-{
- auto* frame = m_document.frame();
- if (frame && frame->loader().documentLoader())
- frame->loader().documentLoader()->setDeviceOrientationAndMotionAccessState(granted);
+ m_accessState = permissionState;
+ callback(permissionState);
- auto pendingRequests = WTFMove(m_pendingRequests);
- for (auto& request : pendingRequests)
- request(granted);
+ if (permissionState != DeviceOrientationOrMotionPermissionState::Granted)
+ return;
- if (!granted)
- return;
-
- for (auto* frame = m_document.frame(); frame && frame->window(); frame = frame->tree().traverseNext(m_document.frame())) {
- frame->window()->startListeningForDeviceOrientationIfNecessary();
- frame->window()->startListeningForDeviceMotionIfNecessary();
- }
+ for (auto* frame = m_document.frame(); frame && frame->window(); frame = frame->tree().traverseNext(m_document.frame())) {
+ frame->window()->startListeningForDeviceOrientationIfNecessary();
+ frame->window()->startListeningForDeviceMotionIfNecessary();
+ }
+ });
}
-Optional<bool> DeviceOrientationAndMotionAccessController::accessState() const
-{
- auto* frame = m_document.frame();
- return frame && frame->loader().documentLoader() ? frame->loader().documentLoader()->deviceOrientationAndMotionAccessState() : false;
-}
-
} // namespace WebCore
#endif // ENABLE(DEVICE_ORIENTATION)
Modified: trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h (244381 => 244382)
--- trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -27,6 +27,7 @@
#if ENABLE(DEVICE_ORIENTATION)
+#include "DeviceOrientationOrMotionPermissionState.h"
#include "ExceptionOr.h"
#include <wtf/Function.h>
#include <wtf/Vector.h>
@@ -41,14 +42,13 @@
public:
explicit DeviceOrientationAndMotionAccessController(Document&);
- Optional<bool> accessState() const;
- void shouldAllowAccess(Function<void(ExceptionOr<bool> granted)>&&);
+ DeviceOrientationOrMotionPermissionState accessState() const { return m_accessState; }
+ void shouldAllowAccess(Function<void(DeviceOrientationOrMotionPermissionState)>&&);
+
private:
- void setAccessState(bool);
-
Document& m_document;
- Vector<Function<void(bool)>> m_pendingRequests;
+ DeviceOrientationOrMotionPermissionState m_accessState { DeviceOrientationOrMotionPermissionState::Prompt };
};
} // namespace WebCore
Modified: trunk/Source/WebCore/dom/DeviceOrientationOrMotionEvent.cpp (244381 => 244382)
--- trunk/Source/WebCore/dom/DeviceOrientationOrMotionEvent.cpp 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebCore/dom/DeviceOrientationOrMotionEvent.cpp 2019-04-17 17:03:59 UTC (rev 244382)
@@ -43,10 +43,10 @@
return promise.resolve(PermissionState::Denied);
}
- document.deviceOrientationAndMotionAccessController().shouldAllowAccess([promise = WTFMove(promise)](ExceptionOr<bool> granted) mutable {
- if (granted.hasException())
- return promise.reject(granted.releaseException());
- promise.resolve(granted.returnValue() ? PermissionState::Granted : PermissionState::Denied);
+ document.deviceOrientationAndMotionAccessController().shouldAllowAccess([promise = WTFMove(promise)](PermissionState permissionState) mutable {
+ if (permissionState == PermissionState::Prompt)
+ return promise.reject(Exception { NotAllowedError, "Requesting device orientation or motion access requires a user gesture to prompt"_s });
+ promise.resolve(permissionState);
});
}
#endif
Modified: trunk/Source/WebCore/dom/DeviceOrientationOrMotionPermissionState.h (244381 => 244382)
--- trunk/Source/WebCore/dom/DeviceOrientationOrMotionPermissionState.h 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebCore/dom/DeviceOrientationOrMotionPermissionState.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -25,8 +25,23 @@
#pragma once
+#include <wtf/EnumTraits.h>
+
namespace WebCore {
-enum class DeviceOrientationOrMotionPermissionState { Granted, Denied };
+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
+ >;
+};
+
+}
Modified: trunk/Source/WebCore/loader/DocumentLoader.h (244381 => 244382)
--- trunk/Source/WebCore/loader/DocumentLoader.h 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebCore/loader/DocumentLoader.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -32,6 +32,7 @@
#include "CachedRawResourceClient.h"
#include "CachedResourceHandle.h"
#include "ContentSecurityPolicyClient.h"
+#include "DeviceOrientationOrMotionPermissionState.h"
#include "DocumentIdentifier.h"
#include "DocumentWriter.h"
#include "FrameDestructionObserver.h"
@@ -280,8 +281,10 @@
bool userContentExtensionsEnabled() const { return m_userContentExtensionsEnabled; }
void setUserContentExtensionsEnabled(bool enabled) { m_userContentExtensionsEnabled = enabled; }
- const Optional<bool>& deviceOrientationAndMotionAccessState() const { return m_deviceOrientationAndMotionAccessState; }
- void setDeviceOrientationAndMotionAccessState(const Optional<bool>& state) { m_deviceOrientationAndMotionAccessState = state; }
+#if ENABLE(DEVICE_ORIENTATION)
+ DeviceOrientationOrMotionPermissionState deviceOrientationAndMotionAccessState() const { return m_deviceOrientationAndMotionAccessState; }
+ void setDeviceOrientationAndMotionAccessState(DeviceOrientationOrMotionPermissionState state) { m_deviceOrientationAndMotionAccessState = state; }
+#endif
AutoplayPolicy autoplayPolicy() const { return m_autoplayPolicy; }
void setAutoplayPolicy(AutoplayPolicy policy) { m_autoplayPolicy = policy; }
@@ -584,7 +587,9 @@
String m_customJavaScriptUserAgentAsSiteSpecificQuirks;
String m_customNavigatorPlatform;
bool m_userContentExtensionsEnabled { true };
- Optional<bool> m_deviceOrientationAndMotionAccessState;
+#if ENABLE(DEVICE_ORIENTATION)
+ DeviceOrientationOrMotionPermissionState m_deviceOrientationAndMotionAccessState { DeviceOrientationOrMotionPermissionState::Prompt };
+#endif
AutoplayPolicy m_autoplayPolicy { AutoplayPolicy::Default };
OptionSet<AutoplayQuirk> m_allowedAutoplayQuirks;
PopUpPolicy m_popUpPolicy { PopUpPolicy::Default };
Modified: trunk/Source/WebCore/page/ChromeClient.h (244381 => 244382)
--- trunk/Source/WebCore/page/ChromeClient.h 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebCore/page/ChromeClient.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -25,6 +25,7 @@
#include "AutoplayEvent.h"
#include "Cursor.h"
#include "DatabaseDetails.h"
+#include "DeviceOrientationOrMotionPermissionState.h"
#include "DisabledAdaptations.h"
#include "DisplayRefreshMonitor.h"
#include "FocusDirection.h"
@@ -485,7 +486,7 @@
virtual void requestStorageAccess(String&& /*subFrameHost*/, String&& /*topFrameHost*/, uint64_t /*frameID*/, uint64_t /*pageID*/, WTF::CompletionHandler<void (bool)>&& callback) { callback(false); }
#if ENABLE(DEVICE_ORIENTATION)
- virtual void shouldAllowDeviceOrientationAndMotionAccess(Frame&, WTF::CompletionHandler<void(bool)>&& callback) { callback(true); }
+ virtual void shouldAllowDeviceOrientationAndMotionAccess(Frame&, bool /* mayPrompt */, WTF::CompletionHandler<void(DeviceOrientationOrMotionPermissionState)>&& callback) { callback(DeviceOrientationOrMotionPermissionState::Denied); }
#endif
virtual void didInsertMenuElement(HTMLMenuElement&) { }
Modified: trunk/Source/WebCore/page/DOMWindow.cpp (244381 => 244382)
--- trunk/Source/WebCore/page/DOMWindow.cpp 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebCore/page/DOMWindow.cpp 2019-04-17 17:03:59 UTC (rev 244382)
@@ -1872,13 +1872,15 @@
if (frame()->settings().deviceOrientationPermissionAPIEnabled()) {
auto accessState = document()->deviceOrientationAndMotionAccessController().accessState();
- if (accessState && !*accessState) {
+ switch (accessState) {
+ case DeviceOrientationOrMotionPermissionState::Denied:
message = "No device motion or orientation events will be fired because permission to use the API was denied."_s;
return false;
- }
- if (!accessState) {
+ case DeviceOrientationOrMotionPermissionState::Prompt:
message = "No device motion or orientation events will be fired until permission has been requested and granted."_s;
return false;
+ case DeviceOrientationOrMotionPermissionState::Granted:
+ break;
}
}
Modified: trunk/Source/WebKit/ChangeLog (244381 => 244382)
--- trunk/Source/WebKit/ChangeLog 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/ChangeLog 2019-04-17 17:03:59 UTC (rev 244382)
@@ -1,3 +1,46 @@
+2019-04-17 Chris Dumez <[email protected]>
+
+ 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.
+
+ 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:
+
2019-04-16 Andy Estes <[email protected]>
[iOSMac] Use UIDocumentPickerViewController for picking files
Modified: trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp (244381 => 244382)
--- trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp 2019-04-17 17:03:59 UTC (rev 244382)
@@ -38,7 +38,9 @@
{
encoder << contentBlockersEnabled;
encoder << autoplayPolicy;
+#if ENABLE(DEVICE_ORIENTATION)
encoder << deviceOrientationAndMotionAccessState;
+#endif
encoder << allowedAutoplayQuirks;
encoder << customHeaderFields;
encoder << popUpPolicy;
@@ -63,10 +65,12 @@
if (!autoplayPolicy)
return WTF::nullopt;
- Optional<Optional<bool>> deviceOrientationAndMotionAccessState;
+#if ENABLE(DEVICE_ORIENTATION)
+ Optional<DeviceOrientationOrMotionPermissionState> deviceOrientationAndMotionAccessState;
decoder >> deviceOrientationAndMotionAccessState;
if (!deviceOrientationAndMotionAccessState)
return WTF::nullopt;
+#endif
Optional<OptionSet<WebsiteAutoplayQuirk>> allowedAutoplayQuirks;
decoder >> allowedAutoplayQuirks;
@@ -122,7 +126,9 @@
WTFMove(*contentBlockersEnabled),
WTFMove(*allowedAutoplayQuirks),
WTFMove(*autoplayPolicy),
+#if ENABLE(DEVICE_ORIENTATION)
WTFMove(*deviceOrientationAndMotionAccessState),
+#endif
WTFMove(*customHeaderFields),
WTFMove(*popUpPolicy),
WTFMove(*websiteDataStoreParameters),
@@ -141,8 +147,11 @@
documentLoader.setCustomUserAgent(websitePolicies.customUserAgent);
documentLoader.setCustomJavaScriptUserAgentAsSiteSpecificQuirks(websitePolicies.customJavaScriptUserAgentAsSiteSpecificQuirks);
documentLoader.setCustomNavigatorPlatform(websitePolicies.customNavigatorPlatform);
+
+#if ENABLE(DEVICE_ORIENTATION)
documentLoader.setDeviceOrientationAndMotionAccessState(websitePolicies.deviceOrientationAndMotionAccessState);
-
+#endif
+
// Only setUserContentExtensionsEnabled if it hasn't already been disabled by reloading without content blockers.
if (documentLoader.userContentExtensionsEnabled())
documentLoader.setUserContentExtensionsEnabled(websitePolicies.contentBlockersEnabled);
Modified: trunk/Source/WebKit/Shared/WebsitePoliciesData.h (244381 => 244382)
--- trunk/Source/WebKit/Shared/WebsitePoliciesData.h 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/Shared/WebsitePoliciesData.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -32,6 +32,7 @@
#include "WebsiteMetaViewportPolicy.h"
#include "WebsitePopUpPolicy.h"
#include "WebsiteSimulatedMouseEventsDispatchPolicy.h"
+#include <WebCore/DeviceOrientationOrMotionPermissionState.h>
#include <WebCore/HTTPHeaderField.h>
#include <wtf/OptionSet.h>
@@ -52,7 +53,9 @@
bool contentBlockersEnabled { true };
OptionSet<WebsiteAutoplayQuirk> allowedAutoplayQuirks;
WebsiteAutoplayPolicy autoplayPolicy { WebsiteAutoplayPolicy::Default };
- Optional<bool> deviceOrientationAndMotionAccessState;
+#if ENABLE(DEVICE_ORIENTATION)
+ WebCore::DeviceOrientationOrMotionPermissionState deviceOrientationAndMotionAccessState;
+#endif
Vector<WebCore::HTTPHeaderField> customHeaderFields;
WebsitePopUpPolicy popUpPolicy { WebsitePopUpPolicy::Default };
Optional<WebsiteDataStoreParameters> websiteDataStoreParameters;
Modified: trunk/Source/WebKit/Sources.txt (244381 => 244382)
--- trunk/Source/WebKit/Sources.txt 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/Sources.txt 2019-04-17 17:03:59 UTC (rev 244382)
@@ -413,6 +413,7 @@
UIProcess/WebStorage/LocalStorageDatabase.cpp
UIProcess/WebStorage/LocalStorageDatabaseTracker.cpp
+UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.cpp
UIProcess/WebsiteData/WebsiteDataRecord.cpp
UIProcess/WebsiteData/WebsiteDataStore.cpp
UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp
Modified: trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp (244381 => 244382)
--- trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp 2019-04-17 17:03:59 UTC (rev 244382)
@@ -48,7 +48,9 @@
policies->setContentBlockersEnabled(m_contentBlockersEnabled);
policies->setAllowedAutoplayQuirks(m_allowedAutoplayQuirks);
policies->setAutoplayPolicy(m_autoplayPolicy);
+#if ENABLE(DEVICE_ORIENTATION)
policies->setDeviceOrientationAndMotionAccessState(m_deviceOrientationAndMotionAccessState);
+#endif
policies->setPopUpPolicy(m_popUpPolicy);
policies->setWebsiteDataStore(m_websiteDataStore.get());
policies->setCustomUserAgent(m_customUserAgent);
@@ -81,7 +83,9 @@
contentBlockersEnabled(),
allowedAutoplayQuirks(),
autoplayPolicy(),
+#if ENABLE(DEVICE_ORIENTATION)
deviceOrientationAndMotionAccessState(),
+#endif
customHeaderFields(),
popUpPolicy(),
m_websiteDataStore ? Optional<WebKit::WebsiteDataStoreParameters> { m_websiteDataStore->websiteDataStore().parameters() } : WTF::nullopt,
Modified: trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h (244381 => 244382)
--- trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -33,6 +33,7 @@
#include "WebsiteMetaViewportPolicy.h"
#include "WebsitePopUpPolicy.h"
#include "WebsiteSimulatedMouseEventsDispatchPolicy.h"
+#include <WebCore/DeviceOrientationOrMotionPermissionState.h>
#include <WebCore/HTTPHeaderField.h>
#include <wtf/OptionSet.h>
#include <wtf/Vector.h>
@@ -62,9 +63,11 @@
WebKit::WebsiteAutoplayPolicy autoplayPolicy() const { return m_autoplayPolicy; }
void setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy policy) { m_autoplayPolicy = policy; }
- const Optional<bool>& deviceOrientationAndMotionAccessState() const { return m_deviceOrientationAndMotionAccessState; }
- void setDeviceOrientationAndMotionAccessState(Optional<bool> state) { m_deviceOrientationAndMotionAccessState = state; }
-
+#if ENABLE(DEVICE_ORIENTATION)
+ WebCore::DeviceOrientationOrMotionPermissionState deviceOrientationAndMotionAccessState() const { return m_deviceOrientationAndMotionAccessState; }
+ void setDeviceOrientationAndMotionAccessState(WebCore::DeviceOrientationOrMotionPermissionState state) { m_deviceOrientationAndMotionAccessState = state; }
+#endif
+
const Vector<WebCore::HTTPHeaderField>& customHeaderFields() const { return m_customHeaderFields; }
Vector<WebCore::HTTPHeaderField>&& takeCustomHeaderFields() { return WTFMove(m_customHeaderFields); }
void setCustomHeaderFields(Vector<WebCore::HTTPHeaderField>&& fields) { m_customHeaderFields = WTFMove(fields); }
@@ -104,7 +107,9 @@
bool m_contentBlockersEnabled { true };
OptionSet<WebKit::WebsiteAutoplayQuirk> m_allowedAutoplayQuirks;
WebKit::WebsiteAutoplayPolicy m_autoplayPolicy { WebKit::WebsiteAutoplayPolicy::Default };
- Optional<bool> m_deviceOrientationAndMotionAccessState;
+#if ENABLE(DEVICE_ORIENTATION)
+ WebCore::DeviceOrientationOrMotionPermissionState m_deviceOrientationAndMotionAccessState { WebCore::DeviceOrientationOrMotionPermissionState::Prompt };
+#endif
Vector<WebCore::HTTPHeaderField> m_customHeaderFields;
WebKit::WebsitePopUpPolicy m_popUpPolicy { WebKit::WebsitePopUpPolicy::Default };
RefPtr<WebsiteDataStore> m_websiteDataStore;
Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp (244381 => 244382)
--- trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp 2019-04-17 17:03:59 UTC (rev 244382)
@@ -36,6 +36,7 @@
#include "WKRetainPtr.h"
#include "WKSecurityOriginRef.h"
#include "WKString.h"
+#include "WebDeviceOrientationAndMotionAccessController.h"
#include "WebResourceLoadStatisticsStore.h"
#include "WebsiteData.h"
#include "WebsiteDataFetchOption.h"
@@ -578,6 +579,13 @@
WebKit::toImpl(dataStoreRef)->websiteDataStore().setPerOriginStorageQuota(quota);
}
+void WKWebsiteDataStoreClearAllDeviceOrientationPermissions(WKWebsiteDataStoreRef dataStoreRef)
+{
+#if ENABLE(DEVICE_ORIENTATION)
+ WebKit::toImpl(dataStoreRef)->websiteDataStore().deviceOrientationAndMotionAccessController().clearPermissions();
+#endif
+}
+
void WKWebsiteDataStoreSetWebAuthenticationMockConfiguration(WKWebsiteDataStoreRef dataStoreRef, WKDictionaryRef configurationRef)
{
#if ENABLE(WEB_AUTHN)
Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h (244381 => 244382)
--- trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -129,6 +129,8 @@
WK_EXPORT void WKWebsiteDataStoreSetWebAuthenticationMockConfiguration(WKWebsiteDataStoreRef dataStoreRef, WKDictionaryRef configuration);
+WK_EXPORT void WKWebsiteDataStoreClearAllDeviceOrientationPermissions(WKWebsiteDataStoreRef dataStoreRef);
+
#ifdef __cplusplus
}
#endif
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm (244381 => 244382)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm 2019-04-17 17:03:59 UTC (rev 244382)
@@ -137,28 +137,52 @@
}
}
-- (void)_setDeviceOrientationAndMotionAccessPolicy:(_WKWebsiteDeviceOrientationAndMotionAccessPolicy)policy
+#if ENABLE(DEVICE_ORIENTATION)
+static WebCore::DeviceOrientationOrMotionPermissionState toDeviceOrientationOrMotionPermissionState(_WKWebsiteDeviceOrientationAndMotionAccessPolicy policy)
{
switch (policy) {
case _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk:
- _websitePolicies->setDeviceOrientationAndMotionAccessState(WTF::nullopt);
- break;
+ return WebCore::DeviceOrientationOrMotionPermissionState::Prompt;
case _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant:
- _websitePolicies->setDeviceOrientationAndMotionAccessState(true);
- break;
+ return WebCore::DeviceOrientationOrMotionPermissionState::Granted;
case _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny:
- _websitePolicies->setDeviceOrientationAndMotionAccessState(false);
break;
}
+ return WebCore::DeviceOrientationOrMotionPermissionState::Denied;
}
+#endif
-- (_WKWebsiteDeviceOrientationAndMotionAccessPolicy)_deviceOrientationAndMotionAccessPolicy
+- (void)_setDeviceOrientationAndMotionAccessPolicy:(_WKWebsiteDeviceOrientationAndMotionAccessPolicy)policy
{
- if (!_websitePolicies->deviceOrientationAndMotionAccessState())
+#if ENABLE(DEVICE_ORIENTATION)
+ _websitePolicies->setDeviceOrientationAndMotionAccessState(toDeviceOrientationOrMotionPermissionState(policy));
+#endif
+}
+
+#if ENABLE(DEVICE_ORIENTATION)
+static _WKWebsiteDeviceOrientationAndMotionAccessPolicy toWKWebsiteDeviceOrientationAndMotionAccessPolicy(WebCore::DeviceOrientationOrMotionPermissionState state)
+{
+ switch (state) {
+ case WebCore::DeviceOrientationOrMotionPermissionState::Prompt:
return _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk;
- return *_websitePolicies->deviceOrientationAndMotionAccessState() ? _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant : _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny;
+ case WebCore::DeviceOrientationOrMotionPermissionState::Granted:
+ return _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant;
+ case WebCore::DeviceOrientationOrMotionPermissionState::Denied:
+ break;
+ }
+ return _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny;
}
+#endif
+- (_WKWebsiteDeviceOrientationAndMotionAccessPolicy)_deviceOrientationAndMotionAccessPolicy
+{
+#if ENABLE(DEVICE_ORIENTATION)
+ return toWKWebsiteDeviceOrientationAndMotionAccessPolicy(_websitePolicies->deviceOrientationAndMotionAccessState());
+#else
+ return _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny;
+#endif
+}
+
- (void)_setPopUpPolicy:(_WKWebsitePopUpPolicy)policy
{
switch (policy) {
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (244381 => 244382)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2019-04-17 17:03:59 UTC (rev 244382)
@@ -7297,12 +7297,12 @@
}
#if ENABLE(DEVICE_ORIENTATION)
-void WebPageProxy::requestDeviceOrientationAndMotionAccess(uint64_t frameID, WebCore::SecurityOriginData&& originData, CompletionHandler<void(bool)>&& completionHandler)
+void WebPageProxy::shouldAllowDeviceOrientationAndMotionAccess(uint64_t frameID, WebCore::SecurityOriginData&& originData, bool mayPrompt, CompletionHandler<void(DeviceOrientationOrMotionPermissionState)>&& completionHandler)
{
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(m_process, frame);
- m_uiClient->shouldAllowDeviceOrientationAndMotionAccess(*this, *frame, WTFMove(originData), WTFMove(completionHandler));
+ websiteDataStore().deviceOrientationAndMotionAccessController().shouldAllowAccess(*this, *frame, WTFMove(originData), mayPrompt, WTFMove(completionHandler));
}
#endif
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (244381 => 244382)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.h 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -1437,7 +1437,7 @@
#endif
#if ENABLE(DEVICE_ORIENTATION)
- void requestDeviceOrientationAndMotionAccess(uint64_t frameID, WebCore::SecurityOriginData&&, CompletionHandler<void(bool)>&&);
+ void shouldAllowDeviceOrientationAndMotionAccess(uint64_t frameID, WebCore::SecurityOriginData&&, bool mayPrompt, CompletionHandler<void(WebCore::DeviceOrientationOrMotionPermissionState)>&&);
#endif
static WebPageProxy* nonEphemeralWebPageProxy();
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (244381 => 244382)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in 2019-04-17 17:03:59 UTC (rev 244382)
@@ -537,7 +537,7 @@
LoadSynchronousURLSchemeTask(struct WebKit::URLSchemeTaskParameters parameters) -> (WebCore::ResourceResponse response, WebCore::ResourceError error, IPC::DataReference data) Synchronous
#if ENABLE(DEVICE_ORIENTATION)
- RequestDeviceOrientationAndMotionAccess(uint64_t frameID, struct WebCore::SecurityOriginData origin) -> (bool granted) Async
+ ShouldAllowDeviceOrientationAndMotionAccess(uint64_t frameID, struct WebCore::SecurityOriginData origin, bool mayPrompt) -> (enum:uint8_t WebCore::DeviceOrientationOrMotionPermissionState permissionState) Async
#endif
#if ENABLE(ATTACHMENT_ELEMENT)
Added: trunk/Source/WebKit/UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.cpp (0 => 244382)
--- trunk/Source/WebKit/UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.cpp (rev 0)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.cpp 2019-04-17 17:03:59 UTC (rev 244382)
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "WebDeviceOrientationAndMotionAccessController.h"
+
+#if ENABLE(DEVICE_ORIENTATION)
+
+#include "APIUIClient.h"
+#include "WebPageProxy.h"
+
+namespace WebKit {
+
+using namespace WebCore;
+
+void WebDeviceOrientationAndMotionAccessController::shouldAllowAccess(WebPageProxy& page, WebFrameProxy& frame, WebCore::SecurityOriginData&& originData, bool mayPrompt, CompletionHandler<void(DeviceOrientationOrMotionPermissionState)>&& completionHandler)
+{
+ auto currentPermission = deviceOrientationPermission(originData);
+ if (currentPermission != DeviceOrientationOrMotionPermissionState::Prompt || !mayPrompt)
+ return completionHandler(currentPermission);
+
+ auto& pendingRequests = m_pendingRequests.ensure(originData, [] {
+ return Vector<CompletionHandler<void(WebCore::DeviceOrientationOrMotionPermissionState)>> { };
+ }).iterator->value;
+ pendingRequests.append(WTFMove(completionHandler));
+ if (pendingRequests.size() > 1)
+ return;
+
+ page.uiClient().shouldAllowDeviceOrientationAndMotionAccess(page, frame, originData, [this, weakThis = makeWeakPtr(this), originData](bool granted) mutable {
+ if (!weakThis)
+ return;
+ m_deviceOrientationPermissionDecisions.set(originData, granted);
+ auto requests = m_pendingRequests.take(originData);
+ for (auto& completionHandler : requests)
+ completionHandler(granted ? DeviceOrientationOrMotionPermissionState::Granted : DeviceOrientationOrMotionPermissionState::Denied);
+ });
+}
+
+DeviceOrientationOrMotionPermissionState WebDeviceOrientationAndMotionAccessController::deviceOrientationPermission(const SecurityOriginData& origin) const
+{
+ auto it = m_deviceOrientationPermissionDecisions.find(origin);
+ if (it == m_deviceOrientationPermissionDecisions.end())
+ return DeviceOrientationOrMotionPermissionState::Prompt;
+ return it->value ? DeviceOrientationOrMotionPermissionState::Granted : DeviceOrientationOrMotionPermissionState::Denied;
+}
+
+void WebDeviceOrientationAndMotionAccessController::clearPermissions()
+{
+ m_deviceOrientationPermissionDecisions.clear();
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(DEVICE_ORIENTATION)
Copied: trunk/Source/WebKit/UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.h (from rev 244381, trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h) (0 => 244382)
--- trunk/Source/WebKit/UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.h (rev 0)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebDeviceOrientationAndMotionAccessController.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -0,0 +1,56 @@
+/*
+ * 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
+
+#if ENABLE(DEVICE_ORIENTATION)
+
+#include <WebCore/DeviceOrientationOrMotionPermissionState.h>
+#include <WebCore/SecurityOriginData.h>
+#include <wtf/HashMap.h>
+#include <wtf/WeakPtr.h>
+
+namespace WebKit {
+
+class WebPageProxy;
+class WebFrameProxy;
+
+class WebDeviceOrientationAndMotionAccessController : public CanMakeWeakPtr<WebDeviceOrientationAndMotionAccessController> {
+public:
+ WebDeviceOrientationAndMotionAccessController() = default;
+
+ void shouldAllowAccess(WebPageProxy&, WebFrameProxy&, WebCore::SecurityOriginData&&, bool mayPrompt, CompletionHandler<void(WebCore::DeviceOrientationOrMotionPermissionState)>&&);
+ void clearPermissions();
+
+private:
+ WebCore::DeviceOrientationOrMotionPermissionState deviceOrientationPermission(const WebCore::SecurityOriginData&) const;
+
+ HashMap<WebCore::SecurityOriginData, bool> m_deviceOrientationPermissionDecisions;
+ HashMap<WebCore::SecurityOriginData, Vector<CompletionHandler<void(WebCore::DeviceOrientationOrMotionPermissionState)>>> m_pendingRequests;
+};
+
+}
+
+#endif
Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (244381 => 244382)
--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -26,10 +26,12 @@
#pragma once
#include "NetworkSessionCreationParameters.h"
+#include "WebDeviceOrientationAndMotionAccessController.h"
#include "WebProcessLifetimeObserver.h"
#include "WebsiteDataStoreClient.h"
#include "WebsiteDataStoreConfiguration.h"
#include <WebCore/Cookie.h>
+#include <WebCore/DeviceOrientationOrMotionPermissionState.h>
#include <WebCore/SecurityOriginData.h>
#include <WebCore/SecurityOriginHash.h>
#include <pal/SessionID.h>
@@ -252,6 +254,10 @@
API::HTTPCookieStore& cookieStore();
+#if ENABLE(DEVICE_ORIENTATION)
+ WebDeviceOrientationAndMotionAccessController& deviceOrientationAndMotionAccessController() { return m_deviceOrientationAndMotionAccessController; }
+#endif
+
#if HAVE(LOAD_OPTIMIZER)
WEBSITEDATASTORE_LOADOPTIMIZER_ADDITIONS_1
#endif
@@ -335,6 +341,10 @@
UniqueRef<AuthenticatorManager> m_authenticatorManager;
#endif
+#if ENABLE(DEVICE_ORIENTATION)
+ WebDeviceOrientationAndMotionAccessController m_deviceOrientationAndMotionAccessController;
+#endif
+
UniqueRef<WebsiteDataStoreClient> m_client;
RefPtr<API::HTTPCookieStore> m_cookieStore;
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (244381 => 244382)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2019-04-17 17:03:59 UTC (rev 244382)
@@ -906,6 +906,7 @@
466BC03C1FA266DA002FA9C1 /* WebSWContextManagerConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 466BC0391FA266C9002FA9C1 /* WebSWContextManagerConnection.h */; };
467E43E82243FF7D00B13924 /* WebProcessDataStoreParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 467E43E72243FF6D00B13924 /* WebProcessDataStoreParameters.h */; };
46A2B6091E5676A600C3DEDA /* BackgroundProcessResponsivenessTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A2B6071E5675A200C3DEDA /* BackgroundProcessResponsivenessTimer.h */; };
+ 46B0524722668D8500265B97 /* WebDeviceOrientationAndMotionAccessController.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B0524422668D2300265B97 /* WebDeviceOrientationAndMotionAccessController.h */; };
46DF063C1F3905F8001980BB /* NetworkCORSPreflightChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DF063A1F3905E5001980BB /* NetworkCORSPreflightChecker.h */; };
4A3CC18B19B0640F00D14AEF /* UserMediaPermissionRequestManagerProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A410F3A19AF7B04002EBAB5 /* UserMediaPermissionRequestManagerProxy.h */; };
4A3CC18D19B0641900D14AEF /* UserMediaPermissionRequestProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A410F3C19AF7B04002EBAB5 /* UserMediaPermissionRequestProxy.h */; };
@@ -3140,6 +3141,8 @@
4683569B21E81CC7006E27A3 /* ProvisionalPageProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProvisionalPageProxy.cpp; sourceTree = "<group>"; };
46A2B6061E5675A200C3DEDA /* BackgroundProcessResponsivenessTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BackgroundProcessResponsivenessTimer.cpp; sourceTree = "<group>"; };
46A2B6071E5675A200C3DEDA /* BackgroundProcessResponsivenessTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackgroundProcessResponsivenessTimer.h; sourceTree = "<group>"; };
+ 46B0524422668D2300265B97 /* WebDeviceOrientationAndMotionAccessController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebDeviceOrientationAndMotionAccessController.h; sourceTree = "<group>"; };
+ 46B0524522668D2400265B97 /* WebDeviceOrientationAndMotionAccessController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebDeviceOrientationAndMotionAccessController.cpp; sourceTree = "<group>"; };
46DF06391F3905E5001980BB /* NetworkCORSPreflightChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCORSPreflightChecker.cpp; sourceTree = "<group>"; };
46DF063A1F3905E5001980BB /* NetworkCORSPreflightChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCORSPreflightChecker.h; sourceTree = "<group>"; };
4A410F3519AF7AC3002EBAB5 /* WKUserMediaPermissionRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKUserMediaPermissionRequest.cpp; sourceTree = "<group>"; };
@@ -4948,6 +4951,8 @@
isa = PBXGroup;
children = (
1A4832C01A965A33008B4DFE /* Cocoa */,
+ 46B0524522668D2400265B97 /* WebDeviceOrientationAndMotionAccessController.cpp */,
+ 46B0524422668D2300265B97 /* WebDeviceOrientationAndMotionAccessController.h */,
1A4832D81A9D1FD2008B4DFE /* WebsiteDataRecord.cpp */,
1A4832CF1A9BD821008B4DFE /* WebsiteDataRecord.h */,
1A53C2A41A32569F004E8C70 /* WebsiteDataStore.cpp */,
@@ -9593,6 +9598,7 @@
E568B91F20A3AB2F00E3C856 /* WebDataListSuggestionsDropdown.h in Headers */,
E5BEF6822130C48000F31111 /* WebDataListSuggestionsDropdownIOS.h in Headers */,
E568B92220A3AC6A00E3C856 /* WebDataListSuggestionsDropdownMac.h in Headers */,
+ 46B0524722668D8500265B97 /* WebDeviceOrientationAndMotionAccessController.h in Headers */,
CD19A26E1A13E834008D650E /* WebDiagnosticLoggingClient.h in Headers */,
1A5B1C5518987EDF004FCF9B /* WebDocumentLoader.h in Headers */,
BC032D7B10F4378D0058C15A /* WebDragClient.h in Headers */,
Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp (244381 => 244382)
--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp 2019-04-17 17:03:59 UTC (rev 244382)
@@ -1317,11 +1317,11 @@
#endif
#if ENABLE(DEVICE_ORIENTATION)
-void WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess(Frame& frame, CompletionHandler<void(bool)>&& callback)
+void WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess(Frame& frame, bool mayPrompt, CompletionHandler<void(DeviceOrientationOrMotionPermissionState)>&& callback)
{
auto* webFrame = WebFrame::fromCoreFrame(frame);
ASSERT(webFrame);
- m_page.shouldAllowDeviceOrientationAndMotionAccess(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), WTFMove(callback));
+ m_page.shouldAllowDeviceOrientationAndMotionAccess(webFrame->frameID(), SecurityOriginData::fromFrame(&frame), mayPrompt, WTFMove(callback));
}
#endif
Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h (244381 => 244382)
--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -367,7 +367,7 @@
#endif
#if ENABLE(DEVICE_ORIENTATION)
- void shouldAllowDeviceOrientationAndMotionAccess(WebCore::Frame&, CompletionHandler<void(bool)>&&) final;
+ void shouldAllowDeviceOrientationAndMotionAccess(WebCore::Frame&, bool mayPrompt, CompletionHandler<void(WebCore::DeviceOrientationOrMotionPermissionState)>&&) final;
#endif
void configureLoggingChannel(const String&, WTFLogChannelState, WTFLogLevel) final;
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (244381 => 244382)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-04-17 17:03:59 UTC (rev 244382)
@@ -6403,9 +6403,9 @@
#endif
#if ENABLE(DEVICE_ORIENTATION)
-void WebPage::shouldAllowDeviceOrientationAndMotionAccess(uint64_t frameID, WebCore::SecurityOriginData&& origin, CompletionHandler<void(bool)>&& completionHandler)
+void WebPage::shouldAllowDeviceOrientationAndMotionAccess(uint64_t frameID, WebCore::SecurityOriginData&& origin, bool mayPrompt, CompletionHandler<void(DeviceOrientationOrMotionPermissionState)>&& completionHandler)
{
- sendWithAsyncReply(Messages::WebPageProxy::RequestDeviceOrientationAndMotionAccess(frameID, WTFMove(origin)), WTFMove(completionHandler));
+ sendWithAsyncReply(Messages::WebPageProxy::ShouldAllowDeviceOrientationAndMotionAccess(frameID, WTFMove(origin), mayPrompt), WTFMove(completionHandler));
}
#endif
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (244381 => 244382)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-04-17 17:03:59 UTC (rev 244382)
@@ -1121,7 +1121,7 @@
#endif
#if ENABLE(DEVICE_ORIENTATION)
- void shouldAllowDeviceOrientationAndMotionAccess(uint64_t frameID, WebCore::SecurityOriginData&&, CompletionHandler<void(bool)>&&);
+ void shouldAllowDeviceOrientationAndMotionAccess(uint64_t frameID, WebCore::SecurityOriginData&&, bool mayPrompt, CompletionHandler<void(WebCore::DeviceOrientationOrMotionPermissionState)>&&);
#endif
void showShareSheet(WebCore::ShareDataWithParsedURL&, CompletionHandler<void(bool)>&& callback);
Modified: trunk/Tools/ChangeLog (244381 => 244382)
--- trunk/Tools/ChangeLog 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Tools/ChangeLog 2019-04-17 17:03:59 UTC (rev 244382)
@@ -1,3 +1,17 @@
+2019-04-17 Chris Dumez <[email protected]>
+
+ 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.
+
+ Add API test coverage.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/DeviceOrientation.mm:
+ (-[DeviceOrientationPermissionUIDelegate _webView:shouldAllowDeviceOrientationAndMotionAccessRequestedByFrame:decisionHandler:]):
+ (TEST):
+
2019-04-17 Aakash Jain <[email protected]>
[ews-app] Clicking 'submit to new ews' doesn't reload status-bubble
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DeviceOrientation.mm (244381 => 244382)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DeviceOrientation.mm 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DeviceOrientation.mm 2019-04-17 17:03:59 UTC (rev 244382)
@@ -39,6 +39,7 @@
static RetainPtr<NSMutableArray> receivedMessages = adoptNS([@[] mutableCopy]);
static bool didReceiveMessage;
+static bool askedClientForPermission;
@interface DeviceOrientationMessageHandler : NSObject <WKScriptMessageHandler>
@end
@@ -74,6 +75,7 @@
- (void)_webView:(WKWebView *)webView shouldAllowDeviceOrientationAndMotionAccessRequestedByFrame:(WKFrameInfo *)requestingFrame decisionHandler:(void (^)(BOOL))decisionHandler
{
decisionHandler(_decisionHandler());
+ askedClientForPermission = true;
}
@end
@@ -156,4 +158,96 @@
runDeviceOrientationTest(DeviceOrientationPermission::Denied);
}
+TEST(DeviceOrientation, RememberPermissionForSession)
+{
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ configuration.get().websiteDataStore = [WKWebsiteDataStore defaultDataStore];
+
+ auto messageHandler = adoptNS([[DeviceOrientationMessageHandler alloc] init]);
+ [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"testHandler"];
+
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ RetainPtr<DeviceOrientationPermissionUIDelegate> uiDelegate = adoptNS([[DeviceOrientationPermissionUIDelegate alloc] initWithHandler:[] { return true; }]);
+ [webView setUIDelegate:uiDelegate.get()];
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+ [webView loadRequest:request];
+ [webView _test_waitForDidFinishNavigation];
+
+ [webView evaluateJavaScript:@"DeviceOrientationEvent.requestPermission().then((granted) => { webkit.messageHandlers.testHandler.postMessage(granted) });" completionHandler: [&] (id result, NSError *error) { }];
+
+ TestWebKitAPI::Util::run(&didReceiveMessage);
+ didReceiveMessage = false;
+
+ EXPECT_TRUE(askedClientForPermission);
+ askedClientForPermission = false;
+ EXPECT_WK_STREQ(@"granted", receivedMessages.get()[0]);
+
+ // Load the same origin again in a new WebView, it should not ask the client.
+ webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ [webView setUIDelegate:uiDelegate.get()];
+
+ [webView loadRequest:request];
+ [webView _test_waitForDidFinishNavigation];
+
+ [webView _evaluateJavaScriptWithoutUserGesture:@"DeviceOrientationEvent.requestPermission().then((granted) => { webkit.messageHandlers.testHandler.postMessage(granted) }, (error) => { webkit.messageHandlers.testHandler.postMessage('error'); });" completionHandler: [&] (id result, NSError *error) { }];
+
+ TestWebKitAPI::Util::run(&didReceiveMessage);
+ didReceiveMessage = false;
+
+ EXPECT_WK_STREQ(@"granted", receivedMessages.get()[1]);
+ EXPECT_FALSE(askedClientForPermission);
+ askedClientForPermission = false;
+
+ // Load the same origin again in a new WebView but this time with a different data store, it should ask the client again.
+ configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ configuration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
+ [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"testHandler"];
+
+ webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ [webView setUIDelegate:uiDelegate.get()];
+
+ [webView loadRequest:request];
+ [webView _test_waitForDidFinishNavigation];
+
+ [webView evaluateJavaScript:@"DeviceOrientationEvent.requestPermission().then((granted) => { webkit.messageHandlers.testHandler.postMessage(granted) });" completionHandler: [&] (id result, NSError *error) { }];
+
+ TestWebKitAPI::Util::run(&didReceiveMessage);
+ didReceiveMessage = false;
+
+ EXPECT_TRUE(askedClientForPermission);
+ askedClientForPermission = false;
+ EXPECT_WK_STREQ(@"granted", receivedMessages.get()[2]);
+
+ // Now go to a different origin, it should ask the client again.
+ NSURLRequest *request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]];
+ [webView loadRequest:request2];
+ [webView _test_waitForDidFinishNavigation];
+
+ [webView evaluateJavaScript:@"DeviceOrientationEvent.requestPermission().then((granted) => { webkit.messageHandlers.testHandler.postMessage(granted) });" completionHandler: [&] (id result, NSError *error) { }];
+
+ TestWebKitAPI::Util::run(&didReceiveMessage);
+ didReceiveMessage = false;
+
+ EXPECT_TRUE(askedClientForPermission);
+ askedClientForPermission = false;
+ EXPECT_WK_STREQ(@"granted", receivedMessages.get()[3]);
+
+ // Go back to the first origin in a new WebView (same data store) and make sure it does not ask the client.
+ webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ [webView setUIDelegate:uiDelegate.get()];
+
+ [webView loadRequest:request];
+ [webView _test_waitForDidFinishNavigation];
+
+ [webView _evaluateJavaScriptWithoutUserGesture:@"DeviceOrientationEvent.requestPermission().then((granted) => { webkit.messageHandlers.testHandler.postMessage(granted) }, (error) => { webkit.messageHandlers.testHandler.postMessage('error'); });" completionHandler: [&] (id result, NSError *error) { }];
+
+ TestWebKitAPI::Util::run(&didReceiveMessage);
+ didReceiveMessage = false;
+
+ EXPECT_WK_STREQ(@"granted", receivedMessages.get()[4]);
+ EXPECT_FALSE(askedClientForPermission);
+ askedClientForPermission = false;
+}
+
#endif // PLATFORM(IOS_FAMILY)
Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (244381 => 244382)
--- trunk/Tools/WebKitTestRunner/TestController.cpp 2019-04-17 16:47:44 UTC (rev 244381)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp 2019-04-17 17:03:59 UTC (rev 244382)
@@ -914,6 +914,9 @@
WKContextClearCachedCredentials(TestController::singleton().context());
+ auto websiteDataStore = WKContextGetWebsiteDataStore(TestController::singleton().context());
+ WKWebsiteDataStoreClearAllDeviceOrientationPermissions(websiteDataStore);
+
ClearIndexedDatabases();
setIDBPerOriginQuota(50 * MB);