Changeset 221024 in webkit


Ignore:
Timestamp:
Aug 22, 2017 11:02:43 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

[Cache API] Add support for overwriting responses with put on an existing record
https://bugs.webkit.org/show_bug.cgi?id=175825

Patch by Youenn Fablet <youenn@apple.com> on 2017-08-22
Reviewed by Geoffrey Garen.

LayoutTests/imported/w3c:

  • web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt:
  • web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt:

Source/WebCore:

Tests: http/wpt/cache-storage/cache-put-keys.https.any.html

http/wpt/cache-storage/cache-put-keys.https.any.worker.html

Adding support for the new response update counter.
Overwriting local cached response with new retrieved response when the counter is different.
Adding support for passing this value from/to workers.

  • Modules/cache/Cache.cpp:

(WebCore::Cache::queryCacheWithTargetStorage):
(WebCore::toConnectionRecord):
(WebCore::Cache::updateRecords):

  • Modules/cache/CacheStorageConnection.cpp:

(WebCore::CacheStorageConnection::Record::copy const):

  • Modules/cache/CacheStorageConnection.h:
  • Modules/cache/CacheStorageRecord.h:
  • Modules/cache/WorkerCacheStorageConnection.cpp:

(WebCore::toCrossThreadRecordData):
(WebCore::fromCrossThreadRecordData):

Source/WebKit:

Add support for encoding/decoding the update counter.
Incrementing it when overwriting an existing response.
Storing the new body in addition to the new response.

  • NetworkProcess/cache/CacheStorageEngine.cpp:

(WebKit::CacheStorageEngine::putRecords):

  • Shared/WebCoreArgumentCoders.cpp:

(IPC::ArgumentCoder<CacheStorageConnection::Record>::encode):
(IPC::ArgumentCoder<CacheStorageConnection::Record>::decode):

LayoutTests:

Adding update counter for response
Skipping new test on WK1.

  • platform/ios-wk1/TestExpectations:
  • platform/mac-wk1/TestExpectations:
  • http/wpt/cache-storage/cache-put-keys.https.any-expected.txt: Added.
  • http/wpt/cache-storage/cache-put-keys.https.any.html: Added.
  • http/wpt/cache-storage/cache-put-keys.https.any.js: Added.

(cache_test):

  • http/wpt/cache-storage/cache-put-keys.https.any.worker-expected.txt: Added.
  • http/wpt/cache-storage/cache-put-keys.https.any.worker.html: Added.
