Title: [175792] trunk/Source/WebCore
Revision
175792
Author
[email protected]
Date
2014-11-09 09:25:21 -0800 (Sun, 09 Nov 2014)

Log Message

Fix various cases of incorrect cross-thread capture of non-thread-safe RefCounted
https://bugs.webkit.org/show_bug.cgi?id=138539

Reviewed by Alexey Proskuryakov.

* Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
(WebCore::WorkerThreadableWebSocketChannel::Peer::didConnect): Use StringCapture
instead of isolatedCopy, to avoid a problem where the original thread does its deref
after passing the string to the other thread.
(WebCore::WorkerThreadableWebSocketChannel::Peer::didReceiveMessage): Ditto.
(WebCore::WorkerThreadableWebSocketChannel::Peer::didClose): Ditto.
(WebCore::WorkerThreadableWebSocketChannel::Bridge::initialize): Ditto.
(WebCore::WorkerThreadableWebSocketChannel::Bridge::connect): Ditto.
(WebCore::WorkerThreadableWebSocketChannel::Bridge::send): Ditto.
(WebCore::WorkerThreadableWebSocketChannel::Bridge::close): Ditto.
(WebCore::WorkerThreadableWebSocketChannel::Bridge::fail): Ditto.

* dom/Document.cpp:
(WebCore::Document::addConsoleMessage): Pass a StringCapture when creating
AddConsoleMessageTask. Same reason as above, but in a different context.
(WebCore::Document::addMessage): Ditto.

* dom/ScriptExecutionContext.h: Changed AddConsoleMessageTask to take and
capture a StringCapture rather than a String, for the same reason as above.

* fileapi/AsyncFileStream.cpp:
(WebCore::AsyncFileStream::write): Use URLCapture instead of trying to use
StringCapture on a URL, since that doesn't preserve the validity flag.

* loader/WorkerThreadableLoader.cpp:
(WebCore::WorkerThreadableLoader::MainThreadBridge::MainThreadBridge): Use StringCapture.
(WebCore::WorkerThreadableLoader::MainThreadBridge::didFail): Ditto.
(WebCore::WorkerThreadableLoader::MainThreadBridge::didFailAccessControlCheck): Ditto.

* platform/URL.h: Added URLCapture.

* platform/network/FormData.cpp:
(WebCore::appendBlobResolved): Remove incorrect pointless code that creates a new URL
from an existing URL with the ParsedURLString constructor.

* workers/DefaultSharedWorkerRepository.cpp: Fixed code that was trying to copy a URL
by copying a string to instead just use URL::copy. The comment claimed that URL::copy
is not thread safe, but that claim is incorrect.
(WebCore::SharedWorkerProxy::postExceptionToWorkerObject): Use StringCapture.
(WebCore::SharedWorkerProxy::postConsoleMessageToWorkerObject): Ditto.
(WebCore::DefaultSharedWorkerRepository::getProxy): Use URL::copy.

* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::addConsoleMessage): Use StringCapture.
(WebCore::WorkerGlobalScope::addMessage): Ditto.
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Ditto.
(WebCore::WorkerMessagingProxy::postConsoleMessageToWorkerObject): Ditto.
(WebCore::WorkerMessagingProxy::sendMessageToInspector): Ditto.
(WebCore::WorkerMessagingProxy::postMessageToPageInspector): Ditto.

* workers/WorkerRunLoop.cpp:
(WebCore::WorkerRunLoop::postTaskAndTerminate): Make a Task with make_unique
rather than with Task::create. Removed an extra isolatedCopy, unneeded because
the Task constructor already does an isolatedCopy.
(WebCore::WorkerRunLoop::postTaskForMode): Ditto.
(WebCore::WorkerRunLoop::Task::create): Deleted.

* workers/WorkerRunLoop.h: Removed unneeded create function and explicit
public empty destructor.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (175791 => 175792)


--- trunk/Source/WebCore/ChangeLog	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/ChangeLog	2014-11-09 17:25:21 UTC (rev 175792)
@@ -1,3 +1,71 @@
+2014-11-09  Darin Adler  <[email protected]>
+
+        Fix various cases of incorrect cross-thread capture of non-thread-safe RefCounted
+        https://bugs.webkit.org/show_bug.cgi?id=138539
+
+        Reviewed by Alexey Proskuryakov.
+
+        * Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
+        (WebCore::WorkerThreadableWebSocketChannel::Peer::didConnect): Use StringCapture
+        instead of isolatedCopy, to avoid a problem where the original thread does its deref
+        after passing the string to the other thread.
+        (WebCore::WorkerThreadableWebSocketChannel::Peer::didReceiveMessage): Ditto.
+        (WebCore::WorkerThreadableWebSocketChannel::Peer::didClose): Ditto.
+        (WebCore::WorkerThreadableWebSocketChannel::Bridge::initialize): Ditto.
+        (WebCore::WorkerThreadableWebSocketChannel::Bridge::connect): Ditto.
+        (WebCore::WorkerThreadableWebSocketChannel::Bridge::send): Ditto.
+        (WebCore::WorkerThreadableWebSocketChannel::Bridge::close): Ditto.
+        (WebCore::WorkerThreadableWebSocketChannel::Bridge::fail): Ditto.
+
+        * dom/Document.cpp:
+        (WebCore::Document::addConsoleMessage): Pass a StringCapture when creating
+        AddConsoleMessageTask. Same reason as above, but in a different context.
+        (WebCore::Document::addMessage): Ditto.
+
+        * dom/ScriptExecutionContext.h: Changed AddConsoleMessageTask to take and
+        capture a StringCapture rather than a String, for the same reason as above.
+
+        * fileapi/AsyncFileStream.cpp:
+        (WebCore::AsyncFileStream::write): Use URLCapture instead of trying to use
+        StringCapture on a URL, since that doesn't preserve the validity flag.
+
+        * loader/WorkerThreadableLoader.cpp:
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::MainThreadBridge): Use StringCapture.
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::didFail): Ditto.
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::didFailAccessControlCheck): Ditto.
+
+        * platform/URL.h: Added URLCapture.
+
+        * platform/network/FormData.cpp:
+        (WebCore::appendBlobResolved): Remove incorrect pointless code that creates a new URL
+        from an existing URL with the ParsedURLString constructor.
+
+        * workers/DefaultSharedWorkerRepository.cpp: Fixed code that was trying to copy a URL
+        by copying a string to instead just use URL::copy. The comment claimed that URL::copy
+        is not thread safe, but that claim is incorrect.
+        (WebCore::SharedWorkerProxy::postExceptionToWorkerObject): Use StringCapture.
+        (WebCore::SharedWorkerProxy::postConsoleMessageToWorkerObject): Ditto.
+        (WebCore::DefaultSharedWorkerRepository::getProxy): Use URL::copy.
+
+        * workers/WorkerGlobalScope.cpp:
+        (WebCore::WorkerGlobalScope::addConsoleMessage): Use StringCapture.
+        (WebCore::WorkerGlobalScope::addMessage): Ditto.
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerMessagingProxy::postExceptionToWorkerObject): Ditto.
+        (WebCore::WorkerMessagingProxy::postConsoleMessageToWorkerObject): Ditto.
+        (WebCore::WorkerMessagingProxy::sendMessageToInspector): Ditto.
+        (WebCore::WorkerMessagingProxy::postMessageToPageInspector): Ditto.
+
+        * workers/WorkerRunLoop.cpp:
+        (WebCore::WorkerRunLoop::postTaskAndTerminate): Make a Task with make_unique
+        rather than with Task::create. Removed an extra isolatedCopy, unneeded because
+        the Task constructor already does an isolatedCopy.
+        (WebCore::WorkerRunLoop::postTaskForMode): Ditto.
+        (WebCore::WorkerRunLoop::Task::create): Deleted.
+
+        * workers/WorkerRunLoop.h: Removed unneeded create function and explicit
+        public empty destructor.
+
 2014-11-09  Chris Dumez  <[email protected]>
 
         Use is<>() / downcast<>() for HTMLCollection subclasses

Modified: trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp (175791 => 175792)


--- trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp	2014-11-09 17:25:21 UTC (rev 175792)
@@ -266,12 +266,12 @@
     ASSERT(isMainThread());
 
     RefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper = m_workerClientWrapper;
