Title: [120433] trunk
Revision
120433
Author
[email protected]
Date
2012-06-15 02:57:13 -0700 (Fri, 15 Jun 2012)

Log Message

FileReader is dysfunctional in documents with "null" origin string
https://bugs.webkit.org/show_bug.cgi?id=78648

Reviewed by Adam Barth.

Source/WebCore:

The fix is to keep in-memory map from blob URL to SecurityOrigin for the
unique origin case.

Test: fast/files/file-reader-file-url.html

* fileapi/Blob.cpp:
(WebCore::Blob::Blob):
* fileapi/BlobURL.cpp:
(WebCore::BlobURL::getOrigin): Return the origin string embeded in the blob URL.
(WebCore):
(WebCore::BlobURL::createBlobURL): Remove the check for null origin string since it is handled now.
* fileapi/BlobURL.h:
(BlobURL):
* fileapi/FileReaderLoader.cpp:
(WebCore::FileReaderLoader::start):
* fileapi/ThreadableBlobRegistry.cpp:
(WebCore):
(WebCore::originMap): Thread-specific in-memory map from the blob URL to the origin.
(WebCore::ThreadableBlobRegistry::registerBlobURL): Add the map from the blob URL to the origin.
(WebCore::ThreadableBlobRegistry::unregisterBlobURL): Remove the map for the unregistered blob URL.
(WebCore::ThreadableBlobRegistry::getCachedOrigin): Retrieve the origin associated with the blob URL.
* fileapi/ThreadableBlobRegistry.h:
(WebCore):
(ThreadableBlobRegistry):
* html/DOMURL.cpp:
(WebCore::DOMURL::createObjectURL):
* page/SecurityOrigin.cpp:
(WebCore::getCachedOrigin): Return the cached origin for the blob URL if it exists.
(WebCore):
(WebCore::SecurityOrigin::create): Call getCachedOrigin to get the cached origin first.

LayoutTests:

* fast/files/file-reader-file-url-expected.txt: Added.
* fast/files/file-reader-file-url.html: Added.
* fast/files/resources/file-reader-file-url-iframe.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (120432 => 120433)


--- trunk/LayoutTests/ChangeLog	2012-06-15 09:53:22 UTC (rev 120432)
+++ trunk/LayoutTests/ChangeLog	2012-06-15 09:57:13 UTC (rev 120433)
@@ -1,3 +1,14 @@
+2012-06-15  Jian Li  <[email protected]>
+
+        FileReader is dysfunctional in documents with "null" origin string
+        https://bugs.webkit.org/show_bug.cgi?id=78648
+
+        Reviewed by Adam Barth.
+
+        * fast/files/file-reader-file-url-expected.txt: Added.
+        * fast/files/file-reader-file-url.html: Added.
+        * fast/files/resources/file-reader-file-url-iframe.html: Added.
+
 2012-06-15  Kent Tamura  <[email protected]>
 
         [Chromium] Update TestExpectations

Added: trunk/LayoutTests/fast/files/file-reader-file-url-expected.txt (0 => 120433)


--- trunk/LayoutTests/fast/files/file-reader-file-url-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/files/file-reader-file-url-expected.txt	2012-06-15 09:57:13 UTC (rev 120433)
@@ -0,0 +1,3 @@
+CONSOLE MESSAGE: line 9: Received data: 0123456789
+
+Test that FileReader works under the file URL with file path separation enforced.

Added: trunk/LayoutTests/fast/files/file-reader-file-url.html (0 => 120433)


--- trunk/LayoutTests/fast/files/file-reader-file-url.html	                        (rev 0)
+++ trunk/LayoutTests/fast/files/file-reader-file-url.html	2012-06-15 09:57:13 UTC (rev 120433)
@@ -0,0 +1,17 @@
+<html>
+<head>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.setAllowUniversalAccessFromFileURLs(false);
+    layoutTestController.setAllowFileAccessFromFileURLs(false);
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+</script>
+</head>
+<body>
+<iframe src=""
+<div id="results"></div>
+Test that FileReader works under the file URL with file path separation enforced.
+</body>
+</html>

Added: trunk/LayoutTests/fast/files/resources/file-reader-file-url-iframe.html (0 => 120433)