Location:
trunk
Files:
6 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r221023 r221024  
     12017-08-22  Youenn Fablet  <youenn@apple.com>
     2
     3        [Cache API] Add support for overwriting responses with put on an existing record
     4        https://bugs.webkit.org/show_bug.cgi?id=175825
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Adding update counter for response
     9        Skipping new test on WK1.
     10
     11        * platform/ios-wk1/TestExpectations:
     12        * platform/mac-wk1/TestExpectations:
     13        * http/wpt/cache-storage/cache-put-keys.https.any-expected.txt: Added.
     14        * http/wpt/cache-storage/cache-put-keys.https.any.html: Added.
     15        * http/wpt/cache-storage/cache-put-keys.https.any.js: Added.
     16        (cache_test):
     17        * http/wpt/cache-storage/cache-put-keys.https.any.worker-expected.txt: Added.
     18        * http/wpt/cache-storage/cache-put-keys.https.any.worker.html: Added.
     19
    1202017-08-22  Matt Lewis  <jlewis3@apple.com>
    221
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r221020 r221024  
     12017-08-22  Youenn Fablet  <youenn@apple.com>
     2
     3        [Cache API] Add support for overwriting responses with put on an existing record
     4        https://bugs.webkit.org/show_bug.cgi?id=175825
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt:
     9        * web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt:
     10
    1112017-08-22  Andy Estes  <aestes@apple.com>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt

    r220984 r221024  
    99PASS Cache.put with HTTP 206 response
    1010PASS Cache.put with HTTP 500 response
    11 FAIL Cache.put called twice with matching Requests and different Responses assert_equals: Cache put should store new response body. expected "New body" but got "Old body"
    12 FAIL Cache.put called twice with request URLs that differ only by a fragment assert_equals: Cache put should store new response body. expected "New body" but got "Old body"
     11PASS Cache.put called twice with matching Requests and different Responses
     12PASS Cache.put called twice with request URLs that differ only by a fragment
    1313PASS Cache.put with a string request
    1414PASS Cache.put with an invalid response
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt

    r220998 r221024  
    99PASS Cache.put with HTTP 206 response
    1010PASS Cache.put with HTTP 500 response
    11 FAIL Cache.put called twice with matching Requests and different Responses assert_equals: Cache put should store new response body. expected "New body" but got "Old body"
    12 FAIL Cache.put called twice with request URLs that differ only by a fragment assert_equals: Cache put should store new response body. expected "New body" but got "Old body"
     11PASS Cache.put called twice with matching Requests and different Responses
     12PASS Cache.put called twice with request URLs that differ only by a fragment
    1313PASS Cache.put with a string request
    1414PASS Cache.put with an invalid response
  • trunk/LayoutTests/platform/ios-wk1/TestExpectations

    r220941 r221024  
    1010# No service worker implementation for WK1
    1111imported/w3c/web-platform-tests/service-workers [ Skip ]
     12http/wpt/cache-storage [ Skip ]
    1213
    1314# Skip WebRTC for now in WK1
  • trunk/LayoutTests/platform/mac-wk1/TestExpectations

    r220981 r221024  
    9797# No service worker implementation for WK1
    9898imported/w3c/web-platform-tests/service-workers [ Skip ]
     99http/wpt/cache-storage [ Skip ]
    99100
    100101# Skip WebRTC for now in WK1
  • trunk/Source/WebCore/ChangeLog

    r221022 r221024  
     12017-08-22  Youenn Fablet  <youenn@apple.com>
     2
     3        [Cache API] Add support for overwriting responses with put on an existing record
     4        https://bugs.webkit.org/show_bug.cgi?id=175825
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Tests: http/wpt/cache-storage/cache-put-keys.https.any.html
     9               http/wpt/cache-storage/cache-put-keys.https.any.worker.html
     10
     11        Adding support for the new response update counter.
     12        Overwriting local cached response with new retrieved response when the counter is different.
     13        Adding support for passing this value from/to workers.
     14
     15        * Modules/cache/Cache.cpp:
     16        (WebCore::Cache::queryCacheWithTargetStorage):
     17        (WebCore::toConnectionRecord):
     18        (WebCore::Cache::updateRecords):
     19        * Modules/cache/CacheStorageConnection.cpp:
     20        (WebCore::CacheStorageConnection::Record::copy const):
     21        * Modules/cache/CacheStorageConnection.h:
     22        * Modules/cache/CacheStorageRecord.h:
     23        * Modules/cache/WorkerCacheStorageConnection.cpp:
     24        (WebCore::toCrossThreadRecordData):
     25        (WebCore::fromCrossThreadRecordData):
     26
    1272017-08-22  Alex Christensen  <achristensen@webkit.org>
    228
  • trunk/Source/WebCore/Modules/cache/Cache.cpp

    r220998 r221024  
    412412    for (auto& record : targetStorage) {
    413413        if (queryCacheMatch(request, record.request.get(), record.response->resourceResponse(), options))
    414             records.append({ record.identifier, record.request.copyRef(), record.response.copyRef() });
     414            records.append({ record.identifier, record.updateResponseCounter, record.request.copyRef(), record.response.copyRef() });
    415415    }
    416416    return records;
     
    441441    ASSERT(!cachedResponse.isNull());
    442442
    443     return { 0,
     443    return { 0, 0,
    444444        request.headers().guard(), WTFMove(cachedRequest), request.fetchOptions(), request.internalRequestReferrer(),
    445445        response.headers().guard(), WTFMove(cachedResponse), WTFMove(responseBody)
     
    473473    for (auto& record : records) {
    474474        size_t index = m_records.findMatching([&](const auto& item) { return item.identifier == record.identifier; });
    475         if (index != notFound)
    476             newRecords.append(WTFMove(m_records[index]));
    477         else {
     475        if (index != notFound) {
     476            auto& current = m_records[index];
     477            if (current.updateResponseCounter != record.updateResponseCounter) {
     478                auto responseHeaders = FetchHeaders::create(record.responseHeadersGuard, HTTPHeaderMap { record.response.httpHeaderFields() });
     479                auto response = FetchResponse::create(*scriptExecutionContext(), std::nullopt, WTFMove(responseHeaders), WTFMove(record.response));
     480                response->setBodyData(WTFMove(record.responseBody));
     481
     482                current.response = WTFMove(response);
     483                current.updateResponseCounter = record.updateResponseCounter;
     484            }
     485            newRecords.append(WTFMove(current));
     486        } else {
    478487            auto requestHeaders = FetchHeaders::create(record.requestHeadersGuard, HTTPHeaderMap { record.request.httpHeaderFields() });
    479488            FetchRequest::InternalRequest internalRequest = { WTFMove(record.request), WTFMove(record.options), WTFMove(record.referrer) };
     
    484493            response->setBodyData(WTFMove(record.responseBody));
    485494
    486             newRecords.append(CacheStorageRecord { record.identifier, WTFMove(request), WTFMove(response) });
     495            newRecords.append(CacheStorageRecord { record.identifier, record.updateResponseCounter, WTFMove(request), WTFMove(response) });
    487496        }
    488497    }
  • trunk/Source/WebCore/Modules/cache/CacheStorageConnection.cpp

    r220928 r221024  
    181181CacheStorageConnection::Record CacheStorageConnection::Record::copy() const
    182182{
    183     return Record { identifier, requestHeadersGuard, request, options, referrer, responseHeadersGuard, response, copyResponseBody(responseBody) };
     183    return Record { identifier, updateResponseCounter, requestHeadersGuard, request, options, referrer, responseHeadersGuard, response, copyResponseBody(responseBody) };
    184184}
    185185
  • trunk/Source/WebCore/Modules/cache/CacheStorageConnection.h

    r220928 r221024  
    6868
    6969        uint64_t identifier;
     70        uint64_t updateResponseCounter;
    7071
    7172        FetchHeaders::Guard requestHeadersGuard;
  • trunk/Source/WebCore/Modules/cache/CacheStorageRecord.h

    r220758 r221024  
    3333struct CacheStorageRecord {
    3434    uint64_t identifier;
     35    uint64_t updateResponseCounter;
    3536
    3637    Ref<FetchRequest> request;
  • trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp

    r220928 r221024  
    4141struct CrossThreadRecordData {
    4242    uint64_t identifier;
     43    uint64_t updateResponseCounter;
    4344
    4445    FetchHeaders::Guard requestHeadersGuard;
     
    5758    return CrossThreadRecordData {
    5859        record.identifier,
     60        record.updateResponseCounter,
    5961        record.requestHeadersGuard,
    6062        record.request.isolatedCopy(),
     
    7173    return CacheStorageConnection::Record {
    7274        data.identifier,
     75        data.updateResponseCounter,
    7376        data.requestHeadersGuard,
    7477        WTFMove(data.request),
  • trunk/Source/WebKit/ChangeLog

    r221022 r221024  
     12017-08-22  Youenn Fablet  <youenn@apple.com>
     2
     3        [Cache API] Add support for overwriting responses with put on an existing record
     4        https://bugs.webkit.org/show_bug.cgi?id=175825
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Add support for encoding/decoding the update counter.
     9        Incrementing it when overwriting an existing response.
     10        Storing the new body in addition to the new response.
     11
     12        * NetworkProcess/cache/CacheStorageEngine.cpp:
     13        (WebKit::CacheStorageEngine::putRecords):
     14        * Shared/WebCoreArgumentCoders.cpp:
     15        (IPC::ArgumentCoder<CacheStorageConnection::Record>::encode):
     16        (IPC::ArgumentCoder<CacheStorageConnection::Record>::decode):
     17
    1182017-08-22  Alex Christensen  <achristensen@webkit.org>
    219
  • trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp

    r220928 r221024  
    175175                    existingRecord.responseHeadersGuard = record.responseHeadersGuard;
    176176                    existingRecord.response = WTFMove(record.response);
     177                    existingRecord.responseBody = WTFMove(record.responseBody);
     178                    ++existingRecord.updateResponseCounter;
    177179                }
    178180            }
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp

    r220928 r221024  
    312312    encoder << record.responseHeadersGuard;
    313313    encoder << record.response;
     314    encoder << record.updateResponseCounter;
    314315
    315316    WTF::switchOn(record.responseBody, [&](const Ref<SharedBuffer>& buffer) {
     
    354355    WebCore::ResourceResponse response;
    355356    if (!decoder.decode(response))
     357        return false;
     358
     359    uint64_t updateResponseCounter;
     360    if (!decoder.decode(updateResponseCounter))
    356361        return false;
    357362
     
    387392    record.responseHeadersGuard = responseHeadersGuard;
    388393    record.response = WTFMove(response);
     394    record.updateResponseCounter = updateResponseCounter;
    389395    record.responseBody = WTFMove(responseBody);
    390396
Note: See TracChangeset for help on using the changeset viewer.