Title: [272102] branches/safari-611-branch
Revision
272102
Author
[email protected]
Date
2021-01-29 21:40:56 -0800 (Fri, 29 Jan 2021)

Log Message

Cherry-pick r271369. rdar://problem/73473654

    WebProcessPool::establishWorkerContextConnectionToNetworkProcess should make sure to remove the selected process from the cache
    https://bugs.webkit.org/show_bug.cgi?id=220503

    Reviewed by Darin Adler.

    Source/WebKit:

    In case we reuse an existing web process, make sure to remove it from web process cache.
    Covered by API test.

    * UIProcess/WebProcessCache.cpp:
    (WebKit::WebProcessCache::addProcessIfPossible):
    (WebKit::WebProcessCache::addProcess):
    * UIProcess/WebProcessPool.cpp:
    (WebKit::WebProcessPool::establishWorkerContextConnectionToNetworkProcess):

    Tools:

    * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271369 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-611-branch/Source/WebKit/ChangeLog (272101 => 272102)


--- branches/safari-611-branch/Source/WebKit/ChangeLog	2021-01-30 05:40:51 UTC (rev 272101)
+++ branches/safari-611-branch/Source/WebKit/ChangeLog	2021-01-30 05:40:56 UTC (rev 272102)
@@ -1,5 +1,48 @@
 2021-01-29  Alan Coon  <[email protected]>
 
+        Cherry-pick r271369. rdar://problem/73473654
+
+    WebProcessPool::establishWorkerContextConnectionToNetworkProcess should make sure to remove the selected process from the cache
+    https://bugs.webkit.org/show_bug.cgi?id=220503
+    
+    Reviewed by Darin Adler.
+    
+    Source/WebKit:
+    
+    In case we reuse an existing web process, make sure to remove it from web process cache.
+    Covered by API test.
+    
+    * UIProcess/WebProcessCache.cpp:
+    (WebKit::WebProcessCache::addProcessIfPossible):
+    (WebKit::WebProcessCache::addProcess):
+    * UIProcess/WebProcessPool.cpp:
+    (WebKit::WebProcessPool::establishWorkerContextConnectionToNetworkProcess):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271369 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-01-11  Youenn Fablet  <[email protected]>
+
+            WebProcessPool::establishWorkerContextConnectionToNetworkProcess should make sure to remove the selected process from the cache
+            https://bugs.webkit.org/show_bug.cgi?id=220503
+
+            Reviewed by Darin Adler.
+
+            In case we reuse an existing web process, make sure to remove it from web process cache.
+            Covered by API test.
+
+            * UIProcess/WebProcessCache.cpp:
+            (WebKit::WebProcessCache::addProcessIfPossible):
+            (WebKit::WebProcessCache::addProcess):
+            * UIProcess/WebProcessPool.cpp:
+            (WebKit::WebProcessPool::establishWorkerContextConnectionToNetworkProcess):
+
+2021-01-29  Alan Coon  <[email protected]>
+
         Cherry-pick r271619. rdar://problem/73461349
 
     REGRESSION(r269865) Mail's context menu when right clicking on a link does not contain correct entries

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/WebProcessCache.cpp (272101 => 272102)


--- branches/safari-611-branch/Source/WebKit/UIProcess/WebProcessCache.cpp	2021-01-30 05:40:51 UTC (rev 272101)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/WebProcessCache.cpp	2021-01-30 05:40:56 UTC (rev 272102)
@@ -85,6 +85,7 @@
     ASSERT(!process->pageCount());
     ASSERT(!process->provisionalPageCount());
     ASSERT(!process->suspendedPageCount());
+    ASSERT(!process->isRunningServiceWorkers());
 
     if (!canCacheProcess(process))
         return false;
@@ -114,6 +115,7 @@
     ASSERT(!cachedProcess->process().pageCount());
     ASSERT(!cachedProcess->process().provisionalPageCount());
     ASSERT(!cachedProcess->process().suspendedPageCount());
+    ASSERT(!cachedProcess->process().isRunningServiceWorkers());
 
     if (!canCacheProcess(cachedProcess->process()))
         return false;

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/WebProcessPool.cpp (272101 => 272102)


--- branches/safari-611-branch/Source/WebKit/UIProcess/WebProcessPool.cpp	2021-01-30 05:40:51 UTC (rev 272101)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/WebProcessPool.cpp	2021-01-30 05:40:56 UTC (rev 272102)
@@ -567,6 +567,11 @@
             serviceWorkerProcessProxy = process.get();
             serviceWorkerProcessProxy->enableServiceWorkers(processPool->userContentControllerIdentifierForServiceWorkers());
 
+            if (serviceWorkerProcessProxy->isInProcessCache()) {
+                processPool->webProcessCache().removeProcess(*serviceWorkerProcessProxy, WebProcessCache::ShouldShutDownProcess::No);
+                ASSERT(!serviceWorkerProcessProxy->isInProcessCache());
+            }
+
             WEBPROCESSPOOL_RELEASE_LOG_IF_ALLOWED_STATIC(ServiceWorker, "establishWorkerContextConnectionToNetworkProcess reusing an existing web process (process=%p, PID=%d)", serviceWorkerProcessProxy, serviceWorkerProcessProxy->processIdentifier());
             break;
         }

