[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

jianli at chromium.org jianli at chromium.org
Wed Dec 22 12:01:17 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit ab8d91a8f7024dec217c33235649a9617c619f23
Author: jianli at chromium.org <jianli at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Aug 12 22:16:10 2010 +0000

    Add ThreadableBlobRegistry to support calling BlobRegistry methods in
    main thread.
    https://bugs.webkit.org/show_bug.cgi?id=43874
    
    Reviewed by David Levin.
    
    * Android.mk:
    * CMakeLists.txt:
    * GNUmakefile.am:
    * WebCore.gypi:
    * WebCore.pro:
    * WebCore.vcproj/WebCore.vcproj:
    * WebCore.xcodeproj/project.pbxproj:
    * dom/ScriptExecutionContext.cpp:
    (WebCore::ScriptExecutionContext::~ScriptExecutionContext):
    (WebCore::ScriptExecutionContext::addBlob):
    (WebCore::ScriptExecutionContext::removeBlob):
    (WebCore::ScriptExecutionContext::createPublicBlobURL):
    (WebCore::ScriptExecutionContext::revokePublicBlobURL):
    * dom/ScriptExecutionContext.h:
    * html/Blob.cpp:
    (WebCore::Blob::Blob):
    (WebCore::Blob::~Blob):
    (WebCore::Blob::contextDestroyed):
    * html/Blob.h:
    * html/BlobRegistryImpl.cpp:
    (WebCore::BlobRegistryImpl::registerBlobURL):
    (WebCore::BlobRegistryImpl::unregisterBlobURL):
    (WebCore::BlobRegistryImpl::getBlobDataFromURL):
    * html/ThreadableBlobRegistry.cpp: Added.
    * html/ThreadableBlobRegistry.h: Added.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65271 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/Android.mk b/WebCore/Android.mk
index c32bcae..a60d16f 100644
--- a/WebCore/Android.mk
+++ b/WebCore/Android.mk
@@ -255,6 +255,8 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
 	\
 	html/AsyncImageResizer.cpp \
 	html/Blob.cpp \
+	html/BlobRegistryImpl.cpp \
+	html/BlobURL.cpp \
 	html/CollectionCache.cpp \
 	html/CSSPreloadScanner.cpp \
 	html/DOMFormData.cpp \
@@ -287,6 +289,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
 	html/HTMLViewSourceParser.cpp \
 	html/ImageData.cpp \
 	html/ImageResizerThread.cpp \
+	html/ThreadableBlobRegistry.cpp \
 	html/TimeRanges.cpp \
 	html/ValidityState.cpp \
 	\
@@ -405,6 +408,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
 	page/animation/KeyframeAnimation.cpp \
 	\
 	platform/Arena.cpp \
+	platform/BlobData.cpp \
 	platform/ContentType.cpp \
 	platform/ContextMenu.cpp \
 	platform/CrossThreadCopier.cpp \
diff --git a/WebCore/CMakeLists.txt b/WebCore/CMakeLists.txt
index 7743d26..ac64f66 100644
--- a/WebCore/CMakeLists.txt
+++ b/WebCore/CMakeLists.txt
@@ -1040,6 +1040,7 @@ SET(WebCore_SOURCES
     html/ImageResizerThread.cpp
     html/LabelsNodeList.cpp
     html/StepRange.cpp
+    html/ThreadableBlobRegistry.cpp
     html/ValidityState.cpp
     html/canvas/CanvasGradient.cpp
     html/canvas/CanvasPattern.cpp
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 64f892c..bc7fd7e 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,37 @@
+2010-08-12  Jian Li  <jianli at chromium.org>
+
+        Reviewed by David Levin.
+
+        Add ThreadableBlobRegistry to support calling BlobRegistry methods in
+        main thread.
+        https://bugs.webkit.org/show_bug.cgi?id=43874
+
+        * Android.mk:
+        * CMakeLists.txt:
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/ScriptExecutionContext.cpp:
+        (WebCore::ScriptExecutionContext::~ScriptExecutionContext):
+        (WebCore::ScriptExecutionContext::addBlob):
+        (WebCore::ScriptExecutionContext::removeBlob):
+        (WebCore::ScriptExecutionContext::createPublicBlobURL):
+        (WebCore::ScriptExecutionContext::revokePublicBlobURL):
+        * dom/ScriptExecutionContext.h:
+        * html/Blob.cpp:
+        (WebCore::Blob::Blob):
+        (WebCore::Blob::~Blob):
+        (WebCore::Blob::contextDestroyed):
+        * html/Blob.h:
+        * html/BlobRegistryImpl.cpp:
+        (WebCore::BlobRegistryImpl::registerBlobURL):
+        (WebCore::BlobRegistryImpl::unregisterBlobURL):
+        (WebCore::BlobRegistryImpl::getBlobDataFromURL):
+        * html/ThreadableBlobRegistry.cpp: Added.
+        * html/ThreadableBlobRegistry.h: Added.
+
 2010-08-12  Csaba Osztrogonác  <ossy at webkit.org>
 
         Reviewed by Darin Adler.
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index 70979d4..bca2aae 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -1565,6 +1565,8 @@ webcore_sources += \
 	WebCore/html/StepRange.cpp \
 	WebCore/html/StepRange.h \
 	WebCore/html/TextMetrics.h \
+	WebCore/html/ThreadableBlobRegistry.cpp \
+	WebCore/html/ThreadableBlobRegistry.h \
 	WebCore/html/ValidityState.cpp \
 	WebCore/html/ValidityState.h \
 	WebCore/html/VoidCallback.h \
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index 4bf62d3..74e8126 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -1731,6 +1731,8 @@
             'html/StepRange.cpp',
             'html/StepRange.h',
             'html/TextMetrics.h',
+            'html/ThreadableBlobRegistry.cpp',
+            'html/ThreadableBlobRegistry.h',
             'html/TimeRanges.cpp',
             'html/TimeRanges.h',
             'html/ValidityState.cpp',
diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index 38a19d8..0eb5c97 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -743,6 +743,7 @@ SOURCES += \
     html/ImageData.cpp \
     html/ImageResizerThread.cpp \
     html/LabelsNodeList.cpp \
+    html/ThreadableBlobRegistry.cpp \
     html/StepRange.cpp \
     html/ValidityState.cpp \
     inspector/ConsoleMessage.cpp \
diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj
index f95d2c1..5ff4250 100644
--- a/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -40949,6 +40949,14 @@
 				>
 			</File>
 			<File
+				RelativePath="..\html\ThreadableBlobRegistry.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\html\ThreadableBlobRegistry.h"
+				>
+			</File>
+			<File
 				RelativePath="..\html\TimeRanges.cpp"
 				>
 			</File>
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index ae51c98..f9ed1b4 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -718,6 +718,8 @@
 		2EED575812109EE4007656BB /* BlobRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EED575712109EE4007656BB /* BlobRegistry.h */; };
 		2EED575B12109EF3007656BB /* BlobData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2EED575912109EF3007656BB /* BlobData.cpp */; };
 		2EED575C12109EF3007656BB /* BlobData.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EED575A12109EF3007656BB /* BlobData.h */; };
