| Differences between
and this patch
- a/Source/WebCore/ChangeLog +101 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2017-08-30  Brady Eidson  <beidson@apple.com>
2
3
        Implement all of "Register" right up until where the script is fetched.
4
        https://bugs.webkit.org/show_bug.cgi?id=176082
5
6
        Reviewed by Andy Estes.
7
8
        Test: http/tests/workers/service/basic-register-exceptions.html
9
10
        This patch implements every detail of the "Register" and "Update" algorithms right up to
11
        where we would actually fetch the service worker script file.
12
13
        It also includes miscellaneous refactoring and cleanup along the way.
14
15
        * CMakeLists.txt:
16
        * WebCore.xcodeproj/project.pbxproj:
17
18
        * page/SecurityOrigin.cpp:
19
        (WebCore::shouldTreatAsPotentiallyTrustworthy): Expose in the header for other files to use.
20
        * page/SecurityOrigin.h:
21
22
        * workers/service/ServiceWorkerContainer.cpp:
23
        (WebCore::ServiceWorkerContainer::addRegistration): Add some more exception cases from the spec.
24
        (WebCore::ServiceWorkerContainer::scheduleJob): Use the correct job identifier.
25
        (WebCore::ServiceWorkerContainer::jobFailedWithException):
26
        (WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
27
        (WebCore::ServiceWorkerContainer::jobDidFinish):
28
        * workers/service/ServiceWorkerContainer.h:
29
30
        * workers/service/ServiceWorkerJob.cpp:
31
        (WebCore::ServiceWorkerJob::ServiceWorkerJob):
32
        (WebCore::ServiceWorkerJob::failedWithException): Call through to the client to handle the failure.
33
        (WebCore::ServiceWorkerJob::resolvedWithRegistration): Call through to the client to handle success.
34
        * workers/service/ServiceWorkerJob.h:
35
        (WebCore::ServiceWorkerJob::promise):
36
        (WebCore::ServiceWorkerJob::identifier const): Deleted. Rely on the identifier from the JobData.
37
38
        * workers/service/ServiceWorkerJobClient.h:
39
40
        * workers/service/ServiceWorkerJobData.cpp:
41
        (WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
42
        (WebCore::ServiceWorkerJobData::isolatedCopy const):
43
        * workers/service/ServiceWorkerJobData.h:
44
        (WebCore::ServiceWorkerJobData::identifier const):
45
        (WebCore::ServiceWorkerJobData::encode const):
46
        (WebCore::ServiceWorkerJobData::decode):
47
        (WebCore::ServiceWorkerJobData::jobIdentifier const): Deleted.
48
49
        * workers/service/ServiceWorkerRegistration.cpp:
50
        (WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration): Make this class an ActiveDOMObject
51
          both because it *is* an active DOM object and because we need to get at the ScriptExecutionContext.
52
        * workers/service/ServiceWorkerRegistration.h:
53
54
        Add a class to encapsulate everything about a registration for encode/decode/crossthread:
55
        * workers/service/ServiceWorkerRegistrationData.cpp:
56
        (WebCore::ServiceWorkerRegistrationData::isolatedCopy const):
57
        * workers/service/ServiceWorkerRegistrationData.h: 
58
        (WebCore::ServiceWorkerRegistrationData::encode const):
59
        (WebCore::ServiceWorkerRegistrationData::decode):
60
61
        * workers/service/ServiceWorkerRegistrationKey.cpp:
62
        (WebCore::ServiceWorkerRegistrationKey::isolatedCopy const):
63
        * workers/service/ServiceWorkerRegistrationKey.h:
64
        (WebCore::ServiceWorkerRegistrationKey::encode const):
65
        (WebCore::ServiceWorkerRegistrationKey::decode):
66
67
        * workers/service/server/SWClientConnection.cpp:
68
        (WebCore::SWClientConnection::scheduleJob):
69
        (WebCore::SWClientConnection::jobResolvedInServer):
70
        * workers/service/server/SWClientConnection.h:
71
72
        * workers/service/server/SWServer.cpp:
73
        (WebCore::SWServer::~SWServer):
74
        (WebCore::SWServer::Connection::scheduleJobInServer):
75
        (WebCore::SWServer::scheduleJob):
76
        (WebCore::SWServer::rejectJob):
77
        (WebCore::SWServer::resolveJob):
78
        * workers/service/server/SWServer.h:
79
80
        * workers/service/server/SWServerRegistration.cpp:
81
        (WebCore::SWServerRegistration::SWServerRegistration):
82
        (WebCore::SWServerRegistration::startNextJob):
83
        (WebCore::SWServerRegistration::isEmpty):
84
        (WebCore::SWServerRegistration::getNewestWorker): Implement "Get Newest Worker" algorithm.
85
        (WebCore::SWServerRegistration::runRegisterJob): Implement the rest of the "Register" algorithm.
86
        (WebCore::SWServerRegistration::runUpdateJob): Implement every part of "Update" up to where we would fetch.
87
        (WebCore::SWServerRegistration::rejectWithExceptionOnMainThread):
88
        (WebCore::SWServerRegistration::resolveWithRegistrationOnMainThread):
89
        (WebCore::SWServerRegistration::resolveCurrentJob):
90
        (WebCore::SWServerRegistration::data const):
91
        (WebCore::SWServerRegistration::performCurrentJob): Deleted.
92
        * workers/service/server/SWServerRegistration.h:
93
        (WebCore::SWServerRegistration::identifier const):
94
95
        Add a stub class to represent "active service workers" in the SWServer:
96
        * workers/service/server/SWServerWorker.cpp:
97
        (WebCore::SWServerWorker::SWServerWorker):
98
        (WebCore::SWServerWorker::~SWServerWorker):
99
        * workers/service/server/SWServerWorker.h: 
100
        (WebCore::SWServerWorker::scriptURL const):
101
1
2017-08-29  Wenson Hsieh  <wenson_hsieh@apple.com>
102
2017-08-29  Wenson Hsieh  <wenson_hsieh@apple.com>
2
103
3
        REGRESSION(r210287) On drop, event.dataTransfer.getData("text") returns an empty string when dragging an image
104
        REGRESSION(r210287) On drop, event.dataTransfer.getData("text") returns an empty string when dragging an image
- a/Source/WebKit/ChangeLog +12 lines
Lines 1-3 a/Source/WebKit/ChangeLog_sec1
1
2017-08-30  Brady Eidson  <beidson@apple.com>
2
3
        Implement all of "Register" right up until where the script is fetched.
4
        https://bugs.webkit.org/show_bug.cgi?id=176082
5
6
        Reviewed by Andy Estes.
7
8
        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
9
        (WebKit::WebSWServerConnection::resolveJobInClient):
10
        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
11
        * WebProcess/Storage/WebSWClientConnection.messages.in:
12
1
2017-08-30  Carlos Alberto Lopez Perez  <clopez@igalia.com>
13
2017-08-30  Carlos Alberto Lopez Perez  <clopez@igalia.com>
2
14
3
        [WPE] Enable MEMORY_SAMPLER
15
        [WPE] Enable MEMORY_SAMPLER
- a/Source/WebCore/CMakeLists.txt +2 lines
Lines 3019-3030 set(WebCore_SOURCES a/Source/WebCore/CMakeLists.txt_sec1
3019
    workers/service/ServiceWorkerJobData.cpp
3019
    workers/service/ServiceWorkerJobData.cpp
3020
    workers/service/ServiceWorkerProvider.cpp
3020
    workers/service/ServiceWorkerProvider.cpp
3021
    workers/service/ServiceWorkerRegistration.cpp
3021
    workers/service/ServiceWorkerRegistration.cpp
3022
    workers/service/ServiceWorkerRegistrationData.cpp
3022
    workers/service/ServiceWorkerRegistrationKey.cpp
3023
    workers/service/ServiceWorkerRegistrationKey.cpp
3023
    workers/service/ServiceWorkerRegistrationOptions.cpp
3024
    workers/service/ServiceWorkerRegistrationOptions.cpp
3024
3025
3025
    workers/service/server/SWClientConnection.cpp
3026
    workers/service/server/SWClientConnection.cpp
3026
    workers/service/server/SWServer.cpp
3027
    workers/service/server/SWServer.cpp
3027
    workers/service/server/SWServerRegistration.cpp
3028
    workers/service/server/SWServerRegistration.cpp
3029
    workers/service/server/SWServerWorker.cpp
3028
3030
3029
    xml/DOMParser.cpp
3031
    xml/DOMParser.cpp
3030
    xml/NativeXPathNSResolver.cpp
3032
    xml/NativeXPathNSResolver.cpp
- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj +16 lines
Lines 2301-2306 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec1
2301
		517A53251F4B905500DCDC0A /* ServiceWorkerJobData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53241F4B904A00DCDC0A /* ServiceWorkerJobData.cpp */; };
2301
		517A53251F4B905500DCDC0A /* ServiceWorkerJobData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53241F4B904A00DCDC0A /* ServiceWorkerJobData.cpp */; };
2302
		517A53281F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */; };
2302
		517A53281F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */; };
2303
		517A53291F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */; settings = {ATTRIBUTES = (Private, ); }; };
2303
		517A53291F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */; settings = {ATTRIBUTES = (Private, ); }; };
2304
		517A53451F50C17F00DCDC0A /* SWServerWorker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53431F50C16100DCDC0A /* SWServerWorker.cpp */; };