Modified: branches/safari-611-branch/Tools/ChangeLog (272101 => 272102)


--- branches/safari-611-branch/Tools/ChangeLog	2021-01-30 05:40:51 UTC (rev 272101)
+++ branches/safari-611-branch/Tools/ChangeLog	2021-01-30 05:40:56 UTC (rev 272102)
@@ -1,3 +1,39 @@
+2021-01-29  Alan Coon  <[email protected]>
+
+        Cherry-pick r271369. rdar://problem/73473654
+
+    WebProcessPool::establishWorkerContextConnectionToNetworkProcess should make sure to remove the selected process from the cache
+    https://bugs.webkit.org/show_bug.cgi?id=220503
+    
+    Reviewed by Darin Adler.
+    
+    Source/WebKit:
+    
+    In case we reuse an existing web process, make sure to remove it from web process cache.
+    Covered by API test.
+    
+    * UIProcess/WebProcessCache.cpp:
+    (WebKit::WebProcessCache::addProcessIfPossible):
+    (WebKit::WebProcessCache::addProcess):
+    * UIProcess/WebProcessPool.cpp:
+    (WebKit::WebProcessPool::establishWorkerContextConnectionToNetworkProcess):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271369 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-01-11  Youenn Fablet  <[email protected]>
+
+            WebProcessPool::establishWorkerContextConnectionToNetworkProcess should make sure to remove the selected process from the cache
+            https://bugs.webkit.org/show_bug.cgi?id=220503
+
+            Reviewed by Darin Adler.
+
+            * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+
 2021-01-25  Alan Coon  <[email protected]>
 
         Cherry-pick r271799. rdar://problem/73581832

Modified: branches/safari-611-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm (272101 => 272102)


--- branches/safari-611-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm	2021-01-30 05:40:51 UTC (rev 272101)
+++ branches/safari-611-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm	2021-01-30 05:40:56 UTC (rev 272102)
@@ -43,6 +43,7 @@
 #import <WebKit/WKWebsiteDataStoreRef.h>
 #import <WebKit/WebKit.h>
 #import <WebKit/_WKExperimentalFeature.h>
+#import <WebKit/_WKProcessPoolConfiguration.h>
 #import <WebKit/_WKWebsiteDataStoreConfiguration.h>
 #import <wtf/Deque.h>
 #import <wtf/HashMap.h>
@@ -2353,3 +2354,79 @@
     TestWebKitAPI::Util::run(&readyToContinue);
     readyToContinue = false;
 }
+
+TEST(ServiceWorkers, WebProcessCache)
+{
+    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
+
+    // Start with a clean slate data store
+    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
+    processPoolConfiguration.get().processSwapsOnNavigation = YES;
+    processPoolConfiguration.get().usesWebProcessCache = YES;
+    processPoolConfiguration.get().prewarmsProcessesAutomatically = YES;
+    auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
+
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setProcessPool:processPool.get()];
+
+    auto messageHandler = adoptNS([[SWMessageHandler alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
+
+    static const char* main =
+    "<script>"
+    "function registerServiceWorker()"
+    "{"
+    "   try {"
+    "       navigator.serviceWorker.register('/sw.js').then(function(reg) {"
+    "           if (reg.active) {"
+    "               alert('worker unexpectedly already active');"
+    "               return;"
+    "           }"
+    "           worker = reg.installing;"
+    "           worker.addEventListener('statechange', function() {"
+    "               if (worker.state == 'activated')"
+    "                   alert('successfully registered');"
+    "               });"
+    "           }).catch(function(error) {"
+    "               alert('Registration failed with: ' + error);"
+    "           });"
+    "   } catch(e) {"
+    "       alert('Exception: ' + e);"
+    "   }"
+    "}"
+    "alert('loaded');"
+    "</script>";
+
+    TestWebKitAPI::HTTPServer server({
+        { "/", { main } },
+        { "/sw.js", { {{ "Content-Type", "application/_javascript_" }}, "" } }
+    });
+
+    // Create a first web view and load a page
+    auto webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    [webView1 loadRequest:server.request()];
+    EXPECT_WK_STREQ([webView1 _test_waitForAlert], "loaded");
+
+    // Create a second web view and load a page
+    auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    [webView2 loadRequest:server.request()];
+    EXPECT_WK_STREQ([webView2 _test_waitForAlert], "loaded");
+
+    // Close the first page to put it in the cache
+    [webView1 _close];
+
+    // Register a service worker, it should go in webView1 process.
+    [webView2 stringByEvaluatingJavaScript:@"registerServiceWorker()"];
+    EXPECT_WK_STREQ([webView2 _test_waitForAlert], "successfully registered");
+
+    // Clearing web process cache should not kill the service worker process
+    [configuration.get().processPool _clearWebProcessCache];
+
+    EXPECT_EQ(1U, configuration.get().processPool._serviceWorkerProcessCount);
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to