Source/WebCore: Migrate createObjectURL & revokeObjectURL to static (Class) methods.
authorarv@chromium.org <arv@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jan 2012 08:00:11 +0000 (08:00 +0000)
committerarv@chromium.org <arv@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jan 2012 08:00:11 +0000 (08:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=74386

Reviewed by Adam Barth.

Test: fast/dom/DOMURL/check-instanceof-domurl-functions.html
Already Existing -
    fast/files/revoke-blob-url.html
    fast/dom/window-domurl-crash.html
    fast/files/apply-blob-url-to-img.html
    fast/files/create-blob-url-crash.html
    fast/files/workers/inline-worker-via-blob-url.html

* html/DOMURL.cpp: Added HashMap for local static objects.
(WebCore::PublicURLManager::PublicURLManager):
(WebCore::PublicURLManager::contextDestroyed):
(WebCore::PublicURLManager::blobURLs):
(WebCore::PublicURLManager::streamURLs):
(WebCore::publicURLManagerMap):
(WebCore::publicURLManager):
(WebCore::publicBlobURLs):
(WebCore::publicStreamURLs):
(WebCore::DOMURL::createObjectURL): Changed to static.
(WebCore::DOMURL::revokeObjectURL): ditto.
* html/DOMURL.h:
(WebCore::DOMURL::create):
(WebCore::DOMURL::~DOMURL):
(WebCore::DOMURL::DOMURL):
* html/DOMURL.idl:
* page/DOMWindow.cpp: Removed object initialization for DOMURL.
* page/DOMWindow.h: ditto.
* page/DOMWindow.idl: ditto.
* workers/WorkerContext.cpp: ditto.
* workers/WorkerContext.h: ditto.
* workers/WorkerContext.idl: ditto.

LayoutTests: Migrate createObjectURL & revokeObjectURL to static (Class) methods
https://bugs.webkit.org/show_bug.cgi?id=74386

Reviewed by Adam Barth.

Added test to check if createObjectURL & revokeObjectURL are static functions.

* fast/dom/DOMURL: Added.
* fast/dom/DOMURL/check-instanceof-domurl-functions-expected.txt: Added.
* fast/dom/DOMURL/check-instanceof-domurl-functions.html: Added.

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/DOMURL/check-instanceof-domurl-functions-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/DOMURL/check-instanceof-domurl-functions.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/DOMURL.cpp
Source/WebCore/html/DOMURL.h
Source/WebCore/html/DOMURL.idl
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/DOMWindow.idl
Source/WebCore/workers/WorkerContext.cpp
Source/WebCore/workers/WorkerContext.h
Source/WebCore/workers/WorkerContext.idl

index 14a0e10..8903913 100644 (file)
@@ -1,3 +1,16 @@
+2012-01-19  Kaustubh Atrawalkar  <kaustubh@motorola.com>
+
+        Migrate createObjectURL & revokeObjectURL to static (Class) methods
+        https://bugs.webkit.org/show_bug.cgi?id=74386
+
+        Reviewed by Adam Barth.
+
+        Added test to check if createObjectURL & revokeObjectURL are static functions.
+
+        * fast/dom/DOMURL: Added.
+        * fast/dom/DOMURL/check-instanceof-domurl-functions-expected.txt: Added.
+        * fast/dom/DOMURL/check-instanceof-domurl-functions.html: Added.
+
 2012-01-20  Alexandru Chiculita  <achicu@adobe.com>
 
         CSS Shaders: Add a Settings flag to enable/disable CSS Shaders at runtime
diff --git a/LayoutTests/fast/dom/DOMURL/check-instanceof-domurl-functions-expected.txt b/LayoutTests/fast/dom/DOMURL/check-instanceof-domurl-functions-expected.txt
new file mode 100644 (file)
index 0000000..1d8c3b2
--- /dev/null
@@ -0,0 +1,15 @@
+Test instanceof functions and properties of webkitURL.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS 'createObjectURL' in webkitURL is true
+PASS 'revokeObjectURL' in webkitURL is true
+PASS url.createObjectURL is undefined.
+PASS url.revokeObjectURL is undefined.
+PASS window.webkitURL.createObjectURL is defined.
+PASS window.webkitURL.revokeObjectURL is defined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/DOMURL/check-instanceof-domurl-functions.html b/LayoutTests/fast/dom/DOMURL/check-instanceof-domurl-functions.html
new file mode 100644 (file)
index 0000000..3aa5c4d
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+description("Test instanceof functions and properties of webkitURL.");
+
+var url = new webkitURL;
+
+shouldBeTrue("'createObjectURL' in webkitURL");
+shouldBeTrue("'revokeObjectURL' in webkitURL");
+
+shouldBeUndefined("url.createObjectURL");
+shouldBeUndefined("url.revokeObjectURL");
+
+shouldBeDefined("window.webkitURL.createObjectURL");
+shouldBeDefined("window.webkitURL.revokeObjectURL");
+
+
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
index e91f117..9f37f16 100755 (executable)
@@ -1,3 +1,41 @@
+2012-01-19  Kaustubh Atrawalkar  <kaustubh@motorola.com> & Erik Arvidsson  <arv@chromium.org>
+
+        Migrate createObjectURL & revokeObjectURL to static (Class) methods.
+        https://bugs.webkit.org/show_bug.cgi?id=74386
+
+        Reviewed by Adam Barth.
+
+        Test: fast/dom/DOMURL/check-instanceof-domurl-functions.html
+        Already Existing -
+            fast/files/revoke-blob-url.html
+            fast/dom/window-domurl-crash.html
+            fast/files/apply-blob-url-to-img.html
+            fast/files/create-blob-url-crash.html
+            fast/files/workers/inline-worker-via-blob-url.html
+
+        * html/DOMURL.cpp: Added HashMap for local static objects.
+        (WebCore::PublicURLManager::PublicURLManager):
+        (WebCore::PublicURLManager::contextDestroyed):
+        (WebCore::PublicURLManager::blobURLs):
+        (WebCore::PublicURLManager::streamURLs):
+        (WebCore::publicURLManagerMap):
+        (WebCore::publicURLManager):
+        (WebCore::publicBlobURLs):
+        (WebCore::publicStreamURLs):
+        (WebCore::DOMURL::createObjectURL): Changed to static.
+        (WebCore::DOMURL::revokeObjectURL): ditto.
+        * html/DOMURL.h:
+        (WebCore::DOMURL::create):
+        (WebCore::DOMURL::~DOMURL):
+        (WebCore::DOMURL::DOMURL):
+        * html/DOMURL.idl:
+        * page/DOMWindow.cpp: Removed object initialization for DOMURL.
+        * page/DOMWindow.h: ditto.
+        * page/DOMWindow.idl: ditto.
+        * workers/WorkerContext.cpp: ditto.
+        * workers/WorkerContext.h: ditto.
+        * workers/WorkerContext.idl: ditto.
+
 2012-01-20  Alexandru Chiculita  <achicu@adobe.com>
 
         CSS Shaders: Add a Settings flag to enable/disable CSS Shaders at runtime
index e42060d..3b72ac9 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011 Motorola Mobility Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  */
 
 #include "config.h"
-
-#if ENABLE(BLOB)
-
 #include "DOMURL.h"
 
+#include "ActiveDOMObject.h"
+#include "KURL.h"
+#include "SecurityOrigin.h"
+#include <wtf/MainThread.h>
+
+#if ENABLE(BLOB)
 #include "Blob.h"
 #include "BlobURL.h"
-#include "KURL.h"
 #include "ScriptExecutionContext.h"
 #include "ThreadableBlobRegistry.h"
-#include <wtf/MainThread.h>
-
+#include <wtf/PassOwnPtr.h>
 #if ENABLE(MEDIA_STREAM)
 #include "MediaStream.h"
 #include "MediaStreamRegistry.h"
 #endif
+#endif
 
 namespace WebCore {
 
-DOMURL::DOMURL(ScriptExecutionContext* scriptExecutionContext)
-    : ContextDestructionObserver(scriptExecutionContext)
+#if ENABLE(BLOB)
+class PublicURLManager;
+typedef HashMap<ScriptExecutionContext*, OwnPtr<PublicURLManager> > PublicURLManagerMap;
+static PublicURLManagerMap& publicURLManagerMap();
+
+class PublicURLManager : public ContextDestructionObserver {
+public:
+    explicit PublicURLManager(ScriptExecutionContext* scriptExecutionContext)
+        : ContextDestructionObserver(scriptExecutionContext) { }
+
+    virtual void contextDestroyed()
+    {
+        HashSet<String>::iterator blobURLsEnd = m_blobURLs.end();
+        for (HashSet<String>::iterator iter = m_blobURLs.begin(); iter != blobURLsEnd; ++iter)
+            ThreadableBlobRegistry::unregisterBlobURL(KURL(ParsedURLString, *iter));
+
+#if ENABLE(MEDIA_STREAM)
+        HashSet<String>::iterator streamURLsEnd = m_streamURLs.end();
+        for (HashSet<String>::iterator iter = m_streamURLs.begin(); iter != streamURLsEnd; ++iter)
+            MediaStreamRegistry::registry().unregisterMediaStreamURL(KURL(ParsedURLString, *iter));
+#endif
+
+        ScriptExecutionContext* context = scriptExecutionContext();
+        ContextDestructionObserver::contextDestroyed();
+        publicURLManagerMap().remove(context);
+    }
+
+    HashSet<String>& blobURLs() { return m_blobURLs; }
+#if ENABLE(MEDIA_STREAM)
+    HashSet<String>& streamURLs() { return m_streamURLs; }
+#endif
+
+private:
+    HashSet<String> m_blobURLs;
+#if ENABLE(MEDIA_STREAM)
+    HashSet<String> m_streamURLs;
+#endif
+};
+
+static PublicURLManagerMap& publicURLManagerMap()
 {
+    DEFINE_STATIC_LOCAL(PublicURLManagerMap, staticPublicURLManagers, ());
+    return staticPublicURLManagers;
 }
 
-DOMURL::~DOMURL()
+static PublicURLManager& publicURLManager(ScriptExecutionContext* scriptExecutionContext)
 {
+    PublicURLManagerMap& map = publicURLManagerMap();
+    OwnPtr<PublicURLManager>& manager = map.add(scriptExecutionContext, nullptr).first->second;
+    if (!manager)
+        manager = adoptPtr(new PublicURLManager(scriptExecutionContext));
+    return *manager;
 }
 
-void DOMURL::contextDestroyed()
+static HashSet<String>& publicBlobURLs(ScriptExecutionContext* scriptExecutionContext)
 {
-    ContextDestructionObserver::contextDestroyed();
-
-    HashSet<String>::iterator publicBlobURLsEnd = m_publicBlobURLs.end();
-    for (HashSet<String>::iterator iter = m_publicBlobURLs.begin(); iter != publicBlobURLsEnd; ++iter)
-        ThreadableBlobRegistry::unregisterBlobURL(KURL(ParsedURLString, *iter));
+    return publicURLManager(scriptExecutionContext).blobURLs();
+}
 
 #if ENABLE(MEDIA_STREAM)
-    HashSet<String>::iterator publicStreamURLsEnd = m_publicStreamURLs.end();
-    for (HashSet<String>::iterator iter = m_publicStreamURLs.begin(); iter != publicStreamURLsEnd; ++iter)
-        MediaStreamRegistry::registry().unregisterMediaStreamURL(KURL(ParsedURLString, *iter));
-#endif
+static HashSet<String>& publicStreamURLs(ScriptExecutionContext* scriptExecutionContext)
+{
+    return publicURLManager(scriptExecutionContext).streamURLs();
 }
 
-#if ENABLE(MEDIA_STREAM)
-String DOMURL::createObjectURL(MediaStream* stream)
+String DOMURL::createObjectURL(ScriptExecutionContext* scriptExecutionContext, MediaStream* stream)
 {
-    if (!m_scriptExecutionContext || !stream)
+    if (!scriptExecutionContext || !stream)
         return String();
 
-    KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext()->securityOrigin());
+    KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext->securityOrigin());
     if (publicURL.isEmpty())
         return String();
 
@@ -81,50 +124,51 @@ String DOMURL::createObjectURL(MediaStream* stream)
     ASSERT(isMainThread());
 
     MediaStreamRegistry::registry().registerMediaStreamURL(publicURL, stream);
-    m_publicStreamURLs.add(publicURL.string());
+    publicStreamURLs(scriptExecutionContext).add(publicURL.string());
 
     return publicURL.string();
 }
 #endif
 
