Make toJS() do the right thing for ServiceWorkerClient
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Oct 2017 21:36:39 +0000 (21:36 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Oct 2017 21:36:39 +0000 (21:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178816

Reviewed by Youenn Fablet.

Make toJS() do the right thing for ServiceWorkerClient. In particular,
it needs to construct a JSServiceWorkerWindowClient wrapper if the
implementation object is a ServiceWorkerWindowClient.

Also, ServiceWorkerClient does not need to be an ActiveDOMObject as
it does not have any long-running tasks. Make it a ContextDestructionObject
instead for now.

* CMakeLists.txt:
* DerivedSources.make:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* workers/service/ServiceWorkerClient.cpp:
(WebCore::ServiceWorkerClient::postMessage):
* workers/service/ServiceWorkerClient.h:
(WebCore::ServiceWorkerClient::create):
* workers/service/ServiceWorkerClient.idl:
* workers/service/ServiceWorkerClientType.h: Copied from Source/WebCore/workers/service/ServiceWorkerClient.idl.
* workers/service/ServiceWorkerClientType.idl: Added.
* workers/service/ServiceWorkerClients.h:
* workers/service/ServiceWorkerClients.idl:

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

Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSServiceWorkerClientCustom.cpp [new file with mode: 0644]
Source/WebCore/workers/service/ServiceWorkerClient.cpp
Source/WebCore/workers/service/ServiceWorkerClient.h
Source/WebCore/workers/service/ServiceWorkerClient.idl
Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp
Source/WebCore/workers/service/ServiceWorkerWindowClient.h

index 83893a3..5b3e1a4 100644 (file)
@@ -1,3 +1,32 @@
+2017-10-25  Chris Dumez  <cdumez@apple.com>
+
+        Make toJS() do the right thing for ServiceWorkerClient
+        https://bugs.webkit.org/show_bug.cgi?id=178816
+
+        Reviewed by Youenn Fablet.
+
+        Make toJS() do the right thing for ServiceWorkerClient. In particular,
+        it needs to construct a JSServiceWorkerWindowClient wrapper if the
+        implementation object is a ServiceWorkerWindowClient.
+
+        Also, ServiceWorkerClient does not need to be an ActiveDOMObject as
+        it does not have any long-running tasks. Make it a ContextDestructionObject
+        instead for now.
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * workers/service/ServiceWorkerClient.cpp:
+        (WebCore::ServiceWorkerClient::postMessage):
+        * workers/service/ServiceWorkerClient.h:
+        (WebCore::ServiceWorkerClient::create):
+        * workers/service/ServiceWorkerClient.idl:
+        * workers/service/ServiceWorkerClientType.h: Copied from Source/WebCore/workers/service/ServiceWorkerClient.idl.
+        * workers/service/ServiceWorkerClientType.idl: Added.
+        * workers/service/ServiceWorkerClients.h:
+        * workers/service/ServiceWorkerClients.idl:
+
 2017-10-25  Simon Fraser  <simon.fraser@apple.com>
 
         When navigating back to a page, compositing layers may not use accelerated drawing
index f556ee6..1ade753 100644 (file)
@@ -403,6 +403,7 @@ bindings/js/JSReadableStreamPrivateConstructors.cpp
 bindings/js/JSReadableStreamSourceCustom.cpp
 bindings/js/JSSVGPathSegCustom.cpp
 bindings/js/JSStyleSheetCustom.cpp
+bindings/js/JSServiceWorkerClientCustom.cpp
 bindings/js/JSTextCustom.cpp
 bindings/js/JSTextTrackCueCustom.cpp
 bindings/js/JSTextTrackCustom.cpp
index a1612f0..bd84b4f 100644 (file)
                83EE598C1F50958B003E8B30 /* JSErrorCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSErrorCallback.cpp; sourceTree = "<group>"; };
                83F570AD1C53268E007FD6CB /* JSXMLDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSXMLDocument.h; sourceTree = "<group>"; };
                83F570AE1C53268E007FD6CB /* JSXMLDocument.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSXMLDocument.cpp; sourceTree = "<group>"; };
+               83F572941FA1066F003837BE /* JSServiceWorkerClientCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSServiceWorkerClientCustom.cpp; sourceTree = "<group>"; };
                83FB33671F508A4E00986E54 /* FileSystemFileEntry.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FileSystemFileEntry.idl; sourceTree = "<group>"; };
                83FB33681F508A4E00986E54 /* FileSystemEntry.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FileSystemEntry.idl; sourceTree = "<group>"; };
                83FB33691F508A4E00986E54 /* FileSystemFileEntry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystemFileEntry.cpp; sourceTree = "<group>"; };
                                BCD9C2610C17AA67005C90A2 /* JSNodeListCustom.cpp */,
                                AD20B18C18E9D216005A8083 /* JSNodeListCustom.h */,
                                CB38FD551CD21D5B00592A3F /* JSPerformanceEntryCustom.cpp */,
+                               83F572941FA1066F003837BE /* JSServiceWorkerClientCustom.cpp */,
                                BC98A27C0C0C9950004BEBF7 /* JSStyleSheetCustom.cpp */,
                                AD726FEC16D9F4B9003A4E6D /* JSStyleSheetCustom.h */,
                                B2C96D8C0B3AF2B7005E80EC /* JSSVGPathSegCustom.cpp */,
diff --git a/Source/WebCore/bindings/js/JSServiceWorkerClientCustom.cpp b/Source/WebCore/bindings/js/JSServiceWorkerClientCustom.cpp
new file mode 100644 (file)
index 0000000..58eea3d
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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 "JSServiceWorkerClient.h"
+
+#include "JSServiceWorkerWindowClient.h"
+
+namespace WebCore {
+
+using namespace JSC;
+
+JSValue toJSNewlyCreated(ExecState*, JSDOMGlobalObject* globalObject, Ref<ServiceWorkerClient>&& client)
+{
+    if (is<ServiceWorkerWindowClient>(client))
+        return createWrapper<ServiceWorkerWindowClient>(globalObject, WTFMove(client));
+    return createWrapper<ServiceWorkerClient>(globalObject, WTFMove(client));
+}
+
+JSValue toJS(ExecState* state, JSDOMGlobalObject* globalObject, ServiceWorkerClient& client)
+{
+    return wrap(state, globalObject, client);
+}
+
+} // namespace WebCore
+
+#endif
index ab23363..cd301d0 100644 (file)
 
 namespace WebCore {
 
-ServiceWorkerClient::ServiceWorkerClient(ScriptExecutionContext& context)
-    : ActiveDOMObject(&context)
+ServiceWorkerClient::ServiceWorkerClient(ScriptExecutionContext& context, Type type)
+    : ContextDestructionObserver(&context)
+    , m_type(type)
 {
-    suspendIfNeeded();
-}
-
-const char* ServiceWorkerClient::activeDOMObjectName() const
-{
-    return "ServiceWorkerClient";
-}
-
-bool ServiceWorkerClient::canSuspendForDocumentSuspension() const
-{
-    return !hasPendingActivity();
 }
 
 String ServiceWorkerClient::url() const
@@ -56,11 +46,6 @@ auto ServiceWorkerClient::frameType() const -> FrameType
     return FrameType::None;
 }
 
-auto ServiceWorkerClient::type() const -> Type
-{
-    return Type::Window;
-}
-
 String ServiceWorkerClient::id() const
 {
     return { };
index 7a96325..69b91e0 100644 (file)
@@ -27,7 +27,7 @@
 
 #if ENABLE(SERVICE_WORKER)
 
-#include "ActiveDOMObject.h"
+#include "ContextDestructionObserver.h"
 #include "ExceptionOr.h"
 #include "ServiceWorkerClientType.h"
 #include <heap/Strong.h>
@@ -40,7 +40,7 @@ class JSValue;
 
 namespace WebCore {
 
-class ServiceWorkerClient : public RefCounted<ServiceWorkerClient>, public ActiveDOMObject {
+class ServiceWorkerClient : public RefCounted<ServiceWorkerClient>, public ContextDestructionObserver {
 public:
     using Type = ServiceWorkerClientType;
     enum class FrameType {
@@ -50,19 +50,22 @@ public:
         None
     };
 
+    static Ref<ServiceWorkerClient> create(ScriptExecutionContext& context, Type type)
+    {
+        return adoptRef(*new ServiceWorkerClient(context, type));
+    }
+
     String url() const;
     FrameType frameType() const;
-    Type type() const;
+    Type type() const { return m_type; }
     String id() const;
 
     ExceptionOr<void> postMessage(JSC::ExecState&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&& transfer);
 
 protected:
-    explicit ServiceWorkerClient(ScriptExecutionContext&);
+    ServiceWorkerClient(ScriptExecutionContext&, Type);
 
-    // ActiveDOMObject.
-    const char* activeDOMObjectName() const final;
-    bool canSuspendForDocumentSuspension() const final;
+    Type m_type;
 };
 
 } // namespace WebCore
index 368c074..f7e4a98 100644 (file)
@@ -25,6 +25,7 @@
 
 [
     Conditional=SERVICE_WORKER,
+    CustomToJSObject,
     EnabledAtRuntime=ServiceWorker,
     Exposed=ServiceWorker,
     InterfaceName=Client,
index 5c78b78..46d2990 100644 (file)
@@ -33,7 +33,7 @@
 namespace WebCore {
 
 ServiceWorkerWindowClient::ServiceWorkerWindowClient(ScriptExecutionContext& context)
-    : ServiceWorkerClient(context)
+    : ServiceWorkerClient(context, Type::Window)
 {
 }
 
index 6bb77d7..83c80e2 100644 (file)
@@ -53,4 +53,8 @@ private:
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ServiceWorkerWindowClient)
+    static bool isType(const WebCore::ServiceWorkerClient& client) { return client.type() == WebCore::ServiceWorkerClientType::Window; }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // ENABLE(SERVICE_WORKER)