+		2EED57FD1214A9C2007656BB /* ThreadableBlobRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2EED57FB1214A9C2007656BB /* ThreadableBlobRegistry.cpp */; };
+		2EED57FE1214A9C2007656BB /* ThreadableBlobRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EED57FC1214A9C2007656BB /* ThreadableBlobRegistry.h */; };
 		31288E720E3005D6003619AE /* WebKitCSSKeyframeRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31288E6E0E3005D6003619AE /* WebKitCSSKeyframeRule.cpp */; };
 		31288E730E3005D6003619AE /* WebKitCSSKeyframeRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 31288E6F0E3005D6003619AE /* WebKitCSSKeyframeRule.h */; };
 		31288E740E3005D6003619AE /* WebKitCSSKeyframesRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31288E700E3005D6003619AE /* WebKitCSSKeyframesRule.cpp */; };
@@ -6475,6 +6477,8 @@
 		2EED575712109EE4007656BB /* BlobRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlobRegistry.h; sourceTree = "<group>"; };
 		2EED575912109EF3007656BB /* BlobData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlobData.cpp; sourceTree = "<group>"; };
 		2EED575A12109EF3007656BB /* BlobData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlobData.h; sourceTree = "<group>"; };
+		2EED57FB1214A9C2007656BB /* ThreadableBlobRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadableBlobRegistry.cpp; sourceTree = "<group>"; };
+		2EED57FC1214A9C2007656BB /* ThreadableBlobRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadableBlobRegistry.h; sourceTree = "<group>"; };
 		31288E6E0E3005D6003619AE /* WebKitCSSKeyframeRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitCSSKeyframeRule.cpp; sourceTree = "<group>"; };
 		31288E6F0E3005D6003619AE /* WebKitCSSKeyframeRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitCSSKeyframeRule.h; sourceTree = "<group>"; };
 		31288E700E3005D6003619AE /* WebKitCSSKeyframesRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitCSSKeyframesRule.cpp; sourceTree = "<group>"; };
@@ -14188,6 +14192,8 @@
 				A5AFB34E115151A700B045CB /* StepRange.h */,
 				BCEF45E80E687767001C1287 /* TextMetrics.h */,
 				BCEF453F0E676AC1001C1287 /* TextMetrics.idl */,