-String DOMURL::createObjectURL(Blob* blob)
+String DOMURL::createObjectURL(ScriptExecutionContext* scriptExecutionContext, Blob* blob)
 {
-    if (!m_scriptExecutionContext || !blob)
+    if (!scriptExecutionContext || !blob)
         return String();
 
-    KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext()->securityOrigin());
+    KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext->securityOrigin());
     if (publicURL.isEmpty())
         return String();
 
     ThreadableBlobRegistry::registerBlobURL(publicURL, blob->url());
-    m_publicBlobURLs.add(publicURL.string());
+    publicBlobURLs(scriptExecutionContext).add(publicURL.string());
 
     return publicURL.string();
 }
 
-void DOMURL::revokeObjectURL(const String& urlString)
+void DOMURL::revokeObjectURL(ScriptExecutionContext* scriptExecutionContext, const String& urlString)
 {
-    if (!m_scriptExecutionContext)
+    if (!scriptExecutionContext)
         return;
 
     KURL url(KURL(), urlString);
 
-    if (m_publicBlobURLs.contains(url.string())) {
+    HashSet<String>& blobURLs = publicBlobURLs(scriptExecutionContext);
+    if (blobURLs.contains(url.string())) {
         ThreadableBlobRegistry::unregisterBlobURL(url);
-        m_publicBlobURLs.remove(url.string());
+        blobURLs.remove(url.string());
     }
-
 #if ENABLE(MEDIA_STREAM)
-    if (m_publicStreamURLs.contains(url.string())) {
+    HashSet<String>& streamURLs = publicStreamURLs(scriptExecutionContext);
+    if (streamURLs.contains(url.string())) {
         // FIXME: make sure of this assertion below. Raise a spec question if required.
         // Since WebWorkers cannot obtain Stream objects, we should be on the main thread.
         ASSERT(isMainThread());
         MediaStreamRegistry::registry().unregisterMediaStreamURL(url);
-        m_publicStreamURLs.remove(url.string());
+        streamURLs.remove(url.string());
     }
 #endif
 }
+#endif // ENABLE(BLOB)
 
 } // namespace WebCore
 
-#endif // ENABLE(BLOB)
index d02fe88..bd4fe8b 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011 Motorola Mobility Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #ifndef DOMURL_h
 #define DOMURL_h
 
-#if ENABLE(BLOB)
-
-#include "ActiveDOMObject.h"
+#include "KURL.h"
 #include "PlatformString.h"
-#include <wtf/HashSet.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 
@@ -40,30 +38,22 @@ class Blob;
 class MediaStream;
 class ScriptExecutionContext;
 
-class DOMURL : public RefCounted<DOMURL>, public ContextDestructionObserver {
-public:
-    static PassRefPtr<DOMURL> create(ScriptExecutionContext* scriptExecutionContext) { return adoptRef(new DOMURL(scriptExecutionContext)); }
-    ~DOMURL();
-
-#if ENABLE(MEDIA_STREAM)
-    String createObjectURL(MediaStream*);
-#endif
-    String createObjectURL(Blob*);
-    void revokeObjectURL(const String&);
+class DOMURL : public RefCounted<DOMURL> {
 
-private:
-    explicit DOMURL(ScriptExecutionContext*);
+public:
+    static PassRefPtr<DOMURL> create() { return adoptRef(new DOMURL); }
 
-    virtual void contextDestroyed();
+#if ENABLE(BLOB)
+    static void contextDestroyed(ScriptExecutionContext*);
 
-    HashSet<String> m_publicBlobURLs;
+    static String createObjectURL(ScriptExecutionContext*, Blob*);
+    static void revokeObjectURL(ScriptExecutionContext*, const String&);
 #if ENABLE(MEDIA_STREAM)
-    HashSet<String> m_publicStreamURLs;
+    static String createObjectURL(ScriptExecutionContext*, MediaStream*);
+#endif
 #endif
 };
 
 } // namespace WebCore
 
-#endif // ENABLE(BLOB)
-
 #endif // DOMURL_h
index d6d5579..d0acad6 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011 Motorola Mobility Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 module html {
     interface [
         Conditional=BLOB,
-        OmitConstructor,
         GenerateNativeConverter,
         GenerateToJS,
-        NoStaticTables
+        Constructor
     ] DOMURL {
 #if defined(ENABLE_MEDIA_STREAM) && ENABLE_MEDIA_STREAM
-        [ConvertNullStringTo=Undefined] DOMString createObjectURL(in MediaStream stream);
+        static [ConvertNullStringTo=Undefined,CallWith=ScriptExecutionContext] DOMString createObjectURL(in MediaStream stream);
 #endif
-        [ConvertNullStringTo=Undefined] DOMString createObjectURL(in Blob blob);
-        void revokeObjectURL(in DOMString url);
+        static [ConvertNullStringTo=Undefined,CallWith=ScriptExecutionContext] DOMString createObjectURL(in Blob blob);
+        static [CallWith=ScriptExecutionContext] void revokeObjectURL(in DOMString url);
     };
 }
index 1ab987b..e7a2749 100644 (file)
@@ -1892,15 +1892,6 @@ void DOMWindow::showModalDialog(const String& urlString, const String& dialogFea
     dialogFrame->page()->chrome()->runModal();
 }
 
-#if ENABLE(BLOB)
-DOMURL* DOMWindow::webkitURL() const
-{
-    if (!m_domURL && isCurrentlyDisplayedInFrame())
-        m_domURL = DOMURL::create(this->scriptExecutionContext());
-    return m_domURL.get();
-}
-#endif
-
 #if ENABLE(QUOTA)
 StorageInfo* DOMWindow::webkitStorageInfo() const
 {
index d10bc53..60566e1 100644 (file)
@@ -351,10 +351,6 @@ namespace WebCore {
         using RefCounted<DOMWindow>::ref;
         using RefCounted<DOMWindow>::deref;
 
-#if ENABLE(BLOB)
-        DOMURL* webkitURL() const;
-#endif
-
 #if ENABLE(DEVICE_ORIENTATION)
         DEFINE_ATTRIBUTE_EVENT_LISTENER(devicemotion);
         DEFINE_ATTRIBUTE_EVENT_LISTENER(deviceorientation);
index 8e9e32e..e94885a 100644 (file)
@@ -798,7 +798,7 @@ module window {
 
         attribute [Conditional=BLOB] WebKitBlobBuilderConstructor WebKitBlobBuilder;
 
-        readonly attribute [Conditional=BLOB] DOMURL webkitURL;
+        attribute [Conditional=BLOB] DOMURLConstructor webkitURL;
 
 #if defined(ENABLE_QUOTA) && ENABLE_QUOTA
         readonly attribute [EnabledAtRuntime=Quota] StorageInfo webkitStorageInfo;
index ed3b784..8b7918e 100644 (file)
@@ -377,15 +377,6 @@ EventTargetData* WorkerContext::ensureEventTargetData()
     return &m_eventTargetData;
 }
 
-#if ENABLE(BLOB)
-DOMURL* WorkerContext::webkitURL() const
-{
-    if (!m_domURL)
-        m_domURL = DOMURL::create(this->scriptExecutionContext());
-    return m_domURL.get();
-}
-#endif
-
 #if ENABLE(FILE_SYSTEM)
 void WorkerContext::webkitRequestFileSystem(int type, long long size, PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
 {
index 5850374..b55f392 100644 (file)
@@ -131,10 +131,6 @@ namespace WebCore {
         virtual bool isContextThread() const;
         virtual bool isJSExecutionForbidden() const;
 
-#if ENABLE(BLOB)
-        DOMURL* webkitURL() const;
-#endif
-
 #if ENABLE(FILE_SYSTEM)
         enum FileSystemType {
             TEMPORARY,
index b947275..55a7b3b 100644 (file)
@@ -101,7 +101,7 @@ module threads {
         attribute FileReaderSyncConstructor FileReaderSync;
 #endif
 
-        readonly attribute [Conditional=BLOB] DOMURL webkitURL;
+        attribute [Conditional=BLOB] DOMURLConstructor webkitURL;
 
 #if defined(ENABLE_FILE_SYSTEM) && ENABLE_FILE_SYSTEM
         const unsigned short TEMPORARY = 0;