Changeset 206010 in webkit


Ignore:
Timestamp:
Sep 16, 2016 12:41:49 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Link loader should use FetchOptions::mode according its crossOrigin attribute
https://bugs.webkit.org/show_bug.cgi?id=161859

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

Source/WebCore:

Tests: http/tests/security/cached-cross-origin-preloaded-css-stylesheet.html

http/tests/security/cached-cross-origin-preloading-css-stylesheet.html

Setting fetch mode according crossorigin attribute for link preload elements.
This allows calling onerror callback for CORS failures, which was not the case before the patch.

Making cached CSS stylesheet reusable accross origins and fetch modes.

  • loader/LinkLoader.cpp:

(WebCore::LinkLoader::preloadIfNeeded): Using CachedResourceRequest::setAsPotentiallyCrossOrigin to set fetch mode.

  • loader/cache/CachedCSSStyleSheet.cpp:

(WebCore::CachedCSSStyleSheet::sheetText): clean-up.
(WebCore::CachedCSSStyleSheet::setBodyDataFrom): Implementing data init for cached css stylesheets.

  • loader/cache/CachedCSSStyleSheet.h:
  • loader/cache/CachedResourceLoader.cpp:

(WebCore::CachedResourceLoader::updateCachedResourceWithCurrentRequest): Activating update support for stylesheets.
(WebCore::CachedResourceLoader::requestResource): Fixing for matching cached resources that need being reloaded due to different origin/fetch mode.

LayoutTests:

  • http/tests/security/cached-cross-origin-preloaded-css-stylesheet-expected.txt: Added.
  • http/tests/security/cached-cross-origin-preloaded-css-stylesheet.html: Added.
  • http/tests/security/cached-cross-origin-preloading-css-stylesheet-expected.txt: Added.
  • http/tests/security/cached-cross-origin-preloading-css-stylesheet.html: Added.
  • http/tests/security/resources/allow-if-origin.php: Adding support for allowing credentials and setting contentType.