+				2EED57FB1214A9C2007656BB /* ThreadableBlobRegistry.cpp */,
+				2EED57FC1214A9C2007656BB /* ThreadableBlobRegistry.h */,
 				E446139D0CD6331000FADA75 /* TimeRanges.cpp */,
 				E446139E0CD6331000FADA75 /* TimeRanges.h */,
 				E446139F0CD6331000FADA75 /* TimeRanges.idl */,
@@ -20149,6 +20155,7 @@
 				E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
 				97DD4D870FDF4D6E00ECF9A4 /* XSSAuditor.h in Headers */,
 				CE172E011136E8CE0062A533 /* ZoomMode.h in Headers */,
+				2EED57FE1214A9C2007656BB /* ThreadableBlobRegistry.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -22574,6 +22581,7 @@
 				93F19B0508245E59001E9ABC /* XSLTProcessorLibxslt.cpp in Sources */,
 				E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
 				97DD4D860FDF4D6E00ECF9A4 /* XSSAuditor.cpp in Sources */,
+				2EED57FD1214A9C2007656BB /* ThreadableBlobRegistry.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/WebCore/dom/ScriptExecutionContext.cpp b/WebCore/dom/ScriptExecutionContext.cpp
index 9fdec9f..6d6b18d 100644
--- a/WebCore/dom/ScriptExecutionContext.cpp
+++ b/WebCore/dom/ScriptExecutionContext.cpp
@@ -28,13 +28,15 @@
 #include "ScriptExecutionContext.h"
 
 #include "ActiveDOMObject.h"
-#include "BlobRegistry.h"
+#include "Blob.h"
+#include "BlobURL.h"
 #include "Database.h"
 #include "DatabaseTask.h"
 #include "DatabaseThread.h"
 #include "FileThread.h"
 #include "MessagePort.h"
 #include "SecurityOrigin.h"
+#include "ThreadableBlobRegistry.h"
 #include "WorkerContext.h"
 #include "WorkerThread.h"
 #include <wtf/MainThread.h>
@@ -91,10 +93,15 @@ ScriptExecutionContext::~ScriptExecutionContext()
         m_fileThread = 0;
     }
 #endif
-    HashSet<String>::iterator blobURLsEnd = m_blobURLs.end();
-    for (HashSet<String>::iterator iter = m_blobURLs.begin(); iter != blobURLsEnd; ++iter)
-        // FIXME: implement thread-safe proxy to make it work with workers.
-        BlobRegistry::instance().unregisterBlobURL(KURL(ParsedURLString, *iter));
+
+    HashSet<Blob*>::iterator blobsEnd = m_blobs.end();
+    for (HashSet<Blob*>::iterator iter = m_blobs.begin(); iter != blobsEnd; ++iter)
+        (*iter)->contextDestroyed();
+#if ENABLE(BLOB)
+    HashSet<String>::iterator publicBlobURLsEnd = m_publicBlobURLs.end();
+    for (HashSet<String>::iterator iter = m_publicBlobURLs.begin(); iter != publicBlobURLsEnd; ++iter)
+        ThreadableBlobRegistry::unregisterBlobURL(this, KURL(ParsedURLString, *iter));
+#endif
 }
 
 #if ENABLE(DATABASE)
@@ -168,6 +175,18 @@ void ScriptExecutionContext::destroyedMessagePort(MessagePort* port)
     m_messagePorts.remove(port);
 }
 
+void ScriptExecutionContext::addBlob(Blob* blob)
+{
+    ASSERT(blob);
+    m_blobs.add(blob);
+}
+
+void ScriptExecutionContext::removeBlob(Blob* blob)
+{
+    ASSERT(blob);
+    m_blobs.remove(blob);
+}
+
 bool ScriptExecutionContext::canSuspendActiveDOMObjects()
 {
     // No protection against m_activeDOMObjects changing during iteration: canSuspend() shouldn't execute arbitrary JS.
@@ -244,19 +263,23 @@ DOMTimer* ScriptExecutionContext::findTimeout(int timeoutId)
     return m_timeouts.get(timeoutId);
 }
 
-void ScriptExecutionContext::trackBlobURL(const String& url)
+#if ENABLE(BLOB)
+KURL ScriptExecutionContext::createPublicBlobURL(Blob* blob)
 {
-    m_blobURLs.add(url);
+    KURL publicURL = BlobURL::createURL(this);
+    ThreadableBlobRegistry::registerBlobURL(this, publicURL, blob->url());
+    m_publicBlobURLs.add(publicURL.string());
+    return publicURL;
 }
 
-void ScriptExecutionContext::revokeBlobURL(const String& url)
+void ScriptExecutionContext::revokePublicBlobURL(const KURL& url)
 {
-    if (m_blobURLs.contains(url)) {
-        // FIXME: implement thread-safe proxy to make it work with workers.
-        BlobRegistry::instance().unregisterBlobURL(KURL(ParsedURLString, url));
-        m_blobURLs.remove(url);
+    if (m_publicBlobURLs.contains(url.string())) {
+        ThreadableBlobRegistry::unregisterBlobURL(this, url);
+        m_publicBlobURLs.remove(url.string());
     }
 }
+#endif
 
 #if ENABLE(BLOB) || ENABLE(FILE_WRITER)
 FileThread* ScriptExecutionContext::fileThread()
diff --git a/WebCore/dom/ScriptExecutionContext.h b/WebCore/dom/ScriptExecutionContext.h
index 79d4d42..761755a 100644
--- a/WebCore/dom/ScriptExecutionContext.h
+++ b/WebCore/dom/ScriptExecutionContext.h
@@ -41,6 +41,7 @@
 namespace WebCore {
 
     class ActiveDOMObject;
+    class Blob;
 #if ENABLE(DATABASE)
     class Database;
     class DatabaseTaskSynchronizer;
@@ -126,8 +127,12 @@ namespace WebCore {
         void removeTimeout(int timeoutId);
         DOMTimer* findTimeout(int timeoutId);
 
-        void trackBlobURL(const String&);
-        void revokeBlobURL(const String&);
+        void addBlob(Blob*);
+        void removeBlob(Blob*);
+#if ENABLE(BLOB)
+        KURL createPublicBlobURL(Blob*);
+        void revokePublicBlobURL(const KURL&);
+#endif
 
 #if USE(JSC)
         JSC::JSGlobalData* globalData();
@@ -156,7 +161,10 @@ namespace WebCore {
 
         HashMap<int, DOMTimer*> m_timeouts;
 
-        HashSet<String> m_blobURLs;
+        HashSet<Blob*> m_blobs;
+#if ENABLE(BLOB)
+        HashSet<String> m_publicBlobURLs;
+#endif
 
         virtual void refScriptExecutionContext() = 0;
         virtual void derefScriptExecutionContext() = 0;
diff --git a/WebCore/html/Blob.cpp b/WebCore/html/Blob.cpp
index f8f795e..3a62ab1 100644
--- a/WebCore/html/Blob.cpp
+++ b/WebCore/html/Blob.cpp
@@ -33,68 +33,89 @@
 
 #include "BlobData.h"
 #include "BlobItem.h"
-#include "BlobRegistry.h"
 #include "BlobURL.h"
 #include "FileSystem.h"
 #include "ScriptExecutionContext.h"
+#include "ThreadableBlobRegistry.h"
 
 namespace WebCore {
 
 // FIXME: To be removed when we switch to using BlobData.
-Blob::Blob(ScriptExecutionContext*, const String& type, const BlobItemList& items)
-    : m_type(type)
+Blob::Blob(ScriptExecutionContext* scriptExecutionContext, const String& type, const BlobItemList& items)
+    : m_scriptExecutionContext(scriptExecutionContext)
+    , m_type(type)
     , m_size(0)
 {
+    m_scriptExecutionContext->addBlob(this);
     for (size_t i = 0; i < items.size(); ++i)
         m_items.append(items[i]);
 }
 
 // FIXME: To be removed when we switch to using BlobData.
-Blob::Blob(ScriptExecutionContext*, const PassRefPtr<BlobItem>& item)
-    : m_size(0)
+Blob::Blob(ScriptExecutionContext* scriptExecutionContext, const PassRefPtr<BlobItem>& item)
+    : m_scriptExecutionContext(scriptExecutionContext)
+    , m_size(0)
 {
+    m_scriptExecutionContext->addBlob(this);
     m_items.append(item);
 }
 
 // FIXME: To be removed when we switch to using BlobData.
-Blob::Blob(ScriptExecutionContext*, const String& path)
-    : m_size(0)
+Blob::Blob(ScriptExecutionContext* scriptExecutionContext, const String& path)
+    : m_scriptExecutionContext(scriptExecutionContext)
+    , m_size(0)
 {
+    m_scriptExecutionContext->addBlob(this);
     // Note: this doesn't initialize the type unlike File(path).
     m_items.append(FileBlobItem::create(path));
 }
 
 Blob::Blob(ScriptExecutionContext* scriptExecutionContext, PassOwnPtr<BlobData> blobData, long long size)
-    : m_type(blobData->contentType())
+    : m_scriptExecutionContext(scriptExecutionContext)
+    , m_type(blobData->contentType())
     , m_size(size)
 {
     ASSERT(blobData.get() && !blobData->items().isEmpty());
 
+    m_scriptExecutionContext->addBlob(this);
+
     // Create a new internal URL and register it with the provided blob data.
     m_url = BlobURL::createURL(scriptExecutionContext);
-    // FIXME: implement thread-safe proxy to make it work with workers.
-    BlobRegistry::instance().registerBlobURL(m_url, blobData);
+    ThreadableBlobRegistry::registerBlobURL(scriptExecutionContext, m_url, blobData);
 }
 
 Blob::Blob(ScriptExecutionContext* scriptExecutionContext, const KURL& srcURL, const String& type, long long size)
-    : m_type(type)
+    : m_scriptExecutionContext(scriptExecutionContext)
+    , m_type(type)
     , m_size(size)
 {
+    m_scriptExecutionContext->addBlob(this);
+
     // FIXME: To be removed when we switch to using BlobData.
     if (srcURL.isEmpty())
         return;
 
     // Create a new internal URL and register it with the same blob data as the source URL.
     m_url = BlobURL::createURL(scriptExecutionContext);
-    // FIXME: implement thread-safe proxy to make it work with workers.
-    BlobRegistry::instance().registerBlobURL(m_url, srcURL);
+    ThreadableBlobRegistry::registerBlobURL(scriptExecutionContext, m_url, srcURL);
 }
 
 Blob::~Blob()
 {
     // The internal URL is only used to refer to the Blob object. So we need to unregister the URL when the object is GC-ed.
-    // FIXME: implement thread-safe proxy to make it work with workers.
-    BlobRegistry::instance().unregisterBlobURL(m_url);
+    if (m_scriptExecutionContext) {
+        m_scriptExecutionContext->removeBlob(this);
+        ThreadableBlobRegistry::unregisterBlobURL(m_scriptExecutionContext, m_url);
+    }
+}
+
+void Blob::contextDestroyed()
+{
+    ASSERT(m_scriptExecutionContext);
+
+    // Unregister the internal URL before the context is gone.
+    ThreadableBlobRegistry::unregisterBlobURL(m_scriptExecutionContext, m_url);
+    m_scriptExecutionContext = 0;
 }
 
 unsigned long long Blob::size() const
@@ -141,19 +162,6 @@ PassRefPtr<Blob> Blob::slice(ScriptExecutionContext* scriptExecutionContext, lon
     }
     return Blob::create(scriptExecutionContext, contentType, items);
 }
-
-KURL Blob::createPublicURL(ScriptExecutionContext* scriptExecutionContext) const
-{
-    KURL url = BlobURL::createURL(scriptExecutionContext);
-
-    // FIXME: implement thread-safe proxy to make it work with workers.
-    BlobRegistry::instance().registerBlobURL(url, m_url);
-
-    // Keep track of the new URL in the ScriptExecutionContext so that it will get unregistered when the context is gone.
-    scriptExecutionContext->trackBlobURL(url.string());
-
-    return url;
-}
 #endif // ENABLE(BLOB)
 
 } // namespace WebCore
diff --git a/WebCore/html/Blob.h b/WebCore/html/Blob.h
index a72929c..374a401 100644
--- a/WebCore/html/Blob.h
+++ b/WebCore/html/Blob.h
@@ -60,6 +60,8 @@ public:
 
     virtual ~Blob();
 
+    void contextDestroyed();
+
     const KURL& url() const { return m_url; }
     unsigned long long size() const;
     const String& type() const { return m_type; }
@@ -73,8 +75,6 @@ public:
 
 #if ENABLE(BLOB)
     PassRefPtr<Blob> slice(ScriptExecutionContext*, long long start, long long length, const String& contentType = String()) const;
-
-    KURL createPublicURL(ScriptExecutionContext*) const;
 #endif
 
 protected:
@@ -95,6 +95,7 @@ protected:
     // It is only used by FileReader to read the blob data via loading from the blob URL resource.
     KURL m_url;
 
+    ScriptExecutionContext* m_scriptExecutionContext;
     String m_type;
     long long m_size;
 };
diff --git a/WebCore/html/BlobRegistryImpl.cpp b/WebCore/html/BlobRegistryImpl.cpp
index 74e5175..bbbb8f0 100644
--- a/WebCore/html/BlobRegistryImpl.cpp
+++ b/WebCore/html/BlobRegistryImpl.cpp
@@ -40,6 +40,7 @@
 #include "ResourceLoader.h"
 #include "ResourceRequest.h"
 #include "ResourceResponse.h"
+#include <wtf/MainThread.h>
 #include <wtf/StdLibExtras.h>
 
 namespace WebCore {
@@ -73,6 +74,7 @@ bool BlobRegistryImpl::loadResourceSynchronously(const ResourceRequest& request,
 
 BlobRegistry& BlobRegistry::instance()
 {
+    ASSERT(isMainThread());
     DEFINE_STATIC_LOCAL(BlobRegistryImpl, instance, ());
     return instance;
 }
@@ -118,6 +120,8 @@ void BlobRegistryImpl::appendStorageItems(BlobStorageData* blobStorageData, cons
 
 void BlobRegistryImpl::registerBlobURL(const KURL& url, PassOwnPtr<BlobData> blobData)
 {
+    ASSERT(isMainThread());
+
     RefPtr<BlobStorageData> blobStorageData = BlobStorageData::create();
     blobStorageData->setContentType(blobData->contentType());
     blobStorageData->setContentDisposition(blobData->contentDisposition());
@@ -143,6 +147,8 @@ void BlobRegistryImpl::registerBlobURL(const KURL& url, PassOwnPtr<BlobData> blo
 
 void BlobRegistryImpl::registerBlobURL(const KURL& url, const KURL& srcURL)
 {
+    ASSERT(isMainThread());
+
     RefPtr<BlobStorageData> src = m_blobs.get(srcURL.string());
     ASSERT(src);
     if (!src)
@@ -158,11 +164,13 @@ void BlobRegistryImpl::registerBlobURL(const KURL& url, const KURL& srcURL)
 
 void BlobRegistryImpl::unregisterBlobURL(const KURL& url)
 {
+    ASSERT(isMainThread());
     m_blobs.remove(url.string());
 }
 
 PassRefPtr<BlobStorageData> BlobRegistryImpl::getBlobDataFromURL(const KURL& url) const
 {
+    ASSERT(isMainThread());
     return m_blobs.get(url.string());
 }
 
diff --git a/WebCore/html/ThreadableBlobRegistry.cpp b/WebCore/html/ThreadableBlobRegistry.cpp
new file mode 100644
index 0000000..fde70fb
--- /dev/null
+++ b/WebCore/html/ThreadableBlobRegistry.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2010 Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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 "ThreadableBlobRegistry.h"
+
+#include "BlobData.h"
+#include "BlobRegistry.h"
+#include "CrossThreadTask.h"
+#include "ScriptExecutionContext.h"
+#include "WorkerContext.h"
+#include "WorkerLoaderProxy.h"
+#include "WorkerThread.h"
+
+namespace WebCore {
+
+static void postTaskToMainThread(ScriptExecutionContext* scriptExecutionContext, PassOwnPtr<ScriptExecutionContext::Task> task)
+{
+    ASSERT(scriptExecutionContext->isWorkerContext());
+    WorkerLoaderProxy& proxy = static_cast<WorkerContext*>(scriptExecutionContext)->thread()->workerLoaderProxy();
+    proxy.postTaskToLoader(task);
+}
+
+static void registerBlobURLTask(ScriptExecutionContext*, const KURL& url, PassOwnPtr<BlobData> blobData)
+{
+    BlobRegistry::instance().registerBlobURL(url, blobData);
+}
+
+void ThreadableBlobRegistry::registerBlobURL(ScriptExecutionContext* scriptExecutionContext, const KURL& url, PassOwnPtr<BlobData> blobData)
+{
+    if (scriptExecutionContext->isWorkerContext())
+        postTaskToMainThread(scriptExecutionContext, createCallbackTask(&registerBlobURLTask, url, blobData));
+    else
+        registerBlobURLTask(scriptExecutionContext, url, blobData);
+}
+
+static void registerBlobURLFromTask(ScriptExecutionContext*, const KURL& url, const KURL& srcURL)
+{
+    BlobRegistry::instance().registerBlobURL(url, srcURL);
+}
+
+void ThreadableBlobRegistry::registerBlobURL(ScriptExecutionContext* scriptExecutionContext, const KURL& url, const KURL& srcURL)
+{
+    if (scriptExecutionContext->isWorkerContext())
+        postTaskToMainThread(scriptExecutionContext, createCallbackTask(&registerBlobURLFromTask, url, srcURL));
+    else
+        registerBlobURLFromTask(scriptExecutionContext, url, srcURL);
+}
+
+static void unregisterBlobURLTask(ScriptExecutionContext*, const KURL& url)
+{
+    BlobRegistry::instance().unregisterBlobURL(url);
+}
+
+void ThreadableBlobRegistry::unregisterBlobURL(ScriptExecutionContext* scriptExecutionContext, const KURL& url)
+{
+    if (scriptExecutionContext->isWorkerContext())
+        postTaskToMainThread(scriptExecutionContext, createCallbackTask(&unregisterBlobURLTask, url));
+    else
+        unregisterBlobURLTask(scriptExecutionContext, url);
+}
+
+} // namespace WebCore
diff --git a/WebCore/html/ThreadableBlobRegistry.h b/WebCore/html/ThreadableBlobRegistry.h
new file mode 100644
index 0000000..7dce6bb
--- /dev/null
+++ b/WebCore/html/ThreadableBlobRegistry.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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.
+ */
+
+#ifndef ThreadableBlobRegistry_h
+#define ThreadableBlobRegistry_h
+
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+class BlobData;
+class KURL;
+class ScriptExecutionContext;
+
+class ThreadableBlobRegistry {
+public:
+    static void registerBlobURL(ScriptExecutionContext*, const KURL&, PassOwnPtr<BlobData>);
+    static void registerBlobURL(ScriptExecutionContext*, const KURL&, const KURL& srcURL);
+    static void unregisterBlobURL(ScriptExecutionContext*, const KURL&);
+};
+
+} // namespace WebCore
+
+#endif // ThreadableBlobRegistry_h

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list