Diff
Modified: trunk/Source/WebCore/ChangeLog (242959 => 242960)
--- trunk/Source/WebCore/ChangeLog 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebCore/ChangeLog 2019-03-14 20:40:09 UTC (rev 242960)
@@ -1,3 +1,26 @@
+2019-03-14 Chris Dumez <[email protected]>
+
+ Add WebsitePolicy for the client to specify the device orientation & motion access policy
+ https://bugs.webkit.org/show_bug.cgi?id=195750
+
+ Reviewed by Geoffrey Garen.
+
+ Add WebsitePolicy for the client to specify the device orientation & motion access policy. If
+ the client already knows access to the device motion & orientation API will be granted / denied,
+ it can let WebKit know via WebsitePolicies so that WebKit will not ask the client when the
+ permission is requested by JS.
+
+ * dom/DeviceOrientationAndMotionAccessController.cpp:
+ (WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess):
+ (WebCore::DeviceOrientationAndMotionAccessController::setAccessState):
+ (WebCore::DeviceOrientationAndMotionAccessController::accessState const):
+ * dom/DeviceOrientationAndMotionAccessController.h:
+ * loader/DocumentLoader.h:
+ (WebCore::DocumentLoader::deviceOrientationAndMotionAccessState const):
+ (WebCore::DocumentLoader::setDeviceOrientationAndMotionAccessState):
+ * page/DOMWindow.cpp:
+ (WebCore::DOMWindow::isAllowedToUseDeviceMotionOrientation const):
+
2019-03-14 Shawn Roberts <[email protected]>
Unreviewed, rolling out r242931.
Modified: trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.cpp (242959 => 242960)
--- trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.cpp 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.cpp 2019-03-14 20:40:09 UTC (rev 242960)
@@ -32,6 +32,7 @@
#include "ChromeClient.h"
#include "DOMWindow.h"
#include "Document.h"
+#include "DocumentLoader.h"
#include "Frame.h"
#include "Page.h"
#include "UserGestureIndicator.h"
@@ -46,8 +47,9 @@
void DeviceOrientationAndMotionAccessController::shouldAllowAccess(Function<void(ExceptionOr<bool> granted)>&& callback)
{
- if (m_accessState)
- return callback(*m_accessState);
+ 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 });
@@ -56,15 +58,11 @@
if (!page)
return callback(false);
- auto* frame = m_document.frame();
- if (!frame)
- return callback(false);
-
m_pendingRequests.append(WTFMove(callback));
if (m_pendingRequests.size() > 1)
return;
- page->chrome().client().shouldAllowDeviceOrientationAndMotionAccess(*frame, [this, weakThis = makeWeakPtr(*this)](bool granted) mutable {
+ page->chrome().client().shouldAllowDeviceOrientationAndMotionAccess(*m_document.frame(), [this, weakThis = makeWeakPtr(*this)](bool granted) mutable {
if (weakThis)
setAccessState(granted);
});
@@ -72,10 +70,10 @@
void DeviceOrientationAndMotionAccessController::setAccessState(bool granted)
{
- ASSERT(!m_accessState);
+ auto* frame = m_document.frame();
+ if (frame && frame->loader().documentLoader())
+ frame->loader().documentLoader()->setDeviceOrientationAndMotionAccessState(granted);
- m_accessState = granted;
-
auto pendingRequests = WTFMove(m_pendingRequests);
for (auto& request : pendingRequests)
request(granted);
@@ -89,6 +87,12 @@
}
}
+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 (242959 => 242960)
--- trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h 2019-03-14 20:40:09 UTC (rev 242960)
@@ -41,7 +41,7 @@
public:
explicit DeviceOrientationAndMotionAccessController(Document&);
- const Optional<bool>& accessState() const { return m_accessState; }
+ Optional<bool> accessState() const;
void shouldAllowAccess(Function<void(ExceptionOr<bool> granted)>&&);
private:
@@ -48,7 +48,6 @@
void setAccessState(bool);
Document& m_document;
- Optional<bool> m_accessState;
Vector<Function<void(bool)>> m_pendingRequests;
};
Modified: trunk/Source/WebCore/loader/DocumentLoader.h (242959 => 242960)
--- trunk/Source/WebCore/loader/DocumentLoader.h 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebCore/loader/DocumentLoader.h 2019-03-14 20:40:09 UTC (rev 242960)
@@ -262,8 +262,8 @@
bool userContentExtensionsEnabled() const { return m_userContentExtensionsEnabled; }
void setUserContentExtensionsEnabled(bool enabled) { m_userContentExtensionsEnabled = enabled; }
- bool deviceOrientationEventEnabled() const { return m_deviceOrientationEventEnabled; }
- void setDeviceOrientationEventEnabled(bool enabled) { m_deviceOrientationEventEnabled = enabled; }
+ const Optional<bool>& deviceOrientationAndMotionAccessState() const { return m_deviceOrientationAndMotionAccessState; }
+ void setDeviceOrientationAndMotionAccessState(const Optional<bool>& state) { m_deviceOrientationAndMotionAccessState = state; }
AutoplayPolicy autoplayPolicy() const { return m_autoplayPolicy; }
void setAutoplayPolicy(AutoplayPolicy policy) { m_autoplayPolicy = policy; }
@@ -552,7 +552,7 @@
String m_customJavaScriptUserAgentAsSiteSpecificQuirks;
String m_customNavigatorPlatform;
bool m_userContentExtensionsEnabled { true };
- bool m_deviceOrientationEventEnabled { true };
+ Optional<bool> m_deviceOrientationAndMotionAccessState;
AutoplayPolicy m_autoplayPolicy { AutoplayPolicy::Default };
OptionSet<AutoplayQuirk> m_allowedAutoplayQuirks;
PopUpPolicy m_popUpPolicy { PopUpPolicy::Default };
Modified: trunk/Source/WebCore/page/DOMWindow.cpp (242959 => 242960)
--- trunk/Source/WebCore/page/DOMWindow.cpp 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebCore/page/DOMWindow.cpp 2019-03-14 20:40:09 UTC (rev 242960)
@@ -1840,7 +1840,7 @@
bool DOMWindow::isAllowedToUseDeviceMotionOrientation(String& message) const
{
- if (!frame() || !frame()->settings().deviceOrientationEventEnabled() || !document() || !document()->loader() || !document()->loader()->deviceOrientationEventEnabled()) {
+ if (!frame() || !frame()->settings().deviceOrientationEventEnabled()) {
message = "API is disabled"_s;
return false;
}
Modified: trunk/Source/WebKit/ChangeLog (242959 => 242960)
--- trunk/Source/WebKit/ChangeLog 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebKit/ChangeLog 2019-03-14 20:40:09 UTC (rev 242960)
@@ -1,3 +1,28 @@
+2019-03-14 Chris Dumez <[email protected]>
+
+ Add WebsitePolicy for the client to specify the device orientation & motion access policy
+ https://bugs.webkit.org/show_bug.cgi?id=195750
+
+ Reviewed by Geoffrey Garen.
+
+ Add WebsitePolicy for the client to specify the device orientation & motion access policy. If
+ the client already knows access to the device motion & orientation API will be granted / denied,
+ it can let WebKit know via WebsitePolicies so that WebKit will not ask the client when the
+ permission is requested by JS.
+
+ * Shared/WebsitePoliciesData.cpp:
+ (WebKit::WebsitePoliciesData::encode const):
+ (WebKit::WebsitePoliciesData::decode):
+ (WebKit::WebsitePoliciesData::applyToDocumentLoader):
+ * Shared/WebsitePoliciesData.h:
+ * UIProcess/API/APIWebsitePolicies.cpp:
+ (API::WebsitePolicies::data):
+ * UIProcess/API/APIWebsitePolicies.h:
+ * UIProcess/API/Cocoa/_WKWebsitePolicies.h:
+ * UIProcess/API/Cocoa/_WKWebsitePolicies.mm:
+ (-[_WKWebsitePolicies setDeviceOrientationAndMotionAccessPolicy:]):
+ (-[_WKWebsitePolicies deviceOrientationAndMotionAccessPolicy]):
+
2019-03-14 Timothy Hatcher <[email protected]>
REGRESSION (r242908): TestWebKitAPI.WebKit.AddAndRemoveDataDetectors Crashed
Modified: trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp (242959 => 242960)
--- trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp 2019-03-14 20:40:09 UTC (rev 242960)
@@ -37,8 +37,8 @@
void WebsitePoliciesData::encode(IPC::Encoder& encoder) const
{
encoder << contentBlockersEnabled;
- encoder << deviceOrientationEventEnabled;
encoder << autoplayPolicy;
+ encoder << deviceOrientationAndMotionAccessState;
encoder << allowedAutoplayQuirks;
encoder << customHeaderFields;
encoder << popUpPolicy;
@@ -54,16 +54,16 @@
decoder >> contentBlockersEnabled;
if (!contentBlockersEnabled)
return WTF::nullopt;
-
- Optional<bool> deviceOrientationEventEnabled;
- decoder >> deviceOrientationEventEnabled;
- if (!deviceOrientationEventEnabled)
- return WTF::nullopt;
Optional<WebsiteAutoplayPolicy> autoplayPolicy;
decoder >> autoplayPolicy;
if (!autoplayPolicy)
return WTF::nullopt;
+
+ Optional<Optional<bool>> deviceOrientationAndMotionAccessState;
+ decoder >> deviceOrientationAndMotionAccessState;
+ if (!deviceOrientationAndMotionAccessState)
+ return WTF::nullopt;
Optional<OptionSet<WebsiteAutoplayQuirk>> allowedAutoplayQuirks;
decoder >> allowedAutoplayQuirks;
@@ -102,9 +102,9 @@
return { {
WTFMove(*contentBlockersEnabled),
- WTFMove(*deviceOrientationEventEnabled),
WTFMove(*allowedAutoplayQuirks),
WTFMove(*autoplayPolicy),
+ WTFMove(*deviceOrientationAndMotionAccessState),
WTFMove(*customHeaderFields),
WTFMove(*popUpPolicy),
WTFMove(*websiteDataStoreParameters),
@@ -120,7 +120,7 @@
documentLoader.setCustomUserAgent(websitePolicies.customUserAgent);
documentLoader.setCustomJavaScriptUserAgentAsSiteSpecificQuirks(websitePolicies.customJavaScriptUserAgentAsSiteSpecificQuirks);
documentLoader.setCustomNavigatorPlatform(websitePolicies.customNavigatorPlatform);
- documentLoader.setDeviceOrientationEventEnabled(websitePolicies.deviceOrientationEventEnabled);
+ documentLoader.setDeviceOrientationAndMotionAccessState(websitePolicies.deviceOrientationAndMotionAccessState);
// Only setUserContentExtensionsEnabled if it hasn't already been disabled by reloading without content blockers.
if (documentLoader.userContentExtensionsEnabled())
Modified: trunk/Source/WebKit/Shared/WebsitePoliciesData.h (242959 => 242960)
--- trunk/Source/WebKit/Shared/WebsitePoliciesData.h 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebKit/Shared/WebsitePoliciesData.h 2019-03-14 20:40:09 UTC (rev 242960)
@@ -47,9 +47,9 @@
static void applyToDocumentLoader(WebsitePoliciesData&&, WebCore::DocumentLoader&);
bool contentBlockersEnabled { true };
- bool deviceOrientationEventEnabled { true };
OptionSet<WebsiteAutoplayQuirk> allowedAutoplayQuirks;
WebsiteAutoplayPolicy autoplayPolicy { WebsiteAutoplayPolicy::Default };
+ Optional<bool> deviceOrientationAndMotionAccessState;
Vector<WebCore::HTTPHeaderField> customHeaderFields;
WebsitePopUpPolicy popUpPolicy { WebsitePopUpPolicy::Default };
Optional<WebsiteDataStoreParameters> websiteDataStoreParameters;
Modified: trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp (242959 => 242960)
--- trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp 2019-03-14 20:40:09 UTC (rev 242960)
@@ -56,7 +56,7 @@
Optional<WebKit::WebsiteDataStoreParameters> parameters;
if (m_websiteDataStore)
parameters = m_websiteDataStore->websiteDataStore().parameters();
- return { contentBlockersEnabled(), deviceOrientationEventEnabled(), allowedAutoplayQuirks(), autoplayPolicy(),
+ return { contentBlockersEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), deviceOrientationAndMotionAccessState(),
customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent, m_customJavaScriptUserAgentAsSiteSpecificQuirks, m_customNavigatorPlatform };
}
Modified: trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h (242959 => 242960)
--- trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h 2019-03-14 20:40:09 UTC (rev 242960)
@@ -49,9 +49,6 @@
bool contentBlockersEnabled() const { return m_contentBlockersEnabled; }
void setContentBlockersEnabled(bool enabled) { m_contentBlockersEnabled = enabled; }
-
- bool deviceOrientationEventEnabled() const { return m_deviceOrientationEventEnabled; }
- void setDeviceOrientationEventEnabled(bool enabled) { m_deviceOrientationEventEnabled = enabled; }
OptionSet<WebKit::WebsiteAutoplayQuirk> allowedAutoplayQuirks() const { return m_allowedAutoplayQuirks; }
void setAllowedAutoplayQuirks(OptionSet<WebKit::WebsiteAutoplayQuirk> quirks) { m_allowedAutoplayQuirks = quirks; }
@@ -58,6 +55,9 @@
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; }
const Vector<WebCore::HTTPHeaderField>& customHeaderFields() const { return m_customHeaderFields; }
Vector<WebCore::HTTPHeaderField>&& takeCustomHeaderFields() { return WTFMove(m_customHeaderFields); }
@@ -84,9 +84,9 @@
WebsitePolicies(bool contentBlockersEnabled, OptionSet<WebKit::WebsiteAutoplayQuirk>, WebKit::WebsiteAutoplayPolicy, Vector<WebCore::HTTPHeaderField>&&, WebKit::WebsitePopUpPolicy, RefPtr<WebsiteDataStore>&&);
bool m_contentBlockersEnabled { true };
- bool m_deviceOrientationEventEnabled { true };
OptionSet<WebKit::WebsiteAutoplayQuirk> m_allowedAutoplayQuirks;
WebKit::WebsiteAutoplayPolicy m_autoplayPolicy { WebKit::WebsiteAutoplayPolicy::Default };
+ Optional<bool> m_deviceOrientationAndMotionAccessState;
Vector<WebCore::HTTPHeaderField> m_customHeaderFields;
WebKit::WebsitePopUpPolicy m_popUpPolicy { WebKit::WebsitePopUpPolicy::Default };
RefPtr<WebsiteDataStore> m_websiteDataStore;
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h (242959 => 242960)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h 2019-03-14 20:40:09 UTC (rev 242960)
@@ -45,6 +45,12 @@
_WKWebsitePopUpPolicyBlock,
} WK_API_AVAILABLE(macosx(10.14), ios(12.0));
+typedef NS_OPTIONS(NSUInteger, _WKWebsiteDeviceOrientationAndMotionAccessPolicy) {
+ _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk,
+ _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant,
+ _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny,
+} WK_API_AVAILABLE(macosx(10.14), ios(12.0));
+
@class WKWebsiteDataStore;
WK_CLASS_AVAILABLE(macosx(10.12.3), ios(10.3))
@@ -59,6 +65,6 @@
@property (nonatomic, copy) NSString *customUserAgent WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
@property (nonatomic, copy) NSString *customJavaScriptUserAgentAsSiteSpecificQuirks WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
@property (nonatomic, copy) NSString *customNavigatorPlatform WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
-@property (nonatomic) BOOL deviceOrientationEventEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic) _WKWebsiteDeviceOrientationAndMotionAccessPolicy deviceOrientationAndMotionAccessPolicy WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
@end
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm (242959 => 242960)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm 2019-03-14 20:40:09 UTC (rev 242960)
@@ -57,16 +57,6 @@
return _websitePolicies->contentBlockersEnabled();
}
-- (void)setDeviceOrientationEventEnabled:(BOOL)deviceOrientationEventEnabled
-{
- _websitePolicies->setDeviceOrientationEventEnabled(deviceOrientationEventEnabled);
-}
-
-- (BOOL)deviceOrientationEventEnabled
-{
- return _websitePolicies->deviceOrientationEventEnabled();
-}
-
- (void)setAllowedAutoplayQuirks:(_WKWebsiteAutoplayQuirk)allowedQuirks
{
OptionSet<WebKit::WebsiteAutoplayQuirk> quirks;
@@ -138,6 +128,28 @@
}
}
+- (void)setDeviceOrientationAndMotionAccessPolicy:(_WKWebsiteDeviceOrientationAndMotionAccessPolicy)policy
+{
+ switch (policy) {
+ case _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk:
+ _websitePolicies->setDeviceOrientationAndMotionAccessState(WTF::nullopt);
+ break;
+ case _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant:
+ _websitePolicies->setDeviceOrientationAndMotionAccessState(true);
+ break;
+ case _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny:
+ _websitePolicies->setDeviceOrientationAndMotionAccessState(false);
+ break;
+ }
+}
+
+- (_WKWebsiteDeviceOrientationAndMotionAccessPolicy)deviceOrientationAndMotionAccessPolicy
+{
+ if (!_websitePolicies->deviceOrientationAndMotionAccessState())
+ return _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk;
+ return *_websitePolicies->deviceOrientationAndMotionAccessState() ? _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant : _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny;
+}
+
- (void)setPopUpPolicy:(_WKWebsitePopUpPolicy)policy
{
switch (policy) {
Modified: trunk/Tools/ChangeLog (242959 => 242960)
--- trunk/Tools/ChangeLog 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Tools/ChangeLog 2019-03-14 20:40:09 UTC (rev 242960)
@@ -1,5 +1,19 @@
2019-03-14 Chris Dumez <[email protected]>
+ Add WebsitePolicy for the client to specify the device orientation & motion access policy
+ https://bugs.webkit.org/show_bug.cgi?id=195750
+
+ Reviewed by Geoffrey Garen.
+
+ Add API test coverage.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
+ (-[WebsitePoliciesDeviceOrientationDelegate initWithDeviceOrientationAccessPolicy:]):
+ (-[WebsitePoliciesDeviceOrientationDelegate _webView:decidePolicyForNavigationAction:userInfo:decisionHandler:]):
+ (-[WebsitePoliciesDeviceOrientationUIDelegate _webView:shouldAllowDeviceOrientationAndMotionAccessRequestedByFrame:decisionHandler:]):
+
+2019-03-14 Chris Dumez <[email protected]>
+
[PSON] Make sure the WebProcessCache is leverage when relaunching a process after termination
https://bugs.webkit.org/show_bug.cgi?id=195747
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm (242959 => 242960)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm 2019-03-14 20:30:08 UTC (rev 242959)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm 2019-03-14 20:40:09 UTC (rev 242960)
@@ -1246,17 +1246,17 @@
)TESTRESOURCE";
@interface WebsitePoliciesDeviceOrientationDelegate : NSObject <WKNavigationDelegate> {
- BOOL _deviceOrientationEventEnabled;
+ _WKWebsiteDeviceOrientationAndMotionAccessPolicy _accessPolicy;
}
-- (instancetype)initWithDeviceOrientationEventEnabled:(BOOL)enabled;
+- (instancetype)initWithDeviceOrientationAccessPolicy:(_WKWebsiteDeviceOrientationAndMotionAccessPolicy)accessPolicy;
@end
@implementation WebsitePoliciesDeviceOrientationDelegate
-- (instancetype)initWithDeviceOrientationEventEnabled:(BOOL)enabled
+- (instancetype)initWithDeviceOrientationAccessPolicy:(_WKWebsiteDeviceOrientationAndMotionAccessPolicy)accessPolicy
{
self = [super init];
- _deviceOrientationEventEnabled = enabled;
+ _accessPolicy = accessPolicy;
return self;
}
@@ -1263,7 +1263,7 @@
- (void)_webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction userInfo:(id <NSSecureCoding>)userInfo decisionHandler:(void (^)(WKNavigationActionPolicy, _WKWebsitePolicies *))decisionHandler
{
_WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease];
- [websitePolicies setDeviceOrientationEventEnabled:_deviceOrientationEventEnabled];
+ [websitePolicies setDeviceOrientationAndMotionAccessPolicy:_accessPolicy];
decisionHandler(WKNavigationActionPolicyAllow, websitePolicies);
}
@@ -1275,6 +1275,8 @@
@end
+static bool calledShouldAllowDeviceOrientationAndMotionAccessDelegate = false;
+
@interface WebsitePoliciesDeviceOrientationUIDelegate : NSObject <WKUIDelegatePrivate> {
}
@end
@@ -1283,12 +1285,13 @@
- (void)_webView:(WKWebView *)webView shouldAllowDeviceOrientationAndMotionAccessRequestedByFrame:(WKFrameInfo *)requestingFrame decisionHandler:(void (^)(BOOL))decisionHandler
{
+ calledShouldAllowDeviceOrientationAndMotionAccessDelegate = true;
decisionHandler(YES);
}
@end
-static void runWebsitePoliciesDeviceOrientationEventTest(bool websitePolicyValue)
+static void runWebsitePoliciesDeviceOrientationEventTest(_WKWebsiteDeviceOrientationAndMotionAccessPolicy accessPolicy)
{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
@@ -1298,7 +1301,7 @@
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
- auto delegate = adoptNS([[WebsitePoliciesDeviceOrientationDelegate alloc] initWithDeviceOrientationEventEnabled:websitePolicyValue]);
+ auto delegate = adoptNS([[WebsitePoliciesDeviceOrientationDelegate alloc] initWithDeviceOrientationAccessPolicy:accessPolicy]);
[webView setNavigationDelegate:delegate.get()];
auto uiDelegate = adoptNS([[WebsitePoliciesDeviceOrientationUIDelegate alloc] init]);
[webView setUIDelegate:uiDelegate.get()];
@@ -1321,7 +1324,12 @@
[webView _simulateDeviceOrientationChangeWithAlpha:1.0 beta:2.0 gamma:3.0];
- if (websitePolicyValue)
+ if (accessPolicy == _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk)
+ EXPECT_TRUE(calledShouldAllowDeviceOrientationAndMotionAccessDelegate);
+ else
+ EXPECT_FALSE(calledShouldAllowDeviceOrientationAndMotionAccessDelegate);
+
+ if (accessPolicy != _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny)
TestWebKitAPI::Util::run(&didReceiveMessage);
else {
TestWebKitAPI::Util::sleep(0.1);
@@ -1329,16 +1337,21 @@
}
}
-TEST(WebKit, WebsitePoliciesDeviceOrientationEventEnabled)
+TEST(WebKit, WebsitePoliciesDeviceOrientationGrantAccess)
{
- runWebsitePoliciesDeviceOrientationEventTest(true);
+ runWebsitePoliciesDeviceOrientationEventTest(_WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant);
}
-TEST(WebKit, WebsitePoliciesDeviceOrientationEventDisabled)
+TEST(WebKit, WebsitePoliciesDeviceOrientationDenyAccess)
{
- runWebsitePoliciesDeviceOrientationEventTest(false);
+ runWebsitePoliciesDeviceOrientationEventTest(_WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny);
}
+TEST(WebKit, WebsitePoliciesDeviceOrientationAskAccess)
+{
+ runWebsitePoliciesDeviceOrientationEventTest(_WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk);
+}
+
#endif // PLATFORM(IOS_FAMILY)
@interface PopUpPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegatePrivate>