Changeset 280881 in webkit


Ignore:
Timestamp:
Aug 10, 2021 7:58:01 PM (11 months ago)
Author:
Chris Dumez
Message:

Add Cross-Origin-Opener-Policy support for Blob URLs
https://bugs.webkit.org/show_bug.cgi?id=228924

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline WPT test that is now passing.

  • web-platform-tests/html/cross-origin-opener-policy/blob-popup.https-expected.txt:

Source/WebCore:

Pass ScriptExecutionContext's cross-origin-opener-policy when registering a public
Blob URL and store it in the blob registry alongside the blob data. As a result,
we are able to service the right COOP headers on the blob response later on when
doing a load of this blob. In the future, we'll pass the cross-origin-embedder-policy
as well, once we support it.

No new tests, rebaselined existing test.

  • Modules/fetch/FetchLoader.cpp:

(WebCore::FetchLoader::startLoadingBlobURL):

  • dom/Document.h:
  • dom/ScriptExecutionContext.cpp:

(WebCore::ScriptExecutionContext::crossOriginOpenerPolicy const):

  • dom/ScriptExecutionContext.h:
  • fileapi/Blob.cpp:

(WebCore::BlobURLRegistry::registerURL):
(WebCore::Blob::Blob):

  • fileapi/FileReaderLoader.cpp:

(WebCore::FileReaderLoader::start):

  • fileapi/ThreadableBlobRegistry.cpp:

(WebCore::ThreadableBlobRegistry::registerBlobURL):

  • fileapi/ThreadableBlobRegistry.h:
  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::loadResource):

  • loader/CrossOriginEmbedderPolicy.cpp:

(WebCore::obtainCrossOriginEmbedderPolicy):
For WebKit1, the initial empty document seems to have an empty URL instead of
"about:blank" so I had to extend the check so that COEP properly gets enabled.

  • loader/CrossOriginOpenerPolicy.cpp:

(WebCore::obtainCrossOriginOpenerPolicy):
For WebKit1, the initial empty document seems to have an empty URL instead of
"about:blank" so I had to extend the check so that COOP properly gets enabled.

(WebCore::crossOriginOpenerPolicyToString):
(WebCore::CrossOriginOpenerPolicy::isolatedCopy const):
(WebCore::addCrossOriginOpenerPolicyHeaders):

  • loader/CrossOriginOpenerPolicy.h:

(WebCore::operator==):
(WebCore::CrossOriginOpenerPolicy::encode const):
(WebCore::CrossOriginOpenerPolicy::decode):

  • platform/network/BlobData.cpp:

(WebCore::BlobData::clone const):

  • platform/network/BlobData.h:

(WebCore::BlobData::crossOriginOpenerPolicy const):
(WebCore::BlobData::setCrossOriginOpenerPolicy):

  • platform/network/BlobRegistry.h:
  • platform/network/BlobRegistryImpl.cpp:

(WebCore::BlobRegistryImpl::registerBlobURL):
(WebCore::BlobRegistryImpl::registerBlobURLOptionallyFileBacked):

  • platform/network/BlobRegistryImpl.h:
  • platform/network/BlobResourceHandle.cpp:

(WebCore::BlobResourceHandle::notifyResponseOnSuccess):

Source/WebKit:

  • NetworkProcess/NetworkConnectionToWebProcess.cpp:

(WebKit::NetworkConnectionToWebProcess::registerBlobURLFromURL):
(WebKit::NetworkConnectionToWebProcess::registerBlobURLOptionallyFileBacked):

  • NetworkProcess/NetworkConnectionToWebProcess.h:
  • NetworkProcess/NetworkConnectionToWebProcess.messages.in:
  • NetworkProcess/NetworkDataTaskBlob.cpp:

(WebKit::NetworkDataTaskBlob::dispatchDidReceiveResponse):

  • NetworkProcess/NetworkProcessPlatformStrategies.cpp:

(WebKit::NetworkProcessPlatformStrategies::createBlobRegistry):

  • WebProcess/FileAPI/BlobRegistryProxy.cpp:

(WebKit::BlobRegistryProxy::registerBlobURL):

  • WebProcess/FileAPI/BlobRegistryProxy.h:

Source/WebKitLegacy/mac:

  • WebCoreSupport/WebPlatformStrategies.mm:

Source/WebKitLegacy/win:

  • WebCoreSupport/WebPlatformStrategies.cpp:
Location:
trunk
Files:
34 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/TestExpectations

    r280870 r280881  
    719719# test is served over HTTP.
    720720imported/w3c/web-platform-tests/html/cross-origin-opener-policy/no-https.html [ Skip ]
    721 
    722 # COOP tests that are failing and keep printing a different uuid in the error output.
    723 imported/w3c/web-platform-tests/html/cross-origin-opener-policy/blob-popup.https.html [ Failure Pass ]
    724 imported/w3c/web-platform-tests/html/cross-origin-opener-policy/coep-blob-popup.https.html [ Failure Pass ]
    725721
    726722# Newly imported WPT tests that are crashing.
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r280870 r280881  
     12021-08-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Add Cross-Origin-Opener-Policy support for Blob URLs
     4        https://bugs.webkit.org/show_bug.cgi?id=228924
     5
     6        Reviewed by Alex Christensen.
     7
     8        Rebaseline WPT test that is now passing.
     9
     10        * web-platform-tests/html/cross-origin-opener-policy/blob-popup.https-expected.txt:
     11
    1122021-08-10  Chris Dumez  <cdumez@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/cross-origin-opener-policy/blob-popup.https-expected.txt

    r280504 r280881  
    1 CONSOLE MESSAGE: TypeError: null is not an object (evaluating 'window.opener.furtherPopup = w')
    21
    3 FAIL Cross-Origin-Opener-Policy and a blob URL popup assert_equals: expected 0 but got 36
     2PASS Cross-Origin-Opener-Policy and a blob URL popup
    43
  • trunk/Source/WebCore/ChangeLog

    r280872 r280881  
     12021-08-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Add Cross-Origin-Opener-Policy support for Blob URLs
     4        https://bugs.webkit.org/show_bug.cgi?id=228924
     5
     6        Reviewed by Alex Christensen.
     7
     8        Pass ScriptExecutionContext's cross-origin-opener-policy when registering a public
     9        Blob URL and store it in the blob registry alongside the blob data. As a result,
     10        we are able to service the right COOP headers on the blob response later on when
     11        doing a load of this blob. In the future, we'll pass the cross-origin-embedder-policy
     12        as well, once we support it.
     13
     14        No new tests, rebaselined existing test.
     15
     16        * Modules/fetch/FetchLoader.cpp:
     17        (WebCore::FetchLoader::startLoadingBlobURL):
     18        * dom/Document.h:
     19        * dom/ScriptExecutionContext.cpp:
     20        (WebCore::ScriptExecutionContext::crossOriginOpenerPolicy const):
     21        * dom/ScriptExecutionContext.h:
     22        * fileapi/Blob.cpp:
     23        (WebCore::BlobURLRegistry::registerURL):
     24        (WebCore::Blob::Blob):
     25        * fileapi/FileReaderLoader.cpp:
     26        (WebCore::FileReaderLoader::start):
     27        * fileapi/ThreadableBlobRegistry.cpp:
     28        (WebCore::ThreadableBlobRegistry::registerBlobURL):
     29        * fileapi/ThreadableBlobRegistry.h:
     30        * html/HTMLMediaElement.cpp:
     31        (WebCore::HTMLMediaElement::loadResource):
     32
     33        * loader/CrossOriginEmbedderPolicy.cpp:
     34        (WebCore::obtainCrossOriginEmbedderPolicy):
     35        For WebKit1, the initial empty document seems to have an empty URL instead of
     36        "about:blank" so I had to extend the check so that COEP properly gets enabled.
     37
     38        * loader/CrossOriginOpenerPolicy.cpp:
     39        (WebCore::obtainCrossOriginOpenerPolicy):
     40        For WebKit1, the initial empty document seems to have an empty URL instead of
     41        "about:blank" so I had to extend the check so that COOP properly gets enabled.
     42
     43        (WebCore::crossOriginOpenerPolicyToString):
     44        (WebCore::CrossOriginOpenerPolicy::isolatedCopy const):
     45        (WebCore::addCrossOriginOpenerPolicyHeaders):
     46        * loader/CrossOriginOpenerPolicy.h:
     47        (WebCore::operator==):
     48        (WebCore::CrossOriginOpenerPolicy::encode const):
     49        (WebCore::CrossOriginOpenerPolicy::decode):
     50        * platform/network/BlobData.cpp:
     51        (WebCore::BlobData::clone const):
     52        * platform/network/BlobData.h:
     53        (WebCore::BlobData::crossOriginOpenerPolicy const):
     54        (WebCore::BlobData::setCrossOriginOpenerPolicy):
     55        * platform/network/BlobRegistry.h:
     56        * platform/network/BlobRegistryImpl.cpp:
     57        (WebCore::BlobRegistryImpl::registerBlobURL):
     58        (WebCore::BlobRegistryImpl::registerBlobURLOptionallyFileBacked):
     59        * platform/network/BlobRegistryImpl.h:
     60        * platform/network/BlobResourceHandle.cpp:
     61        (WebCore::BlobResourceHandle::notifyResponseOnSuccess):
     62
    1632021-08-10  Wenson Hsieh  <wenson_hsieh@apple.com>
    264
  • trunk/Source/WebCore/Modules/fetch/FetchLoader.cpp

    r278516 r280881  
    6666    }
    6767
    68     ThreadableBlobRegistry::registerBlobURL(context.securityOrigin(), m_urlForReading, blobURL);
     68    ThreadableBlobRegistry::registerBlobURL(context.securityOrigin(), context.crossOriginOpenerPolicy(), m_urlForReading, blobURL);
    6969
    7070    ResourceRequest request(m_urlForReading);
  • trunk/Source/WebCore/dom/Document.h

    r280870 r280881  
    13551355    bool shouldForceNoOpenerBasedOnCOOP() const;
    13561356
    1357     const CrossOriginOpenerPolicy& crossOriginOpenerPolicy() const;
     1357    const CrossOriginOpenerPolicy& crossOriginOpenerPolicy() const final;
    13581358    void setCrossOriginOpenerPolicy(const CrossOriginOpenerPolicy&);
    13591359
  • trunk/Source/WebCore/dom/ScriptExecutionContext.cpp

    r277958 r280881  
    3232#include "CachedScript.h"
    3333#include "CommonVM.h"
     34#include "CrossOriginOpenerPolicy.h"
    3435#include "DOMTimer.h"
    3536#include "DOMWindow.h"
     
    336337}
    337338
     339const CrossOriginOpenerPolicy& ScriptExecutionContext::crossOriginOpenerPolicy() const
     340{
     341    static NeverDestroyed<CrossOriginOpenerPolicy> coop;
     342    return coop;
     343}
     344
    338345void ScriptExecutionContext::suspendActiveDOMObjectIfNeeded(ActiveDOMObject& activeDOMObject)
    339346{
  • trunk/Source/WebCore/dom/ScriptExecutionContext.h

    r278426 r280881  
    7979enum class TaskSource : uint8_t;
    8080
     81struct CrossOriginOpenerPolicy;
     82
    8183#if ENABLE(SERVICE_WORKER)
    8284class ServiceWorker;
     
    146148    bool activeDOMObjectsAreSuspended() const { return m_activeDOMObjectsAreSuspended; }
    147149    bool activeDOMObjectsAreStopped() const { return m_activeDOMObjectsAreStopped; }
     150
     151    virtual const CrossOriginOpenerPolicy& crossOriginOpenerPolicy() const;
    148152
    149153    JSC::ScriptExecutionStatus jscScriptExecutionStatus() const;
  • trunk/Source/WebCore/fileapi/Blob.cpp

    r280824 r280881  
    6363{
    6464    ASSERT(&blob.registry() == this);
    65     ThreadableBlobRegistry::registerBlobURL(context.securityOrigin(), publicURL, static_cast<Blob&>(blob).url());
     65    ThreadableBlobRegistry::registerBlobURL(context.securityOrigin(), context.crossOriginOpenerPolicy(), publicURL, static_cast<Blob&>(blob).url());
    6666}
    6767
     
    138138{
    139139    if (fileBackedPath.isEmpty())
    140         ThreadableBlobRegistry::registerBlobURL(nullptr, m_internalURL, srcURL);
     140        ThreadableBlobRegistry::registerBlobURL(nullptr, { }, m_internalURL, srcURL);
    141141    else
    142142        ThreadableBlobRegistry::registerBlobURLOptionallyFileBacked(m_internalURL, srcURL, fileBackedPath, m_type);
  • trunk/Source/WebCore/fileapi/FileReaderLoader.cpp

    r278516 r280881  
    8383        return;
    8484    }
    85     ThreadableBlobRegistry::registerBlobURL(scriptExecutionContext->securityOrigin(), m_urlForReading, blob.url());
     85    ThreadableBlobRegistry::registerBlobURL(scriptExecutionContext->securityOrigin(), scriptExecutionContext->crossOriginOpenerPolicy(), m_urlForReading, blob.url());
    8686
    8787    // Construct and load the request.
  • trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp

    r280824 r280881  
    100100}
    101101
    102 void ThreadableBlobRegistry::registerBlobURL(SecurityOrigin* origin, const URL& url, const URL& srcURL)
     102void ThreadableBlobRegistry::registerBlobURL(SecurityOrigin* origin, const CrossOriginOpenerPolicy& coop, const URL& url, const URL& srcURL)
    103103{
    104104    // 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.
     
    107107
    108108    if (isMainThread()) {
    109         blobRegistry().registerBlobURL(url, srcURL);
     109        blobRegistry().registerBlobURL(url, srcURL, coop);
    110110        return;
    111111    }
    112112
    113     callOnMainThread([url = url.isolatedCopy(), srcURL = srcURL.isolatedCopy()] {
    114         blobRegistry().registerBlobURL(url, srcURL);
     113    callOnMainThread([url = url.isolatedCopy(), srcURL = srcURL.isolatedCopy(), coop = crossThreadCopy(coop)] {
     114        blobRegistry().registerBlobURL(url, srcURL, coop);
    115115    });
    116116}
  • trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.h

    r280824 r280881  
    3939class SecurityOrigin;
    4040
     41struct CrossOriginOpenerPolicy;
     42
    4143class ThreadableBlobRegistry {
    4244public:
    4345    static void registerFileBlobURL(const URL&, const String& path, const String& replacementPath, const String& contentType);
    4446    static void registerBlobURL(const URL&, Vector<BlobPart>&& blobParts, const String& contentType);
    45     static void registerBlobURL(SecurityOrigin*, const URL&, const URL& srcURL);
     47    static void registerBlobURL(SecurityOrigin*, const CrossOriginOpenerPolicy&, const URL&, const URL& srcURL);
    4648    static void registerBlobURLOptionallyFileBacked(const URL&, const URL& srcURL, const String& fileBackedPath, const String& contentType);
    4749    static void registerBlobURLForSlice(const URL& newURL, const URL& srcURL, long long start, long long end, const String& contentType);
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r280720 r280881  
    15531553            ThreadableBlobRegistry::unregisterBlobURL(m_blobURLForReading);
    15541554        m_blobURLForReading = BlobURL::createPublicURL(&document().securityOrigin());
    1555         ThreadableBlobRegistry::registerBlobURL(&document().securityOrigin(), m_blobURLForReading, m_blob->url());
     1555        ThreadableBlobRegistry::registerBlobURL(&document().securityOrigin(), document().crossOriginOpenerPolicy(), m_blobURLForReading, m_blob->url());
    15561556
    15571557        if (!m_player->load(m_blobURLForReading, contentType, keySystem))
  • trunk/Source/WebCore/loader/CrossOriginEmbedderPolicy.cpp

    r280504 r280881  
    4646    CrossOriginEmbedderPolicy policy;
    4747    // FIXME: about:blank should be marked as secure as per https://w3c.github.io/webappsec-secure-contexts/#potentially-trustworthy-url.
    48     if (!context.isSecureContext() && context.url() != aboutBlankURL())
     48    if (!context.isSecureContext() && context.url() != aboutBlankURL() && !context.url().isEmpty())
    4949        return policy;
    5050
  • trunk/Source/WebCore/loader/CrossOriginOpenerPolicy.cpp

    r280504 r280881  
    3434namespace WebCore {
    3535
     36static String crossOriginOpenerPolicyToString(const CrossOriginOpenerPolicyValue& coop)
     37{
     38    switch (coop) {
     39    case CrossOriginOpenerPolicyValue::SameOrigin:
     40    case CrossOriginOpenerPolicyValue::SameOriginPlusCOEP:
     41        return "same-origin"_s;
     42    case CrossOriginOpenerPolicyValue::SameOriginAllowPopups:
     43        return "same-origin-allow-popups"_s;
     44    case CrossOriginOpenerPolicyValue::UnsafeNone:
     45        break;
     46    }
     47    return "unsafe-none"_s;
     48}
     49
    3650// https://html.spec.whatwg.org/multipage/origin.html#obtain-coop
    3751CrossOriginOpenerPolicy obtainCrossOriginOpenerPolicy(const ResourceResponse& response, const ScriptExecutionContext& context)
     
    6276    CrossOriginOpenerPolicy policy;
    6377    // FIXME: about:blank should be marked as secure as per https://w3c.github.io/webappsec-secure-contexts/#potentially-trustworthy-url.
    64     if (!context.isSecureContext() && context.url() != aboutBlankURL())
     78    if (!context.isSecureContext() && context.url() != aboutBlankURL() && !context.url().isEmpty())
    6579        return policy;
    6680
     
    7084}
    7185
     86CrossOriginOpenerPolicy CrossOriginOpenerPolicy::isolatedCopy() const
     87{
     88    return {
     89        value,
     90        reportingEndpoint.isolatedCopy(),
     91        reportOnlyValue,
     92        reportOnlyReportingEndpoint.isolatedCopy()
     93    };
     94}
     95
     96void addCrossOriginOpenerPolicyHeaders(ResourceResponse& response, const CrossOriginOpenerPolicy& coop)
     97{
     98    if (coop.value != CrossOriginOpenerPolicyValue::UnsafeNone) {
     99        if (coop.reportingEndpoint.isEmpty())
     100            response.setHTTPHeaderField(HTTPHeaderName::CrossOriginOpenerPolicy, crossOriginOpenerPolicyToString(coop.value));
     101        else
     102            response.setHTTPHeaderField(HTTPHeaderName::CrossOriginOpenerPolicy, makeString(crossOriginOpenerPolicyToString(coop.value), "; report-to=\"", coop.reportingEndpoint, '\"'));
     103        if (coop.value == CrossOriginOpenerPolicyValue::SameOriginPlusCOEP)
     104            response.setHTTPHeaderField(HTTPHeaderName::CrossOriginEmbedderPolicy, "require-corp"_s); // FIXME: Pass in coep and set header value correctly.
     105    }
     106    if (coop.reportOnlyValue != CrossOriginOpenerPolicyValue::UnsafeNone) {
     107        if (coop.reportOnlyReportingEndpoint.isEmpty())
     108            response.setHTTPHeaderField(HTTPHeaderName::CrossOriginOpenerPolicyReportOnly, crossOriginOpenerPolicyToString(coop.reportOnlyValue));
     109        else
     110            response.setHTTPHeaderField(HTTPHeaderName::CrossOriginOpenerPolicyReportOnly, makeString(crossOriginOpenerPolicyToString(coop.reportOnlyValue), "; report-to=\"", coop.reportOnlyReportingEndpoint, '\"'));
     111        if (coop.reportOnlyValue == CrossOriginOpenerPolicyValue::SameOriginPlusCOEP)
     112            response.setHTTPHeaderField(HTTPHeaderName::CrossOriginEmbedderPolicyReportOnly, "require-corp"_s); // FIXME: Pass in coep and set header value correctly.
     113    }
     114}
     115
    72116} // namespace WebCore
  • trunk/Source/WebCore/loader/CrossOriginOpenerPolicy.h

    r280504 r280881  
    4949    CrossOriginOpenerPolicyValue reportOnlyValue { CrossOriginOpenerPolicyValue::UnsafeNone };
    5050    String reportOnlyReportingEndpoint;
     51
     52    CrossOriginOpenerPolicy isolatedCopy() const;
     53    template<class Encoder> void encode(Encoder&) const;
     54    template<class Decoder> static std::optional<CrossOriginOpenerPolicy> decode(Decoder&);
    5155};
     56
     57inline bool operator==(const CrossOriginOpenerPolicy& a, const CrossOriginOpenerPolicy& b)
     58{
     59    return a.value == b.value && a.reportingEndpoint == b.reportingEndpoint && a.reportOnlyValue == b.reportOnlyValue && a.reportOnlyReportingEndpoint == b.reportOnlyReportingEndpoint;
     60}
     61
     62template<class Encoder>
     63void CrossOriginOpenerPolicy::encode(Encoder& encoder) const
     64{
     65    encoder << value << reportingEndpoint << reportOnlyValue << reportOnlyReportingEndpoint;
     66}
     67
     68template<class Decoder>
     69std::optional<CrossOriginOpenerPolicy> CrossOriginOpenerPolicy::decode(Decoder& decoder)
     70{
     71    std::optional<CrossOriginOpenerPolicyValue> value;
     72    decoder >> value;
     73    if (!value)
     74        return std::nullopt;
     75
     76    std::optional<String> reportingEndpoint;
     77    decoder >> reportingEndpoint;
     78    if (!reportingEndpoint)
     79        return std::nullopt;
     80
     81    std::optional<CrossOriginOpenerPolicyValue> reportOnlyValue;
     82    decoder >> reportOnlyValue;
     83    if (!reportOnlyValue)
     84        return std::nullopt;
     85
     86    std::optional<String> reportOnlyReportingEndpoint;
     87    decoder >> reportOnlyReportingEndpoint;
     88    if (!reportOnlyReportingEndpoint)
     89        return std::nullopt;
     90
     91    return {{
     92        *value,
     93        WTFMove(*reportingEndpoint),
     94        *reportOnlyValue,
     95        WTFMove(*reportOnlyReportingEndpoint)
     96    }};
     97}
    5298
    5399// https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-result
     
    62108
    63109CrossOriginOpenerPolicy obtainCrossOriginOpenerPolicy(const ResourceResponse&, const ScriptExecutionContext&);
     110WEBCORE_EXPORT void addCrossOriginOpenerPolicyHeaders(ResourceResponse&, const CrossOriginOpenerPolicy&);
    64111
    65112} // namespace WebCore
     113
     114namespace WTF {
     115
     116template<> struct EnumTraits<WebCore::CrossOriginOpenerPolicyValue> {
     117    using values = EnumValues<
     118    WebCore::CrossOriginOpenerPolicyValue,
     119    WebCore::CrossOriginOpenerPolicyValue::UnsafeNone,
     120    WebCore::CrossOriginOpenerPolicyValue::SameOrigin,
     121    WebCore::CrossOriginOpenerPolicyValue::SameOriginPlusCOEP,
     122    WebCore::CrossOriginOpenerPolicyValue::SameOriginAllowPopups
     123    >;
     124};
     125
     126} // namespace WTF
  • trunk/Source/WebCore/platform/network/BlobData.cpp

    r204466 r280881  
    7979}
    8080
     81Ref<BlobData> BlobData::clone() const
     82{
     83    auto blobData = BlobData::create(m_contentType);
     84    blobData->m_coop = m_coop;
     85    blobData->m_items = m_items;
     86    return blobData;
     87}
     88
    8189void BlobData::appendFile(BlobDataFileReference* file, long long offset, long long length)
    8290{
  • trunk/Source/WebCore/platform/network/BlobData.h

    r218799 r280881  
    3333
    3434#include "BlobDataFileReference.h"
     35#include "CrossOriginOpenerPolicy.h"
    3536#include "ThreadSafeDataBuffer.h"
    3637#include <wtf/Forward.h>
     
    106107    const String& contentType() const { return m_contentType; }
    107108
     109    const CrossOriginOpenerPolicy& crossOriginOpenerPolicy() const { return m_coop; }
     110    void setCrossOriginOpenerPolicy(const CrossOriginOpenerPolicy& coop) { m_coop = coop; }
     111
    108112    const BlobDataItemList& items() const { return m_items; }
    109113    void swapItems(BlobDataItemList&);
     
    111115    void appendData(const ThreadSafeDataBuffer&);
    112116    void appendFile(Ref<BlobDataFileReference>&&);
     117
     118    Ref<BlobData> clone() const;
    113119
    114120private:
     
    120126
    121127    String m_contentType;
     128    CrossOriginOpenerPolicy m_coop;
    122129    BlobDataItemList m_items;
    123130};
  • trunk/Source/WebCore/platform/network/BlobRegistry.h

    r280824 r280881  
    3232#pragma once
    3333
     34#include <optional>
    3435#include <wtf/Forward.h>
    3536
     
    4041class BlobRegistry;
    4142class BlobRegistryImpl;
     43
     44struct CrossOriginOpenerPolicy;
    4245
    4346WEBCORE_EXPORT BlobRegistry& blobRegistry();
     
    5457   
    5558    // Registers a new blob URL referring to the blob data identified by the specified srcURL.
    56     virtual void registerBlobURL(const URL&, const URL& srcURL) = 0;
     59    virtual void registerBlobURL(const URL&, const URL& srcURL, const CrossOriginOpenerPolicy&) = 0;
    5760
    5861    // Registers a new blob URL referring to the blob data identified by the specified srcURL or, if none found, referring to the file found at the given path.
  • trunk/Source/WebCore/platform/network/BlobRegistryImpl.cpp

    r280824 r280881  
    153153}
    154154
    155 void BlobRegistryImpl::registerBlobURL(const URL& url, const URL& srcURL)
    156 {
    157     registerBlobURLOptionallyFileBacked(url, srcURL, nullptr, { });
    158 }
    159 
    160 void BlobRegistryImpl::registerBlobURLOptionallyFileBacked(const URL& url, const URL& srcURL, RefPtr<BlobDataFileReference>&& file, const String& contentType)
     155void BlobRegistryImpl::registerBlobURL(const URL& url, const URL& srcURL, const CrossOriginOpenerPolicy& coop)
     156{
     157    registerBlobURLOptionallyFileBacked(url, srcURL, nullptr, { }, coop);
     158}
     159
     160void BlobRegistryImpl::registerBlobURLOptionallyFileBacked(const URL& url, const URL& srcURL, RefPtr<BlobDataFileReference>&& file, const String& contentType, const CrossOriginOpenerPolicy& coop)
    161161{
    162162    ASSERT(isMainThread());
     
    165165    BlobData* src = getBlobDataFromURL(srcURL);
    166166    if (src) {
    167         addBlobData(url.string(), src);
     167        if (src->crossOriginOpenerPolicy() == coop)
     168            addBlobData(url.string(), src);
     169        else {
     170            auto clone = src->clone();
     171            clone->setCrossOriginOpenerPolicy(coop);
     172            addBlobData(url.string(), WTFMove(clone));
     173        }
    168174        return;
    169175    }
     
    174180    auto backingFile = BlobData::create(contentType);
    175181    backingFile->appendFile(file.releaseNonNull());
     182    backingFile->setCrossOriginOpenerPolicy(coop);
    176183
    177184    addBlobData(url.string(), WTFMove(backingFile));
  • trunk/Source/WebCore/platform/network/BlobRegistryImpl.h

    r280824 r280881  
    4646class ResourceRequest;
    4747class ThreadSafeDataBuffer;
     48struct CrossOriginOpenerPolicy;
    4849
    4950// BlobRegistryImpl is not thread-safe. It should only be called from main thread.
     
    6263    void registerFileBlobURL(const URL&, Ref<BlobDataFileReference>&&, const String& contentType);
    6364    void registerBlobURL(const URL&, Vector<BlobPart>&&, const String& contentType);
    64     void registerBlobURL(const URL&, const URL& srcURL);
    65     void registerBlobURLOptionallyFileBacked(const URL&, const URL& srcURL, RefPtr<BlobDataFileReference>&&, const String& contentType);
     65    void registerBlobURL(const URL&, const URL& srcURL, const CrossOriginOpenerPolicy&);
     66    void registerBlobURLOptionallyFileBacked(const URL&, const URL& srcURL, RefPtr<BlobDataFileReference>&&, const String& contentType, const CrossOriginOpenerPolicy&);
    6667    void registerBlobURLForSlice(const URL&, const URL& srcURL, long long start, long long end, const String& contentType);
    6768    void unregisterBlobURL(const URL&);
  • trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp

    r278738 r280881  
    3535#include "AsyncFileStream.h"
    3636#include "BlobData.h"
     37#include "CrossOriginOpenerPolicy.h"
    3738#include "FileStream.h"
    3839#include "HTTPHeaderNames.h"
     
    577578    response.setHTTPHeaderField(HTTPHeaderName::ContentType, m_blobData->contentType());
    578579    response.setHTTPHeaderField(HTTPHeaderName::ContentLength, String::number(m_totalRemainingSize));
     580    addCrossOriginOpenerPolicyHeaders(response, m_blobData->crossOriginOpenerPolicy());
    579581
    580582    if (isRangeRequest)
  • trunk/Source/WebKit/ChangeLog

    r280879 r280881  
     12021-08-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Add Cross-Origin-Opener-Policy support for Blob URLs
     4        https://bugs.webkit.org/show_bug.cgi?id=228924
     5
     6        Reviewed by Alex Christensen.
     7
     8        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
     9        (WebKit::NetworkConnectionToWebProcess::registerBlobURLFromURL):
     10        (WebKit::NetworkConnectionToWebProcess::registerBlobURLOptionallyFileBacked):
     11        * NetworkProcess/NetworkConnectionToWebProcess.h:
     12        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
     13        * NetworkProcess/NetworkDataTaskBlob.cpp:
     14        (WebKit::NetworkDataTaskBlob::dispatchDidReceiveResponse):
     15        * NetworkProcess/NetworkProcessPlatformStrategies.cpp:
     16        (WebKit::NetworkProcessPlatformStrategies::createBlobRegistry):
     17        * WebProcess/FileAPI/BlobRegistryProxy.cpp:
     18        (WebKit::BlobRegistryProxy::registerBlobURL):
     19        * WebProcess/FileAPI/BlobRegistryProxy.h:
     20
    1212021-08-10  Tim Horton  <timothy_horton@apple.com>
    222
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp

    r280824 r280881  
    829829}
    830830
    831 void NetworkConnectionToWebProcess::registerBlobURLFromURL(const URL& url, const URL& srcURL)
     831void NetworkConnectionToWebProcess::registerBlobURLFromURL(const URL& url, const URL& srcURL, CrossOriginOpenerPolicy&& coop)
    832832{
    833833    auto* session = networkSession();
     
    835835        return;
    836836
    837     session->blobRegistry().registerBlobURL(url, srcURL);
     837    session->blobRegistry().registerBlobURL(url, srcURL, WTFMove(coop));
    838838}
    839839
     
    846846        return;
    847847
    848     session->blobRegistry().registerBlobURLOptionallyFileBacked(url, srcURL, BlobDataFileReferenceWithSandboxExtension::create(fileBackedPath), contentType);
     848    session->blobRegistry().registerBlobURLOptionallyFileBacked(url, srcURL, BlobDataFileReferenceWithSandboxExtension::create(fileBackedPath), contentType, { });
    849849}
    850850
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h

    r280824 r280881  
    6767enum class StorageAccessScope : bool;
    6868enum class ShouldAskITP : bool;
     69struct CrossOriginOpenerPolicy;
    6970struct RequestStorageAccessResult;
    7071struct SameSiteInfo;
     
    230231    void registerFileBlobURL(const URL&, const String& path, const String& replacementPath, SandboxExtension::Handle&&, const String& contentType);
    231232    void registerBlobURL(const URL&, Vector<WebCore::BlobPart>&&, const String& contentType);
    232     void registerBlobURLFromURL(const URL&, const URL& srcURL);
     233    void registerBlobURLFromURL(const URL&, const URL& srcURL, WebCore::CrossOriginOpenerPolicy&&);
    233234    void registerBlobURLOptionallyFileBacked(const URL&, const URL& srcURL, const String& fileBackedPath, const String& contentType);
    234235    void registerBlobURLForSlice(const URL&, const URL& srcURL, int64_t start, int64_t end, const String& contentType);
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in

    r280824 r280881  
    5151    RegisterFileBlobURL(URL url, String path, String replacementPath, WebKit::SandboxExtension::Handle extensionHandle, String contentType)
    5252    RegisterBlobURL(URL url, Vector<WebCore::BlobPart> blobParts, String contentType)
    53     RegisterBlobURLFromURL(URL url, URL srcURL)
     53    RegisterBlobURLFromURL(URL url, URL srcURL, struct WebCore::CrossOriginOpenerPolicy coop)
    5454    RegisterBlobURLOptionallyFileBacked(URL url, URL srcURL, String fileBackedPath, String contentType)
    5555    RegisterBlobURLForSlice(URL url, URL srcURL, int64_t start, int64_t end, String contentType)
  • trunk/Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp

    r278532 r280881  
    4242#include <WebCore/AsyncFileStream.h>
    4343#include <WebCore/BlobRegistryImpl.h>
     44#include <WebCore/CrossOriginOpenerPolicy.h>
    4445#include <WebCore/HTTPParsers.h>
    4546#include <WebCore/ParsedContentRange.h>
     
    265266        response.setHTTPHeaderField(HTTPHeaderName::ContentType, m_blobData->contentType());
    266267        response.setHTTPHeaderField(HTTPHeaderName::ContentLength, String::number(m_totalRemainingSize));
     268        addCrossOriginOpenerPolicyHeaders(response, m_blobData->crossOriginOpenerPolicy());
    267269
    268270        if (isRangeRequest)
  • trunk/Source/WebKit/NetworkProcess/NetworkProcessPlatformStrategies.cpp

    r280824 r280881  
    6060        void registerFileBlobURL(const URL&, Ref<BlobDataFileReference>&&, const String& path, const String& contentType) final { ASSERT_NOT_REACHED(); }
    6161        void registerBlobURL(const URL&, Vector<BlobPart>&&, const String& contentType) final { ASSERT_NOT_REACHED(); }
    62         void registerBlobURL(const URL&, const URL& srcURL) final { ASSERT_NOT_REACHED(); }
     62        void registerBlobURL(const URL&, const URL& srcURL, const WebCore::CrossOriginOpenerPolicy&) final { ASSERT_NOT_REACHED(); }
    6363        void registerBlobURLOptionallyFileBacked(const URL&, const URL& srcURL, RefPtr<BlobDataFileReference>&&, const String& contentType) final { ASSERT_NOT_REACHED(); }
    6464        void registerBlobURLForSlice(const URL&, const URL& srcURL, long long start, long long end, const String& contentType) final { ASSERT_NOT_REACHED(); }
  • trunk/Source/WebKit/WebProcess/FileAPI/BlobRegistryProxy.cpp

    r280824 r280881  
    3232#include "WebProcess.h"
    3333#include <WebCore/BlobDataFileReference.h>
     34#include <WebCore/CrossOriginOpenerPolicy.h>
    3435#include <WebCore/SWContextManager.h>
    3536
     
    5455}
    5556
    56 void BlobRegistryProxy::registerBlobURL(const URL& url, const URL& srcURL)
     57void BlobRegistryProxy::registerBlobURL(const URL& url, const URL& srcURL, const CrossOriginOpenerPolicy& coop)
    5758{
    58     WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::RegisterBlobURLFromURL { url, srcURL }, 0);
     59    WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::RegisterBlobURLFromURL { url, srcURL, coop }, 0);
    5960}
    6061
  • trunk/Source/WebKit/WebProcess/FileAPI/BlobRegistryProxy.h

    r280824 r280881  
    3434    void registerFileBlobURL(const URL&, Ref<WebCore::BlobDataFileReference>&&, const String& path, const String& contentType) final;
    3535    void registerBlobURL(const URL&, Vector<WebCore::BlobPart>&&, const String& contentType) final;
    36     void registerBlobURL(const URL&, const URL& srcURL) final;
     36    void registerBlobURL(const URL&, const URL& srcURL, const WebCore::CrossOriginOpenerPolicy&) final;
    3737    void registerBlobURLOptionallyFileBacked(const URL&, const URL& srcURL, RefPtr<WebCore::BlobDataFileReference>&&, const String& contentType) final;
    3838    void unregisterBlobURL(const URL&) final;
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r280855 r280881  
     12021-08-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Add Cross-Origin-Opener-Policy support for Blob URLs
     4        https://bugs.webkit.org/show_bug.cgi?id=228924
     5
     6        Reviewed by Alex Christensen.
     7
     8        * WebCoreSupport/WebPlatformStrategies.mm:
     9
    1102021-08-10  Chris Dumez  <cdumez@apple.com>
    211
  • trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm

    r280824 r280881  
    8686    void registerFileBlobURL(const URL& url, Ref<BlobDataFileReference>&& reference, const String&, const String& contentType) final { m_blobRegistry.registerFileBlobURL(url, WTFMove(reference), contentType); }
    8787    void registerBlobURL(const URL& url, Vector<BlobPart>&& parts, const String& contentType) final { m_blobRegistry.registerBlobURL(url, WTFMove(parts), contentType); }
    88     void registerBlobURL(const URL& url, const URL& srcURL) final { m_blobRegistry.registerBlobURL(url, srcURL); }
    89     void registerBlobURLOptionallyFileBacked(const URL& url, const URL& srcURL, RefPtr<BlobDataFileReference>&& reference, const String& contentType) final { m_blobRegistry.registerBlobURLOptionallyFileBacked(url, srcURL, WTFMove(reference), contentType); }
     88    void registerBlobURL(const URL& url, const URL& srcURL, const CrossOriginOpenerPolicy& coop) final { m_blobRegistry.registerBlobURL(url, srcURL, coop); }
     89    void registerBlobURLOptionallyFileBacked(const URL& url, const URL& srcURL, RefPtr<BlobDataFileReference>&& reference, const String& contentType) final { m_blobRegistry.registerBlobURLOptionallyFileBacked(url, srcURL, WTFMove(reference), contentType, { }); }
    9090    void registerBlobURLForSlice(const URL& url, const URL& srcURL, long long start, long long end, const String& contentType) final { m_blobRegistry.registerBlobURLForSlice(url, srcURL, start, end, contentType); }
    9191    void unregisterBlobURL(const URL& url) final { m_blobRegistry.unregisterBlobURL(url); }
  • trunk/Source/WebKitLegacy/win/ChangeLog

    r280824 r280881  
     12021-08-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Add Cross-Origin-Opener-Policy support for Blob URLs
     4        https://bugs.webkit.org/show_bug.cgi?id=228924
     5
     6        Reviewed by Alex Christensen.
     7
     8        * WebCoreSupport/WebPlatformStrategies.cpp:
     9
    1102021-08-09  Chris Dumez  <cdumez@apple.com>
    211
  • trunk/Source/WebKitLegacy/win/WebCoreSupport/WebPlatformStrategies.cpp

    r280824 r280881  
    8282    void registerFileBlobURL(const URL& url, Ref<BlobDataFileReference>&& reference, const String&, const String& contentType) final { m_blobRegistry.registerFileBlobURL(url, WTFMove(reference), contentType); }
    8383    void registerBlobURL(const URL& url, Vector<BlobPart>&& parts, const String& contentType) final { m_blobRegistry.registerBlobURL(url, WTFMove(parts), contentType); }
    84     void registerBlobURL(const URL& url, const URL& srcURL) final { m_blobRegistry.registerBlobURL(url, srcURL); }
    85     void registerBlobURLOptionallyFileBacked(const URL& url, const URL& srcURL, RefPtr<BlobDataFileReference>&& reference, const String& contentType) final { m_blobRegistry.registerBlobURLOptionallyFileBacked(url, srcURL, WTFMove(reference), contentType); }
     84    void registerBlobURL(const URL& url, const URL& srcURL, const CrossOriginOpenerPolicy& coop) final { m_blobRegistry.registerBlobURL(url, srcURL, coop); }
     85    void registerBlobURLOptionallyFileBacked(const URL& url, const URL& srcURL, RefPtr<BlobDataFileReference>&& reference, const String& contentType) final { m_blobRegistry.registerBlobURLOptionallyFileBacked(url, srcURL, WTFMove(reference), contentType, { }); }
    8686    void registerBlobURLForSlice(const URL& url, const URL& srcURL, long long start, long long end, const String& contentType) final { m_blobRegistry.registerBlobURLForSlice(url, srcURL, start, end, contentType); }
    8787    void unregisterBlobURL(const URL& url) final { m_blobRegistry.unregisterBlobURL(url); }
Note: See TracChangeset for help on using the changeset viewer.