⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 120433 in webkit


Ignore:
Timestamp:
Jun 15, 2012, 2:57:13 AM (14 years ago)
Author:
jianli@chromium.org
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.
Location:
trunk
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r120431 r120433  
     12012-06-15  Jian Li  <jianli@chromium.org>
     2
     3        FileReader is dysfunctional in documents with "null" origin string
     4        https://bugs.webkit.org/show_bug.cgi?id=78648
     5
     6        Reviewed by Adam Barth.
     7
     8        * fast/files/file-reader-file-url-expected.txt: Added.
     9        * fast/files/file-reader-file-url.html: Added.
     10        * fast/files/resources/file-reader-file-url-iframe.html: Added.
     11
    1122012-06-15  Kent Tamura  <tkent@chromium.org>
    213
  • trunk/Source/WebCore/ChangeLog

    r120432 r120433  
     12012-06-15  Jian Li  <jianli@chromium.org>
     2
     3        FileReader is dysfunctional in documents with "null" origin string
     4        https://bugs.webkit.org/show_bug.cgi?id=78648
     5
     6        Reviewed by Adam Barth.
     7
     8        The fix is to keep in-memory map from blob URL to SecurityOrigin for the
     9        unique origin case.
     10
     11        Test: fast/files/file-reader-file-url.html
     12
     13        * fileapi/Blob.cpp:
     14        (WebCore::Blob::Blob):
     15        * fileapi/BlobURL.cpp:
     16        (WebCore::BlobURL::getOrigin): Return the origin string embeded in the blob URL.
     17        (WebCore):
     18        (WebCore::BlobURL::createBlobURL): Remove the check for null origin string since it is handled now.
     19        * fileapi/BlobURL.h:
     20        (BlobURL):
     21        * fileapi/FileReaderLoader.cpp:
     22        (WebCore::FileReaderLoader::start):
     23        * fileapi/ThreadableBlobRegistry.cpp:
     24        (WebCore):
     25        (WebCore::originMap): Thread-specific in-memory map from the blob URL to the origin.
     26        (WebCore::ThreadableBlobRegistry::registerBlobURL): Add the map from the blob URL to the origin.
     27        (WebCore::ThreadableBlobRegistry::unregisterBlobURL): Remove the map for the unregistered blob URL.
     28        (WebCore::ThreadableBlobRegistry::getCachedOrigin): Retrieve the origin associated with the blob URL.
     29        * fileapi/ThreadableBlobRegistry.h:
     30        (WebCore):
     31        (ThreadableBlobRegistry):
     32        * html/DOMURL.cpp:
     33        (WebCore::DOMURL::createObjectURL):
     34        * page/SecurityOrigin.cpp:
     35        (WebCore::getCachedOrigin): Return the cached origin for the blob URL if it exists.
     36        (WebCore):
     37        (WebCore::SecurityOrigin::create): Call getCachedOrigin to get the cached origin first.
     38
    1392012-06-15  Yoshifumi Inoue  <yosin@chromium.org>
    240
  • trunk/Source/WebCore/fileapi/Blob.cpp

    r120392 r120433  
    7878    // Create a new internal URL and register it with the same blob data as the source URL.
    7979    m_internalURL = BlobURL::createInternalURL();
    80     ThreadableBlobRegistry::registerBlobURL(m_internalURL, srcURL);
     80    ThreadableBlobRegistry::registerBlobURL(0, m_internalURL, srcURL);
    8181}
    8282
  • trunk/Source/WebCore/fileapi/BlobURL.cpp

    r120392 r120433  
    5353}
    5454
     55String BlobURL::getOrigin(const KURL& url)
     56{
     57    ASSERT(url.protocolIs(kBlobProtocol));
     58
     59    unsigned startIndex = url.pathStart();
     60    unsigned endIndex = url.pathAfterLastSlash();
     61    return url.string().substring(startIndex, endIndex - startIndex - 1);
     62}
     63
    5564String BlobURL::getIdentifier(const KURL& url)
    5665{
     
    6473{
    6574    ASSERT(!originString.isEmpty());
    66     if (originString == "null")
    67         return KURL();
    6875    String urlString = kBlobProtocol;
    6976    urlString += ":";
  • trunk/Source/WebCore/fileapi/BlobURL.h

    r120392 r120433  
    5151    static KURL createPublicURL(SecurityOrigin*);
    5252    static KURL createInternalURL();
     53    static String getOrigin(const KURL&);
    5354    static String getIdentifier(const KURL&);
    5455    static const char* blobProtocol() { return kBlobProtocol; }
  • trunk/Source/WebCore/fileapi/FileReaderLoader.cpp

    r120392 r120433  
    8181        return;
    8282    }
    83     ThreadableBlobRegistry::registerBlobURL(m_urlForReading, blob->url());
     83    ThreadableBlobRegistry::registerBlobURL(scriptExecutionContext->securityOrigin(), m_urlForReading, blob->url());
    8484
    8585    // Construct and load the request.
  • trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp

    r120392 r120433  
    3535#include "BlobData.h"
    3636#include "BlobRegistry.h"
     37#include "BlobURL.h"
     38#include "SecurityOrigin.h"
     39#include <wtf/HashMap.h>
    3740#include <wtf/MainThread.h>
     41#include <wtf/RefPtr.h>
     42#include <wtf/ThreadSpecific.h>
     43#include <wtf/text/StringHash.h>
     44
     45using WTF::ThreadSpecific;
    3846
    3947namespace WebCore {
     
    6573#if ENABLE(BLOB)
    6674
     75typedef HashMap<String, RefPtr<SecurityOrigin> > BlobUrlOriginMap;
     76static ThreadSpecific<BlobUrlOriginMap>& originMap()
     77{
     78    AtomicallyInitializedStatic(ThreadSpecific<BlobUrlOriginMap>*, map = new ThreadSpecific<BlobUrlOriginMap>);
     79    return *map;
     80}
     81
    6782static void registerBlobURLTask(void* context)
    6883{
     
    87102}
    88103
    89 void ThreadableBlobRegistry::registerBlobURL(const KURL& url, const KURL& srcURL)
     104void ThreadableBlobRegistry::registerBlobURL(SecurityOrigin* origin, const KURL& url, const KURL& srcURL)
    90105{
     106    // 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.
     107    if (origin && BlobURL::getOrigin(url) == "null")
     108        originMap()->add(url.string(), origin);
     109
    91110    if (isMainThread())
    92111        blobRegistry().registerBlobURL(url, srcURL);
     
    105124void ThreadableBlobRegistry::unregisterBlobURL(const KURL& url)
    106125{
    107     if (isMainThread())
     126    if (isMainThread()) {
     127        originMap()->remove(url.string());
    108128        blobRegistry().unregisterBlobURL(url);
    109     else {
     129    } else {
    110130        OwnPtr<BlobRegistryContext> context = adoptPtr(new BlobRegistryContext(url));
    111131        callOnMainThread(&unregisterBlobURLTask, context.leakPtr());
    112132    }
     133}
     134
     135PassRefPtr<SecurityOrigin> ThreadableBlobRegistry::getCachedOrigin(const KURL& url)
     136{
     137    return originMap()->get(url.string());
    113138}
    114139
     
    126151{
    127152}
     153
     154PassRefPtr<SecurityOrigin> ThreadableBlobRegistry::getCachedOrigin(const KURL& url)
     155{
     156    return 0;
     157}
     158
    128159#endif // ENABL(BLOB)
    129160
  • trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.h

    r120392 r120433  
    3333
    3434#include <wtf/PassOwnPtr.h>
     35#include <wtf/PassRefPtr.h>
    3536
    3637namespace WebCore {
     
    3839class BlobData;
    3940class KURL;
     41class SecurityOrigin;
    4042
    4143class ThreadableBlobRegistry {
    4244public:
    4345    static void registerBlobURL(const KURL&, PassOwnPtr<BlobData>);
    44     static void registerBlobURL(const KURL&, const KURL& srcURL);
     46    static void registerBlobURL(SecurityOrigin*, const KURL&, const KURL& srcURL);
    4547    static void unregisterBlobURL(const KURL&);
     48
     49    // 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
     50    // in the blob URL.
     51    static PassRefPtr<SecurityOrigin> getCachedOrigin(const KURL&);
    4652};
    4753
  • trunk/Source/WebCore/html/DOMURL.cpp

    r120392 r120433  
    7979        return String();
    8080
    81     ThreadableBlobRegistry::registerBlobURL(publicURL, blob->url());
     81    ThreadableBlobRegistry::registerBlobURL(scriptExecutionContext->securityOrigin(), publicURL, blob->url());
    8282    scriptExecutionContext->publicURLManager().blobURLs().add(publicURL.string());
    8383
  • trunk/Source/WebCore/page/SecurityOrigin.cpp

    r120392 r120433  
    3636#include "SchemeRegistry.h"
    3737#include "SecurityPolicy.h"
     38#include "ThreadableBlobRegistry.h"
    3839#include <wtf/MainThread.h>
    3940#include <wtf/StdLibExtras.h>
     
    8889    // we finish implementing it.
    8990    return KURL(ParsedURLString, decodeURLEscapeSequences(url.path()));
     91}
     92
     93static PassRefPtr<SecurityOrigin> getCachedOrigin(const KURL& url)
     94{
     95#if ENABLE(BLOB)
     96    if (url.protocolIs("blob"))
     97        return ThreadableBlobRegistry::getCachedOrigin(url);
     98#endif
     99    return 0;
    90100}
    91101
     
    172182PassRefPtr<SecurityOrigin> SecurityOrigin::create(const KURL& url)
    173183{
     184    RefPtr<SecurityOrigin> cachedOrigin = getCachedOrigin(url);
     185    if (cachedOrigin.get())
     186        return cachedOrigin;
     187
    174188    if (shouldTreatAsUniqueOrigin(url)) {
    175189        RefPtr<SecurityOrigin> origin = adoptRef(new SecurityOrigin());
Note: See TracChangeset for help on using the changeset viewer.