Title: [221392] trunk
Revision
221392
Author
beid...@apple.com
Date
2017-08-30 12:40:35 -0700 (Wed, 30 Aug 2017)

Log Message

Implement all of "Register" right up until where the script is fetched.
https://bugs.webkit.org/show_bug.cgi?id=176082

Reviewed by Andy Estes.

Source/WebCore:

Test: http/tests/workers/service/basic-register-exceptions.html

This patch implements every detail of the "Register" and "Update" algorithms right up to
where we would actually fetch the service worker script file.

It also includes miscellaneous refactoring and cleanup along the way.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:

* page/SecurityOrigin.cpp:
(WebCore::shouldTreatAsPotentiallyTrustworthy): Expose in the header for other files to use.
* page/SecurityOrigin.h:

* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::addRegistration): Add some more exception cases from the spec.
(WebCore::ServiceWorkerContainer::scheduleJob): Use the correct job identifier.
(WebCore::ServiceWorkerContainer::jobFailedWithException):
(WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
(WebCore::ServiceWorkerContainer::jobDidFinish):
* workers/service/ServiceWorkerContainer.h:

* workers/service/ServiceWorkerJob.cpp:
(WebCore::ServiceWorkerJob::ServiceWorkerJob):
(WebCore::ServiceWorkerJob::failedWithException): Call through to the client to handle the failure.
(WebCore::ServiceWorkerJob::resolvedWithRegistration): Call through to the client to handle success.
* workers/service/ServiceWorkerJob.h:
(WebCore::ServiceWorkerJob::promise):
(WebCore::ServiceWorkerJob::identifier const): Deleted. Rely on the identifier from the JobData.

* workers/service/ServiceWorkerJobClient.h:

* workers/service/ServiceWorkerJobData.cpp:
(WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
(WebCore::ServiceWorkerJobData::isolatedCopy const):
* workers/service/ServiceWorkerJobData.h:
(WebCore::ServiceWorkerJobData::identifier const):
(WebCore::ServiceWorkerJobData::encode const):
(WebCore::ServiceWorkerJobData::decode):
(WebCore::ServiceWorkerJobData::jobIdentifier const): Deleted.

* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration): Make this class an ActiveDOMObject
  both because it *is* an active DOM object and because we need to get at the ScriptExecutionContext.
* workers/service/ServiceWorkerRegistration.h:

Add a class to encapsulate everything about a registration for encode/decode/crossthread:
* workers/service/ServiceWorkerRegistrationData.cpp:
(WebCore::ServiceWorkerRegistrationData::isolatedCopy const):
* workers/service/ServiceWorkerRegistrationData.h:
(WebCore::ServiceWorkerRegistrationData::encode const):
(WebCore::ServiceWorkerRegistrationData::decode):

* workers/service/ServiceWorkerRegistrationKey.cpp:
(WebCore::ServiceWorkerRegistrationKey::isolatedCopy const):
* workers/service/ServiceWorkerRegistrationKey.h:
(WebCore::ServiceWorkerRegistrationKey::encode const):
(WebCore::ServiceWorkerRegistrationKey::decode):

* workers/service/server/SWClientConnection.cpp:
(WebCore::SWClientConnection::scheduleJob):
(WebCore::SWClientConnection::jobResolvedInServer):
* workers/service/server/SWClientConnection.h:

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::~SWServer):
(WebCore::SWServer::Connection::scheduleJobInServer):
(WebCore::SWServer::scheduleJob):
(WebCore::SWServer::rejectJob):
(WebCore::SWServer::resolveJob):
* workers/service/server/SWServer.h:

* workers/service/server/SWServerRegistration.cpp:
(WebCore::SWServerRegistration::SWServerRegistration):
(WebCore::SWServerRegistration::startNextJob):
(WebCore::SWServerRegistration::isEmpty):
(WebCore::SWServerRegistration::getNewestWorker): Implement "Get Newest Worker" algorithm.
(WebCore::SWServerRegistration::runRegisterJob): Implement the rest of the "Register" algorithm.
(WebCore::SWServerRegistration::runUpdateJob): Implement every part of "Update" up to where we would fetch.
(WebCore::SWServerRegistration::rejectWithExceptionOnMainThread):
(WebCore::SWServerRegistration::resolveWithRegistrationOnMainThread):
(WebCore::SWServerRegistration::resolveCurrentJob):
(WebCore::SWServerRegistration::data const):
(WebCore::SWServerRegistration::performCurrentJob): Deleted.
* workers/service/server/SWServerRegistration.h:
(WebCore::SWServerRegistration::identifier const):

Add a stub class to represent "active service workers" in the SWServer:
* workers/service/server/SWServerWorker.cpp:
(WebCore::SWServerWorker::SWServerWorker):
(WebCore::SWServerWorker::~SWServerWorker):
* workers/service/server/SWServerWorker.h:
(WebCore::SWServerWorker::scriptURL const):

Source/WebKit:

* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::resolveJobInClient):
* StorageProcess/ServiceWorker/WebSWServerConnection.h:
* WebProcess/Storage/WebSWClientConnection.messages.in:

LayoutTests:

* http/tests/workers/service/basic-register-exceptions-expected.txt: Added.
* http/tests/workers/service/basic-register-exceptions.html: Added.
* http/tests/workers/service/resources/basic-register-exceptions.js: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (221391 => 221392)


--- trunk/LayoutTests/ChangeLog	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/LayoutTests/ChangeLog	2017-08-30 19:40:35 UTC (rev 221392)
@@ -1,3 +1,14 @@
+2017-08-30  Brady Eidson  <beid...@apple.com>
+
+        Implement all of "Register" right up until where the script is fetched.
+        https://bugs.webkit.org/show_bug.cgi?id=176082
+
+        Reviewed by Andy Estes.
+
+        * http/tests/workers/service/basic-register-exceptions-expected.txt: Added.
+        * http/tests/workers/service/basic-register-exceptions.html: Added.
+        * http/tests/workers/service/resources/basic-register-exceptions.js: Added.
+
 2017-08-22  Matt Rajca  <mra...@apple.com>
 
         Opt all Mac clients into document-level media user gesture quirks.

Added: trunk/LayoutTests/http/tests/workers/service/basic-register-exceptions-expected.txt (0 => 221392)


--- trunk/LayoutTests/http/tests/workers/service/basic-register-exceptions-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/basic-register-exceptions-expected.txt	2017-08-30 19:40:35 UTC (rev 221392)
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: line 10: Registration failed with error: TypeError: serviceWorker.register() cannot be called with an empty script URL
+CONSOLE MESSAGE: line 20: Registration failed with error: TypeError: serviceWorker.register() must be called with a valid relative script URL
+CONSOLE MESSAGE: line 30: Registration failed with error: TypeError: serviceWorker.register() must be called with a script URL whose protocol is either HTTP or HTTPS
+CONSOLE MESSAGE: line 40: Registration failed with error: TypeError: serviceWorker.register() must be called with a script URL whose path does not contain '%2f' or '%5c'
+CONSOLE MESSAGE: line 50: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS
+CONSOLE MESSAGE: line 60: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() cannot have a path that contains '%2f' or '%5c'
+CONSOLE MESSAGE: line 70: Registration failed with error: SecurityError: Script origin does not match the registering client's origin
+CONSOLE MESSAGE: line 81: Registration failed with error: SecurityError: Scope origin does not match the registering client's origin
+

Added: trunk/LayoutTests/http/tests/workers/service/basic-register-exceptions.html (0 => 221392)


--- trunk/LayoutTests/http/tests/workers/service/basic-register-exceptions.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/basic-register-exceptions.html	2017-08-30 19:40:35 UTC (rev 221392)
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src=""
+</head>
+<body>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/workers/service/resources/basic-register-exceptions.js (0 => 221392)


--- trunk/LayoutTests/http/tests/workers/service/resources/basic-register-exceptions.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/basic-register-exceptions.js	2017-08-30 19:40:35 UTC (rev 221392)
@@ -0,0 +1,87 @@
+function done()
+{
+    finishSWTest();
+}
+
+navigator.serviceWorker.register("", { })
+.then(function(r) {
+	console.log("Registered! (unexpectedly)");
+}, function(e) {
+	console.log("Registration failed with error: " + e);
+})
+.catch(function(e) {
+	console.log("Exception registering: " + e);
+});
+
+navigator.serviceWorker.register("http://127.0.0.1:abc", { })
+.then(function(r) {
+	console.log("Registered! (unexpectedly)");
+}, function(e) {
+	console.log("Registration failed with error: " + e);
+})
+.catch(function(e) {
+	console.log("Exception registering: " + e);
+});
+
+navigator.serviceWorker.register("somescheme://script.js", { })
+.then(function(r) {
+	console.log("Registered! (unexpectedly)");
+}, function(e) {
+	console.log("Registration failed with error: " + e);
+})
+.catch(function(e) {
+	console.log("Exception registering: " + e);
+});
+
+navigator.serviceWorker.register("resources/%2fscript.js", { })
+.then(function(r) {
+	console.log("Registered! (unexpectedly)");
+}, function(e) {
+	console.log("Registration failed with error: " + e);
+})
+.catch(function(e) {
+	console.log("Exception registering: " + e);
+});
+
+navigator.serviceWorker.register("resources/script.js", { scope: "somescheme://script.js" })
+.then(function(r) {
+	console.log("Registered! (unexpectedly)");
+}, function(e) {
+	console.log("Registration failed with error: " + e);
+})
+.catch(function(e) {
+	console.log("Exception registering: " + e);
+});
+
+navigator.serviceWorker.register("resources/script.js", { scope: "%2fscript.js" })
+.then(function(r) {
+	console.log("Registered! (unexpectedly)");
+}, function(e) {
+	console.log("Registration failed with error: " + e);
+})
+.catch(function(e) {
+	console.log("Exception registering: " + e);
+});
+
+navigator.serviceWorker.register("http://localhost:8000/workers/service/resources/empty-worker.js", { })
+.then(function(r) {
+	console.log("Registered! (unexpectedly)");
+}, function(e) {
+	console.log("Registration failed with error: " + e);
+})
+.catch(function(e) {
+	console.log("Exception registering: " + e);
+});
+
+navigator.serviceWorker.register("resources/empty-worker.js", { scope: "http://localhost:8000/workers/service/" })
+.then(function(r) {
+	console.log("Registered! (unexpectedly)");
+	done();
+}, function(e) {
+	console.log("Registration failed with error: " + e);
+	done();
+})
+.catch(function(e) {
+	console.log("Exception registering: " + e);
+	done();
+});

Modified: trunk/Source/WebCore/CMakeLists.txt (221391 => 221392)


--- trunk/Source/WebCore/CMakeLists.txt	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/CMakeLists.txt	2017-08-30 19:40:35 UTC (rev 221392)
@@ -3019,6 +3019,7 @@
     workers/service/ServiceWorkerJobData.cpp
     workers/service/ServiceWorkerProvider.cpp
     workers/service/ServiceWorkerRegistration.cpp
+    workers/service/ServiceWorkerRegistrationData.cpp
     workers/service/ServiceWorkerRegistrationKey.cpp
     workers/service/ServiceWorkerRegistrationOptions.cpp
 
@@ -3025,6 +3026,7 @@
     workers/service/server/SWClientConnection.cpp
     workers/service/server/SWServer.cpp
     workers/service/server/SWServerRegistration.cpp
+    workers/service/server/SWServerWorker.cpp
 
     xml/DOMParser.cpp
     xml/NativeXPathNSResolver.cpp

Modified: trunk/Source/WebCore/ChangeLog (221391 => 221392)


