Changeset 205190 in webkit


Ignore:
Timestamp:
Aug 30, 2016 11:22:15 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[Fetch API] Blob not found URL should result in a network error
https://bugs.webkit.org/show_bug.cgi?id=161381

Patch by Youenn Fablet <youenn@apple.com> on 2016-08-30
Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

  • web-platform-tests/fetch/api/basic/scheme-blob-expected.txt:
  • web-platform-tests/fetch/api/basic/scheme-blob-worker-expected.txt:
  • web-platform-tests/fetch/api/basic/scheme-blob-worker.html:
  • web-platform-tests/fetch/api/basic/scheme-blob.html:
  • web-platform-tests/fetch/api/basic/scheme-blob.js:

(invalidRequestMethods.forEach):

Source/WebCore:

Covered by rebased and updated tests.

Raising a network error if no blob can be found from the URL.
It is no longer notified by a 404 response.

Updated FileReaderLoader to generate the correct exception.

Made some clean-up in the code, in particular adding an enum class for BlobResourceHandle errors.

  • fileapi/FileReaderLoader.cpp:

(WebCore::FileReaderLoader::didFail):
(WebCore::FileReaderLoader::toErrorCode):
(WebCore::FileReaderLoader::httpStatusCodeToErrorCode):

  • fileapi/FileReaderLoader.h:
  • platform/network/BlobResourceHandle.cpp:

(WebCore::BlobResourceHandle::loadResourceSynchronously):
(WebCore::BlobResourceHandle::doStart):
(WebCore::BlobResourceHandle::didGetSize):
(WebCore::BlobResourceHandle::readSync):
(WebCore::BlobResourceHandle::readFileSync):
(WebCore::BlobResourceHandle::readAsync):
(WebCore::BlobResourceHandle::didOpen):
(WebCore::BlobResourceHandle::didRead):
(WebCore::BlobResourceHandle::failed):
(WebCore::BlobResourceHandle::notifyResponse):
(WebCore::BlobResourceHandle::notifyResponseOnError):
(WebCore::BlobResourceHandle::notifyFail):

  • platform/network/BlobResourceHandle.h:

LayoutTests:

  • fast/files/apply-blob-url-to-xhr-expected.txt:
  • fast/files/workers/worker-apply-blob-url-to-xhr-expected.txt:
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r205189 r205190  
     12016-08-30  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Blob not found URL should result in a network error
     4        https://bugs.webkit.org/show_bug.cgi?id=161381
     5
     6        Reviewed by Sam Weinig.
     7
     8        * fast/files/apply-blob-url-to-xhr-expected.txt:
     9        * fast/files/workers/worker-apply-blob-url-to-xhr-expected.txt:
     10
    1112016-08-30  Ryan Haddad  <ryanhaddad@apple.com>
    212
  • trunk/LayoutTests/fast/files/apply-blob-url-to-xhr-expected.txt

    r195588 r205190  
    66Received exception 19: NetworkError
    77Test that XMLHttpRequest GET fails after the blob URL is revoked.
    8 Status: 404
    9 Response:
     8Received exception 19: NetworkError
    109DONE
    1110
  • trunk/LayoutTests/fast/files/workers/worker-apply-blob-url-to-xhr-expected.txt

    r195588 r205190  
    66Received exception 19: NetworkError
    77Test that XMLHttpRequest GET fails after the blob URL is revoked.
    8 Status: 404
    9 Response:
     8Received exception 19: NetworkError
    109DONE
    1110
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r205188 r205190  
     12016-08-30  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Blob not found URL should result in a network error
     4        https://bugs.webkit.org/show_bug.cgi?id=161381
     5
     6        Reviewed by Sam Weinig.
     7
     8        * web-platform-tests/fetch/api/basic/scheme-blob-expected.txt:
     9        * web-platform-tests/fetch/api/basic/scheme-blob-worker-expected.txt:
     10        * web-platform-tests/fetch/api/basic/scheme-blob-worker.html:
     11        * web-platform-tests/fetch/api/basic/scheme-blob.html:
     12        * web-platform-tests/fetch/api/basic/scheme-blob.js:
     13        (invalidRequestMethods.forEach):
     14
    1152016-08-30  Youenn Fablet  <youenn@apple.com>
    216
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-blob-expected.txt

    r201557 r205190  
    11
    22PASS Fetching [GET] URL.createObjectURL(blob) is OK
    3 PASS Fetching [GET] blob:http://www.localhost:8800/ is KO
     3PASS Fetching [GET] not found blob URL is KO
    44PASS Fetching [POST] URL.createObjectURL(blob) is KO
    55PASS Fetching [OPTIONS] URL.createObjectURL(blob) is KO
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-blob-worker-expected.txt

    r201557 r205190  
    11
    22PASS Fetching [GET] URL.createObjectURL(blob) is OK
    3 PASS Fetching [GET] blob:http://www.localhost:8800/ is KO
     3PASS Fetching [GET] not found blob URL is KO
    44PASS Fetching [POST] URL.createObjectURL(blob) is KO
    55PASS Fetching [OPTIONS] URL.createObjectURL(blob) is KO
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-blob-worker.html

    r197748 r205190  
    1212  <body>
    1313    <script>
    14       fetch_tests_from_worker(new Worker("scheme-blob.js?pipe=sub"));
     14      fetch_tests_from_worker(new Worker("scheme-blob.js"));
    1515    </script>
    1616  </body>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-blob.html

    r197748 r205190  
    1212  <body>
    1313    <script src="../resources/utils.js"></script>
    14     <script src="scheme-blob.js?pipe=sub"></script>
     14    <script src="scheme-blob.js"></script>
    1515  </body>
    1616</html>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-blob.js

    r201557 r205190  
    3131
    3232var blob2 = new Blob(["Blob's data"], { "type" : "text/plain" });
    33 checkKoUrl("blob:http://{{domains[www]}}:{{ports[http][0]}}/", "GET",
    34           "Fetching [GET] blob:http://{{domains[www]}}:{{ports[http][0]}}/ is KO");
     33var blob2URL = URL.createObjectURL(blob2);
     34checkKoUrl(blob2URL + "notfoundblob", "GET",
     35          "Fetching [GET] not found blob URL is KO");
    3536
    3637var invalidRequestMethods = [
     
    4344];
    4445invalidRequestMethods.forEach(function(method) {
    45   checkKoUrl(URL.createObjectURL(blob2), method, "Fetching [" + method + "] URL.createObjectURL(blob) is KO");
     46  checkKoUrl(blob2URL, method, "Fetching [" + method + "] URL.createObjectURL(blob) is KO");
    4647});
    4748
  • trunk/Source/WebCore/ChangeLog

    r205188 r205190  
     12016-08-30  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Blob not found URL should result in a network error
     4        https://bugs.webkit.org/show_bug.cgi?id=161381
     5
     6        Reviewed by Sam Weinig.
     7
     8        Covered by rebased and updated tests.
     9
     10        Raising a network error if no blob can be found from the URL.
     11        It is no longer notified by a 404 response.
     12
     13        Updated FileReaderLoader to generate the correct exception.
     14
     15        Made some clean-up in the code, in particular adding an enum class for BlobResourceHandle errors.
     16
     17        * fileapi/FileReaderLoader.cpp:
     18        (WebCore::FileReaderLoader::didFail):
     19        (WebCore::FileReaderLoader::toErrorCode):
     20        (WebCore::FileReaderLoader::httpStatusCodeToErrorCode):
     21        * fileapi/FileReaderLoader.h:
     22        * platform/network/BlobResourceHandle.cpp:
     23        (WebCore::BlobResourceHandle::loadResourceSynchronously):
     24        (WebCore::BlobResourceHandle::doStart):
     25        (WebCore::BlobResourceHandle::didGetSize):
     26        (WebCore::BlobResourceHandle::readSync):
     27        (WebCore::BlobResourceHandle::readFileSync):
     28        (WebCore::BlobResourceHandle::readAsync):
     29        (WebCore::BlobResourceHandle::didOpen):
     30        (WebCore::BlobResourceHandle::didRead):
     31        (WebCore::BlobResourceHandle::failed):
     32        (WebCore::BlobResourceHandle::notifyResponse):
     33        (WebCore::BlobResourceHandle::notifyResponseOnError):
     34        (WebCore::BlobResourceHandle::notifyFail):
     35        * platform/network/BlobResourceHandle.h:
     36
    1372016-08-30  Youenn Fablet  <youenn@apple.com>
    238
  • trunk/Source/WebCore/fileapi/FileReaderLoader.cpp

    r204019 r205190  
    3737#include "FileReaderLoaderClient.h"
    3838#include "HTTPHeaderNames.h"
     39#include "ResourceError.h"
    3940#include "ResourceRequest.h"
    4041#include "ResourceResponse.h"
     
    228229}
    229230
    230 void FileReaderLoader::didFail(const ResourceError&)
     231void FileReaderLoader::didFail(const ResourceError& error)
    231232{
    232233    // If we're aborting, do not proceed with normal error handling since it is covered in aborting code.
     
    234235        return;
    235236
    236     failed(FileError::NOT_READABLE_ERR);
     237    failed(toErrorCode(static_cast<BlobResourceHandle::Error>(error.errorCode())));
    237238}
    238239
     
    243244    if (m_client)
    244245        m_client->didFail(m_errorCode);
     246}
     247
     248FileError::ErrorCode FileReaderLoader::toErrorCode(BlobResourceHandle::Error error)
     249{
     250    switch (error) {
     251    case BlobResourceHandle::Error::NotFoundError:
     252        return FileError::NOT_FOUND_ERR;
     253    default:
     254        return FileError::NOT_READABLE_ERR;
     255    }
    245256}
    246257
     
    250261    case 403:
    251262        return FileError::SECURITY_ERR;
    252     case 404:
    253         return FileError::NOT_FOUND_ERR;
    254263    default:
    255264        return FileError::NOT_READABLE_ERR;
  • trunk/Source/WebCore/fileapi/FileReaderLoader.h

    r199985 r205190  
    3232#define FileReaderLoader_h
    3333
     34#include "BlobResourceHandle.h"
    3435#include "FileError.h"
    3536#include "URL.h"
     
    9394
    9495    static FileError::ErrorCode httpStatusCodeToErrorCode(int);
     96    static FileError::ErrorCode toErrorCode(BlobResourceHandle::Error);
    9597
    9698    ReadType m_readType;
  • trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp

    r203303 r205190  
    5656static const int httpPartialContent = 206;
    5757static const int httpNotAllowed = 403;
    58 static const int httpNotFound = 404;
    5958static const int httpRequestedRangeNotSatisfiable = 416;
    6059static const int httpInternalError = 500;
     
    6261static const char* httpPartialContentText = "Partial Content";
    6362static const char* httpNotAllowedText = "Not Allowed";
    64 static const char* httpNotFoundText = "Not Found";
    6563static const char* httpRequestedRangeNotSatisfiableText = "Requested Range Not Satisfiable";
    6664static const char* httpInternalErrorText = "Internal Server Error";
    6765
    6866static const char* const webKitBlobResourceDomain = "WebKitBlobResource";
    69 enum {
    70     notFoundError = 1,
    71     securityError = 2,
    72     rangeError = 3,
    73     notReadableError = 4,
    74     methodNotAllowed = 5
    75 };
    7667
    7768///////////////////////////////////////////////////////////////////////////////
     
    10495    // We cannot handle the size that is more than maximum integer.
    10596    if (response.expectedContentLength() > INT_MAX) {
    106         m_error = ResourceError(webKitBlobResourceDomain, notReadableError, response.url(), "File is too large");
     97        m_error = ResourceError(webKitBlobResourceDomain, static_cast<int>(BlobResourceHandle::Error::NotReadableError), response.url(), "File is too large");
    10798        return;
    10899    }
     
    133124{
    134125    if (!equalLettersIgnoringASCIICase(request.httpMethod(), "get")) {
    135         error = ResourceError(webKitBlobResourceDomain, methodNotAllowed, response.url(), "Request method must be GET");
     126        error = ResourceError(webKitBlobResourceDomain, static_cast<int>(Error::MethodNotAllowed), response.url(), "Request method must be GET");
    136127        return;
    137128    }
     
    189180
    190181    // Do not continue if the request is aborted or an error occurs.
    191     if (m_aborted || m_errorCode)
     182    if (erroredOrAborted())
    192183        return;
    193184
    194185    if (!equalLettersIgnoringASCIICase(firstRequest().httpMethod(), "get")) {
    195         notifyFail(methodNotAllowed);
     186        notifyFail(Error::MethodNotAllowed);
    196187        return;
    197188    }
     
    199190    // If the blob data is not found, fail now.
    200191    if (!m_blobData) {
    201         m_errorCode = notFoundError;
    202         notifyResponse();
     192        notifyFail(Error::NotFoundError);
    203193        return;
    204194    }
     
    207197    String range = firstRequest().httpHeaderField(HTTPHeaderName::Range);
    208198    if (!range.isEmpty() && !parseRange(range, m_rangeOffset, m_rangeEnd, m_rangeSuffixLength)) {
    209         m_errorCode = rangeError;
     199        m_errorCode = Error::RangeError;
    210200        notifyResponse();
    211201        return;
     
    216206    else {
    217207        Ref<BlobResourceHandle> protectedThis(*this); // getSizeForNext calls the client
    218         for (size_t i = 0; i < m_blobData->items().size() && !m_aborted && !m_errorCode; ++i)
     208        for (size_t i = 0; i < m_blobData->items().size() && !erroredOrAborted(); ++i)
    219209            getSizeForNext();
    220210        notifyResponse();
     
    262252
    263253    // Do not continue if the request is aborted or an error occurs.
    264     if (m_aborted || m_errorCode)
     254    if (erroredOrAborted())
    265255        return;
    266256
    267257    // If the size is -1, it means the file has been moved or changed. Fail now.
    268258    if (size == -1) {
    269         m_errorCode = notFoundError;
    270         notifyResponse();
     259        notifyFail(Error::NotFoundError);
    271260        return;
    272261    }
     
    330319    while (remaining) {
    331320        // Do not continue if the request is aborted or an error occurs.
    332         if (m_aborted || m_errorCode)
     321        if (erroredOrAborted())
    333322            break;
    334323
     
    336325        if (!m_totalRemainingSize || m_readItemCount >= m_blobData->items().size())
    337326            break;
    338        
     327
    339328        const BlobDataItem& item = m_blobData->items().at(m_readItemCount);
    340329        int bytesRead = 0;
     
    353342
    354343    int result;
    355     if (m_aborted || m_errorCode)
     344    if (erroredOrAborted())
    356345        result = -1;
    357346    else
     
    402391        m_currentItemReadSize = 0;
    403392        if (!success) {
    404             m_errorCode = notReadableError;
     393            m_errorCode = Error::NotReadableError;
    405394            return 0;
    406395        }
     
    411400    int bytesRead = m_stream->read(buf, length);
    412401    if (bytesRead < 0) {
    413         m_errorCode = notReadableError;
     402        m_errorCode = Error::NotReadableError;
    414403        return 0;
    415404    }
     
    430419
    431420    // Do not continue if the request is aborted or an error occurs.
    432     if (m_aborted || m_errorCode)
     421    if (erroredOrAborted())
    433422        return;
    434423
     
    486475
    487476    if (!success) {
    488         failed(notReadableError);
     477        failed(Error::NotReadableError);
    489478        return;
    490479    }
     
    497486{
    498487    if (bytesRead < 0) {
    499         failed(notReadableError);
     488        failed(Error::NotReadableError);
    500489        return;
    501490    }
     
    534523}
    535524
    536 void BlobResourceHandle::failed(int errorCode)
     525void BlobResourceHandle::failed(Error errorCode)
    537526{
    538527    ASSERT(m_async);
     
    554543        return;
    555544
    556     if (m_errorCode) {
     545    if (m_errorCode != Error::NoError) {
    557546        Ref<BlobResourceHandle> protectedThis(*this);
    558547        notifyResponseOnError();
     
    591580void BlobResourceHandle::notifyResponseOnError()
    592581{
    593     ASSERT(m_errorCode);
     582    ASSERT(m_errorCode != Error::NoError);
    594583
    595584    ResourceResponse response(firstRequest().url(), "text/plain", 0, String());
    596585    switch (m_errorCode) {
    597     case rangeError:
     586    case Error::RangeError:
    598587        response.setHTTPStatusCode(httpRequestedRangeNotSatisfiable);
    599588        response.setHTTPStatusText(httpRequestedRangeNotSatisfiableText);
    600589        break;
    601     case notFoundError:
    602         response.setHTTPStatusCode(httpNotFound);
    603         response.setHTTPStatusText(httpNotFoundText);
    604         break;
    605     case securityError:
     590    case Error::SecurityError:
    606591        response.setHTTPStatusCode(httpNotAllowed);
    607592        response.setHTTPStatusText(httpNotAllowedText);
     
    627612}
    628613
    629 void BlobResourceHandle::notifyFail(int errorCode)
     614void BlobResourceHandle::notifyFail(Error errorCode)
    630615{
    631616    if (client())
    632         client()->didFail(this, ResourceError(webKitBlobResourceDomain, errorCode, firstRequest().url(), String()));
     617        client()->didFail(this, ResourceError(webKitBlobResourceDomain, static_cast<int>(errorCode), firstRequest().url(), String()));
    633618}
    634619
  • trunk/Source/WebCore/platform/network/BlobResourceHandle.h

    r201761 r205190  
    5656    bool aborted() const { return m_aborted; }
    5757
     58    enum class Error {
     59        NoError = 0,
     60        NotFoundError = 1,
     61        SecurityError = 2,
     62        RangeError = 3,
     63        NotReadableError = 4,
     64        MethodNotAllowed = 5
     65    };
     66
    5867private:
    5968    BlobResourceHandle(BlobData*, const ResourceRequest&, ResourceHandleClient*, bool async);
     
    7382    void seek();
    7483    void consumeData(const char* data, int bytesRead);
    75     void failed(int errorCode);
     84    void failed(Error);
    7685
    7786    void readAsync();
     
    8695    void notifyResponseOnError();
    8796    void notifyReceiveData(const char*, int);
    88     void notifyFail(int errorCode);
     97    void notifyFail(Error);
    8998    void notifyFinish();
     99
     100    bool erroredOrAborted() const { return m_aborted || m_errorCode != Error::NoError; }
    90101
    91102    enum { kPositionNotSpecified = -1 };
     
    97108    Vector<char> m_buffer;
    98109    Vector<long long> m_itemLengthList;
    99     int m_errorCode { 0 };
     110    Error m_errorCode { Error::NoError };
    100111    bool m_aborted { false };
    101112    long long m_rangeOffset { kPositionNotSpecified };
Note: See TracChangeset for help on using the changeset viewer.