Changeset 166101 in webkit


Ignore:
Timestamp:
Mar 21, 2014 3:21:29 PM (10 years ago)
Author:
eric.carlson@apple.com
Message:

[iOS] remote command callbacks must happen on the WebThread
https://bugs.webkit.org/show_bug.cgi?id=130618

Reviewed by Jer Noble.

  • platform/ios/RemoteCommandListenerIOS.h:

(WebCore::RemoteCommandListenerIOS::createWeakPtr):

  • platform/ios/RemoteCommandListenerIOS.mm:

(WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): Dispatch commands to the

main thread before making listener callbacks.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r166100 r166101  
     12014-03-21  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [iOS] remote command callbacks must happen on the WebThread
     4        https://bugs.webkit.org/show_bug.cgi?id=130618
     5
     6        Reviewed by Jer Noble.
     7
     8        * platform/ios/RemoteCommandListenerIOS.h:
     9        (WebCore::RemoteCommandListenerIOS::createWeakPtr):
     10        * platform/ios/RemoteCommandListenerIOS.mm:
     11        (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): Dispatch commands to the
     12            main thread before making listener callbacks.
     13
    1142014-03-21  Zalan Bujtas  <zalan@apple.com>
    215
  • trunk/Source/WebCore/platform/ios/RemoteCommandListenerIOS.h

    r165676 r166101  
    3232
    3333#include <wtf/RetainPtr.h>
     34#include <wtf/WeakPtr.h>
    3435
    3536#ifndef __OBJC__
     
    4546
    4647protected:
     48    WeakPtr<RemoteCommandListenerIOS> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
     49   
     50    WeakPtrFactory<RemoteCommandListenerIOS> m_weakPtrFactory;
    4751    RetainPtr<id> m_playTarget;
    4852    RetainPtr<id> m_pauseTarget;
  • trunk/Source/WebCore/platform/ios/RemoteCommandListenerIOS.mm

    r165676 r166101  
    4747RemoteCommandListenerIOS::RemoteCommandListenerIOS(RemoteCommandListenerClient& client)
    4848    : RemoteCommandListener(client)
     49    , m_weakPtrFactory(this)
    4950{
    5051    MPRemoteCommandCenter *center = [getMPRemoteCommandCenterClass() sharedCommandCenter];
     52    auto weakThis = createWeakPtr();
     53   
     54    m_pauseTarget = [[center pauseCommand] addTargetWithHandler:^(MPRemoteCommandEvent *) {
     55        callOnMainThread([weakThis] {
     56            if (!weakThis)
     57                return;
     58            weakThis->m_client.didReceiveRemoteControlCommand(MediaSession::PauseCommand);
     59        });
    5160
    52     m_pauseTarget = [[center pauseCommand] addTargetWithHandler:^(MPRemoteCommandEvent *) {
    53         m_client.didReceiveRemoteControlCommand(MediaSession::PauseCommand);
    5461        return MPRemoteCommandHandlerStatusSuccess;
    5562    }];
     63
    5664    m_playTarget = [[center playCommand] addTargetWithHandler:^(MPRemoteCommandEvent *) {
    57         m_client.didReceiveRemoteControlCommand(MediaSession::PlayCommand);
     65        callOnMainThread([weakThis] {
     66            if (!weakThis)
     67                return;
     68            weakThis->m_client.didReceiveRemoteControlCommand(MediaSession::PlayCommand);
     69        });
     70
    5871        return MPRemoteCommandHandlerStatusSuccess;
    5972    }];
     73
    6074    m_togglePlayPauseTarget = [[center togglePlayPauseCommand] addTargetWithHandler:^(MPRemoteCommandEvent *) {
    61         m_client.didReceiveRemoteControlCommand(MediaSession::TogglePlayPauseCommand);
     75        callOnMainThread([weakThis] {
     76            if (!weakThis)
     77                return;
     78            weakThis->m_client.didReceiveRemoteControlCommand(MediaSession::TogglePlayPauseCommand);
     79        });
     80
    6281        return MPRemoteCommandHandlerStatusSuccess;
    6382    }];
     83
    6484    m_seekBackwardTarget = [[center seekBackwardCommand] addTargetWithHandler:^(MPRemoteCommandEvent *event) {
    6585        ASSERT([event isKindOfClass:getMPSeekCommandEventClass()]);
     86
    6687        MPSeekCommandEvent* seekEvent = static_cast<MPSeekCommandEvent *>(event);
    67         m_client.didReceiveRemoteControlCommand([seekEvent type] == MPSeekCommandEventTypeBeginSeeking ? MediaSession::BeginSeekingBackwardCommand : MediaSession::EndSeekingBackwardCommand);
     88        MediaSession::RemoteControlCommandType command = [seekEvent type] == MPSeekCommandEventTypeBeginSeeking ? MediaSession::BeginSeekingBackwardCommand : MediaSession::EndSeekingBackwardCommand;
     89
     90        callOnMainThread([weakThis, command] {
     91            if (!weakThis)
     92                return;
     93            weakThis->m_client.didReceiveRemoteControlCommand(command);
     94        });
     95
    6896        return MPRemoteCommandHandlerStatusSuccess;
    6997    }];
     98   
    7099    m_seekForwardTarget = [[center seekForwardCommand] addTargetWithHandler:^(MPRemoteCommandEvent *event) {
    71100        ASSERT([event isKindOfClass:getMPSeekCommandEventClass()]);
    72101        MPSeekCommandEvent* seekEvent = static_cast<MPSeekCommandEvent *>(event);
    73         m_client.didReceiveRemoteControlCommand([seekEvent type] == MPSeekCommandEventTypeBeginSeeking ? MediaSession::BeginSeekingForwardCommand : MediaSession::EndSeekingForwardCommand);
     102
     103        MediaSession::RemoteControlCommandType command = [seekEvent type] == MPSeekCommandEventTypeBeginSeeking ? MediaSession::BeginSeekingForwardCommand : MediaSession::EndSeekingForwardCommand;
     104
     105        callOnMainThread([weakThis, command] {
     106            if (!weakThis)
     107                return;
     108            weakThis->m_client.didReceiveRemoteControlCommand(command);
     109        });
     110
    74111        return MPRemoteCommandHandlerStatusSuccess;
    75112    }];
Note: See TracChangeset for help on using the changeset viewer.