--- trunk/Source/WebCore/ChangeLog	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/ChangeLog	2017-08-30 19:40:35 UTC (rev 221392)
@@ -1,3 +1,104 @@
+2017-08-30  Brady Eidson  <beid...@apple.com>
+
+        Implement all of "Register" right up until where the script is fetched.
+        https://bugs.webkit.org/show_bug.cgi?id=176082
+
+        Reviewed by Andy Estes.
+
+        Test: http/tests/workers/service/basic-register-exceptions.html
+
+        This patch implements every detail of the "Register" and "Update" algorithms right up to
+        where we would actually fetch the service worker script file.
+
+        It also includes miscellaneous refactoring and cleanup along the way.
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+
+        * page/SecurityOrigin.cpp:
+        (WebCore::shouldTreatAsPotentiallyTrustworthy): Expose in the header for other files to use.
+        * page/SecurityOrigin.h:
+
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::addRegistration): Add some more exception cases from the spec.
+        (WebCore::ServiceWorkerContainer::scheduleJob): Use the correct job identifier.
+        (WebCore::ServiceWorkerContainer::jobFailedWithException):
+        (WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
+        (WebCore::ServiceWorkerContainer::jobDidFinish):
+        * workers/service/ServiceWorkerContainer.h:
+
+        * workers/service/ServiceWorkerJob.cpp:
+        (WebCore::ServiceWorkerJob::ServiceWorkerJob):
+        (WebCore::ServiceWorkerJob::failedWithException): Call through to the client to handle the failure.
+        (WebCore::ServiceWorkerJob::resolvedWithRegistration): Call through to the client to handle success.
+        * workers/service/ServiceWorkerJob.h:
+        (WebCore::ServiceWorkerJob::promise):
+        (WebCore::ServiceWorkerJob::identifier const): Deleted. Rely on the identifier from the JobData.
+
+        * workers/service/ServiceWorkerJobClient.h:
+
+        * workers/service/ServiceWorkerJobData.cpp:
+        (WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
+        (WebCore::ServiceWorkerJobData::isolatedCopy const):
+        * workers/service/ServiceWorkerJobData.h:
+        (WebCore::ServiceWorkerJobData::identifier const):
+        (WebCore::ServiceWorkerJobData::encode const):
+        (WebCore::ServiceWorkerJobData::decode):
+        (WebCore::ServiceWorkerJobData::jobIdentifier const): Deleted.
+
+        * workers/service/ServiceWorkerRegistration.cpp:
+        (WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration): Make this class an ActiveDOMObject
+          both because it *is* an active DOM object and because we need to get at the ScriptExecutionContext.
+        * workers/service/ServiceWorkerRegistration.h:
+
+        Add a class to encapsulate everything about a registration for encode/decode/crossthread:
+        * workers/service/ServiceWorkerRegistrationData.cpp:
+        (WebCore::ServiceWorkerRegistrationData::isolatedCopy const):
+        * workers/service/ServiceWorkerRegistrationData.h: 
+        (WebCore::ServiceWorkerRegistrationData::encode const):
+        (WebCore::ServiceWorkerRegistrationData::decode):
+
+        * workers/service/ServiceWorkerRegistrationKey.cpp:
+        (WebCore::ServiceWorkerRegistrationKey::isolatedCopy const):
+        * workers/service/ServiceWorkerRegistrationKey.h:
+        (WebCore::ServiceWorkerRegistrationKey::encode const):
+        (WebCore::ServiceWorkerRegistrationKey::decode):
+
+        * workers/service/server/SWClientConnection.cpp:
+        (WebCore::SWClientConnection::scheduleJob):
+        (WebCore::SWClientConnection::jobResolvedInServer):
+        * workers/service/server/SWClientConnection.h:
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::~SWServer):
+        (WebCore::SWServer::Connection::scheduleJobInServer):
+        (WebCore::SWServer::scheduleJob):
+        (WebCore::SWServer::rejectJob):
+        (WebCore::SWServer::resolveJob):
+        * workers/service/server/SWServer.h:
+
+        * workers/service/server/SWServerRegistration.cpp:
+        (WebCore::SWServerRegistration::SWServerRegistration):
+        (WebCore::SWServerRegistration::startNextJob):
+        (WebCore::SWServerRegistration::isEmpty):
+        (WebCore::SWServerRegistration::getNewestWorker): Implement "Get Newest Worker" algorithm.
+        (WebCore::SWServerRegistration::runRegisterJob): Implement the rest of the "Register" algorithm.
+        (WebCore::SWServerRegistration::runUpdateJob): Implement every part of "Update" up to where we would fetch.
+        (WebCore::SWServerRegistration::rejectWithExceptionOnMainThread):
+        (WebCore::SWServerRegistration::resolveWithRegistrationOnMainThread):
+        (WebCore::SWServerRegistration::resolveCurrentJob):
+        (WebCore::SWServerRegistration::data const):
+        (WebCore::SWServerRegistration::performCurrentJob): Deleted.
+        * workers/service/server/SWServerRegistration.h:
+        (WebCore::SWServerRegistration::identifier const):
+
+        Add a stub class to represent "active service workers" in the SWServer:
+        * workers/service/server/SWServerWorker.cpp:
+        (WebCore::SWServerWorker::SWServerWorker):
+        (WebCore::SWServerWorker::~SWServerWorker):
+        * workers/service/server/SWServerWorker.h: 
+        (WebCore::SWServerWorker::scriptURL const):
+
 2017-08-30  Don Olmstead  <don.olmst...@sony.com>
 
         [CMake][WinCairo] Use find_package for libpng and libjpeg

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (221391 => 221392)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-08-30 19:40:35 UTC (rev 221392)
@@ -2301,6 +2301,10 @@
 		517A53251F4B905500DCDC0A /* ServiceWorkerJobData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53241F4B904A00DCDC0A /* ServiceWorkerJobData.cpp */; };
 		517A53281F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */; };
 		517A53291F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		517A53451F50C17F00DCDC0A /* SWServerWorker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53431F50C16100DCDC0A /* SWServerWorker.cpp */; };
+		517A53461F50C17F00DCDC0A /* SWServerWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A53421F50C16100DCDC0A /* SWServerWorker.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		517A534E1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */; };
+		517A534F1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		517A63C31B74318700E7DCDC /* KeyedDecoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */; };
 		517A63C41B74318B00E7DCDC /* KeyedEncoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63C11B74317E00E7DCDC /* KeyedEncoderCF.cpp */; };
 		517A63C51B74318F00E7DCDC /* KeyedDecoderCF.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -10122,6 +10126,10 @@
 		517A53241F4B904A00DCDC0A /* ServiceWorkerJobData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerJobData.cpp; sourceTree = "<group>"; };
 		517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationKey.h; sourceTree = "<group>"; };
 		517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationKey.cpp; sourceTree = "<group>"; };
+		517A53421F50C16100DCDC0A /* SWServerWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWServerWorker.h; sourceTree = "<group>"; };
+		517A53431F50C16100DCDC0A /* SWServerWorker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWServerWorker.cpp; sourceTree = "<group>"; };
+		517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationData.cpp; sourceTree = "<group>"; };
+		517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationData.h; sourceTree = "<group>"; };
 		517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedDecoderCF.cpp; sourceTree = "<group>"; };
 		517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyedDecoderCF.h; sourceTree = "<group>"; };
 		517A63C11B74317E00E7DCDC /* KeyedEncoderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedEncoderCF.cpp; sourceTree = "<group>"; };
@@ -18758,6 +18766,8 @@
 				517A52EE1F47535900DCDC0A /* SWServer.h */,
 				51F645951F4A686100B54DED /* SWServerRegistration.cpp */,
 				51F645941F4A684F00B54DED /* SWServerRegistration.h */,
+				517A53431F50C16100DCDC0A /* SWServerWorker.cpp */,
+				517A53421F50C16100DCDC0A /* SWServerWorker.h */,
 			);
 			path = server;
 			sourceTree = "<group>";
@@ -18863,6 +18873,8 @@
 				51F1754D1F3EBC0C00C74950 /* ServiceWorkerRegistration.cpp */,
 				51F1754C1F3EBC0C00C74950 /* ServiceWorkerRegistration.h */,
 				51F1754B1F3EBC0C00C74950 /* ServiceWorkerRegistration.idl */,
+				517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */,
+				517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */,
 				517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */,
 				517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */,
 				51F645A01F4BF51600B54DED /* ServiceWorkerRegistrationOptions.cpp */,
@@ -29709,6 +29721,7 @@
 				51F6456A1F4539C000B54DED /* ServiceWorkerJobType.h in Headers */,
 				51F175661F3EBC8300C74950 /* ServiceWorkerProvider.h in Headers */,
 				51F175681F3EBC8300C74950 /* ServiceWorkerRegistration.h in Headers */,
+				517A534F1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.h in Headers */,
 				517A53291F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.h in Headers */,
 				51F175691F3EBC8300C74950 /* ServiceWorkerRegistrationOptions.h in Headers */,
 				51F1756C1F3EBC8300C74950 /* ServiceWorkerUpdateViaCache.h in Headers */,
