Changeset 260642 in webkit


Ignore:
Timestamp:
Apr 24, 2020 7:57:32 AM (4 years ago)
Author:
Chris Dumez
Message:

[iOS] Stop using legacy BKSApplicationStateMonitor
https://bugs.webkit.org/show_bug.cgi?id=210945

Reviewed by Tim Horton.

Source/WebKit:

Stop using legacy BKSApplicationStateMonitor and use RunningBoard API instead.

  • Configurations/WebKit.xcconfig:

Stop linking against ApplicationServices when using iOS 14 SDK now that we are
fully transitioned to RunningBoard.

  • Platform/spi/ios/RunningBoardServicesSPI.h:
  • UIProcess/ApplicationStateTracker.h:
  • UIProcess/ApplicationStateTracker.mm:

(WebKit::ApplicationStateTracker::ApplicationStateTracker):
(WebKit::isApplicationForeground):
(WebKit::ApplicationStateTracker::~ApplicationStateTracker):
(WebKit::isBackgroundState): Deleted.

  • UIProcess/ios/PageClientImplIOS.mm:

(WebKit::PageClientImpl::isApplicationVisible):

WebKitLibraries:

  • WebKitPrivateFrameworkStubs/iOS/13/RunningBoardServices.framework/RunningBoardServices.tbd:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r260614 r260642  
     12020-04-24  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] Stop using legacy BKSApplicationStateMonitor
     4        https://bugs.webkit.org/show_bug.cgi?id=210945
     5
     6        Reviewed by Tim Horton.
     7
     8        Stop using legacy BKSApplicationStateMonitor and use RunningBoard API instead.
     9
     10        * Configurations/WebKit.xcconfig:
     11        Stop linking against ApplicationServices when using iOS 14 SDK now that we are
     12        fully transitioned to RunningBoard.
     13
     14        * Platform/spi/ios/RunningBoardServicesSPI.h:
     15        * UIProcess/ApplicationStateTracker.h:
     16        * UIProcess/ApplicationStateTracker.mm:
     17        (WebKit::ApplicationStateTracker::ApplicationStateTracker):
     18        (WebKit::isApplicationForeground):
     19        (WebKit::ApplicationStateTracker::~ApplicationStateTracker):
     20        (WebKit::isBackgroundState): Deleted.
     21        * UIProcess/ios/PageClientImplIOS.mm:
     22        (WebKit::PageClientImpl::isApplicationVisible):
     23
    1242020-04-23  Simon Fraser  <simon.fraser@apple.com>
    225
  • trunk/Source/WebKit/Configurations/WebKit.xcconfig

    r260581 r260642  
    4949WK_APPKIT_LDFLAGS_maccatalyst = -framework AppKit;
    5050
    51 WK_ASSERTION_SERVICES_LDFLAGS = $(WK_ASSERTION_SERVICES_LDFLAGS_$(WK_COCOA_TOUCH));
    52 WK_ASSERTION_SERVICES_LDFLAGS_cocoatouch = -framework AssertionServices;
     51WK_ASSERTION_SERVICES_LDFLAGS = $(WK_ASSERTION_SERVICES_LDFLAGS_$(WK_PLATFORM_NAME));
     52WK_ASSERTION_SERVICES_LDFLAGS_iphoneos = $(WK_ASSERTION_SERVICES_LDFLAGS$(WK_IOS_14));
     53WK_ASSERTION_SERVICES_LDFLAGS_iphonesimulator = $(WK_ASSERTION_SERVICES_LDFLAGS$(WK_IOS_14));
     54WK_ASSERTION_SERVICES_LDFLAGS_IOS_BEFORE_14 = -framework AssertionServices;
     55// FIXME: It is unnecessary to link against AssertionServices with the latest SDK for the following platforms too.
     56WK_ASSERTION_SERVICES_LDFLAGS_watchos = -framework AssertionServices;
     57WK_ASSERTION_SERVICES_LDFLAGS_watchsimulator = -framework AssertionServices;
     58WK_ASSERTION_SERVICES_LDFLAGS_appletvos = -framework AssertionServices;
     59WK_ASSERTION_SERVICES_LDFLAGS_appletvsimulator = -framework AssertionServices;
     60WK_ASSERTION_SERVICES_LDFLAGS_maccatalyst = -framework AssertionServices;
    5361
    5462WK_RUNNINGBOARD_SERVICES_LDFLAGS = $(WK_RUNNINGBOARD_SERVICES_LDFLAGS_$(WK_COCOA_TOUCH));
  • trunk/Source/WebKit/Platform/spi/ios/RunningBoardServicesSPI.h

    r259610 r260642  
    4343@end
    4444
    45 @protocol RBSAssertionObserving <NSObject>
    46 - (void)assertionWillInvalidate:(RBSAssertion *)assertion;
    47 - (void)assertion:(RBSAssertion *)assertion didInvalidateWithError:(NSError *)error;
    48 @end
     45@protocol RBSAssertionObserving;
    4946
    5047@interface RBSAssertion : NSObject
     
    5653@end
    5754
     55@protocol RBSAssertionObserving <NSObject>
     56- (void)assertionWillInvalidate:(RBSAssertion *)assertion;
     57- (void)assertion:(RBSAssertion *)assertion didInvalidateWithError:(NSError *)error;
     58@end
     59
     60@interface RBSProcessIdentifier : NSObject
     61+ (RBSProcessIdentifier *)identifierWithPid:(pid_t)pid;
     62@end
     63
     64typedef NS_ENUM(uint8_t, RBSTaskState) {
     65    RBSTaskStateUnknown                 = 0,
     66    RBSTaskStateNone                    = 1,
     67    RBSTaskStateRunningUnknown          = 2,
     68    RBSTaskStateRunningSuspended        = 3,
     69    RBSTaskStateRunningScheduled        = 4,
     70};
     71
     72@interface RBSProcessState : NSObject
     73@property (nonatomic, readonly, assign) RBSTaskState taskState;
     74@property (nonatomic, readonly, copy) NSSet<NSString *> *endowmentNamespaces;
     75@end
     76
     77@interface RBSProcessHandle : NSObject
     78+ (RBSProcessHandle *)handleForIdentifier:(RBSProcessIdentifier *)identifier error:(NSError **)outError;
     79@property (nonatomic, readonly, strong) RBSProcessState *currentState;
     80@end
     81
    5882#endif
  • trunk/Source/WebKit/UIProcess/ApplicationStateTracker.h

    r258767 r260642  
    6363    bool m_isInBackground;
    6464
    65     RetainPtr<BKSApplicationStateMonitor> m_applicationStateMonitor;
    66 
    6765    id m_didEnterBackgroundObserver;
    6866    id m_didFinishSnapshottingAfterEnteringBackgroundObserver;
     
    8179
    8280ApplicationType applicationType(UIWindow *);
     81bool isApplicationForeground(pid_t);
    8382
    8483}
  • trunk/Source/WebKit/UIProcess/ApplicationStateTracker.mm

    r258767 r260642  
    3131#import "AssertionServicesSPI.h"
    3232#import "Logging.h"
     33#import "RunningBoardServicesSPI.h"
    3334#import "SandboxUtilities.h"
    3435#import "UIKitSPI.h"
     
    6263
    6364    return ApplicationType::Application;
    64 }
    65 
    66 static bool isBackgroundState(BKSApplicationState state)
    67 {
    68     switch (state) {
    69     case BKSApplicationStateBackgroundRunning:
    70     case BKSApplicationStateBackgroundTaskSuspended:
    71         return true;
    72 
    73     default:
    74         return false;
    75     }
    7665}
    7766
     
    169158        ASSERT(applicationPID);
    170159
    171         auto applicationStateMonitor = adoptNS([[BKSApplicationStateMonitor alloc] init]);
    172         m_isInBackground = isBackgroundState([applicationStateMonitor mostElevatedApplicationStateForPID:applicationPID]);
    173         [applicationStateMonitor invalidate];
     160        m_isInBackground = !isApplicationForeground(applicationPID);
    174161
    175162        // Workaround for <rdar://problem/34028921>. If the host application is StoreKitUIService then it is also a ViewService
     
    195182}
    196183
     184bool isApplicationForeground(pid_t pid)
     185{
     186    RBSProcessIdentifier *processIdentifier = [RBSProcessIdentifier identifierWithPid:pid];
     187    if (!processIdentifier) {
     188        RELEASE_LOG_ERROR(ProcessSuspension, "isApplicationForeground: Failed to construct RBSProcessIdentifier from PID %d", pid);
     189        return false;
     190    }
     191
     192    NSError *error = nil;
     193    RBSProcessHandle *processHandle = [RBSProcessHandle handleForIdentifier:processIdentifier error:&error];
     194    if (!processHandle) {
     195        RELEASE_LOG_ERROR(ProcessSuspension, "isApplicationForeground: Failed to get RBSProcessHandle for process with PID %d, error: %{public}@", pid, error);
     196        return false;
     197    }
     198
     199    RBSProcessState *state = processHandle.currentState;
     200    if (state.taskState != RBSTaskStateRunningScheduled) {
     201        RELEASE_LOG_ERROR(ProcessSuspension, "isApplicationForeground: Process with PID %d is not running", pid);
     202        return false;
     203    }
     204
     205    return [[state endowmentNamespaces] containsObject:@"com.apple.frontboard.visibility"];
     206}
     207
    197208ApplicationStateTracker::~ApplicationStateTracker()
    198209{
    199210    RELEASE_LOG(ViewState, "%p - ~ApplicationStateTracker", this);
    200     if (m_applicationStateMonitor) {
    201         [m_applicationStateMonitor invalidate];
    202         return;
    203     }
    204211
    205212    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
  • trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm

    r260134 r260642  
    3939#import "NativeWebKeyboardEvent.h"
    4040#import "NavigationState.h"
     41#import "RunningBoardServicesSPI.h"
    4142#import "StringUtilities.h"
    4243#import "UIKitSPI.h"
     
    169170    ASSERT(applicationPID);
    170171
    171     auto applicationStateMonitor = adoptNS([[BKSApplicationStateMonitor alloc] init]);
    172     auto applicationState = [applicationStateMonitor mostElevatedApplicationStateForPID:applicationPID];
    173     [applicationStateMonitor invalidate];
    174     return applicationState != BKSApplicationStateBackgroundRunning && applicationState != BKSApplicationStateBackgroundTaskSuspended;
     172    return isApplicationForeground(applicationPID);
    175173}
    176174
  • trunk/WebKitLibraries/ChangeLog

    r258520 r260642  
     12020-04-24  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] Stop using legacy BKSApplicationStateMonitor
     4        https://bugs.webkit.org/show_bug.cgi?id=210945
     5
     6        Reviewed by Tim Horton.
     7
     8        * WebKitPrivateFrameworkStubs/iOS/13/RunningBoardServices.framework/RunningBoardServices.tbd:
     9
    1102020-03-16  Keith Rollin  <krollin@apple.com>
    211
  • trunk/WebKitLibraries/WebKitPrivateFrameworkStubs/iOS/13/RunningBoardServices.framework/RunningBoardServices.tbd

    r258180 r260642  
    66exports:
    77  - archs:           [ x86_64, arm64, arm64e ]
    8     objc-classes:    [ RBSAttribute, RBSDomainAttribute, RBSTarget, RBSAssertion ]
     8    objc-classes:    [ RBSAttribute, RBSDomainAttribute, RBSTarget, RBSAssertion, RBSProcessIdentifier, RBSProcessState, RBSProcessHandle ]
    99...
Note: See TracChangeset for help on using the changeset viewer.