Add a preference to enable / disable devicemotion and deviceorientation events
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Dec 2018 22:04:02 +0000 (22:04 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Dec 2018 22:04:02 +0000 (22:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192631
<rdar://problem/46646244>

Reviewed by Geoffrey Garen.

Add setting to toggle support for the deviceorientation / devicemotion events:
- https://w3c.github.io/deviceorientation/

Source/WebCore:

* page/DOMWindow.cpp:
(WebCore::DOMWindow::addEventListener):
* page/Settings.yaml:

Source/WebKit:

* Shared/WebPreferences.yaml:
* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences _setDeviceOrientationEventEnabled:]):
(-[WKPreferences _deviceOrientationEventEnabled]):
* UIProcess/API/Cocoa/WKPreferencesPrivate.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239130 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/Settings.yaml
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferences.yaml
Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm
Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h

index 6e1ab3d..b6b82e0 100644 (file)
@@ -1,3 +1,18 @@
+2018-12-12  Chris Dumez  <cdumez@apple.com>
+
+        Add a preference to enable / disable devicemotion and deviceorientation events
+        https://bugs.webkit.org/show_bug.cgi?id=192631
+        <rdar://problem/46646244>
+
+        Reviewed by Geoffrey Garen.
+
+        Add setting to toggle support for the deviceorientation / devicemotion events:
+        - https://w3c.github.io/deviceorientation/
+
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::addEventListener):
+        * page/Settings.yaml:
+
 2018-12-11  Ryosuke Niwa  <rniwa@webkit.org>
 
         Make HTMLConverter take two Positions in preparation to make it work with shadow DOM
index 42c6e7e..2772950 100644 (file)
@@ -1821,41 +1821,6 @@ bool DOMWindow::addEventListener(const AtomicString& eventType, Ref<EventListene
         addUnloadEventListener(this);
     else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this))
         addBeforeUnloadEventListener(this);
-#if ENABLE(DEVICE_ORIENTATION)
-#if PLATFORM(IOS_FAMILY)
-    else if ((eventType == eventNames().devicemotionEvent || eventType == eventNames().deviceorientationEvent) && document()) {
-        if (isSameSecurityOriginAsMainFrame() && isSecureContext()) {
-            if (eventType == eventNames().deviceorientationEvent)
-                document()->deviceOrientationController()->addDeviceEventListener(this);
-            else
-                document()->deviceMotionController()->addDeviceEventListener(this);
-        } else if (document()) {
-            if (isSecureContext())
-                document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion or orientation listener from child frame that wasn't the same security origin as the main page."_s);
-            else
-                document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure."_s);
-        }
-    }
-#else
-    else if (eventType == eventNames().devicemotionEvent) {
-        if (isSameSecurityOriginAsMainFrame() && isSecureContext()) {
-            if (DeviceMotionController* controller = DeviceMotionController::from(page()))
-                controller->addDeviceEventListener(this);
-        } else if (document())
-            document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion listener from child frame that wasn't the same security origin as the main page."_s);
-    } else if (eventType == eventNames().deviceorientationEvent) {
-        if (isSameSecurityOriginAsMainFrame() && isSecureContext()) {
-            if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
-                controller->addDeviceEventListener(this);
-        } else if (document()) {
-            if (isSecureContext())
-                document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device orientation listener from child frame that wasn't the same security origin as the main page."_s);
-            else
-                document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure."_s);
-        }
-    }
-#endif // PLATFORM(IOS_FAMILY)
-#endif // ENABLE(DEVICE_ORIENTATION)
 #if PLATFORM(IOS_FAMILY)
     else if (eventType == eventNames().scrollEvent)
         incrementScrollEventListenersCount();
@@ -1873,6 +1838,44 @@ bool DOMWindow::addEventListener(const AtomicString& eventType, Ref<EventListene
         incrementGamepadEventListenerCount();
 #endif
 
+#if ENABLE(DEVICE_ORIENTATION)
+    if (frame() && frame()->settings().deviceOrientationEventEnabled()) {
+#if PLATFORM(IOS_FAMILY)
+        if ((eventType == eventNames().devicemotionEvent || eventType == eventNames().deviceorientationEvent) && document()) {
+            if (isSameSecurityOriginAsMainFrame() && isSecureContext()) {
+                if (eventType == eventNames().deviceorientationEvent)
+                    document()->deviceOrientationController()->addDeviceEventListener(this);
+                else
+                    document()->deviceMotionController()->addDeviceEventListener(this);
+            } else if (document()) {
+                if (isSecureContext())
+                    document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion or orientation listener from child frame that wasn't the same security origin as the main page."_s);
+                else
+                    document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure."_s);
+            }
+        }
+#else
+        if (eventType == eventNames().devicemotionEvent) {
+            if (isSameSecurityOriginAsMainFrame() && isSecureContext()) {
+                if (DeviceMotionController* controller = DeviceMotionController::from(page()))
+                    controller->addDeviceEventListener(this);
+            } else if (document())
+                document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion listener from child frame that wasn't the same security origin as the main page."_s);
+        } else if (eventType == eventNames().deviceorientationEvent) {
+            if (isSameSecurityOriginAsMainFrame() && isSecureContext()) {
+                if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
+                    controller->addDeviceEventListener(this);
+            } else if (document()) {
+                if (isSecureContext())
+                    document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device orientation listener from child frame that wasn't the same security origin as the main page."_s);
+                else
+                    document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure."_s);
+            }
+        }
+#endif // PLATFORM(IOS_FAMILY)
+    }
+#endif // ENABLE(DEVICE_ORIENTATION)
+
     return true;
 }
 
