Source/WebCore/ChangeLog

 12017-08-24 Brady Eidson <beidson@apple.com>
 2
 3 Introduce ServerWorkerRegistration task queues.
 4 https://bugs.webkit.org/show_bug.cgi?id=175851
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Test: http/tests/workers/service/registration-task-queue-scheduling-1.html
 9
 10 This change introduces:
 11 - A task thread/queue owned by each SWServer object.
 12 - The SWServerRegistration object, which is the in-server representation of a
 13 service worker registration scope.
 14 - A registration job queue per SWServerRegistration object which actually runs the
 15 jobs as tasks on the owning SWServer's thread.
 16
 17 With that infrastructure in place, it moves the "register" job to something that is
 18 scheduled and rejected asynchronously, as opposed to synchronously rejected.
 19
 20 The test verifies that two different registration scopes (localhost and 127.0.0.1)
 21 can both spam the SWServer with registration requests, but neither of their queues
 22 starve the other.
 23
 24 The rest of this change is a lot of support and plumbing for making the above happen.
 25
 26 * CMakeLists.txt:
 27 * WebCore.xcodeproj/project.pbxproj:
 28
 29 * dom/ExceptionData.cpp:
 30 (WebCore::ExceptionData::isolatedCopy const):
 31 * dom/ExceptionData.h:
 32
 33 * workers/service/ServiceWorkerContainer.cpp:
 34 (WebCore::ServiceWorkerContainer::addRegistration):
 35 (WebCore::ServiceWorkerContainer::connectionIdentifier):
 36 * workers/service/ServiceWorkerContainer.h:
 37
 38 * workers/service/ServiceWorkerJob.cpp:
 39 (WebCore::ServiceWorkerJob::ServiceWorkerJob):
 40 (WebCore::ServiceWorkerJob::data const): Deleted.
 41 * workers/service/ServiceWorkerJob.h:
 42 (WebCore::ServiceWorkerJob::create):
 43 (WebCore::ServiceWorkerJob::data const):
 44 (WebCore::ServiceWorkerJob::createRegisterJob): Deleted.
 45
 46 * workers/service/ServiceWorkerJobClient.h:
 47
 48 * workers/service/ServiceWorkerJobData.cpp:
 49 (WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
 50 (WebCore::ServiceWorkerJobData::registrationKey const):
 51 (WebCore::ServiceWorkerJobData::isolatedCopy const):
 52 * workers/service/ServiceWorkerJobData.h:
 53 (WebCore::ServiceWorkerJobData::jobIdentifier const):
 54 (WebCore::ServiceWorkerJobData::connectionIdentifier const):
 55 (WebCore::ServiceWorkerJobData::encode const):
 56 (WebCore::ServiceWorkerJobData::decode):
 57
 58 * workers/service/ServiceWorkerRegistrationKey.cpp:
 59 (WebCore::ServiceWorkerRegistrationKey::emptyKey):
 60 (WebCore::ServiceWorkerRegistrationKey::hash const):
 61 (WebCore::ServiceWorkerRegistrationKey::operator== const):
 62 * workers/service/ServiceWorkerRegistrationKey.h:
 63 (WTF::ServiceWorkerRegistrationKeyHash::hash):
 64 (WTF::ServiceWorkerRegistrationKeyHash::equal):
 65 (WTF::HashTraits<WebCore::ServiceWorkerRegistrationKey>::emptyValue):
 66 (WTF::HashTraits<WebCore::ServiceWorkerRegistrationKey>::constructDeletedValue):
 67 (WTF::HashTraits<WebCore::ServiceWorkerRegistrationKey>::isDeletedValue):
 68
 69 * workers/service/ServiceWorkerRegistrationOptions.cpp:
 70 (WebCore::RegistrationOptions::isolatedCopy const):
 71 * workers/service/ServiceWorkerRegistrationOptions.h:
 72 (WebCore::RegistrationOptions::encode const):
 73 (WebCore::RegistrationOptions::decode):
 74
 75 * workers/service/server/SWClientConnection.h:
 76
 77 * workers/service/server/SWServer.cpp:
 78 (WebCore::SWServer::Connection::Connection):
 79 (WebCore::SWServer::~SWServer):
 80 (WebCore::SWServer::Connection::scheduleJobInServer):
 81 (WebCore::SWServer::SWServer):
 82 (WebCore::SWServer::scheduleJob):
 83 (WebCore::SWServer::rejectJob):
 84 (WebCore::SWServer::taskThreadEntryPoint):
 85 (WebCore::SWServer::postTask):
 86 (WebCore::SWServer::postTaskReply):
 87 (WebCore::SWServer::handleTaskRepliesOnMainThread):
 88 (WebCore::SWServer::registerConnection):
 89 (WebCore::SWServer::unregisterConnection):
 90 * workers/service/server/SWServer.h:
 91 (WebCore::SWServer::Connection::identifier const):
 92
 93 * workers/service/server/SWServerRegistration.cpp: Added.
 94 (WebCore::SWServerRegistration::SWServerRegistration):
 95 (WebCore::SWServerRegistration::~SWServerRegistration):
 96 (WebCore::SWServerRegistration::enqueueJob):
 97 (WebCore::SWServerRegistration::startNextJob):
 98 (WebCore::SWServerRegistration::performCurrentJob):
 99 (WebCore::SWServerRegistration::rejectCurrentJob):
 100 (WebCore::SWServerRegistration::finishCurrentJob):
 101 * workers/service/server/SWServerRegistration.h:
 102
11032017-08-24 Ryan Haddad <ryanhaddad@apple.com>
2104
3105 Unreviewed, rolling out r221139.

Source/WebKit/ChangeLog

 12017-08-24 Brady Eidson <beidson@apple.com>
 2
 3 Introduce ServerWorkerRegistration task queues.
 4 https://bugs.webkit.org/show_bug.cgi?id=175851
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
 9 (WebKit::WebSWServerConnection::WebSWServerConnection):
 10 * StorageProcess/ServiceWorker/WebSWServerConnection.h:
 11 (WebKit::WebSWServerConnection::identifier const): Deleted.
 12
 13 * WebProcess/Storage/WebSWClientConnection.h:
 14 (WebKit::WebSWClientConnection::identifier const): Deleted.
 15
1162017-08-24 Youenn Fablet <youenn@apple.com>
217
318 [Cache API] UIProcess should provide the directory path where to store Cache Storage data

Source/WebCore/CMakeLists.txt

@@set(WebCore_SOURCES
15451545 dom/EventNames.cpp
15461546 dom/EventPath.cpp
15471547 dom/EventTarget.cpp
 1548 dom/ExceptionData.cpp
15481549 dom/ExtensionStyleSheets.cpp
15491550 dom/FocusEvent.cpp
15501551 dom/GenericEventQueue.cpp

@@set(WebCore_SOURCES
29892990 workers/service/ServiceWorkerContainer.cpp
29902991 workers/service/ServiceWorkerGlobalScope.cpp
29912992 workers/service/ServiceWorkerJob.cpp
 2993 workers/service/ServiceWorkerJobData.cpp
29922994 workers/service/ServiceWorkerProvider.cpp
29932995 workers/service/ServiceWorkerRegistration.cpp
2994  workers/service/ServiceWorkerRegistrationParameters.cpp
 2996 workers/service/ServiceWorkerRegistrationKey.cpp
 2997 workers/service/ServiceWorkerRegistrationOptions.cpp
29952998
29962999 workers/service/server/SWClientConnection.cpp
29973000 workers/service/server/SWServer.cpp
 3001 workers/service/server/SWServerRegistration.cpp
29983002
29993003 xml/DOMParser.cpp
30003004 xml/NativeXPathNSResolver.cpp

Source/WebCore/WebCore.xcodeproj/project.pbxproj

22972297 517A52F11F4754E700DCDC0A /* SWServer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A52EF1F47535900DCDC0A /* SWServer.cpp */; };
22982298 517A531C1F4B53B100DCDC0A /* SWClientConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A52FE1F478CCE00DCDC0A /* SWClientConnection.cpp */; };
22992299 517A531D1F4B53B100DCDC0A /* SWClientConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A52FF1F478CCE00DCDC0A /* SWClientConnection.h */; settings = {ATTRIBUTES = (Private, ); }; };
 2300 517A53251F4B905500DCDC0A /* ServiceWorkerJobData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53241F4B904A00DCDC0A /* ServiceWorkerJobData.cpp */; };
 2301 517A53281F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */; };
 2302 517A53291F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */; settings = {ATTRIBUTES = (Private, ); }; };
23002303 517A63C31B74318700E7DCDC /* KeyedDecoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */; };
23012304 517A63C41B74318B00E7DCDC /* KeyedEncoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63C11B74317E00E7DCDC /* KeyedEncoderCF.cpp */; };
23022305 517A63C51B74318F00E7DCDC /* KeyedDecoderCF.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */; settings = {ATTRIBUTES = (Private, ); }; };

24642467 51F175661F3EBC8300C74950 /* ServiceWorkerProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F1754E1F3EBC0C00C74950 /* ServiceWorkerProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
24652468 51F175671F3EBC8300C74950 /* ServiceWorkerRegistration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F1754D1F3EBC0C00C74950 /* ServiceWorkerRegistration.cpp */; };
24662469 51F175681F3EBC8300C74950 /* ServiceWorkerRegistration.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F1754C1F3EBC0C00C74950 /* ServiceWorkerRegistration.h */; };
2467  51F175691F3EBC8300C74950 /* ServiceWorkerRegistrationOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F1754A1F3EBC0C00C74950 /* ServiceWorkerRegistrationOptions.h */; };
2468  51F1756A1F3EBC8300C74950 /* ServiceWorkerRegistrationParameters.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F175491F3EBC0C00C74950 /* ServiceWorkerRegistrationParameters.cpp */; };
2469  51F1756B1F3EBC8300C74950 /* ServiceWorkerRegistrationParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F175481F3EBC0C00C74950 /* ServiceWorkerRegistrationParameters.h */; };
 2470 51F175691F3EBC8300C74950 /* ServiceWorkerRegistrationOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F1754A1F3EBC0C00C74950 /* ServiceWorkerRegistrationOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
24702471 51F1756C1F3EBC8300C74950 /* ServiceWorkerUpdateViaCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F175471F3EBC0C00C74950 /* ServiceWorkerUpdateViaCache.h */; };
24712472 51F645621F45398F00B54DED /* ExceptionData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F645601F45398B00B54DED /* ExceptionData.h */; settings = {ATTRIBUTES = (Private, ); }; };
24722473 51F645691F4539B900B54DED /* ServiceWorkerJobData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F645661F45399F00B54DED /* ServiceWorkerJobData.h */; settings = {ATTRIBUTES = (Private, ); }; };
24732474 51F6456A1F4539C000B54DED /* ServiceWorkerJobType.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F645651F45399F00B54DED /* ServiceWorkerJobType.h */; settings = {ATTRIBUTES = (Private, ); }; };
 2475 51F645961F4A686F00B54DED /* SWServerRegistration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F645951F4A686100B54DED /* SWServerRegistration.cpp */; };
 2476 51F645971F4A686F00B54DED /* SWServerRegistration.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F645941F4A684F00B54DED /* SWServerRegistration.h */; settings = {ATTRIBUTES = (Private, ); }; };
 2477 51F645A21F4BF53C00B54DED /* ServiceWorkerRegistrationOptions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F645A01F4BF51600B54DED /* ServiceWorkerRegistrationOptions.cpp */; };
 2478 51F645A41F4C001700B54DED /* ExceptionData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F645A31F4C000C00B54DED /* ExceptionData.cpp */; };
24742479 51F798EF1BE880E7008AE491 /* IDBIndexInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F798EB1BE880D3008AE491 /* IDBIndexInfo.cpp */; };
24752480 51F798F01BE880E7008AE491 /* IDBIndexInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F798EC1BE880D3008AE491 /* IDBIndexInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
24762481 51F886C01F32923100C193EF /* JSNavigatorServiceWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F886BF1F32920700C193EF /* JSNavigatorServiceWorker.h */; };

1007210077 517A52EF1F47535900DCDC0A /* SWServer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWServer.cpp; sourceTree = "<group>"; };
1007310078 517A52FE1F478CCE00DCDC0A /* SWClientConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWClientConnection.cpp; sourceTree = "<group>"; };
1007410079 517A52FF1F478CCE00DCDC0A /* SWClientConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWClientConnection.h; sourceTree = "<group>"; };
 10080 517A53241F4B904A00DCDC0A /* ServiceWorkerJobData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerJobData.cpp; sourceTree = "<group>"; };
 10081 517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationKey.h; sourceTree = "<group>"; };
 10082 517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationKey.cpp; sourceTree = "<group>"; };
1007510083 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedDecoderCF.cpp; sourceTree = "<group>"; };
1007610084 517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyedDecoderCF.h; sourceTree = "<group>"; };
1007710085 517A63C11B74317E00E7DCDC /* KeyedEncoderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedEncoderCF.cpp; sourceTree = "<group>"; };

1022510233 51F175051F358BDE00C74950 /* JSWorkerType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWorkerType.h; sourceTree = "<group>"; };
1022610234 51F175461F3EBC0C00C74950 /* ServiceWorkerUpdateViaCache.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ServiceWorkerUpdateViaCache.idl; sourceTree = "<group>"; };
1022710235 51F175471F3EBC0C00C74950 /* ServiceWorkerUpdateViaCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerUpdateViaCache.h; sourceTree = "<group>"; };
10228  51F175481F3EBC0C00C74950 /* ServiceWorkerRegistrationParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationParameters.h; sourceTree = "<group>"; };
10229  51F175491F3EBC0C00C74950 /* ServiceWorkerRegistrationParameters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationParameters.cpp; sourceTree = "<group>"; };
1023010236 51F1754A1F3EBC0C00C74950 /* ServiceWorkerRegistrationOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationOptions.h; sourceTree = "<group>"; };
1023110237 51F1754B1F3EBC0C00C74950 /* ServiceWorkerRegistration.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ServiceWorkerRegistration.idl; sourceTree = "<group>"; };
1023210238 51F1754C1F3EBC0C00C74950 /* ServiceWorkerRegistration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistration.h; sourceTree = "<group>"; };

1024810254 51F645601F45398B00B54DED /* ExceptionData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExceptionData.h; sourceTree = "<group>"; };
1024910255 51F645651F45399F00B54DED /* ServiceWorkerJobType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerJobType.h; sourceTree = "<group>"; };
1025010256 51F645661F45399F00B54DED /* ServiceWorkerJobData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerJobData.h; sourceTree = "<group>"; };
 10257 51F645941F4A684F00B54DED /* SWServerRegistration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWServerRegistration.h; sourceTree = "<group>"; };
 10258 51F645951F4A686100B54DED /* SWServerRegistration.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWServerRegistration.cpp; sourceTree = "<group>"; };
 10259 51F645A01F4BF51600B54DED /* ServiceWorkerRegistrationOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationOptions.cpp; sourceTree = "<group>"; };
 10260 51F645A31F4C000C00B54DED /* ExceptionData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExceptionData.cpp; sourceTree = "<group>"; };
1025110261 51F6A3D50663BF04004D2919 /* HTMLCanvasElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLCanvasElement.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
1025210262 51F6A3D60663BF04004D2919 /* HTMLCanvasElement.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = HTMLCanvasElement.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
1025310263 51F798EB1BE880D3008AE491 /* IDBIndexInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBIndexInfo.cpp; sourceTree = "<group>"; };

1865518665 517A52FF1F478CCE00DCDC0A /* SWClientConnection.h */,
1865618666 517A52EF1F47535900DCDC0A /* SWServer.cpp */,
1865718667 517A52EE1F47535900DCDC0A /* SWServer.h */,
 18668 51F645951F4A686100B54DED /* SWServerRegistration.cpp */,
 18669 51F645941F4A684F00B54DED /* SWServerRegistration.h */,