-    String subprotocolCopy = m_mainWebSocketChannel->subprotocol().isolatedCopy();
-    String extensionsCopy = m_mainWebSocketChannel->extensions().isolatedCopy();
-    m_loaderProxy.postTaskForModeToWorkerGlobalScope([workerClientWrapper, subprotocolCopy, extensionsCopy] (ScriptExecutionContext& context) {
+    StringCapture capturedSubprotocol(m_mainWebSocketChannel->subprotocol());
+    StringCapture capturedExtensions(m_mainWebSocketChannel->extensions());
+    m_loaderProxy.postTaskForModeToWorkerGlobalScope([workerClientWrapper, capturedSubprotocol, capturedExtensions] (ScriptExecutionContext& context) {
         ASSERT_UNUSED(context, context.isWorkerGlobalScope());
-        workerClientWrapper->setSubprotocol(subprotocolCopy);
-        workerClientWrapper->setExtensions(extensionsCopy);
+        workerClientWrapper->setSubprotocol(capturedSubprotocol.string());
+        workerClientWrapper->setExtensions(capturedExtensions.string());
         workerClientWrapper->didConnect();
     }, m_taskMode);
 }
@@ -281,10 +281,10 @@
     ASSERT(isMainThread());
 
     RefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper = m_workerClientWrapper;
-    String messageCopy = message.isolatedCopy();
-    m_loaderProxy.postTaskForModeToWorkerGlobalScope([workerClientWrapper, messageCopy] (ScriptExecutionContext& context) {
+    StringCapture capturedMessage(message);
+    m_loaderProxy.postTaskForModeToWorkerGlobalScope([workerClientWrapper, capturedMessage] (ScriptExecutionContext& context) {
         ASSERT_UNUSED(context, context.isWorkerGlobalScope());
-        workerClientWrapper->didReceiveMessage(messageCopy);
+        workerClientWrapper->didReceiveMessage(capturedMessage.string());
     }, m_taskMode);
 }
 
@@ -327,11 +327,11 @@
     m_mainWebSocketChannel = 0;
 
     RefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper = m_workerClientWrapper;
-    String reasonCopy = reason.isolatedCopy();
+    StringCapture capturedReason(reason);
     m_loaderProxy.postTaskForModeToWorkerGlobalScope(
-        [workerClientWrapper, unhandledBufferedAmount, closingHandshakeCompletion, code, reasonCopy] (ScriptExecutionContext& context) {
+        [workerClientWrapper, unhandledBufferedAmount, closingHandshakeCompletion, code, capturedReason] (ScriptExecutionContext& context) {
             ASSERT_UNUSED(context, context.isWorkerGlobalScope());
-            workerClientWrapper->didClose(unhandledBufferedAmount, closingHandshakeCompletion, code, reasonCopy);
+            workerClientWrapper->didClose(unhandledBufferedAmount, closingHandshakeCompletion, code, capturedReason.string());
         }, m_taskMode);
 }
 
@@ -399,9 +399,9 @@
 
     WorkerLoaderProxy* loaderProxy = &m_loaderProxy;
     RefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper = m_workerClientWrapper;
-    String taskModeCopy = m_taskMode.isolatedCopy();
-    m_loaderProxy.postTaskToLoader([loaderProxy, workerClientWrapper, taskModeCopy] (ScriptExecutionContext& context) {
-        mainThreadInitialize(context, loaderProxy, workerClientWrapper, taskModeCopy);
+    StringCapture capturedTaskMode(m_taskMode);
+    m_loaderProxy.postTaskToLoader([loaderProxy, workerClientWrapper, capturedTaskMode] (ScriptExecutionContext& context) {
+        mainThreadInitialize(context, loaderProxy, workerClientWrapper, capturedTaskMode.string());
     });
     waitForMethodCompletion();
 
@@ -418,14 +418,14 @@
         return;
 
     Peer* peer = m_peer;
-    URL urlCopy = url.copy();
-    String protocolCopy = protocol.isolatedCopy();
-    m_loaderProxy.postTaskToLoader([peer, urlCopy, protocolCopy] (ScriptExecutionContext& context) {
+    URLCapture capturedURL(url);
+    StringCapture capturedProtocol(protocol);
+    m_loaderProxy.postTaskToLoader([peer, capturedURL, capturedProtocol] (ScriptExecutionContext& context) {
         ASSERT(isMainThread());
         ASSERT_UNUSED(context, context.isDocument());
         ASSERT(peer);
 
-        peer->connect(urlCopy, protocolCopy);
+        peer->connect(capturedURL.url(), capturedProtocol.string());
     });
 }
 
@@ -436,13 +436,13 @@
     setMethodNotCompleted();
 
     Peer* peer = m_peer;
-    String messageCopy = message.isolatedCopy();
-    m_loaderProxy.postTaskToLoader([peer, messageCopy] (ScriptExecutionContext& context) {
+    StringCapture capturedMessage(message);
+    m_loaderProxy.postTaskToLoader([peer, capturedMessage] (ScriptExecutionContext& context) {
         ASSERT(isMainThread());
         ASSERT_UNUSED(context, context.isDocument());
         ASSERT(peer);
 
-        peer->send(messageCopy);
+        peer->send(capturedMessage.string());
     });
 
     Ref<Bridge> protect(*this);
@@ -490,16 +490,15 @@
     setMethodNotCompleted();
 
     Peer* peer = m_peer;
-    URL urlCopy = binaryData.url().copy();
-    String typeCopy = binaryData.type().isolatedCopy();
+    URLCapture capturedURL(binaryData.url());
+    StringCapture capturedType(binaryData.type());
     long long size = binaryData.size();
-    m_loaderProxy.postTaskToLoader([peer, urlCopy, typeCopy, size] (ScriptExecutionContext& context) {
+    m_loaderProxy.postTaskToLoader([peer, capturedURL, capturedType, size] (ScriptExecutionContext& context) {
         ASSERT(isMainThread());
         ASSERT_UNUSED(context, context.isDocument());
         ASSERT(peer);
 
-        RefPtr<Blob> blob = Blob::deserialize(urlCopy, typeCopy, size);
-        peer->send(*blob);
+        peer->send(*Blob::deserialize(capturedURL.url(), capturedType.string(), size));
     });
 
     Ref<Bridge> protect(*this);
@@ -539,13 +538,13 @@
         return;
 
     Peer* peer = m_peer;
-    String reasonCopy = reason.isolatedCopy();
-    m_loaderProxy.postTaskToLoader([peer, code, reasonCopy] (ScriptExecutionContext& context) {
+    StringCapture capturedReason(reason);
+    m_loaderProxy.postTaskToLoader([peer, code, capturedReason] (ScriptExecutionContext& context) {
         ASSERT(isMainThread());
         ASSERT_UNUSED(context, context.isDocument());
         ASSERT(peer);
 
-        peer->close(code, reasonCopy);
+        peer->close(code, capturedReason.string());
     });
 }
 
@@ -555,13 +554,13 @@
         return;
 
     Peer* peer = m_peer;
-    String reasonCopy = reason.isolatedCopy();
-    m_loaderProxy.postTaskToLoader([peer, reasonCopy] (ScriptExecutionContext& context) {
+    StringCapture capturedReason(reason);
+    m_loaderProxy.postTaskToLoader([peer, capturedReason] (ScriptExecutionContext& context) {
         ASSERT(isMainThread());
         ASSERT_UNUSED(context, context.isDocument());
         ASSERT(peer);
 
-        peer->fail(reasonCopy);
+        peer->fail(capturedReason.string());
     });
 }
 

Modified: trunk/Source/WebCore/dom/Document.cpp (175791 => 175792)


--- trunk/Source/WebCore/dom/Document.cpp	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/dom/Document.cpp	2014-11-09 17:25:21 UTC (rev 175792)
@@ -4979,7 +4979,7 @@
 void Document::addConsoleMessage(MessageSource source, MessageLevel level, const String& message, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask(source, level, message.isolatedCopy()));
+        postTask(AddConsoleMessageTask(source, level, StringCapture(message)));
         return;
     }
 
@@ -4990,7 +4990,7 @@
 void Document::addMessage(MessageSource source, MessageLevel level, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, PassRefPtr<Inspector::ScriptCallStack> callStack, JSC::ExecState* state, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask(source, level, message));
+        postTask(AddConsoleMessageTask(source, level, StringCapture(message)));
         return;
     }
 

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (175791 => 175792)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2014-11-09 17:25:21 UTC (rev 175792)
@@ -184,9 +184,9 @@
 protected:
     class AddConsoleMessageTask : public Task {
     public:
-        AddConsoleMessageTask(MessageSource source, MessageLevel level, const String& message)
-            : Task([source, level, message] (ScriptExecutionContext& context) {
-                context.addConsoleMessage(source, level, message);
+        AddConsoleMessageTask(MessageSource source, MessageLevel level, const StringCapture& message)
+            : Task([source, level, message](ScriptExecutionContext& context) {
+                context.addConsoleMessage(source, level, message.string());
             })
         {
         }

Modified: trunk/Source/WebCore/fileapi/AsyncFileStream.cpp (175791 => 175792)


--- trunk/Source/WebCore/fileapi/AsyncFileStream.cpp	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/fileapi/AsyncFileStream.cpp	2014-11-09 17:25:21 UTC (rev 175792)
@@ -192,10 +192,9 @@
 
 void AsyncFileStream::write(const URL& blobURL, long long position, int length)
 {
-    // FIXME: Would be more elegant to have a URLCapture for cases like this to avoid re-parsing the URL.
-    StringCapture capturedURL(blobURL.string());
+    URLCapture capturedURL(blobURL);
     perform([capturedURL, position, length](FileStream& stream) -> std::function<void(FileStreamClient&)> {
-        int bytesWritten = stream.write(URL(ParsedURLString, capturedURL.string()), position, length);
+        int bytesWritten = stream.write(capturedURL.url(), position, length);
         return [bytesWritten](FileStreamClient& client) {
             client.didWrite(bytesWritten);
         };

Modified: trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp (175791 => 175792)


--- trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp	2014-11-09 17:25:21 UTC (rev 175792)
@@ -92,13 +92,13 @@
     ASSERT(m_workerClientWrapper.get());
 
     CrossThreadResourceRequestData* requestData = request.copyData().leakPtr();
-    String outgoingReferrerCopy = outgoingReferrer.isolatedCopy();
-    m_loaderProxy.postTaskToLoader([this, requestData, options, outgoingReferrerCopy] (ScriptExecutionContext& context) {
+    StringCapture capturedOutgoingReferrer(outgoingReferrer);
+    m_loaderProxy.postTaskToLoader([this, requestData, options, capturedOutgoingReferrer](ScriptExecutionContext& context) {
         ASSERT(isMainThread());
         Document& document = downcast<Document>(context);
 
         OwnPtr<ResourceRequest> request = ResourceRequest::adopt(adoptPtr(requestData));
-        request->setHTTPReferrer(outgoingReferrerCopy);
+        request->setHTTPReferrer(capturedOutgoingReferrer.string());
 
         // FIXME: If the a site requests a local resource, then this will return a non-zero value but the sync path
         // will return a 0 value. Either this should return 0 or the other code path should do a callback with
@@ -193,20 +193,22 @@
 void WorkerThreadableLoader::MainThreadBridge::didFail(const ResourceError& error)
 {
     RefPtr<ThreadableLoaderClientWrapper> workerClientWrapper = m_workerClientWrapper;
-    ResourceError errorCopy = error.copy();
-    m_loaderProxy.postTaskForModeToWorkerGlobalScope([workerClientWrapper, errorCopy] (ScriptExecutionContext& context) {
+    ResourceError* capturedError = new ResourceError(error.copy());
+    m_loaderProxy.postTaskForModeToWorkerGlobalScope([workerClientWrapper, capturedError] (ScriptExecutionContext& context) {
         ASSERT_UNUSED(context, context.isWorkerGlobalScope());
-        workerClientWrapper->didFail(errorCopy);
+        workerClientWrapper->didFail(*capturedError);
+        delete capturedError;
     }, m_taskMode);
 }
 
 void WorkerThreadableLoader::MainThreadBridge::didFailAccessControlCheck(const ResourceError& error)
 {
     RefPtr<ThreadableLoaderClientWrapper> workerClientWrapper = m_workerClientWrapper;
-    ResourceError errorCopy = error.copy();
-    m_loaderProxy.postTaskForModeToWorkerGlobalScope([workerClientWrapper, errorCopy] (ScriptExecutionContext& context) {
+    ResourceError* capturedError = new ResourceError(error.copy());
+    m_loaderProxy.postTaskForModeToWorkerGlobalScope([workerClientWrapper, capturedError] (ScriptExecutionContext& context) {
         ASSERT_UNUSED(context, context.isWorkerGlobalScope());
-        workerClientWrapper->didFailAccessControlCheck(errorCopy);
+        workerClientWrapper->didFailAccessControlCheck(*capturedError);
+        delete capturedError;
     }, m_taskMode);
 }
 

Modified: trunk/Source/WebCore/platform/URL.h (175791 => 175792)


--- trunk/Source/WebCore/platform/URL.h	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/platform/URL.h	2014-11-09 17:25:21 UTC (rev 175792)
@@ -81,8 +81,9 @@
     // standard String constructor.
 
     // Makes a deep copy. Helpful only if you need to use a URL on another
-    // thread.  Since the underlying StringImpl objects are immutable, there's
+    // thread. Since the underlying StringImpl objects are immutable, there's
     // no other reason to ever prefer copy() over plain old assignment.
+    // FIXME: Rename to isolatedCopy to match String.
     URL copy() const;
 
     bool isNull() const;
@@ -254,6 +255,24 @@
 
 WEBCORE_EXPORT String encodeWithURLEscapeSequences(const String&);
 
+#if PLATFORM(IOS)
+WEBCORE_EXPORT void enableURLSchemeCanonicalization(bool);
+#endif
+
+// Like StringCapture, but for URLs.
+class URLCapture {
+public:
+    explicit URLCapture(const URL&);
+    explicit URLCapture(URL&&);
+    URLCapture(const URLCapture&);
+    const URL& url() const;
+    URL releaseURL();
+
+private:
+    void operator=(const URLCapture&) = delete;
+    URL m_URL;
+};
+
 // Inlines.
 
 inline bool operator==(const URL& a, const URL& b)
@@ -344,10 +363,31 @@
     return m_pathAfterLastSlash;
 }
 
-#if PLATFORM(IOS)
-WEBCORE_EXPORT void enableURLSchemeCanonicalization(bool);
-#endif
+inline URLCapture::URLCapture(const URL& url)
+    : m_URL(url)
+{
+}
 
+inline URLCapture::URLCapture(URL&& url)
+    : m_URL(url)
+{
+}
+
+inline URLCapture::URLCapture(const URLCapture& other)
+    : m_URL(other.m_URL.copy())
+{
+}
+
+inline const URL& URLCapture::url() const
+{
+    return m_URL;
+}
+
+inline URL URLCapture::releaseURL()
+{
+    return WTF::move(m_URL);
+}
+
 } // namespace WebCore
 
 namespace WTF {

Modified: trunk/Source/WebCore/platform/network/FormData.cpp (175791 => 175792)


--- trunk/Source/WebCore/platform/network/FormData.cpp	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/platform/network/FormData.cpp	2014-11-09 17:25:21 UTC (rev 175792)
@@ -283,7 +283,7 @@
         LOG_ERROR("Tried to resolve a blob without a usable registry");
         return;
     }
-    BlobData* blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(URL(ParsedURLString, url));
+    BlobData* blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(url);
     if (!blobData) {
         LOG_ERROR("Could not get blob data from a registry");
         return;

Modified: trunk/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp (175791 => 175792)


--- trunk/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp	2014-11-09 17:25:21 UTC (rev 175792)
@@ -34,7 +34,6 @@
 
 #include "DefaultSharedWorkerRepository.h"
 
-#include "ActiveDOMObject.h"
 #include "Document.h"
 #include "ExceptionCode.h"
 #include "InspectorInstrumentation.h"
@@ -44,10 +43,8 @@
 #include "PageGroup.h"
 #include "PlatformStrategies.h"
 #include "SecurityOrigin.h"
-#include "SecurityOriginHash.h"
 #include "SharedWorker.h"
 #include "SharedWorkerGlobalScope.h"
-#include "SharedWorkerRepository.h"
 #include "SharedWorkerStrategy.h"
 #include "SharedWorkerThread.h"
 #include "WorkerLoaderProxy.h"
@@ -55,42 +52,33 @@
 #include "WorkerScriptLoader.h"
 #include "WorkerScriptLoaderClient.h"
 #include <inspector/ScriptCallStack.h>
-#include <mutex>
-#include <wtf/HashSet.h>
 #include <wtf/NeverDestroyed.h>
-#include <wtf/Threading.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
-class SharedWorkerProxy : public ThreadSafeRefCounted<SharedWorkerProxy>, public WorkerLoaderProxy, public WorkerReportingProxy {
+class SharedWorkerProxy final : public ThreadSafeRefCounted<SharedWorkerProxy>, public WorkerLoaderProxy, public WorkerReportingProxy {
 public:
     static PassRefPtr<SharedWorkerProxy> create(const String& name, const URL& url, PassRefPtr<SecurityOrigin> origin) { return adoptRef(new SharedWorkerProxy(name, url, origin)); }
 
     void setThread(PassRefPtr<SharedWorkerThread> thread) { m_thread = thread; }
     SharedWorkerThread* thread() { return m_thread.get(); }
     bool isClosing() const { return m_closing; }
-    URL url() const
-    {
-        // Don't use m_url.copy() because it isn't a threadsafe method.
-        return URL(ParsedURLString, m_url.string().isolatedCopy());
-    }
-
+    URL url() const { return m_url.copy(); }
     String name() const { return m_name.isolatedCopy(); }
     bool matches(const String& name, PassRefPtr<SecurityOrigin> origin, const URL& urlToMatch) const;
 
     // WorkerLoaderProxy
-    virtual void postTaskToLoader(ScriptExecutionContext::Task);
-    virtual bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task, const String&);
+    virtual void postTaskToLoader(ScriptExecutionContext::Task) override;
+    virtual bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task, const String&) override;
 
     // WorkerReportingProxy
-    virtual void postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL);
-    virtual void postConsoleMessageToWorkerObject(MessageSource, MessageLevel, const String& message, int lineNumber, int columnNumber, const String& sourceURL);
+    virtual void postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) override;
+    virtual void postConsoleMessageToWorkerObject(MessageSource, MessageLevel, const String& message, int lineNumber, int columnNumber, const String& sourceURL) override;
 #if ENABLE(INSPECTOR)
-    virtual void postMessageToPageInspector(const String&);
+    virtual void postMessageToPageInspector(const String&) override;
 #endif
-    virtual void workerGlobalScopeClosed();
-    virtual void workerGlobalScopeDestroyed();
+    virtual void workerGlobalScopeClosed() override;
+    virtual void workerGlobalScopeDestroyed() override;
 
     // Updates the list of the worker's documents, per section 4.5 of the WebWorkers spec.
     void addToWorkerDocuments(ScriptExecutionContext*);
@@ -181,24 +169,22 @@
 void SharedWorkerProxy::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
 {
     MutexLocker lock(m_workerDocumentsLock);
-    String errorMessageCopy = errorMessage.isolatedCopy();
-    String sourceURLCopy = sourceURL.isolatedCopy();
-
+    StringCapture capturedErrorMessage(errorMessage);
+    StringCapture capturedSourceURL(sourceURL);
     for (auto& document : m_workerDocuments)
-        document->postTask([errorMessageCopy, lineNumber, columnNumber, sourceURLCopy] (ScriptExecutionContext& context) {
-            context.reportException(errorMessageCopy, lineNumber, columnNumber, sourceURLCopy, nullptr);
+        document->postTask([capturedErrorMessage, lineNumber, columnNumber, capturedSourceURL] (ScriptExecutionContext& context) {
+            context.reportException(capturedErrorMessage.string(), lineNumber, columnNumber, capturedSourceURL.string(), nullptr);
         });
 }
 
 void SharedWorkerProxy::postConsoleMessageToWorkerObject(MessageSource source, MessageLevel level, const String& message, int lineNumber, int columnNumber, const String& sourceURL)
 {
     MutexLocker lock(m_workerDocumentsLock);
-    String messageCopy = message.isolatedCopy();
-    String sourceURLCopy = sourceURL.isolatedCopy();
-
+    StringCapture capturedMessage(message);
+    StringCapture capturedSourceURL(sourceURL);
     for (auto& document : m_workerDocuments)
-        document->postTask([source, level, messageCopy, sourceURLCopy, lineNumber, columnNumber] (ScriptExecutionContext& context) {
-            context.addConsoleMessage(source, level, messageCopy, sourceURLCopy, lineNumber, columnNumber);
+        document->postTask([source, level, capturedMessage, capturedSourceURL, lineNumber, columnNumber] (ScriptExecutionContext& context) {
+            context.addConsoleMessage(source, level, capturedMessage.string(), capturedSourceURL.string(), lineNumber, columnNumber);
         });
 }
 
@@ -417,7 +403,7 @@
     // Look for an existing worker, and create one if it doesn't exist.
     // Items in the cache are freed on another thread, so do a threadsafe copy of the URL before creating the origin,
     // to make sure no references to external strings linger.
-    RefPtr<SecurityOrigin> origin = SecurityOrigin::create(URL(ParsedURLString, url.string().isolatedCopy()));
+    RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url.copy());
     for (unsigned i = 0; i < m_proxies.size(); i++) {
         if (!m_proxies[i]->isClosing() && m_proxies[i]->matches(name, origin, url))
             return m_proxies[i];

Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (175791 => 175792)


--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp	2014-11-09 17:25:21 UTC (rev 175792)
@@ -222,7 +222,7 @@
 void WorkerGlobalScope::addConsoleMessage(MessageSource source, MessageLevel level, const String& message, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask(source, level, message));
+        postTask(AddConsoleMessageTask(source, level, StringCapture(message)));
         return;
     }
 
@@ -233,7 +233,7 @@
 void WorkerGlobalScope::addMessage(MessageSource source, MessageLevel level, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, PassRefPtr<ScriptCallStack> callStack, JSC::ExecState* state, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {
-        postTask(AddConsoleMessageTask(source, level, message));
+        postTask(AddConsoleMessageTask(source, level, StringCapture(message)));
         return;
     }
 

Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp (175791 => 175792)


--- trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp	2014-11-09 17:25:21 UTC (rev 175792)
@@ -146,9 +146,9 @@
 
 void WorkerMessagingProxy::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
 {
-    String errorMessageCopy = errorMessage.isolatedCopy();
-    String sourceURLCopy = sourceURL.isolatedCopy();
-    m_scriptExecutionContext->postTask([this, errorMessageCopy, sourceURLCopy, lineNumber, columnNumber] (ScriptExecutionContext& context) {
+    StringCapture capturedErrorMessage(errorMessage);
+    StringCapture capturedSourceURL(sourceURL);
+    m_scriptExecutionContext->postTask([this, capturedErrorMessage, capturedSourceURL, lineNumber, columnNumber] (ScriptExecutionContext& context) {
         Worker* workerObject = this->workerObject();
         if (!workerObject)
             return;
@@ -156,20 +156,20 @@
         // We don't bother checking the askedToTerminate() flag here, because exceptions should *always* be reported even if the thread is terminated.
         // This is intentionally different than the behavior in MessageWorkerTask, because terminated workers no longer deliver messages (section 4.6 of the WebWorker spec), but they do report exceptions.
 
-        bool errorHandled = !workerObject->dispatchEvent(ErrorEvent::create(errorMessageCopy, sourceURLCopy, lineNumber, columnNumber));
+        bool errorHandled = !workerObject->dispatchEvent(ErrorEvent::create(capturedErrorMessage.string(), capturedSourceURL.string(), lineNumber, columnNumber));
         if (!errorHandled)
-            context.reportException(errorMessageCopy, lineNumber, columnNumber, sourceURLCopy, 0);
+            context.reportException(capturedErrorMessage.string(), lineNumber, columnNumber, capturedSourceURL.string(), 0);
     });
 }
 
 void WorkerMessagingProxy::postConsoleMessageToWorkerObject(MessageSource source, MessageLevel level, const String& message, int lineNumber, int columnNumber, const String& sourceURL)
 {
-    String messageCopy = message.isolatedCopy();
-    String sourceURLCopy = sourceURL.isolatedCopy();
-    m_scriptExecutionContext->postTask([this, source, level, messageCopy, sourceURLCopy, lineNumber, columnNumber] (ScriptExecutionContext& context) {
+    StringCapture capturedMessage(message);
+    StringCapture capturedSourceURL(sourceURL);
+    m_scriptExecutionContext->postTask([this, source, level, capturedMessage, capturedSourceURL, lineNumber, columnNumber] (ScriptExecutionContext& context) {
         if (askedToTerminate())
             return;
-        context.addConsoleMessage(source, level, messageCopy, sourceURLCopy, lineNumber, columnNumber);
+        context.addConsoleMessage(source, level, capturedMessage.string(), capturedSourceURL.string(), lineNumber, columnNumber);
     });
 }
 
@@ -242,9 +242,9 @@
 {
     if (m_askedToTerminate)
         return;
-    String messageCopy = message.isolatedCopy();
-    m_workerThread->runLoop().postTaskForMode([messageCopy] (ScriptExecutionContext& context) {
-        downcast<WorkerGlobalScope>(context).workerInspectorController().dispatchMessageFromFrontend(messageCopy);
+    StringCapture capturedMessage(message);
+    m_workerThread->runLoop().postTaskForMode([capturedMessage] (ScriptExecutionContext& context) {
+        downcast<WorkerGlobalScope>(context).workerInspectorController().dispatchMessageFromFrontend(capturedMessage.string());
     }, WorkerDebuggerAgent::debuggerTaskMode);
     WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(m_workerThread.get());
 }
@@ -294,9 +294,9 @@
 #if ENABLE(INSPECTOR)
 void WorkerMessagingProxy::postMessageToPageInspector(const String& message)
 {
-    String messageCopy = message.isolatedCopy();
-    m_scriptExecutionContext->postTask([this, messageCopy] (ScriptExecutionContext&) {
-        m_pageInspector->dispatchMessageFromWorker(messageCopy);
+    StringCapture capturedMessage(message);
+    m_scriptExecutionContext->postTask([this, capturedMessage] (ScriptExecutionContext&) {
+        m_pageInspector->dispatchMessageFromWorker(capturedMessage.string());
     });
 }
 #endif

Modified: trunk/Source/WebCore/workers/WorkerRunLoop.cpp (175791 => 175792)


--- trunk/Source/WebCore/workers/WorkerRunLoop.cpp	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/workers/WorkerRunLoop.cpp	2014-11-09 17:25:21 UTC (rev 175792)
@@ -199,19 +199,14 @@
 
 void WorkerRunLoop::postTaskAndTerminate(ScriptExecutionContext::Task task)
 {
-    m_messageQueue.appendAndKill(Task::create(WTF::move(task), defaultMode().isolatedCopy()));
+    m_messageQueue.appendAndKill(std::make_unique<Task>(WTF::move(task), defaultMode()));
 }
 
 void WorkerRunLoop::postTaskForMode(ScriptExecutionContext::Task task, const String& mode)
 {
-    m_messageQueue.append(Task::create(WTF::move(task), mode.isolatedCopy()));
+    m_messageQueue.append(std::make_unique<Task>(WTF::move(task), mode));
 }
 
-std::unique_ptr<WorkerRunLoop::Task> WorkerRunLoop::Task::create(ScriptExecutionContext::Task task, const String& mode)
-{
-    return std::unique_ptr<Task>(new Task(WTF::move(task), mode));
-}
-
 void WorkerRunLoop::Task::performTask(const WorkerRunLoop& runLoop, WorkerGlobalScope* context)
 {
     if ((!context->isClosing() && !runLoop.terminated()) || m_task.isCleanupTask())

Modified: trunk/Source/WebCore/workers/WorkerRunLoop.h (175791 => 175792)


--- trunk/Source/WebCore/workers/WorkerRunLoop.h	2014-11-09 17:21:51 UTC (rev 175791)
+++ trunk/Source/WebCore/workers/WorkerRunLoop.h	2014-11-09 17:25:21 UTC (rev 175792)
@@ -68,14 +68,11 @@
         class Task {
             WTF_MAKE_NONCOPYABLE(Task); WTF_MAKE_FAST_ALLOCATED;
         public:
-            static std::unique_ptr<Task> create(ScriptExecutionContext::Task, const String& mode);
-            ~Task() { }
+            Task(ScriptExecutionContext::Task, const String& mode);
             const String& mode() const { return m_mode; }
             void performTask(const WorkerRunLoop&, WorkerGlobalScope*);
 
         private:
-            Task(ScriptExecutionContext::Task, const String& mode);
-        
             ScriptExecutionContext::Task m_task;
             String m_mode;
         };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to