2305
		517A53461F50C17F00DCDC0A /* SWServerWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A53421F50C16100DCDC0A /* SWServerWorker.h */; settings = {ATTRIBUTES = (Private, ); }; };
2306
		517A534E1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */; };
2307
		517A534F1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */; settings = {ATTRIBUTES = (Private, ); }; };
2304
		517A63C31B74318700E7DCDC /* KeyedDecoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */; };
2308
		517A63C31B74318700E7DCDC /* KeyedDecoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */; };
2305
		517A63C41B74318B00E7DCDC /* KeyedEncoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63C11B74317E00E7DCDC /* KeyedEncoderCF.cpp */; };
2309
		517A63C41B74318B00E7DCDC /* KeyedEncoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63C11B74317E00E7DCDC /* KeyedEncoderCF.cpp */; };
2306
		517A63C51B74318F00E7DCDC /* KeyedDecoderCF.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */; settings = {ATTRIBUTES = (Private, ); }; };
2310
		517A63C51B74318F00E7DCDC /* KeyedDecoderCF.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */; settings = {ATTRIBUTES = (Private, ); }; };
Lines 10122-10127 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec2
10122
		517A53241F4B904A00DCDC0A /* ServiceWorkerJobData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerJobData.cpp; sourceTree = "<group>"; };
10126
		517A53241F4B904A00DCDC0A /* ServiceWorkerJobData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerJobData.cpp; sourceTree = "<group>"; };
10123
		517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationKey.h; sourceTree = "<group>"; };
10127
		517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationKey.h; sourceTree = "<group>"; };
10124
		517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationKey.cpp; sourceTree = "<group>"; };
10128
		517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationKey.cpp; sourceTree = "<group>"; };
10129
		517A53421F50C16100DCDC0A /* SWServerWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWServerWorker.h; sourceTree = "<group>"; };
10130
		517A53431F50C16100DCDC0A /* SWServerWorker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWServerWorker.cpp; sourceTree = "<group>"; };
10131
		517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerRegistrationData.cpp; sourceTree = "<group>"; };
10132
		517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerRegistrationData.h; sourceTree = "<group>"; };
10125
		517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedDecoderCF.cpp; sourceTree = "<group>"; };
10133
		517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedDecoderCF.cpp; sourceTree = "<group>"; };
10126
		517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyedDecoderCF.h; sourceTree = "<group>"; };
10134
		517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyedDecoderCF.h; sourceTree = "<group>"; };
10127
		517A63C11B74317E00E7DCDC /* KeyedEncoderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedEncoderCF.cpp; sourceTree = "<group>"; };
10135
		517A63C11B74317E00E7DCDC /* KeyedEncoderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyedEncoderCF.cpp; sourceTree = "<group>"; };
Lines 18758-18763 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec3
18758
				517A52EE1F47535900DCDC0A /* SWServer.h */,
18766
				517A52EE1F47535900DCDC0A /* SWServer.h */,
18759
				51F645951F4A686100B54DED /* SWServerRegistration.cpp */,
18767
				51F645951F4A686100B54DED /* SWServerRegistration.cpp */,
18760
				51F645941F4A684F00B54DED /* SWServerRegistration.h */,
18768
				51F645941F4A684F00B54DED /* SWServerRegistration.h */,
18769
				517A53431F50C16100DCDC0A /* SWServerWorker.cpp */,
18770
				517A53421F50C16100DCDC0A /* SWServerWorker.h */,
18761
			);
18771
			);
18762
			path = server;
18772
			path = server;
18763
			sourceTree = "<group>";
18773
			sourceTree = "<group>";
Lines 18863-18868 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec4
18863
				51F1754D1F3EBC0C00C74950 /* ServiceWorkerRegistration.cpp */,
18873
				51F1754D1F3EBC0C00C74950 /* ServiceWorkerRegistration.cpp */,
18864
				51F1754C1F3EBC0C00C74950 /* ServiceWorkerRegistration.h */,
18874
				51F1754C1F3EBC0C00C74950 /* ServiceWorkerRegistration.h */,
18865
				51F1754B1F3EBC0C00C74950 /* ServiceWorkerRegistration.idl */,
18875
				51F1754B1F3EBC0C00C74950 /* ServiceWorkerRegistration.idl */,
18876
				517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */,
18877
				517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */,
18866
				517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */,
18878
				517A53271F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.cpp */,
18867
				517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */,
18879
				517A53261F4B90B200DCDC0A /* ServiceWorkerRegistrationKey.h */,
18868
				51F645A01F4BF51600B54DED /* ServiceWorkerRegistrationOptions.cpp */,
18880
				51F645A01F4BF51600B54DED /* ServiceWorkerRegistrationOptions.cpp */,
Lines 29709-29714 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec5
29709
				51F6456A1F4539C000B54DED /* ServiceWorkerJobType.h in Headers */,
29721
				51F6456A1F4539C000B54DED /* ServiceWorkerJobType.h in Headers */,
29710
				51F175661F3EBC8300C74950 /* ServiceWorkerProvider.h in Headers */,
29722
				51F175661F3EBC8300C74950 /* ServiceWorkerProvider.h in Headers */,
29711
				51F175681F3EBC8300C74950 /* ServiceWorkerRegistration.h in Headers */,
29723
				51F175681F3EBC8300C74950 /* ServiceWorkerRegistration.h in Headers */,
29724
				517A534F1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.h in Headers */,
29712
				517A53291F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.h in Headers */,
29725
				517A53291F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.h in Headers */,
29713
				51F175691F3EBC8300C74950 /* ServiceWorkerRegistrationOptions.h in Headers */,
29726
				51F175691F3EBC8300C74950 /* ServiceWorkerRegistrationOptions.h in Headers */,
29714
				51F1756C1F3EBC8300C74950 /* ServiceWorkerUpdateViaCache.h in Headers */,
29727
				51F1756C1F3EBC8300C74950 /* ServiceWorkerUpdateViaCache.h in Headers */,
Lines 30130-30135 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec6
30130
				517A531D1F4B53B100DCDC0A /* SWClientConnection.h in Headers */,
30143
				517A531D1F4B53B100DCDC0A /* SWClientConnection.h in Headers */,
30131
				517A52F01F47535B00DCDC0A /* SWServer.h in Headers */,
30144
				517A52F01F47535B00DCDC0A /* SWServer.h in Headers */,
30132
				51F645971F4A686F00B54DED /* SWServerRegistration.h in Headers */,
30145
				51F645971F4A686F00B54DED /* SWServerRegistration.h in Headers */,
30146
				517A53461F50C17F00DCDC0A /* SWServerWorker.h in Headers */,
30133
				E180811716FCF9CB00B80D07 /* SynchronousLoaderClient.h in Headers */,
30147
				E180811716FCF9CB00B80D07 /* SynchronousLoaderClient.h in Headers */,
30134
				26FAE4CF1852E3A5004C8C46 /* SynchronousResourceHandleCFURLConnectionDelegate.h in Headers */,
30148
				26FAE4CF1852E3A5004C8C46 /* SynchronousResourceHandleCFURLConnectionDelegate.h in Headers */,
30135
				0F03C0741884695E00A5F8CA /* SystemMemory.h in Headers */,
30149
				0F03C0741884695E00A5F8CA /* SystemMemory.h in Headers */,
Lines 33600-33605 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec7
33600
				517A53251F4B905500DCDC0A /* ServiceWorkerJobData.cpp in Sources */,
33614
				517A53251F4B905500DCDC0A /* ServiceWorkerJobData.cpp in Sources */,
33601
				51F175651F3EBC8300C74950 /* ServiceWorkerProvider.cpp in Sources */,
33615
				51F175651F3EBC8300C74950 /* ServiceWorkerProvider.cpp in Sources */,
33602
				51F175671F3EBC8300C74950 /* ServiceWorkerRegistration.cpp in Sources */,
33616
				51F175671F3EBC8300C74950 /* ServiceWorkerRegistration.cpp in Sources */,
33617
				517A534E1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.cpp in Sources */,
33603
				517A53281F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.cpp in Sources */,
33618
				517A53281F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.cpp in Sources */,
33604
				51F645A21F4BF53C00B54DED /* ServiceWorkerRegistrationOptions.cpp in Sources */,
33619
				51F645A21F4BF53C00B54DED /* ServiceWorkerRegistrationOptions.cpp in Sources */,
33605
				93309E0F099E64920056E581 /* SetNodeAttributeCommand.cpp in Sources */,
33620
				93309E0F099E64920056E581 /* SetNodeAttributeCommand.cpp in Sources */,
Lines 33907-33912 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec8
33907
				517A531C1F4B53B100DCDC0A /* SWClientConnection.cpp in Sources */,
33922
				517A531C1F4B53B100DCDC0A /* SWClientConnection.cpp in Sources */,
33908
				517A52F11F4754E700DCDC0A /* SWServer.cpp in Sources */,
33923
				517A52F11F4754E700DCDC0A /* SWServer.cpp in Sources */,
33909
				51F645961F4A686F00B54DED /* SWServerRegistration.cpp in Sources */,
33924
				51F645961F4A686F00B54DED /* SWServerRegistration.cpp in Sources */,
33925
				517A53451F50C17F00DCDC0A /* SWServerWorker.cpp in Sources */,
33910
				E180811216FCF42F00B80D07 /* SynchronousLoaderClient.cpp in Sources */,
