Make sure WTF::generateObjectIdentifier() internal counter does not get duplicated
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2019 17:50:53 +0000 (17:50 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2019 17:50:53 +0000 (17:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193848

Reviewed by Youenn Fablet.

Source/WebCore:

* dom/Document.cpp:
* dom/MessageChannel.cpp:
(WebCore::MessageChannel::MessageChannel):
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::contextIdentifier const):
* history/HistoryItem.cpp:
(WebCore::HistoryItem::HistoryItem):
* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::registerTemporaryServiceWorkerClient):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::DOMWindow):
* platform/Process.cpp:
(WebCore::Process::identifier):
* workers/service/ServiceWorkerJobData.cpp:
(WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
* workers/service/server/RegistrationDatabase.cpp:
(WebCore::RegistrationDatabase::importRecords):
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::Connection::Connection):
(WebCore::SWServer::updateWorker):
* workers/service/server/SWServerRegistration.cpp:
(WebCore::generateServiceWorkerRegistrationIdentifier):
* workers/service/server/SWServerToContextConnection.cpp:
(WebCore::generateServerToContextConnectionIdentifier):

Source/WebKit:

* Platform/IPC/Connection.cpp:
(IPC::Connection::Connection):
* UIProcess/ChildProcessProxy.h:
* UIProcess/UserContent/WebUserContentControllerProxy.cpp:
(WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy):
* UIProcess/WebBackForwardList.cpp:
(WebKit::WebBackForwardList::restoreFromState):
* UIProcess/WebProcessPool.cpp:
* WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp:
(WebKit::UserMediaPermissionRequestManager::addDeviceChangeObserver):

Source/WTF:

Move WTF::generateObjectIdentifier()'s internal counter out-of-line so make sure it never gets
duplicated at each call site. This has caused some hard-to-debug issues with duplicate
identifiers such as Bug 193761.

Also move it to ObjectIdentifier and rename it to generate() as this make call sites nicer
when they have a typedef for the ObjectIdentifier<T> type.

* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/ObjectIdentifier.cpp: Copied from Source/WebCore/platform/Process.cpp.
(WTF::ObjectIdentifierBase::generateIdentifierInternal):
(WTF::ObjectIdentifierBase::generateThreadSafeIdentifierInternal):
* wtf/ObjectIdentifier.h:
(WTF::ObjectIdentifier::generate):
(WTF::ObjectIdentifier::generateThreadSafe):

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

25 files changed:
Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/CMakeLists.txt
Source/WTF/wtf/ObjectIdentifier.cpp [new file with mode: 0644]
Source/WTF/wtf/ObjectIdentifier.h
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/MessageChannel.cpp
Source/WebCore/dom/ScriptExecutionContext.cpp
Source/WebCore/history/HistoryItem.cpp
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/platform/ProcessIdentifier.cpp
Source/WebCore/workers/service/ServiceWorkerJobData.cpp
Source/WebCore/workers/service/server/RegistrationDatabase.cpp
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServerRegistration.cpp
Source/WebCore/workers/service/server/SWServerToContextConnection.cpp
Source/WebKit/ChangeLog
Source/WebKit/Platform/IPC/Connection.cpp
Source/WebKit/UIProcess/ChildProcessProxy.h
Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp
Source/WebKit/UIProcess/WebBackForwardList.cpp
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp

index 0723582..3b5b101 100644 (file)
@@ -1,3 +1,26 @@
+2019-01-29  Chris Dumez  <cdumez@apple.com>
+
+        Make sure WTF::generateObjectIdentifier() internal counter does not get duplicated
+        https://bugs.webkit.org/show_bug.cgi?id=193848
+
+        Reviewed by Youenn Fablet.
+
+        Move WTF::generateObjectIdentifier()'s internal counter out-of-line so make sure it never gets
+        duplicated at each call site. This has caused some hard-to-debug issues with duplicate
+        identifiers such as Bug 193761.
+
+        Also move it to ObjectIdentifier and rename it to generate() as this make call sites nicer
+        when they have a typedef for the ObjectIdentifier<T> type.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/CMakeLists.txt:
+        * wtf/ObjectIdentifier.cpp: Copied from Source/WebCore/platform/Process.cpp.
+        (WTF::ObjectIdentifierBase::generateIdentifierInternal):
+        (WTF::ObjectIdentifierBase::generateThreadSafeIdentifierInternal):
+        * wtf/ObjectIdentifier.h:
+        (WTF::ObjectIdentifier::generate):
+        (WTF::ObjectIdentifier::generateThreadSafe):
+
 2019-01-28  Ross Kirsling  <ross.kirsling@sony.com>
 
         Move platform-specific files out of WTF root directory.
index 127ca50..5ad514d 100644 (file)
@@ -83,6 +83,7 @@
                7AF023B52061E17000A8EFD6 /* ProcessPrivilege.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AF023B42061E16F00A8EFD6 /* ProcessPrivilege.cpp */; };
                7AFEC6B11EB22B5900DADE36 /* UUID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AFEC6B01EB22B5900DADE36 /* UUID.cpp */; };
                8134013815B092FD001FF0B8 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8134013615B092FD001FF0B8 /* Base64.cpp */; };
+               8348BA0E21FBC0D500FD3054 /* ObjectIdentifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8348BA0D21FBC0D400FD3054 /* ObjectIdentifier.cpp */; };
                93934BD318A1E8C300D0D6A1 /* StringViewCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93934BD218A1E8C300D0D6A1 /* StringViewCocoa.mm */; };
                93934BD518A1F16900D0D6A1 /* StringViewCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93934BD418A1F16900D0D6A1 /* StringViewCF.cpp */; };
                93F1993E19D7958D00C2390B /* StringView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F1993D19D7958D00C2390B /* StringView.cpp */; };
                7E29C33D15FFD79B00516D61 /* ObjCRuntimeExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjCRuntimeExtras.h; sourceTree = "<group>"; };
                8134013615B092FD001FF0B8 /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Base64.cpp; sourceTree = "<group>"; };
                8134013715B092FD001FF0B8 /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64.h; sourceTree = "<group>"; };
+               8348BA0D21FBC0D400FD3054 /* ObjectIdentifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectIdentifier.cpp; sourceTree = "<group>"; };
                83A8AC3D1FABBE94002064AC /* ObjectIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectIdentifier.h; sourceTree = "<group>"; };
                83ABB3C020B3823200BA3306 /* WeakObjCPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakObjCPtr.h; sourceTree = "<group>"; };
                83F2BADE1CF9524E003E99C3 /* Function.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Function.h; sourceTree = "<group>"; };
                                A8A472D5151A825B004123FF /* NumberOfCores.cpp */,
                                A8A472D6151A825B004123FF /* NumberOfCores.h */,
                                7E29C33D15FFD79B00516D61 /* ObjCRuntimeExtras.h */,
+                               8348BA0D21FBC0D400FD3054 /* ObjectIdentifier.cpp */,
                                83A8AC3D1FABBE94002064AC /* ObjectIdentifier.h */,
                                1AFDE6521953B23D00C48FFA /* Optional.h */,
                                1A4656181C7FC68E00F5920F /* OptionSet.h */,
                                0F66B28C1DC97BAB004A1D3F /* MonotonicTime.cpp in Sources */,
                                5CC0EE8A2162BC2200A1A842 /* NSURLExtras.mm in Sources */,
                                A8A473F4151A825B004123FF /* NumberOfCores.cpp in Sources */,
+                               8348BA0E21FBC0D500FD3054 /* ObjectIdentifier.cpp in Sources */,
                                A3EE5C3A21FFAC5F00FABD61 /* OSAllocatorPOSIX.cpp in Sources */,
                                A8A473F9151A825B004123FF /* OSRandomSource.cpp in Sources */,
                                A8A47402151A825B004123FF /* PageBlock.cpp in Sources */,