1865818670 );
1865918671 path = server;
1866018672 sourceTree = "<group>";

1875218764 51F175521F3EBC0C00C74950 /* ServiceWorkerJob.cpp */,
1875318765 51F175511F3EBC0C00C74950 /* ServiceWorkerJob.h */,
1875418766 51F175501F3EBC0C00C74950 /* ServiceWorkerJobClient.h */,
 18767 517A53241F4B904A00DCDC0A /* ServiceWorkerJobData.cpp */,
1875518768 51F645661F45399F00B54DED /* ServiceWorkerJobData.h */,
1875618769 51F645651F45399F00B54DED /* ServiceWorkerJobType.h */,
1875718770 51F1754F1F3EBC0C00C74950 /* ServiceWorkerProvider.cpp */,

1875918772 51F1754D1F3EBC0C00C74950 /* ServiceWorkerRegistration.cpp */,
1876018773 51F1754C1F3EBC0C00C74950 /* ServiceWorkerRegistration.h */,
1876118774 51F1754B1F3EBC0C00C74950 /* ServiceWorkerRegistration.idl */,
 18775 517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */,
 18776 517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */,
 18777 51F645A01F4BF51600B54DED /* ServiceWorkerRegistrationOptions.cpp */,
1876218778 51F1754A1F3EBC0C00C74950 /* ServiceWorkerRegistrationOptions.h */,
18763  51F175491F3EBC0C00C74950 /* ServiceWorkerRegistrationParameters.cpp */,
18764  51F175481F3EBC0C00C74950 /* ServiceWorkerRegistrationParameters.h */,
1876518779 51F175471F3EBC0C00C74950 /* ServiceWorkerUpdateViaCache.h */,
1876618780 51F175461F3EBC0C00C74950 /* ServiceWorkerUpdateViaCache.idl */,
1876718781 );

2586925883 CDCE5CD014633BC900D47CCA /* EventTargetFactory.in */,
2587025884 93D196321D6CAB8200FC7E47 /* Exception.h */,
2587125885 935FBCF109BA143B00E230B1 /* ExceptionCode.h */,
 25886 51F645A31F4C000C00B54DED /* ExceptionData.cpp */,
2587225887 51F645601F45398B00B54DED /* ExceptionData.h */,
2587325888 93D196301D6CAB7600FC7E47 /* ExceptionOr.h */,
2587425889 E47E276716036EDC00EE2AFB /* ExtensionStyleSheets.cpp */,

2951929534 51F6456A1F4539C000B54DED /* ServiceWorkerJobType.h in Headers */,
2952029535 51F175661F3EBC8300C74950 /* ServiceWorkerProvider.h in Headers */,
2952129536 51F175681F3EBC8300C74950 /* ServiceWorkerRegistration.h in Headers */,
 29537 517A53291F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.h in Headers */,
2952229538 51F175691F3EBC8300C74950 /* ServiceWorkerRegistrationOptions.h in Headers */,
29523  51F1756B1F3EBC8300C74950 /* ServiceWorkerRegistrationParameters.h in Headers */,
2952429539 51F1756C1F3EBC8300C74950 /* ServiceWorkerUpdateViaCache.h in Headers */,
2952529540 93309E10099E64920056E581 /* SetNodeAttributeCommand.h in Headers */,
2952629541 B8DBDB4C130B0F8A00F5CDB1 /* SetSelectionCommand.h in Headers */,

2993929954 B2E4EC980D00C22B00432643 /* SVGZoomEvent.h in Headers */,
2994029955 517A531D1F4B53B100DCDC0A /* SWClientConnection.h in Headers */,
2994129956 517A52F01F47535B00DCDC0A /* SWServer.h in Headers */,
 29957 51F645971F4A686F00B54DED /* SWServerRegistration.h in Headers */,
2994229958 E180811716FCF9CB00B80D07 /* SynchronousLoaderClient.h in Headers */,
2994329959 26FAE4CF1852E3A5004C8C46 /* SynchronousResourceHandleCFURLConnectionDelegate.h in Headers */,
2994429960 0F03C0741884695E00A5F8CA /* SystemMemory.h in Headers */,

3134931365 E0FEF372B27C53EAC1C1FBEE /* EventSource.cpp in Sources */,
3135031366 E12EDBEA0B308E0B002704B6 /* EventTarget.cpp in Sources */,
3135131367 262EC41D1D110B9000BA78FC /* EventTrackingRegions.cpp in Sources */,
 31368 51F645A41F4C001700B54DED /* ExceptionData.cpp in Sources */,
3135231369 724ED32C1A3A7E5400F5F13C /* EXTBlendMinMax.cpp in Sources */,
3135331370 31DCDF431DA1C45400EA5B93 /* ExtendedColor.cpp in Sources */,
3135431371 6E67D2A61280E8A4008758F7 /* Extensions3DOpenGL.cpp in Sources */,

3338633403 51F1755E1F3EBC8300C74950 /* ServiceWorkerContainer.cpp in Sources */,
3338733404 51F175601F3EBC8300C74950 /* ServiceWorkerGlobalScope.cpp in Sources */,
3338833405 51F175621F3EBC8300C74950 /* ServiceWorkerJob.cpp in Sources */,
 33406 517A53251F4B905500DCDC0A /* ServiceWorkerJobData.cpp in Sources */,
3338933407 51F175651F3EBC8300C74950 /* ServiceWorkerProvider.cpp in Sources */,
3339033408 51F175671F3EBC8300C74950 /* ServiceWorkerRegistration.cpp in Sources */,
33391  51F1756A1F3EBC8300C74950 /* ServiceWorkerRegistrationParameters.cpp in Sources */,
 33409 517A53281F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.cpp in Sources */,
 33410 51F645A21F4BF53C00B54DED /* ServiceWorkerRegistrationOptions.cpp in Sources */,
3339233411 93309E0F099E64920056E581 /* SetNodeAttributeCommand.cpp in Sources */,
3339333412 B8DBDB4B130B0F8A00F5CDB1 /* SetSelectionCommand.cpp in Sources */,
3339433413 14C9A5EA0B3D105F005A0232 /* Settings.cpp in Sources */,

3369333712 B2E4EC970D00C22B00432643 /* SVGZoomEvent.cpp in Sources */,
3369433713 517A531C1F4B53B100DCDC0A /* SWClientConnection.cpp in Sources */,
3369533714 517A52F11F4754E700DCDC0A /* SWServer.cpp in Sources */,
 33715 51F645961F4A686F00B54DED /* SWServerRegistration.cpp in Sources */,
3369633716 E180811216FCF42F00B80D07 /* SynchronousLoaderClient.cpp in Sources */,
3369733717 E180811616FCF9CB00B80D07 /* SynchronousLoaderClient.mm in Sources */,
3369833718 442ABCD617D9262F00D30715 /* SynchronousLoaderClientCFNet.cpp in Sources */,