Location:
trunk
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r206009 r206010  
     12016-09-16  Youenn Fablet  <youenn@apple.com>
     2
     3        Link loader should use FetchOptions::mode according its crossOrigin attribute
     4        https://bugs.webkit.org/show_bug.cgi?id=161859
     5
     6        Reviewed by Sam Weinig.
     7
     8        * http/tests/security/cached-cross-origin-preloaded-css-stylesheet-expected.txt: Added.
     9        * http/tests/security/cached-cross-origin-preloaded-css-stylesheet.html: Added.
     10        * http/tests/security/cached-cross-origin-preloading-css-stylesheet-expected.txt: Added.
     11        * http/tests/security/cached-cross-origin-preloading-css-stylesheet.html: Added.
     12        * http/tests/security/resources/allow-if-origin.php: Adding support for allowing credentials and setting contentType.
     13
    1142016-09-16  Youenn Fablet  <youenn@apple.com>
    215
  • trunk/LayoutTests/http/tests/security/resources/allow-if-origin.php

    r205473 r206010  
    1313}
    1414
     15$allowCredentials = $_GET['allowCredentials'];
     16if (isset($allowCredentials))
     17    header("Access-Control-Allow-Credentials: true");
     18
    1519$allowCache = $_GET['allowCache'];
    1620if (isset($allowCache))
     
    2327$fp = fopen($name, 'rb');
    2428
    25 header("Content-Type: image/png");
     29$contentType = $_GET['contentType'];
     30if (!isset($contentType))
     31    $contentType = 'image/png';
     32
     33header("Content-Type: " . $contentType);
     34
    2635header("Content-Length: " . filesize($name));
    2736
  • trunk/Source/WebCore/ChangeLog

    r206009 r206010  
     12016-09-16  Youenn Fablet  <youenn@apple.com>
     2
     3        Link loader should use FetchOptions::mode according its crossOrigin attribute
     4        https://bugs.webkit.org/show_bug.cgi?id=161859
     5
     6        Reviewed by Sam Weinig.
     7
     8        Tests: http/tests/security/cached-cross-origin-preloaded-css-stylesheet.html
     9               http/tests/security/cached-cross-origin-preloading-css-stylesheet.html
     10
     11        Setting fetch mode according crossorigin attribute for link preload elements.
     12        This allows calling onerror callback for CORS failures, which was not the case before the patch.
     13
     14        Making cached CSS stylesheet reusable accross origins and fetch modes.
     15
     16        * loader/LinkLoader.cpp:
     17        (WebCore::LinkLoader::preloadIfNeeded): Using CachedResourceRequest::setAsPotentiallyCrossOrigin to set fetch mode.
     18        * loader/cache/CachedCSSStyleSheet.cpp:
     19        (WebCore::CachedCSSStyleSheet::sheetText): clean-up.
     20        (WebCore::CachedCSSStyleSheet::setBodyDataFrom): Implementing data init for cached css stylesheets.
     21        * loader/cache/CachedCSSStyleSheet.h:
     22        * loader/cache/CachedResourceLoader.cpp:
     23        (WebCore::CachedResourceLoader::updateCachedResourceWithCurrentRequest): Activating update support for stylesheets.
     24        (WebCore::CachedResourceLoader::requestResource): Fixing for matching cached resources that need being reloaded due to different origin/fetch mode.
     25
    1262016-09-16  Youenn Fablet  <youenn@apple.com>
    227
  • trunk/Source/WebCore/loader/LinkLoader.cpp

    r205287 r206010  
    162162    linkRequest.setInitiator("link");
    163163
    164     if (!crossOriginMode.isNull()) {
    165         ASSERT(document.securityOrigin());
    166         StoredCredentials allowCredentials = equalLettersIgnoringASCIICase(crossOriginMode, "use-credentials") ? AllowStoredCredentials : DoNotAllowStoredCredentials;
    167         updateRequestForAccessControl(linkRequest.mutableResourceRequest(), *document.securityOrigin(), allowCredentials);
    168     }
     164    linkRequest.setAsPotentiallyCrossOrigin(crossOriginMode, document);
    169165    linkRequest.setForPreload(true);
    170166    CachedResourceHandle<CachedResource> cachedLinkResource = document.cachedResourceLoader().preload(type.value(), linkRequest, emptyString(), CachedResourceLoader::ExplicitPreload);
  • trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp

    r204466 r206010  
    7777    return m_decoder->encoding().name();
    7878}
    79    
     79
    8080const String CachedCSSStyleSheet::sheetText(MIMETypeCheck mimeTypeCheck, bool* hasValidMIMEType) const
    81 { 
     81{
    8282    if (!m_data || m_data->isEmpty() || !canUseSheet(mimeTypeCheck, hasValidMIMEType))
    8383        return String();
    84    
     84
    8585    if (!m_decodedSheetText.isNull())
    8686        return m_decodedSheetText;
    87    
     87
    8888    // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory
    8989    return m_decoder->decodeAndFlush(m_data->data(), m_data->size());
     90}
     91
     92void CachedCSSStyleSheet::setBodyDataFrom(const CachedResource& resource)
     93{
     94    ASSERT(resource.type() == type());
     95    const CachedCSSStyleSheet& sheet = static_cast<const CachedCSSStyleSheet&>(resource);
     96
     97    m_decoder = sheet.m_decoder;
     98    m_decodedSheetText = sheet.m_decodedSheetText;
     99    m_parsedStyleSheetCache = sheet.m_parsedStyleSheetCache;
    90100}
    91101
  • trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.h

    r204466 r206010  
    4949    private:
    5050        bool canUseSheet(MIMETypeCheck, bool* hasValidMIMEType) const;
    51         bool mayTryReplaceEncodedData() const override { return true; }
     51        bool mayTryReplaceEncodedData() const final { return true; }
    5252
    53         void didAddClient(CachedResourceClient*) override;
     53        void didAddClient(CachedResourceClient*) final;
    5454
    55         void setEncoding(const String&) override;
    56         String encoding() const override;
    57         const TextResourceDecoder* textResourceDecoder() const override { return m_decoder.get(); }
    58         void finishLoading(SharedBuffer*) override;
    59         void destroyDecodedData() override;
     55        void setEncoding(const String&) final;
     56        String encoding() const final;
     57        const TextResourceDecoder* textResourceDecoder() const final { return m_decoder.get(); }
     58        void finishLoading(SharedBuffer*) final;
     59        void destroyDecodedData() final;
     60
     61        void setBodyDataFrom(const CachedResource&) final;
    6062
    6163    protected:
    62         void checkNotify() override;
     64        void checkNotify() final;
    6365
    6466        RefPtr<TextResourceDecoder> m_decoder;
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp

    r205854 r206010  
    547547
    548548    // FIXME: We should progressively extend this to other reusable resources
    549     if (resource.type() != CachedResource::Type::ImageResource && resource.type() != CachedResource::Type::Script && resource.type() != CachedResource::Type::TextTrackResource)
     549    if (resource.type() != CachedResource::Type::ImageResource && resource.type() != CachedResource::Type::Script && resource.type() != CachedResource::Type::TextTrackResource && resource.type() != CachedResource::Type::CSSStyleSheet)
    550550        return false;
    551551
Note: See TracChangeset for help on using the changeset viewer.