33926
				E180811216FCF42F00B80D07 /* SynchronousLoaderClient.cpp in Sources */,
33911
				E180811616FCF9CB00B80D07 /* SynchronousLoaderClient.mm in Sources */,
33927
				E180811616FCF9CB00B80D07 /* SynchronousLoaderClient.mm in Sources */,
33912
				442ABCD617D9262F00D30715 /* SynchronousLoaderClientCFNet.cpp in Sources */,
33928
				442ABCD617D9262F00D30715 /* SynchronousLoaderClientCFNet.cpp in Sources */,
- a/Source/WebCore/page/SecurityOrigin.cpp -1 / +1 lines
Lines 123-129 static bool isLoopbackIPAddress(const URL& url) a/Source/WebCore/page/SecurityOrigin.cpp_sec1
123
}
123
}
124
124
125
// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy (Editor's Draft, 17 November 2016)
125
// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy (Editor's Draft, 17 November 2016)
126
static bool shouldTreatAsPotentiallyTrustworthy(const URL& url)
126
bool shouldTreatAsPotentiallyTrustworthy(const URL& url)
127
{
127
{
128
    if (!url.isValid())
128
    if (!url.isValid())
129
        return false;
129
        return false;
- a/Source/WebCore/page/SecurityOrigin.h +2 lines
Lines 234-239 private: a/Source/WebCore/page/SecurityOrigin.h_sec1
234
    bool m_isPotentiallyTrustworthy { false };
234
    bool m_isPotentiallyTrustworthy { false };
235
};
235
};
236
236
237
bool shouldTreatAsPotentiallyTrustworthy(const URL&);
238
237
// Returns true if the Origin header values serialized from these two origins would be the same.
239
// Returns true if the Origin header values serialized from these two origins would be the same.
238
bool originsMatch(const SecurityOrigin&, const SecurityOrigin&);
240
bool originsMatch(const SecurityOrigin&, const SecurityOrigin&);
239
bool originsMatch(const SecurityOrigin*, const SecurityOrigin*);
241
bool originsMatch(const SecurityOrigin*, const SecurityOrigin*);
- a/Source/WebCore/workers/service/ServiceWorkerContainer.cpp -4 / +40 lines
Lines 29-36 a/Source/WebCore/workers/service/ServiceWorkerContainer.cpp_sec1
29
#if ENABLE(SERVICE_WORKER)
29
#if ENABLE(SERVICE_WORKER)
30
30
31
#include "Exception.h"
31
#include "Exception.h"
32
#include "IDLTypes.h"
32
#include "JSDOMPromiseDeferred.h"
33
#include "JSDOMPromiseDeferred.h"
34
#include "JSServiceWorkerRegistration.h"
33
#include "NavigatorBase.h"
35
#include "NavigatorBase.h"
36
#include "ScopeGuard.h"
34
#include "ScriptExecutionContext.h"
37
#include "ScriptExecutionContext.h"
35
#include "SecurityOrigin.h"
38
#include "SecurityOrigin.h"
36
#include "ServiceWorkerJob.h"
39
#include "ServiceWorkerJob.h"
Lines 104-110 void ServiceWorkerContainer::addRegistration(const String& relativeScriptURL, co a/Source/WebCore/workers/service/ServiceWorkerContainer.cpp_sec2
104
107
105
    String path = jobData.scriptURL.path();
108
    String path = jobData.scriptURL.path();
106
    if (path.containsIgnoringASCIICase("%2f") || path.containsIgnoringASCIICase("%5c")) {
109
    if (path.containsIgnoringASCIICase("%2f") || path.containsIgnoringASCIICase("%5c")) {
107
        promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() must be called with a script URL whose path does not contain '%%2f' or '%%5c'") });
110
        promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() must be called with a script URL whose path does not contain '%2f' or '%5c'") });
108
        return;
111
        return;
109
    }
112
    }
110
113
Lines 112-121 void ServiceWorkerContainer::addRegistration(const String& relativeScriptURL, co a/Source/WebCore/workers/service/ServiceWorkerContainer.cpp_sec3
112
    if (!scope.isEmpty())
115
    if (!scope.isEmpty())
113
        jobData.scopeURL = context->completeURL(scope);
116
        jobData.scopeURL = context->completeURL(scope);
114
117
118
    if (!jobData.scopeURL.isNull() && !jobData.scopeURL.protocolIsInHTTPFamily()) {
119
        promise->reject(Exception { TypeError, ASCIILiteral("Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS") });
120
        return;
121
    }
122
123
    path = jobData.scopeURL.path();
124
    if (path.containsIgnoringASCIICase("%2f") || path.containsIgnoringASCIICase("%5c")) {
125
        promise->reject(Exception { TypeError, ASCIILiteral("Scope URL provided to serviceWorker.register() cannot have a path that contains '%2f' or '%5c'") });
126
        return;
127
    }
128
115
    jobData.clientCreationURL = context->url();
129
    jobData.clientCreationURL = context->url();
116
    jobData.topOrigin = SecurityOriginData::fromSecurityOrigin(context->topOrigin());
130
    jobData.topOrigin = SecurityOriginData::fromSecurityOrigin(context->topOrigin());
117
    jobData.type = ServiceWorkerJobType::Register;
131
    jobData.type = ServiceWorkerJobType::Register;
118
    jobData.registrationOptions = std::make_unique<RegistrationOptions>(options);
132
    jobData.registrationOptions = options;
119
133
120
    scheduleJob(ServiceWorkerJob::create(*this, WTFMove(promise), WTFMove(jobData)));
134
    scheduleJob(ServiceWorkerJob::create(*this, WTFMove(promise), WTFMove(jobData)));
121
}
135
}
Lines 125-131 void ServiceWorkerContainer::scheduleJob(Ref<ServiceWorkerJob>&& job) a/Source/WebCore/workers/service/ServiceWorkerContainer.cpp_sec4
125
    ASSERT(m_swConnection);
139
    ASSERT(m_swConnection);
126
140
127
    ServiceWorkerJob& rawJob = job.get();
141
    ServiceWorkerJob& rawJob = job.get();
128
    auto result = m_jobMap.add(rawJob.identifier(), WTFMove(job));
142
    auto result = m_jobMap.add(rawJob.data().identifier(), WTFMove(job));
129
    ASSERT_UNUSED(result, result.isNewEntry);
143
    ASSERT_UNUSED(result, result.isNewEntry);
130
144
131
    m_swConnection->scheduleJob(rawJob);
145
    m_swConnection->scheduleJob(rawJob);
Lines 145-153 void ServiceWorkerContainer::startMessages() a/Source/WebCore/workers/service/ServiceWorkerContainer.cpp_sec5
145
{
159
{
146
}
160
}
147
161
162
void ServiceWorkerContainer::jobFailedWithException(ServiceWorkerJob& job, const Exception& exception)
163
{
164
    job.promise().reject(exception);
165
    jobDidFinish(job);
166
}
167
168
void ServiceWorkerContainer::jobResolvedWithRegistration(ServiceWorkerJob& job, const ServiceWorkerRegistrationData& data)
169
{
170
    ScopeGuard guard([this, &job] {
171
        jobDidFinish(job);
172
    });
173
174
    auto* context = scriptExecutionContext();
175
    if (!context) {
176
        LOG_ERROR("ServiceWorkerContainer::jobResolvedWithRegistration called but the containers ScriptExecutionContext is gone");
177
        return;
178
    }
179
180
    auto registration = ServiceWorkerRegistration::create(*context, data);
181
    job.promise().resolve<IDLInterface<ServiceWorkerRegistration>>(registration.get());
182
}
183
148
void ServiceWorkerContainer::jobDidFinish(ServiceWorkerJob& job)
184
void ServiceWorkerContainer::jobDidFinish(ServiceWorkerJob& job)
149
{
185
{
150
    auto taken = m_jobMap.take(job.identifier());
186
    auto taken = m_jobMap.take(job.data().identifier());
151
    ASSERT_UNUSED(taken, taken.get() == &job);
187
    ASSERT_UNUSED(taken, taken.get() == &job);
152
}
188
}
153
189
- a/Source/WebCore/workers/service/ServiceWorkerContainer.h -1 / +5 lines
Lines 70-76 public: a/Source/WebCore/workers/service/ServiceWorkerContainer.h_sec1
70
70
71
private:
71
private:
72
    void scheduleJob(Ref<ServiceWorkerJob>&&);
72
    void scheduleJob(Ref<ServiceWorkerJob>&&);
73
    void jobDidFinish(ServiceWorkerJob&) final;
73
74
    void jobFailedWithException(ServiceWorkerJob&, const Exception&) final;
75
    void jobResolvedWithRegistration(ServiceWorkerJob&, const ServiceWorkerRegistrationData&) final;
76
    void jobDidFinish(ServiceWorkerJob&);
77
74
    uint64_t connectionIdentifier() final;
78
    uint64_t connectionIdentifier() final;
75
79
76
    const char* activeDOMObjectName() const final;
80
    const char* activeDOMObjectName() const final;