Source/WebCore/dom/ExceptionData.cpp

 1/*
 2 * Copyright (C) 2017 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "ExceptionData.h"
 28
 29namespace WebCore {
 30
 31ExceptionData ExceptionData::isolatedCopy() const
 32{
 33 ExceptionData result;
 34 result.code = code;
 35 result.message = message.isolatedCopy();
 36
 37 return result;
 38}
 39
 40} // namespace WebCore

Source/WebCore/dom/ExceptionData.h

@@struct ExceptionData {
3434 ExceptionCode code;
3535 String message;
3636
 37 ExceptionData isolatedCopy() const;
 38
3739 template<class Encoder> void encode(Encoder&) const;
3840 template<class Decoder> static bool decode(Decoder&, ExceptionData&);
3941

Source/WebCore/workers/service/ServiceWorkerContainer.cpp

3434#include "ScriptExecutionContext.h"
3535#include "SecurityOrigin.h"
3636#include "ServiceWorkerJob.h"
 37#include "ServiceWorkerJobData.h"
3738#include "ServiceWorkerProvider.h"
38 #include "ServiceWorkerRegistrationParameters.h"
3939#include "URL.h"
4040#include <wtf/RunLoop.h>
4141

@@void ServiceWorkerContainer::addRegistration(const String& relativeScriptURL, co
8888 return;
8989 }
9090
91  ServiceWorkerRegistrationParameters parameters;
92  parameters.scriptURL = context->completeURL(relativeScriptURL);
93  if (!parameters.scriptURL.isValid()) {
 91 ServiceWorkerJobData jobData(m_swConnection->identifier());
 92
 93 jobData.scriptURL = context->completeURL(relativeScriptURL);
 94 if (!jobData.scriptURL.isValid()) {
9495 promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() must be called with a valid relative script URL") });
9596 return;
9697 }
9798
9899 // FIXME: The spec disallows scripts outside of HTTP(S), but we'll likely support app custom URL schemes in WebKit.
99  if (!parameters.scriptURL.protocolIsInHTTPFamily()) {
 100 if (!jobData.scriptURL.protocolIsInHTTPFamily()) {
100101 promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() must be called with a script URL whose protocol is either HTTP or HTTPS") });
101102 return;
102103 }
103104
104  String path = parameters.scriptURL.path();
 105 String path = jobData.scriptURL.path();
105106 if (path.containsIgnoringASCIICase("%2f") || path.containsIgnoringASCIICase("%5c")) {
106107 promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() must be called with a script URL whose path does not contain '%%2f' or '%%5c'") });
107108 return;

@@void ServiceWorkerContainer::addRegistration(const String& relativeScriptURL, co
109110
110111 String scope = options.scope.isEmpty() ? ASCIILiteral("./") : options.scope;
111112 if (!scope.isEmpty())
112  parameters.scopeURL = context->completeURL(scope);
 113 jobData.scopeURL = context->completeURL(scope);
113114
114  parameters.clientCreationURL = context->url();
115  parameters.topOrigin = SecurityOriginData::fromSecurityOrigin(context->topOrigin());
116  parameters.options = options;
 115 jobData.clientCreationURL = context->url();
 116 jobData.topOrigin = SecurityOriginData::fromSecurityOrigin(context->topOrigin());
 117 jobData.type = ServiceWorkerJobType::Register;
 118 jobData.registrationOptions = std::make_unique<RegistrationOptions>(options);
117119
118  scheduleJob(ServiceWorkerJob::createRegisterJob(*this, WTFMove(promise), WTFMove(parameters)));
 120 scheduleJob(ServiceWorkerJob::create(*this, WTFMove(promise), WTFMove(jobData)));
119121}
120122
121123void ServiceWorkerContainer::scheduleJob(Ref<ServiceWorkerJob>&& job)

@@void ServiceWorkerContainer::jobDidFinish(ServiceWorkerJob& job)
149151 ASSERT_UNUSED(taken, taken.get() == &job);
150152}
151153
 154uint64_t ServiceWorkerContainer::connectionIdentifier()
 155{
 156 ASSERT(m_swConnection);
 157 return m_swConnection->identifier();
 158}
 159
152160const char* ServiceWorkerContainer::activeDOMObjectName() const
153161{
154162 return "ServiceWorkerContainer";

Source/WebCore/workers/service/ServiceWorkerContainer.h

@@public:
7171private:
7272 void scheduleJob(Ref<ServiceWorkerJob>&&);
7373 void jobDidFinish(ServiceWorkerJob&) final;
 74 uint64_t connectionIdentifier() final;
7475
7576 const char* activeDOMObjectName() const final;
7677 bool canSuspendForDocumentSuspension() const final;

Source/WebCore/workers/service/ServiceWorkerJob.cpp

3030
3131#include "JSDOMPromiseDeferred.h"
3232#include "ServiceWorkerJobData.h"
33 #include "ServiceWorkerRegistrationParameters.h"
3433
3534namespace WebCore {
3635
3736static std::atomic<uint64_t> currentIdentifier;
3837
39 ServiceWorkerJob::ServiceWorkerJob(ServiceWorkerJobClient& client, Ref<DeferredPromise>&& promise, ServiceWorkerRegistrationParameters&& parameters)
 38ServiceWorkerJob::ServiceWorkerJob(ServiceWorkerJobClient& client, Ref<DeferredPromise>&& promise, ServiceWorkerJobData&& jobData)
4039 : m_client(client)
 40 , m_jobData(WTFMove(jobData))
4141 , m_promise(WTFMove(promise))
4242 , m_identifier(++currentIdentifier)
4343{
44  m_registrationParameters = std::make_unique<ServiceWorkerRegistrationParameters>(WTFMove(parameters));
4544}
4645
4746ServiceWorkerJob::~ServiceWorkerJob()

@@void ServiceWorkerJob::failedWithException(const Exception& exception)
6160 m_client->jobDidFinish(*this);
6261}
6362
64 ServiceWorkerJobData ServiceWorkerJob::data() const
65 {
66  return { m_identifier, m_type };
67 }
68 
6963} // namespace WebCore
7064
7165#endif // ENABLE(SERVICE_WORKER)

Source/WebCore/workers/service/ServiceWorkerJob.h

2828#if ENABLE(SERVICE_WORKER)
2929
3030#include "ServiceWorkerJobClient.h"
 31#include "ServiceWorkerJobData.h"
3132#include <wtf/RefPtr.h>
3233#include <wtf/RunLoop.h>
3334#include <wtf/ThreadSafeRefCounted.h>

@@namespace WebCore {
3839class DeferredPromise;
3940class Exception;
4041enum class ServiceWorkerJobType;
41 struct ServiceWorkerJobData;
42 struct ServiceWorkerRegistrationParameters;
4342
4443class ServiceWorkerJob : public ThreadSafeRefCounted<ServiceWorkerJob> {
4544public:
46  static Ref<ServiceWorkerJob> createRegisterJob(ServiceWorkerJobClient& client, Ref<DeferredPromise>&& promise, ServiceWorkerRegistrationParameters&& parameters)
 45 static Ref<ServiceWorkerJob> create(ServiceWorkerJobClient& client, Ref<DeferredPromise>&& promise, ServiceWorkerJobData&& jobData)
4746 {
48  return adoptRef(*new ServiceWorkerJob(client, WTFMove(promise), WTFMove(parameters)));
 47 return adoptRef(*new ServiceWorkerJob(client, WTFMove(promise), WTFMove(jobData)));
4948 }
5049
5150 WEBCORE_EXPORT ~ServiceWorkerJob();

@@public:
5453
5554 uint64_t identifier() const { return m_identifier; }
5655
57  ServiceWorkerJobData data() const;
 56 ServiceWorkerJobData data() const { return m_jobData; }
5857
5958private:
60  ServiceWorkerJob(ServiceWorkerJobClient&, Ref<DeferredPromise>&&, ServiceWorkerRegistrationParameters&&);
 59 ServiceWorkerJob(ServiceWorkerJobClient&, Ref<DeferredPromise>&&, ServiceWorkerJobData&&);
6160
6261 Ref<ServiceWorkerJobClient> m_client;
63  std::unique_ptr<ServiceWorkerRegistrationParameters> m_registrationParameters;
 62 ServiceWorkerJobData m_jobData;
6463 Ref<DeferredPromise> m_promise;
6564
6665 bool m_completed { false };
6766 uint64_t m_identifier;
6867
69  ServiceWorkerJobType m_type;
70 
7168 Ref<RunLoop> m_runLoop { RunLoop::current() };
7269
7370#if !ASSERT_DISABLED

Source/WebCore/workers/service/ServiceWorkerJobClient.h

@@public:
3636 virtual ~ServiceWorkerJobClient() { };
3737
3838 virtual void jobDidFinish(ServiceWorkerJob&) = 0;
 39 virtual uint64_t connectionIdentifier() = 0;
3940
4041 virtual void ref() = 0;
4142 virtual void deref() = 0;

Source/WebCore/workers/service/ServiceWorkerJobData.cpp

 1/*
 2 * Copyright (C) 2017 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "ServiceWorkerJobData.h"
 28
 29#if ENABLE(SERVICE_WORKER)
 30
 31namespace WebCore {
 32
 33static std::atomic<uint64_t> currentJobIdentifier;
 34
 35ServiceWorkerJobData::ServiceWorkerJobData(uint64_t connectionIdentifier)
 36 : m_jobIdentifier(++currentJobIdentifier)
 37 , m_connectionIdentifier(connectionIdentifier)
 38{
 39}
 40
 41ServiceWorkerJobData::ServiceWorkerJobData(const ServiceWorkerJobData& other)
 42{
 43 m_jobIdentifier = other.m_jobIdentifier;
 44 m_connectionIdentifier = other.m_connectionIdentifier;
 45 scriptURL = other.scriptURL;
 46 clientCreationURL = other.clientCreationURL;
 47 topOrigin = other.topOrigin;
 48 scopeURL = other.scopeURL;
 49 type = other.type;
 50
 51 if (other.registrationOptions)
 52 registrationOptions = std::make_unique<RegistrationOptions>(*other.registrationOptions);
 53}
 54
 55ServiceWorkerRegistrationKey ServiceWorkerJobData::registrationKey() const
 56{
 57 return { clientCreationURL, topOrigin };
 58}
 59
 60ServiceWorkerJobData ServiceWorkerJobData::isolatedCopy() const
 61{
 62 ServiceWorkerJobData result;
 63 result.m_jobIdentifier = m_jobIdentifier;
 64 result.m_connectionIdentifier = m_connectionIdentifier;
 65 result.type = type;
 66
 67 result.scriptURL = scriptURL.isolatedCopy();
 68 result.clientCreationURL = clientCreationURL.isolatedCopy();
 69 result.topOrigin = topOrigin.isolatedCopy();
 70 result.scopeURL = scopeURL.isolatedCopy();
 71
 72 if (registrationOptions)
 73 result.registrationOptions = std::make_unique<RegistrationOptions>(registrationOptions->isolatedCopy());
 74 return result;
 75}
 76
 77} // namespace WebCore
 78
 79#endif // ENABLE(SERVICE_WORKER)

Source/WebCore/workers/service/ServiceWorkerJobData.h

2727
2828#if ENABLE(SERVICE_WORKER)
2929
30 namespace WebCore {
 30#include "SecurityOriginData.h"
 31#include "ServiceWorkerJobType.h"
 32#include "ServiceWorkerRegistrationKey.h"
 33#include "ServiceWorkerRegistrationOptions.h"
 34#include "URL.h"
3135
32 enum class ServiceWorkerJobType;
 36namespace WebCore {
3337
3438struct ServiceWorkerJobData {
35  uint64_t identifier;
 39public:
 40 ServiceWorkerJobData(uint64_t connectionIdentifier);
 41 ServiceWorkerJobData(const ServiceWorkerJobData&);
 42 ServiceWorkerJobData() = default;
 43
 44 uint64_t jobIdentifier() const { return m_jobIdentifier; }
 45 uint64_t connectionIdentifier() const { return m_connectionIdentifier; }
 46
 47 URL scriptURL;
 48 URL clientCreationURL;
 49 SecurityOriginData topOrigin;
 50 URL scopeURL;
3651 ServiceWorkerJobType type;
3752
 53 std::unique_ptr<RegistrationOptions> registrationOptions;
 54
 55 ServiceWorkerRegistrationKey registrationKey() const;
 56 ServiceWorkerJobData isolatedCopy() const;
 57
3858 template<class Encoder> void encode(Encoder&) const;
3959 template<class Decoder> static bool decode(Decoder&, ServiceWorkerJobData&);
 60
 61private:
 62 uint64_t m_jobIdentifier { 0 };
 63 uint64_t m_connectionIdentifier { 0 };
4064};
4165
4266template<class Encoder>
4367void ServiceWorkerJobData::encode(Encoder& encoder) const
4468{
45  encoder << identifier;
 69 encoder << m_jobIdentifier << m_connectionIdentifier << scriptURL << clientCreationURL << topOrigin << scopeURL;
4670 encoder.encodeEnum(type);
 71 switch (type) {
 72 case ServiceWorkerJobType::Register:
 73 RELEASE_ASSERT(registrationOptions);
 74 encoder << *registrationOptions;
 75 break;
 76 }
4777}
4878
4979template<class Decoder>
5080bool ServiceWorkerJobData::decode(Decoder& decoder, ServiceWorkerJobData& jobData)
5181{
52  if (!decoder.decode(jobData.identifier))
 82 if (!decoder.decode(jobData.m_jobIdentifier))
 83 return false;
 84 if (!decoder.decode(jobData.m_connectionIdentifier))
 85 return false;
 86 if (!decoder.decode(jobData.scriptURL))
 87 return false;
 88 if (!decoder.decode(jobData.clientCreationURL))
 89 return false;
 90 if (!decoder.decode(jobData.topOrigin))
 91 return false;
 92 if (!decoder.decode(jobData.scopeURL))
5393 return false;
5494 if (!decoder.decodeEnum(jobData.type))
5595 return false;
5696
 97 switch (jobData.type) {
 98 case ServiceWorkerJobType::Register:
 99 jobData.registrationOptions = std::make_unique<RegistrationOptions>();
 100 if (!decoder.decode(*jobData.registrationOptions))
 101 return false;
 102 break;
 103 }
 104
57105 return true;
58106}
59107

Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp

 1/*
 2 * Copyright (C) 2017 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "ServiceWorkerRegistrationKey.h"
 28
 29#if ENABLE(SERVICE_WORKER)
 30
 31#include "URLHash.h"
 32
 33namespace WebCore {
 34
 35ServiceWorkerRegistrationKey ServiceWorkerRegistrationKey::emptyKey()
 36{
 37 return { };
 38}
 39
 40unsigned ServiceWorkerRegistrationKey::hash() const
 41{
 42 unsigned hashes[2];
 43 hashes[0] = URLHash::hash(clientCreationURL);
 44 hashes[1] = SecurityOriginDataHash::hash(topOrigin);
 45
 46 return StringHasher::hashMemory(hashes, sizeof(hashes));
 47}
 48
 49bool ServiceWorkerRegistrationKey::operator==(const ServiceWorkerRegistrationKey& other) const
 50{
 51 return clientCreationURL == other.clientCreationURL && topOrigin == other.topOrigin;
 52}
 53
 54} // namespace WebCore
 55
 56#endif // ENABLE(SERVICE_WORKER)

Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h

 1/*
 2 * Copyright (C) 2017 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#if ENABLE(SERVICE_WORKER)
 29
 30#include "SecurityOriginData.h"
 31#include "URL.h"
 32
 33namespace WebCore {
 34
 35struct ServiceWorkerRegistrationKey {
 36 URL clientCreationURL;
 37 SecurityOriginData topOrigin;
 38
 39 static ServiceWorkerRegistrationKey emptyKey();
 40 unsigned hash() const;
 41
 42 bool operator==(const ServiceWorkerRegistrationKey&) const;
 43};
 44
 45} // namespace WebCore
 46
 47namespace WTF {
 48
 49struct ServiceWorkerRegistrationKeyHash {
 50 static unsigned hash(const WebCore::ServiceWorkerRegistrationKey& key) { return key.hash(); }
 51 static bool equal(const WebCore::ServiceWorkerRegistrationKey& a, const WebCore::ServiceWorkerRegistrationKey& b) { return a == b; }
 52 static const bool safeToCompareToEmptyOrDeleted = false;
 53};
 54
 55template<> struct HashTraits<WebCore::ServiceWorkerRegistrationKey> : GenericHashTraits<WebCore::ServiceWorkerRegistrationKey> {
 56 static WebCore::ServiceWorkerRegistrationKey emptyValue() { return WebCore::ServiceWorkerRegistrationKey::emptyKey(); }
 57
 58 static void constructDeletedValue(WebCore::ServiceWorkerRegistrationKey& slot) { slot.clientCreationURL = WebCore::URL(HashTableDeletedValue); }
 59 static bool isDeletedValue(const WebCore::ServiceWorkerRegistrationKey& slot) { return slot.clientCreationURL.isHashTableDeletedValue(); }
 60};
 61
 62template<> struct DefaultHash<WebCore::ServiceWorkerRegistrationKey> {
 63 typedef ServiceWorkerRegistrationKeyHash Hash;
 64};
 65
 66} // namespace WTF
 67
 68#endif // ENABLE(SERVICE_WORKER)

Source/WebCore/workers/service/ServiceWorkerRegistrationOptions.cpp

 1/*
 2 * Copyright (C) 2017 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "ServiceWorkerRegistrationOptions.h"
 28
 29#if ENABLE(SERVICE_WORKER)
 30
 31namespace WebCore {
 32
 33RegistrationOptions RegistrationOptions::isolatedCopy() const
 34{
 35 RegistrationOptions result;
 36 result.scope = scope.isolatedCopy();
 37 result.type = type;
 38 result.updateViaCache = updateViaCache;
 39
 40 return result;
 41}
 42
 43} // namespace WebCore
 44
 45#endif // ENABLE(SERVICE_WORKER)

Source/WebCore/workers/service/ServiceWorkerRegistrationOptions.h

@@struct RegistrationOptions {
3838 String scope;
3939 WorkerType type;
4040 ServiceWorkerUpdateViaCache updateViaCache;
 41
 42 RegistrationOptions isolatedCopy() const;
 43
 44 template<class Encoder> void encode(Encoder&) const;
 45 template<class Decoder> static bool decode(Decoder&, RegistrationOptions&);
4146};
4247
 48template<class Encoder>
 49void RegistrationOptions::encode(Encoder& encoder) const
 50{
 51 encoder << scope;
 52 encoder.encodeEnum(type);
 53 encoder.encodeEnum(updateViaCache);
 54}
 55
 56template<class Decoder>
 57bool RegistrationOptions::decode(Decoder& decoder, RegistrationOptions& options)
 58{
 59 if (!decoder.decode(options.scope))
 60 return false;
 61 if (!decoder.decodeEnum(options.type))
 62 return false;
 63 if (!decoder.decodeEnum(options.updateViaCache))
 64 return false;
 65
 66 return true;
 67}
 68
4369} // namespace WebCore
4470
4571#endif // ENABLE(SERVICE_WORKER)

Source/WebCore/workers/service/ServiceWorkerRegistrationParameters.cpp

1 /*
2  * Copyright (C) 2017 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "ServiceWorkerRegistrationParameters.h"
28 
29 #if ENABLE(SERVICE_WORKER)
30 
31 namespace WebCore {
32 
33 } // namespace WebCore
34 
35 #endif // ENABLE(SERVICE_WORKER)

Source/WebCore/workers/service/ServiceWorkerRegistrationParameters.h

1 /*
2  * Copyright (C) 2017 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #pragma once
27 
28 #if ENABLE(SERVICE_WORKER)
29 
30 #include "SecurityOriginData.h"
31 #include "ServiceWorkerRegistrationOptions.h"
32 #include "URL.h"
33 #include <pal/SessionID.h>
34 
35 namespace WebCore {
36 
37 struct ServiceWorkerRegistrationParameters {
38  URL scriptURL;
39  URL clientCreationURL;
40  SecurityOriginData topOrigin;
41  URL scopeURL;
42  RegistrationOptions options;
43 };
44 
45 } // namespace WebCore
46 
47 #endif // ENABLE(SERVICE_WORKER)

Source/WebCore/workers/service/server/SWClientConnection.h

@@public:
4242
4343 void scheduleJob(ServiceWorkerJob&);
4444
 45 virtual uint64_t identifier() const = 0;
 46
4547protected:
4648 WEBCORE_EXPORT void jobRejectedInServer(uint64_t jobIdentifier, const ExceptionData&);
4749

Source/WebCore/workers/service/server/SWServer.cpp

3131#include "ExceptionCode.h"
3232#include "ExceptionData.h"
3333#include "Logging.h"
 34#include "SWServerRegistration.h"
3435#include "ServiceWorkerJobData.h"
3536#include <wtf/text/WTFString.h>
3637
3738namespace WebCore {
3839
39 SWServer::Connection::Connection(SWServer& server)
 40SWServer::Connection::Connection(SWServer& server, uint64_t identifier)
4041 : m_server(server)
 42 , m_identifier(identifier)
4143{
4244 m_server.registerConnection(*this);
4345}

@@SWServer::Connection::~Connection()
4749 m_server.unregisterConnection(*this);
4850}
4951
50 
5152SWServer::~SWServer()
5253{
5354 RELEASE_ASSERT(m_connections.isEmpty());
 55 RELEASE_ASSERT(m_registrations.isEmpty());
 56
 57 // For a SWServer to be cleanly shut down its thread must have finished and gone away.
 58 // At this stage in development of the feature that actually never happens.
 59 // But once it does start happening, this ASSERT will catch us doing it wrong.
 60 Locker<Lock> locker(m_taskThreadLock);
 61 ASSERT(!m_taskThread);
5462}
5563
5664void SWServer::Connection::scheduleJobInServer(const ServiceWorkerJobData& jobData)
5765{
58  LOG(ServiceWorker, "Scheduling ServiceWorker job %" PRIu64 " in server", jobData.identifier);
59  m_server.scheduleJob(*this, jobData);
 66 LOG(ServiceWorker, "Scheduling ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.jobIdentifier());
 67 ASSERT(identifier() == jobData.connectionIdentifier());
 68
 69 m_server.scheduleJob(jobData);
 70}
 71
 72SWServer::SWServer()
 73{
 74 Locker<Lock> locker(m_taskThreadLock);
 75 m_taskThread = Thread::create(ASCIILiteral("ServiceWorker Task Thread"), [this] {
 76 taskThreadEntryPoint();
 77 });
 78}
 79
 80void SWServer::scheduleJob(const ServiceWorkerJobData& jobData)
 81{
 82 ASSERT(m_connections.contains(jobData.connectionIdentifier()));
 83
 84 auto result = m_registrations.add(jobData.registrationKey(), nullptr);
 85 if (result.isNewEntry)
 86 result.iterator->value = std::make_unique<SWServerRegistration>(*this);
 87
 88 ASSERT(result.iterator->value);
 89
 90 result.iterator->value->enqueueJob(jobData);
 91}
 92
 93void SWServer::rejectJob(const ServiceWorkerJobData& jobData, const ExceptionData& exceptionData)
 94{
 95 LOG(ServiceWorker, "Rejected ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.jobIdentifier());
 96 auto* connection = m_connections.get(jobData.connectionIdentifier());
 97 if (!connection)
 98 return;
 99
 100 connection->rejectJobInClient(jobData.jobIdentifier(), exceptionData);
 101}
 102
 103void SWServer::taskThreadEntryPoint()
 104{
 105 ASSERT(!isMainThread());
 106 {
 107 Locker<Lock> locker(m_taskThreadLock);
 108 }
 109
 110 while (!m_taskQueue.isKilled())
 111 m_taskQueue.waitForMessage().performTask();
 112
 113 Locker<Lock> locker(m_taskThreadLock);
 114 m_taskThread = nullptr;
60115}
61116
62 void SWServer::scheduleJob(Connection& connection, const ServiceWorkerJobData& jobData)
 117void SWServer::postTask(CrossThreadTask&& task)
63118{
64  // FIXME: For now, all scheduled jobs immediately reject.
65  connection.rejectJobInClient(jobData.identifier, ExceptionData { UnknownError, ASCIILiteral("serviceWorker job scheduling is not yet implemented") });
 119 m_taskQueue.append(WTFMove(task));
 120}
 121
 122void SWServer::postTaskReply(CrossThreadTask&& task)
 123{
 124 m_taskReplyQueue.append(WTFMove(task));
 125
 126 Locker<Lock> locker(m_mainThreadReplyLock);
 127 if (m_mainThreadReplyScheduled)
 128 return;
 129
 130 m_mainThreadReplyScheduled = true;
 131 callOnMainThread([this] {
 132 handleTaskRepliesOnMainThread();
 133 });
 134}
 135
 136void SWServer::handleTaskRepliesOnMainThread()
 137{
 138 {
 139 Locker<Lock> locker(m_mainThreadReplyLock);
 140 m_mainThreadReplyScheduled = false;
 141 }
 142
 143 while (auto task = m_taskReplyQueue.tryGetMessage())
 144 task->performTask();
66145}
67146
68147void SWServer::registerConnection(Connection& connection)
69148{
70  auto result = m_connections.add(&connection);
71  ASSERT_UNUSED(result, result.isNewEntry);
 149 auto result = m_connections.add(connection.identifier(), nullptr);
 150 ASSERT(result.isNewEntry);
 151 result.iterator->value = &connection;
72152}
73153
74154void SWServer::unregisterConnection(Connection& connection)
75155{
76  ASSERT(m_connections.contains(&connection));
77  m_connections.remove(&connection);
 156 ASSERT(m_connections.get(connection.identifier()) == &connection);
 157 m_connections.remove(connection.identifier());
78158}
79159
80160} // namespace WebCore

Source/WebCore/workers/service/server/SWServer.h

2727
2828#if ENABLE(SERVICE_WORKER)
2929
 30#include "SWServerRegistration.h"
3031#include "ServiceWorkerJob.h"
 32#include "ServiceWorkerRegistrationKey.h"
 33#include <wtf/CrossThreadQueue.h>
 34#include <wtf/CrossThreadTask.h>
3135#include <wtf/HashMap.h>
3236#include <wtf/HashSet.h>
 37#include <wtf/RunLoop.h>
3338#include <wtf/ThreadSafeRefCounted.h>
 39#include <wtf/Threading.h>
3440
3541namespace WebCore {
3642
 43class SWServerRegistration;
3744struct ExceptionData;
3845
3946class SWServer {

@@public:
4350 public:
4451 WEBCORE_EXPORT virtual ~Connection();
4552
 53 uint64_t identifier() const { return m_identifier; };
 54
4655 protected:
47  WEBCORE_EXPORT Connection(SWServer&);
 56 WEBCORE_EXPORT Connection(SWServer&, uint64_t identifier);
4857 SWServer& server() { return m_server; }
4958
5059 WEBCORE_EXPORT void scheduleJobInServer(const ServiceWorkerJobData&);

@@public:
5362 virtual void rejectJobInClient(uint64_t jobIdentifier, const ExceptionData&) = 0;
5463
5564 SWServer& m_server;
 65 uint64_t m_identifier;
5666 };
5767
 68 WEBCORE_EXPORT SWServer();
5869 WEBCORE_EXPORT ~SWServer();
5970
60  WEBCORE_EXPORT void scheduleJob(Connection&, const ServiceWorkerJobData&);
 71 void scheduleJob(const ServiceWorkerJobData&);
 72 void rejectJob(const ServiceWorkerJobData&, const ExceptionData&);
 73
 74 void postTask(CrossThreadTask&&);
 75 void postTaskReply(CrossThreadTask&&);
6176
6277private:
6378 void registerConnection(Connection&);
6479 void unregisterConnection(Connection&);
6580
66  HashSet<Connection*> m_connections;
 81 void taskThreadEntryPoint();
 82 void handleTaskRepliesOnMainThread();
 83
 84 HashMap<uint64_t, Connection*> m_connections;
 85 HashMap<ServiceWorkerRegistrationKey, std::unique_ptr<SWServerRegistration>> m_registrations;
 86
 87 RefPtr<Thread> m_taskThread;
 88 Lock m_taskThreadLock;
 89
 90 CrossThreadQueue<CrossThreadTask> m_taskQueue;
 91 CrossThreadQueue<CrossThreadTask> m_taskReplyQueue;
 92
 93 Lock m_mainThreadReplyLock;
 94 bool m_mainThreadReplyScheduled { false };
6795};
6896
6997} // namespace WebCore

Source/WebCore/workers/service/server/SWServerRegistration.cpp

 1/*
 2 * Copyright (C) 2017 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "SWServerRegistration.h"
 28
 29#if ENABLE(SERVICE_WORKER)
 30
 31#include "ExceptionData.h"
 32#include "SWServer.h"
 33
 34namespace WebCore {
 35
 36SWServerRegistration::SWServerRegistration(SWServer& server)
 37 : m_jobTimer(*this, &SWServerRegistration::startNextJob)
 38 , m_server(server)
 39{
 40}
 41
 42SWServerRegistration::~SWServerRegistration()
 43{
 44 ASSERT(m_jobQueue.isEmpty());
 45}
 46
 47void SWServerRegistration::enqueueJob(const ServiceWorkerJobData& jobData)
 48{
 49 // FIXME: Per the spec, check if this job is equivalent to the last job on the queue.
 50 // If it is, stack it along with that job.
 51
 52 m_jobQueue.append(jobData);
 53
 54 if (m_currentJob)
 55 return;
 56
 57 if (!m_jobTimer.isActive())
 58 m_jobTimer.startOneShot(0_s);
 59}
 60
 61void SWServerRegistration::startNextJob()
 62{
 63 ASSERT(isMainThread());
 64 ASSERT(!m_currentJob);
 65 ASSERT(!m_jobQueue.isEmpty());
 66
 67 m_currentJob = std::make_unique<ServiceWorkerJobData>(m_jobQueue.takeFirst().isolatedCopy());
 68 m_server.postTask(createCrossThreadTask(*this, &SWServerRegistration::performCurrentJob));
 69}
 70
 71void SWServerRegistration::performCurrentJob()
 72{
 73 ASSERT(!isMainThread());
 74
 75 auto exception = ExceptionData { UnknownError, ASCIILiteral("serviceWorker job scheduling is not yet implemented") };
 76 m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::rejectCurrentJob, exception));
 77}
 78
 79void SWServerRegistration::rejectCurrentJob(const ExceptionData& exceptionData)
 80{
 81 ASSERT(isMainThread());
 82 ASSERT(m_currentJob);
 83
 84 m_server.rejectJob(*m_currentJob, exceptionData);
 85
 86 finishCurrentJob();
 87}
 88
 89void SWServerRegistration::finishCurrentJob()
 90{
 91 ASSERT(m_currentJob);
 92 ASSERT(!m_jobTimer.isActive());
 93
 94 m_currentJob = nullptr;
 95 if (m_jobQueue.isEmpty())
 96 return;
 97
 98 startNextJob();
 99}
 100
 101} // namespace WebCore
 102
 103#endif // ENABLE(SERVICE_WORKER)

Source/WebCore/workers/service/server/SWServerRegistration.h

 1/*
 2 * Copyright (C) 2017 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#if ENABLE(SERVICE_WORKER)
 29
 30#include "ServiceWorkerJobData.h"
 31#include "Timer.h"
 32#include <wtf/Deque.h>
 33
 34namespace WebCore {
 35
 36class SWServer;
 37struct ExceptionData;
 38
 39class SWServerRegistration {
 40public:
 41 SWServerRegistration(SWServer&);
 42 SWServerRegistration(const SWServerRegistration&) = delete;
 43 ~SWServerRegistration();
 44
 45 void enqueueJob(const ServiceWorkerJobData&);
 46
 47private:
 48 void jobTimerFired();
 49 void performCurrentJob();
 50 void rejectCurrentJob(const ExceptionData&);
 51
 52 void startNextJob();
 53 void finishCurrentJob();
 54
 55 Deque<ServiceWorkerJobData> m_jobQueue;
 56 std::unique_ptr<ServiceWorkerJobData> m_currentJob;
 57
 58 Timer m_jobTimer;
 59 SWServer& m_server;
 60};
 61
 62} // namespace WebCore
 63
 64#endif // ENABLE(SERVICE_WORKER)

Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp

@@using namespace WebCore;
4545namespace WebKit {
4646
4747WebSWServerConnection::WebSWServerConnection(SWServer& server, IPC::Connection& connection, uint64_t connectionIdentifier, const SessionID& sessionID)
48  : SWServer::Connection(server)
 48 : SWServer::Connection(server, connectionIdentifier)
4949 , m_sessionID(sessionID)
50  , m_identifier(connectionIdentifier)
5150 , m_connection(connection)
5251{
5352}

Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h

@@public:
4444 WebSWServerConnection(const WebSWServerConnection&) = delete;
4545 ~WebSWServerConnection() final;
4646
47  uint64_t identifier() const { return m_identifier; }
48 
4947 void disconnectedFromWebProcess();
5048 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
5149

@@private:
5452 void rejectJobInClient(uint64_t jobIdentifier, const WebCore::ExceptionData&) final;
5553
5654 IPC::Connection* messageSenderConnection() final { return m_connection.ptr(); }
57  uint64_t messageSenderDestinationID() final { return m_identifier; }
 55 uint64_t messageSenderDestinationID() final { return identifier(); }
5856
5957 PAL::SessionID m_sessionID;
60  uint64_t m_identifier;
6158
6259 Ref<IPC::Connection> m_connection;
6360}; // class WebSWServerConnection

Source/WebKit/WebProcess/Storage/WebSWClientConnection.h

@@public:
4545 WebSWClientConnection(const WebSWClientConnection&) = delete;
4646 ~WebSWClientConnection() final;
4747
48  uint64_t identifier() const { return m_identifier; }
 48 uint64_t identifier() const final { return m_identifier; }
4949
5050 void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final;
5151

LayoutTests/ChangeLog

 12017-08-24 Brady Eidson <beidson@apple.com>
 2
 3 Introduce ServerWorkerRegistration task queues.
 4 https://bugs.webkit.org/show_bug.cgi?id=175851
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * http/tests/workers/service/registration-task-queue-scheduling-1-expected.txt: Added.
 9 * http/tests/workers/service/registration-task-queue-scheduling-1.html: Added.
 10 * http/tests/workers/service/resources/registration-task-queue-scheduling-1-second-window.html: Added.
 11 * http/tests/workers/service/resources/registration-task-queue-scheduling-1.js: Added.
 12
1132017-08-24 Ryan Haddad <ryanhaddad@apple.com>
214
315 Unreviewed, rolling out r221139.

LayoutTests/http/tests/workers/service/registration-task-queue-scheduling-1-expected.txt

 1ALERT: Done
 2

LayoutTests/http/tests/workers/service/registration-task-queue-scheduling-1.html

 1<html>
 2<head>
 3<script src="resources/sw-test-pre.js"></script>
 4</head>
 5<body>
 6
 7<script src="resources/registration-task-queue-scheduling-1.js"></script>
 8</body>
 9</html>

LayoutTests/http/tests/workers/service/resources/registration-task-queue-scheduling-1-second-window.html

 1<script>
 2
 3if (!window.opener)
 4 alert("This HTML file should not be opened directly")
 5
 6for (var i = 0; i < 1000; ++i) {
 7 navigator.serviceWorker.register("empty-worker.js", { })
 8 .then(function(r) {
 9 alert("Popup window resolved successfully (unexpected)")
 10 opener.postMessage("done", "*");
 11 }, function(e) {
 12 opener.postMessage("responded", "*");
 13 })
 14}
 15
 16</script>

LayoutTests/http/tests/workers/service/resources/registration-task-queue-scheduling-1.js

 1// This test makes sure that two different windows from two different domains who spam SW registrations get responses intertwined with each other
 2// as each registration should operate on its own task queue.
 3
 4if (location.hostname != "127.0.0.1")
 5 alert("This test must be initiated from the hostname 127.0.0.1");
 6
 7window.onmessage = function(evt)
 8{
 9 if (evt.data == "done") {
 10 alert("Error in popup window");
 11 finishSWTest();
 12 } else if (evt.data == "responded") {
 13 if (!window.popupTimestamp)
 14 window.popupTimestamp = new Date();
 15
 16 responded();
 17 } else {
 18 alert("Unexpected event from popup window");
 19 finishSWTest();
 20 }
 21}
 22
 23function responded()
 24{
 25 if (!window.thisTimestamp) {
 26 window.thisTimestamp = new Date();
 27
 28 if (window.popupTimestamp)
 29 alert("Registrations in second window should not have responded before the first");
 30
 31 return;
 32 }
 33
 34 if (!window.popupTimestamp)
 35 return;
 36
 37 if (window.popupTimestamp < window.thisTimestamp)
 38 alert("Popup should not have popped up before this main window");
 39 else
 40 alert("Done");
 41
 42 finishSWTest();
 43}
 44
 45for (var i = 0; i < 1000; ++i) {
 46 navigator.serviceWorker.register("resources/empty-worker.js", { })
 47 .then(function(r) {
 48 console.log("Original window resolved successfully (unexpected)")
 49 done();
 50 }, function(e) {
 51 if (e+"" != "UnknownError: serviceWorker job scheduling is not yet implemented") {
 52 alert("Unexpected error received from server");
 53 finishSWTest();
 54 }
 55
 56 responded();
 57 })
 58}
 59
 60otherWindow = window.open("http://localhost:8000/workers/service/resources/registration-task-queue-scheduling-1-second-window.html", "other");