@@ -30130,6 +30143,7 @@
 				517A531D1F4B53B100DCDC0A /* SWClientConnection.h in Headers */,
 				517A52F01F47535B00DCDC0A /* SWServer.h in Headers */,
 				51F645971F4A686F00B54DED /* SWServerRegistration.h in Headers */,
+				517A53461F50C17F00DCDC0A /* SWServerWorker.h in Headers */,
 				E180811716FCF9CB00B80D07 /* SynchronousLoaderClient.h in Headers */,
 				26FAE4CF1852E3A5004C8C46 /* SynchronousResourceHandleCFURLConnectionDelegate.h in Headers */,
 				0F03C0741884695E00A5F8CA /* SystemMemory.h in Headers */,
@@ -33600,6 +33614,7 @@
 				517A53251F4B905500DCDC0A /* ServiceWorkerJobData.cpp in Sources */,
 				51F175651F3EBC8300C74950 /* ServiceWorkerProvider.cpp in Sources */,
 				51F175671F3EBC8300C74950 /* ServiceWorkerRegistration.cpp in Sources */,
+				517A534E1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.cpp in Sources */,
 				517A53281F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.cpp in Sources */,
 				51F645A21F4BF53C00B54DED /* ServiceWorkerRegistrationOptions.cpp in Sources */,
 				93309E0F099E64920056E581 /* SetNodeAttributeCommand.cpp in Sources */,
@@ -33907,6 +33922,7 @@
 				517A531C1F4B53B100DCDC0A /* SWClientConnection.cpp in Sources */,
 				517A52F11F4754E700DCDC0A /* SWServer.cpp in Sources */,
 				51F645961F4A686F00B54DED /* SWServerRegistration.cpp in Sources */,
+				517A53451F50C17F00DCDC0A /* SWServerWorker.cpp in Sources */,
 				E180811216FCF42F00B80D07 /* SynchronousLoaderClient.cpp in Sources */,
 				E180811616FCF9CB00B80D07 /* SynchronousLoaderClient.mm in Sources */,
 				442ABCD617D9262F00D30715 /* SynchronousLoaderClientCFNet.cpp in Sources */,

Modified: trunk/Source/WebCore/page/SecurityOrigin.cpp (221391 => 221392)


--- trunk/Source/WebCore/page/SecurityOrigin.cpp	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/page/SecurityOrigin.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -123,7 +123,7 @@
 }
 
 // https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy (Editor's Draft, 17 November 2016)
-static bool shouldTreatAsPotentiallyTrustworthy(const URL& url)
+bool shouldTreatAsPotentiallyTrustworthy(const URL& url)
 {
     if (!url.isValid())
         return false;

Modified: trunk/Source/WebCore/page/SecurityOrigin.h (221391 => 221392)


--- trunk/Source/WebCore/page/SecurityOrigin.h	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/page/SecurityOrigin.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -234,6 +234,8 @@
     bool m_isPotentiallyTrustworthy { false };
 };
 
+bool shouldTreatAsPotentiallyTrustworthy(const URL&);
+
 // Returns true if the Origin header values serialized from these two origins would be the same.
 bool originsMatch(const SecurityOrigin&, const SecurityOrigin&);
 bool originsMatch(const SecurityOrigin*, const SecurityOrigin*);

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (221391 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -29,8 +29,11 @@
 #if ENABLE(SERVICE_WORKER)
 
 #include "Exception.h"
+#include "IDLTypes.h"
 #include "JSDOMPromiseDeferred.h"
+#include "JSServiceWorkerRegistration.h"
 #include "NavigatorBase.h"
+#include "ScopeGuard.h"
 #include "ScriptExecutionContext.h"
 #include "SecurityOrigin.h"
 #include "ServiceWorkerJob.h"
@@ -104,7 +107,7 @@
 
     String path = jobData.scriptURL.path();
     if (path.containsIgnoringASCIICase("%2f") || path.containsIgnoringASCIICase("%5c")) {
-        promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() must be called with a script URL whose path does not contain '%%2f' or '%%5c'") });
+        promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() must be called with a script URL whose path does not contain '%2f' or '%5c'") });
         return;
     }
 
@@ -112,10 +115,21 @@
     if (!scope.isEmpty())
         jobData.scopeURL = context->completeURL(scope);
 
+    if (!jobData.scopeURL.isNull() && !jobData.scopeURL.protocolIsInHTTPFamily()) {
+        promise->reject(Exception { TypeError, ASCIILiteral("Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS") });
+        return;
+    }
+
+    path = jobData.scopeURL.path();
+    if (path.containsIgnoringASCIICase("%2f") || path.containsIgnoringASCIICase("%5c")) {
+        promise->reject(Exception { TypeError, ASCIILiteral("Scope URL provided to serviceWorker.register() cannot have a path that contains '%2f' or '%5c'") });
+        return;
+    }
+
     jobData.clientCreationURL = context->url();
     jobData.topOrigin = SecurityOriginData::fromSecurityOrigin(context->topOrigin());
     jobData.type = ServiceWorkerJobType::Register;
-    jobData.registrationOptions = std::make_unique<RegistrationOptions>(options);
+    jobData.registrationOptions = options;
 
     scheduleJob(ServiceWorkerJob::create(*this, WTFMove(promise), WTFMove(jobData)));
 }
@@ -125,7 +139,7 @@
     ASSERT(m_swConnection);
 
     ServiceWorkerJob& rawJob = job.get();
-    auto result = m_jobMap.add(rawJob.identifier(), WTFMove(job));
+    auto result = m_jobMap.add(rawJob.data().identifier(), WTFMove(job));
     ASSERT_UNUSED(result, result.isNewEntry);
 
     m_swConnection->scheduleJob(rawJob);
@@ -145,9 +159,31 @@
 {
 }
 
