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

Changeset 253357 in webkit


Ignore:
Timestamp:
Dec 10, 2019, 5:35:14 PM (7 years ago)
Author:
pvollan@apple.com
Message:

[iOS] Calls to the device motion API should be done in the UI process
https://bugs.webkit.org/show_bug.cgi?id=204770

Reviewed by Brent Fulgham.

Source/WebCore:

The device motion API on iOS is communicating with iohideventsystem. Since mach lookup to this daemon
will be closed, the calls to this API should be moved from the WebContent process to the UI process.
This patch implements forwarding of the device orientation requests to the UI process through the
class, DeviceOrientationUpdateProvider, which is subclassed by WebDeviceOrientationUpdateProvider in
modern WebKit. This class implements forwarding of the requests to the UI process, and receives
device orientation updates from the UI process. An instance of this class will be shared by all
device orientation clients on a page, and passed as part of the page configuration parameters. On
the UI process side, the class WebDeviceOrientationUpdateProviderProxy attached to the Web page
proxy is taking care of calling the device orientation API through the existing WebCoreMotionManager
Objective-C class, and send device orientation updates back to the Web process. Also, use a weak
hash set of clients in WebDeviceOrientationUpdateProvider.

No new tests, covered by existing tests.

  • dom/Document.cpp:
  • platform/ios/DeviceMotionClientIOS.h:
  • platform/ios/DeviceMotionClientIOS.mm:

(WebCore::DeviceMotionClientIOS::DeviceMotionClientIOS):
(WebCore::DeviceMotionClientIOS::startUpdating):
(WebCore::DeviceMotionClientIOS::stopUpdating):
(WebCore::DeviceMotionClientIOS::deviceMotionControllerDestroyed):

  • platform/ios/DeviceOrientationClientIOS.mm:

(WebCore::DeviceOrientationClientIOS::startUpdating):
(WebCore::DeviceOrientationClientIOS::stopUpdating):
(WebCore::DeviceOrientationClientIOS::deviceOrientationControllerDestroyed):

  • platform/ios/DeviceOrientationUpdateProvider.h:
  • platform/ios/MotionManagerClient.h:

(WebCore::MotionManagerClient::orientationChanged):
(WebCore::MotionManagerClient::motionChanged):

  • platform/ios/WebCoreMotionManager.h:
  • platform/ios/WebCoreMotionManager.mm:

(-[WebCoreMotionManager addMotionClient:]):
(-[WebCoreMotionManager removeMotionClient:]):
(-[WebCoreMotionManager checkClientStatus]):
(-[WebCoreMotionManager sendAccelerometerData:]):
(-[WebCoreMotionManager sendMotionData:withHeading:]):

Source/WebKit:

The class WebDeviceOrientationUpdateProviderProxy will handle messages to start and stop updating device motion
in the UI process. Also, add a message to update the device motion in the WebContent process. In the UI process,
the device motion API is called through the already existing WebCoreMotionManager class.

  • Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
  • UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.h:
  • UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.messages.in:
  • UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.mm:

(WebKit::WebDeviceOrientationUpdateProviderProxy::startUpdatingDeviceMotion):
(WebKit::WebDeviceOrientationUpdateProviderProxy::stopUpdatingDeviceMotion):
(WebKit::WebDeviceOrientationUpdateProviderProxy::motionChanged):

  • WebProcess/WebCoreSupport/WebDeviceOrientationUpdateProvider.cpp:

(WebKit::WebDeviceOrientationUpdateProvider::startUpdatingDeviceOrientation):
(WebKit::WebDeviceOrientationUpdateProvider::stopUpdatingDeviceOrientation):
(WebKit::WebDeviceOrientationUpdateProvider::startUpdatingDeviceMotion):
(WebKit::WebDeviceOrientationUpdateProvider::stopUpdatingDeviceMotion):
(WebKit::WebDeviceOrientationUpdateProvider::deviceOrientationChanged):
(WebKit::WebDeviceOrientationUpdateProvider::deviceMotionChanged):
(WebKit::WebDeviceOrientationUpdateProvider::startUpdating): Deleted.
(WebKit::WebDeviceOrientationUpdateProvider::stopUpdating): Deleted.

  • WebProcess/WebCoreSupport/WebDeviceOrientationUpdateProvider.h:
  • WebProcess/WebCoreSupport/WebDeviceOrientationUpdateProvider.messages.in:
Location:
trunk/Source
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r253353 r253357  
     12019-12-10  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [iOS] Calls to the device motion API should be done in the UI process
     4        https://bugs.webkit.org/show_bug.cgi?id=204770
     5
     6        Reviewed by Brent Fulgham.
     7
     8        The device motion API on iOS is communicating with iohideventsystem. Since mach lookup to this daemon
     9        will be closed, the calls to this API should be moved from the WebContent process to the UI process.
     10        This patch implements forwarding of the device orientation requests to the UI process through the
     11        class, DeviceOrientationUpdateProvider, which is subclassed by WebDeviceOrientationUpdateProvider in
     12        modern WebKit. This class implements forwarding of the requests to the UI process, and receives
     13        device orientation updates from the UI process. An instance of this class will be shared by all
     14        device orientation clients on a page, and passed as part of the page configuration parameters. On
     15        the UI process side, the class WebDeviceOrientationUpdateProviderProxy attached to the Web page
     16        proxy is taking care of calling the device orientation API through the existing WebCoreMotionManager
     17        Objective-C class, and send device orientation updates back to the Web process. Also, use a weak
     18        hash set of clients in WebDeviceOrientationUpdateProvider.
     19
     20        No new tests, covered by existing tests.
     21
     22        * dom/Document.cpp:
     23        * platform/ios/DeviceMotionClientIOS.h:
     24        * platform/ios/DeviceMotionClientIOS.mm:
     25        (WebCore::DeviceMotionClientIOS::DeviceMotionClientIOS):
     26        (WebCore::DeviceMotionClientIOS::startUpdating):
     27        (WebCore::DeviceMotionClientIOS::stopUpdating):
     28        (WebCore::DeviceMotionClientIOS::deviceMotionControllerDestroyed):
     29        * platform/ios/DeviceOrientationClientIOS.mm:
     30        (WebCore::DeviceOrientationClientIOS::startUpdating):
     31        (WebCore::DeviceOrientationClientIOS::stopUpdating):
     32        (WebCore::DeviceOrientationClientIOS::deviceOrientationControllerDestroyed):
     33        * platform/ios/DeviceOrientationUpdateProvider.h:
     34        * platform/ios/MotionManagerClient.h:
     35        (WebCore::MotionManagerClient::orientationChanged):
     36        (WebCore::MotionManagerClient::motionChanged):
     37        * platform/ios/WebCoreMotionManager.h:
     38        * platform/ios/WebCoreMotionManager.mm:
     39        (-[WebCoreMotionManager addMotionClient:]):
     40        (-[WebCoreMotionManager removeMotionClient:]):
     41        (-[WebCoreMotionManager checkClientStatus]):
     42        (-[WebCoreMotionManager sendAccelerometerData:]):
     43        (-[WebCoreMotionManager sendMotionData:withHeading:]):
     44
    1452019-12-10  Per Arne Vollan  <pvollan@apple.com>
    246
  • trunk/Source/WebCore/dom/Document.cpp

    r253308 r253357  
    564564    , m_loadEventDelayTimer(*this, &Document::loadEventDelayTimerFired)
    565565#if PLATFORM(IOS_FAMILY) && ENABLE(DEVICE_ORIENTATION)
    566     , m_deviceMotionClient(makeUnique<DeviceMotionClientIOS>())
     566    , m_deviceMotionClient(makeUnique<DeviceMotionClientIOS>(page() ? page()->deviceOrientationUpdateProvider() : nullptr))
    567567    , m_deviceMotionController(makeUnique<DeviceMotionController>(*m_deviceMotionClient))
    568568    , m_deviceOrientationClient(makeUnique<DeviceOrientationClientIOS>(page() ? page()->deviceOrientationUpdateProvider() : nullptr))
  • trunk/Source/WebCore/platform/ios/DeviceMotionClientIOS.h

    r237266 r253357  
    3131#include "DeviceMotionController.h"
    3232#include "DeviceMotionData.h"
     33#include "DeviceOrientationUpdateProvider.h"
     34#include "MotionManagerClient.h"
    3335#include <wtf/RefPtr.h>
    3436
     
    3739namespace WebCore {
    3840
    39 class DeviceMotionClientIOS : public DeviceMotionClient {
     41class DeviceMotionClientIOS : public DeviceMotionClient, public MotionManagerClient {
    4042public:
    41     DeviceMotionClientIOS();
     43    DeviceMotionClientIOS(RefPtr<DeviceOrientationUpdateProvider>&&);
    4244    ~DeviceMotionClientIOS() override;
    4345    void setController(DeviceMotionController*) override;
     
    4749    void deviceMotionControllerDestroyed() override;
    4850
    49     void motionChanged(double, double, double, double, double, double, double, double, double);
     51    void motionChanged(double, double, double, double, double, double, double, double, double) override;
    5052
    5153private:
    52     WebCoreMotionManager* m_motionManager;
    53     DeviceMotionController* m_controller;
     54    WebCoreMotionManager* m_motionManager { nullptr };
     55    DeviceMotionController* m_controller { nullptr };
    5456    RefPtr<DeviceMotionData> m_currentDeviceMotionData;
    55     bool m_updating;
     57    RefPtr<DeviceOrientationUpdateProvider> m_deviceOrientationUpdateProvider;
     58    bool m_updating { false };
    5659};
    5760
  • trunk/Source/WebCore/platform/ios/DeviceMotionClientIOS.mm

    r237266 r253357  
    3434namespace WebCore {
    3535
    36 DeviceMotionClientIOS::DeviceMotionClientIOS()
     36DeviceMotionClientIOS::DeviceMotionClientIOS(RefPtr<DeviceOrientationUpdateProvider>&& deviceOrientationUpdateProvider)
    3737    : DeviceMotionClient()
    38     , m_motionManager(nullptr)
    39     , m_updating(0)
     38    , m_deviceOrientationUpdateProvider(WTFMove(deviceOrientationUpdateProvider))
    4039{
    4140}
     
    5453    m_updating = true;
    5554
     55    if (m_deviceOrientationUpdateProvider) {
     56        m_deviceOrientationUpdateProvider->startUpdatingDeviceMotion(*this);
     57        return;
     58    }
     59
    5660    if (!m_motionManager)
    5761        m_motionManager = [WebCoreMotionManager sharedManager];
     
    6367{
    6468    m_updating = false;
     69
     70    if (m_deviceOrientationUpdateProvider) {
     71        m_deviceOrientationUpdateProvider->stopUpdatingDeviceMotion(*this);
     72        return;
     73    }
    6574
    6675    // Remove ourselves as the motion client so we won't get updates.
     
    7584void DeviceMotionClientIOS::deviceMotionControllerDestroyed()
    7685{
     86    if (m_deviceOrientationUpdateProvider) {
     87        m_deviceOrientationUpdateProvider->stopUpdatingDeviceMotion(*this);
     88        return;
     89    }
     90
    7791    [m_motionManager removeMotionClient:this];
    7892}
  • trunk/Source/WebCore/platform/ios/DeviceOrientationClientIOS.mm

    r253231 r253357  
    5454
    5555    if (m_deviceOrientationUpdateProvider) {
    56         m_deviceOrientationUpdateProvider->startUpdating(*this);
     56        m_deviceOrientationUpdateProvider->startUpdatingDeviceOrientation(*this);
    5757        return;
    5858    }
     
    6969
    7070    if (m_deviceOrientationUpdateProvider) {
    71         m_deviceOrientationUpdateProvider->stopUpdating(*this);
     71        m_deviceOrientationUpdateProvider->stopUpdatingDeviceOrientation(*this);
    7272        return;
    7373    }
     
    8585{
    8686    if (m_deviceOrientationUpdateProvider) {
    87         m_deviceOrientationUpdateProvider->stopUpdating(*this);
     87        m_deviceOrientationUpdateProvider->stopUpdatingDeviceOrientation(*this);
    8888        return;
    8989    }
  • trunk/Source/WebCore/platform/ios/DeviceOrientationUpdateProvider.h

    r253231 r253357  
    3838    virtual ~DeviceOrientationUpdateProvider() { }
    3939
    40     virtual void startUpdating(MotionManagerClient&) = 0;
    41     virtual void stopUpdating(MotionManagerClient&) = 0;
     40    virtual void startUpdatingDeviceOrientation(MotionManagerClient&) = 0;
     41    virtual void stopUpdatingDeviceOrientation(MotionManagerClient&) = 0;
     42
     43    virtual void startUpdatingDeviceMotion(MotionManagerClient&) = 0;
     44    virtual void stopUpdatingDeviceMotion(MotionManagerClient&) = 0;
    4245
    4346    virtual void deviceOrientationChanged(double, double, double, double, double) = 0;
     47    virtual void deviceMotionChanged(double, double, double, double, double, double, double, double, double) = 0;
    4448   
    4549protected:
  • trunk/Source/WebCore/platform/ios/MotionManagerClient.h

    r253231 r253357  
    3636    virtual ~MotionManagerClient() { };
    3737
    38     virtual void orientationChanged(double, double, double, double, double) = 0;
     38    virtual void orientationChanged(double, double, double, double, double) { }
     39    virtual void motionChanged(double, double, double, double, double, double, double, double, double) { }
    3940};
    4041
  • trunk/Source/WebCore/platform/ios/WebCoreMotionManager.h

    r253231 r253357  
    4444    CMMotionManager* m_motionManager;
    4545    CLLocationManager* m_locationManager;
    46     HashSet<WebCore::DeviceMotionClientIOS*> m_deviceMotionClients;
     46    WeakHashSet<WebCore::MotionManagerClient> m_deviceMotionClients;
    4747    WeakHashSet<WebCore::MotionManagerClient> m_deviceOrientationClients;
    4848    NSTimer* m_updateTimer;
     
    5353
    5454+ (WebCoreMotionManager *)sharedManager;
    55 - (void)addMotionClient:(WebCore::DeviceMotionClientIOS *)client;
    56 - (void)removeMotionClient:(WebCore::DeviceMotionClientIOS *)client;
     55- (void)addMotionClient:(WebCore::MotionManagerClient *)client;
     56- (void)removeMotionClient:(WebCore::MotionManagerClient *)client;
    5757- (void)addOrientationClient:(WebCore::MotionManagerClient *)client;
    5858- (void)removeOrientationClient:(WebCore::MotionManagerClient *)client;
  • trunk/Source/WebCore/platform/ios/WebCoreMotionManager.mm

    r253296 r253357  
    101101}
    102102
    103 - (void)addMotionClient:(WebCore::DeviceMotionClientIOS *)client
    104 {
    105     m_deviceMotionClients.add(client);
     103- (void)addMotionClient:(WebCore::MotionManagerClient *)client
     104{
     105    m_deviceMotionClients.add(*client);
    106106    if (m_initialized)
    107107        [self checkClientStatus];
    108108}
    109109
    110 - (void)removeMotionClient:(WebCore::DeviceMotionClientIOS *)client
    111 {
    112     m_deviceMotionClients.remove(client);
     110- (void)removeMotionClient:(WebCore::MotionManagerClient *)client
     111{
     112    m_deviceMotionClients.remove(*client);
    113113    if (m_initialized)
    114114        [self checkClientStatus];
     
    172172    ASSERT(m_motionManager);
    173173
    174     if (m_deviceMotionClients.size() || m_deviceOrientationClients.computeSize()) {
     174    if (m_deviceMotionClients.computeSize() || m_deviceOrientationClients.computeSize()) {
    175175        if (m_gyroAvailable)
    176176            [m_motionManager startDeviceMotionUpdates];
     
    226226        CMAcceleration accel = newAcceleration.acceleration;
    227227
    228         for (auto& client : copyToVector(m_deviceMotionClients))
    229             client->motionChanged(0, 0, 0, accel.x * kGravity, accel.y * kGravity, accel.z * kGravity, 0, 0, 0);
     228        Vector<WeakPtr<WebCore::MotionManagerClient>> motionClients;
     229        motionClients.reserveInitialCapacity(m_deviceMotionClients.computeSize());
     230        for (auto& client : m_deviceMotionClients)
     231            motionClients.uncheckedAppend(makeWeakPtr(&client));
     232
     233        for (auto& client : motionClients) {
     234            if (client)
     235                client->motionChanged(0, 0, 0, accel.x * kGravity, accel.y * kGravity, accel.z * kGravity, 0, 0, 0);
     236        }
    230237    });
    231238}
     
    244251        CMRotationRate rotationRate = newMotion.rotationRate;
    245252
    246         for (auto& client : copyToVector(m_deviceMotionClients))
    247             client->motionChanged(userAccel.x * kGravity, userAccel.y * kGravity, userAccel.z * kGravity, totalAccel.x * kGravity, totalAccel.y * kGravity, totalAccel.z * kGravity, rad2deg(rotationRate.x), rad2deg(rotationRate.y), rad2deg(rotationRate.z));
     253        Vector<WeakPtr<WebCore::MotionManagerClient>> motionClients;
     254        motionClients.reserveInitialCapacity(m_deviceMotionClients.computeSize());
     255        for (auto& client : m_deviceMotionClients)
     256            motionClients.uncheckedAppend(makeWeakPtr(&client));
     257       
     258        for (auto& client : motionClients) {
     259            if (client)
     260                client->motionChanged(userAccel.x * kGravity, userAccel.y * kGravity, userAccel.z * kGravity, totalAccel.x * kGravity, totalAccel.y * kGravity, totalAccel.z * kGravity, rad2deg(rotationRate.x), rad2deg(rotationRate.y), rad2deg(rotationRate.z));
     261        }
    248262
    249263        CMAttitude* attitude = newMotion.attitude;
  • trunk/Source/WebKit/ChangeLog

    r253354 r253357  
     12019-12-10  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [iOS] Calls to the device motion API should be done in the UI process
     4        https://bugs.webkit.org/show_bug.cgi?id=204770
     5
     6        Reviewed by Brent Fulgham.
     7
     8        The class WebDeviceOrientationUpdateProviderProxy will handle messages to start and stop updating device motion
     9        in the UI process. Also, add a message to update the device motion in the WebContent process. In the UI process,
     10        the device motion API is called through the already existing WebCoreMotionManager class.
     11
     12        * Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
     13        * UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.h:
     14        * UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.messages.in:
     15        * UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.mm:
     16        (WebKit::WebDeviceOrientationUpdateProviderProxy::startUpdatingDeviceMotion):
     17        (WebKit::WebDeviceOrientationUpdateProviderProxy::stopUpdatingDeviceMotion):
     18        (WebKit::WebDeviceOrientationUpdateProviderProxy::motionChanged):
     19        * WebProcess/WebCoreSupport/WebDeviceOrientationUpdateProvider.cpp:
     20        (WebKit::WebDeviceOrientationUpdateProvider::startUpdatingDeviceOrientation):
     21        (WebKit::WebDeviceOrientationUpdateProvider::stopUpdatingDeviceOrientation):
     22        (WebKit::WebDeviceOrientationUpdateProvider::startUpdatingDeviceMotion):
     23        (WebKit::WebDeviceOrientationUpdateProvider::stopUpdatingDeviceMotion):
     24        (WebKit::WebDeviceOrientationUpdateProvider::deviceOrientationChanged):
     25        (WebKit::WebDeviceOrientationUpdateProvider::deviceMotionChanged):
     26        (WebKit::WebDeviceOrientationUpdateProvider::startUpdating): Deleted.
     27        (WebKit::WebDeviceOrientationUpdateProvider::stopUpdating): Deleted.
     28        * WebProcess/WebCoreSupport/WebDeviceOrientationUpdateProvider.h:
     29        * WebProcess/WebCoreSupport/WebDeviceOrientationUpdateProvider.messages.in:
     30
    1312019-12-10  Chris Dumez  <cdumez@apple.com>
    232
  • trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb

    r253351 r253357  
    113113
    114114(define-once (location-services)
    115     (allow mach-lookup
     115    (allow mach-lookup (with report) (with telemetry)
    116116           (global-name "com.apple.locationd.registration"))
    117117    (allow-carrier-bundle) ;; <rdar://problem/21192365>
  • trunk/Source/WebKit/UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.h

    r253256 r253357  
    4343    void startUpdatingDeviceOrientation();
    4444    void stopUpdatingDeviceOrientation();
    45    
     45
     46    void startUpdatingDeviceMotion();
     47    void stopUpdatingDeviceMotion();
     48
    4649private:
    4750    // WebCore::WebCoreMotionManagerClient
    4851    void orientationChanged(double, double, double, double, double) final;
    49    
     52    void motionChanged(double, double, double, double, double, double, double, double, double) final;
     53
    5054    // IPC::MessageReceiver
    5155    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
  • trunk/Source/WebKit/UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.messages.in

    r253231 r253357  
    2525    StartUpdatingDeviceOrientation();
    2626    StopUpdatingDeviceOrientation();
     27    StartUpdatingDeviceMotion();
     28    StopUpdatingDeviceMotion();
    2729}
    2830#endif
  • trunk/Source/WebKit/UIProcess/ios/WebDeviceOrientationUpdateProviderProxy.mm

    r253231 r253357  
    5858}
    5959
     60void WebDeviceOrientationUpdateProviderProxy::startUpdatingDeviceMotion()
     61{
     62    [[WebCoreMotionManager sharedManager] addMotionClient:this];
     63}
     64
     65void WebDeviceOrientationUpdateProviderProxy::stopUpdatingDeviceMotion()
     66{
     67    [[WebCoreMotionManager sharedManager] removeMotionClient:this];
     68}
     69
    6070void WebDeviceOrientationUpdateProviderProxy::orientationChanged(double alpha, double beta, double gamma, double compassHeading, double compassAccuracy)
    6171{
     
    6373}
    6474
     75void WebDeviceOrientationUpdateProviderProxy::motionChanged(double xAcceleration, double yAcceleration, double zAcceleration, double xAccelerationIncludingGravity, double yAccelerationIncludingGravity, double zAccelerationIncludingGravity, double xRotationRate, double yRotationRate, double zRotationRate)
     76{
     77    m_page.send(Messages::WebDeviceOrientationUpdateProvider::DeviceMotionChanged(xAcceleration, yAcceleration, zAcceleration, xAccelerationIncludingGravity, yAccelerationIncludingGravity, zAccelerationIncludingGravity, xRotationRate, yRotationRate, zRotationRate));
     78}
     79
    6580} // namespace WebKit
    6681
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebDeviceOrientationUpdateProvider.cpp

    r253256 r253357  
    5050}
    5151
    52 void WebDeviceOrientationUpdateProvider::startUpdating(WebCore::MotionManagerClient& client)
     52void WebDeviceOrientationUpdateProvider::startUpdatingDeviceOrientation(WebCore::MotionManagerClient& client)
    5353{
    54     if (m_clients.isEmpty() && m_page)
     54    if (m_deviceOrientationClients.computesEmpty() && m_page)
    5555        m_page->send(Messages::WebDeviceOrientationUpdateProviderProxy::StartUpdatingDeviceOrientation());
    56     m_clients.add(&client);
     56    m_deviceOrientationClients.add(client);
    5757}
    5858
    59 void WebDeviceOrientationUpdateProvider::stopUpdating(WebCore::MotionManagerClient& client)
     59void WebDeviceOrientationUpdateProvider::stopUpdatingDeviceOrientation(WebCore::MotionManagerClient& client)
    6060{
    61     if (m_clients.isEmpty())
     61    if (m_deviceOrientationClients.computesEmpty())
    6262        return;
    63     m_clients.remove(&client);
    64     if (m_clients.isEmpty() && m_page)
     63    m_deviceOrientationClients.remove(client);
     64    if (m_deviceOrientationClients.computesEmpty() && m_page)
    6565        m_page->send(Messages::WebDeviceOrientationUpdateProviderProxy::StopUpdatingDeviceOrientation());
     66}
     67
     68void WebDeviceOrientationUpdateProvider::startUpdatingDeviceMotion(WebCore::MotionManagerClient& client)
     69{
     70    if (m_deviceMotionClients.computesEmpty() && m_page)
     71        m_page->send(Messages::WebDeviceOrientationUpdateProviderProxy::StartUpdatingDeviceMotion());
     72    m_deviceMotionClients.add(client);
     73}
     74
     75void WebDeviceOrientationUpdateProvider::stopUpdatingDeviceMotion(WebCore::MotionManagerClient& client)
     76{
     77    if (m_deviceMotionClients.computesEmpty())
     78        return;
     79    m_deviceMotionClients.remove(client);
     80    if (m_deviceMotionClients.computesEmpty() && m_page)
     81        m_page->send(Messages::WebDeviceOrientationUpdateProviderProxy::StopUpdatingDeviceMotion());
    6682}
    6783
    6884void WebDeviceOrientationUpdateProvider::deviceOrientationChanged(double alpha, double beta, double gamma, double compassHeading, double compassAccuracy)
    6985{
    70     for (auto* client : copyToVector(m_clients))
    71         client->orientationChanged(alpha, beta, gamma, compassHeading, compassAccuracy);
     86    Vector<WeakPtr<WebCore::MotionManagerClient>> clients;
     87    for (auto& client : m_deviceOrientationClients)
     88        clients.append(makeWeakPtr(&client));
     89
     90    for (auto& client : clients) {
     91        if (client)
     92            client->orientationChanged(alpha, beta, gamma, compassHeading, compassAccuracy);
     93    }
     94}
     95
     96void WebDeviceOrientationUpdateProvider::deviceMotionChanged(double xAcceleration, double yAcceleration, double zAcceleration, double xAccelerationIncludingGravity, double yAccelerationIncludingGravity, double zAccelerationIncludingGravity, double xRotationRate, double yRotationRate, double zRotationRate)
     97{
     98    Vector<WeakPtr<WebCore::MotionManagerClient>> clients;
     99    for (auto& client : m_deviceMotionClients)
     100        clients.append(makeWeakPtr(&client));
     101   
     102    for (auto& client : clients) {
     103        if (client)
     104            client->motionChanged(xAcceleration, yAcceleration, zAcceleration, xAccelerationIncludingGravity, yAccelerationIncludingGravity,  zAccelerationIncludingGravity, xRotationRate, yRotationRate, zRotationRate);
     105    }
    72106}
    73107
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebDeviceOrientationUpdateProvider.h

    r253256 r253357  
    3131#include <WebCore/DeviceOrientationUpdateProvider.h>
    3232
    33 #include <wtf/HashSet.h>
     33#include <wtf/WeakHashSet.h>
    3434#include <wtf/WeakPtr.h>
    3535
     
    4747
    4848    // WebCore::DeviceOrientationUpdateProvider
    49     void startUpdating(WebCore::MotionManagerClient&) final;
    50     void stopUpdating(WebCore::MotionManagerClient&) final;
     49    void startUpdatingDeviceOrientation(WebCore::MotionManagerClient&) final;
     50    void stopUpdatingDeviceOrientation(WebCore::MotionManagerClient&) final;
     51    void startUpdatingDeviceMotion(WebCore::MotionManagerClient&) final;
     52    void stopUpdatingDeviceMotion(WebCore::MotionManagerClient&) final;
    5153    void deviceOrientationChanged(double, double, double, double, double) final;
     54    void deviceMotionChanged(double, double, double, double, double, double, double, double, double) final;
    5255
    5356    // IPC::MessageReceiver.
     
    5659    WeakPtr<WebPage> m_page;
    5760    WebCore::PageIdentifier m_pageIdentifier;
    58     HashSet<WebCore::MotionManagerClient*> m_clients;
     61    WeakHashSet<WebCore::MotionManagerClient> m_deviceOrientationClients;
     62    WeakHashSet<WebCore::MotionManagerClient> m_deviceMotionClients;
    5963};
    6064
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebDeviceOrientationUpdateProvider.messages.in

    r253231 r253357  
    2424messages -> WebDeviceOrientationUpdateProvider {
    2525    DeviceOrientationChanged(double alpha, double beta, double gamma, double compassHeading, double compassAccuracy)
     26    DeviceMotionChanged(double xAcceleration, double yAcceleration, double zAcceleration, double xAccelerationIncludingGravity, double yAccelerationIncludingGravity, double zAccelerationIncludingGravity, double xRotationRate, double yRotationRate, double zRotationRate)
    2627}
    2728#endif
Note: See TracChangeset for help on using the changeset viewer.