index 6daec2a..a797193 100644 (file)
@@ -745,6 +745,11 @@ touchEventEmulationEnabled:
   getter: isTouchEventEmulationEnabled
   conditional: TOUCH_EVENTS
 
+deviceOrientationEventEnabled:
+  type: bool
+  initial: true
+  conditional: DEVICE_ORIENTATION
+
 shouldEnableTextAutosizingBoost:
   type: bool
   initial: false
index e285bf7..573ae31 100644 (file)
@@ -1,3 +1,20 @@
+2018-12-12  Chris Dumez  <cdumez@apple.com>
+
+        Add a preference to enable / disable devicemotion and deviceorientation events
+        https://bugs.webkit.org/show_bug.cgi?id=192631
+        <rdar://problem/46646244>
+
+        Reviewed by Geoffrey Garen.
+
+        Add setting to toggle support for the deviceorientation / devicemotion events:
+        - https://w3c.github.io/deviceorientation/
+
+        * Shared/WebPreferences.yaml:
+        * UIProcess/API/Cocoa/WKPreferences.mm:
+        (-[WKPreferences _setDeviceOrientationEventEnabled:]):
+        (-[WKPreferences _deviceOrientationEventEnabled]):
+        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
+
 2018-12-12  Ross Kirsling  <ross.kirsling@sony.com>
 
         Unreviewed build fix for WinCairo Debug after r239080(?).
index 39d41a7..077bde3 100644 (file)
@@ -6,6 +6,12 @@ BlankAnchorTargetImpliesNoOpenerEnabled:
    humanReadableDescription: "target=_blank on anchor elements implies rel=noopener"
    category: experimental
 
+DeviceOrientationEventEnabled:
+  type: bool
+  defaultValue: true
+  condition: ENABLE(DEVICE_ORIENTATION)
+  webcoreName: deviceOrientationEventEnabled
+
 JavaScriptEnabled:
   type: bool
   defaultValue: true
index eda9c81..3ac5b5c 100644 (file)
@@ -1346,6 +1346,22 @@ static WebCore::EditableLinkBehavior toEditableLinkBehavior(_WKEditableLinkBehav
     return _preferences->webAnimationsCSSIntegrationEnabled();
 }
 
+- (void)_setDeviceOrientationEventEnabled:(BOOL)enabled
+{
+#if ENABLE(DEVICE_ORIENTATION)
+    _preferences->setDeviceOrientationEventEnabled(enabled);
+#endif
+}
+
+- (BOOL)_deviceOrientationEventEnabled
+{
+#if ENABLE(DEVICE_ORIENTATION)
+    return _preferences->deviceOrientationEventEnabled();
+#else
+    return false;
+#endif
+}
+
 @end
 
 #endif // WK_API_ENABLED
index 28698bf..af64c61 100644 (file)
@@ -150,6 +150,7 @@ typedef NS_ENUM(NSInteger, _WKEditableLinkBehavior) {
 @property (nonatomic, setter=_setShouldIgnoreMetaViewport:) BOOL _shouldIgnoreMetaViewport WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic, setter=_setVideoQualityIncludesDisplayCompositingEnabled:) BOOL _videoQualityIncludesDisplayCompositingEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic, setter=_setWebAnimationsCSSIntegrationEnabled:) BOOL _webAnimationsCSSIntegrationEnabled WK_API_AVAILABLE(macosx(10.14), ios(WK_IOS_TBA));
+@property (nonatomic, setter=_setDeviceOrientationEventEnabled:) BOOL _deviceOrientationEventEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 #if !TARGET_OS_IPHONE
 @property (nonatomic, setter=_setWebGLEnabled:) BOOL _webGLEnabled WK_API_AVAILABLE(macosx(10.13.4));