+void ServiceWorkerContainer::jobFailedWithException(ServiceWorkerJob& job, const Exception& exception)
+{
+    job.promise().reject(exception);
+    jobDidFinish(job);
+}
+
+void ServiceWorkerContainer::jobResolvedWithRegistration(ServiceWorkerJob& job, const ServiceWorkerRegistrationData& data)
+{
+    ScopeGuard guard([this, &job] {
+        jobDidFinish(job);
+    });
+
+    auto* context = scriptExecutionContext();
+    if (!context) {
+        LOG_ERROR("ServiceWorkerContainer::jobResolvedWithRegistration called but the containers ScriptExecutionContext is gone");
+        return;
+    }
+
+    auto registration = ServiceWorkerRegistration::create(*context, data);
+    job.promise().resolve<IDLInterface<ServiceWorkerRegistration>>(registration.get());
+}
+
 void ServiceWorkerContainer::jobDidFinish(ServiceWorkerJob& job)
 {
-    auto taken = m_jobMap.take(job.identifier());
+    auto taken = m_jobMap.take(job.data().identifier());
     ASSERT_UNUSED(taken, taken.get() == &job);
 }
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h (221391 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -70,7 +70,11 @@
 
 private:
     void scheduleJob(Ref<ServiceWorkerJob>&&);
-    void jobDidFinish(ServiceWorkerJob&) final;
+
+    void jobFailedWithException(ServiceWorkerJob&, const Exception&) final;
+    void jobResolvedWithRegistration(ServiceWorkerJob&, const ServiceWorkerRegistrationData&) final;
+    void jobDidFinish(ServiceWorkerJob&);
+
     uint64_t connectionIdentifier() final;
 
     const char* activeDOMObjectName() const final;

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp (221391 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -30,16 +30,14 @@
 
 #include "JSDOMPromiseDeferred.h"
 #include "ServiceWorkerJobData.h"
+#include "ServiceWorkerRegistration.h"
 
 namespace WebCore {
 
-static std::atomic<uint64_t> currentIdentifier;
-
 ServiceWorkerJob::ServiceWorkerJob(ServiceWorkerJobClient& client, Ref<DeferredPromise>&& promise, ServiceWorkerJobData&& jobData)
     : m_client(client)
     , m_jobData(WTFMove(jobData))
     , m_promise(WTFMove(promise))
-    , m_identifier(++currentIdentifier)
 {
 }
 
@@ -51,13 +49,19 @@
 void ServiceWorkerJob::failedWithException(const Exception& exception)
 {
     ASSERT(currentThread() == m_creationThread);
+    ASSERT(!m_completed);
 
+    m_completed = true;
+    m_client->jobFailedWithException(*this, exception);
+}
+
+void ServiceWorkerJob::resolvedWithRegistration(const ServiceWorkerRegistrationData& data)
+{
+    ASSERT(currentThread() == m_creationThread);
     ASSERT(!m_completed);
-    m_promise->reject(exception);
+
     m_completed = true;
-
-    // Can cause this to be deleted.
-    m_client->jobDidFinish(*this);
+    m_client->jobResolvedWithRegistration(*this, data);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJob.h (221391 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJob.h	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJob.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -39,6 +39,7 @@
 class DeferredPromise;
 class Exception;
 enum class ServiceWorkerJobType;
+struct ServiceWorkerRegistrationData;
 
 class ServiceWorkerJob : public ThreadSafeRefCounted<ServiceWorkerJob> {
 public:
@@ -49,11 +50,11 @@
 
     WEBCORE_EXPORT ~ServiceWorkerJob();
 
-    WEBCORE_EXPORT void failedWithException(const Exception&);
+    void failedWithException(const Exception&);
+    void resolvedWithRegistration(const ServiceWorkerRegistrationData&);
 
-    uint64_t identifier() const { return m_identifier; }
-
     ServiceWorkerJobData data() const { return m_jobData; }
+    DeferredPromise& promise() { return m_promise.get(); }
 
 private:
     ServiceWorkerJob(ServiceWorkerJobClient&, Ref<DeferredPromise>&&, ServiceWorkerJobData&&);
@@ -63,7 +64,6 @@
     Ref<DeferredPromise> m_promise;
 
     bool m_completed { false };
-    uint64_t m_identifier;
 
     Ref<RunLoop> m_runLoop { RunLoop::current() };
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h (221391 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -29,13 +29,17 @@
 
 namespace WebCore {
 
+class Exception;
 class ServiceWorkerJob;
+struct ServiceWorkerRegistrationData;
 
 class ServiceWorkerJobClient {
 public:
     virtual ~ServiceWorkerJobClient() { };
 
-    virtual void jobDidFinish(ServiceWorkerJob&) = 0;
+    virtual void jobFailedWithException(ServiceWorkerJob&, const Exception&) = 0;
+    virtual void jobResolvedWithRegistration(ServiceWorkerJob&, const ServiceWorkerRegistrationData&) = 0;
+
     virtual uint64_t connectionIdentifier() = 0;
 
     virtual void ref() = 0;

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJobData.cpp (221391 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJobData.cpp	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJobData.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -47,9 +47,7 @@
     topOrigin = other.topOrigin;
     scopeURL = other.scopeURL;
     type = other.type;
-
-    if (other.registrationOptions)
-        registrationOptions = std::make_unique<RegistrationOptions>(*other.registrationOptions);
+    registrationOptions = other.registrationOptions;
 }
 
 ServiceWorkerRegistrationKey ServiceWorkerJobData::registrationKey() const
@@ -68,9 +66,8 @@
     result.clientCreationURL = clientCreationURL.isolatedCopy();
     result.topOrigin = topOrigin.isolatedCopy();
     result.scopeURL = scopeURL.isolatedCopy();
+    result.registrationOptions = registrationOptions.isolatedCopy();
 
-    if (registrationOptions)
-        result.registrationOptions = std::make_unique<RegistrationOptions>(registrationOptions->isolatedCopy());
     return result;
 }
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJobData.h (221391 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJobData.h	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJobData.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -41,7 +41,7 @@
     ServiceWorkerJobData(const ServiceWorkerJobData&);
     ServiceWorkerJobData() = default;
 
-    uint64_t jobIdentifier() const { return m_jobIdentifier; }
+    uint64_t identifier() const { return m_jobIdentifier; }
     uint64_t connectionIdentifier() const { return m_connectionIdentifier; }
 
     URL scriptURL;
@@ -50,7 +50,7 @@
     URL scopeURL;
     ServiceWorkerJobType type;
 
-    std::unique_ptr<RegistrationOptions> registrationOptions;
+    RegistrationOptions registrationOptions;
 
     ServiceWorkerRegistrationKey registrationKey() const;
     ServiceWorkerJobData isolatedCopy() const;
@@ -70,8 +70,7 @@
     encoder.encodeEnum(type);
     switch (type) {
     case ServiceWorkerJobType::Register:
-        RELEASE_ASSERT(registrationOptions);
-        encoder << *registrationOptions;
+        encoder << registrationOptions;
         break;
     }
 }
@@ -96,8 +95,7 @@
 
     switch (jobData.type) {
     case ServiceWorkerJobType::Register:
-        jobData.registrationOptions = std::make_unique<RegistrationOptions>();
-        if (!decoder.decode(*jobData.registrationOptions))
+        if (!decoder.decode(jobData.registrationOptions))
             return false;
         break;
     }

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp (221391 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -30,6 +30,13 @@
 
 namespace WebCore {
 
+ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& context, const ServiceWorkerRegistrationData& registrationData)
+    : ActiveDOMObject(&context)
+    , m_registrationData(registrationData)
+{
+    suspendIfNeeded();
+}
+
 ServiceWorker* ServiceWorkerRegistration::installing()
 {
     return nullptr;

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h (221391 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -27,15 +27,17 @@
 
 #if ENABLE(SERVICE_WORKER)
 
+#include "ActiveDOMObject.h"
 #include "EventTarget.h"
 #include "JSDOMPromiseDeferred.h"
+#include "ServiceWorkerRegistrationData.h"
 
 namespace WebCore {
 
-class Frame;
+class ScriptExecutionContext;
 class ServiceWorker;
 
-class ServiceWorkerRegistration final : public EventTargetWithInlineData {
+class ServiceWorkerRegistration final : public EventTargetWithInlineData, public ActiveDOMObject {
 public:
     enum class UpdateViaCache {
         Imports,
@@ -43,7 +45,11 @@
         None,
     };
 
-    static Ref<ServiceWorkerRegistration> create(Frame& frame) { return adoptRef(*new ServiceWorkerRegistration(frame)); }
+    static Ref<ServiceWorkerRegistration> create(ScriptExecutionContext& context, const ServiceWorkerRegistrationData& data)
+    {
+        return adoptRef(*new ServiceWorkerRegistration(context, data));
+    }
+
     virtual ~ServiceWorkerRegistration() = default;
 
     ServiceWorker* installing();
@@ -57,12 +63,17 @@
     void unregister(Ref<DeferredPromise>&&);
 
 private:
-    explicit ServiceWorkerRegistration(Frame&);
+    ServiceWorkerRegistration(ScriptExecutionContext&, const ServiceWorkerRegistrationData&);
 
     virtual EventTargetInterface eventTargetInterface() const;
     virtual ScriptExecutionContext* scriptExecutionContext() const;
     void refEventTarget() final { ref(); }
     void derefEventTarget() final { deref(); }
+
+    const char* activeDOMObjectName() const { return "ServiceWorkerRegistration"; }
+    bool canSuspendForDocumentSuspension() const { return false; }
+
+    ServiceWorkerRegistrationData m_registrationData;
 };
 
 } // namespace WebCore

Copied: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp (from rev 221388, trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h) (0 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ServiceWorkerRegistrationData.h"
+
+#if ENABLE(SERVICE_WORKER)
+
+namespace WebCore {
+
+ServiceWorkerRegistrationData ServiceWorkerRegistrationData::isolatedCopy() const
+{
+    ServiceWorkerRegistrationData result;
+    result.key = key.isolatedCopy();
+    result.identifier = identifier;
+    return result;
+}
+
+} // namespace WTF
+
+#endif // ENABLE(SERVICE_WORKER)

Copied: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h (from rev 221388, trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp) (0 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "ServiceWorkerRegistrationKey.h"
+
+namespace WebCore {
+
+struct ServiceWorkerRegistrationData {
+    ServiceWorkerRegistrationKey key;
+    uint64_t identifier;
+
+    ServiceWorkerRegistrationData isolatedCopy() const;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static bool decode(Decoder&, ServiceWorkerRegistrationData&);
+};
+
+
+template<class Encoder>
+void ServiceWorkerRegistrationData::encode(Encoder& encoder) const
+{
+    encoder << key << identifier;
+}
+
+template<class Decoder>
+bool ServiceWorkerRegistrationData::decode(Decoder& decoder, ServiceWorkerRegistrationData& data)
+{
+    if (!decoder.decode(data.key))
+        return false;
+    if (!decoder.decodeEnum(data.identifier))
+        return false;
+
+    return true;
+}
+
+} // namespace WTF
+
+#endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp (221391 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -51,6 +51,14 @@
     return clientCreationURL == other.clientCreationURL && topOrigin == other.topOrigin;
 }
 
+ServiceWorkerRegistrationKey ServiceWorkerRegistrationKey::isolatedCopy() const
+{
+    ServiceWorkerRegistrationKey result;
+    result.clientCreationURL = clientCreationURL.isolatedCopy();
+    result.topOrigin = topOrigin.isolatedCopy();
+    return result;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h (221391 => 221392)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -40,8 +40,30 @@
     unsigned hash() const;
 
     bool operator==(const ServiceWorkerRegistrationKey&) const;
+
+    ServiceWorkerRegistrationKey isolatedCopy() const;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static bool decode(Decoder&, ServiceWorkerRegistrationKey&);
 };
 
+template<class Encoder>
+void ServiceWorkerRegistrationKey::encode(Encoder& encoder) const
+{
+    encoder << clientCreationURL << topOrigin;
+}
+
+template<class Decoder>
+bool ServiceWorkerRegistrationKey::decode(Decoder& decoder, ServiceWorkerRegistrationKey& key)
+{
+    if (!decoder.decode(key.clientCreationURL))
+        return false;
+    if (!decoder.decode(key.topOrigin))
+        return false;
+
+    return true;
+}
+
 } // namespace WebCore
 
 namespace WTF {

Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp (221391 => 221392)


--- trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -43,7 +43,7 @@
 
 void SWClientConnection::scheduleJob(ServiceWorkerJob& job)
 {
-    auto addResult = m_scheduledJobs.add(job.identifier(), &job);
+    auto addResult = m_scheduledJobs.add(job.data().identifier(), &job);
     ASSERT_UNUSED(addResult, addResult.isNewEntry);
 
     scheduleJobInServer(job.data());
@@ -60,6 +60,17 @@
     job->failedWithException(exceptionData.toException());
 }
 
+void SWClientConnection::jobResolvedInServer(uint64_t jobIdentifier, const ServiceWorkerRegistrationData& registrationData)
+{
+    auto job = m_scheduledJobs.take(jobIdentifier);
+    if (!job) {
+        LOG_ERROR("Job %" PRIu64 " resolved in server, but was not found", jobIdentifier);
+        return;
+    }
+
+    job->resolvedWithRegistration(registrationData);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.h (221391 => 221392)


--- trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -34,6 +34,7 @@
 namespace WebCore {
 
 struct ExceptionData;
+struct ServiceWorkerRegistrationData;
 
 class SWClientConnection : public ThreadSafeRefCounted<SWClientConnection> {
 public:
@@ -46,6 +47,7 @@
 
 protected:
     WEBCORE_EXPORT void jobRejectedInServer(uint64_t jobIdentifier, const ExceptionData&);
+    WEBCORE_EXPORT void jobResolvedInServer(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&);
 
 private:
     virtual void scheduleJobInServer(const ServiceWorkerJobData&) = 0;

Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (221391 => 221392)


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -54,6 +54,9 @@
     RELEASE_ASSERT(m_connections.isEmpty());
     RELEASE_ASSERT(m_registrations.isEmpty());
 
+    ASSERT(m_taskQueue.isEmpty());
+    ASSERT(m_taskReplyQueue.isEmpty());
+
     // For a SWServer to be cleanly shut down its thread must have finished and gone away.
     // At this stage in development of the feature that actually never happens.
     // But once it does start happening, this ASSERT will catch us doing it wrong.
@@ -63,7 +66,7 @@
 
 void SWServer::Connection::scheduleJobInServer(const ServiceWorkerJobData& jobData)
 {
-    LOG(ServiceWorker, "Scheduling ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.jobIdentifier());
+    LOG(ServiceWorker, "Scheduling ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.identifier());
     ASSERT(identifier() == jobData.connectionIdentifier());
 
     m_server.scheduleJob(jobData);
@@ -82,7 +85,7 @@
 
     auto result = m_registrations.add(jobData.registrationKey(), nullptr);
     if (result.isNewEntry)
-        result.iterator->value = std::make_unique<SWServerRegistration>(*this);
+        result.iterator->value = std::make_unique<SWServerRegistration>(*this, jobData.registrationKey());
 
     ASSERT(result.iterator->value);
 
@@ -91,14 +94,24 @@
 
 void SWServer::rejectJob(const ServiceWorkerJobData& jobData, const ExceptionData& exceptionData)
 {
-    LOG(ServiceWorker, "Rejected ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.jobIdentifier());
+    LOG(ServiceWorker, "Rejected ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.identifier());
     auto* connection = m_connections.get(jobData.connectionIdentifier());
     if (!connection)
         return;
 
-    connection->rejectJobInClient(jobData.jobIdentifier(), exceptionData);
+    connection->rejectJobInClient(jobData.identifier(), exceptionData);
 }
 
+void SWServer::resolveJob(const ServiceWorkerJobData& jobData, const ServiceWorkerRegistrationData& registrationData)
+{
+    LOG(ServiceWorker, "Resolved ServiceWorker job %" PRIu64 "-%" PRIu64 " in server with registration %" PRIu64, jobData.connectionIdentifier(), jobData.identifier(), registrationData.identifier);
+    auto* connection = m_connections.get(jobData.connectionIdentifier());
+    if (!connection)
+        return;
+
+    connection->resolveJobInClient(jobData.identifier(), registrationData);
+}
+
 void SWServer::taskThreadEntryPoint()
 {
     ASSERT(!isMainThread());

Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (221391 => 221392)


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -42,6 +42,7 @@
 
 class SWServerRegistration;
 struct ExceptionData;
+struct ServiceWorkerRegistrationData;
 
 class SWServer {
 public:
@@ -60,6 +61,7 @@
 
     private:
         virtual void rejectJobInClient(uint64_t jobIdentifier, const ExceptionData&) = 0;
+        virtual void resolveJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&) = 0;
 
         SWServer& m_server;
         uint64_t m_identifier;
@@ -70,7 +72,7 @@
 
     void scheduleJob(const ServiceWorkerJobData&);
     void rejectJob(const ServiceWorkerJobData&, const ExceptionData&);
-
+    void resolveJob(const ServiceWorkerJobData&, const ServiceWorkerRegistrationData&);
     void postTask(CrossThreadTask&&);
     void postTaskReply(CrossThreadTask&&);
 

Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp (221391 => 221392)


--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -30,12 +30,20 @@
 
 #include "ExceptionData.h"
 #include "SWServer.h"
+#include "SWServerWorker.h"
+#include "SecurityOrigin.h"
+#include "ServiceWorkerRegistrationData.h"
+#include "WorkerType.h"
 
 namespace WebCore {
 
-SWServerRegistration::SWServerRegistration(SWServer& server)
+static std::atomic<uint64_t> currentIdentifier;
+
+SWServerRegistration::SWServerRegistration(SWServer& server, const ServiceWorkerRegistrationKey& key)
     : m_jobTimer(*this, &SWServerRegistration::startNextJob)
     , m_server(server)
+    , m_identifier(++currentIdentifier)
+    , m_registrationKey(key)
 {
 }
 
@@ -65,17 +73,102 @@
     ASSERT(!m_jobQueue.isEmpty());
 
     m_currentJob = std::make_unique<ServiceWorkerJobData>(m_jobQueue.takeFirst().isolatedCopy());
-    m_server.postTask(createCrossThreadTask(*this, &SWServerRegistration::performCurrentJob));
+
+    switch (m_currentJob->type) {
+    case ServiceWorkerJobType::Register:
+        m_server.postTask(createCrossThreadTask(*this, &SWServerRegistration::runRegisterJob, *m_currentJob));
+        return;
+    }
+
+    RELEASE_ASSERT_NOT_REACHED();
 }
 
-void SWServerRegistration::performCurrentJob()
+bool SWServerRegistration::isEmpty()
 {
     ASSERT(!isMainThread());
 
-    auto exception = ExceptionData { UnknownError, ASCIILiteral("serviceWorker job scheduling is not yet implemented") };
+    // Having or not-having an m_updateViaCache flag is currently
+    // the signal as to whether or not this is an empty (i.e. "new") registration.
+    // There will be a more explicit signal in the near future.
+    return !m_updateViaCache;
+}
+
+SWServerWorker* SWServerRegistration::getNewestWorker()
+{
+    ASSERT(!isMainThread());
+    if (m_installingWorker)
+        return m_installingWorker.get();
+    if (m_waitingWorker)
+        return m_waitingWorker.get();
+
+    return m_activeWorker.get();
+}
+
+void SWServerRegistration::runRegisterJob(const ServiceWorkerJobData& job)
+{
+    ASSERT(!isMainThread());
+    ASSERT(job.type == ServiceWorkerJobType::Register);
+
+    if (!shouldTreatAsPotentiallyTrustworthy(job.scriptURL))
+        return rejectWithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Script URL is not potentially trustworthy") });
+
+    // If the origin of job’s script url is not job’s referrer's origin, then:
+    if (!protocolHostAndPortAreEqual(job.scriptURL, job.clientCreationURL))
+        return rejectWithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Script origin does not match the registering client's origin") });
+
+    // If the origin of job’s scope url is not job’s referrer's origin, then:
+    if (!protocolHostAndPortAreEqual(job.scopeURL, job.clientCreationURL))
+        return rejectWithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Scope origin does not match the registering client's origin") });
+
+    // If registration is not null (in our parlance "empty"), then:
+    if (!isEmpty()) {
+        ASSERT(m_updateViaCache);
+
+        m_uninstalling = false;
+        auto* newestWorker = getNewestWorker();
+        if (newestWorker && equalIgnoringFragmentIdentifier(job.scriptURL, newestWorker->scriptURL()) && job.registrationOptions.updateViaCache == *m_updateViaCache) {
+            resolveWithRegistrationOnMainThread();
+            return;
+        }
+    } else {
+        m_scopeURL = job.scopeURL.isolatedCopy();
+        m_scopeURL.removeFragmentIdentifier();
+        m_updateViaCache = job.registrationOptions.updateViaCache;
+    }
+
+    runUpdateJob(job);
+}
+
+void SWServerRegistration::runUpdateJob(const ServiceWorkerJobData& job)
+{
+    // If registration is null (in our parlance "empty") or registration’s uninstalling flag is set, then:
+    if (isEmpty())
+        return rejectWithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a null/nonexistent service worker registration") });
+    if (m_uninstalling)
+        return rejectWithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a service worker registration that is uninstalling") });
+
+    // If job’s job type is update, and newestWorker’s script url does not equal job’s script url with the exclude fragments flag set, then:
+    auto* newestWorker = getNewestWorker();
+    if (newestWorker && !equalIgnoringFragmentIdentifier(job.scriptURL, newestWorker->scriptURL()))
+        return rejectWithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a service worker with a requested script URL whose newest worker has a different script URL") });
+
+    // FIXME: At this point we are ready to actually fetch the script for the worker in the registering context.
+    // For now we're still hard coding the same rejection we have so far.
+    rejectWithExceptionOnMainThread(ExceptionData { UnknownError, ASCIILiteral("serviceWorker job scheduling is not yet implemented") });
+}
+
+void SWServerRegistration::rejectWithExceptionOnMainThread(const ExceptionData& exception)
+{
+    ASSERT(!isMainThread());
     m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::rejectCurrentJob, exception));
 }
 
+void SWServerRegistration::resolveWithRegistrationOnMainThread()
+{
+    ASSERT(!isMainThread());
+    m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::resolveCurrentJob, data()));
+}
+
 void SWServerRegistration::rejectCurrentJob(const ExceptionData& exceptionData)
 {
     ASSERT(isMainThread());
@@ -86,6 +179,16 @@
     finishCurrentJob();
 }
 
+void SWServerRegistration::resolveCurrentJob(const ServiceWorkerRegistrationData& data)
+{
+    ASSERT(isMainThread());
+    ASSERT(m_currentJob);
+
+    m_server.resolveJob(*m_currentJob, data);
+
+    finishCurrentJob();
+}
+
 void SWServerRegistration::finishCurrentJob()
 {
     ASSERT(m_currentJob);
@@ -98,6 +201,12 @@
     startNextJob();
 }
 
+ServiceWorkerRegistrationData SWServerRegistration::data() const
+{
+    return { m_registrationKey, m_identifier };
+}
+
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.h (221391 => 221392)


--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.h	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -28,6 +28,7 @@
 #if ENABLE(SERVICE_WORKER)
 
 #include "ServiceWorkerJobData.h"
+#include "ServiceWorkerRegistrationData.h"
 #include "Timer.h"
 #include <wtf/Deque.h>
 
@@ -34,29 +35,49 @@
 namespace WebCore {
 
 class SWServer;
+class SWServerWorker;
 struct ExceptionData;
 
 class SWServerRegistration {
 public:
-    explicit SWServerRegistration(SWServer&);
+    explicit SWServerRegistration(SWServer&, const ServiceWorkerRegistrationKey&);
     SWServerRegistration(const SWServerRegistration&) = delete;
     ~SWServerRegistration();
 
     void enqueueJob(const ServiceWorkerJobData&);
 
+    uint64_t identifier() const { return m_identifier; }
+    ServiceWorkerRegistrationData data() const;
+
 private:
     void jobTimerFired();
-    void performCurrentJob();
+    void startNextJob();
     void rejectCurrentJob(const ExceptionData&);
-
-    void startNextJob();
+    void resolveCurrentJob(const ServiceWorkerRegistrationData&);
     void finishCurrentJob();
 
+    void runRegisterJob(const ServiceWorkerJobData&);
+    void runUpdateJob(const ServiceWorkerJobData&);
+
+    void rejectWithExceptionOnMainThread(const ExceptionData&);
+    void resolveWithRegistrationOnMainThread();
+    bool isEmpty();
+    SWServerWorker* getNewestWorker();
+
     Deque<ServiceWorkerJobData> m_jobQueue;
     std::unique_ptr<ServiceWorkerJobData> m_currentJob;
 
+    bool m_uninstalling { false };
+    std::unique_ptr<SWServerWorker> m_installingWorker;
+    std::unique_ptr<SWServerWorker> m_waitingWorker;
+    std::unique_ptr<SWServerWorker> m_activeWorker;
+    URL m_scopeURL;
+    std::optional<ServiceWorkerUpdateViaCache> m_updateViaCache;
+
     Timer m_jobTimer;
     SWServer& m_server;
+    uint64_t m_identifier;
+    ServiceWorkerRegistrationKey m_registrationKey;
 };
 
 } // namespace WebCore

Copied: trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp (from rev 221388, trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h) (0 => 221392)


--- trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SWServerWorker.h"
+
+#if ENABLE(SERVICE_WORKER)
+
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+SWServerWorker::SWServerWorker(const URL& url)
+    : m_scriptURL(url)
+{
+    ASSERT(!isMainThread());
+}
+
+SWServerWorker::~SWServerWorker()
+{
+    ASSERT(!isMainThread());
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)

Copied: trunk/Source/WebCore/workers/service/server/SWServerWorker.h (from rev 221388, trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h) (0 => 221392)


--- trunk/Source/WebCore/workers/service/server/SWServerWorker.h	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "URL.h"
+
+namespace WebCore {
+
+class SWServerWorker {
+public:
+    SWServerWorker(const URL&);
+    SWServerWorker(const SWServerWorker&) = delete;
+    ~SWServerWorker();
+    const URL& scriptURL() const { return m_scriptURL; }
+
+private:
+    URL m_scriptURL;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebKit/ChangeLog (221391 => 221392)


--- trunk/Source/WebKit/ChangeLog	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebKit/ChangeLog	2017-08-30 19:40:35 UTC (rev 221392)
@@ -1,3 +1,15 @@
+2017-08-30  Brady Eidson  <beid...@apple.com>
+
+        Implement all of "Register" right up until where the script is fetched.
+        https://bugs.webkit.org/show_bug.cgi?id=176082
+
+        Reviewed by Andy Estes.
+
+        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::resolveJobInClient):
+        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+        * WebProcess/Storage/WebSWClientConnection.messages.in:
+
 2017-08-30  Andy Estes  <aes...@apple.com>
 
         [Mac] Upstream Accessibility-related WebKitSystemInterface functions

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp (221391 => 221392)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp	2017-08-30 19:40:35 UTC (rev 221392)
@@ -65,6 +65,11 @@
     send(Messages::WebSWClientConnection::JobRejectedInServer(jobIdentifier, exceptionData));
 }
 
+void WebSWServerConnection::resolveJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData& registrationData)
+{
+    send(Messages::WebSWClientConnection::JobResolvedInServer(jobIdentifier, registrationData));
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h (221391 => 221392)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h	2017-08-30 19:40:35 UTC (rev 221392)
@@ -50,6 +50,7 @@
 private:
     // Implement SWServer::Connection
     void rejectJobInClient(uint64_t jobIdentifier, const WebCore::ExceptionData&) final;
+    void resolveJobInClient(uint64_t jobIdentifier, const WebCore::ServiceWorkerRegistrationData&) final;
 
     IPC::Connection* messageSenderConnection() final { return m_connection.ptr(); }
     uint64_t messageSenderDestinationID() final { return identifier(); }

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in (221391 => 221392)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in	2017-08-30 19:10:22 UTC (rev 221391)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in	2017-08-30 19:40:35 UTC (rev 221392)
@@ -25,6 +25,7 @@
 messages -> WebSWClientConnection {
     # When possible, these messages can be implemented directly by WebCore::SWServer::Connection
     JobRejectedInServer(uint64_t identifier, struct WebCore::ExceptionData exception)
+    JobResolvedInServer(uint64_t identifier, struct WebCore::ServiceWorkerRegistrationData registration)
 }
 
 #endif // ENABLE(SERVICE_WORKER)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to