⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 242664 in webkit


Ignore:
Timestamp:
Mar 8, 2019, 4:30:45 PM (7 years ago)
Author:
Chris Dumez
Message:

Add support for Device Orientation / Motion permission API
https://bugs.webkit.org/show_bug.cgi?id=195329
<rdar://problem/47645367>

Reviewed by Geoffrey Garen.

Source/WebCore:

Add support for Device Orientation / Motion permission API:

Pages can add event listeners for 'deviceorientation' / 'devicemotion' events but
such events will not be fired until the page's JavaScript calls
DeviceOrientationEvent.requestPermission() / DeviceMotionEvent.requestPermission()
and the user grants the request.

The feature is currently behind an experimental feature flag, off by default.

Tests: fast/device-orientation/device-motion-request-permission-denied.html

fast/device-orientation/device-motion-request-permission-granted.html
fast/device-orientation/device-motion-request-permission-user-gesture.html
fast/device-orientation/device-orientation-request-permission-denied.html
fast/device-orientation/device-orientation-request-permission-granted.html
fast/device-orientation/device-orientation-request-permission-user-gesture.html

  • CMakeLists.txt:
  • DerivedSources-input.xcfilelist:
  • DerivedSources-output.xcfilelist:
  • DerivedSources.make:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • dom/DeviceMotionEvent.h:
  • dom/DeviceMotionEvent.idl:
  • dom/DeviceOrientationAndMotionAccessController.cpp: Added.

(WebCore::DeviceOrientationAndMotionAccessController::DeviceOrientationAndMotionAccessController):
(WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess):
(WebCore::DeviceOrientationAndMotionAccessController::setAccessState):

  • dom/DeviceOrientationAndMotionAccessController.h: Added.

(WebCore::DeviceOrientationAndMotionAccessController::accessState const):

  • dom/DeviceOrientationEvent.h:
  • dom/DeviceOrientationEvent.idl:
  • dom/DeviceOrientationOrMotionEvent.cpp: Added.

(WebCore::DeviceOrientationOrMotionEvent::requestPermission):

  • dom/DeviceOrientationOrMotionEvent.h: Added.
  • dom/DeviceOrientationOrMotionEvent.idl: Added.
  • dom/DeviceOrientationOrMotionPermissionState.h: Added.
  • dom/DeviceOrientationOrMotionPermissionState.idl: Added.
  • dom/Document.cpp:

(WebCore::Document::deviceOrientationAndMotionAccessController):

  • dom/Document.h:
  • dom/Event.cpp:
  • dom/MessagePort.cpp:
  • dom/Microtasks.cpp:
  • page/ChromeClient.h:
  • page/DOMWindow.cpp:

(WebCore::DOMWindow::addEventListener):
(WebCore::DOMWindow::deviceOrientationController const):
(WebCore::DOMWindow::deviceMotionController const):
(WebCore::DOMWindow::isAllowedToUseDeviceMotionOrientation const):
(WebCore::DOMWindow::isAllowedToAddDeviceMotionOrientationListener const):
(WebCore::DOMWindow::startListeningForDeviceOrientationIfNecessary):
(WebCore::DOMWindow::stopListeningForDeviceOrientationIfNecessary):
(WebCore::DOMWindow::startListeningForDeviceMotionIfNecessary):
(WebCore::DOMWindow::stopListeningForDeviceMotionIfNecessary):
(WebCore::DOMWindow::removeEventListener):
(WebCore::DOMWindow::removeAllEventListeners):

  • page/DOMWindow.h:
  • page/DeviceController.cpp:

(WebCore::DeviceController::hasDeviceEventListener const):

  • page/DeviceController.h:
  • page/Settings.yaml:

Source/WebKit:

Add support for Device Orientation / Motion permission API:

This adds new SPI to WKUIDelegatePrivate, until we can make this API.

  • Shared/WebPreferences.yaml:
  • UIProcess/API/APIUIClient.h:

(API::UIClient::shouldAllowDeviceOrientationAndMotionAccess):

  • UIProcess/API/C/WKPage.cpp:

(WKPageSetPageUIClient):

  • UIProcess/API/C/WKPageUIClient.h:
  • UIProcess/API/Cocoa/WKUIDelegate.h:
  • UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
  • UIProcess/Cocoa/UIDelegate.h:
  • UIProcess/Cocoa/UIDelegate.mm:

(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::shouldAllowDeviceOrientationAndMotionAccess):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::requestDeviceOrientationAndMotionAccess):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess):

  • WebProcess/WebCoreSupport/WebChromeClient.h:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::nextDeviceOrientationAndMotionPermissionCallbackID):
(WebKit::WebPage::shouldAllowDeviceOrientationAndMotionAccess):
(WebKit::WebPage::didReceiveDeviceOrientationAndMotionAccessDecision):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:

Tools:

Add test infrastructure to help test the Device Orientation / Motion permission API.

  • WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
  • WebKitTestRunner/InjectedBundle/TestRunner.cpp:

(WTR::TestRunner::setShouldAllowDeviceOrientationAndMotionAccess):

  • WebKitTestRunner/InjectedBundle/TestRunner.h:
  • WebKitTestRunner/TestController.cpp:

(WTR::shouldAllowDeviceOrientationAndMotionAccess):
(WTR::TestController::createWebViewWithOptions):
(WTR::TestController::resetStateToConsistentValues):
(WTR::TestController::handleDeviceOrientationAndMotionAccessRequest):

  • WebKitTestRunner/TestController.h:

(WTR::TestController::setShouldAllowDeviceOrientationAndMotionAccess):

  • WebKitTestRunner/TestInvocation.cpp:

(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):

LayoutTests:

Add layout test coverage.

  • TestExpectations:
  • fast/device-orientation/device-motion-request-permission-denied-expected.txt: Added.
  • fast/device-orientation/device-motion-request-permission-denied.html: Added.
  • fast/device-orientation/device-motion-request-permission-granted-expected.txt: Added.
  • fast/device-orientation/device-motion-request-permission-granted.html: Added.
  • fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt: Added.
  • fast/device-orientation/device-motion-request-permission-user-gesture.html: Added.
  • fast/device-orientation/device-orientation-request-permission-denied-expected.txt: Added.
  • fast/device-orientation/device-orientation-request-permission-denied.html: Added.
  • fast/device-orientation/device-orientation-request-permission-granted-expected.txt: Added.
  • fast/device-orientation/device-orientation-request-permission-granted.html: Added.
  • fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt: Added.
  • fast/device-orientation/device-orientation-request-permission-user-gesture.html: Added.
  • http/tests/events/device-orientation-motion-non-secure-context.html:
  • http/tests/events/device-orientation-motion-secure-context-expected.txt:
  • http/tests/events/device-orientation-motion-secure-context.html:
  • platform/ios-wk2/TestExpectations:
  • platform/ios/http/tests/events/device-orientation-motion-non-secure-context-expected.txt:
  • platform/ios/http/tests/events/device-orientation-motion-secure-context-expected.txt:
Location:
trunk
Files:
20 added
57 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r242661 r242664  
     12019-03-08  Chris Dumez  <cdumez@apple.com>
     2
     3        Add support for Device Orientation / Motion permission API
     4        https://bugs.webkit.org/show_bug.cgi?id=195329
     5        <rdar://problem/47645367>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Add layout test coverage.
     10
     11        * TestExpectations:
     12        * fast/device-orientation/device-motion-request-permission-denied-expected.txt: Added.
     13        * fast/device-orientation/device-motion-request-permission-denied.html: Added.
     14        * fast/device-orientation/device-motion-request-permission-granted-expected.txt: Added.
     15        * fast/device-orientation/device-motion-request-permission-granted.html: Added.
     16        * fast/device-orientation/device-motion-request-permission-user-gesture-expected.txt: Added.
     17        * fast/device-orientation/device-motion-request-permission-user-gesture.html: Added.
     18        * fast/device-orientation/device-orientation-request-permission-denied-expected.txt: Added.
     19        * fast/device-orientation/device-orientation-request-permission-denied.html: Added.
     20        * fast/device-orientation/device-orientation-request-permission-granted-expected.txt: Added.
     21        * fast/device-orientation/device-orientation-request-permission-granted.html: Added.
     22        * fast/device-orientation/device-orientation-request-permission-user-gesture-expected.txt: Added.
     23        * fast/device-orientation/device-orientation-request-permission-user-gesture.html: Added.
     24        * http/tests/events/device-orientation-motion-non-secure-context.html:
     25        * http/tests/events/device-orientation-motion-secure-context-expected.txt:
     26        * http/tests/events/device-orientation-motion-secure-context.html:
     27        * platform/ios-wk2/TestExpectations:
     28        * platform/ios/http/tests/events/device-orientation-motion-non-secure-context-expected.txt:
     29        * platform/ios/http/tests/events/device-orientation-motion-secure-context-expected.txt:
     30
    1312019-03-08  Zalan Bujtas  <zalan@apple.com>
    232
  • trunk/LayoutTests/TestExpectations

    r242624 r242664  
    3434fast/viewport/ios [ Skip ]
    3535fast/visual-viewport/ios/ [ Skip ]
     36fast/device-orientation [ Skip ]
    3637fast/events/ios [ Skip ]
    3738fast/events/watchos [ Skip ]
  • trunk/LayoutTests/http/tests/events/device-orientation-motion-non-secure-context.html

    r239089 r242664  
    2828    addEventListener("devicemotion", function() { });
    2929    internals.postTask(() => {
    30         shouldBeEqualToString("lastConsoleMessage", "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure.");
     30        shouldBeEqualToString("lastConsoleMessage", "Blocked attempt to add a device motion or orientation event listener, reason: Browsing context is not secure.");
    3131        finishJSTest();
    3232    });
     
    4545    addEventListener("deviceorientation", function() { });
    4646    internals.postTask(() => {
    47         shouldBeEqualToString("lastConsoleMessage", "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure.");
     47        shouldBeEqualToString("lastConsoleMessage", "Blocked attempt to add a device motion or orientation event listener, reason: Browsing context is not secure.");
    4848        runDeviceMotionTest();
    4949    });
  • trunk/LayoutTests/http/tests/events/device-orientation-motion-secure-context-expected.txt

    r239087 r242664  
    1 CONSOLE MESSAGE: line 37: Device Orientation API is not supported
    2 CONSOLE MESSAGE: line 19: Device Motion API is not supported
     1CONSOLE MESSAGE: line 50: Device Orientation API is not supported
     2CONSOLE MESSAGE: line 25: Device Motion API is not supported
    33Tests that trying to set an event listener for deviceorientation and deviceorientation does not log an error in secure contexts.
    44
    55On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
     6
    67
    78
  • trunk/LayoutTests/http/tests/events/device-orientation-motion-secure-context.html

    r239087 r242664  
    66description("Tests that trying to set an event listener for deviceorientation and deviceorientation does not log an error in secure contexts.");
    77jsTestIsAsync = true;
     8
     9if (window.testRunner) {
     10    if (testRunner.setShouldAllowDeviceOrientationAndMotionAccess)
     11        testRunner.setShouldAllowDeviceOrientationAndMotionAccess(true);
     12}
    813
    914// localhost is secure by default.
     
    1621function runDeviceMotionTest()
    1722{
     23    debug("");
    1824    if (!window.DeviceMotionEvent) {
    1925        console.log("Device Motion API is not supported");
     
    2228    }
    2329
    24     lastConsoleMessage = null;
    25     debug("");
    26     debug("* Registering device motion listener");
    27     addEventListener("devicemotion", function() { });
    28     internals.postTask(() => {
    29         shouldBeNull("lastConsoleMessage");
    30         finishJSTest();
     30    debug("* Requesting device motion access...");
     31    internals.withUserGesture(() => {
     32        DeviceMotionEvent.requestPermission().then((_result) => {
     33            result = _result;
     34            shouldBeEqualToString("result", "granted");
     35
     36            lastConsoleMessage = null;
     37            debug("* Registering device motion listener");
     38            addEventListener("devicemotion", function() { });
     39            internals.postTask(() => {
     40                shouldBeNull("lastConsoleMessage");
     41                finishJSTest();
     42            });
     43        });
    3144    });
    3245}
     
    4053    }
    4154
    42     lastConsoleMessage = null;
    43     debug("* Registering device orientation listener");
    44     addEventListener("deviceorientation", function() { });
    45     internals.postTask(() => {
    46         shouldBeNull("lastConsoleMessage");
    47         runDeviceMotionTest();
     55    debug("* Requesting device orientation access...");
     56    internals.withUserGesture(() => {
     57        DeviceOrientationEvent.requestPermission().then((_result) => {
     58            result = _result;
     59            shouldBeEqualToString("result", "granted");
     60
     61            lastConsoleMessage = null;
     62            debug("* Registering device orientation listener");
     63            addEventListener("deviceorientation", function() { });
     64            internals.postTask(() => {
     65                shouldBeNull("lastConsoleMessage");
     66                runDeviceMotionTest();
     67            });
     68        });
    4869    });
    4970}
  • trunk/LayoutTests/platform/ios-wk2/TestExpectations

    r242333 r242664  
    88
    99compositing/ios [ Pass ]
     10fast/device-orientation [ Pass ]
    1011fast/history/ios [ Pass ]
    1112fast/scrolling/ios [ Pass ]
  • trunk/LayoutTests/platform/ios/http/tests/events/device-orientation-motion-non-secure-context-expected.txt

    r239089 r242664  
    1 CONSOLE MESSAGE: line 45: Blocked attempt to add a device motion or orientation listener because the browsing context is not secure.
    2 CONSOLE MESSAGE: line 28: Blocked attempt to add a device motion or orientation listener because the browsing context is not secure.
     1CONSOLE MESSAGE: line 45: Blocked attempt to add a device motion or orientation event listener, reason: Browsing context is not secure.
     2CONSOLE MESSAGE: line 28: Blocked attempt to add a device motion or orientation event listener, reason: Browsing context is not secure.
    33Tests that trying to set an event listener for deviceorientation and deviceorientation logs an error in non-secure contexts.
    44
     
    77
    88* Registering device orientation listener
    9 PASS lastConsoleMessage is "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure."
     9PASS lastConsoleMessage is "Blocked attempt to add a device motion or orientation event listener, reason: Browsing context is not secure."
    1010
    1111* Registering device motion listener
    12 PASS lastConsoleMessage is "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure."
     12PASS lastConsoleMessage is "Blocked attempt to add a device motion or orientation event listener, reason: Browsing context is not secure."
    1313PASS successfullyParsed is true
    1414
  • trunk/LayoutTests/platform/ios/http/tests/events/device-orientation-motion-secure-context-expected.txt

    r239087 r242664  
     1Received device orientation & motion access request for security origin "http://127.0.0.1:8000".
    12Tests that trying to set an event listener for deviceorientation and deviceorientation does not log an error in secure contexts.
    23
     
    45
    56
     7* Requesting device orientation access...
     8PASS result is "granted"
    69* Registering device orientation listener
    710PASS lastConsoleMessage is null
    811
     12* Requesting device motion access...
     13PASS result is "granted"
    914* Registering device motion listener
    1015PASS lastConsoleMessage is null
  • trunk/Source/WebCore/CMakeLists.txt

    r242615 r242664  
    672672    dom/DeviceMotionEvent.idl
    673673    dom/DeviceOrientationEvent.idl
     674    dom/DeviceOrientationOrMotionEvent.idl
     675    dom/DeviceOrientationOrMotionPermissionState.idl
    674676    dom/Document.idl
    675677    dom/DocumentAndElementEventHandlers.idl
  • trunk/Source/WebCore/ChangeLog

    r242661 r242664  
     12019-03-08  Chris Dumez  <cdumez@apple.com>
     2
     3        Add support for Device Orientation / Motion permission API
     4        https://bugs.webkit.org/show_bug.cgi?id=195329
     5        <rdar://problem/47645367>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Add support for Device Orientation / Motion permission API:
     10        - https://github.com/w3c/deviceorientation/issues/57
     11
     12        Pages can add event listeners for 'deviceorientation' / 'devicemotion' events but
     13        such events will not be fired until the page's JavaScript calls
     14        DeviceOrientationEvent.requestPermission() / DeviceMotionEvent.requestPermission()
     15        and the user grants the request.
     16
     17        The feature is currently behind an experimental feature flag, off by default.
     18
     19        Tests: fast/device-orientation/device-motion-request-permission-denied.html
     20               fast/device-orientation/device-motion-request-permission-granted.html
     21               fast/device-orientation/device-motion-request-permission-user-gesture.html
     22               fast/device-orientation/device-orientation-request-permission-denied.html
     23               fast/device-orientation/device-orientation-request-permission-granted.html
     24               fast/device-orientation/device-orientation-request-permission-user-gesture.html
     25
     26        * CMakeLists.txt:
     27        * DerivedSources-input.xcfilelist:
     28        * DerivedSources-output.xcfilelist:
     29        * DerivedSources.make:
     30        * Sources.txt:
     31        * WebCore.xcodeproj/project.pbxproj:
     32        * dom/DeviceMotionEvent.h:
     33        * dom/DeviceMotionEvent.idl:
     34        * dom/DeviceOrientationAndMotionAccessController.cpp: Added.
     35        (WebCore::DeviceOrientationAndMotionAccessController::DeviceOrientationAndMotionAccessController):
     36        (WebCore::DeviceOrientationAndMotionAccessController::shouldAllowAccess):
     37        (WebCore::DeviceOrientationAndMotionAccessController::setAccessState):
     38        * dom/DeviceOrientationAndMotionAccessController.h: Added.
     39        (WebCore::DeviceOrientationAndMotionAccessController::accessState const):
     40        * dom/DeviceOrientationEvent.h:
     41        * dom/DeviceOrientationEvent.idl:
     42        * dom/DeviceOrientationOrMotionEvent.cpp: Added.
     43        (WebCore::DeviceOrientationOrMotionEvent::requestPermission):
     44        * dom/DeviceOrientationOrMotionEvent.h: Added.
     45        * dom/DeviceOrientationOrMotionEvent.idl: Added.
     46        * dom/DeviceOrientationOrMotionPermissionState.h: Added.
     47        * dom/DeviceOrientationOrMotionPermissionState.idl: Added.
     48        * dom/Document.cpp:
     49        (WebCore::Document::deviceOrientationAndMotionAccessController):
     50        * dom/Document.h:
     51        * dom/Event.cpp:
     52        * dom/MessagePort.cpp:
     53        * dom/Microtasks.cpp:
     54        * page/ChromeClient.h:
     55        * page/DOMWindow.cpp:
     56        (WebCore::DOMWindow::addEventListener):
     57        (WebCore::DOMWindow::deviceOrientationController const):
     58        (WebCore::DOMWindow::deviceMotionController const):
     59        (WebCore::DOMWindow::isAllowedToUseDeviceMotionOrientation const):
     60        (WebCore::DOMWindow::isAllowedToAddDeviceMotionOrientationListener const):
     61        (WebCore::DOMWindow::startListeningForDeviceOrientationIfNecessary):
     62        (WebCore::DOMWindow::stopListeningForDeviceOrientationIfNecessary):
     63        (WebCore::DOMWindow::startListeningForDeviceMotionIfNecessary):
     64        (WebCore::DOMWindow::stopListeningForDeviceMotionIfNecessary):
     65        (WebCore::DOMWindow::removeEventListener):
     66        (WebCore::DOMWindow::removeAllEventListeners):
     67        * page/DOMWindow.h:
     68        * page/DeviceController.cpp:
     69        (WebCore::DeviceController::hasDeviceEventListener const):
     70        * page/DeviceController.h:
     71        * page/Settings.yaml:
     72
    1732019-03-08  Zalan Bujtas  <zalan@apple.com>
    274
  • trunk/Source/WebCore/DerivedSources-input.xcfilelist

    r242615 r242664  
    565565$(PROJECT_DIR)/dom/DeviceMotionEvent.idl
    566566$(PROJECT_DIR)/dom/DeviceOrientationEvent.idl
     567$(PROJECT_DIR)/dom/DeviceOrientationOrMotionEvent.idl
     568$(PROJECT_DIR)/dom/DeviceOrientationOrMotionPermissionState.idl
    567569$(PROJECT_DIR)/dom/Document.idl
    568570$(PROJECT_DIR)/dom/DocumentAndElementEventHandlers.idl
  • trunk/Source/WebCore/DerivedSources-output.xcfilelist

    r242615 r242664  
    460460$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSDeviceOrientationEvent.cpp
    461461$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSDeviceOrientationEvent.h
     462$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSDeviceOrientationOrMotionEvent.cpp
     463$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSDeviceOrientationOrMotionEvent.h
     464$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSDeviceOrientationOrMotionPermissionState.cpp
     465$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSDeviceOrientationOrMotionPermissionState.h
    462466$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSDocument.cpp
    463467$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSDocument.h
  • trunk/Source/WebCore/DerivedSources.make

    r242615 r242664  
    572572    $(WebCore)/dom/DeviceMotionEvent.idl \
    573573    $(WebCore)/dom/DeviceOrientationEvent.idl \
     574    $(WebCore)/dom/DeviceOrientationOrMotionEvent.idl \
     575    $(WebCore)/dom/DeviceOrientationOrMotionPermissionState.idl \
    574576    $(WebCore)/dom/Document.idl \
    575577    $(WebCore)/dom/DocumentAndElementEventHandlers.idl \
  • trunk/Source/WebCore/Sources.txt

    r242624 r242664  
    821821dom/DeviceMotionData.cpp
    822822dom/DeviceMotionEvent.cpp
     823dom/DeviceOrientationAndMotionAccessController.cpp
    823824dom/DeviceOrientationController.cpp
    824825dom/DeviceOrientationData.cpp
    825826dom/DeviceOrientationEvent.cpp
     827dom/DeviceOrientationOrMotionEvent.cpp
    826828dom/Document.cpp
    827829dom/DocumentEventQueue.cpp
     
    27242726JSDeviceMotionEvent.cpp
    27252727JSDeviceOrientationEvent.cpp
     2728JSDeviceOrientationOrMotionPermissionState.cpp
     2729JSDeviceOrientationOrMotionEvent.cpp
    27262730JSDocument.cpp
    27272731JSDocumentAndElementEventHandlers.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r242624 r242664  
    12551255                460BB6161D0A1BF000221812 /* Base64Utilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 460BB6141D0A1BEC00221812 /* Base64Utilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12561256                460CBF361D4BCD0E0092E88E /* JSDOMWindowProperties.h in Headers */ = {isa = PBXBuildFile; fileRef = 460CBF341D4BCCFE0092E88E /* JSDOMWindowProperties.h */; };
     1257                460E3075222F4EFD009A0606 /* DeviceOrientationOrMotionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 461DA52A222F486F00D05A87 /* DeviceOrientationOrMotionEvent.h */; };
     1258                460E3077222F4F03009A0606 /* DeviceOrientationOrMotionPermissionState.h in Headers */ = {isa = PBXBuildFile; fileRef = 465EDD9F222F4EC300B46E16 /* DeviceOrientationOrMotionPermissionState.h */; };
    12571259                46218ACB1F72D64E00574FBE /* DOMHighResTimeStamp.h in Headers */ = {isa = PBXBuildFile; fileRef = 46E016AD1F72D61E00282B2C /* DOMHighResTimeStamp.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12581260                463521AD2081092A00C28922 /* WindowProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 463521AA2081090B00C28922 /* WindowProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    12721274                46B95199207D634D00A7D2DD /* RemoteDOMWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B9518E207D632A00A7D2DD /* RemoteDOMWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12731275                46B9519A207D635400A7D2DD /* RemoteFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B95192207D632E00A7D2DD /* RemoteFrame.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1276                46B95BF52231CFD60053A504 /* DeviceOrientationAndMotionAccessController.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B95BF42231CFB80053A504 /* DeviceOrientationAndMotionAccessController.h */; };
    12741277                46BCBBC22085008F00710638 /* JSRemoteDOMWindowBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 46BCBBC02085007F00710638 /* JSRemoteDOMWindowBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12751278                46C376622085177D00C73829 /* JSRemoteDOMWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C376612085176D00C73829 /* JSRemoteDOMWindow.h */; };
     
    77267729                460CBF341D4BCCFE0092E88E /* JSDOMWindowProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMWindowProperties.h; sourceTree = "<group>"; };
    77277730                460D19441FCE21DD00C3DB85 /* JSServiceWorkerGlobalScopeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSServiceWorkerGlobalScopeCustom.cpp; sourceTree = "<group>"; };
     7731                461DA52A222F486F00D05A87 /* DeviceOrientationOrMotionEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceOrientationOrMotionEvent.h; sourceTree = "<group>"; };
     7732                461DA52C222F486F00D05A87 /* DeviceOrientationOrMotionEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceOrientationOrMotionEvent.cpp; sourceTree = "<group>"; };
    77287733                4634592B1AC2271000ECB71C /* PowerObserverMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PowerObserverMac.cpp; sourceTree = "<group>"; };
    77297734                463521AA2081090B00C28922 /* WindowProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowProxy.h; sourceTree = "<group>"; };
     
    77337738                4642404520EAF0ED00B29FD2 /* DatabaseManagerCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseManagerCocoa.mm; sourceTree = "<group>"; };
    77347739                465A8E781C8A24CE00E7D3E4 /* RuntimeApplicationChecksCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RuntimeApplicationChecksCocoa.mm; sourceTree = "<group>"; };
     7740                465EDD9D222F4EC300B46E16 /* DeviceOrientationOrMotionEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DeviceOrientationOrMotionEvent.idl; sourceTree = "<group>"; };
     7741                465EDD9F222F4EC300B46E16 /* DeviceOrientationOrMotionPermissionState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceOrientationOrMotionPermissionState.h; sourceTree = "<group>"; };
     7742                465EDDA0222F4EC400B46E16 /* DeviceOrientationOrMotionPermissionState.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DeviceOrientationOrMotionPermissionState.idl; sourceTree = "<group>"; };
    77357743                466DC6AB1EDE021D00746224 /* JSDOMRectList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMRectList.cpp; sourceTree = "<group>"; };
    77367744                466ED8D21EDE0135005E43F6 /* JSDOMRectList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMRectList.h; sourceTree = "<group>"; };
     
    77557763                46B95193207D632F00A7D2DD /* AbstractDOMWindow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AbstractDOMWindow.cpp; sourceTree = "<group>"; };
    77567764                46B95194207D633000A7D2DD /* AbstractFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AbstractFrame.cpp; sourceTree = "<group>"; };
     7765                46B95BF22231CFB80053A504 /* DeviceOrientationAndMotionAccessController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceOrientationAndMotionAccessController.cpp; sourceTree = "<group>"; };
     7766                46B95BF42231CFB80053A504 /* DeviceOrientationAndMotionAccessController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceOrientationAndMotionAccessController.h; sourceTree = "<group>"; };
    77577767                46BCBBBE2085005B00710638 /* JSRemoteDOMWindowCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSRemoteDOMWindowCustom.cpp; sourceTree = "<group>"; };
    77587768                46BCBBC02085007F00710638 /* JSRemoteDOMWindowBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRemoteDOMWindowBase.h; sourceTree = "<group>"; };
     
    2749927509                                31FB1A55120A5D0600DC02A0 /* DeviceMotionEvent.h */,
    2750027510                                31FB1A56120A5D0600DC02A0 /* DeviceMotionEvent.idl */,
     27511                                46B95BF22231CFB80053A504 /* DeviceOrientationAndMotionAccessController.cpp */,
     27512                                46B95BF42231CFB80053A504 /* DeviceOrientationAndMotionAccessController.h */,
    2750127513                                59A8F1D711A69520001AC34A /* DeviceOrientationClient.h */,
    2750227514                                59A8F1D311A69508001AC34A /* DeviceOrientationController.cpp */,
     
    2750727519                                59A85EA3119D68EC00DEF1EF /* DeviceOrientationEvent.h */,
    2750827520                                59A85EAA119D7B6E00DEF1EF /* DeviceOrientationEvent.idl */,
     27521                                461DA52C222F486F00D05A87 /* DeviceOrientationOrMotionEvent.cpp */,
     27522                                461DA52A222F486F00D05A87 /* DeviceOrientationOrMotionEvent.h */,
     27523                                465EDD9D222F4EC300B46E16 /* DeviceOrientationOrMotionEvent.idl */,
     27524                                465EDD9F222F4EC300B46E16 /* DeviceOrientationOrMotionPermissionState.h */,
     27525                                465EDDA0222F4EC400B46E16 /* DeviceOrientationOrMotionPermissionState.idl */,
    2750927526                                A8185F3409765765005826D9 /* Document.cpp */,
    2751027527                                A8185F3809765765005826D9 /* Document.h */,
     
    2903129048                                31FB1A5B120A5D0600DC02A0 /* DeviceMotionData.h in Headers */,
    2903229049                                31FB1A5D120A5D0600DC02A0 /* DeviceMotionEvent.h in Headers */,
     29050                                46B95BF52231CFD60053A504 /* DeviceOrientationAndMotionAccessController.h in Headers */,
    2903329051                                59A8F1D811A69520001AC34A /* DeviceOrientationClient.h in Headers */,
    2903429052                                3140379D124BEA7F00AF40E4 /* DeviceOrientationClientIOS.h in Headers */,
     
    2903729055                                590E1B4911E4EF4B0069F784 /* DeviceOrientationData.h in Headers */,
    2903829056                                59A85EA4119D68EC00DEF1EF /* DeviceOrientationEvent.h in Headers */,
     29057                                460E3075222F4EFD009A0606 /* DeviceOrientationOrMotionEvent.h in Headers */,
     29058                                460E3077222F4F03009A0606 /* DeviceOrientationOrMotionPermissionState.h in Headers */,
    2903929059                                572B401F21757A64000AD43E /* DeviceRequestConverter.h in Headers */,
    2904029060                                572B403A21772581000AD43E /* DeviceResponseConverter.h in Headers */,
  • trunk/Source/WebCore/dom/DeviceMotionEvent.h

    r239427 r242664  
    2626#pragma once
    2727
     28#include "DeviceOrientationOrMotionEvent.h"
    2829#include "Event.h"
    2930
     
    3233class DeviceMotionData;
    3334
    34 class DeviceMotionEvent final : public Event {
     35class DeviceMotionEvent final : public Event, public DeviceOrientationOrMotionEvent {
    3536public:
    3637    virtual ~DeviceMotionEvent();
  • trunk/Source/WebCore/dom/DeviceMotionEvent.idl

    r210741 r242664  
    5858    double? gamma;
    5959};
     60
     61DeviceMotionEvent implements DeviceOrientationOrMotionEvent;
  • trunk/Source/WebCore/dom/DeviceOrientationEvent.h

    r239427 r242664  
    2626#pragma once
    2727
     28#include "DeviceOrientationOrMotionEvent.h"
    2829#include "Event.h"
    2930
     
    3233class DeviceOrientationData;
    3334
    34 class DeviceOrientationEvent final : public Event {
     35class DeviceOrientationEvent final : public Event, public DeviceOrientationOrMotionEvent {
    3536public:
    3637    static Ref<DeviceOrientationEvent> create(const AtomicString& eventType, DeviceOrientationData* orientation)
  • trunk/Source/WebCore/dom/DeviceOrientationEvent.idl

    r237266 r242664  
    5656};
    5757
     58DeviceOrientationEvent implements DeviceOrientationOrMotionEvent;
  • trunk/Source/WebCore/dom/Document.cpp

    r242624 r242664  
    245245#if ENABLE(DEVICE_ORIENTATION)
    246246#include "DeviceMotionEvent.h"
     247#include "DeviceOrientationAndMotionAccessController.h"
    247248#include "DeviceOrientationEvent.h"
    248249#endif
     
    86128613}
    86138614
     8615#if ENABLE(DEVICE_ORIENTATION)
     8616
     8617DeviceOrientationAndMotionAccessController& Document::deviceOrientationAndMotionAccessController()
     8618{
     8619    if (&topDocument() != this)
     8620        return topDocument().deviceOrientationAndMotionAccessController();
     8621
     8622    if (!m_deviceOrientationAndMotionAccessController)
     8623        m_deviceOrientationAndMotionAccessController = std::make_unique<DeviceOrientationAndMotionAccessController>(*this);
     8624    return *m_deviceOrientationAndMotionAccessController;
     8625}
     8626
     8627#endif
     8628
    86148629#if ENABLE(CSS_PAINTING_API)
    86158630Worklet& Document::ensurePaintWorklet()
  • trunk/Source/WebCore/dom/Document.h

    r242624 r242664  
    225225#endif
    226226
     227#if ENABLE(DEVICE_ORIENTATION)
    227228#if PLATFORM(IOS_FAMILY)
    228229class DeviceMotionClient;
     
    230231class DeviceOrientationClient;
    231232class DeviceOrientationController;
     233#endif
     234class DeviceOrientationAndMotionAccessController;
    232235#endif
    233236
     
    12171220#endif
    12181221
    1219 #if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS_FAMILY)
     1222#if ENABLE(DEVICE_ORIENTATION)
     1223#if PLATFORM(IOS_FAMILY)
    12201224    DeviceMotionController& deviceMotionController() const;
    12211225    DeviceOrientationController& deviceOrientationController() const;
    12221226    WEBCORE_EXPORT void simulateDeviceOrientationChange(double alpha, double beta, double gamma);
    12231227#endif
     1228
     1229    DeviceOrientationAndMotionAccessController& deviceOrientationAndMotionAccessController();
     1230#endif // ENABLE(DEVICE_ORIENTATION)
    12241231
    12251232    const DocumentTiming& timing() const { return m_documentTiming; }
     
    18701877#endif
    18711878
    1872 #if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS_FAMILY)
     1879#if ENABLE(DEVICE_ORIENTATION)
     1880#if PLATFORM(IOS_FAMILY)
    18731881    std::unique_ptr<DeviceMotionClient> m_deviceMotionClient;
    18741882    std::unique_ptr<DeviceMotionController> m_deviceMotionController;
    18751883    std::unique_ptr<DeviceOrientationClient> m_deviceOrientationClient;
    18761884    std::unique_ptr<DeviceOrientationController> m_deviceOrientationController;
     1885#endif
     1886    std::unique_ptr<DeviceOrientationAndMotionAccessController> m_deviceOrientationAndMotionAccessController;
    18771887#endif
    18781888
  • trunk/Source/WebCore/dom/Event.cpp

    r241432 r242664  
    2929#include "EventPath.h"
    3030#include "EventTarget.h"
     31#include "InspectorInstrumentation.h"
    3132#include "Performance.h"
    3233#include "UserGestureIndicator.h"
  • trunk/Source/WebCore/dom/MessagePort.cpp

    r234347 r242664  
    3636#include "WorkerGlobalScope.h"
    3737#include "WorkerThread.h"
     38#include <wtf/CompletionHandler.h>
    3839
    3940namespace WebCore {
  • trunk/Source/WebCore/dom/Microtasks.cpp

    r234854 r242664  
    2323#include "Microtasks.h"
    2424
     25#include "WorkerGlobalScope.h"
    2526#include <wtf/MainThread.h>
    2627#include <wtf/NeverDestroyed.h>
  • trunk/Source/WebCore/page/ChromeClient.h

    r242108 r242664  
    483483    virtual void requestStorageAccess(String&& /*subFrameHost*/, String&& /*topFrameHost*/, uint64_t /*frameID*/, uint64_t /*pageID*/, WTF::CompletionHandler<void (bool)>&& callback) { callback(false); }
    484484
     485#if ENABLE(DEVICE_ORIENTATION)
     486    virtual void shouldAllowDeviceOrientationAndMotionAccess(const SecurityOrigin&, WTF::CompletionHandler<void(bool)>&& callback) { callback(true); }
     487#endif
     488
    485489    virtual void didInsertMenuElement(HTMLMenuElement&) { }
    486490    virtual void didRemoveMenuElement(HTMLMenuElement&) { }
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r242253 r242664  
    5050#include "DeviceMotionData.h"
    5151#include "DeviceMotionEvent.h"
     52#include "DeviceOrientationAndMotionAccessController.h"
    5253#include "DeviceOrientationController.h"
    5354#include "Document.h"
     
    18271828        incrementGamepadEventListenerCount();
    18281829#endif
    1829 
    18301830#if ENABLE(DEVICE_ORIENTATION)
    1831     if (frame() && frame()->settings().deviceOrientationEventEnabled() && document() && document()->loader() && document()->loader()->deviceOrientationEventEnabled()) {
     1831    else if (eventType == eventNames().deviceorientationEvent)
     1832        startListeningForDeviceOrientationIfNecessary();
     1833    else if (eventType == eventNames().devicemotionEvent)
     1834        startListeningForDeviceMotionIfNecessary();
     1835#endif
     1836
     1837    return true;
     1838}
     1839
     1840#if ENABLE(DEVICE_ORIENTATION)
     1841
     1842DeviceOrientationController* DOMWindow::deviceOrientationController() const
     1843{
    18321844#if PLATFORM(IOS_FAMILY)
    1833         if ((eventType == eventNames().devicemotionEvent || eventType == eventNames().deviceorientationEvent)) {
    1834             if (isSameSecurityOriginAsMainFrame() && isSecureContext()) {
    1835                 if (eventType == eventNames().deviceorientationEvent)
    1836                     document()->deviceOrientationController().addDeviceEventListener(*this);
    1837                 else
    1838                     document()->deviceMotionController().addDeviceEventListener(*this);
    1839             } else if (document()) {
    1840                 if (isSecureContext())
    1841                     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);
    1842                 else
    1843                     document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure."_s);
    1844             }
     1845    return document() ? &document()->deviceOrientationController() : nullptr;
     1846#else
     1847    return DeviceOrientationController::from(page());
     1848#endif
     1849}
     1850
     1851DeviceMotionController* DOMWindow::deviceMotionController() const
     1852{
     1853#if PLATFORM(IOS_FAMILY)
     1854    return document() ? &document()->deviceMotionController() : nullptr;
     1855#else
     1856    return DeviceMotionController::from(page());
     1857#endif
     1858}
     1859
     1860bool DOMWindow::isAllowedToUseDeviceMotionOrientation(String& message) const
     1861{
     1862    if (!frame() || !frame()->settings().deviceOrientationEventEnabled() || !document() || !document()->loader() || !document()->loader()->deviceOrientationEventEnabled()) {
     1863        message = "API is disabled"_s;
     1864        return false;
     1865    }
     1866
     1867    if (!isSecureContext()) {
     1868        message = "Browsing context is not secure"_s;
     1869        return false;
     1870    }
     1871
     1872    if (!isSameSecurityOriginAsMainFrame()) {
     1873        message = "Source frame did not have the same security origin as the main page"_s;
     1874        return false;
     1875    }
     1876    return true;
     1877}
     1878
     1879bool DOMWindow::isAllowedToAddDeviceMotionOrientationListener(String& message) const
     1880{
     1881    String innerMessage;
     1882    if (!isAllowedToUseDeviceMotionOrientation(innerMessage)) {
     1883        message = makeString("Blocked attempt to add a device motion or orientation event listener, reason: ", innerMessage, ".");
     1884        return false;
     1885    }
     1886
     1887    if (frame()->settings().deviceOrientationPermissionAPIEnabled()) {
     1888        auto accessState = document()->deviceOrientationAndMotionAccessController().accessState();
     1889        if (accessState && !*accessState) {
     1890            message = "No device motion or orientation events will be fired because permission to use the API was denied."_s;
     1891            return false;
    18451892        }
    1846 #else
    1847         if (eventType == eventNames().devicemotionEvent) {
    1848             if (isSameSecurityOriginAsMainFrame() && isSecureContext()) {
    1849                 if (DeviceMotionController* controller = DeviceMotionController::from(page()))
    1850                     controller->addDeviceEventListener(*this);
    1851             } else
    1852                 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);
    1853         } else if (eventType == eventNames().deviceorientationEvent) {
    1854             if (isSameSecurityOriginAsMainFrame() && isSecureContext()) {
    1855                 if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
    1856                     controller->addDeviceEventListener(*this);
    1857             } else {
    1858                 if (isSecureContext())
    1859                     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);
    1860                 else
    1861                     document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure."_s);
    1862             }
     1893        if (!accessState) {
     1894            message = "No device motion or orientation events will be fired until permission has been requested and granted."_s;
     1895            return false;
    18631896        }
    1864 #endif // PLATFORM(IOS_FAMILY)
    1865     } else if (eventType == eventNames().devicemotionEvent)
     1897    }
     1898
     1899    return true;
     1900}
     1901
     1902void DOMWindow::startListeningForDeviceOrientationIfNecessary()
     1903{
     1904    if (!hasEventListeners(eventNames().deviceorientationEvent))
     1905        return;
     1906
     1907    auto* deviceController = deviceOrientationController();
     1908    if (!deviceController || deviceController->hasDeviceEventListener(*this))
     1909        return;
     1910
     1911    String errorMessage;
     1912    if (!isAllowedToAddDeviceMotionOrientationListener(errorMessage)) {
     1913        if (auto* document = this->document())
     1914            document->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, errorMessage);
     1915        return;
     1916    }
     1917
     1918    deviceController->addDeviceEventListener(*this);
     1919}
     1920
     1921void DOMWindow::stopListeningForDeviceOrientationIfNecessary()
     1922{
     1923    if (hasEventListeners(eventNames().deviceorientationEvent))
     1924        return;
     1925
     1926    if (auto* deviceController = deviceOrientationController())
     1927        deviceController->removeDeviceEventListener(*this);
     1928}
     1929
     1930void DOMWindow::startListeningForDeviceMotionIfNecessary()
     1931{
     1932    if (!hasEventListeners(eventNames().devicemotionEvent))
     1933        return;
     1934
     1935    auto* deviceController = deviceMotionController();
     1936    if (!deviceController || deviceController->hasDeviceEventListener(*this))
     1937        return;
     1938
     1939    String errorMessage;
     1940    if (!isAllowedToAddDeviceMotionOrientationListener(errorMessage)) {
    18661941        failedToRegisterDeviceMotionEventListener();
    1867 #endif // ENABLE(DEVICE_ORIENTATION)
    1868 
    1869     return true;
    1870 }
    1871 
    1872 #if ENABLE(DEVICE_ORIENTATION)
     1942        if (auto* document = this->document())
     1943            document->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, errorMessage);
     1944        return;
     1945    }
     1946
     1947    deviceController->addDeviceEventListener(*this);
     1948}
     1949
     1950void DOMWindow::stopListeningForDeviceMotionIfNecessary()
     1951{
     1952    if (hasEventListeners(eventNames().devicemotionEvent))
     1953        return;
     1954
     1955    if (auto* deviceController = deviceMotionController())
     1956        deviceController->removeDeviceEventListener(*this);
     1957}
    18731958
    18741959void DOMWindow::failedToRegisterDeviceMotionEventListener()
     
    19422027    else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this))
    19432028        removeBeforeUnloadEventListener(this);
    1944 #if ENABLE(DEVICE_ORIENTATION)
    1945 #if PLATFORM(IOS_FAMILY)
    1946     else if (eventType == eventNames().devicemotionEvent && document())
    1947         document()->deviceMotionController().removeDeviceEventListener(*this);
    1948     else if (eventType == eventNames().deviceorientationEvent && document())
    1949         document()->deviceOrientationController().removeDeviceEventListener(*this);
    1950 #else
    1951     else if (eventType == eventNames().devicemotionEvent) {
    1952         if (DeviceMotionController* controller = DeviceMotionController::from(page()))
    1953             controller->removeDeviceEventListener(*this);
    1954     } else if (eventType == eventNames().deviceorientationEvent) {
    1955         if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
    1956             controller->removeDeviceEventListener(*this);
    1957     }
    1958 #endif // PLATFORM(IOS_FAMILY)
    1959 #endif // ENABLE(DEVICE_ORIENTATION)
    19602029#if PLATFORM(IOS_FAMILY)
    19612030    else if (eventType == eventNames().scrollEvent)
     
    19772046    else if (eventNames().isGamepadEventType(eventType))
    19782047        decrementGamepadEventListenerCount();
     2048#endif
     2049#if ENABLE(DEVICE_ORIENTATION)
     2050    else if (eventType == eventNames().deviceorientationEvent)
     2051        stopListeningForDeviceOrientationIfNecessary();
     2052    else if (eventType == eventNames().devicemotionEvent)
     2053        stopListeningForDeviceMotionIfNecessary();
    19792054#endif
    19802055
     
    20602135
    20612136#if ENABLE(DEVICE_ORIENTATION)
    2062 #if PLATFORM(IOS_FAMILY)
    2063     if (Document* document = this->document()) {
    2064         document->deviceMotionController().removeAllDeviceEventListeners(*this);
    2065         document->deviceOrientationController().removeAllDeviceEventListeners(*this);
    2066     }
    2067 #else
    2068     if (DeviceMotionController* controller = DeviceMotionController::from(page()))
    2069         controller->removeAllDeviceEventListeners(*this);
    2070     if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
    2071         controller->removeAllDeviceEventListeners(*this);
    2072 #endif // PLATFORM(IOS_FAMILY)
    2073 #endif // ENABLE(DEVICE_ORIENTATION)
     2137        stopListeningForDeviceOrientationIfNecessary();
     2138        stopListeningForDeviceMotionIfNecessary();
     2139#endif
    20742140
    20752141#if PLATFORM(IOS_FAMILY)
  • trunk/Source/WebCore/page/DOMWindow.h

    r242138 r242664  
    8383class WebKitPoint;
    8484
     85#if ENABLE(DEVICE_ORIENTATION)
     86class DeviceMotionController;
     87class DeviceOrientationController;
     88#endif
     89
    8590struct ImageBitmapOptions;
    8691struct WindowFeatures;
     
    310315    void decrementScrollEventListenersCount();
    311316    unsigned scrollEventListenerCount() const { return m_scrollEventListenerCount; }
     317#endif
     318
     319#if ENABLE(DEVICE_ORIENTATION)
     320    void startListeningForDeviceOrientationIfNecessary();
     321    void stopListeningForDeviceOrientationIfNecessary();
     322    void startListeningForDeviceMotionIfNecessary();
     323    void stopListeningForDeviceMotionIfNecessary();
     324
     325    bool isAllowedToUseDeviceMotionOrientation(String& message) const;
     326    bool isAllowedToAddDeviceMotionOrientationListener(String& message) const;
     327
     328    DeviceOrientationController* deviceOrientationController() const;
     329    DeviceMotionController* deviceMotionController() const;
    312330#endif
    313331
  • trunk/Source/WebCore/page/DeviceController.cpp

    r240237 r242664  
    7070}
    7171
     72bool DeviceController::hasDeviceEventListener(DOMWindow& window) const
     73{
     74    return m_listeners.contains(&window);
     75}
     76
    7277void DeviceController::dispatchDeviceEvent(Event& event)
    7378{
  • trunk/Source/WebCore/page/DeviceController.h

    r240237 r242664  
    4747    void removeDeviceEventListener(DOMWindow&);
    4848    void removeAllDeviceEventListeners(DOMWindow&);
     49    bool hasDeviceEventListener(DOMWindow&) const;
    4950
    5051    void dispatchDeviceEvent(Event&);
  • trunk/Source/WebCore/page/Settings.yaml

    r242621 r242664  
    768768  conditional: DEVICE_ORIENTATION
    769769
     770deviceOrientationPermissionAPIEnabled:
     771  type: bool
     772  initial: false
     773  conditional: DEVICE_ORIENTATION
     774
    770775shouldEnableTextAutosizingBoost:
    771776  type: bool
  • trunk/Source/WebKit/ChangeLog

    r242662 r242664  
     12019-03-08  Chris Dumez  <cdumez@apple.com>
     2
     3        Add support for Device Orientation / Motion permission API
     4        https://bugs.webkit.org/show_bug.cgi?id=195329
     5        <rdar://problem/47645367>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Add support for Device Orientation / Motion permission API:
     10        - https://github.com/w3c/deviceorientation/issues/57
     11
     12        This adds new SPI to WKUIDelegatePrivate, until we can make this API.
     13
     14        * Shared/WebPreferences.yaml:
     15        * UIProcess/API/APIUIClient.h:
     16        (API::UIClient::shouldAllowDeviceOrientationAndMotionAccess):
     17        * UIProcess/API/C/WKPage.cpp:
     18        (WKPageSetPageUIClient):
     19        * UIProcess/API/C/WKPageUIClient.h:
     20        * UIProcess/API/Cocoa/WKUIDelegate.h:
     21        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
     22        * UIProcess/Cocoa/UIDelegate.h:
     23        * UIProcess/Cocoa/UIDelegate.mm:
     24        (WebKit::UIDelegate::setDelegate):
     25        (WebKit::UIDelegate::UIClient::shouldAllowDeviceOrientationAndMotionAccess):
     26        * UIProcess/WebPageProxy.cpp:
     27        (WebKit::WebPageProxy::requestDeviceOrientationAndMotionAccess):
     28        * UIProcess/WebPageProxy.h:
     29        * UIProcess/WebPageProxy.messages.in:
     30        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     31        (WebKit::WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess):
     32        * WebProcess/WebCoreSupport/WebChromeClient.h:
     33        * WebProcess/WebPage/WebPage.cpp:
     34        (WebKit::nextDeviceOrientationAndMotionPermissionCallbackID):
     35        (WebKit::WebPage::shouldAllowDeviceOrientationAndMotionAccess):
     36        (WebKit::WebPage::didReceiveDeviceOrientationAndMotionAccessDecision):
     37        * WebProcess/WebPage/WebPage.h:
     38        * WebProcess/WebPage/WebPage.messages.in:
     39
    1402019-03-08  Brady Eidson  <beidson@apple.com>
    241
  • trunk/Source/WebKit/Shared/WebPreferences.yaml

    r242621 r242664  
    1212  condition: ENABLE(DEVICE_ORIENTATION)
    1313  webcoreName: deviceOrientationEventEnabled
     14
     15DeviceOrientationPermissionAPIEnabled:
     16  type: bool
     17  defaultValue: defaultDeviceOrientationPermissionAPIEnabled()
     18  condition: ENABLE(DEVICE_ORIENTATION)
     19  webcoreName: deviceOrientationPermissionAPIEnabled
     20  humanReadableName: "Permission API for device orientation / motion access."
     21  humanReadableDescription: "DeviceOrientationEvent.requestPermission() / DeviceMotionEvent.requestPermission()"
     22  category: experimental
    1423
    1524JavaScriptEnabled:
  • trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.cpp

    r238461 r242664  
    4545}
    4646
     47bool defaultDeviceOrientationPermissionAPIEnabled()
     48{
     49#if PLATFORM(IOS) && ENABLE(DEVICE_ORIENTATION)
     50    return linkedOnOrAfter(WebKit::SDKVersion::FirstWithDeviceOrientationAndMotionPermissionAPI);
     51#else
     52    return false;
     53#endif
     54}
     55
    4756bool defaultCustomPasteboardDataEnabled()
    4857{
  • trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h

    r242350 r242664  
    228228
    229229bool defaultPassiveTouchListenersAsDefaultOnDocument();
     230bool defaultDeviceOrientationPermissionAPIEnabled();
    230231bool defaultCustomPasteboardDataEnabled();
    231232
  • trunk/Source/WebKit/UIProcess/API/APIUIClient.h

    r241926 r242664  
    174174#endif
    175175
     176#if ENABLE(DEVICE_ORIENTATION)
     177    virtual void shouldAllowDeviceOrientationAndMotionAccess(WebKit::WebPageProxy&, SecurityOrigin&, CompletionHandler<void(bool)>&& completionHandler) { completionHandler(true); }
     178#endif
     179
    176180    virtual void didClickAutoFillButton(WebKit::WebPageProxy&, Object*) { }
    177181
  • trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp

    r241584 r242664  
    116116
    117117template<> struct ClientTraits<WKPageUIClientBase> {
    118     typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2, WKPageUIClientV3, WKPageUIClientV4, WKPageUIClientV5, WKPageUIClientV6, WKPageUIClientV7, WKPageUIClientV8, WKPageUIClientV9, WKPageUIClientV10, WKPageUIClientV11, WKPageUIClientV12> Versions;
     118    typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2, WKPageUIClientV3, WKPageUIClientV4, WKPageUIClientV5, WKPageUIClientV6, WKPageUIClientV7, WKPageUIClientV8, WKPageUIClientV9, WKPageUIClientV10, WKPageUIClientV11, WKPageUIClientV12, WKPageUIClientV13> Versions;
    119119};
    120120
     
    19041904        }
    19051905
     1906#if ENABLE(DEVICE_ORIENTATION)
     1907        void shouldAllowDeviceOrientationAndMotionAccess(WebPageProxy& page, API::SecurityOrigin& origin, CompletionHandler<void(bool)>&& completionHandler) final
     1908        {
     1909            if (!m_client.shouldAllowDeviceOrientationAndMotionAccess)
     1910                return completionHandler(true);
     1911
     1912            completionHandler(m_client.shouldAllowDeviceOrientationAndMotionAccess(toAPI(&page), toAPI(&origin), m_client.base.clientInfo));
     1913        }
     1914#endif
     1915
    19061916        // Printing.
    19071917        float headerHeight(WebPageProxy& page, WebFrameProxy& frame) final
  • trunk/Source/WebKit/UIProcess/API/C/WKPageUIClient.h

    r239625 r242664  
    135135typedef void (*WKDidExceedBackgroundResourceLimitWhileInForegroundCallback)(WKPageRef page, WKResourceLimit limit, const void* clientInfo);
    136136typedef void (*WKPageDidResignInputElementStrongPasswordAppearanceCallback)(WKPageRef page, WKTypeRef userData, const void *clientInfo);
     137typedef bool (*WKPageShouldAllowDeviceOrientationAndMotionAccessCallback)(WKPageRef page, WKSecurityOriginRef securityOrigin, const void *clientInfo);
    137138
    138139// Deprecated
     
    11411142} WKPageUIClientV12;
    11421143
     1144typedef struct WKPageUIClientV13 {
     1145    WKPageUIClientBase                                                  base;
     1146
     1147    // Version 0.
     1148    WKPageCreateNewPageCallback_deprecatedForUseWithV0                  createNewPage_deprecatedForUseWithV0;
     1149    WKPageUIClientCallback                                              showPage;
     1150    WKPageUIClientCallback                                              close;
     1151    WKPageTakeFocusCallback                                             takeFocus;
     1152    WKPageFocusCallback                                                 focus;
     1153    WKPageUnfocusCallback                                               unfocus;
     1154    WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0             runJavaScriptAlert_deprecatedForUseWithV0;
     1155    WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0           runJavaScriptConfirm_deprecatedForUseWithV0;
     1156    WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0            runJavaScriptPrompt_deprecatedForUseWithV0;
     1157    WKPageSetStatusTextCallback                                         setStatusText;
     1158    WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0        mouseDidMoveOverElement_deprecatedForUseWithV0;
     1159    WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0     missingPluginButtonClicked_deprecatedForUseWithV0;
     1160    WKPageDidNotHandleKeyEventCallback                                  didNotHandleKeyEvent;
     1161    WKPageDidNotHandleWheelEventCallback                                didNotHandleWheelEvent;
     1162    WKPageGetToolbarsAreVisibleCallback                                 toolbarsAreVisible;
     1163    WKPageSetToolbarsAreVisibleCallback                                 setToolbarsAreVisible;
     1164    WKPageGetMenuBarIsVisibleCallback                                   menuBarIsVisible;
     1165    WKPageSetMenuBarIsVisibleCallback                                   setMenuBarIsVisible;
     1166    WKPageGetStatusBarIsVisibleCallback                                 statusBarIsVisible;
     1167    WKPageSetStatusBarIsVisibleCallback                                 setStatusBarIsVisible;
     1168    WKPageGetIsResizableCallback                                        isResizable;
     1169    WKPageSetIsResizableCallback                                        setIsResizable;
     1170    WKPageGetWindowFrameCallback                                        getWindowFrame;
     1171    WKPageSetWindowFrameCallback                                        setWindowFrame;
     1172    WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6    runBeforeUnloadConfirmPanel_deprecatedForUseWithV6;
     1173    WKPageUIClientCallback                                              didDraw;
     1174    WKPageUIClientCallback                                              pageDidScroll;
     1175    WKPageExceededDatabaseQuotaCallback                                 exceededDatabaseQuota;
     1176    WKPageRunOpenPanelCallback                                          runOpenPanel;
     1177    WKPageDecidePolicyForGeolocationPermissionRequestCallback           decidePolicyForGeolocationPermissionRequest;
     1178    WKPageHeaderHeightCallback                                          headerHeight;
     1179    WKPageFooterHeightCallback                                          footerHeight;
     1180    WKPageDrawHeaderCallback                                            drawHeader;
     1181    WKPageDrawFooterCallback                                            drawFooter;
     1182    WKPagePrintFrameCallback                                            printFrame;
     1183    WKPageUIClientCallback                                              runModal;
     1184    void*                                                               unused1; // Used to be didCompleteRubberBandForMainFrame
     1185    WKPageSaveDataToFileInDownloadsFolderCallback                       saveDataToFileInDownloadsFolder;
     1186    void*                                                               shouldInterruptJavaScript_unavailable;
     1187
     1188    // Version 1.
     1189    WKPageCreateNewPageCallback_deprecatedForUseWithV1                  createNewPage_deprecatedForUseWithV1;
     1190    WKPageMouseDidMoveOverElementCallback                               mouseDidMoveOverElement;
     1191    WKPageDecidePolicyForNotificationPermissionRequestCallback          decidePolicyForNotificationPermissionRequest;
     1192    WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1;
     1193
     1194    // Version 2.
     1195    WKPageShowColorPickerCallback                                       showColorPicker;
     1196    WKPageHideColorPickerCallback                                       hideColorPicker;
     1197    WKPageUnavailablePluginButtonClickedCallback                        unavailablePluginButtonClicked;
     1198
     1199    // Version 3.
     1200    WKPagePinnedStateDidChangeCallback                                  pinnedStateDidChange;
     1201
     1202    // Version 4.
     1203    void*                                                               unused2; // Used to be didBeginTrackingPotentialLongMousePress.
     1204    void*                                                               unused3; // Used to be didRecognizeLongMousePress.
     1205    void*                                                               unused4; // Used to be didCancelTrackingPotentialLongMousePress.
     1206    WKPageIsPlayingAudioDidChangeCallback                               isPlayingAudioDidChange;
     1207
     1208    // Version 5.
     1209    WKPageDecidePolicyForUserMediaPermissionRequestCallback             decidePolicyForUserMediaPermissionRequest;
     1210    WKPageDidClickAutoFillButtonCallback                                didClickAutoFillButton;
     1211    WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV5             runJavaScriptAlert_deprecatedForUseWithV5;
     1212    WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV5           runJavaScriptConfirm_deprecatedForUseWithV5;
     1213    WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV5            runJavaScriptPrompt_deprecatedForUseWithV5;
     1214    WKPageMediaSessionMetadataDidChangeCallback                         mediaSessionMetadataDidChange;
     1215
     1216    // Version 6.
     1217    WKPageCreateNewPageCallback                                         createNewPage;
     1218    WKPageRunJavaScriptAlertCallback                                    runJavaScriptAlert;
     1219    WKPageRunJavaScriptConfirmCallback                                  runJavaScriptConfirm;
     1220    WKPageRunJavaScriptPromptCallback                                   runJavaScriptPrompt;
     1221    WKCheckUserMediaPermissionCallback                                  checkUserMediaPermissionForOrigin;
     1222
     1223    // Version 7.
     1224    WKPageRunBeforeUnloadConfirmPanelCallback                           runBeforeUnloadConfirmPanel;
     1225    WKFullscreenMayReturnToInlineCallback                               fullscreenMayReturnToInline;
     1226
     1227    // Version 8.
     1228    WKRequestPointerLockCallback                                        requestPointerLock;
     1229    WKDidLosePointerLockCallback                                        didLosePointerLock;
     1230
     1231    // Version 9.
     1232    WKHandleAutoplayEventCallback                                       handleAutoplayEvent;
     1233
     1234    // Version 10.
     1235    WKHasVideoInPictureInPictureDidChangeCallback                       hasVideoInPictureInPictureDidChange;
     1236    WKDidExceedBackgroundResourceLimitWhileInForegroundCallback         didExceedBackgroundResourceLimitWhileInForeground;
     1237
     1238    // Version 11.
     1239    WKPageDidResignInputElementStrongPasswordAppearanceCallback         didResignInputElementStrongPasswordAppearance;
     1240
     1241    // Version 12.
     1242    WKPageRequestStorageAccessConfirmCallback                           requestStorageAccessConfirm;
     1243
     1244    // Version 13.
     1245    WKPageShouldAllowDeviceOrientationAndMotionAccessCallback           shouldAllowDeviceOrientationAndMotionAccess;
     1246} WKPageUIClientV13;
     1247
    11431248#ifdef __cplusplus
    11441249}
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegate.h

    r242339 r242664  
    3535@class WKOpenPanelParameters;
    3636@class WKPreviewElementInfo;
     37@class WKSecurityOrigin;
    3738@class WKWebView;
    3839@class WKWebViewConfiguration;
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r242339 r242664  
    172172- (void)_webView:(WKWebView *)webView didPresentFocusedElementViewController:(UIViewController *)controller WK_API_AVAILABLE(ios(12.0));
    173173- (void)_webView:(WKWebView *)webView didDismissFocusedElementViewController:(UIViewController *)controller WK_API_AVAILABLE(ios(12.0));
     174
     175/*! @abstract Allows your app to determine whether or not the given security origin should have access to the device's orientation and motion.
     176 @param securityOrigin The security origin which requested access to the device's orientation and motion.
     177 @param decisionHandler The decision handler to call once the app has made its decision. Pass YES to allow the origin access, NO otherwise.
     178
     179 If you do not implement this method, access to the device's orientation and motion will be granted.
     180 */
     181- (void)_webView:(WKWebView *)webView shouldAllowDeviceOrientationAndMotionAccessForSecurityOrigin:(WKSecurityOrigin *)securityOrigin decisionHandler:(void (^)(BOOL))decisionHandler WK_API_AVAILABLE(ios(WK_IOS_TBA));
     182
    174183#else // TARGET_OS_IPHONE
    175184- (void)_prepareForImmediateActionAnimationForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.13.4));
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h

    r242339 r242664  
    121121        void saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String&, const WTF::String&, const URL&, API::Data&) final;
    122122#endif
     123#if ENABLE(DEVICE_ORIENTATION)
     124        void shouldAllowDeviceOrientationAndMotionAccess(WebKit::WebPageProxy&, API::SecurityOrigin&, CompletionHandler<void(bool)>&&) final;
     125#endif
    123126        bool needsFontAttributes() const final { return m_uiDelegate.m_delegateMethods.webViewDidChangeFontAttributes; }
    124127        void didChangeFontAttributes(const WebCore::FontAttributes&) final;
     
    189192        bool webViewRequestNotificationPermissionForSecurityOriginDecisionHandler : 1;
    190193#endif
     194#if ENABLE(DEVICE_ORIENTATION)
     195        bool webViewShouldAllowDeviceOrientationAndMotionAccessForSecurityOriginDecisionHandler : 1;
     196#endif
    191197        bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
    192198        bool webViewDecideDatabaseQuotaForSecurityOriginDatabaseNameDisplayNameCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm

    r242339 r242664  
    134134    m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:)];
    135135#endif
     136#if ENABLE(DEVICE_ORIENTATION)
     137    m_delegateMethods.webViewShouldAllowDeviceOrientationAndMotionAccessForSecurityOriginDecisionHandler = [delegate respondsToSelector:@selector(_webView:shouldAllowDeviceOrientationAndMotionAccessForSecurityOrigin:decisionHandler:)];
     138#endif
    136139    m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler = [delegate respondsToSelector:@selector(_webView:decideDatabaseQuotaForSecurityOrigin:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:)];
    137140    m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginDatabaseNameDisplayNameCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler = [delegate respondsToSelector:@selector(_webView:decideDatabaseQuotaForSecurityOrigin:databaseName:displayName:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:)];
     
    845848#endif
    846849
     850#if ENABLE(DEVICE_ORIENTATION)
     851void UIDelegate::UIClient::shouldAllowDeviceOrientationAndMotionAccess(WebKit::WebPageProxy&, API::SecurityOrigin& securityOrigin, CompletionHandler<void(bool)>&& completionHandler)
     852{
     853    if (!m_uiDelegate.m_delegateMethods.webViewShouldAllowDeviceOrientationAndMotionAccessForSecurityOriginDecisionHandler)
     854        return completionHandler(true);
     855
     856    auto delegate = m_uiDelegate.m_delegate.get();
     857    if (!delegate)
     858        return completionHandler(true);
     859
     860    auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:shouldAllowDeviceOrientationAndMotionAccessForSecurityOrigin:decisionHandler:));
     861    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView shouldAllowDeviceOrientationAndMotionAccessForSecurityOrigin:wrapper(securityOrigin) decisionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL granted) mutable {
     862        if (checker->completionHandlerHasBeenCalled())
     863            return;
     864        checker->didCallCompletionHandler();
     865        completionHandler(granted);
     866    }).get()];
     867}
     868#endif
     869
    847870void UIDelegate::UIClient::didChangeFontAttributes(const WebCore::FontAttributes& fontAttributes)
    848871{
  • trunk/Source/WebKit/UIProcess/Cocoa/VersionChecks.h

    r242521 r242664  
    3939#endif
    4040
     41#ifndef DYLD_IOS_VERSION_FIRST_WITH_DEVICE_ORIENTATION_AND_MOTION_PERMISSION_API
     42#define DYLD_IOS_VERSION_FIRST_WITH_DEVICE_ORIENTATION_AND_MOTION_PERMISSION_API 0
     43#endif
     44
    4145namespace WebKit {
    4246
     
    5761    FirstWithSnapshotAfterScreenUpdates = DYLD_IOS_VERSION_FIRST_WITH_SNAPSHOT_AFTER_SCREEN_UPDATES,
    5862    FirstWhereDownloadAttributeDoesNotOverrideNavigationDelegate = DYLD_IOS_VERSION_FIRST_WHERE_DOWNLOAD_ATTRIBUTE_DOES_NOT_OVERRIDE_NAVIGATION_DELEGATE,
     63    FirstWithDeviceOrientationAndMotionPermissionAPI = DYLD_IOS_VERSION_FIRST_WITH_DEVICE_ORIENTATION_AND_MOTION_PERMISSION_API,
    5964#elif PLATFORM(MAC)
    6065    FirstWithNetworkCache = DYLD_MACOSX_VERSION_10_11,
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r242603 r242664  
    71757175}
    71767176
     7177#if ENABLE(DEVICE_ORIENTATION)
     7178void WebPageProxy::requestDeviceOrientationAndMotionAccess(WebCore::SecurityOriginData&& originData, uint64_t callbackID)
     7179{
     7180    auto origin = API::SecurityOrigin::create(originData.securityOrigin());
     7181    m_uiClient->shouldAllowDeviceOrientationAndMotionAccess(*this, origin.get(), [this, weakThis = makeWeakPtr(*this), callbackID](bool granted) {
     7182        if (!weakThis || !isValid())
     7183            return;
     7184        m_process->send(Messages::WebPage::DidReceiveDeviceOrientationAndMotionAccessDecision(callbackID, granted), m_pageID);
     7185    });
     7186}
     7187#endif
     7188
    71777189void WebPageProxy::requestNotificationPermission(uint64_t requestID, const String& originString)
    71787190{
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r242616 r242664  
    14021402#endif
    14031403
     1404#if ENABLE(DEVICE_ORIENTATION)
     1405    void requestDeviceOrientationAndMotionAccess(WebCore::SecurityOriginData&&, uint64_t callbackID);
     1406#endif
     1407
    14041408    static WebPageProxy* nonEphemeralWebPageProxy();
    14051409
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r242551 r242664  
    534534    LoadSynchronousURLSchemeTask(struct WebKit::URLSchemeTaskParameters parameters) -> (WebCore::ResourceResponse response, WebCore::ResourceError error, IPC::DataReference data) Delayed
    535535
     536#if ENABLE(DEVICE_ORIENTATION)
     537    RequestDeviceOrientationAndMotionAccess(struct WebCore::SecurityOriginData origin, uint64_t callbackID);
     538#endif
     539
    536540#if ENABLE(ATTACHMENT_ELEMENT)
    537541    RegisterAttachmentIdentifierFromData(String identifier, String contentType, String preferredFileName, IPC::SharedBufferDataReference data)
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r242010 r242664  
    13211321#endif
    13221322
     1323#if ENABLE(DEVICE_ORIENTATION)
     1324void WebChromeClient::shouldAllowDeviceOrientationAndMotionAccess(const SecurityOrigin& origin, CompletionHandler<void(bool)>&& callback)
     1325{
     1326    m_page.shouldAllowDeviceOrientationAndMotionAccess(origin, WTFMove(callback));
     1327}
     1328#endif
     1329
    13231330} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h

    r242108 r242664  
    367367#endif
    368368
     369#if ENABLE(DEVICE_ORIENTATION)
     370    void shouldAllowDeviceOrientationAndMotionAccess(const WebCore::SecurityOrigin&, CompletionHandler<void(bool)>&&) final;
     371#endif
     372
    369373    String m_cachedToolTip;
    370374    mutable RefPtr<WebFrame> m_cachedFrameSetLargestFrame;
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r242624 r242664  
    63406340}
    63416341#endif
     6342
     6343#if ENABLE(DEVICE_ORIENTATION)
     6344static uint64_t nextDeviceOrientationAndMotionPermissionCallbackID()
     6345{
     6346    static uint64_t nextCallbackID = 0;
     6347    return ++nextCallbackID;
     6348}
     6349
     6350void WebPage::shouldAllowDeviceOrientationAndMotionAccess(const WebCore::SecurityOrigin& origin, CompletionHandler<void(bool)>&& callback)
     6351{
     6352    auto callbackID = nextDeviceOrientationAndMotionPermissionCallbackID();
     6353    ASSERT(!m_deviceOrientationAndMotionPermissionCallbackMap.contains(callbackID));
     6354    m_deviceOrientationAndMotionPermissionCallbackMap.add(callbackID, WTFMove(callback));
     6355
     6356    send(Messages::WebPageProxy::RequestDeviceOrientationAndMotionAccess(origin.data(), callbackID));
     6357}
     6358
     6359void WebPage::didReceiveDeviceOrientationAndMotionAccessDecision(uint64_t callbackID, bool granted)
     6360{
     6361    auto callback = m_deviceOrientationAndMotionPermissionCallbackMap.take(callbackID);
     6362    ASSERT(callback);
     6363    callback(granted);
     6364}
     6365#endif
    63426366   
    63436367static ShareSheetCallbackID nextShareSheetCallbackID()
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r242624 r242664  
    11111111#endif
    11121112
     1113#if ENABLE(DEVICE_ORIENTATION)
     1114    void shouldAllowDeviceOrientationAndMotionAccess(const WebCore::SecurityOrigin&, CompletionHandler<void(bool)>&&);
     1115#endif
     1116
    11131117    void showShareSheet(WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&& callback);
    11141118    void didCompleteShareSheet(bool wasCompleted, ShareSheetCallbackID contextId);
     
    12051209    void requestDragStart(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition);
    12061210    void requestAdditionalItemsForDragSession(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition);
     1211#endif
     1212
     1213#if ENABLE(DEVICE_ORIENTATION)
     1214    void didReceiveDeviceOrientationAndMotionAccessDecision(uint64_t callbackID, bool granted);
    12071215#endif
    12081216
     
    18371845    HashMap<ShareSheetCallbackID, WTF::Function<void(bool completed)>> m_shareSheetResponseCallbackMap;
    18381846
     1847#if ENABLE(DEVICE_ORIENTATION)
     1848    HashMap<uint64_t, WTF::CompletionHandler<void(bool granted)>> m_deviceOrientationAndMotionPermissionCallbackMap;
     1849#endif
     1850
    18391851#if ENABLE(APPLICATION_MANIFEST)
    18401852    HashMap<uint64_t, uint64_t> m_applicationManifestFetchCallbackMap;
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r242551 r242664  
    364364    DidReceiveNotificationPermissionDecision(uint64_t notificationID, bool allowed)
    365365
     366#if ENABLE(DEVICE_ORIENTATION)
     367    DidReceiveDeviceOrientationAndMotionAccessDecision(uint64_t callbackID, bool granted)
     368#endif
     369
    366370    # Printing.
    367371    BeginPrinting(uint64_t frameID, struct WebKit::PrintInfo printInfo)
  • trunk/Tools/ChangeLog

    r242658 r242664  
     12019-03-08  Chris Dumez  <cdumez@apple.com>
     2
     3        Add support for Device Orientation / Motion permission API
     4        https://bugs.webkit.org/show_bug.cgi?id=195329
     5        <rdar://problem/47645367>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Add test infrastructure to help test the Device Orientation / Motion permission API.
     10
     11        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
     12        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
     13        (WTR::TestRunner::setShouldAllowDeviceOrientationAndMotionAccess):
     14        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     15        * WebKitTestRunner/TestController.cpp:
     16        (WTR::shouldAllowDeviceOrientationAndMotionAccess):
     17        (WTR::TestController::createWebViewWithOptions):
     18        (WTR::TestController::resetStateToConsistentValues):
     19        (WTR::TestController::handleDeviceOrientationAndMotionAccessRequest):
     20        * WebKitTestRunner/TestController.h:
     21        (WTR::TestController::setShouldAllowDeviceOrientationAndMotionAccess):
     22        * WebKitTestRunner/TestInvocation.cpp:
     23        (WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
     24
    1252019-03-08  Saam barati  <sbarati@apple.com>
    226
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl

    r242598 r242664  
    104104    boolean isCommandEnabled(DOMString name);
    105105    unsigned long windowCount();
     106
     107    // Device Orientation Motion.
     108    void setShouldAllowDeviceOrientationAndMotionAccess(boolean value);
    106109
    107110    // Special DOM variables.
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r242598 r242664  
    12951295}
    12961296
     1297void TestRunner::setShouldAllowDeviceOrientationAndMotionAccess(bool value)
     1298{
     1299    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetShouldAllowDeviceOrientationAndMotionAccess"));
     1300    WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
     1301    WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get());
     1302}
     1303
    12971304void TestRunner::terminateNetworkProcess()
    12981305{
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r242598 r242664  
    349349    void setIgnoresViewportScaleLimits(bool);
    350350    void setShouldDownloadUndisplayableMIMETypes(bool);
     351    void setShouldAllowDeviceOrientationAndMotionAccess(bool);
    351352
    352353    bool didCancelClientRedirect() const { return m_didCancelClientRedirect; }
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r242598 r242664  
    261261{
    262262    WKPageDidAllowPointerLock(page);
     263}
     264
     265static bool shouldAllowDeviceOrientationAndMotionAccess(WKPageRef, WKSecurityOriginRef origin, const void*)
     266{
     267    return TestController::singleton().handleDeviceOrientationAndMotionAccessRequest(origin);
    263268}
    264269
     
    571576
    572577    platformCreateWebView(configuration.get(), options);
    573     WKPageUIClientV8 pageUIClient = {
    574         { 8, m_mainWebView.get() },
     578    WKPageUIClientV13 pageUIClient = {
     579        { 13, m_mainWebView.get() },
    575580        0, // createNewPage_deprecatedForUseWithV0
    576581        0, // showPage
     
    638643        0, // fullscreenMayReturnToInline
    639644        requestPointerLock,
    640         0,
     645        0, // didLosePointerLock
     646        0, // handleAutoplayEvent
     647        0, // hasVideoInPictureInPictureDidChange
     648        0, // didExceedBackgroundResourceLimitWhileInForeground
     649        0, // didResignInputElementStrongPasswordAppearance
     650        0, // requestStorageAccessConfirm
     651        shouldAllowDeviceOrientationAndMotionAccess
    641652    };
    642653    WKPageSetPageUIClient(m_mainWebView->page(), &pageUIClient.base);
     
    943954
    944955    m_shouldDownloadUndisplayableMIMETypes = false;
     956
     957    m_shouldAllowDeviceOrientationAndMotionAccess = false;
    945958
    946959    m_workQueueManager.clearWorkQueue();
     
    25492562}
    25502563
     2564bool TestController::handleDeviceOrientationAndMotionAccessRequest(WKSecurityOriginRef origin)
     2565{
     2566    m_currentInvocation->outputText(makeString("Received device orientation & motion access request for security origin \"", originUserVisibleName(origin), "\".\n"));
     2567    return m_shouldAllowDeviceOrientationAndMotionAccess;
     2568}
     2569
    25512570void TestController::handleUserMediaPermissionRequest(WKFrameRef frame, WKSecurityOriginRef userMediaDocumentOrigin, WKSecurityOriginRef topLevelDocumentOrigin, WKUserMediaPermissionRequestRef request)
    25522571{
  • trunk/Tools/WebKitTestRunner/TestController.h

    r242598 r242664  
    151151    void resetUserMediaPermissionRequestCountForOrigin(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString);
    152152
     153    // Device Orientation / Motion.
     154    bool handleDeviceOrientationAndMotionAccessRequest(WKSecurityOriginRef);
     155
    153156    // Content Extensions.
    154157    void configureContentExtensionForTest(const TestInvocation&);
     
    200203
    201204    void setShouldDownloadUndisplayableMIMETypes(bool value) { m_shouldDownloadUndisplayableMIMETypes = value; }
     205    void setShouldAllowDeviceOrientationAndMotionAccess(bool value) { m_shouldAllowDeviceOrientationAndMotionAccess = value; }
    202206
    203207    void setStatisticsDebugMode(bool value);
     
    510514    bool m_policyDelegatePermissive { false };
    511515    bool m_shouldDownloadUndisplayableMIMETypes { false };
     516    bool m_shouldAllowDeviceOrientationAndMotionAccess { false };
    512517
    513518    bool m_rejectsProtectionSpaceAndContinueForAuthenticationChallenges { false };
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r242598 r242664  
    748748    }
    749749
     750    if (WKStringIsEqualToUTF8CString(messageName, "SetShouldAllowDeviceOrientationAndMotionAccess")) {
     751        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
     752        WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
     753        TestController::singleton().setShouldAllowDeviceOrientationAndMotionAccess(WKBooleanGetValue(value));
     754        return;
     755    }
     756
    750757    if (WKStringIsEqualToUTF8CString(messageName, "RunUIProcessScript")) {
    751758        WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
Note: See TracChangeset for help on using the changeset viewer.