Diff
Modified: trunk/LayoutTests/ChangeLog (224879 => 224880)
--- trunk/LayoutTests/ChangeLog 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/LayoutTests/ChangeLog 2017-11-15 18:00:24 UTC (rev 224880)
@@ -1,3 +1,20 @@
+2017-11-15 Chris Dumez <cdu...@apple.com>
+
+ [Service Workers] Implement Client API
+ https://bugs.webkit.org/show_bug.cgi?id=179709
+
+ Reviewed by Alex Christensen.
+
+ Add layout test coverage.
+
+ * http/tests/workers/service/Client-properties-auxiliary-expected.txt: Added.
+ * http/tests/workers/service/Client-properties-auxiliary.html: Added.
+ * http/tests/workers/service/Client-properties-expected.txt: Added.
+ * http/tests/workers/service/Client-properties-subframe-expected.txt: Added.
+ * http/tests/workers/service/Client-properties-subframe.html: Added.
+ * http/tests/workers/service/Client-properties.html: Added.
+ * http/tests/workers/service/resources/Client-properties-worker.js: Added.
+
2017-11-15 Youenn Fablet <you...@apple.com>
Remove service worker selection based on registration
Added: trunk/LayoutTests/http/tests/workers/service/Client-properties-auxiliary-expected.txt (0 => 224880)
--- trunk/LayoutTests/http/tests/workers/service/Client-properties-auxiliary-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/Client-properties-auxiliary-expected.txt 2017-11-15 18:00:24 UTC (rev 224880)
@@ -0,0 +1,5 @@
+client.url: http://127.0.0.1:8000/workers/service/Client-properties.html
+client.frameType: auxiliary
+client.type: window
+client.id is non empty: YES
+
Added: trunk/LayoutTests/http/tests/workers/service/Client-properties-auxiliary.html (0 => 224880)
--- trunk/LayoutTests/http/tests/workers/service/Client-properties-auxiliary.html (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/Client-properties-auxiliary.html 2017-11-15 18:00:24 UTC (rev 224880)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+if (window.testRunner)
+ testRunner.setCanOpenWindows(true);
+
+window.open("Client-properties.html");
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/workers/service/Client-properties-expected.txt (0 => 224880)
--- trunk/LayoutTests/http/tests/workers/service/Client-properties-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/Client-properties-expected.txt 2017-11-15 18:00:24 UTC (rev 224880)
@@ -0,0 +1,5 @@
+client.url: http://127.0.0.1:8000/workers/service/Client-properties.html
+client.frameType: top-level
+client.type: window
+client.id is non empty: YES
+
Added: trunk/LayoutTests/http/tests/workers/service/Client-properties-subframe-expected.txt (0 => 224880)
--- trunk/LayoutTests/http/tests/workers/service/Client-properties-subframe-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/Client-properties-subframe-expected.txt 2017-11-15 18:00:24 UTC (rev 224880)
@@ -0,0 +1,6 @@
+
+client.url: http://127.0.0.1:8000/workers/service/Client-properties.html
+client.frameType: nested
+client.type: window
+client.id is non empty: YES
+
Added: trunk/LayoutTests/http/tests/workers/service/Client-properties-subframe.html (0 => 224880)
--- trunk/LayoutTests/http/tests/workers/service/Client-properties-subframe.html (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/Client-properties-subframe.html 2017-11-15 18:00:24 UTC (rev 224880)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<iframe src=""
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/workers/service/Client-properties.html (0 => 224880)
--- trunk/LayoutTests/http/tests/workers/service/Client-properties.html (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/Client-properties.html 2017-11-15 18:00:24 UTC (rev 224880)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+
+logWindow = window;
+if (window.opener)
+ logWindow = window.opener;
+else if (window.parent)
+ logWindow = window.parent;
+
+navigator.serviceWorker.addEventListener("message", function(event) {
+ if (event.data ="" "DONE") {
+ finishSWTest();
+ return;
+ }
+ logWindow.log(event.data);
+});
+
+navigator.serviceWorker.register("resources/Client-properties-worker.js", { }).then(function() {
+ navigator.serviceWorker.controller.postMessage("TEST");
+});
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/workers/service/resources/Client-properties-worker.js (0 => 224880)
--- trunk/LayoutTests/http/tests/workers/service/resources/Client-properties-worker.js (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/Client-properties-worker.js 2017-11-15 18:00:24 UTC (rev 224880)
@@ -0,0 +1,10 @@
+self.addEventListener("message", function(e) {
+ let client = e.source;
+
+ client.postMessage("client.url: " + client.url);
+ client.postMessage("client.frameType: " + client.frameType);
+ client.postMessage("client.type: " + client.type);
+ client.postMessage("client.id is non empty: " + (client.id.length ? "YES" : "NO"));
+
+ client.postMessage("DONE");
+});
Modified: trunk/Source/WebCore/ChangeLog (224879 => 224880)
--- trunk/Source/WebCore/ChangeLog 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/ChangeLog 2017-11-15 18:00:24 UTC (rev 224880)
@@ -1,3 +1,53 @@
+2017-11-15 Chris Dumez <cdu...@apple.com>
+
+ [Service Workers] Implement Client API
+ https://bugs.webkit.org/show_bug.cgi?id=179709
+
+ Reviewed by Alex Christensen.
+
+ Implement Client API as per:
+ - https://w3c.github.io/ServiceWorker/#client-interface
+
+ Tests:
+ http/tests/workers/service/Client-properties.html
+ http/tests/workers/service/Client-properties-subframe.html
+ http/tests/workers/service/Client-properties-auxiliary.html
+
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * workers/service/ServiceWorker.cpp:
+ (WebCore::ServiceWorker::postMessage):
+ * workers/service/ServiceWorkerClient.cpp:
+ (WebCore::ServiceWorkerClient::ServiceWorkerClient):
+ (WebCore::ServiceWorkerClient::url const):
+ (WebCore::ServiceWorkerClient::type const):
+ (WebCore::ServiceWorkerClient::frameType const):
+ (WebCore::ServiceWorkerClient::id const):
+ (WebCore::ServiceWorkerClient::postMessage):
+ * workers/service/ServiceWorkerClient.h:
+ (WebCore::ServiceWorkerClient::create):
+ * workers/service/ServiceWorkerClientData.cpp: Copied from Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp.
+ (WebCore::toServiceWorkerClientFrameType):
+ (WebCore::ServiceWorkerClientData::isolatedCopy const):
+ (WebCore::ServiceWorkerClientData::from):
+ * workers/service/ServiceWorkerClientData.h: Copied from Source/WebCore/workers/service/ServiceWorkerClient.h.
+ (WebCore::ServiceWorkerClientData::encode const):
+ (WebCore::ServiceWorkerClientData::decode):
+ * workers/service/ServiceWorkerClientIdentifier.h:
+ (WebCore::ServiceWorkerClientIdentifier::encode const):
+ (WebCore::ServiceWorkerClientIdentifier::decode):
+ * workers/service/ServiceWorkerTypes.h:
+ * workers/service/ServiceWorkerWindowClient.cpp:
+ (WebCore::ServiceWorkerWindowClient::ServiceWorkerWindowClient):
+ * workers/service/ServiceWorkerWindowClient.h:
+ * workers/service/context/SWContextManager.cpp:
+ (WebCore::SWContextManager::postMessageToServiceWorkerGlobalScope):
+ * workers/service/context/SWContextManager.h:
+ * workers/service/context/ServiceWorkerThread.cpp:
+ (WebCore::ServiceWorkerThread::postMessageToServiceWorkerGlobalScope):
+ * workers/service/context/ServiceWorkerThread.h:
+ * workers/service/server/SWClientConnection.h:
+
2017-11-15 Ryan Haddad <ryanhad...@apple.com>
Unreviewed, rolling out r224863.
Modified: trunk/Source/WebCore/Sources.txt (224879 => 224880)
--- trunk/Source/WebCore/Sources.txt 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/Sources.txt 2017-11-15 18:00:24 UTC (rev 224880)
@@ -2172,6 +2172,7 @@
workers/service/FetchEvent.cpp
workers/service/ServiceWorker.cpp
workers/service/ServiceWorkerClient.cpp
+workers/service/ServiceWorkerClientData.cpp
workers/service/ServiceWorkerClients.cpp
workers/service/ServiceWorkerContainer.cpp
workers/service/ServiceWorkerContextData.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (224879 => 224880)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-11-15 18:00:24 UTC (rev 224880)
@@ -2176,7 +2176,7 @@
836589DE1F54A76900DC31F4 /* JSFileSystemDirectoryReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 836589D91F54A76200DC31F4 /* JSFileSystemDirectoryReader.h */; };
836589E01F54A76E00DC31F4 /* JSFileSystemEntriesCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 836589D81F54A76200DC31F4 /* JSFileSystemEntriesCallback.h */; };
8367587F1C56E99B008A1087 /* JSHTMLDataElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 834B86A81C56E93E00F3F0E3 /* JSHTMLDataElement.h */; };
- 8369FDFC1FA102E300C1FF1F /* ServiceWorkerClientType.h in Headers */ = {isa = PBXBuildFile; fileRef = 8369FDFB1FA102CB00C1FF1F /* ServiceWorkerClientType.h */; };
+ 8369FDFC1FA102E300C1FF1F /* ServiceWorkerClientType.h in Headers */ = {isa = PBXBuildFile; fileRef = 8369FDFB1FA102CB00C1FF1F /* ServiceWorkerClientType.h */; settings = {ATTRIBUTES = (Private, ); }; };
836ACEC31ECA62C8004BD012 /* DOMMatrixReadOnly.h in Headers */ = {isa = PBXBuildFile; fileRef = 836ACEC01ECA62B0004BD012 /* DOMMatrixReadOnly.h */; };
836ACECA1ECA9569004BD012 /* DOMMatrix.h in Headers */ = {isa = PBXBuildFile; fileRef = 836ACEC51ECA6654004BD012 /* DOMMatrix.h */; };
836ACECB1ECA956D004BD012 /* DOMMatrixInit.h in Headers */ = {isa = PBXBuildFile; fileRef = 836ACEC71ECA6654004BD012 /* DOMMatrixInit.h */; };
@@ -2193,6 +2193,7 @@
8371AC3B1F509BE400FBF284 /* ErrorCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 8371AC391F509BDD00FBF284 /* ErrorCallback.h */; };
8372DB311A6780A800C697C5 /* DiagnosticLoggingResultType.h in Headers */ = {isa = PBXBuildFile; fileRef = 8372DB301A6780A800C697C5 /* DiagnosticLoggingResultType.h */; settings = {ATTRIBUTES = (Private, ); }; };
83765F951DAC522F00C06537 /* MouseEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = 83765F941DAC521800C06537 /* MouseEventInit.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 8379363F1FBBB0B400C8023C /* ServiceWorkerClientData.h in Headers */ = {isa = PBXBuildFile; fileRef = 8379363E1FBBB0A500C8023C /* ServiceWorkerClientData.h */; settings = {ATTRIBUTES = (Private, ); }; };
837964CF1F8DB69D00218EA0 /* GeolocationPositionIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 837964CE1F8DB69A00218EA0 /* GeolocationPositionIOS.mm */; };
837A80131E1E127300026B9F /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 837A80111E1E127300026B9F /* Localizable.stringsdict */; };
837B7D201DC3F55000D051FC /* ValidationBubbleIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 837B7D1F1DC3F54C00D051FC /* ValidationBubbleIOS.mm */; };
@@ -9438,6 +9439,8 @@
837609C81F54CC13000C122D /* ErrorCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ErrorCallback.cpp; sourceTree = "<group>"; };
83765F931DAC521800C06537 /* MouseEventInit.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MouseEventInit.idl; sourceTree = "<group>"; };
83765F941DAC521800C06537 /* MouseEventInit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MouseEventInit.h; sourceTree = "<group>"; };
+ 8379363C1FBBB0A400C8023C /* ServiceWorkerClientData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerClientData.cpp; sourceTree = "<group>"; };
+ 8379363E1FBBB0A500C8023C /* ServiceWorkerClientData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerClientData.h; sourceTree = "<group>"; };
837964CE1F8DB69A00218EA0 /* GeolocationPositionIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = GeolocationPositionIOS.mm; path = Modules/geolocation/ios/GeolocationPositionIOS.mm; sourceTree = SOURCE_ROOT; };
837A80121E1E127300026B9F /* English */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = English; path = English.lproj/Localizable.stringsdict; sourceTree = SOURCE_ROOT; };
837B7D1F1DC3F54C00D051FC /* ValidationBubbleIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ValidationBubbleIOS.mm; sourceTree = "<group>"; };
@@ -17269,6 +17272,8 @@
46EF14271F97B7BA00C2A524 /* ServiceWorkerClient.cpp */,
46EF14241F97B7BA00C2A524 /* ServiceWorkerClient.h */,
46EF14281F97B7BA00C2A524 /* ServiceWorkerClient.idl */,
+ 8379363C1FBBB0A400C8023C /* ServiceWorkerClientData.cpp */,
+ 8379363E1FBBB0A500C8023C /* ServiceWorkerClientData.h */,
837D46251FA2A8C50054E1FA /* ServiceWorkerClientIdentifier.h */,
46EF14211F97B7BA00C2A524 /* ServiceWorkerClients.cpp */,
46EF14221F97B7BA00C2A524 /* ServiceWorkerClients.h */,
@@ -28934,6 +28939,7 @@
51F1755D1F3EBC8300C74950 /* ServiceWorker.h in Headers */,
A581ED131FB288CF00CED4EC /* ServiceWorkerAgent.h in Headers */,
46EF142D1F97B7D800C2A524 /* ServiceWorkerClient.h in Headers */,
+ 8379363F1FBBB0B400C8023C /* ServiceWorkerClientData.h in Headers */,
837D46271FA2A8CE0054E1FA /* ServiceWorkerClientIdentifier.h in Headers */,
46EF142C1F97B7D800C2A524 /* ServiceWorkerClients.h in Headers */,
8369FDFC1FA102E300C1FF1F /* ServiceWorkerClientType.h in Headers */,
Modified: trunk/Source/WebCore/workers/service/ServiceWorker.cpp (224879 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorker.cpp 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.cpp 2017-11-15 18:00:24 UTC (rev 224880)
@@ -33,6 +33,7 @@
#include "SWClientConnection.h"
#include "ScriptExecutionContext.h"
#include "SerializedScriptValue.h"
+#include "ServiceWorkerClientData.h"
#include "ServiceWorkerProvider.h"
#include <runtime/JSCJSValueInlines.h>
#include <wtf/NeverDestroyed.h>
@@ -126,8 +127,14 @@
if (channels && !channels->isEmpty())
return Exception { NotSupportedError, ASCIILiteral("Passing MessagePort objects to postMessage is not yet supported") };
+ // FIXME: We should add support for workers.
+ if (!is<Document>(context))
+ return Exception { NotSupportedError, ASCIILiteral("serviceWorkerClient.postMessage() from workers is not yet supported") };
+
+ auto sourceClientData = ServiceWorkerClientData::from(context);
+
auto& swConnection = ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(context.sessionID());
- swConnection.postMessageToServiceWorkerGlobalScope(identifier(), message.releaseReturnValue(), context);
+ swConnection.postMessageToServiceWorkerGlobalScope(identifier(), message.releaseReturnValue(), WTFMove(sourceClientData));
return { };
}
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClient.cpp (224879 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClient.cpp 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClient.cpp 2017-11-15 18:00:24 UTC (rev 224880)
@@ -37,11 +37,12 @@
namespace WebCore {
-ServiceWorkerClient::ServiceWorkerClient(ScriptExecutionContext& context, const Identifier& identifier, Type type)
+ServiceWorkerClient::ServiceWorkerClient(ScriptExecutionContext& context, ServiceWorkerClientData&& data)
: ContextDestructionObserver(&context)
- , m_identifier(identifier)
- , m_type(type)
+ , m_data(WTFMove(data))
{
+ ASSERT(m_data.identifier.serverConnectionIdentifier);
+ ASSERT(m_data.identifier.scriptExecutionContextIdentifier);
}
ServiceWorkerClient::~ServiceWorkerClient()
@@ -48,19 +49,24 @@
{
}
-String ServiceWorkerClient::url() const
+const URL& ServiceWorkerClient::url() const
{
- return { };
+ return m_data.url;
}
+auto ServiceWorkerClient::type() const -> Type
+{
+ return m_data.type;
+}
+
auto ServiceWorkerClient::frameType() const -> FrameType
{
- return FrameType::None;
+ return m_data.frameType;
}
String ServiceWorkerClient::id() const
{
- return m_identifier.toString();
+ return m_data.identifier.toString();
}
ExceptionOr<void> ServiceWorkerClient::postMessage(ScriptExecutionContext& context, JSC::JSValue messageValue, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
@@ -84,7 +90,7 @@
return Exception { NotSupportedError, ASCIILiteral("Passing MessagePort objects to postMessage is not yet supported") };
auto sourceIdentifier = downcast<ServiceWorkerGlobalScope>(context).thread().identifier();
- callOnMainThread([message = message.releaseReturnValue(), destinationIdentifier = m_identifier, sourceIdentifier, sourceOrigin = context.origin().isolatedCopy()] () mutable {
+ callOnMainThread([message = message.releaseReturnValue(), destinationIdentifier = m_data.identifier, sourceIdentifier, sourceOrigin = context.origin().isolatedCopy()] () mutable {
if (auto* connection = SWContextManager::singleton().connection())
connection->postMessageToServiceWorkerClient(destinationIdentifier, WTFMove(message), sourceIdentifier, sourceOrigin);
});
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClient.h (224879 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClient.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClient.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -29,8 +29,7 @@
#include "ContextDestructionObserver.h"
#include "ExceptionOr.h"
-#include "ServiceWorkerClientIdentifier.h"
-#include "ServiceWorkerClientType.h"
+#include "ServiceWorkerClientData.h"
#include <heap/Strong.h>
#include <wtf/RefCounted.h>
@@ -45,32 +44,26 @@
using Identifier = ServiceWorkerClientIdentifier;
using Type = ServiceWorkerClientType;
- enum class FrameType {
- Auxiliary,
- TopLevel,
- Nested,
- None
- };
+ using FrameType = ServiceWorkerClientFrameType;
- static Ref<ServiceWorkerClient> create(ScriptExecutionContext& context, const Identifier& identifier, Type type)
+ static Ref<ServiceWorkerClient> create(ScriptExecutionContext& context, ServiceWorkerClientData&& data)
{
- return adoptRef(*new ServiceWorkerClient(context, identifier, type));
+ return adoptRef(*new ServiceWorkerClient(context, WTFMove(data)));
}
~ServiceWorkerClient();
- String url() const;
+ const URL& url() const;
FrameType frameType() const;
- Type type() const { return m_type; }
+ Type type() const;
String id() const;
ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&& transfer);
protected:
- ServiceWorkerClient(ScriptExecutionContext&, const Identifier&, Type);
+ ServiceWorkerClient(ScriptExecutionContext&, ServiceWorkerClientData&&);
- Identifier m_identifier;
- Type m_type;
+ ServiceWorkerClientData m_data;
};
} // namespace WebCore
Copied: trunk/Source/WebCore/workers/service/ServiceWorkerClientData.cpp (from rev 224879, trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp) (0 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClientData.cpp (rev 0)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClientData.cpp 2017-11-15 18:00:24 UTC (rev 224880)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(SERVICE_WORKER)
+#include "ServiceWorkerClientData.h"
+
+#include "DOMWindow.h"
+#include "Document.h"
+#include "Frame.h"
+
+namespace WebCore {
+
+static ServiceWorkerClientFrameType toServiceWorkerClientFrameType(ScriptExecutionContext& context)
+{
+ if (!is<Document>(context))
+ return ServiceWorkerClientFrameType::None;
+
+ auto& document = downcast<Document>(context);
+ auto* frame = document.frame();
+ if (!frame)
+ return ServiceWorkerClientFrameType::None;
+
+ if (frame->isMainFrame()) {
+ if (auto* window = document.domWindow()) {
+ if (window->opener())
+ return ServiceWorkerClientFrameType::Auxiliary;
+ }
+ return ServiceWorkerClientFrameType::TopLevel;
+ }
+ return ServiceWorkerClientFrameType::Nested;
+}
+
+ServiceWorkerClientData ServiceWorkerClientData::isolatedCopy() const
+{
+ return { identifier, type, frameType, url.isolatedCopy() };
+}
+
+ServiceWorkerClientData ServiceWorkerClientData::from(ScriptExecutionContext& context)
+{
+ bool isDocument = is<Document>(context);
+
+ ASSERT_WITH_MESSAGE(isDocument, "Only documents have identifiers at the moment");
+
+ return {
+ { 0, downcast<Document>(context).identifier() },
+ isDocument ? ServiceWorkerClientType::Window : ServiceWorkerClientType::Worker,
+ toServiceWorkerClientFrameType(context),
+ context.url()
+ };
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
Copied: trunk/Source/WebCore/workers/service/ServiceWorkerClientData.h (from rev 224879, trunk/Source/WebCore/workers/service/ServiceWorkerClient.h) (0 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClientData.h (rev 0)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClientData.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "ServiceWorkerClientIdentifier.h"
+#include "ServiceWorkerClientType.h"
+#include "ServiceWorkerTypes.h"
+#include "URL.h"
+
+namespace WebCore {
+
+class ScriptExecutionContext;
+
+struct ServiceWorkerClientData {
+ ServiceWorkerClientIdentifier identifier;
+ ServiceWorkerClientType type;
+ ServiceWorkerClientFrameType frameType;
+ URL url;
+
+ ServiceWorkerClientData isolatedCopy() const;
+
+ static ServiceWorkerClientData from(ScriptExecutionContext&);
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static std::optional<ServiceWorkerClientData> decode(Decoder&);
+};
+
+template<class Encoder>
+void ServiceWorkerClientData::encode(Encoder& encoder) const
+{
+ encoder << identifier << type << frameType << url;
+}
+
+template<class Decoder>
+std::optional<ServiceWorkerClientData> ServiceWorkerClientData::decode(Decoder& decoder)
+{
+ std::optional<ServiceWorkerClientIdentifier> identifier;
+ decoder >> identifier;
+ if (!identifier)
+ return std::nullopt;
+
+ std::optional<ServiceWorkerClientType> type;
+ decoder >> type;
+ if (!type)
+ return std::nullopt;
+
+ std::optional<ServiceWorkerClientFrameType> frameType;
+ decoder >> frameType;
+ if (!frameType)
+ return std::nullopt;
+
+ std::optional<URL> url;
+ decoder >> url;
+ if (!url)
+ return std::nullopt;
+
+ return { { WTFMove(*identifier), WTFMove(*type), WTFMove(*frameType), WTFMove(*url) } };
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h (224879 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -34,6 +34,31 @@
uint64_t scriptExecutionContextIdentifier;
String toString() const { return String::number(serverConnectionIdentifier) + "-" + String::number(scriptExecutionContextIdentifier); }
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static std::optional<ServiceWorkerClientIdentifier> decode(Decoder&);
};
+template<class Encoder>
+void ServiceWorkerClientIdentifier::encode(Encoder& encoder) const
+{
+ encoder << serverConnectionIdentifier << scriptExecutionContextIdentifier;
}
+
+template<class Decoder>
+std::optional<ServiceWorkerClientIdentifier> ServiceWorkerClientIdentifier::decode(Decoder& decoder)
+{
+ std::optional<uint64_t> serverConnectionIdentifier;
+ decoder >> serverConnectionIdentifier;
+ if (!serverConnectionIdentifier)
+ return std::nullopt;
+
+ std::optional<uint64_t> scriptExecutionContextIdentifier;
+ decoder >> scriptExecutionContextIdentifier;
+ if (!scriptExecutionContextIdentifier)
+ return std::nullopt;
+
+ return { { WTFMove(*serverConnectionIdentifier), WTFMove(*scriptExecutionContextIdentifier) } };
+}
+
+}
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClientType.h (224879 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClientType.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClientType.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -27,6 +27,8 @@
#if ENABLE(SERVICE_WORKER)
+#include <wtf/EnumTraits.h>
+
namespace WebCore {
enum class ServiceWorkerClientType {
@@ -36,6 +38,20 @@
All
};
-}
+} // namespace WebCore
+namespace WTF {
+
+template <> struct EnumTraits<WebCore::ServiceWorkerClientType> {
+ using values = EnumValues<
+ WebCore::ServiceWorkerClientType,
+ WebCore::ServiceWorkerClientType::Window,
+ WebCore::ServiceWorkerClientType::Worker,
+ WebCore::ServiceWorkerClientType::Sharedworker,
+ WebCore::ServiceWorkerClientType::All
+ >;
+};
+
+} // namespace WTF
+
#endif
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h (224879 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -31,6 +31,7 @@
#include "ServiceWorkerIdentifier.h"
#include "ServiceWorkerRegistrationKey.h"
#include "ServiceWorkerTypes.h"
+#include "ServiceWorkerUpdateViaCache.h"
namespace WebCore {
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerTypes.h (224879 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorkerTypes.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerTypes.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -27,6 +27,7 @@
#if ENABLE(SERVICE_WORKER)
+#include <wtf/EnumTraits.h>
#include <wtf/ObjectIdentifier.h>
namespace WebCore {
@@ -45,6 +46,13 @@
Redundant,
};
+enum class ServiceWorkerClientFrameType {
+ Auxiliary,
+ TopLevel,
+ Nested,
+ None
+};
+
enum class ShouldNotifyWhenResolved { No, Yes };
enum ServiceWorkerRegistrationIdentifierType { };
@@ -55,4 +63,46 @@
} // namespace WebCore
+namespace WTF {
+
+template <> struct EnumTraits<WebCore::ServiceWorkerClientFrameType> {
+ using values = EnumValues<
+ WebCore::ServiceWorkerClientFrameType,
+ WebCore::ServiceWorkerClientFrameType::Auxiliary,
+ WebCore::ServiceWorkerClientFrameType::TopLevel,
+ WebCore::ServiceWorkerClientFrameType::Nested,
+ WebCore::ServiceWorkerClientFrameType::None
+ >;
+};
+
+template <> struct EnumTraits<WebCore::ServiceWorkerRegistrationState> {
+ using values = EnumValues<
+ WebCore::ServiceWorkerRegistrationState,
+ WebCore::ServiceWorkerRegistrationState::Installing,
+ WebCore::ServiceWorkerRegistrationState::Waiting,
+ WebCore::ServiceWorkerRegistrationState::Active
+ >;
+};
+
+template <> struct EnumTraits<WebCore::ServiceWorkerState> {
+ using values = EnumValues<
+ WebCore::ServiceWorkerState,
+ WebCore::ServiceWorkerState::Installing,
+ WebCore::ServiceWorkerState::Installed,
+ WebCore::ServiceWorkerState::Activating,
+ WebCore::ServiceWorkerState::Activated,
+ WebCore::ServiceWorkerState::Redundant
+ >;
+};
+
+template <> struct EnumTraits<WebCore::ShouldNotifyWhenResolved> {
+ using values = EnumValues<
+ WebCore::ShouldNotifyWhenResolved,
+ WebCore::ShouldNotifyWhenResolved::No,
+ WebCore::ShouldNotifyWhenResolved::Yes
+ >;
+};
+
+} // namespace WTF
+
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerUpdateViaCache.h (224879 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorkerUpdateViaCache.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerUpdateViaCache.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -27,6 +27,8 @@
#if ENABLE(SERVICE_WORKER)
+#include <wtf/EnumTraits.h>
+
namespace WebCore {
enum class ServiceWorkerUpdateViaCache {
@@ -37,4 +39,17 @@
} // namespace WebCore
+namespace WTF {
+
+template <> struct EnumTraits<WebCore::ServiceWorkerUpdateViaCache> {
+ using values = EnumValues<
+ WebCore::ServiceWorkerUpdateViaCache,
+ WebCore::ServiceWorkerUpdateViaCache::Imports,
+ WebCore::ServiceWorkerUpdateViaCache::All,
+ WebCore::ServiceWorkerUpdateViaCache::None
+ >;
+};
+
+} // namespace WTF
+
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp (224879 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp 2017-11-15 18:00:24 UTC (rev 224880)
@@ -32,8 +32,8 @@
namespace WebCore {
-ServiceWorkerWindowClient::ServiceWorkerWindowClient(ScriptExecutionContext& context, const Identifier& identifier)
- : ServiceWorkerClient(context, identifier, Type::Window)
+ServiceWorkerWindowClient::ServiceWorkerWindowClient(ScriptExecutionContext& context, ServiceWorkerClientData&& data)
+ : ServiceWorkerClient(context, WTFMove(data))
{
}
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.h (224879 => 224880)
--- trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -36,9 +36,9 @@
class ServiceWorkerWindowClient final : public ServiceWorkerClient {
public:
- static Ref<ServiceWorkerWindowClient> create(ScriptExecutionContext& context, const Identifier& identifier)
+ static Ref<ServiceWorkerWindowClient> create(ScriptExecutionContext& context, ServiceWorkerClientData&& data)
{
- return adoptRef(*new ServiceWorkerWindowClient(context, identifier));
+ return adoptRef(*new ServiceWorkerWindowClient(context, WTFMove(data)));
}
VisibilityState visibilityState() const;
@@ -48,7 +48,7 @@
void navigate(const String& url, Ref<DeferredPromise>&&);
private:
- ServiceWorkerWindowClient(ScriptExecutionContext&, const Identifier&);
+ ServiceWorkerWindowClient(ScriptExecutionContext&, ServiceWorkerClientData&&);
};
} // namespace WebCore
Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.cpp (224879 => 224880)
--- trunk/Source/WebCore/workers/service/context/SWContextManager.cpp 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.cpp 2017-11-15 18:00:24 UTC (rev 224880)
@@ -64,7 +64,7 @@
return m_workerMap.get(identifier);
}
-void SWContextManager::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destination, Ref<SerializedScriptValue>&& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin)
+void SWContextManager::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destination, Ref<SerializedScriptValue>&& message, ServiceWorkerClientData&& source)
{
auto* serviceWorker = m_workerMap.get(destination);
if (!serviceWorker)
@@ -71,7 +71,7 @@
return;
// FIXME: We should pass valid MessagePortChannels.
- serviceWorker->thread().postMessageToServiceWorkerGlobalScope(WTFMove(message), nullptr, sourceIdentifier, sourceOrigin);
+ serviceWorker->thread().postMessageToServiceWorkerGlobalScope(WTFMove(message), nullptr, WTFMove(source));
}
void SWContextManager::fireInstallEvent(ServiceWorkerIdentifier identifier)
Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.h (224879 => 224880)
--- trunk/Source/WebCore/workers/service/context/SWContextManager.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -57,7 +57,7 @@
WEBCORE_EXPORT void registerServiceWorkerThreadForInstall(Ref<ServiceWorkerThreadProxy>&&);
WEBCORE_EXPORT ServiceWorkerThreadProxy* serviceWorkerThreadProxy(ServiceWorkerIdentifier) const;
- WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destination, Ref<SerializedScriptValue>&& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
+ WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destination, Ref<SerializedScriptValue>&& message, ServiceWorkerClientData&& source);
WEBCORE_EXPORT void fireInstallEvent(ServiceWorkerIdentifier);
WEBCORE_EXPORT void fireActivateEvent(ServiceWorkerIdentifier);
Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp (224879 => 224880)
--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp 2017-11-15 18:00:24 UTC (rev 224880)
@@ -104,13 +104,14 @@
}, WorkerRunLoop::defaultMode());
}
-void ServiceWorkerThread::postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&& message, std::unique_ptr<MessagePortChannelArray>&& channels, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin)
+void ServiceWorkerThread::postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&& message, std::unique_ptr<MessagePortChannelArray>&& channels, ServiceWorkerClientData&& source)
{
- ScriptExecutionContext::Task task([this, channels = WTFMove(channels), message = WTFMove(message), sourceIdentifier, sourceOrigin = sourceOrigin.isolatedCopy()] (ScriptExecutionContext& context) mutable {
+ ScriptExecutionContext::Task task([this, channels = WTFMove(channels), message = WTFMove(message), sourceData = source.isolatedCopy()] (ScriptExecutionContext& context) mutable {
auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context);
auto ports = MessagePort::entanglePorts(serviceWorkerGlobalScope, WTFMove(channels));
- ExtendableMessageEventSource source = RefPtr<ServiceWorkerClient> { ServiceWorkerWindowClient::create(context, sourceIdentifier) };
- auto messageEvent = ExtendableMessageEvent::create(WTFMove(ports), WTFMove(message), sourceOrigin, { }, WTFMove(source));
+ RefPtr<ServiceWorkerClient> source = ServiceWorkerWindowClient::create(context, WTFMove(sourceData));
+ auto sourceOrigin = SecurityOrigin::create(source->url());
+ auto messageEvent = ExtendableMessageEvent::create(WTFMove(ports), WTFMove(message), sourceOrigin->toString(), { }, ExtendableMessageEventSource { source });
serviceWorkerGlobalScope.dispatchEvent(messageEvent);
serviceWorkerGlobalScope.thread().workerObjectProxy().confirmMessageFromWorkerObject(serviceWorkerGlobalScope.hasPendingActivity());
updateExtendedEventsSet(messageEvent.ptr());
Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h (224879 => 224880)
--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -40,6 +40,7 @@
class MessagePortChannel;
class SerializedScriptValue;
class WorkerObjectProxy;
+struct ServiceWorkerClientData;
struct ServiceWorkerClientIdentifier;
struct ServiceWorkerContextData;
@@ -56,7 +57,7 @@
WorkerObjectProxy& workerObjectProxy() const { return m_workerObjectProxy; }
WEBCORE_EXPORT void postFetchTask(Ref<ServiceWorkerFetch::Client>&&, ResourceRequest&&, FetchOptions&&);
- WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&&, std::unique_ptr<MessagePortChannelArray>&&, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
+ WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&&, std::unique_ptr<MessagePortChannelArray>&&, ServiceWorkerClientData&& source);
void fireInstallEvent();
void fireActivateEvent();
Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.h (224879 => 224880)
--- trunk/Source/WebCore/workers/service/server/SWClientConnection.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -44,6 +44,7 @@
enum class ServiceWorkerState;
enum class ShouldNotifyWhenResolved;
struct ExceptionData;
+struct ServiceWorkerClientData;
struct ServiceWorkerData;
struct ServiceWorkerFetchResult;
struct ServiceWorkerRegistrationData;
@@ -67,7 +68,7 @@
virtual void didResolveRegistrationPromise(const ServiceWorkerRegistrationKey&) = 0;
- virtual void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&&, ScriptExecutionContext& source) = 0;
+ virtual void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&&, ServiceWorkerClientData&& source) = 0;
virtual uint64_t identifier() const = 0;
virtual bool mayHaveServiceWorkerRegisteredForOrigin(const SecurityOrigin&) const = 0;
Modified: trunk/Source/WebKit/ChangeLog (224879 => 224880)
--- trunk/Source/WebKit/ChangeLog 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebKit/ChangeLog 2017-11-15 18:00:24 UTC (rev 224880)
@@ -1,3 +1,24 @@
+2017-11-15 Chris Dumez <cdu...@apple.com>
+
+ [Service Workers] Implement Client API
+ https://bugs.webkit.org/show_bug.cgi?id=179709
+
+ Reviewed by Alex Christensen.
+
+ * Shared/WebCoreArgumentCoders.cpp:
+ * Shared/WebCoreArgumentCoders.h:
+ * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+ (WebKit::WebSWServerConnection::postMessageToServiceWorkerGlobalScope):
+ * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+ * StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
+ * WebProcess/Storage/WebSWClientConnection.cpp:
+ (WebKit::WebSWClientConnection::postMessageToServiceWorkerGlobalScope):
+ * WebProcess/Storage/WebSWClientConnection.h:
+ * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+ (WebKit::WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope):
+ * WebProcess/Storage/WebSWContextManagerConnection.h:
+ * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+
2017-11-15 Ryan Haddad <ryanhad...@apple.com>
Unreviewed, rolling out r224863.
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (224879 => 224880)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2017-11-15 18:00:24 UTC (rev 224880)
@@ -65,7 +65,6 @@
#include <WebCore/ScrollingConstraints.h>
#include <WebCore/ScrollingCoordinator.h>
#include <WebCore/SearchPopupMenu.h>
-#include <WebCore/ServiceWorkerClientIdentifier.h>
#include <WebCore/TextCheckerClient.h>
#include <WebCore/TextIndicator.h>
#include <WebCore/TimingFunction.h>
@@ -1902,27 +1901,6 @@
return true;
}
-#if ENABLE(SERVICE_WORKER)
-void ArgumentCoder<ServiceWorkerClientIdentifier>::encode(Encoder& encoder, const ServiceWorkerClientIdentifier& identifier)
-{
- encoder << identifier.serverConnectionIdentifier << identifier.scriptExecutionContextIdentifier;
-}
-
-bool ArgumentCoder<ServiceWorkerClientIdentifier>::decode(Decoder& decoder, ServiceWorkerClientIdentifier& identifier)
-{
- uint64_t serverConnectionIdentifier;
- if (!decoder.decode(serverConnectionIdentifier))
- return false;
-
- uint64_t scriptExecutionContextIdentifier;
- if (!decoder.decode(scriptExecutionContextIdentifier))
- return false;
-
- identifier = { serverConnectionIdentifier, scriptExecutionContextIdentifier };
- return true;
-}
-#endif
-
void ArgumentCoder<TextCheckingResult>::encode(Encoder& encoder, const TextCheckingResult& result)
{
encoder.encodeEnum(result.type);
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (224879 => 224880)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -39,8 +39,6 @@
#include <WebCore/PaymentHeaders.h>
#include <WebCore/RealtimeMediaSource.h>
#include <WebCore/ScrollSnapOffsetsInfo.h>
-#include <WebCore/ServiceWorkerTypes.h>
-#include <WebCore/ServiceWorkerUpdateViaCache.h>
#include <WebCore/StoredCredentialsPolicy.h>
#include <WebCore/WorkerType.h>
@@ -159,10 +157,6 @@
#if ENABLE(INDEXED_DATABASE)
using IDBKeyPath = Variant<String, Vector<String>>;
#endif
-
-#if ENABLE(SERVICE_WORKER)
-struct ServiceWorkerClientIdentifier;
-#endif
}
namespace IPC {
@@ -483,13 +477,6 @@
static bool decode(Decoder&, WebCore::TextCheckingRequestData&);
};
-#if ENABLE(SERVICE_WORKER)
-template<> struct ArgumentCoder<WebCore::ServiceWorkerClientIdentifier> {
- static void encode(Encoder&, const WebCore::ServiceWorkerClientIdentifier&);
- static bool decode(Decoder&, WebCore::ServiceWorkerClientIdentifier&);
-};
-#endif
-
template<> struct ArgumentCoder<WebCore::TextCheckingResult> {
static void encode(Encoder&, const WebCore::TextCheckingResult&);
static std::optional<WebCore::TextCheckingResult> decode(Decoder&);
@@ -806,43 +793,4 @@
>;
};
-#if ENABLE(SERVICE_WORKER)
-template <> struct EnumTraits<WebCore::ServiceWorkerUpdateViaCache> {
- using values = EnumValues<
- WebCore::ServiceWorkerUpdateViaCache,
- WebCore::ServiceWorkerUpdateViaCache::Imports,
- WebCore::ServiceWorkerUpdateViaCache::All,
- WebCore::ServiceWorkerUpdateViaCache::None
- >;
-};
-
-template <> struct EnumTraits<WebCore::ServiceWorkerRegistrationState> {
- using values = EnumValues<
- WebCore::ServiceWorkerRegistrationState,
- WebCore::ServiceWorkerRegistrationState::Installing,
- WebCore::ServiceWorkerRegistrationState::Waiting,
- WebCore::ServiceWorkerRegistrationState::Active
- >;
-};
-
-template <> struct EnumTraits<WebCore::ServiceWorkerState> {
- using values = EnumValues<
- WebCore::ServiceWorkerState,
- WebCore::ServiceWorkerState::Installing,
- WebCore::ServiceWorkerState::Installed,
- WebCore::ServiceWorkerState::Activating,
- WebCore::ServiceWorkerState::Activated,
- WebCore::ServiceWorkerState::Redundant
- >;
-};
-
-template <> struct EnumTraits<WebCore::ShouldNotifyWhenResolved> {
- using values = EnumValues<
- WebCore::ShouldNotifyWhenResolved,
- WebCore::ShouldNotifyWhenResolved::No,
- WebCore::ShouldNotifyWhenResolved::Yes
- >;
-};
-#endif
-
} // namespace WTF
Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp (224879 => 224880)
--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp 2017-11-15 18:00:24 UTC (rev 224880)
@@ -45,6 +45,7 @@
#include <WebCore/NotImplemented.h>
#include <WebCore/SWServerRegistration.h>
#include <WebCore/SecurityOrigin.h>
+#include <WebCore/ServiceWorkerClientData.h>
#include <WebCore/ServiceWorkerClientIdentifier.h>
#include <WebCore/ServiceWorkerContextData.h>
#include <WebCore/ServiceWorkerJobData.h>
@@ -111,10 +112,10 @@
sendToContextProcess(Messages::WebSWContextManagerConnection::StartFetch(identifier(), fetchIdentifier, serviceWorkerIdentifier, request, options));
}
-void WebSWServerConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationServiceWorkerIdentifier, const IPC::DataReference& message, uint64_t sourceScriptExecutionContextIdentifier, const String& sourceOrigin)
+void WebSWServerConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationServiceWorkerIdentifier, const IPC::DataReference& message, ServiceWorkerClientData&& source)
{
- ServiceWorkerClientIdentifier sourceIdentifier { identifier(), sourceScriptExecutionContextIdentifier };
- sendToContextProcess(Messages::WebSWContextManagerConnection::PostMessageToServiceWorkerGlobalScope { destinationServiceWorkerIdentifier, message, sourceIdentifier, sourceOrigin });
+ source.identifier.serverConnectionIdentifier = identifier();
+ sendToContextProcess(Messages::WebSWContextManagerConnection::PostMessageToServiceWorkerGlobalScope { destinationServiceWorkerIdentifier, message, WTFMove(source) });
}
void WebSWServerConnection::didReceiveFetchResponse(uint64_t fetchIdentifier, const ResourceResponse& response)
Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h (224879 => 224880)
--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -34,6 +34,7 @@
namespace WebCore {
struct ExceptionData;
+struct ServiceWorkerClientData;
class ServiceWorkerRegistrationKey;
}
@@ -70,7 +71,7 @@
void startFetch(uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier>, const WebCore::ResourceRequest&, const WebCore::FetchOptions&);
- void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, uint64_t sourceScriptExecutionContextIdentifier, const String& sourceOrigin);
+ void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerClientData&& source);
void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const WebCore::URL& clientURL);
void getRegistrations(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const WebCore::URL& clientURL);
Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in (224879 => 224880)
--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in 2017-11-15 18:00:24 UTC (rev 224880)
@@ -30,7 +30,7 @@
RemoveServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationKey key, WebCore::ServiceWorkerRegistrationIdentifier identifier)
StartFetch(uint64_t identifier, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
- PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationServiceWorkerIdentifier, IPC::DataReference message, uint64_t sourceScriptExecutionContextIdentifier, String sourceOrigin)
+ PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationServiceWorkerIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientData source)
DidResolveRegistrationPromise(WebCore::ServiceWorkerRegistrationKey key)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (224879 => 224880)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp 2017-11-15 18:00:24 UTC (rev 224880)
@@ -37,6 +37,7 @@
#include "WebSWServerConnectionMessages.h"
#include <WebCore/Document.h>
#include <WebCore/SerializedScriptValue.h>
+#include <WebCore/ServiceWorkerClientData.h>
#include <WebCore/ServiceWorkerFetchResult.h>
#include <WebCore/ServiceWorkerJobData.h>
#include <WebCore/ServiceWorkerRegistrationData.h>
@@ -80,13 +81,9 @@
send(Messages::WebSWServerConnection::RemoveServiceWorkerRegistrationInServer(key, identifier));
}
-void WebSWClientConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&& scriptValue, ScriptExecutionContext& source)
+void WebSWClientConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&& scriptValue, ServiceWorkerClientData&& source)
{
- // FIXME: Add support for posting messages from workers.
- if (!is<Document>(source))
- return;
-
- send(Messages::WebSWServerConnection::PostMessageToServiceWorkerGlobalScope(destinationIdentifier, IPC::DataReference { scriptValue->data() }, downcast<Document>(source).identifier(), source.origin()));
+ send(Messages::WebSWServerConnection::PostMessageToServiceWorkerGlobalScope(destinationIdentifier, IPC::DataReference { scriptValue->data() }, WTFMove(source)));
}
void WebSWClientConnection::didResolveRegistrationPromise(const ServiceWorkerRegistrationKey& key)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (224879 => 224880)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -68,7 +68,7 @@
private:
void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final;
void finishFetchingScriptInServer(const WebCore::ServiceWorkerFetchResult&) final;
- void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, Ref<WebCore::SerializedScriptValue>&&, WebCore::ScriptExecutionContext& source) final;
+ void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, Ref<WebCore::SerializedScriptValue>&&, WebCore::ServiceWorkerClientData&& source) final;
void matchRegistration(const WebCore::SecurityOrigin& topOrigin, const WebCore::URL& clientURL, RegistrationCallback&&) final;
void didMatchRegistration(uint64_t matchRequestIdentifier, std::optional<WebCore::ServiceWorkerRegistrationData>&&);
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (224879 => 224880)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2017-11-15 18:00:24 UTC (rev 224880)
@@ -47,6 +47,7 @@
#include <WebCore/PageConfiguration.h>
#include <WebCore/RuntimeEnabledFeatures.h>
#include <WebCore/SerializedScriptValue.h>
+#include <WebCore/ServiceWorkerClientIdentifier.h>
#include <pal/SessionID.h>
#if USE(QUICK_LOOK)
@@ -142,9 +143,9 @@
serviceWorkerThreadProxy->thread().postFetchTask(WTFMove(client), WTFMove(request), WTFMove(options));
}
-void WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin)
+void WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, ServiceWorkerClientData&& source)
{
- SWContextManager::singleton().postMessageToServiceWorkerGlobalScope(destinationIdentifier, SerializedScriptValue::adopt(message.vector()), sourceIdentifier, sourceOrigin);
+ SWContextManager::singleton().postMessageToServiceWorkerGlobalScope(destinationIdentifier, SerializedScriptValue::adopt(message.vector()), WTFMove(source));
}
void WebSWContextManagerConnection::fireInstallEvent(ServiceWorkerIdentifier identifier)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h (224879 => 224880)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h 2017-11-15 18:00:24 UTC (rev 224880)
@@ -60,7 +60,7 @@
void serviceWorkerStartedWithMessage(WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
void installServiceWorker(const WebCore::ServiceWorkerContextData&);
void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier>, WebCore::ResourceRequest&&, WebCore::FetchOptions&&);
- void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, const WebCore::ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
+ void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerClientData&& source);
void fireInstallEvent(WebCore::ServiceWorkerIdentifier);
void fireActivateEvent(WebCore::ServiceWorkerIdentifier);
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in (224879 => 224880)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2017-11-15 17:13:25 UTC (rev 224879)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2017-11-15 18:00:24 UTC (rev 224880)
@@ -25,7 +25,7 @@
messages -> WebSWContextManagerConnection {
InstallServiceWorker(struct WebCore::ServiceWorkerContextData contextData)
StartFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
- PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientIdentifier sourceIdentifier, String sourceOrigin)
+ PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientData source)
FireInstallEvent(WebCore::ServiceWorkerIdentifier identifier)
FireActivateEvent(WebCore::ServiceWorkerIdentifier identifier)
}