Changeset 213672 in webkit


Ignore:
Timestamp:
Mar 9, 2017 2:29:39 PM (7 years ago)
Author:
yoav@yoav.ws
Message:

[link preload] Double downloads of preloaded CSS
https://bugs.webkit.org/show_bug.cgi?id=169274

Reviewed by Antti Koivisto.

Source/WebCore:

Avoid reloading link preloads in case of a charset mismatch.

Charset mismatch can happen for header based preloads, as they are requested before
the HTML's <meta charset> tag is processed. This change makes sure that in those
cases, we modify the resource's encoding setting instead of reloading it.

Test: http/tests/preload/single_download_preload_headers.php

  • loader/cache/CachedResource.cpp:

(WebCore::CachedResource::CachedResource): Initialize m_unknownCharset to be the same as the preload flag.

  • loader/cache/CachedResource.h:

(WebCore::CachedResource::hasUnknownEncoding):
(WebCore::CachedResource::setHasUnknownEncoding):

  • loader/cache/CachedResourceLoader.cpp:

(WebCore::CachedResourceLoader::determineRevalidationPolicy): In case of a charset
mismatch, set the encoding of the Resource instead of reloading it if the charset is unknown.

LayoutTests:

Added tests making sure that header based preloads also trigger a single download,
and that we properly handle multiple charsets for the same preloaded resource.

  • http/tests/preload/single_download_preload_headers-expected.txt: Added.
  • http/tests/preload/single_download_preload_headers.php: Added.
  • http/tests/preload/preload-encoding-expected.txt: Added.
  • http/tests/preload/preload-encoding.php: Added.
Location:
trunk
Files:
5 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r213671 r213672  
     12017-03-09  Yoav Weiss  <yoav@yoav.ws>
     2
     3        [link preload] Double downloads of preloaded CSS
     4        https://bugs.webkit.org/show_bug.cgi?id=169274
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Added tests making sure that header based preloads also trigger a single download,
     9        and that we properly handle multiple charsets for the same preloaded resource.
     10
     11        * http/tests/preload/single_download_preload_headers-expected.txt: Added.
     12        * http/tests/preload/single_download_preload_headers.php: Added.
     13        * http/tests/preload/preload-encoding-expected.txt: Added.
     14        * http/tests/preload/preload-encoding.php: Added.
     15
    1162017-03-09  Jiewen Tan  <jiewen_tan@apple.com>
    217
  • trunk/Source/WebCore/ChangeLog

    r213671 r213672  
     12017-03-09  Yoav Weiss  <yoav@yoav.ws>
     2
     3        [link preload] Double downloads of preloaded CSS
     4        https://bugs.webkit.org/show_bug.cgi?id=169274
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Avoid reloading link preloads in case of a charset mismatch.
     9
     10        Charset mismatch can happen for header based preloads, as they are requested before
     11        the HTML's `<meta charset>` tag is processed. This change makes sure that in those
     12        cases, we modify the resource's encoding setting instead of reloading it.
     13
     14        Test: http/tests/preload/single_download_preload_headers.php
     15
     16        * loader/cache/CachedResource.cpp:
     17        (WebCore::CachedResource::CachedResource): Initialize m_unknownCharset to be the same as the preload flag.
     18        * loader/cache/CachedResource.h:
     19        (WebCore::CachedResource::hasUnknownEncoding):
     20        (WebCore::CachedResource::setHasUnknownEncoding):
     21        * loader/cache/CachedResourceLoader.cpp:
     22        (WebCore::CachedResourceLoader::determineRevalidationPolicy): In case of a charset
     23        mismatch, set the encoding of the Resource instead of reloading it if the charset is unknown.
     24
    1252017-03-09  Jiewen Tan  <jiewen_tan@apple.com>
    226
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r213350 r213672  
    124124    , m_initiatorName(request.initiatorName())
    125125    , m_isLinkPreload(request.isLinkPreload())
     126    , m_hasUnknownEncoding(request.isLinkPreload())
    126127    , m_type(type)
    127128{
  • trunk/Source/WebCore/loader/cache/CachedResource.h

    r212993 r213672  
    233233    bool isLinkPreload() { return m_isLinkPreload; }
    234234    void setLinkPreload() { m_isLinkPreload = true; }
     235    bool hasUnknownEncoding() { return m_hasUnknownEncoding; }
     236    void setHasUnknownEncoding(bool hasUnknownEncoding) { m_hasUnknownEncoding = hasUnknownEncoding; }
    235237
    236238    void registerHandle(CachedResourceHandleBase*);
     
    335337    bool m_loading { false };
    336338    bool m_isLinkPreload { false };
     339    bool m_hasUnknownEncoding { false };
    337340
    338341    bool m_switchingClientsToRevalidatedResource { false };
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp

    r212449 r213672  
    923923
    924924    auto* textDecoder = existingResource->textResourceDecoder();
    925     if (textDecoder && !textDecoder->hasEqualEncodingForCharset(cachedResourceRequest.charset()))
    926         return Reload;
     925    if (textDecoder && !textDecoder->hasEqualEncodingForCharset(cachedResourceRequest.charset())) {
     926        if (!existingResource->hasUnknownEncoding())
     927            return Reload;
     928        existingResource->setHasUnknownEncoding(false);
     929        existingResource->setEncoding(cachedResourceRequest.charset());
     930    }
    927931
    928932    // FIXME: We should use the same cache policy for all resource types. The raw resource policy is overly strict
Note: See TracChangeset for help on using the changeset viewer.