index 178383d..1c6d730 100644 (file)
@@ -375,6 +375,7 @@ set(WTF_SOURCES
     MonotonicTime.cpp
     NumberOfCores.cpp
     OSRandomSource.cpp
+    ObjectIdentifier.cpp
     PageBlock.cpp
     ParallelHelperPool.cpp
     ParallelJobsGeneric.cpp
diff --git a/Source/WTF/wtf/ObjectIdentifier.cpp b/Source/WTF/wtf/ObjectIdentifier.cpp
new file mode 100644 (file)
index 0000000..7e40d48
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ObjectIdentifier.h"
+
+
+namespace WTF {
+
+uint64_t ObjectIdentifierBase::generateIdentifierInternal()
+{
+    static uint64_t current;
+    return ++current;
+}
+
+uint64_t ObjectIdentifierBase::generateThreadSafeIdentifierInternal()
+{
+    static LazyNeverDestroyed<std::atomic<uint64_t>> current;
+    static std::once_flag initializeCurrentIdentifier;
+    std::call_once(initializeCurrentIdentifier, [] {
+        current.construct(0);
+    });
+    return ++current.get();
+}
+
+} // namespace WTF
index 6615269..40897b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 namespace WTF {
 
-template<typename T> class ObjectIdentifier {
+class ObjectIdentifierBase {
+protected:
+    WTF_EXPORT_PRIVATE static uint64_t generateIdentifierInternal();
+    WTF_EXPORT_PRIVATE static uint64_t generateThreadSafeIdentifierInternal();
+};
+
+template<typename T> class ObjectIdentifier : private ObjectIdentifierBase {
 public:
+    static ObjectIdentifier generate()
+    {
+        return ObjectIdentifier { generateIdentifierInternal() };
+    }
+
+    static ObjectIdentifier generateThreadSafe()
+    {
+        return ObjectIdentifier { generateThreadSafeIdentifierInternal() };
+    }
+
     ObjectIdentifier() = default;
 
     ObjectIdentifier(HashTableDeletedValueType) : m_identifier(hashTableDeletedValue()) { }
@@ -74,8 +90,6 @@ public:
     }
 
 private:
-    template<typename U> friend ObjectIdentifier<U> generateObjectIdentifier();
-    template<typename U> friend ObjectIdentifier<U> generateThreadSafeObjectIdentifier();
     template<typename U> friend ObjectIdentifier<U> makeObjectIdentifier(uint64_t);
     friend struct HashTraits<ObjectIdentifier>;
     template<typename U> friend struct ObjectIdentifierHash;
@@ -91,22 +105,6 @@ private:
     uint64_t m_identifier { 0 };
 };
 
-template<typename T> inline ObjectIdentifier<T> generateObjectIdentifier()
-{
-    static uint64_t currentIdentifier;
-    return ObjectIdentifier<T> { ++currentIdentifier };
-}
-
-template<typename T> inline ObjectIdentifier<T> generateThreadSafeObjectIdentifier()
-{
-    static LazyNeverDestroyed<std::atomic<uint64_t>> currentIdentifier;
-    static std::once_flag initializeCurrentIdentifier;
-    std::call_once(initializeCurrentIdentifier, [] {
-        currentIdentifier.construct(0);
-    });
-    return ObjectIdentifier<T> { ++currentIdentifier.get() };
-}
-
 template<typename T> inline ObjectIdentifier<T> makeObjectIdentifier(uint64_t identifier)
 {
     return ObjectIdentifier<T> { identifier };
@@ -127,6 +125,4 @@ template<typename T> struct DefaultHash<ObjectIdentifier<T>> {
 } // namespace WTF
 
 using WTF::ObjectIdentifier;
-using WTF::generateObjectIdentifier;
-using WTF::generateThreadSafeObjectIdentifier;
 using WTF::makeObjectIdentifier;
index fe06edf..27bfb85 100644 (file)
@@ -1,3 +1,35 @@
+2019-01-29  Chris Dumez  <cdumez@apple.com>
+
+        Make sure WTF::generateObjectIdentifier() internal counter does not get duplicated
+        https://bugs.webkit.org/show_bug.cgi?id=193848
+
+        Reviewed by Youenn Fablet.
+
+        * dom/Document.cpp:
+        * dom/MessageChannel.cpp:
+        (WebCore::MessageChannel::MessageChannel):
+        * dom/ScriptExecutionContext.cpp:
+        (WebCore::ScriptExecutionContext::contextIdentifier const):
+        * history/HistoryItem.cpp:
+        (WebCore::HistoryItem::HistoryItem):
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::registerTemporaryServiceWorkerClient):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::DOMWindow):
+        * platform/Process.cpp:
+        (WebCore::Process::identifier):
+        * workers/service/ServiceWorkerJobData.cpp:
+        (WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
+        * workers/service/server/RegistrationDatabase.cpp:
+        (WebCore::RegistrationDatabase::importRecords):
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::Connection::Connection):
+        (WebCore::SWServer::updateWorker):
+        * workers/service/server/SWServerRegistration.cpp:
+        (WebCore::generateServiceWorkerRegistrationIdentifier):
+        * workers/service/server/SWServerToContextConnection.cpp:
+        (WebCore::generateServerToContextConnectionIdentifier):
+
 
 2019-01-29  Alex Christensen  <achristensen@webkit.org>
 
index 0325412..50bccef 100644 (file)
@@ -533,7 +533,7 @@ Document::Document(Frame* frame, const URL& url, unsigned documentClasses, unsig
     , m_isSynthesized(constructionFlags & Synthesized)
     , m_isNonRenderedPlaceholder(constructionFlags & NonRenderedPlaceholder)
     , m_orientationNotifier(currentOrientation(frame))
-    , m_identifier(generateObjectIdentifier<DocumentIdentifierType>())
+    , m_identifier(DocumentIdentifier::generate())
     , m_undoManager(UndoManager::create(*this))
 {
     auto addResult = allDocumentsMap().add(m_identifier, this);
index 72932d8..8dcfe1f 100644 (file)
@@ -39,8 +39,8 @@ Ref<MessageChannel> MessageChannel::create(ScriptExecutionContext& context)
 
 MessageChannel::MessageChannel(ScriptExecutionContext& context)
 {
-    MessagePortIdentifier id1 = { Process::identifier(), generateObjectIdentifier<MessagePortIdentifier::PortIdentifierType>() };
-    MessagePortIdentifier id2 = { Process::identifier(), generateObjectIdentifier<MessagePortIdentifier::PortIdentifierType>() };
+    MessagePortIdentifier id1 = { Process::identifier(), ObjectIdentifier<MessagePortIdentifier::PortIdentifierType>::generate() };
+    MessagePortIdentifier id2 = { Process::identifier(), ObjectIdentifier<MessagePortIdentifier::PortIdentifierType>::generate() };
 
     m_port1 = MessagePort::create(context, id1, id2);
     m_port2 = MessagePort::create(context, id2, id1);
index 3cfeb05..e859852 100644 (file)
@@ -105,7 +105,7 @@ ScriptExecutionContextIdentifier ScriptExecutionContext::contextIdentifier() con
     if (!m_contextIdentifier) {
         Locker<Lock> locker(allScriptExecutionContextsMapLock);
 
-        m_contextIdentifier = generateObjectIdentifier<ScriptExecutionContextIdentifierType>();
+        m_contextIdentifier = ScriptExecutionContextIdentifier::generate();
 
         ASSERT(!allScriptExecutionContextsMap().contains(m_contextIdentifier));
         allScriptExecutionContextsMap().add(m_contextIdentifier, const_cast<ScriptExecutionContext*>(this));
index 44d49c7..3c059e6 100644 (file)
@@ -66,7 +66,7 @@ HistoryItem::HistoryItem(const String& urlString, const String& title)
 }
 
 HistoryItem::HistoryItem(const String& urlString, const String& title, const String& alternateTitle)
-    : HistoryItem(urlString, title, alternateTitle, { Process::identifier(), generateObjectIdentifier<BackForwardItemIdentifier::ItemIdentifierType>() })
+    : HistoryItem(urlString, title, alternateTitle, { Process::identifier(), ObjectIdentifier<BackForwardItemIdentifier::ItemIdentifierType>::generate() })
 {
 }
 
index 4754bea..6ac2131 100644 (file)
@@ -1779,7 +1779,7 @@ void DocumentLoader::registerTemporaryServiceWorkerClient(const URL& url)
         return;
 
     m_temporaryServiceWorkerClient = TemporaryServiceWorkerClient {
-        generateObjectIdentifier<DocumentIdentifierType>(),
+        DocumentIdentifier::generate(),
         *ServiceWorkerProvider::singleton().existingServiceWorkerConnectionForSession(m_frame->page()->sessionID())
     };
 
index 58e0b08..0979336 100644 (file)
@@ -404,7 +404,7 @@ void DOMWindow::setCanShowModalDialogOverride(bool allow)
 }
 
 DOMWindow::DOMWindow(Document& document)
-    : AbstractDOMWindow(GlobalWindowIdentifier { Process::identifier(), generateObjectIdentifier<WindowIdentifierType>() })
+    : AbstractDOMWindow(GlobalWindowIdentifier { Process::identifier(), WindowIdentifier::generate() })
     , ContextDestructionObserver(&document)
 {
     ASSERT(frame());
index 94dc5ea..e9dd68d 100644 (file)
@@ -44,7 +44,7 @@ ProcessIdentifier identifier()
     static std::once_flag onceFlag;
     std::call_once(onceFlag, [] {
         if (!globalIdentifier)
-            globalIdentifier = generateObjectIdentifier<ProcessIdentifierType>();
+            globalIdentifier = ProcessIdentifier::generate();
     });
 
     return *globalIdentifier;
index 29c80e1..47a79f0 100644 (file)
@@ -36,7 +36,7 @@ ServiceWorkerJobData::ServiceWorkerJobData(const Identifier& identifier)
 }
 
 ServiceWorkerJobData::ServiceWorkerJobData(SWServerConnectionIdentifier connectionIdentifier, const DocumentOrWorkerIdentifier& localSourceContext)
-    : m_identifier { connectionIdentifier, generateThreadSafeObjectIdentifier<ServiceWorkerJobIdentifierType>() }
+    : m_identifier { connectionIdentifier, ServiceWorkerJobIdentifier::generateThreadSafe() }
 {
     WTF::switchOn(localSourceContext, [&](DocumentIdentifier documentIdentifier) {
         sourceContext = ServiceWorkerClientIdentifier { connectionIdentifier, documentIdentifier };
index 56dd9bc..b629f43 100644 (file)
@@ -400,8 +400,8 @@ String RegistrationDatabase::importRecords()
         if (!key || !originURL.isValid() || !topOrigin || !updateViaCache || !scriptURL.isValid() || !workerType)
             continue;
 
-        auto workerIdentifier = generateObjectIdentifier<ServiceWorkerIdentifierType>();
-        auto registrationIdentifier = generateObjectIdentifier<ServiceWorkerRegistrationIdentifierType>();
+        auto workerIdentifier = ServiceWorkerIdentifier::generate();
+        auto registrationIdentifier = ServiceWorkerRegistrationIdentifier::generate();
         auto serviceWorkerData = ServiceWorkerData { workerIdentifier, scriptURL, ServiceWorkerState::Activated, *workerType, registrationIdentifier };
         auto registration = ServiceWorkerRegistrationData { WTFMove(*key), registrationIdentifier, URL(originURL, scopePath), *updateViaCache, lastUpdateCheckTime, WTF::nullopt, WTF::nullopt, WTFMove(serviceWorkerData) };
         auto contextData = ServiceWorkerContextData { WTF::nullopt, WTFMove(registration), workerIdentifier, WTFMove(script), WTFMove(contentSecurityPolicy), WTFMove(referrerPolicy), WTFMove(scriptURL), *workerType, m_sessionID, true, WTFMove(scriptResourceMap) };
index 044bc84..df2b8ee 100644 (file)
@@ -52,7 +52,7 @@ static Seconds terminationDelay { 10_s };
 
 SWServer::Connection::Connection(SWServer& server)
     : m_server(server)
-    , m_identifier(generateObjectIdentifier<SWServerConnectionIdentifierType>())
+    , m_identifier(SWServerConnectionIdentifier::generate())
 {
 }
 
@@ -505,7 +505,7 @@ void SWServer::removeClientServiceWorkerRegistration(Connection& connection, Ser
 
 void SWServer::updateWorker(Connection&, const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerRegistration& registration, const URL& url, const String& script, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy, const String& referrerPolicy, WorkerType type, HashMap<URL, ServiceWorkerContextData::ImportedScript>&& scriptResourceMap)
 {
-    tryInstallContextData({ jobDataIdentifier, registration.data(), generateObjectIdentifier<ServiceWorkerIdentifierType>(), script, contentSecurityPolicy, referrerPolicy, url, type, sessionID(), false, WTFMove(scriptResourceMap) });
+    tryInstallContextData({ jobDataIdentifier, registration.data(), ServiceWorkerIdentifier::generate(), script, contentSecurityPolicy, referrerPolicy, url, type, sessionID(), false, WTFMove(scriptResourceMap) });
 }
 
 void SWServer::tryInstallContextData(ServiceWorkerContextData&& data)
index 6567ca4..4d1c554 100644 (file)
@@ -37,7 +37,7 @@ namespace WebCore {
 
 static ServiceWorkerRegistrationIdentifier generateServiceWorkerRegistrationIdentifier()
 {
-    return generateObjectIdentifier<ServiceWorkerRegistrationIdentifierType>();
+    return ServiceWorkerRegistrationIdentifier::generate();
 }
 
 SWServerRegistration::SWServerRegistration(SWServer& server, const ServiceWorkerRegistrationKey& key, ServiceWorkerUpdateViaCache updateViaCache, const URL& scopeURL, const URL& scriptURL)
index 3ea309d..70caf2f 100644 (file)
@@ -36,7 +36,7 @@ namespace WebCore {
 
 static SWServerToContextConnectionIdentifier generateServerToContextConnectionIdentifier()
 {
-    return generateObjectIdentifier<SWServerToContextConnectionIdentifierType>();
+    return SWServerToContextConnectionIdentifier::generate();
 }
 
 static HashMap<SecurityOriginData, SWServerToContextConnection*>& allConnectionsByOrigin()
index 9c3e5e2..93c34b5 100644 (file)
@@ -1,5 +1,23 @@
 2019-01-29  Chris Dumez  <cdumez@apple.com>
 
+        Make sure WTF::generateObjectIdentifier() internal counter does not get duplicated
+        https://bugs.webkit.org/show_bug.cgi?id=193848
+
+        Reviewed by Youenn Fablet.
+
+        * Platform/IPC/Connection.cpp:
+        (IPC::Connection::Connection):
+        * UIProcess/ChildProcessProxy.h:
+        * UIProcess/UserContent/WebUserContentControllerProxy.cpp:
+        (WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy):
+        * UIProcess/WebBackForwardList.cpp:
+        (WebKit::WebBackForwardList::restoreFromState):
+        * UIProcess/WebProcessPool.cpp:
+        * WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp:
+        (WebKit::UserMediaPermissionRequestManager::addDeviceChangeObserver):
+
+2019-01-29  Chris Dumez  <cdumez@apple.com>
+
         REGRESSION (PSON): Twitter link gets stuck at t.co after navigating back in tab
         https://bugs.webkit.org/show_bug.cgi?id=193932
         <rdar://problem/47598947>
index a4236cb..174b04c 100644 (file)
@@ -245,7 +245,7 @@ static HashMap<uintptr_t, HashMap<uint64_t, CompletionHandler<void(Decoder*)>>>&
     
 Connection::Connection(Identifier identifier, bool isServer, Client& client)
     : m_client(client)
-    , m_uniqueID(generateObjectIdentifier<UniqueIDType>())
+    , m_uniqueID(UniqueID::generate())
     , m_isServer(isServer)
     , m_syncRequestID(0)
     , m_onlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage(false)
index 1bd0b9b..83f8048 100644 (file)
@@ -105,7 +105,7 @@ private:
     RefPtr<IPC::Connection> m_connection;
     IPC::MessageReceiverMap m_messageReceiverMap;
     bool m_alwaysRunsAtBackgroundPriority { false };
-    WebCore::ProcessIdentifier m_processIdentifier { generateObjectIdentifier<WebCore::ProcessIdentifierType>() };
+    WebCore::ProcessIdentifier m_processIdentifier { WebCore::ProcessIdentifier::generate() };
 };
 
 template<typename T>
index 751ace5..9711b23 100644 (file)
@@ -62,7 +62,7 @@ WebUserContentControllerProxy* WebUserContentControllerProxy::get(UserContentCon
 }
     
 WebUserContentControllerProxy::WebUserContentControllerProxy()
-    : m_identifier(generateObjectIdentifier<UserContentControllerIdentifierType>())
+    : m_identifier(UserContentControllerIdentifier::generate())
     , m_userScripts(API::Array::create())
     , m_userStyleSheets(API::Array::create())
 {
index 7ae26b2..f2d5a16 100644 (file)
@@ -434,7 +434,7 @@ void WebBackForwardList::restoreFromState(BackForwardListState backForwardListSt
     items.reserveInitialCapacity(backForwardListState.items.size());
 
     for (auto& backForwardListItemState : backForwardListState.items) {
-        backForwardListItemState.identifier = { Process::identifier(), generateObjectIdentifier<BackForwardItemIdentifier::ItemIdentifierType>() };
+        backForwardListItemState.identifier = { Process::identifier(), ObjectIdentifier<BackForwardItemIdentifier::ItemIdentifierType>::generate() };
         items.uncheckedAppend(WebBackForwardListItem::create(WTFMove(backForwardListItemState), m_page->pageID()));
     }
     m_currentIndex = backForwardListState.currentIndex ? Optional<size_t>(*backForwardListState.currentIndex) : WTF::nullopt;
index 7f78c6e..b681d86 100644 (file)
@@ -260,7 +260,7 @@ WebProcessPool::WebProcessPool(API::ProcessPoolConfiguration& configuration)
     std::call_once(onceFlag, [] {
         WTF::setProcessPrivileges(allPrivileges());
         WebCore::NetworkStorageSession::permitProcessToUseCookieAPI(true);
-        Process::setIdentifier(generateObjectIdentifier<WebCore::ProcessIdentifierType>());
+        Process::setIdentifier(WebCore::ProcessIdentifier::generate());
     });
 
     if (m_configuration->shouldHaveLegacyDataStore())
index 5623cc0..c179e8d 100644 (file)
@@ -232,7 +232,7 @@ void UserMediaPermissionRequestManager::revokeUserMediaDeviceSandboxExtensions(c
 
 UserMediaClient::DeviceChangeObserverToken UserMediaPermissionRequestManager::addDeviceChangeObserver(WTF::Function<void()>&& observer)
 {
-    auto identifier = generateObjectIdentifier<WebCore::UserMediaClient::DeviceChangeObserverTokenType>();
+    auto identifier = WebCore::UserMediaClient::DeviceChangeObserverToken::generate();
     m_deviceChangeObserverMap.add(identifier, WTFMove(observer));
 
     if (!m_monitoringDeviceChange) {