- a/Source/WebCore/workers/service/ServiceWorkerJob.cpp -7 / +11 lines
Lines 30-45 a/Source/WebCore/workers/service/ServiceWorkerJob.cpp_sec1
30
30
31
#include "JSDOMPromiseDeferred.h"
31
#include "JSDOMPromiseDeferred.h"
32
#include "ServiceWorkerJobData.h"
32
#include "ServiceWorkerJobData.h"
33
#include "ServiceWorkerRegistration.h"
33
34
34
namespace WebCore {
35
namespace WebCore {
35
36
36
static std::atomic<uint64_t> currentIdentifier;
37
38
ServiceWorkerJob::ServiceWorkerJob(ServiceWorkerJobClient& client, Ref<DeferredPromise>&& promise, ServiceWorkerJobData&& jobData)
37
ServiceWorkerJob::ServiceWorkerJob(ServiceWorkerJobClient& client, Ref<DeferredPromise>&& promise, ServiceWorkerJobData&& jobData)
39
    : m_client(client)
38
    : m_client(client)
40
    , m_jobData(WTFMove(jobData))
39
    , m_jobData(WTFMove(jobData))
41
    , m_promise(WTFMove(promise))
40
    , m_promise(WTFMove(promise))
42
    , m_identifier(++currentIdentifier)
43
{
41
{
44
}
42
}
45
43
Lines 51-63 ServiceWorkerJob::~ServiceWorkerJob() a/Source/WebCore/workers/service/ServiceWorkerJob.cpp_sec2
51
void ServiceWorkerJob::failedWithException(const Exception& exception)
49
void ServiceWorkerJob::failedWithException(const Exception& exception)
52
{
50
{
53
    ASSERT(currentThread() == m_creationThread);
51
    ASSERT(currentThread() == m_creationThread);
54
55
    ASSERT(!m_completed);
52
    ASSERT(!m_completed);
56
    m_promise->reject(exception);
53
57
    m_completed = true;
54
    m_completed = true;
55
    m_client->jobFailedWithException(*this, exception);
56
}
58
57
59
    // Can cause this to be deleted.
58
void ServiceWorkerJob::resolvedWithRegistration(const ServiceWorkerRegistrationData& data)
60
    m_client->jobDidFinish(*this);
59
{
60
    ASSERT(currentThread() == m_creationThread);
61
    ASSERT(!m_completed);
62
63
    m_completed = true;
64
    m_client->jobResolvedWithRegistration(*this, data);
61
}
65
}
62
66
63
} // namespace WebCore
67
} // namespace WebCore
- a/Source/WebCore/workers/service/ServiceWorkerJob.h -4 / +4 lines
Lines 39-44 namespace WebCore { a/Source/WebCore/workers/service/ServiceWorkerJob.h_sec1
39
class DeferredPromise;
39
class DeferredPromise;
40
class Exception;
40
class Exception;
41
enum class ServiceWorkerJobType;
41
enum class ServiceWorkerJobType;
42
struct ServiceWorkerRegistrationData;
42
43
43
class ServiceWorkerJob : public ThreadSafeRefCounted<ServiceWorkerJob> {
44
class ServiceWorkerJob : public ThreadSafeRefCounted<ServiceWorkerJob> {
44
public:
45
public:
Lines 49-59 public: a/Source/WebCore/workers/service/ServiceWorkerJob.h_sec2
49
50
50
    WEBCORE_EXPORT ~ServiceWorkerJob();
51
    WEBCORE_EXPORT ~ServiceWorkerJob();
51
52
52
    WEBCORE_EXPORT void failedWithException(const Exception&);
53
    void failedWithException(const Exception&);
53
54
    void resolvedWithRegistration(const ServiceWorkerRegistrationData&);
54
    uint64_t identifier() const { return m_identifier; }
55
55
56
    ServiceWorkerJobData data() const { return m_jobData; }
56
    ServiceWorkerJobData data() const { return m_jobData; }
57
    DeferredPromise& promise() { return m_promise.get(); }
57
58
58
private:
59
private:
59
    ServiceWorkerJob(ServiceWorkerJobClient&, Ref<DeferredPromise>&&, ServiceWorkerJobData&&);
60
    ServiceWorkerJob(ServiceWorkerJobClient&, Ref<DeferredPromise>&&, ServiceWorkerJobData&&);
Lines 63-69 private: a/Source/WebCore/workers/service/ServiceWorkerJob.h_sec3
63
    Ref<DeferredPromise> m_promise;
64
    Ref<DeferredPromise> m_promise;
64
65
65
    bool m_completed { false };
66
    bool m_completed { false };
66
    uint64_t m_identifier;
67
67
68
    Ref<RunLoop> m_runLoop { RunLoop::current() };
68
    Ref<RunLoop> m_runLoop { RunLoop::current() };
69
69
- a/Source/WebCore/workers/service/ServiceWorkerJobClient.h -1 / +5 lines
Lines 29-41 a/Source/WebCore/workers/service/ServiceWorkerJobClient.h_sec1
29
29
30
namespace WebCore {
30
namespace WebCore {
31
31
32
class Exception;
32
class ServiceWorkerJob;
33
class ServiceWorkerJob;
34
struct ServiceWorkerRegistrationData;
33
35
34
class ServiceWorkerJobClient {
36
class ServiceWorkerJobClient {
35
public:
37
public:
36
    virtual ~ServiceWorkerJobClient() { };
38
    virtual ~ServiceWorkerJobClient() { };
37
39
38
    virtual void jobDidFinish(ServiceWorkerJob&) = 0;
40
    virtual void jobFailedWithException(ServiceWorkerJob&, const Exception&) = 0;
41
    virtual void jobResolvedWithRegistration(ServiceWorkerJob&, const ServiceWorkerRegistrationData&) = 0;
42
39
    virtual uint64_t connectionIdentifier() = 0;
43
    virtual uint64_t connectionIdentifier() = 0;
40
44
41
    virtual void ref() = 0;
45
    virtual void ref() = 0;
- a/Source/WebCore/workers/service/ServiceWorkerJobData.cpp -5 / +2 lines
Lines 47-55 ServiceWorkerJobData::ServiceWorkerJobData(const ServiceWorkerJobData& other) a/Source/WebCore/workers/service/ServiceWorkerJobData.cpp_sec1
47
    topOrigin = other.topOrigin;
47
    topOrigin = other.topOrigin;
48
    scopeURL = other.scopeURL;
48
    scopeURL = other.scopeURL;
49
    type = other.type;
49
    type = other.type;
50
50
    registrationOptions = other.registrationOptions;
51
    if (other.registrationOptions)
52
        registrationOptions = std::make_unique<RegistrationOptions>(*other.registrationOptions);
53
}
51
}
54
52
55
ServiceWorkerRegistrationKey ServiceWorkerJobData::registrationKey() const
53
ServiceWorkerRegistrationKey ServiceWorkerJobData::registrationKey() const
Lines 68-76 ServiceWorkerJobData ServiceWorkerJobData::isolatedCopy() const a/Source/WebCore/workers/service/ServiceWorkerJobData.cpp_sec2
68
    result.clientCreationURL = clientCreationURL.isolatedCopy();
66
    result.clientCreationURL = clientCreationURL.isolatedCopy();
69
    result.topOrigin = topOrigin.isolatedCopy();
67
    result.topOrigin = topOrigin.isolatedCopy();
70
    result.scopeURL = scopeURL.isolatedCopy();
68
    result.scopeURL = scopeURL.isolatedCopy();
69
    result.registrationOptions = registrationOptions.isolatedCopy();
71
70
72
    if (registrationOptions)
73
        result.registrationOptions = std::make_unique<RegistrationOptions>(registrationOptions->isolatedCopy());
74
    return result;
71
    return result;
75
}
72
}
76
73
- a/Source/WebCore/workers/service/ServiceWorkerJobData.h -6 / +4 lines
Lines 41-47 public: a/Source/WebCore/workers/service/ServiceWorkerJobData.h_sec1
41
    ServiceWorkerJobData(const ServiceWorkerJobData&);
41
    ServiceWorkerJobData(const ServiceWorkerJobData&);
42
    ServiceWorkerJobData() = default;
42
    ServiceWorkerJobData() = default;
43
43
44
    uint64_t jobIdentifier() const { return m_jobIdentifier; }
44
    uint64_t identifier() const { return m_jobIdentifier; }
45
    uint64_t connectionIdentifier() const { return m_connectionIdentifier; }
45
    uint64_t connectionIdentifier() const { return m_connectionIdentifier; }
46
46
47
    URL scriptURL;
47
    URL scriptURL;
Lines 50-56 public: a/Source/WebCore/workers/service/ServiceWorkerJobData.h_sec2
50
    URL scopeURL;
50
    URL scopeURL;
51
    ServiceWorkerJobType type;
51
    ServiceWorkerJobType type;
52
52
53
    std::unique_ptr<RegistrationOptions> registrationOptions;
53
    RegistrationOptions registrationOptions;
54
54
55
    ServiceWorkerRegistrationKey registrationKey() const;
55
    ServiceWorkerRegistrationKey registrationKey() const;
56
    ServiceWorkerJobData isolatedCopy() const;
56
    ServiceWorkerJobData isolatedCopy() const;
Lines 70-77 void ServiceWorkerJobData::encode(Encoder& encoder) const a/Source/WebCore/workers/service/ServiceWorkerJobData.h_sec3
70
    encoder.encodeEnum(type);
70
    encoder.encodeEnum(type);
71
    switch (type) {
71
    switch (type) {
72
    case ServiceWorkerJobType::Register:
72
    case ServiceWorkerJobType::Register:
73
        RELEASE_ASSERT(registrationOptions);
73
        encoder << registrationOptions;
74
        encoder << *registrationOptions;
75
        break;
74
        break;
76
    }
75
    }
77
}
76
}
Lines 96-103 bool ServiceWorkerJobData::decode(Decoder& decoder, ServiceWorkerJobData& jobDat a/Source/WebCore/workers/service/ServiceWorkerJobData.h_sec4
96
95
97
    switch (jobData.type) {
96
    switch (jobData.type) {
98
    case ServiceWorkerJobType::Register:
97
    case ServiceWorkerJobType::Register:
99
        jobData.registrationOptions = std::make_unique<RegistrationOptions>();
98
        if (!decoder.decode(jobData.registrationOptions))
100
        if (!decoder.decode(*jobData.registrationOptions))
101
            return false;
99
            return false;
102
        break;
100
        break;
103
    }
101
    }
- a/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp +7 lines
Lines 30-35 a/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp_sec1
30
30
31
namespace WebCore {
31
namespace WebCore {
32
32
33
ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& context, const ServiceWorkerRegistrationData& registrationData)
34
    : ActiveDOMObject(&context)
35
    , m_registrationData(registrationData)
36
{
37
    suspendIfNeeded();
38
}
39
33
ServiceWorker* ServiceWorkerRegistration::installing()
40
ServiceWorker* ServiceWorkerRegistration::installing()
34
{
41
{
35
    return nullptr;
42
    return nullptr;
- a/Source/WebCore/workers/service/ServiceWorkerRegistration.h -4 / +15 lines
Lines 27-41 a/Source/WebCore/workers/service/ServiceWorkerRegistration.h_sec1
27
27
28
#if ENABLE(SERVICE_WORKER)
28
#if ENABLE(SERVICE_WORKER)
29
29
30
#include "ActiveDOMObject.h"
30
#include "EventTarget.h"
31
#include "EventTarget.h"
31
#include "JSDOMPromiseDeferred.h"
32
#include "JSDOMPromiseDeferred.h"
33
#include "ServiceWorkerRegistrationData.h"
32
34
33
namespace WebCore {
35
namespace WebCore {
34
36
35
class Frame;
37
class ScriptExecutionContext;
36
class ServiceWorker;
38
class ServiceWorker;
37
39
38
class ServiceWorkerRegistration final : public EventTargetWithInlineData {
40
class ServiceWorkerRegistration final : public EventTargetWithInlineData, public ActiveDOMObject {
39
public:
41
public:
40
    enum class UpdateViaCache {
42
    enum class UpdateViaCache {
41
        Imports,
43
        Imports,
Lines 43-49 public: a/Source/WebCore/workers/service/ServiceWorkerRegistration.h_sec2
43
        None,
45
        None,
44
    };
46
    };
45
47
46
    static Ref<ServiceWorkerRegistration> create(Frame& frame) { return adoptRef(*new ServiceWorkerRegistration(frame)); }
48
    static Ref<ServiceWorkerRegistration> create(ScriptExecutionContext& context, const ServiceWorkerRegistrationData& data)
49
    {
50
        return adoptRef(*new ServiceWorkerRegistration(context, data));
51
    }
52
47
    virtual ~ServiceWorkerRegistration() = default;
53
    virtual ~ServiceWorkerRegistration() = default;
48
54
49
    ServiceWorker* installing();
55
    ServiceWorker* installing();
Lines 57-68 public: a/Source/WebCore/workers/service/ServiceWorkerRegistration.h_sec3
57
    void unregister(Ref<DeferredPromise>&&);
63
    void unregister(Ref<DeferredPromise>&&);
58
64
59
private:
65
private:
60
    explicit ServiceWorkerRegistration(Frame&);
66
    ServiceWorkerRegistration(ScriptExecutionContext&, const ServiceWorkerRegistrationData&);
61
67
62
    virtual EventTargetInterface eventTargetInterface() const;
68
    virtual EventTargetInterface eventTargetInterface() const;
63
    virtual ScriptExecutionContext* scriptExecutionContext() const;
69
    virtual ScriptExecutionContext* scriptExecutionContext() const;
64
    void refEventTarget() final { ref(); }
70
    void refEventTarget() final { ref(); }
65
    void derefEventTarget() final { deref(); }
71
    void derefEventTarget() final { deref(); }
72
73
    const char* activeDOMObjectName() const { return "ServiceWorkerRegistration"; }
74
    bool canSuspendForDocumentSuspension() const { return false; }
75
76
    ServiceWorkerRegistrationData m_registrationData;
66
};
77
};
67
78
68
} // namespace WebCore
79
} // namespace WebCore
- a/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp +43 lines
Line 0 a/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp_sec1
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 "ServiceWorkerRegistrationData.h"
28
29
#if ENABLE(SERVICE_WORKER)
30
31
namespace WebCore {
32
33
ServiceWorkerRegistrationData ServiceWorkerRegistrationData::isolatedCopy() const
34
{
35
    ServiceWorkerRegistrationData result;
36
    result.key = key.isolatedCopy();
37
    result.identifier = identifier;
38
    return result;
39
}
40
41
} // namespace WTF
42
43
#endif // ENABLE(SERVICE_WORKER)
- a/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h +64 lines
Line 0 a/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h_sec1
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 "ServiceWorkerRegistrationKey.h"
31
32
namespace WebCore {
33
34
struct ServiceWorkerRegistrationData {
35
    ServiceWorkerRegistrationKey key;
36
    uint64_t identifier;
37
38
    ServiceWorkerRegistrationData isolatedCopy() const;
39
40
    template<class Encoder> void encode(Encoder&) const;
41
    template<class Decoder> static bool decode(Decoder&, ServiceWorkerRegistrationData&);
42
};
43
44
45
template<class Encoder>
46
void ServiceWorkerRegistrationData::encode(Encoder& encoder) const
47
{
48
    encoder << key << identifier;
49
}
50
51
template<class Decoder>
52
bool ServiceWorkerRegistrationData::decode(Decoder& decoder, ServiceWorkerRegistrationData& data)
53
{
54
    if (!decoder.decode(data.key))
55
        return false;
56
    if (!decoder.decodeEnum(data.identifier))
57
        return false;
58
59
    return true;
60
}
61
62
} // namespace WTF
63
64
#endif // ENABLE(SERVICE_WORKER)
- a/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp +8 lines
Lines 51-56 bool ServiceWorkerRegistrationKey::operator==(const ServiceWorkerRegistrationKey a/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp_sec1
51
    return clientCreationURL == other.clientCreationURL && topOrigin == other.topOrigin;
51
    return clientCreationURL == other.clientCreationURL && topOrigin == other.topOrigin;
52
}
52
}
53
53
54
ServiceWorkerRegistrationKey ServiceWorkerRegistrationKey::isolatedCopy() const
55
{
56
    ServiceWorkerRegistrationKey result;
57
    result.clientCreationURL = clientCreationURL.isolatedCopy();
58
    result.topOrigin = topOrigin.isolatedCopy();
59
    return result;
60
}
61
54
} // namespace WebCore
62
} // namespace WebCore
55
63
56
#endif // ENABLE(SERVICE_WORKER)
64
#endif // ENABLE(SERVICE_WORKER)
- a/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h +22 lines
Lines 40-47 struct ServiceWorkerRegistrationKey { a/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h_sec1
40
    unsigned hash() const;
40
    unsigned hash() const;
41
41
42
    bool operator==(const ServiceWorkerRegistrationKey&) const;
42
    bool operator==(const ServiceWorkerRegistrationKey&) const;
43
44
    ServiceWorkerRegistrationKey isolatedCopy() const;
45
46
    template<class Encoder> void encode(Encoder&) const;
47
    template<class Decoder> static bool decode(Decoder&, ServiceWorkerRegistrationKey&);
43
};
48
};
44
49
50
template<class Encoder>
51
void ServiceWorkerRegistrationKey::encode(Encoder& encoder) const
52
{
53
    encoder << clientCreationURL << topOrigin;
54
}
55
56
template<class Decoder>
57
bool ServiceWorkerRegistrationKey::decode(Decoder& decoder, ServiceWorkerRegistrationKey& key)
58
{
59
    if (!decoder.decode(key.clientCreationURL))
60
        return false;
61
    if (!decoder.decode(key.topOrigin))
62
        return false;
63
64
    return true;
65
}
66
45
} // namespace WebCore
67
} // namespace WebCore
46
68
47
namespace WTF {
69
namespace WTF {
- a/Source/WebCore/workers/service/server/SWClientConnection.cpp -1 / +12 lines
Lines 43-49 SWClientConnection::~SWClientConnection() a/Source/WebCore/workers/service/server/SWClientConnection.cpp_sec1
43
43
44
void SWClientConnection::scheduleJob(ServiceWorkerJob& job)
44
void SWClientConnection::scheduleJob(ServiceWorkerJob& job)
45
{
45
{
46
    auto addResult = m_scheduledJobs.add(job.identifier(), &job);
46
    auto addResult = m_scheduledJobs.add(job.data().identifier(), &job);
47
    ASSERT_UNUSED(addResult, addResult.isNewEntry);
47
    ASSERT_UNUSED(addResult, addResult.isNewEntry);
48
48
49
    scheduleJobInServer(job.data());
49
    scheduleJobInServer(job.data());
Lines 60-65 void SWClientConnection::jobRejectedInServer(uint64_t jobIdentifier, const Excep a/Source/WebCore/workers/service/server/SWClientConnection.cpp_sec2
60
    job->failedWithException(exceptionData.toException());
60
    job->failedWithException(exceptionData.toException());
61
}
61
}
62
62
63
void SWClientConnection::jobResolvedInServer(uint64_t jobIdentifier, const ServiceWorkerRegistrationData& registrationData)
64
{
65
    auto job = m_scheduledJobs.take(jobIdentifier);
66
    if (!job) {
67
        LOG_ERROR("Job %" PRIu64 " resolved in server, but was not found", jobIdentifier);
68
        return;
69
    }
70
71
    job->resolvedWithRegistration(registrationData);
72
}
73
63
} // namespace WebCore
74
} // namespace WebCore
64
75
65
#endif // ENABLE(SERVICE_WORKER)
76
#endif // ENABLE(SERVICE_WORKER)
- a/Source/WebCore/workers/service/server/SWClientConnection.h +2 lines
Lines 34-39 a/Source/WebCore/workers/service/server/SWClientConnection.h_sec1
34
namespace WebCore {
34
namespace WebCore {
35
35
36
struct ExceptionData;
36
struct ExceptionData;
37
struct ServiceWorkerRegistrationData;
37
38
38
class SWClientConnection : public ThreadSafeRefCounted<SWClientConnection> {
39
class SWClientConnection : public ThreadSafeRefCounted<SWClientConnection> {
39
public:
40
public:
Lines 46-51 public: a/Source/WebCore/workers/service/server/SWClientConnection.h_sec2
46
47
47
protected:
48
protected:
48
    WEBCORE_EXPORT void jobRejectedInServer(uint64_t jobIdentifier, const ExceptionData&);
49
    WEBCORE_EXPORT void jobRejectedInServer(uint64_t jobIdentifier, const ExceptionData&);
50
    WEBCORE_EXPORT void jobResolvedInServer(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&);
49
51
50
private:
52
private:
51
    virtual void scheduleJobInServer(const ServiceWorkerJobData&) = 0;
53
    virtual void scheduleJobInServer(const ServiceWorkerJobData&) = 0;
- a/Source/WebCore/workers/service/server/SWServer.cpp -4 / +17 lines
Lines 54-59 SWServer::~SWServer() a/Source/WebCore/workers/service/server/SWServer.cpp_sec1
54
    RELEASE_ASSERT(m_connections.isEmpty());
54
    RELEASE_ASSERT(m_connections.isEmpty());
55
    RELEASE_ASSERT(m_registrations.isEmpty());
55
    RELEASE_ASSERT(m_registrations.isEmpty());
56
56
57
    ASSERT(m_taskQueue.isEmpty());
58
    ASSERT(m_taskReplyQueue.isEmpty());
59
57
    // For a SWServer to be cleanly shut down its thread must have finished and gone away.
60
    // 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.
61
    // 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.
62
    // But once it does start happening, this ASSERT will catch us doing it wrong.
Lines 63-69 SWServer::~SWServer() a/Source/WebCore/workers/service/server/SWServer.cpp_sec2
63
66
64
void SWServer::Connection::scheduleJobInServer(const ServiceWorkerJobData& jobData)
67
void SWServer::Connection::scheduleJobInServer(const ServiceWorkerJobData& jobData)
65
{
68
{
66
    LOG(ServiceWorker, "Scheduling ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.jobIdentifier());
69
    LOG(ServiceWorker, "Scheduling ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.identifier());
67
    ASSERT(identifier() == jobData.connectionIdentifier());
70
    ASSERT(identifier() == jobData.connectionIdentifier());
68
71
69
    m_server.scheduleJob(jobData);
72
    m_server.scheduleJob(jobData);
Lines 82-88 void SWServer::scheduleJob(const ServiceWorkerJobData& jobData) a/Source/WebCore/workers/service/server/SWServer.cpp_sec3
82
85
83
    auto result = m_registrations.add(jobData.registrationKey(), nullptr);
86
    auto result = m_registrations.add(jobData.registrationKey(), nullptr);
84
    if (result.isNewEntry)
87
    if (result.isNewEntry)
85
        result.iterator->value = std::make_unique<SWServerRegistration>(*this);
88
        result.iterator->value = std::make_unique<SWServerRegistration>(*this, jobData.registrationKey());
86
89
87
    ASSERT(result.iterator->value);
90
    ASSERT(result.iterator->value);
88
91
Lines 91-102 void SWServer::scheduleJob(const ServiceWorkerJobData& jobData) a/Source/WebCore/workers/service/server/SWServer.cpp_sec4
91
94
92
void SWServer::rejectJob(const ServiceWorkerJobData& jobData, const ExceptionData& exceptionData)
95
void SWServer::rejectJob(const ServiceWorkerJobData& jobData, const ExceptionData& exceptionData)
93
{
96
{
94
    LOG(ServiceWorker, "Rejected ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.jobIdentifier());
97
    LOG(ServiceWorker, "Rejected ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.identifier());
98
    auto* connection = m_connections.get(jobData.connectionIdentifier());
99
    if (!connection)
100
        return;
101
102
    connection->rejectJobInClient(jobData.identifier(), exceptionData);
103
}
104
105
void SWServer::resolveJob(const ServiceWorkerJobData& jobData, const ServiceWorkerRegistrationData& registrationData)
106
{
107
    LOG(ServiceWorker, "Resolved ServiceWorker job %" PRIu64 "-%" PRIu64 " in server with registration %" PRIu64, jobData.connectionIdentifier(), jobData.identifier(), registrationData.identifier);
95
    auto* connection = m_connections.get(jobData.connectionIdentifier());
108
    auto* connection = m_connections.get(jobData.connectionIdentifier());
96
    if (!connection)
109
    if (!connection)
97
        return;
110
        return;
98
111
99
    connection->rejectJobInClient(jobData.jobIdentifier(), exceptionData);
112
    connection->resolveJobInClient(jobData.identifier(), registrationData);
100
}
113
}
101
114
102
void SWServer::taskThreadEntryPoint()
115
void SWServer::taskThreadEntryPoint()
- a/Source/WebCore/workers/service/server/SWServer.h -1 / +3 lines
Lines 42-47 namespace WebCore { a/Source/WebCore/workers/service/server/SWServer.h_sec1
42
42
43
class SWServerRegistration;
43
class SWServerRegistration;
44
struct ExceptionData;
44
struct ExceptionData;
45
struct ServiceWorkerRegistrationData;
45
46
46
class SWServer {
47
class SWServer {
47
public:
48
public:
Lines 60-65 public: a/Source/WebCore/workers/service/server/SWServer.h_sec2
60
61
61
    private:
62
    private:
62
        virtual void rejectJobInClient(uint64_t jobIdentifier, const ExceptionData&) = 0;
63
        virtual void rejectJobInClient(uint64_t jobIdentifier, const ExceptionData&) = 0;
64
        virtual void resolveJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData&) = 0;
63
65
64
        SWServer& m_server;
66
        SWServer& m_server;
65
        uint64_t m_identifier;
67
        uint64_t m_identifier;
Lines 70-76 public: a/Source/WebCore/workers/service/server/SWServer.h_sec3
70
72
71
    void scheduleJob(const ServiceWorkerJobData&);
73
    void scheduleJob(const ServiceWorkerJobData&);
72
    void rejectJob(const ServiceWorkerJobData&, const ExceptionData&);
74
    void rejectJob(const ServiceWorkerJobData&, const ExceptionData&);
73
75
    void resolveJob(const ServiceWorkerJobData&, const ServiceWorkerRegistrationData&);
74
    void postTask(CrossThreadTask&&);
76
    void postTask(CrossThreadTask&&);
75
    void postTaskReply(CrossThreadTask&&);
77
    void postTaskReply(CrossThreadTask&&);
76
78
- a/Source/WebCore/workers/service/server/SWServerRegistration.cpp -4 / +113 lines
Lines 30-41 a/Source/WebCore/workers/service/server/SWServerRegistration.cpp_sec1
30
30
31
#include "ExceptionData.h"
31
#include "ExceptionData.h"
32
#include "SWServer.h"
32
#include "SWServer.h"
33
#include "SWServerWorker.h"
34
#include "SecurityOrigin.h"
35
#include "ServiceWorkerRegistrationData.h"
36
#include "WorkerType.h"
33
37
34
namespace WebCore {
38
namespace WebCore {
35
39
36
SWServerRegistration::SWServerRegistration(SWServer& server)
40
static std::atomic<uint64_t> currentIdentifier;
41
42
SWServerRegistration::SWServerRegistration(SWServer& server, const ServiceWorkerRegistrationKey& key)
37
    : m_jobTimer(*this, &SWServerRegistration::startNextJob)
43
    : m_jobTimer(*this, &SWServerRegistration::startNextJob)
38
    , m_server(server)
44
    , m_server(server)
45
    , m_identifier(++currentIdentifier)
46
    , m_registrationKey(key)
39
{
47
{
40
}
48
}
41
49
Lines 65-81 void SWServerRegistration::startNextJob() a/Source/WebCore/workers/service/server/SWServerRegistration.cpp_sec2
65
    ASSERT(!m_jobQueue.isEmpty());
73
    ASSERT(!m_jobQueue.isEmpty());
66
74
67
    m_currentJob = std::make_unique<ServiceWorkerJobData>(m_jobQueue.takeFirst().isolatedCopy());
75
    m_currentJob = std::make_unique<ServiceWorkerJobData>(m_jobQueue.takeFirst().isolatedCopy());
68
    m_server.postTask(createCrossThreadTask(*this, &SWServerRegistration::performCurrentJob));
76
77
    switch (m_currentJob->type) {
78
    case ServiceWorkerJobType::Register:
79
        m_server.postTask(createCrossThreadTask(*this, &SWServerRegistration::runRegisterJob, *m_currentJob));
80
        return;
81
    }
82
83
    RELEASE_ASSERT_NOT_REACHED();
84
}
85
86
bool SWServerRegistration::isEmpty()
87
{
88
    ASSERT(!isMainThread());
89
90
    // Having or not-having an m_updateViaCache flag is currently
91
    // the signal as to whether or not this is an empty (i.e. "new") registration.
92
    // There will be a more explicit signal in the near future.
93
    return !m_updateViaCache;
69
}
94
}
70
95
71
void SWServerRegistration::performCurrentJob()
96
SWServerWorker* SWServerRegistration::getNewestWorker()
72
{
97
{
73
    ASSERT(!isMainThread());
98
    ASSERT(!isMainThread());
99
    if (m_installingWorker)
100
        return m_installingWorker.get();
101
    if (m_waitingWorker)
102
        return m_waitingWorker.get();
103
104
    return m_activeWorker.get();
105
}
106
107
void SWServerRegistration::runRegisterJob(const ServiceWorkerJobData& job)
108
{
109
    ASSERT(!isMainThread());
110
    ASSERT(job.type == ServiceWorkerJobType::Register);
111
112
    if (!shouldTreatAsPotentiallyTrustworthy(job.scriptURL))
113
        return rejectWithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Script URL is not potentially trustworthy") });
114
115
    // If the origin of job’s script url is not job’s referrer's origin, then:
116
    if (!protocolHostAndPortAreEqual(job.scriptURL, job.clientCreationURL))
117
        return rejectWithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Script origin does not match the registering client's origin") });
118
119
    // If the origin of job’s scope url is not job’s referrer's origin, then:
120
    if (!protocolHostAndPortAreEqual(job.scopeURL, job.clientCreationURL))
121
        return rejectWithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Scope origin does not match the registering client's origin") });
122
123
    // If registration is not null (in our parlance "empty"), then:
124
    if (!isEmpty()) {
125
        ASSERT(m_updateViaCache);
126
127
        m_uninstalling = false;
128
        auto* newestWorker = getNewestWorker();
129
        if (newestWorker && equalIgnoringFragmentIdentifier(job.scriptURL, newestWorker->scriptURL()) && job.registrationOptions.updateViaCache == *m_updateViaCache) {
130
            resolveWithRegistrationOnMainThread();
131
            return;
132
        }
133
    } else {
134
        m_scopeURL = job.scopeURL.isolatedCopy();
135
        m_scopeURL.removeFragmentIdentifier();
136
        m_updateViaCache = job.registrationOptions.updateViaCache;
137
    }
138
139
    runUpdateJob(job);
140
}
141
142
void SWServerRegistration::runUpdateJob(const ServiceWorkerJobData& job)
143
{
144
    // If registration is null (in our parlance "empty") or registration’s uninstalling flag is set, then:
145
    if (isEmpty())
146
        return rejectWithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a null/nonexistent service worker registration") });
147
    if (m_uninstalling)
148
        return rejectWithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a service worker registration that is uninstalling") });
149
150
    // 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:
151
    auto* newestWorker = getNewestWorker();
152
    if (newestWorker && !equalIgnoringFragmentIdentifier(job.scriptURL, newestWorker->scriptURL()))
153
        return rejectWithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a service worker with a requested script URL whose newest worker has a different script URL") });
154
155
    // FIXME: At this point we are ready to actually fetch the script for the worker in the registering context.
156
    // For now we're still hard coding the same rejection we have so far.
157
    rejectWithExceptionOnMainThread(ExceptionData { UnknownError, ASCIILiteral("serviceWorker job scheduling is not yet implemented") });
158
}
74
159
75
    auto exception = ExceptionData { UnknownError, ASCIILiteral("serviceWorker job scheduling is not yet implemented") };
160
void SWServerRegistration::rejectWithExceptionOnMainThread(const ExceptionData& exception)
161
{
162
    ASSERT(!isMainThread());
76
    m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::rejectCurrentJob, exception));
163
    m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::rejectCurrentJob, exception));
77
}
164
}
78
165
166
void SWServerRegistration::resolveWithRegistrationOnMainThread()
167
{
168
    ASSERT(!isMainThread());
169
    m_server.postTaskReply(createCrossThreadTask(*this, &SWServerRegistration::resolveCurrentJob, data()));
170
}
171
79
void SWServerRegistration::rejectCurrentJob(const ExceptionData& exceptionData)
172
void SWServerRegistration::rejectCurrentJob(const ExceptionData& exceptionData)
80
{
173
{
81
    ASSERT(isMainThread());
174
    ASSERT(isMainThread());
Lines 86-91 void SWServerRegistration::rejectCurrentJob(const ExceptionData& exceptionData) a/Source/WebCore/workers/service/server/SWServerRegistration.cpp_sec3
86
    finishCurrentJob();
179
    finishCurrentJob();
87
}
180
}
88
181
182
void SWServerRegistration::resolveCurrentJob(const ServiceWorkerRegistrationData& data)
183
{
184
    ASSERT(isMainThread());
185
    ASSERT(m_currentJob);
186
187
    m_server.resolveJob(*m_currentJob, data);
188
189
    finishCurrentJob();
190
}
191
89
void SWServerRegistration::finishCurrentJob()
192
void SWServerRegistration::finishCurrentJob()
90
{
193
{
91
    ASSERT(m_currentJob);
194
    ASSERT(m_currentJob);
Lines 98-103 void SWServerRegistration::finishCurrentJob() a/Source/WebCore/workers/service/server/SWServerRegistration.cpp_sec4
98
    startNextJob();
201
    startNextJob();
99
}
202
}
100
203
204
ServiceWorkerRegistrationData SWServerRegistration::data() const
205
{
206
    return { m_registrationKey, m_identifier };
207
}
208
209
101
} // namespace WebCore
210
} // namespace WebCore
102
211
103
#endif // ENABLE(SERVICE_WORKER)
212
#endif // ENABLE(SERVICE_WORKER)
- a/Source/WebCore/workers/service/server/SWServerRegistration.h -4 / +25 lines
Lines 28-62 a/Source/WebCore/workers/service/server/SWServerRegistration.h_sec1
28
#if ENABLE(SERVICE_WORKER)
28
#if ENABLE(SERVICE_WORKER)
29
29
30
#include "ServiceWorkerJobData.h"
30
#include "ServiceWorkerJobData.h"
31
#include "ServiceWorkerRegistrationData.h"
31
#include "Timer.h"
32
#include "Timer.h"
32
#include <wtf/Deque.h>
33
#include <wtf/Deque.h>
33
34
34
namespace WebCore {
35
namespace WebCore {
35
36
36
class SWServer;
37
class SWServer;
38
class SWServerWorker;
37
struct ExceptionData;
39
struct ExceptionData;
38
40
39
class SWServerRegistration {
41
class SWServerRegistration {
40
public:
42
public:
41
    explicit SWServerRegistration(SWServer&);
43
    explicit SWServerRegistration(SWServer&, const ServiceWorkerRegistrationKey&);
42
    SWServerRegistration(const SWServerRegistration&) = delete;
44
    SWServerRegistration(const SWServerRegistration&) = delete;
43
    ~SWServerRegistration();
45
    ~SWServerRegistration();
44
46
45
    void enqueueJob(const ServiceWorkerJobData&);
47
    void enqueueJob(const ServiceWorkerJobData&);
46
48
49
    uint64_t identifier() const { return m_identifier; }
50
    ServiceWorkerRegistrationData data() const;
51
47
private:
52
private:
48
    void jobTimerFired();
53
    void jobTimerFired();
49
    void performCurrentJob();
50
    void rejectCurrentJob(const ExceptionData&);
51
52
    void startNextJob();
54
    void startNextJob();
55
    void rejectCurrentJob(const ExceptionData&);
56
    void resolveCurrentJob(const ServiceWorkerRegistrationData&);
53
    void finishCurrentJob();
57
    void finishCurrentJob();
54
58
59
    void runRegisterJob(const ServiceWorkerJobData&);
60
    void runUpdateJob(const ServiceWorkerJobData&);
61
62
    void rejectWithExceptionOnMainThread(const ExceptionData&);
63
    void resolveWithRegistrationOnMainThread();
64
    bool isEmpty();
65
    SWServerWorker* getNewestWorker();
66
55
    Deque<ServiceWorkerJobData> m_jobQueue;
67
    Deque<ServiceWorkerJobData> m_jobQueue;
56
    std::unique_ptr<ServiceWorkerJobData> m_currentJob;
68
    std::unique_ptr<ServiceWorkerJobData> m_currentJob;
57
69
70
    bool m_uninstalling { false };
71
    std::unique_ptr<SWServerWorker> m_installingWorker;
72
    std::unique_ptr<SWServerWorker> m_waitingWorker;
73
    std::unique_ptr<SWServerWorker> m_activeWorker;
74
    URL m_scopeURL;
75
    std::optional<ServiceWorkerUpdateViaCache> m_updateViaCache;
76
58
    Timer m_jobTimer;
77
    Timer m_jobTimer;
59
    SWServer& m_server;
78
    SWServer& m_server;
79
    uint64_t m_identifier;
80
    ServiceWorkerRegistrationKey m_registrationKey;
60
};
81
};
61
82
62
} // namespace WebCore
83
} // namespace WebCore
- a/Source/WebCore/workers/service/server/SWServerWorker.cpp +48 lines
Line 0 a/Source/WebCore/workers/service/server/SWServerWorker.cpp_sec1
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 "SWServerWorker.h"
28
29
#if ENABLE(SERVICE_WORKER)
30
31
#include <wtf/MainThread.h>
32
33
namespace WebCore {
34
35
SWServerWorker::SWServerWorker(const URL& url)
36
    : m_scriptURL(url)
37
{
38
    ASSERT(!isMainThread());
39
}
40
41
SWServerWorker::~SWServerWorker()
42
{
43
    ASSERT(!isMainThread());
44
}
45
46
} // namespace WebCore
47
48
#endif // ENABLE(SERVICE_WORKER)
- a/Source/WebCore/workers/service/server/SWServerWorker.h +47 lines
Line 0 a/Source/WebCore/workers/service/server/SWServerWorker.h_sec1
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 "URL.h"
31
32
namespace WebCore {
33
34
class SWServerWorker {
35
public:
36
    SWServerWorker(const URL&);
37
    SWServerWorker(const SWServerWorker&) = delete;
38
    ~SWServerWorker();
39
    const URL& scriptURL() const { return m_scriptURL; }
40
41
private:
42
    URL m_scriptURL;
43
};
44
45
} // namespace WebCore
46
47
#endif // ENABLE(SERVICE_WORKER)
- a/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp +5 lines
Lines 65-70 void WebSWServerConnection::rejectJobInClient(uint64_t jobIdentifier, const Exce a/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp_sec1
65
    send(Messages::WebSWClientConnection::JobRejectedInServer(jobIdentifier, exceptionData));
65
    send(Messages::WebSWClientConnection::JobRejectedInServer(jobIdentifier, exceptionData));
66
}
66
}
67
67
68
void WebSWServerConnection::resolveJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData& registrationData)
69
{
70
    send(Messages::WebSWClientConnection::JobResolvedInServer(jobIdentifier, registrationData));
71
}
72
68
} // namespace WebKit
73
} // namespace WebKit
69
74
70
#endif // ENABLE(SERVICE_WORKER)
75
#endif // ENABLE(SERVICE_WORKER)
- a/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h +1 lines
Lines 50-55 public: a/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h_sec1
50
private:
50
private:
51
    // Implement SWServer::Connection
51
    // Implement SWServer::Connection
52
    void rejectJobInClient(uint64_t jobIdentifier, const WebCore::ExceptionData&) final;
52
    void rejectJobInClient(uint64_t jobIdentifier, const WebCore::ExceptionData&) final;
53
    void resolveJobInClient(uint64_t jobIdentifier, const WebCore::ServiceWorkerRegistrationData&) final;
53
54
54
    IPC::Connection* messageSenderConnection() final { return m_connection.ptr(); }
55
    IPC::Connection* messageSenderConnection() final { return m_connection.ptr(); }
55
    uint64_t messageSenderDestinationID() final { return identifier(); }
56
    uint64_t messageSenderDestinationID() final { return identifier(); }
- a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in +1 lines
Lines 25-30 a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in_sec1
25
messages -> WebSWClientConnection {
25
messages -> WebSWClientConnection {
26
    # When possible, these messages can be implemented directly by WebCore::SWServer::Connection
26
    # When possible, these messages can be implemented directly by WebCore::SWServer::Connection
27
    JobRejectedInServer(uint64_t identifier, struct WebCore::ExceptionData exception)
27
    JobRejectedInServer(uint64_t identifier, struct WebCore::ExceptionData exception)
28
    JobResolvedInServer(uint64_t identifier, struct WebCore::ServiceWorkerRegistrationData registration)
28
}
29
}
29
30
30
#endif // ENABLE(SERVICE_WORKER)
31
#endif // ENABLE(SERVICE_WORKER)
- a/LayoutTests/ChangeLog +11 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2017-08-30  Brady Eidson  <beidson@apple.com>
2
3
        Implement all of "Register" right up until where the script is fetched.
4
        https://bugs.webkit.org/show_bug.cgi?id=176082
5
6
        Reviewed by Andy Estes.
7
8
        * http/tests/workers/service/basic-register-exceptions-expected.txt: Added.
9
        * http/tests/workers/service/basic-register-exceptions.html: Added.
10
        * http/tests/workers/service/resources/basic-register-exceptions.js: Added.
11
1
2017-08-30  Per Arne Vollan  <pvollan@apple.com>
12
2017-08-30  Per Arne Vollan  <pvollan@apple.com>
2
13
3
        The test imported/w3c/web-platform-tests/dom/traversal/NodeFilter-constants.html is slow on Windows.
14
        The test imported/w3c/web-platform-tests/dom/traversal/NodeFilter-constants.html is slow on Windows.
- a/LayoutTests/http/tests/workers/service/basic-register-exceptions-expected.txt +9 lines
Line 0 a/LayoutTests/http/tests/workers/service/basic-register-exceptions-expected.txt_sec1
1
CONSOLE MESSAGE: line 10: Registration failed with error: TypeError: serviceWorker.register() cannot be called with an empty script URL
2
CONSOLE MESSAGE: line 20: Registration failed with error: TypeError: serviceWorker.register() must be called with a valid relative script URL
3
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
4
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'
5
CONSOLE MESSAGE: line 50: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS
6
CONSOLE MESSAGE: line 60: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() cannot have a path that contains '%2f' or '%5c'
7
CONSOLE MESSAGE: line 70: Registration failed with error: SecurityError: Script origin does not match the registering client's origin
8
CONSOLE MESSAGE: line 81: Registration failed with error: SecurityError: Scope origin does not match the registering client's origin
9
- a/LayoutTests/http/tests/workers/service/basic-register-exceptions.html +9 lines
Line 0 a/LayoutTests/http/tests/workers/service/basic-register-exceptions.html_sec1
1
<html>
2
<head>
3
<script src="resources/sw-test-pre.js"></script>
4
</head>
5
<body>
6
7
<script src="resources/basic-register-exceptions.js"></script>
8
</body>
9
</html>
- a/LayoutTests/http/tests/workers/service/resources/basic-register-exceptions.js +87 lines
Line 0 a/LayoutTests/http/tests/workers/service/resources/basic-register-exceptions.js_sec1
1
function done()
2
{
3
    finishSWTest();
4
}
5
6
navigator.serviceWorker.register("", { })
7
.then(function(r) {
8
	console.log("Registered! (unexpectedly)");
9
}, function(e) {
10
	console.log("Registration failed with error: " + e);
11
})
12
.catch(function(e) {
13
	console.log("Exception registering: " + e);
14
});
15
16
navigator.serviceWorker.register("http://127.0.0.1:abc", { })
17
.then(function(r) {
18
	console.log("Registered! (unexpectedly)");
19
}, function(e) {
20
	console.log("Registration failed with error: " + e);
21
})
22
.catch(function(e) {
23
	console.log("Exception registering: " + e);
24
});
25
26
navigator.serviceWorker.register("somescheme://script.js", { })
27
.then(function(r) {
28
	console.log("Registered! (unexpectedly)");
29
}, function(e) {
30
	console.log("Registration failed with error: " + e);
31
})
32
.catch(function(e) {
33
	console.log("Exception registering: " + e);
34
});
35
36
navigator.serviceWorker.register("resources/%2fscript.js", { })
37
.then(function(r) {
38
	console.log("Registered! (unexpectedly)");
39
}, function(e) {
40
	console.log("Registration failed with error: " + e);
41
})
42
.catch(function(e) {
43
	console.log("Exception registering: " + e);
44
});
45
46
navigator.serviceWorker.register("resources/script.js", { scope: "somescheme://script.js" })
47
.then(function(r) {
48
	console.log("Registered! (unexpectedly)");
49
}, function(e) {
50
	console.log("Registration failed with error: " + e);
51
})
52
.catch(function(e) {
53
	console.log("Exception registering: " + e);
54
});
55
56
navigator.serviceWorker.register("resources/script.js", { scope: "%2fscript.js" })
57
.then(function(r) {
58
	console.log("Registered! (unexpectedly)");
59
}, function(e) {
60
	console.log("Registration failed with error: " + e);
61
})
62
.catch(function(e) {
63
	console.log("Exception registering: " + e);
64
});
65
66
navigator.serviceWorker.register("http://localhost:8000/workers/service/resources/empty-worker.js", { })
67
.then(function(r) {
68
	console.log("Registered! (unexpectedly)");
69
}, function(e) {
70
	console.log("Registration failed with error: " + e);
71
})
72
.catch(function(e) {
73
	console.log("Exception registering: " + e);
74
});
75
76
navigator.serviceWorker.register("resources/empty-worker.js", { scope: "http://localhost:8000/workers/service/" })
77
.then(function(r) {
78
	console.log("Registered! (unexpectedly)");
79
	done();
80
}, function(e) {
81
	console.log("Registration failed with error: " + e);
82
	done();
83
})
84
.catch(function(e) {
85
	console.log("Exception registering: " + e);
86
	done();
87
});

Return to Bug 176082