--- trunk/LayoutTests/fast/files/resources/file-reader-file-url-iframe.html	                        (rev 0)
+++ trunk/LayoutTests/fast/files/resources/file-reader-file-url-iframe.html	2012-06-15 09:57:13 UTC (rev 120433)
@@ -0,0 +1,25 @@
+<html>
+<head>
+<script>
+function runTest()
+{
+    var blob = new Blob(["0123456789"]);
+    var reader = new FileReader();
+    reader._onload_ = function(event) {
+        console.log("Received data: " + event.target.result);
+    }
+    reader._onloadend_ = function() {
+        if (window.layoutTestController)
+            layoutTestController.notifyDone();
+    }
+    reader._onerror_ = function(event) {
+        console.log("Received error event: " + event.target.error.code);
+    };
+    reader.readAsText(blob);
+}
+
+</script>
+</head>
+<body _onload_="runTest()">
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (120432 => 120433)


--- trunk/Source/WebCore/ChangeLog	2012-06-15 09:53:22 UTC (rev 120432)
+++ trunk/Source/WebCore/ChangeLog	2012-06-15 09:57:13 UTC (rev 120433)
@@ -1,3 +1,41 @@
+2012-06-15  Jian Li  <[email protected]>
+
+        FileReader is dysfunctional in documents with "null" origin string
+        https://bugs.webkit.org/show_bug.cgi?id=78648
+
+        Reviewed by Adam Barth.
+
+        The fix is to keep in-memory map from blob URL to SecurityOrigin for the
+        unique origin case.
+
+        Test: fast/files/file-reader-file-url.html
+
+        * fileapi/Blob.cpp:
+        (WebCore::Blob::Blob):
+        * fileapi/BlobURL.cpp:
+        (WebCore::BlobURL::getOrigin): Return the origin string embeded in the blob URL.
+        (WebCore):
+        (WebCore::BlobURL::createBlobURL): Remove the check for null origin string since it is handled now.
+        * fileapi/BlobURL.h:
+        (BlobURL):
+        * fileapi/FileReaderLoader.cpp:
+        (WebCore::FileReaderLoader::start):
+        * fileapi/ThreadableBlobRegistry.cpp:
+        (WebCore):
+        (WebCore::originMap): Thread-specific in-memory map from the blob URL to the origin.
+        (WebCore::ThreadableBlobRegistry::registerBlobURL): Add the map from the blob URL to the origin.
+        (WebCore::ThreadableBlobRegistry::unregisterBlobURL): Remove the map for the unregistered blob URL.
+        (WebCore::ThreadableBlobRegistry::getCachedOrigin): Retrieve the origin associated with the blob URL.
+        * fileapi/ThreadableBlobRegistry.h:
+        (WebCore):
+        (ThreadableBlobRegistry):
+        * html/DOMURL.cpp:
+        (WebCore::DOMURL::createObjectURL):
+        * page/SecurityOrigin.cpp:
+        (WebCore::getCachedOrigin): Return the cached origin for the blob URL if it exists.
+        (WebCore):
+        (WebCore::SecurityOrigin::create): Call getCachedOrigin to get the cached origin first.
+
 2012-06-15  Yoshifumi Inoue  <[email protected]>
 
         [Forms] Move search field related code to RenderSearchField from RenderTextControlSingleLine

Modified: trunk/Source/WebCore/fileapi/Blob.cpp (120432 => 120433)


--- trunk/Source/WebCore/fileapi/Blob.cpp	2012-06-15 09:53:22 UTC (rev 120432)
+++ trunk/Source/WebCore/fileapi/Blob.cpp	2012-06-15 09:57:13 UTC (rev 120433)
@@ -77,7 +77,7 @@
 {
     // Create a new internal URL and register it with the same blob data as the source URL.
     m_internalURL = BlobURL::createInternalURL();
-    ThreadableBlobRegistry::registerBlobURL(m_internalURL, srcURL);
+    ThreadableBlobRegistry::registerBlobURL(0, m_internalURL, srcURL);
 }
 
 Blob::~Blob()

Modified: trunk/Source/WebCore/fileapi/BlobURL.cpp (120432 => 120433)


--- trunk/Source/WebCore/fileapi/BlobURL.cpp	2012-06-15 09:53:22 UTC (rev 120432)
+++ trunk/Source/WebCore/fileapi/BlobURL.cpp	2012-06-15 09:57:13 UTC (rev 120433)
@@ -52,6 +52,15 @@
     return createBlobURL("blobinternal://");
 }
 
+String BlobURL::getOrigin(const KURL& url)
+{
+    ASSERT(url.protocolIs(kBlobProtocol));
+
+    unsigned startIndex = url.pathStart();
+    unsigned endIndex = url.pathAfterLastSlash();
+    return url.string().substring(startIndex, endIndex - startIndex - 1);
+}
+
 String BlobURL::getIdentifier(const KURL& url)
 {
     ASSERT(url.protocolIs(kBlobProtocol));
@@ -63,8 +72,6 @@
 KURL BlobURL::createBlobURL(const String& originString)
 {
     ASSERT(!originString.isEmpty());
-    if (originString == "null")
-        return KURL();
     String urlString = kBlobProtocol;
     urlString += ":";
     urlString += encodeWithURLEscapeSequences(originString);

Modified: trunk/Source/WebCore/fileapi/BlobURL.h (120432 => 120433)


--- trunk/Source/WebCore/fileapi/BlobURL.h	2012-06-15 09:53:22 UTC (rev 120432)
+++ trunk/Source/WebCore/fileapi/BlobURL.h	2012-06-15 09:57:13 UTC (rev 120433)
@@ -50,6 +50,7 @@
 public:
     static KURL createPublicURL(SecurityOrigin*);
     static KURL createInternalURL();
+    static String getOrigin(const KURL&);
     static String getIdentifier(const KURL&);
     static const char* blobProtocol() { return kBlobProtocol; }
 

Modified: trunk/Source/WebCore/fileapi/FileReaderLoader.cpp (120432 => 120433)


--- trunk/Source/WebCore/fileapi/FileReaderLoader.cpp	2012-06-15 09:53:22 UTC (rev 120432)
+++ trunk/Source/WebCore/fileapi/FileReaderLoader.cpp	2012-06-15 09:57:13 UTC (rev 120433)
@@ -80,7 +80,7 @@
         failed(FileError::SECURITY_ERR);
         return;
     }
-    ThreadableBlobRegistry::registerBlobURL(m_urlForReading, blob->url());
+    ThreadableBlobRegistry::registerBlobURL(scriptExecutionContext->securityOrigin(), m_urlForReading, blob->url());
 
     // Construct and load the request.
     ResourceRequest request(m_urlForReading);

Modified: trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp (120432 => 120433)


--- trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp	2012-06-15 09:53:22 UTC (rev 120432)
+++ trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp	2012-06-15 09:57:13 UTC (rev 120433)
@@ -34,8 +34,16 @@
 
 #include "BlobData.h"
 #include "BlobRegistry.h"
+#include "BlobURL.h"
+#include "SecurityOrigin.h"
+#include <wtf/HashMap.h>
 #include <wtf/MainThread.h>
+#include <wtf/RefPtr.h>
+#include <wtf/ThreadSpecific.h>
+#include <wtf/text/StringHash.h>
 
+using WTF::ThreadSpecific;
+
 namespace WebCore {
 
 struct BlobRegistryContext {
@@ -64,6 +72,13 @@
 
 #if ENABLE(BLOB)
 
+typedef HashMap<String, RefPtr<SecurityOrigin> > BlobUrlOriginMap;
+static ThreadSpecific<BlobUrlOriginMap>& originMap()
+{
+    AtomicallyInitializedStatic(ThreadSpecific<BlobUrlOriginMap>*, map = new ThreadSpecific<BlobUrlOriginMap>);
+    return *map;
+}
+
 static void registerBlobURLTask(void* context)
 {
     OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobRegistryContext*>(context));
@@ -86,8 +101,12 @@
     blobRegistry().registerBlobURL(blobRegistryContext->url, blobRegistryContext->srcURL);
 }
 
-void ThreadableBlobRegistry::registerBlobURL(const KURL& url, const KURL& srcURL)
+void ThreadableBlobRegistry::registerBlobURL(SecurityOrigin* origin, const KURL& url, const KURL& srcURL)
 {
+    // If the blob URL contains null origin, as in the context with unique security origin or file URL, save the mapping between url and origin so that the origin can be retrived when doing security origin check.
+    if (origin && BlobURL::getOrigin(url) == "null")
+        originMap()->add(url.string(), origin);
+
     if (isMainThread())
         blobRegistry().registerBlobURL(url, srcURL);
     else {
@@ -104,14 +123,20 @@
 
 void ThreadableBlobRegistry::unregisterBlobURL(const KURL& url)
 {
-    if (isMainThread())
+    if (isMainThread()) {
+        originMap()->remove(url.string());
         blobRegistry().unregisterBlobURL(url);
-    else {
+    } else {
         OwnPtr<BlobRegistryContext> context = adoptPtr(new BlobRegistryContext(url));
         callOnMainThread(&unregisterBlobURLTask, context.leakPtr());
     }
 }
 
+PassRefPtr<SecurityOrigin> ThreadableBlobRegistry::getCachedOrigin(const KURL& url)
+{
+    return originMap()->get(url.string());
+}
+
 #else
 
 void ThreadableBlobRegistry::registerBlobURL(const KURL&, PassOwnPtr<BlobData>)
@@ -125,6 +150,12 @@
 void ThreadableBlobRegistry::unregisterBlobURL(const KURL&)
 {
 }
+
+PassRefPtr<SecurityOrigin> ThreadableBlobRegistry::getCachedOrigin(const KURL& url)
+{
+    return 0;
+}
+
 #endif // ENABL(BLOB)
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.h (120432 => 120433)


--- trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.h	2012-06-15 09:53:22 UTC (rev 120432)
+++ trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.h	2012-06-15 09:57:13 UTC (rev 120433)
@@ -32,17 +32,23 @@
 #define ThreadableBlobRegistry_h
 
 #include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
 
 namespace WebCore {
 
 class BlobData;
 class KURL;
+class SecurityOrigin;
 
 class ThreadableBlobRegistry {
 public:
     static void registerBlobURL(const KURL&, PassOwnPtr<BlobData>);
-    static void registerBlobURL(const KURL&, const KURL& srcURL);
+    static void registerBlobURL(SecurityOrigin*, const KURL&, const KURL& srcURL);
     static void unregisterBlobURL(const KURL&);
+
+    // Returns the origin for the given blob URL. This is because we are not able to embed the unique security origin or the origin of file URL
+    // in the blob URL.
+    static PassRefPtr<SecurityOrigin> getCachedOrigin(const KURL&);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/DOMURL.cpp (120432 => 120433)


--- trunk/Source/WebCore/html/DOMURL.cpp	2012-06-15 09:53:22 UTC (rev 120432)
+++ trunk/Source/WebCore/html/DOMURL.cpp	2012-06-15 09:57:13 UTC (rev 120433)
@@ -78,7 +78,7 @@
     if (publicURL.isEmpty())
         return String();
 
-    ThreadableBlobRegistry::registerBlobURL(publicURL, blob->url());
+    ThreadableBlobRegistry::registerBlobURL(scriptExecutionContext->securityOrigin(), publicURL, blob->url());
     scriptExecutionContext->publicURLManager().blobURLs().add(publicURL.string());
 
     return publicURL.string();

Modified: trunk/Source/WebCore/page/SecurityOrigin.cpp (120432 => 120433)


--- trunk/Source/WebCore/page/SecurityOrigin.cpp	2012-06-15 09:53:22 UTC (rev 120432)
+++ trunk/Source/WebCore/page/SecurityOrigin.cpp	2012-06-15 09:57:13 UTC (rev 120433)
@@ -35,6 +35,7 @@
 #include "KURL.h"
 #include "SchemeRegistry.h"
 #include "SecurityPolicy.h"
+#include "ThreadableBlobRegistry.h"
 #include <wtf/MainThread.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/text/StringBuilder.h>
@@ -89,6 +90,15 @@
     return KURL(ParsedURLString, decodeURLEscapeSequences(url.path()));
 }
 
+static PassRefPtr<SecurityOrigin> getCachedOrigin(const KURL& url)
+{
+#if ENABLE(BLOB)
+    if (url.protocolIs("blob"))
+        return ThreadableBlobRegistry::getCachedOrigin(url);
+#endif
+    return 0;
+}
+
 static bool shouldTreatAsUniqueOrigin(const KURL& url)
 {
     if (!url.isValid())
@@ -171,6 +181,10 @@
 
 PassRefPtr<SecurityOrigin> SecurityOrigin::create(const KURL& url)
 {
+    RefPtr<SecurityOrigin> cachedOrigin = getCachedOrigin(url);
+    if (cachedOrigin.get())
+        return cachedOrigin;
+
     if (shouldTreatAsUniqueOrigin(url)) {
         RefPtr<SecurityOrigin> origin = adoptRef(new SecurityOrigin());
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to