Changeset 245327 in webkit


Ignore:
Timestamp:
May 15, 2019 9:35:58 AM (5 years ago)
Author:
youenn@apple.com
Message:

Constant crashes under WebPage::isThrottleable() after r245299
https://bugs.webkit.org/show_bug.cgi?id=197902
<rdar://problem/50793796>

Reviewed by Alex Christensen.

Source/WebKit:

Update throttle state after a run loop iteration when page state changes to make sure the pageMap does not have null pages.
Add appNapEnabled preference that is used by added API test.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::updateThrottleState):

  • UIProcess/API/Cocoa/WKPreferences.mm:

(-[WKPreferences _setAppNapEnabled:]):
(-[WKPreferences _appNapEnabled]):

  • UIProcess/API/Cocoa/WKPreferencesPrivate.h:

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r245322 r245327  
     12019-05-15  Youenn Fablet  <youenn@apple.com>
     2
     3        Constant crashes under WebPage::isThrottleable() after r245299
     4        https://bugs.webkit.org/show_bug.cgi?id=197902
     5        <rdar://problem/50793796>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Update throttle state after a run loop iteration when page state changes to make sure the pageMap does not have null pages.
     10        Add appNapEnabled preference that is used by added API test.
     11
     12        * WebProcess/WebPage/WebPage.cpp:
     13        (WebKit::WebPage::updateThrottleState):
     14        * UIProcess/API/Cocoa/WKPreferences.mm:
     15        (-[WKPreferences _setAppNapEnabled:]):
     16        (-[WKPreferences _appNapEnabled]):
     17        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
     18
    1192019-05-15  Alex Christensen  <achristensen@webkit.org>
    220
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm

    r244465 r245327  
    12661266}
    12671267
     1268- (void)_setAppNapEnabled:(BOOL)enabled
     1269{
     1270    _preferences->setPageVisibilityBasedProcessSuppressionEnabled(enabled);
     1271}
     1272
     1273- (BOOL)_appNapEnabled
     1274{
     1275    return _preferences->pageVisibilityBasedProcessSuppressionEnabled();
     1276}
     1277
    12681278#endif // PLATFORM(MAC)
    12691279
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h

    r245294 r245327  
    201201@property (nonatomic, setter=_setWebAudioEnabled:) BOOL _webAudioEnabled WK_API_AVAILABLE(macos(10.14));
    202202@property (nonatomic, setter=_setAggressiveTileRetentionEnabled:) BOOL _aggressiveTileRetentionEnabled WK_API_AVAILABLE(macos(10.14));
     203@property (nonatomic, setter=_setAppNapEnabled:) BOOL _appNapEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA));
    203204#endif
    204205
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r245299 r245327  
    777777
    778778#if ENABLE(SERVICE_WORKER)
    779     if (auto* connection = ServiceWorkerProvider::singleton().existingServiceWorkerConnectionForSession(sessionID())) {
    780         if (isThrottleable != connection->isThrottleable())
    781             connection->updateThrottleState();
    782     }
     779    RunLoop::main().dispatch([isThrottleable, sessionID = sessionID()] {
     780        if (auto* connection = ServiceWorkerProvider::singleton().existingServiceWorkerConnectionForSession(sessionID)) {
     781            if (isThrottleable != connection->isThrottleable())
     782                connection->updateThrottleState();
     783        }
     784    });
    783785#endif
    784786}
  • trunk/Tools/ChangeLog

    r245324 r245327  
     12019-05-15  Youenn Fablet  <youenn@apple.com>
     2
     3        Constant crashes under WebPage::isThrottleable() after r245299
     4        https://bugs.webkit.org/show_bug.cgi?id=197902
     5        <rdar://problem/50793796>
     6
     7        Reviewed by Alex Christensen.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
     10
    1112019-05-15  Philippe Normand  <pnormand@igalia.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm

    r245200 r245327  
    2828#import "PlatformUtilities.h"
    2929#import "Test.h"
     30#import "TestNavigationDelegate.h"
     31#import "TestWKWebView.h"
    3032#import <WebKit/WKPreferencesPrivate.h>
    3133#import <WebKit/WKProcessPoolPrivate.h>
     
    5355
    5456static bool done;
     57static bool didFinishNavigation;
    5558
    5659static String expectedMessage;
     
    16201623}
    16211624
     1625TEST(ServiceWorkers, ThrottleCrash)
     1626{
     1627    ASSERT(mainBytes);
     1628    ASSERT(scriptBytes);
     1629
     1630    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
     1631
     1632    // Start with a clean slate data store
     1633    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
     1634        done = true;
     1635    }];
     1636    TestWebKitAPI::Util::run(&done);
     1637    done = false;
     1638
     1639    auto messageHandler = adoptNS([[SWMessageHandler alloc] init]);
     1640
     1641    auto handler = adoptNS([[SWSchemes alloc] init]);
     1642    handler->resources.set("sw1://host/main.html", ResourceInfo { @"text/html", mainBytes });
     1643    handler->resources.set("sw1://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });
     1644
     1645    auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]);
     1646    [navigationDelegate setDidFinishNavigation:^(WKWebView *, WKNavigation *) {
     1647        didFinishNavigation = true;
     1648    }];
     1649
     1650    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1651#if PLATFORM(MAC)
     1652    [[configuration preferences] _setAppNapEnabled:YES];
     1653#endif
     1654    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
     1655    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"sw1"];
     1656
     1657    auto *processPool = configuration.get().processPool;
     1658    [processPool _registerURLSchemeServiceWorkersCanHandle:@"sw1"];
     1659
     1660    auto webView1 = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get() addToWindow: YES]);
     1661    [webView1 setNavigationDelegate:navigationDelegate.get()];
     1662
     1663    // Let's make it so that webView1 be app nappable after loading is completed.
     1664    [webView1.get().window resignKeyWindow];
     1665#if PLATFORM(MAC)
     1666    [webView1.get().window orderOut:nil];
     1667#endif
     1668
     1669    auto *request1 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw1://host/main.html"]];
     1670    [webView1 loadRequest:request1];
     1671
     1672    didFinishNavigation = false;
     1673    TestWebKitAPI::Util::run(&didFinishNavigation);
     1674
     1675    auto webView2Configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1676#if PLATFORM(MAC)
     1677    [[webView2Configuration preferences] _setAppNapEnabled:NO];
     1678#endif
     1679    [webView2Configuration setProcessPool:processPool];
     1680    [[webView2Configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
     1681    [webView2Configuration setURLSchemeHandler:handler.get() forURLScheme:@"sw1"];
     1682    webView2Configuration.get()._relatedWebView = webView1.get();
     1683
     1684    auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webView2Configuration.get()]);
     1685    [webView2 setNavigationDelegate:navigationDelegate.get()];
     1686
     1687    [webView2 loadRequest:request1];
     1688
     1689    didFinishNavigation = false;
     1690    TestWebKitAPI::Util::run(&didFinishNavigation);
     1691}
     1692
    16221693TEST(ServiceWorkers, LoadData)
    16231694{
Note: See TracChangeset for help on using the changeset viewer.