Changeset 242960 in webkit
- Timestamp:
- Mar 14, 2019, 1:40:09 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/dom/DeviceOrientationAndMotionAccessController.cpp (modified) (5 diffs)
-
Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h (modified) (2 diffs)
-
Source/WebCore/loader/DocumentLoader.h (modified) (2 diffs)
-
Source/WebCore/page/DOMWindow.cpp (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/Shared/WebsitePoliciesData.cpp (modified) (4 diffs)
-
Source/WebKit/Shared/WebsitePoliciesData.h (modified) (1 diff)
-
Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp (modified) (1 diff)
-
Source/WebKit/UIProcess/API/APIWebsitePolicies.h (modified) (3 diffs)
-
Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm (modified) (2 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r242956 r242960 1 2019-03-14 Chris Dumez <cdumez@apple.com> 2 3 Add WebsitePolicy for the client to specify the device orientation & motion access policy 4 https://bugs.webkit.org/show_bug.cgi?id=195750 5 6 Reviewed by Geoffrey Garen. 7 8 Add WebsitePolicy for the client to specify the device orientation & motion access policy. If 9 the client already knows access to the device motion & orientation API will be granted / denied, 10 it can let WebKit know via WebsitePolicies so that WebKit will not ask the client when the 11 permission is requested by JS. 12 13 * dom/DeviceOrientationAndMotionAccessController.cpp: 14 (WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess): 15 (WebCore::DeviceOrientationAndMotionAccessController::setAccessState): 16 (WebCore::DeviceOrientationAndMotionAccessController::accessState const): 17 * dom/DeviceOrientationAndMotionAccessController.h: 18 * loader/DocumentLoader.h: 19 (WebCore::DocumentLoader::deviceOrientationAndMotionAccessState const): 20 (WebCore::DocumentLoader::setDeviceOrientationAndMotionAccessState): 21 * page/DOMWindow.cpp: 22 (WebCore::DOMWindow::isAllowedToUseDeviceMotionOrientation const): 23 1 24 2019-03-14 Shawn Roberts <sroberts@apple.com> 2 25 -
trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.cpp
r242951 r242960 33 33 #include "DOMWindow.h" 34 34 #include "Document.h" 35 #include "DocumentLoader.h" 35 36 #include "Frame.h" 36 37 #include "Page.h" … … 47 48 void DeviceOrientationAndMotionAccessController::shouldAllowAccess(Function<void(ExceptionOr<bool> granted)>&& callback) 48 49 { 49 if (m_accessState) 50 return callback(*m_accessState); 50 if (auto accessState = this->accessState()) 51 return callback(*accessState); 52 ASSERT(m_document.frame()); 51 53 52 54 if (!UserGestureIndicator::processingUserGesture()) … … 57 59 return callback(false); 58 60 59 auto* frame = m_document.frame();60 if (!frame)61 return callback(false);62 63 61 m_pendingRequests.append(WTFMove(callback)); 64 62 if (m_pendingRequests.size() > 1) 65 63 return; 66 64 67 page->chrome().client().shouldAllowDeviceOrientationAndMotionAccess(* frame, [this, weakThis = makeWeakPtr(*this)](bool granted) mutable {65 page->chrome().client().shouldAllowDeviceOrientationAndMotionAccess(*m_document.frame(), [this, weakThis = makeWeakPtr(*this)](bool granted) mutable { 68 66 if (weakThis) 69 67 setAccessState(granted); … … 73 71 void DeviceOrientationAndMotionAccessController::setAccessState(bool granted) 74 72 { 75 ASSERT(!m_accessState);76 77 m_accessState = granted;73 auto* frame = m_document.frame(); 74 if (frame && frame->loader().documentLoader()) 75 frame->loader().documentLoader()->setDeviceOrientationAndMotionAccessState(granted); 78 76 79 77 auto pendingRequests = WTFMove(m_pendingRequests); … … 90 88 } 91 89 90 Optional<bool> DeviceOrientationAndMotionAccessController::accessState() const 91 { 92 auto* frame = m_document.frame(); 93 return frame && frame->loader().documentLoader() ? frame->loader().documentLoader()->deviceOrientationAndMotionAccessState() : false; 94 } 95 92 96 } // namespace WebCore 93 97 -
trunk/Source/WebCore/dom/DeviceOrientationAndMotionAccessController.h
r242951 r242960 42 42 explicit DeviceOrientationAndMotionAccessController(Document&); 43 43 44 const Optional<bool>& accessState() const { return m_accessState; }44 Optional<bool> accessState() const; 45 45 void shouldAllowAccess(Function<void(ExceptionOr<bool> granted)>&&); 46 46 … … 49 49 50 50 Document& m_document; 51 Optional<bool> m_accessState;52 51 Vector<Function<void(bool)>> m_pendingRequests; 53 52 }; -
trunk/Source/WebCore/loader/DocumentLoader.h
r241480 r242960 263 263 void setUserContentExtensionsEnabled(bool enabled) { m_userContentExtensionsEnabled = enabled; } 264 264 265 bool deviceOrientationEventEnabled() const { return m_deviceOrientationEventEnabled; }266 void setDeviceOrientation EventEnabled(bool enabled) { m_deviceOrientationEventEnabled = enabled; }265 const Optional<bool>& deviceOrientationAndMotionAccessState() const { return m_deviceOrientationAndMotionAccessState; } 266 void setDeviceOrientationAndMotionAccessState(const Optional<bool>& state) { m_deviceOrientationAndMotionAccessState = state; } 267 267 268 268 AutoplayPolicy autoplayPolicy() const { return m_autoplayPolicy; } … … 553 553 String m_customNavigatorPlatform; 554 554 bool m_userContentExtensionsEnabled { true }; 555 bool m_deviceOrientationEventEnabled { true };555 Optional<bool> m_deviceOrientationAndMotionAccessState; 556 556 AutoplayPolicy m_autoplayPolicy { AutoplayPolicy::Default }; 557 557 OptionSet<AutoplayQuirk> m_allowedAutoplayQuirks; -
trunk/Source/WebCore/page/DOMWindow.cpp
r242899 r242960 1841 1841 bool DOMWindow::isAllowedToUseDeviceMotionOrientation(String& message) const 1842 1842 { 1843 if (!frame() || !frame()->settings().deviceOrientationEventEnabled() || !document() || !document()->loader() || !document()->loader()->deviceOrientationEventEnabled()) {1843 if (!frame() || !frame()->settings().deviceOrientationEventEnabled()) { 1844 1844 message = "API is disabled"_s; 1845 1845 return false; -
trunk/Source/WebKit/ChangeLog
r242953 r242960 1 2019-03-14 Chris Dumez <cdumez@apple.com> 2 3 Add WebsitePolicy for the client to specify the device orientation & motion access policy 4 https://bugs.webkit.org/show_bug.cgi?id=195750 5 6 Reviewed by Geoffrey Garen. 7 8 Add WebsitePolicy for the client to specify the device orientation & motion access policy. If 9 the client already knows access to the device motion & orientation API will be granted / denied, 10 it can let WebKit know via WebsitePolicies so that WebKit will not ask the client when the 11 permission is requested by JS. 12 13 * Shared/WebsitePoliciesData.cpp: 14 (WebKit::WebsitePoliciesData::encode const): 15 (WebKit::WebsitePoliciesData::decode): 16 (WebKit::WebsitePoliciesData::applyToDocumentLoader): 17 * Shared/WebsitePoliciesData.h: 18 * UIProcess/API/APIWebsitePolicies.cpp: 19 (API::WebsitePolicies::data): 20 * UIProcess/API/APIWebsitePolicies.h: 21 * UIProcess/API/Cocoa/_WKWebsitePolicies.h: 22 * UIProcess/API/Cocoa/_WKWebsitePolicies.mm: 23 (-[_WKWebsitePolicies setDeviceOrientationAndMotionAccessPolicy:]): 24 (-[_WKWebsitePolicies deviceOrientationAndMotionAccessPolicy]): 25 1 26 2019-03-14 Timothy Hatcher <timothy@apple.com> 2 27 -
trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp
r240646 r242960 38 38 { 39 39 encoder << contentBlockersEnabled; 40 encoder << deviceOrientationEventEnabled;41 40 encoder << autoplayPolicy; 41 encoder << deviceOrientationAndMotionAccessState; 42 42 encoder << allowedAutoplayQuirks; 43 43 encoder << customHeaderFields; … … 55 55 if (!contentBlockersEnabled) 56 56 return WTF::nullopt; 57 58 Optional<bool> deviceOrientationEventEnabled;59 decoder >> deviceOrientationEventEnabled;60 if (!deviceOrientationEventEnabled)61 return WTF::nullopt;62 57 63 58 Optional<WebsiteAutoplayPolicy> autoplayPolicy; 64 59 decoder >> autoplayPolicy; 65 60 if (!autoplayPolicy) 61 return WTF::nullopt; 62 63 Optional<Optional<bool>> deviceOrientationAndMotionAccessState; 64 decoder >> deviceOrientationAndMotionAccessState; 65 if (!deviceOrientationAndMotionAccessState) 66 66 return WTF::nullopt; 67 67 … … 103 103 return { { 104 104 WTFMove(*contentBlockersEnabled), 105 WTFMove(*deviceOrientationEventEnabled),106 105 WTFMove(*allowedAutoplayQuirks), 107 106 WTFMove(*autoplayPolicy), 107 WTFMove(*deviceOrientationAndMotionAccessState), 108 108 WTFMove(*customHeaderFields), 109 109 WTFMove(*popUpPolicy), … … 121 121 documentLoader.setCustomJavaScriptUserAgentAsSiteSpecificQuirks(websitePolicies.customJavaScriptUserAgentAsSiteSpecificQuirks); 122 122 documentLoader.setCustomNavigatorPlatform(websitePolicies.customNavigatorPlatform); 123 documentLoader.setDeviceOrientation EventEnabled(websitePolicies.deviceOrientationEventEnabled);123 documentLoader.setDeviceOrientationAndMotionAccessState(websitePolicies.deviceOrientationAndMotionAccessState); 124 124 125 125 // Only setUserContentExtensionsEnabled if it hasn't already been disabled by reloading without content blockers. -
trunk/Source/WebKit/Shared/WebsitePoliciesData.h
r240646 r242960 48 48 49 49 bool contentBlockersEnabled { true }; 50 bool deviceOrientationEventEnabled { true };51 50 OptionSet<WebsiteAutoplayQuirk> allowedAutoplayQuirks; 52 51 WebsiteAutoplayPolicy autoplayPolicy { WebsiteAutoplayPolicy::Default }; 52 Optional<bool> deviceOrientationAndMotionAccessState; 53 53 Vector<WebCore::HTTPHeaderField> customHeaderFields; 54 54 WebsitePopUpPolicy popUpPolicy { WebsitePopUpPolicy::Default }; -
trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp
r240646 r242960 57 57 if (m_websiteDataStore) 58 58 parameters = m_websiteDataStore->websiteDataStore().parameters(); 59 return { contentBlockersEnabled(), deviceOrientationEventEnabled(), allowedAutoplayQuirks(), autoplayPolicy(),59 return { contentBlockersEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), deviceOrientationAndMotionAccessState(), 60 60 customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent, m_customJavaScriptUserAgentAsSiteSpecificQuirks, m_customNavigatorPlatform }; 61 61 } -
trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h
r242776 r242960 50 50 bool contentBlockersEnabled() const { return m_contentBlockersEnabled; } 51 51 void setContentBlockersEnabled(bool enabled) { m_contentBlockersEnabled = enabled; } 52 53 bool deviceOrientationEventEnabled() const { return m_deviceOrientationEventEnabled; }54 void setDeviceOrientationEventEnabled(bool enabled) { m_deviceOrientationEventEnabled = enabled; }55 52 56 53 OptionSet<WebKit::WebsiteAutoplayQuirk> allowedAutoplayQuirks() const { return m_allowedAutoplayQuirks; } … … 59 56 WebKit::WebsiteAutoplayPolicy autoplayPolicy() const { return m_autoplayPolicy; } 60 57 void setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy policy) { m_autoplayPolicy = policy; } 58 59 const Optional<bool>& deviceOrientationAndMotionAccessState() const { return m_deviceOrientationAndMotionAccessState; } 60 void setDeviceOrientationAndMotionAccessState(Optional<bool> state) { m_deviceOrientationAndMotionAccessState = state; } 61 61 62 62 const Vector<WebCore::HTTPHeaderField>& customHeaderFields() const { return m_customHeaderFields; } … … 85 85 86 86 bool m_contentBlockersEnabled { true }; 87 bool m_deviceOrientationEventEnabled { true };88 87 OptionSet<WebKit::WebsiteAutoplayQuirk> m_allowedAutoplayQuirks; 89 88 WebKit::WebsiteAutoplayPolicy m_autoplayPolicy { WebKit::WebsiteAutoplayPolicy::Default }; 89 Optional<bool> m_deviceOrientationAndMotionAccessState; 90 90 Vector<WebCore::HTTPHeaderField> m_customHeaderFields; 91 91 WebKit::WebsitePopUpPolicy m_popUpPolicy { WebKit::WebsitePopUpPolicy::Default }; -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h
r242339 r242960 46 46 } WK_API_AVAILABLE(macosx(10.14), ios(12.0)); 47 47 48 typedef NS_OPTIONS(NSUInteger, _WKWebsiteDeviceOrientationAndMotionAccessPolicy) { 49 _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk, 50 _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant, 51 _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny, 52 } WK_API_AVAILABLE(macosx(10.14), ios(12.0)); 53 48 54 @class WKWebsiteDataStore; 49 55 … … 60 66 @property (nonatomic, copy) NSString *customJavaScriptUserAgentAsSiteSpecificQuirks WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 61 67 @property (nonatomic, copy) NSString *customNavigatorPlatform WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 62 @property (nonatomic) BOOL deviceOrientationEventEnabledWK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));68 @property (nonatomic) _WKWebsiteDeviceOrientationAndMotionAccessPolicy deviceOrientationAndMotionAccessPolicy WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 63 69 64 70 @end -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm
r242339 r242960 58 58 } 59 59 60 - (void)setDeviceOrientationEventEnabled:(BOOL)deviceOrientationEventEnabled61 {62 _websitePolicies->setDeviceOrientationEventEnabled(deviceOrientationEventEnabled);63 }64 65 - (BOOL)deviceOrientationEventEnabled66 {67 return _websitePolicies->deviceOrientationEventEnabled();68 }69 70 60 - (void)setAllowedAutoplayQuirks:(_WKWebsiteAutoplayQuirk)allowedQuirks 71 61 { … … 139 129 } 140 130 131 - (void)setDeviceOrientationAndMotionAccessPolicy:(_WKWebsiteDeviceOrientationAndMotionAccessPolicy)policy 132 { 133 switch (policy) { 134 case _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk: 135 _websitePolicies->setDeviceOrientationAndMotionAccessState(WTF::nullopt); 136 break; 137 case _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant: 138 _websitePolicies->setDeviceOrientationAndMotionAccessState(true); 139 break; 140 case _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny: 141 _websitePolicies->setDeviceOrientationAndMotionAccessState(false); 142 break; 143 } 144 } 145 146 - (_WKWebsiteDeviceOrientationAndMotionAccessPolicy)deviceOrientationAndMotionAccessPolicy 147 { 148 if (!_websitePolicies->deviceOrientationAndMotionAccessState()) 149 return _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk; 150 return *_websitePolicies->deviceOrientationAndMotionAccessState() ? _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant : _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny; 151 } 152 141 153 - (void)setPopUpPolicy:(_WKWebsitePopUpPolicy)policy 142 154 { -
trunk/Tools/ChangeLog
r242952 r242960 1 2019-03-14 Chris Dumez <cdumez@apple.com> 2 3 Add WebsitePolicy for the client to specify the device orientation & motion access policy 4 https://bugs.webkit.org/show_bug.cgi?id=195750 5 6 Reviewed by Geoffrey Garen. 7 8 Add API test coverage. 9 10 * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm: 11 (-[WebsitePoliciesDeviceOrientationDelegate initWithDeviceOrientationAccessPolicy:]): 12 (-[WebsitePoliciesDeviceOrientationDelegate _webView:decidePolicyForNavigationAction:userInfo:decisionHandler:]): 13 (-[WebsitePoliciesDeviceOrientationUIDelegate _webView:shouldAllowDeviceOrientationAndMotionAccessRequestedByFrame:decisionHandler:]): 14 1 15 2019-03-14 Chris Dumez <cdumez@apple.com> 2 16 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm
r242823 r242960 1247 1247 1248 1248 @interface WebsitePoliciesDeviceOrientationDelegate : NSObject <WKNavigationDelegate> { 1249 BOOL _deviceOrientationEventEnabled;1250 } 1251 - (instancetype)initWithDeviceOrientation EventEnabled:(BOOL)enabled;1249 _WKWebsiteDeviceOrientationAndMotionAccessPolicy _accessPolicy; 1250 } 1251 - (instancetype)initWithDeviceOrientationAccessPolicy:(_WKWebsiteDeviceOrientationAndMotionAccessPolicy)accessPolicy; 1252 1252 @end 1253 1253 1254 1254 @implementation WebsitePoliciesDeviceOrientationDelegate 1255 1255 1256 - (instancetype)initWithDeviceOrientation EventEnabled:(BOOL)enabled1256 - (instancetype)initWithDeviceOrientationAccessPolicy:(_WKWebsiteDeviceOrientationAndMotionAccessPolicy)accessPolicy 1257 1257 { 1258 1258 self = [super init]; 1259 _ deviceOrientationEventEnabled = enabled;1259 _accessPolicy = accessPolicy; 1260 1260 return self; 1261 1261 } … … 1264 1264 { 1265 1265 _WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease]; 1266 [websitePolicies setDeviceOrientation EventEnabled:_deviceOrientationEventEnabled];1266 [websitePolicies setDeviceOrientationAndMotionAccessPolicy:_accessPolicy]; 1267 1267 1268 1268 decisionHandler(WKNavigationActionPolicyAllow, websitePolicies); … … 1276 1276 @end 1277 1277 1278 static bool calledShouldAllowDeviceOrientationAndMotionAccessDelegate = false; 1279 1278 1280 @interface WebsitePoliciesDeviceOrientationUIDelegate : NSObject <WKUIDelegatePrivate> { 1279 1281 } … … 1284 1286 - (void)_webView:(WKWebView *)webView shouldAllowDeviceOrientationAndMotionAccessRequestedByFrame:(WKFrameInfo *)requestingFrame decisionHandler:(void (^)(BOOL))decisionHandler 1285 1287 { 1288 calledShouldAllowDeviceOrientationAndMotionAccessDelegate = true; 1286 1289 decisionHandler(YES); 1287 1290 } … … 1289 1292 @end 1290 1293 1291 static void runWebsitePoliciesDeviceOrientationEventTest( bool websitePolicyValue)1294 static void runWebsitePoliciesDeviceOrientationEventTest(_WKWebsiteDeviceOrientationAndMotionAccessPolicy accessPolicy) 1292 1295 { 1293 1296 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); … … 1299 1302 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1300 1303 1301 auto delegate = adoptNS([[WebsitePoliciesDeviceOrientationDelegate alloc] initWithDeviceOrientation EventEnabled:websitePolicyValue]);1304 auto delegate = adoptNS([[WebsitePoliciesDeviceOrientationDelegate alloc] initWithDeviceOrientationAccessPolicy:accessPolicy]); 1302 1305 [webView setNavigationDelegate:delegate.get()]; 1303 1306 auto uiDelegate = adoptNS([[WebsitePoliciesDeviceOrientationUIDelegate alloc] init]); … … 1322 1325 [webView _simulateDeviceOrientationChangeWithAlpha:1.0 beta:2.0 gamma:3.0]; 1323 1326 1324 if (websitePolicyValue) 1327 if (accessPolicy == _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk) 1328 EXPECT_TRUE(calledShouldAllowDeviceOrientationAndMotionAccessDelegate); 1329 else 1330 EXPECT_FALSE(calledShouldAllowDeviceOrientationAndMotionAccessDelegate); 1331 1332 if (accessPolicy != _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny) 1325 1333 TestWebKitAPI::Util::run(&didReceiveMessage); 1326 1334 else { … … 1330 1338 } 1331 1339 1332 TEST(WebKit, WebsitePoliciesDeviceOrientationEventEnabled) 1333 { 1334 runWebsitePoliciesDeviceOrientationEventTest(true); 1335 } 1336 1337 TEST(WebKit, WebsitePoliciesDeviceOrientationEventDisabled) 1338 { 1339 runWebsitePoliciesDeviceOrientationEventTest(false); 1340 TEST(WebKit, WebsitePoliciesDeviceOrientationGrantAccess) 1341 { 1342 runWebsitePoliciesDeviceOrientationEventTest(_WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant); 1343 } 1344 1345 TEST(WebKit, WebsitePoliciesDeviceOrientationDenyAccess) 1346 { 1347 runWebsitePoliciesDeviceOrientationEventTest(_WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny); 1348 } 1349 1350 TEST(WebKit, WebsitePoliciesDeviceOrientationAskAccess) 1351 { 1352 runWebsitePoliciesDeviceOrientationEventTest(_WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk); 1340 1353 } 1341 1354
Note:
See TracChangeset
for help on using the changeset viewer.