ServiceWorkerRegistration::updateStateFromServer fix! (Don't always create a new...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Nov 2017 01:13:27 +0000 (01:13 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Nov 2017 01:13:27 +0000 (01:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179456

Reviewed by Chris Dumez.

No new tests (No behavior change yet).

* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::updateStateFromServer): Re-use a previous worker instead of always creating a new one.

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

Source/WebCore/ChangeLog
Source/WebCore/workers/service/ServiceWorkerRegistration.cpp

index a1df0d2..594bb2b 100644 (file)
@@ -1,3 +1,15 @@
+2017-11-08  Brady Eidson  <beidson@apple.com>
+
+        ServiceWorkerRegistration::updateStateFromServer fix! (Don't always create a new ServiceWorker every time).
+        https://bugs.webkit.org/show_bug.cgi?id=179456
+
+        Reviewed by Chris Dumez.
+
+        No new tests (No behavior change yet).
+
+        * workers/service/ServiceWorkerRegistration.cpp:
+        (WebCore::ServiceWorkerRegistration::updateStateFromServer): Re-use a previous worker instead of always creating a new one.
+
 2017-11-08  Brent Fulgham  <bfulgham@apple.com>
 
         XMLHttpRequest should not treat file URLs as same origin
index d76b971..a797568 100644 (file)
@@ -170,8 +170,13 @@ void ServiceWorkerRegistration::updateStateFromServer(ServiceWorkerRegistrationS
         return;
 
     RefPtr<ServiceWorker> worker;
-    if (serviceWorkerIdentifier)
-        worker = ServiceWorker::create(*context, *serviceWorkerIdentifier, m_registrationData.scriptURL);
+    if (serviceWorkerIdentifier) {
+        auto* newestWorker = getNewestWorker();
+        if (newestWorker && newestWorker->identifier() == *serviceWorkerIdentifier)
+            worker = newestWorker;
+        else
+            worker = ServiceWorker::create(*context, *serviceWorkerIdentifier, m_registrationData.scriptURL);
+    }
 
     switch (state) {
     case ServiceWorkerRegistrationState::Installing: