Changeset 290189 in webkit


Ignore:
Timestamp:
Feb 18, 2022 5:02:27 PM (2 years ago)
Author:
pvollan@apple.com
Message:

Move content filtering to Networking process
https://bugs.webkit.org/show_bug.cgi?id=233760
<rdar://problem/86150702>

Reviewed by Brent Fulgham.

Source/WebCore:

Remove content filtering from DocumentLoader when the feature is enabled, since this takes place in the WebContent process.
Modify the ContentFilter class by removing use of the types CachedResoure and CachedRawResource, since objects of these
types are not available in the Networking process. Parameters with these types are replaced with URL parameters.
The new behavior is behind a feature flag, which is not enabled in this patch.

  • WebCore.xcodeproj/project.pbxproj:
  • loader/ContentFilter.cpp:

(WebCore::ContentFilter::startFilteringMainResource):
(WebCore::ContentFilter::stopFilteringMainResource):
(WebCore::ContentFilter::continueAfterResponseReceived):
(WebCore::ContentFilter::continueAfterDataReceived):
(WebCore::ContentFilter::continueAfterNotifyFinished):
(WebCore::ContentFilter::didDecide):
(WebCore::ContentFilter::deliverResourceData):
(WebCore::ContentFilter::url):
(WebCore::ContentFilter::deliverStoredResourceData):

  • loader/ContentFilter.h:

(WebCore::ContentFilter::blockedError const):
(WebCore::ContentFilter::isAllowed const):
(WebCore::ContentFilter::responseReceived const):

  • loader/ContentFilterClient.h:
  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::notifyFinished):
(WebCore::DocumentLoader::willSendRequest):
(WebCore::DocumentLoader::responseReceived):
(WebCore::DocumentLoader::dataReceived):
(WebCore::DocumentLoader::detachFromFrame):
(WebCore::DocumentLoader::startLoadingMainResource):
(WebCore::DocumentLoader::clearMainResource):
(WebCore::DocumentLoader::becomeMainResourceClient):
(WebCore::DocumentLoader::contentFilterDidBlock):
(WebCore::DocumentLoader::handleContentFilterDidBlock):
(WebCore::DocumentLoader::handleContentFilterProvisionalLoadFailure):
(WebCore::DocumentLoader::contentFilterWillHandleProvisionalLoadFailure):
(WebCore::DocumentLoader::contentFilterHandleProvisionalLoadFailure):

  • loader/DocumentLoader.h:
  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::dispatchDidFailProvisionalLoad):

  • loader/PolicyChecker.cpp:

(WebCore::FrameLoader::PolicyChecker::checkNavigationPolicy):

  • loader/SubstituteData.h:

(WebCore::SubstituteData::encode const):
(WebCore::SubstituteData::decode):

  • platform/cocoa/ContentFilterUnblockHandlerCocoa.mm:

(WebCore::ContentFilterUnblockHandler::canHandleRequest const):

Source/WebKit:

Move content filtering from the DocumentLoader class in the WebProcess to the NetworkResourceLoader class in the
Networking process. The NetworkResourceLoader is now a client of the content filter, and will send messages
to the DocumentLoader in the WebProcess to cancel the load when the content filter decided to block the load.
If the content filter is providing replacement data, this will also be sent over IPC to the WebProcess.
Data is not being sent to the WebProcess until the content filter has decided to allow the load, if content
filtering is enabled.

  • NetworkProcess/NetworkResourceLoader.cpp:

(WebKit::NetworkResourceLoader::start):
(WebKit::NetworkResourceLoader::startContentFiltering):
(WebKit::NetworkResourceLoader::didReceiveResponse):
(WebKit::NetworkResourceLoader::didFinishLoading):
(WebKit::NetworkResourceLoader::willSendRedirectedRequest):
(WebKit::NetworkResourceLoader::bufferingTimerFired):
(WebKit::NetworkResourceLoader::sendBuffer):
(WebKit::NetworkResourceLoader::didRetrieveCacheEntry):
(WebKit::NetworkResourceLoader::sendResultForCacheEntry):
(WebKit::NetworkResourceLoader::dataReceivedThroughContentFilter):
(WebKit::NetworkResourceLoader::contentFilterDidBlock):
(WebKit::NetworkResourceLoader::cancelMainResourceLoadForContentFilter):
(WebKit::NetworkResourceLoader::handleProvisionalLoadFailureFromContentFilter):

  • NetworkProcess/NetworkResourceLoader.h:
  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::reloadAfterUnblockedContentFilter):

  • UIProcess/Network/NetworkProcessProxy.h:
  • UIProcess/Network/NetworkProcessProxy.messages.in:
  • WebProcess/Network/WebResourceLoader.cpp:

(WebKit::WebResourceLoader::contentFilterDidBlockLoad):
(WebKit::WebResourceLoader::cancelMainResourceLoadForContentFilter):
(WebKit::WebResourceLoader::handleProvisionalLoadFailureFromContentFilter):
(WebKit::WebResourceLoader::reload):

  • WebProcess/Network/WebResourceLoader.h:
  • WebProcess/Network/WebResourceLoader.messages.in:
Location:
trunk/Source
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r290188 r290189  
     12022-02-18  Per Arne Vollan  <pvollan@apple.com>
     2
     3        Move content filtering to Networking process
     4        https://bugs.webkit.org/show_bug.cgi?id=233760
     5        <rdar://problem/86150702>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Remove content filtering from DocumentLoader when the feature is enabled, since this takes place in the WebContent process.
     10        Modify the ContentFilter class by removing use of the types CachedResoure and CachedRawResource, since objects of these
     11        types are not available in the Networking process. Parameters with these types are replaced with URL parameters.
     12        The new behavior is behind a feature flag, which is not enabled in this patch.
     13
     14        * WebCore.xcodeproj/project.pbxproj:
     15        * loader/ContentFilter.cpp:
     16        (WebCore::ContentFilter::startFilteringMainResource):
     17        (WebCore::ContentFilter::stopFilteringMainResource):
     18        (WebCore::ContentFilter::continueAfterResponseReceived):
     19        (WebCore::ContentFilter::continueAfterDataReceived):
     20        (WebCore::ContentFilter::continueAfterNotifyFinished):
     21        (WebCore::ContentFilter::didDecide):
     22        (WebCore::ContentFilter::deliverResourceData):
     23        (WebCore::ContentFilter::url):
     24        (WebCore::ContentFilter::deliverStoredResourceData):
     25        * loader/ContentFilter.h:
     26        (WebCore::ContentFilter::blockedError const):
     27        (WebCore::ContentFilter::isAllowed const):
     28        (WebCore::ContentFilter::responseReceived const):
     29        * loader/ContentFilterClient.h:
     30        * loader/DocumentLoader.cpp:
     31        (WebCore::DocumentLoader::notifyFinished):
     32        (WebCore::DocumentLoader::willSendRequest):
     33        (WebCore::DocumentLoader::responseReceived):
     34        (WebCore::DocumentLoader::dataReceived):
     35        (WebCore::DocumentLoader::detachFromFrame):
     36        (WebCore::DocumentLoader::startLoadingMainResource):
     37        (WebCore::DocumentLoader::clearMainResource):
     38        (WebCore::DocumentLoader::becomeMainResourceClient):
     39        (WebCore::DocumentLoader::contentFilterDidBlock):
     40        (WebCore::DocumentLoader::handleContentFilterDidBlock):
     41        (WebCore::DocumentLoader::handleContentFilterProvisionalLoadFailure):
     42        (WebCore::DocumentLoader::contentFilterWillHandleProvisionalLoadFailure):
     43        (WebCore::DocumentLoader::contentFilterHandleProvisionalLoadFailure):
     44        * loader/DocumentLoader.h:
     45        * loader/FrameLoader.cpp:
     46        (WebCore::FrameLoader::dispatchDidFailProvisionalLoad):
     47        * loader/PolicyChecker.cpp:
     48        (WebCore::FrameLoader::PolicyChecker::checkNavigationPolicy):
     49        * loader/SubstituteData.h:
     50        (WebCore::SubstituteData::encode const):
     51        (WebCore::SubstituteData::decode):
     52        * platform/cocoa/ContentFilterUnblockHandlerCocoa.mm:
     53        (WebCore::ContentFilterUnblockHandler::canHandleRequest const):
     54
    1552022-02-18  Mark Lam  <mark.lam@apple.com>
    256
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r290188 r290189  
    33693369                A14832CF187F684700DA63A6 /* WebCoreThreadSystemInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = A14832A1187F508700DA63A6 /* WebCoreThreadSystemInterface.h */; settings = {ATTRIBUTES = (Private, ); }; };
    33703370                A1491DA31F859D870095F5D4 /* PaymentSession.h in Headers */ = {isa = PBXBuildFile; fileRef = A1491DA21F859D870095F5D4 /* PaymentSession.h */; };
    3371                 A149786F1ABAF33800CEF7E4 /* ContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A149786D1ABAF33800CEF7E4 /* ContentFilter.h */; };
     3371                A149786F1ABAF33800CEF7E4 /* ContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A149786D1ABAF33800CEF7E4 /* ContentFilter.h */; settings = {ATTRIBUTES = (Private, ); }; };
    33723372                A14978711ABAF3A500CEF7E4 /* PlatformContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A14978701ABAF3A500CEF7E4 /* PlatformContentFilter.h */; settings = {ATTRIBUTES = (Private, ); }; };
    33733373                A14BB0A01F9813B800605A35 /* MockPayment.h in Headers */ = {isa = PBXBuildFile; fileRef = A14BB09E1F9813B800605A35 /* MockPayment.h */; };
  • trunk/Source/WebCore/loader/ContentFilter.cpp

    r287687 r290189  
    114114}
    115115
    116 void ContentFilter::startFilteringMainResource(CachedRawResource& resource)
     116#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     117void ContentFilter::startFilteringMainResource(const URL& url)
    117118{
    118119    if (m_state != State::Stopped)
    119120        return;
    120121
    121     LOG(ContentFiltering, "ContentFilter will start filtering main resource at <%s>.\n", resource.url().string().ascii().data());
     122    LOG(ContentFiltering, "ContentFilter will start filtering main resource at <%{sensitive}s>.\n", url.string().ascii().data());
     123    m_state = State::Filtering;
     124    ASSERT(m_mainResourceURL.isEmpty());
     125    m_mainResourceURL = url;
     126}
     127#else
     128void ContentFilter::startFilteringMainResource(CachedRawResource& resource)
     129{
     130    if (m_state != State::Stopped)
     131        return;
     132
     133    LOG(ContentFiltering, "ContentFilter will start filtering main resource at <%{sensitive}s>.\n", resource.url().string().ascii().data());
    122134    m_state = State::Filtering;
    123135    ASSERT(!m_mainResource);
    124136    m_mainResource = &resource;
    125137}
     138#endif
    126139
    127140void ContentFilter::stopFilteringMainResource()
     
    129142    if (m_state != State::Blocked)
    130143        m_state = State::Stopped;
     144#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     145    m_mainResourceURL = URL();
     146#else
    131147    m_mainResource = nullptr;
     148#endif
    132149}
    133150
     
    143160    }
    144161
     162    m_responseReceived = true;
     163
    145164    return m_state != State::Blocked;
    146165}
    147166
     167#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     168bool ContentFilter::continueAfterDataReceived(const SharedBuffer& data, size_t encodedDataLength)
     169#else
    148170bool ContentFilter::continueAfterDataReceived(const SharedBuffer& data)
     171#endif
    149172{
    150173    Ref<ContentFilterClient> protectedClient { m_client };
    151174
    152175    if (m_state == State::Filtering) {
    153         LOG(ContentFiltering, "ContentFilter received %zu bytes of data from <%s>.\n", data.size(), m_mainResource->url().string().ascii().data());
     176        LOG(ContentFiltering, "ContentFilter received %zu bytes of data from <%{sensitive}s>.\n", data.size(), url().string().ascii().data());
     177
    154178        forEachContentFilterUntilBlocked([data = Ref { data }](auto& contentFilter) {
    155179            contentFilter.addData(data);
    156180        });
    157 
    158         if (m_state == State::Allowed)
    159             deliverResourceData(*m_mainResource);
     181#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     182        if (m_state == State::Allowed) {
     183            deliverStoredResourceData();
     184            deliverResourceData(data, encodedDataLength);
     185        } else
     186            m_buffers.append(ResourceDataItem { RefPtr { &data }, encodedDataLength });
     187#else
     188        if (m_state == State::Allowed) {
     189            ASSERT(m_mainResource->dataBufferingPolicy() == DataBufferingPolicy::BufferData);
     190            if (auto* buffer = m_mainResource->resourceBuffer())
     191                deliverResourceData(buffer->makeContiguous());
     192        }
     193#endif
    160194        return false;
    161195    }
     
    164198}
    165199
     200#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     201bool ContentFilter::continueAfterNotifyFinished(const URL& resourceURL)
     202#else
    166203bool ContentFilter::continueAfterNotifyFinished(CachedResource& resource)
    167 {
     204#endif
     205{
     206    Ref<ContentFilterClient> protectedClient { m_client };
     207#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     208    ASSERT_UNUSED(resourceURL, resourceURL == m_mainResourceURL);
     209#else
    168210    ASSERT_UNUSED(resource, &resource == m_mainResource);
    169     Ref<ContentFilterClient> protectedClient { m_client };
    170 
    171211    if (m_mainResource->errorOccurred())
    172212        return true;
     213#endif
    173214
    174215    if (m_state == State::Filtering) {
    175         LOG(ContentFiltering, "ContentFilter will finish filtering main resource at <%s>.\n", m_mainResource->url().string().ascii().data());
     216        LOG(ContentFiltering, "ContentFilter will finish filtering main resource at <%{sensitive}s>.\n", url().string().ascii().data());
    176217        forEachContentFilterUntilBlocked([](PlatformContentFilter& contentFilter) {
    177218            contentFilter.finishedAddingData();
     
    180221        if (m_state != State::Blocked) {
    181222            m_state = State::Allowed;
    182             deliverResourceData(*m_mainResource);
     223#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     224            deliverStoredResourceData();
     225#else
     226            if (auto* buffer = m_mainResource->resourceBuffer()) {
     227                ASSERT(m_mainResource->dataBufferingPolicy() == DataBufferingPolicy::BufferData);
     228                deliverResourceData(buffer->makeContiguous());
     229            }
     230#endif
    183231        }
    184232
     
    220268    ASSERT(m_state != State::Blocked);
    221269    ASSERT(state == State::Allowed || state == State::Blocked);
    222     LOG(ContentFiltering, "ContentFilter decided load should be %s for main resource at <%s>.\n", state == State::Allowed ? "allowed" : "blocked", m_mainResource ? m_mainResource->url().string().ascii().data() : "");
     270#if !LOG_DISABLED
     271    LOG(ContentFiltering, "ContentFilter decided load should be %s for main resource at <%{sensitive}s>.\n", state == State::Allowed ? "allowed" : "blocked", url().string().ascii().data());
     272#endif // !LOG_DISABLED
    223273    m_state = state;
    224274    if (m_state != State::Blocked)
     
    229279}
    230280
    231 void ContentFilter::deliverResourceData(CachedResource& resource)
     281void ContentFilter::deliverResourceData(const SharedBuffer& buffer, size_t encodedDataLength)
    232282{
    233283    ASSERT(m_state == State::Allowed);
    234     ASSERT(resource.dataBufferingPolicy() == DataBufferingPolicy::BufferData);
    235     if (auto* resourceBuffer = resource.resourceBuffer())
    236         m_client.dataReceivedThroughContentFilter(resourceBuffer->makeContiguous());
     284#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     285    m_client.dataReceivedThroughContentFilter(buffer, encodedDataLength);
     286#else
     287    UNUSED_PARAM(encodedDataLength);
     288    m_client.dataReceivedThroughContentFilter(buffer);
     289#endif
     290}
     291
     292URL ContentFilter::url()
     293{
     294#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     295    return m_mainResourceURL;
     296#else
     297    if (m_mainResource)
     298        return m_mainResource->url();
     299    return URL();
     300#endif
    237301}
    238302
     
    246310}
    247311
     312#if !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    248313bool ContentFilter::continueAfterSubstituteDataRequest(const DocumentLoader& activeLoader, const SubstituteData& substituteData)
    249314{
     
    260325    return true;
    261326}
     327#endif
    262328
    263329bool ContentFilter::willHandleProvisionalLoadFailure(const ResourceError& error) const
     
    284350}
    285351
     352#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     353void ContentFilter::deliverStoredResourceData()
     354{
     355    for (auto& buffer : m_buffers)
     356        deliverResourceData(*buffer.buffer, buffer.encodedDataLength);
     357    m_buffers.clear();
     358}
     359#endif
     360
    286361} // namespace WebCore
    287362
  • trunk/Source/WebCore/loader/ContentFilter.h

    r287687 r290189  
    5151    template <typename T> static void addType() { types().append(type<T>()); }
    5252
    53     static std::unique_ptr<ContentFilter> create(ContentFilterClient&);
    54     ~ContentFilter();
     53    WEBCORE_EXPORT static std::unique_ptr<ContentFilter> create(ContentFilterClient&);
     54    WEBCORE_EXPORT ~ContentFilter();
    5555
    5656    static const char* urlScheme() { return "x-apple-content-filter"; }
    5757
     58#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     59    WEBCORE_EXPORT void startFilteringMainResource(const URL&);
     60#else
    5861    void startFilteringMainResource(CachedRawResource&);
    59     void stopFilteringMainResource();
     62#endif
     63    WEBCORE_EXPORT void stopFilteringMainResource();
    6064
    61     bool continueAfterWillSendRequest(ResourceRequest&, const ResourceResponse&);
    62     bool continueAfterResponseReceived(const ResourceResponse&);
     65    WEBCORE_EXPORT bool continueAfterWillSendRequest(ResourceRequest&, const ResourceResponse&);
     66    WEBCORE_EXPORT bool continueAfterResponseReceived(const ResourceResponse&);
     67#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     68    WEBCORE_EXPORT bool continueAfterDataReceived(const SharedBuffer&, size_t encodedDataLength);
     69    WEBCORE_EXPORT bool continueAfterNotifyFinished(const URL& resourceURL);
     70#else
    6371    bool continueAfterDataReceived(const SharedBuffer&);
    6472    bool continueAfterNotifyFinished(CachedResource&);
     73#endif
    6574
    6675    static bool continueAfterSubstituteDataRequest(const DocumentLoader& activeLoader, const SubstituteData&);
    6776    bool willHandleProvisionalLoadFailure(const ResourceError&) const;
    68     void handleProvisionalLoadFailure(const ResourceError&);
     77    WEBCORE_EXPORT void handleProvisionalLoadFailure(const ResourceError&);
    6978
     79    const ResourceError& blockedError() const { return m_blockedError; }
     80    bool isAllowed() const { return m_state == State::Allowed; }
     81    bool responseReceived() const { return m_responseReceived; }
     82   
    7083private:
    7184    using State = PlatformContentFilter::State;
     
    8396    template <typename Function> void forEachContentFilterUntilBlocked(Function&&);
    8497    void didDecide(State);
    85     void deliverResourceData(CachedResource&);
    86 
     98    void deliverResourceData(const SharedBuffer&, size_t encodedDataLength = 0);
     99#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     100    void deliverStoredResourceData();
     101#endif
     102   
     103    URL url();
     104   
    87105    Container m_contentFilters;
    88106    ContentFilterClient& m_client;
     107#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     108    URL m_mainResourceURL;
     109    struct ResourceDataItem {
     110        RefPtr<const SharedBuffer> buffer;
     111        size_t encodedDataLength;
     112    };
     113   
     114    Vector<ResourceDataItem> m_buffers;
     115#else
    89116    CachedResourceHandle<CachedRawResource> m_mainResource;
     117#endif
    90118    const PlatformContentFilter* m_blockingContentFilter { nullptr };
    91119    State m_state { State::Stopped };
    92120    ResourceError m_blockedError;
    93121    bool m_isLoadingBlockedPage { false };
     122    bool m_responseReceived { false };
    94123};
    95124
  • trunk/Source/WebCore/loader/ContentFilterClient.h

    r287684 r290189  
    4343    virtual void deref() const = 0;
    4444
     45#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     46    virtual void dataReceivedThroughContentFilter(const SharedBuffer&, size_t) = 0;
     47#else
    4548    virtual void dataReceivedThroughContentFilter(const SharedBuffer&) = 0;
     49#endif
    4650    virtual ResourceError contentFilterDidBlock(ContentFilterUnblockHandler, String&& unblockRequestDeniedScript) = 0;
    4751    virtual void cancelMainResourceLoadForContentFilter(const ResourceError&) = 0;
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r290167 r290189  
    420420{
    421421    ASSERT(isMainThread());
    422 #if ENABLE(CONTENT_FILTERING)
     422#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    423423    if (m_contentFilter && !m_contentFilter->continueAfterNotifyFinished(resource))
    424424        return;
     
    711711    }
    712712
    713 #if ENABLE(CONTENT_FILTERING)
     713#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    714714    if (m_contentFilter && !m_contentFilter->continueAfterWillSendRequest(newRequest, redirectResponse))
    715715        return completionHandler(WTFMove(newRequest));
     
    903903    CompletionHandlerCallingScope completionHandlerCaller(WTFMove(completionHandler));
    904904
    905 #if ENABLE(CONTENT_FILTERING)
     905#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    906906    if (m_contentFilter && !m_contentFilter->continueAfterResponseReceived(response))
    907907        return;
     
    13231323void DocumentLoader::dataReceived(const SharedBuffer& buffer)
    13241324{
    1325 #if ENABLE(CONTENT_FILTERING)
     1325#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    13261326    if (m_contentFilter && !m_contentFilter->continueAfterDataReceived(buffer))
    13271327        return;
     
    14641464    if (m_mainResource && m_mainResource->hasClient(*this))
    14651465        m_mainResource->removeClient(*this);
    1466 #if ENABLE(CONTENT_FILTERING)
     1466#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    14671467    if (m_contentFilter)
    14681468        m_contentFilter->stopFilteringMainResource();
     
    20262026    }
    20272027
    2028 #if ENABLE(CONTENT_FILTERING)
     2028#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    20292029    m_contentFilter = !m_substituteData.isValid() ? ContentFilter::create(*this) : nullptr;
    20302030#endif
     
    22312231    if (m_mainResource && m_mainResource->hasClient(*this))
    22322232        m_mainResource->removeClient(*this);
    2233 #if ENABLE(CONTENT_FILTERING)
     2233#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    22342234    if (m_contentFilter)
    22352235        m_contentFilter->stopFilteringMainResource();
     
    23582358void DocumentLoader::becomeMainResourceClient()
    23592359{
    2360 #if ENABLE(CONTENT_FILTERING)
     2360#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    23612361    if (m_contentFilter)
    23622362        m_contentFilter->startFilteringMainResource(*m_mainResource);
     
    24152415}
    24162416
     2417#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     2418void DocumentLoader::dataReceivedThroughContentFilter(const SharedBuffer& buffer)
     2419{
     2420    dataReceived(buffer);
     2421}
     2422
     2423void DocumentLoader::cancelMainResourceLoadForContentFilter(const ResourceError& error)
     2424{
     2425    cancelMainResourceLoad(error);
     2426}
     2427
     2428ResourceError DocumentLoader::contentFilterDidBlock(ContentFilterUnblockHandler unblockHandler, String&& unblockRequestDeniedScript)
     2429{
     2430    return handleContentFilterDidBlock(unblockHandler, WTFMove(unblockRequestDeniedScript));
     2431}
     2432
     2433void DocumentLoader::handleProvisionalLoadFailureFromContentFilter(const URL& blockedPageURL, SubstituteData& substituteData)
     2434{
     2435    frameLoader()->load(FrameLoadRequest(*frame(), blockedPageURL, substituteData));
     2436}
     2437#endif // ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     2438
    24172439#if ENABLE(CONTENT_FILTERING)
    2418 void DocumentLoader::dataReceivedThroughContentFilter(const SharedBuffer& buffer)
    2419 {
    2420     dataReceived(buffer);
    2421 }
    2422 
    2423 void DocumentLoader::cancelMainResourceLoadForContentFilter(const ResourceError& error)
    2424 {
    2425     cancelMainResourceLoad(error);
    2426 }
    2427 
    2428 void DocumentLoader::handleProvisionalLoadFailureFromContentFilter(const URL& blockedPageURL, SubstituteData& substituteData)
    2429 {
    2430     frameLoader()->load(FrameLoadRequest(*frame(), blockedPageURL, substituteData));
    2431 }
    2432 
    2433 ResourceError DocumentLoader::contentFilterDidBlock(ContentFilterUnblockHandler unblockHandler, String&& unblockRequestDeniedScript)
     2440ResourceError DocumentLoader::handleContentFilterDidBlock(ContentFilterUnblockHandler unblockHandler, String&& unblockRequestDeniedScript)
    24342441{
    24352442    unblockHandler.setUnreachableURL(documentURL());
     
    24412448    }
    24422449    frameLoader()->client().contentFilterDidBlockLoad(WTFMove(unblockHandler));
    2443     return frameLoader()->blockedByContentFilterError(request());
    2444 }
     2450    auto error = frameLoader()->blockedByContentFilterError(request());
     2451
     2452#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     2453    m_blockedByContentFilter = true;
     2454    m_blockedError = error;
     2455#endif
     2456
     2457    return error;
     2458}
     2459
     2460void DocumentLoader::handleContentFilterProvisionalLoadFailure(const URL& blockedPageURL, const SubstituteData& substituteData)
     2461{
     2462    frameLoader()->load(FrameLoadRequest(*frame(), blockedPageURL, substituteData));
     2463}
     2464
     2465bool DocumentLoader::contentFilterWillHandleProvisionalLoadFailure(const ResourceError& error)
     2466{
     2467#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     2468    return m_blockedByContentFilter && m_blockedError.errorCode() == error.errorCode() && m_blockedError.domain() == error.domain();
     2469#else
     2470    return m_contentFilter && m_contentFilter->willHandleProvisionalLoadFailure(error);
     2471#endif
     2472}
     2473
     2474void DocumentLoader::contentFilterHandleProvisionalLoadFailure(const ResourceError& error)
     2475{
     2476#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     2477    UNUSED_PARAM(error);
     2478#else
     2479    if (m_contentFilter)
     2480        m_contentFilter->handleProvisionalLoadFailure(error);
     2481#endif
     2482}
     2483
    24452484#endif // ENABLE(CONTENT_FILTERING)
    24462485
  • trunk/Source/WebCore/loader/DocumentLoader.h

    r289134 r290189  
    160160    , public FrameDestructionObserver
    161161    , public ContentSecurityPolicyClient
    162 #if ENABLE(CONTENT_FILTERING)
     162#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    163163    , public ContentFilterClient
    164164#endif
     
    403403
    404404#if ENABLE(CONTENT_FILTERING)
     405#if !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    405406    ContentFilter* contentFilter() const { return m_contentFilter.get(); }
    406407    void ref() const final { RefCounted<DocumentLoader>::ref(); }
    407408    void deref() const final { RefCounted<DocumentLoader>::deref(); }
    408409#endif
     410    WEBCORE_EXPORT ResourceError handleContentFilterDidBlock(ContentFilterUnblockHandler, String&& unblockRequestDeniedScript);
     411    WEBCORE_EXPORT void handleContentFilterProvisionalLoadFailure(const URL& blockedPageURL, const SubstituteData&);
     412#endif
    409413
    410414    void startIconLoading();
     
    451455    bool isContinuingLoadAfterProvisionalLoadStarted() const { return m_isContinuingLoadAfterProvisionalLoadStarted; }
    452456    void setIsContinuingLoadAfterProvisionalLoadStarted(bool isContinuingLoadAfterProvisionalLoadStarted) { m_isContinuingLoadAfterProvisionalLoadStarted = isContinuingLoadAfterProvisionalLoadStarted; }
     457
     458#if ENABLE(CONTENT_FILTERING)
     459    bool contentFilterWillHandleProvisionalLoadFailure(const ResourceError&);
     460    void contentFilterHandleProvisionalLoadFailure(const ResourceError&);
     461#endif
    453462
    454463protected:
     
    504513    void responseReceived(const ResourceResponse&, CompletionHandler<void()>&&);
    505514
    506 #if ENABLE(CONTENT_FILTERING)
     515#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    507516    // ContentFilterClient
    508517    WEBCORE_EXPORT void dataReceivedThroughContentFilter(const SharedBuffer&) final;
     
    656665
    657666#if ENABLE(CONTENT_FILTERING)
     667#if !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    658668    std::unique_ptr<ContentFilter> m_contentFilter;
     669#else
     670    bool m_blockedByContentFilter { false };
     671    ResourceError m_blockedError;
     672#endif
    659673#endif
    660674
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r289203 r290189  
    24542454
    24552455#if ENABLE(CONTENT_FILTERING)
    2456     auto contentFilter = provisionalDocumentLoader.contentFilter();
    24572456    auto contentFilterWillContinueLoading = false;
    24582457#endif
     
    24622461        willContinueLoading = WillContinueLoading::Yes;
    24632462#if ENABLE(CONTENT_FILTERING)
    2464     if (contentFilter && contentFilter->willHandleProvisionalLoadFailure(error)) {
     2463    if (provisionalDocumentLoader.contentFilterWillHandleProvisionalLoadFailure(error)) {
    24652464        willContinueLoading = WillContinueLoading::Yes;
    24662465        contentFilterWillContinueLoading = true;
     
    24722471#if ENABLE(CONTENT_FILTERING)
    24732472    if (contentFilterWillContinueLoading)
    2474         contentFilter->handleProvisionalLoadFailure(error);
     2473        provisionalDocumentLoader.contentFilterHandleProvisionalLoadFailure(error);
    24752474#endif
    24762475
  • trunk/Source/WebCore/loader/PolicyChecker.cpp

    r289549 r290189  
    142142    if (substituteData.isValid() && !substituteData.failingURL().isEmpty()) {
    143143        bool shouldContinue = true;
    144 #if ENABLE(CONTENT_FILTERING)
     144#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
    145145        if (auto loader = m_frame.loader().activeDocumentLoader())
    146146            shouldContinue = ContentFilter::continueAfterSubstituteDataRequest(*loader, substituteData);
  • trunk/Source/WebCore/loader/SubstituteData.h

    r287021 r290189  
    6060        const URL& failingURL() const { return m_failingURL; }
    6161        const ResourceResponse& response() const { return m_response; }
    62        
     62
     63        template<class Encoder> void encode(Encoder&) const;
     64        template<class Decoder> static std::optional<SubstituteData> decode(Decoder&);
     65
    6366    private:
    6467        RefPtr<FragmentedSharedBuffer> m_content;
     
    6871    };
    6972
     73template<class Encoder>
     74void SubstituteData::encode(Encoder& encoder) const
     75{
     76    encoder << m_content << m_failingURL << m_response << m_shouldRevealToSessionHistory;
     77}
     78
     79template<class Decoder>
     80std::optional<SubstituteData> SubstituteData::decode(Decoder& decoder)
     81{
     82    std::optional<RefPtr<FragmentedSharedBuffer>> content;
     83    decoder >> content;
     84    if (!content)
     85        return std::nullopt;
     86
     87    std::optional<URL> failingURL;
     88    decoder >> failingURL;
     89    if (!failingURL)
     90        return std::nullopt;
     91
     92    std::optional<ResourceResponse> response;
     93    decoder >> response;
     94    if (!response)
     95        return std::nullopt;
     96
     97    std::optional<SessionHistoryVisibility> shouldRevealToSessionHistory;
     98    decoder >> shouldRevealToSessionHistory;
     99    if (!shouldRevealToSessionHistory)
     100        return std::nullopt;
     101
     102    return { { WTFMove(*content), *failingURL, *response, *shouldRevealToSessionHistory } };
     103}
     104
    70105} // namespace WebCore
  • trunk/Source/WebKit/ChangeLog

    r290187 r290189  
     12022-02-18  Per Arne Vollan  <pvollan@apple.com>
     2
     3        Move content filtering to Networking process
     4        https://bugs.webkit.org/show_bug.cgi?id=233760
     5        <rdar://problem/86150702>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Move content filtering from the DocumentLoader class in the WebProcess to the NetworkResourceLoader class in the
     10        Networking process. The NetworkResourceLoader is now a client of the content filter, and will send messages
     11        to the DocumentLoader in the WebProcess to cancel the load when the content filter decided to block the load.
     12        If the content filter is providing replacement data, this will also be sent over IPC to the WebProcess.
     13        Data is not being sent to the WebProcess until the content filter has decided to allow the load, if content
     14        filtering is enabled.
     15
     16        * NetworkProcess/NetworkResourceLoader.cpp:
     17        (WebKit::NetworkResourceLoader::start):
     18        (WebKit::NetworkResourceLoader::startContentFiltering):
     19        (WebKit::NetworkResourceLoader::didReceiveResponse):
     20        (WebKit::NetworkResourceLoader::didFinishLoading):
     21        (WebKit::NetworkResourceLoader::willSendRedirectedRequest):
     22        (WebKit::NetworkResourceLoader::bufferingTimerFired):
     23        (WebKit::NetworkResourceLoader::sendBuffer):
     24        (WebKit::NetworkResourceLoader::didRetrieveCacheEntry):
     25        (WebKit::NetworkResourceLoader::sendResultForCacheEntry):
     26        (WebKit::NetworkResourceLoader::dataReceivedThroughContentFilter):
     27        (WebKit::NetworkResourceLoader::contentFilterDidBlock):
     28        (WebKit::NetworkResourceLoader::cancelMainResourceLoadForContentFilter):
     29        (WebKit::NetworkResourceLoader::handleProvisionalLoadFailureFromContentFilter):
     30        * NetworkProcess/NetworkResourceLoader.h:
     31        * UIProcess/Network/NetworkProcessProxy.cpp:
     32        (WebKit::NetworkProcessProxy::reloadAfterUnblockedContentFilter):
     33        * UIProcess/Network/NetworkProcessProxy.h:
     34        * UIProcess/Network/NetworkProcessProxy.messages.in:
     35        * WebProcess/Network/WebResourceLoader.cpp:
     36        (WebKit::WebResourceLoader::contentFilterDidBlockLoad):
     37        (WebKit::WebResourceLoader::cancelMainResourceLoadForContentFilter):
     38        (WebKit::WebResourceLoader::handleProvisionalLoadFailureFromContentFilter):
     39        (WebKit::WebResourceLoader::reload):
     40        * WebProcess/Network/WebResourceLoader.h:
     41        * WebProcess/Network/WebResourceLoader.messages.in:
     42
    1432022-02-18  Per Arne Vollan  <pvollan@apple.com>
    244
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp

    r289134 r290189  
    6868#endif
    6969
     70#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     71#include <WebCore/ContentFilter.h>
     72#include <WebCore/ContentFilterUnblockHandler.h>
     73#endif
     74
    7075#define LOADER_RELEASE_LOG(fmt, ...) RELEASE_LOG(Network, "%p - [pageProxyID=%" PRIu64 ", webPageID=%" PRIu64 ", frameID=%" PRIu64 ", resourceID=%" PRIu64 ", isMainResource=%d, destination=%u, isSynchronous=%d] NetworkResourceLoader::" fmt, this, m_parameters.webPageProxyID.toUInt64(), m_parameters.webPageID.toUInt64(), m_parameters.webFrameID.toUInt64(), m_parameters.identifier.toUInt64(), isMainResource(), static_cast<unsigned>(m_parameters.options.destination), isSynchronous(), ##__VA_ARGS__)
    7176#define LOADER_RELEASE_LOG_ERROR(fmt, ...) RELEASE_LOG_ERROR(Network, "%p - [pageProxyID=%" PRIu64 ", webPageID=%" PRIu64 ", frameID=%" PRIu64 ", resourceID=%" PRIu64 ", isMainResource=%d, destination=%u, isSynchronous=%d] NetworkResourceLoader::" fmt, this, m_parameters.webPageProxyID.toUInt64(), m_parameters.webPageID.toUInt64(), m_parameters.webFrameID.toUInt64(), m_parameters.identifier.toUInt64(), isMainResource(), static_cast<unsigned>(m_parameters.options.destination), isSynchronous(), ##__VA_ARGS__)
     
    188193    m_wasStarted = true;
    189194
     195    auto newRequest = ResourceRequest { originalRequest() };
     196#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     197    startContentFiltering(newRequest);
     198#endif
     199
    190200    if (m_networkLoadChecker) {
    191         m_networkLoadChecker->check(ResourceRequest { originalRequest() }, this, [this, weakThis = WeakPtr { *this }] (auto&& result) {
     201        m_networkLoadChecker->check(ResourceRequest { newRequest }, this, [this, weakThis = WeakPtr { *this }] (auto&& result) {
    192202            if (!weakThis)
    193203                return;
     
    218228    }
    219229    // FIXME: Remove that code path once m_networkLoadChecker is used for all network loads.
    220     if (canUseCache(originalRequest())) {
     230    if (canUseCache(newRequest)) {
    221231        retrieveCacheEntry(originalRequest());
    222232        return;
    223233    }
    224234
    225     startNetworkLoad(ResourceRequest { originalRequest() }, FirstLoad::Yes);
    226 }
     235    startNetworkLoad(ResourceRequest { newRequest }, FirstLoad::Yes);
     236}
     237
     238#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     239void NetworkResourceLoader::startContentFiltering(ResourceRequest& request)
     240{
     241    if (!isMainResource())
     242        return;
     243    m_contentFilter = ContentFilter::create(*this);
     244    if (!m_contentFilter->continueAfterWillSendRequest(request, ResourceResponse()))
     245        return;
     246    m_contentFilter->startFilteringMainResource(request.url());
     247}
     248#endif
    227249
    228250void NetworkResourceLoader::retrieveCacheEntry(const ResourceRequest& request)
     
    693715    LOADER_RELEASE_LOG("didReceiveResponse: (httpStatusCode=%d, MIMEType=%" PUBLIC_LOG_STRING ", expectedContentLength=%" PRId64 ", hasCachedEntryForValidation=%d, hasNetworkLoadChecker=%d)", receivedResponse.httpStatusCode(), receivedResponse.mimeType().utf8().data(), receivedResponse.expectedContentLength(), !!m_cacheEntryForValidation, !!m_networkLoadChecker);
    694716
     717#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     718    if (m_contentFilter && !m_contentFilter->continueAfterResponseReceived(receivedResponse))
     719        return completionHandler(PolicyAction::Ignore);
     720#endif
     721
    695722    if (isMainResource())
    696723        didReceiveMainResourceResponse(receivedResponse);
     
    905932            sendBuffer(*m_bufferedData.get(), -1);
    906933        }
     934#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     935        if (m_contentFilter) {
     936            m_contentFilter->continueAfterNotifyFinished(m_parameters.request.url());
     937            m_contentFilter->stopFilteringMainResource();
     938        }
     939#endif
     940
    907941        send(Messages::WebResourceLoader::DidFinishResourceLoad(networkLoadMetrics));
    908942    }
     
    9941028        m_firstResponseURL = redirectResponse.url();
    9951029
     1030#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     1031    if (m_contentFilter && !m_contentFilter->continueAfterWillSendRequest(request, redirectResponse))
     1032        return;
     1033#endif
     1034
    9961035    std::optional<WebCore::PrivateClickMeasurement::AttributionTriggerData> privateClickMeasurementAttributionTriggerData;
    9971036    if (!sessionID().isEphemeral()) {
     
    12521291        return;
    12531292
     1293#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     1294    auto sharedBuffer = m_bufferedData.takeAsContiguous();
     1295    bool shouldFilter = m_contentFilter && !m_contentFilter->continueAfterDataReceived(sharedBuffer, m_bufferedDataEncodedDataLength);
     1296    if (!shouldFilter)
     1297        send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferCopy(sharedBuffer.get()), m_bufferedDataEncodedDataLength));
     1298#else
    12541299    send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferCopy(*m_bufferedData.get()), m_bufferedDataEncodedDataLength));
    1255 
     1300#endif
    12561301    m_bufferedData.empty();
    12571302    m_bufferedDataEncodedDataLength = 0;
     
    12611306{
    12621307    ASSERT(!isSynchronous());
     1308
     1309#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     1310    if (m_contentFilter && !m_contentFilter->continueAfterDataReceived(buffer.makeContiguous(), encodedDataLength))
     1311        return;
     1312#endif
    12631313
    12641314    send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferCopy(buffer), encodedDataLength));
     
    13081358    auto response = entry->response();
    13091359
     1360#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     1361    if (m_contentFilter && !m_contentFilter->responseReceived() && !m_contentFilter->continueAfterResponseReceived(response))
     1362        return;
     1363#endif
     1364
    13101365    if (isMainResource())
    13111366        didReceiveMainResourceResponse(response);
     
    13591414#if ENABLE(SHAREABLE_RESOURCE)
    13601415    if (!entry->shareableResourceHandle().isNull()) {
     1416#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     1417        if (m_contentFilter && !m_contentFilter->continueAfterDataReceived(entry->buffer()->makeContiguous(), entry->buffer()->size())) {
     1418            m_contentFilter->continueAfterNotifyFinished(m_parameters.request.url());
     1419            m_contentFilter->stopFilteringMainResource();
     1420            return;
     1421        }
     1422#endif
    13611423        send(Messages::WebResourceLoader::DidReceiveResource(entry->shareableResourceHandle()));
    13621424        return;
     
    13821444
    13831445    sendBuffer(*entry->buffer(), entry->buffer()->size());
     1446#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     1447    if (m_contentFilter) {
     1448        m_contentFilter->continueAfterNotifyFinished(m_parameters.request.url());
     1449        m_contentFilter->stopFilteringMainResource();
     1450    }
     1451#endif
    13841452    send(Messages::WebResourceLoader::DidFinishResourceLoad(networkLoadMetrics));
    13851453}
     
    16981766}
    16991767
     1768#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     1769void NetworkResourceLoader::dataReceivedThroughContentFilter(const SharedBuffer& buffer, size_t encodedDataLength)
     1770{
     1771    send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferCopy(buffer), encodedDataLength));
     1772}
     1773
     1774WebCore::ResourceError NetworkResourceLoader::contentFilterDidBlock(WebCore::ContentFilterUnblockHandler unblockHandler, String&& unblockRequestDeniedScript)
     1775{
     1776    send(Messages::WebResourceLoader::ContentFilterDidBlockLoad(unblockHandler, unblockRequestDeniedScript));
     1777    if (!unblockHandler.needsUIProcess()) {
     1778        unblockHandler.requestUnblockAsync([this, protectedThis = Ref { *this }](bool unblocked) {
     1779            if (!unblocked)
     1780                return;
     1781            m_connection->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::ReloadAfterUnblockedContentFilter(m_parameters.webPageProxyID), 0);
     1782        });
     1783    }
     1784    return WebKit::blockedByContentFilterError(m_parameters.request);
     1785}
     1786
     1787void NetworkResourceLoader::cancelMainResourceLoadForContentFilter(const WebCore::ResourceError& error)
     1788{
     1789    RELEASE_ASSERT(m_contentFilter);
     1790    m_contentFilter->handleProvisionalLoadFailure(error);
     1791}
     1792
     1793void NetworkResourceLoader::handleProvisionalLoadFailureFromContentFilter(const URL& blockedPageURL, WebCore::SubstituteData& substituteData)
     1794{
     1795    if (substituteData.isValid())
     1796        send(Messages::WebResourceLoader::HandleProvisionalLoadFailureFromContentFilter(blockedPageURL, substituteData));
     1797    else {
     1798        RELEASE_ASSERT(m_contentFilter);
     1799        auto& error = m_contentFilter->blockedError();
     1800        send(Messages::WebResourceLoader::CancelMainResourceLoadForContentFilter(error));
     1801    }
     1802}
     1803#endif // ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     1804
    17001805} // namespace WebKit
    17011806
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h

    r289134 r290189  
    3535#include "NetworkResourceLoadParameters.h"
    3636#include "PrivateRelayed.h"
     37#include <WebCore/ContentFilterClient.h>
    3738#include <WebCore/ContentSecurityPolicyClient.h>
    3839#include <WebCore/CrossOriginAccessControl.h>
     
    4647namespace WebCore {
    4748class BlobDataFileReference;
     49class ContentFilter;
    4850class FormData;
    4951class NetworkStorageSession;
     
    7375    , public WebCore::ContentSecurityPolicyClient
    7476    , public WebCore::CrossOriginAccessControlCheckDisabler
     77#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     78    , public WebCore::ContentFilterClient
     79#endif
    7580    , public CanMakeWeakPtr<NetworkResourceLoader> {
    7681public:
     
    9398    void didReceiveNetworkResourceLoaderMessage(IPC::Connection&, IPC::Decoder&);
    9499
    95     void continueWillSendRequest(WebCore::ResourceRequest&& newRequest, bool isAllowedToAskUserForCredentials);
     100    void continueWillSendRequest(WebCore::ResourceRequest&&, bool isAllowedToAskUserForCredentials);
    96101
    97102    void setResponse(WebCore::ResourceResponse&& response) { m_response = WTFMove(response); }
     
    156161    bool isAppInitiated();
    157162
     163#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     164    void ref() const final { RefCounted<NetworkResourceLoader>::ref(); }
     165    void deref() const final { RefCounted<NetworkResourceLoader>::deref(); }
     166#endif
     167
    158168private:
    159169    NetworkResourceLoader(NetworkResourceLoadParameters&&, NetworkConnectionToWebProcess&, Messages::NetworkConnectionToWebProcess::PerformSynchronousLoadDelayedReply&&);
     
    162172    IPC::Connection* messageSenderConnection() const override;
    163173    uint64_t messageSenderDestinationID() const override { return m_parameters.identifier.toUInt64(); }
     174
     175#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     176    // ContentFilterClient
     177    void dataReceivedThroughContentFilter(const WebCore::SharedBuffer&, size_t) final;
     178    WebCore::ResourceError contentFilterDidBlock(WebCore::ContentFilterUnblockHandler, String&& unblockRequestDeniedScript) final;
     179    void cancelMainResourceLoadForContentFilter(const WebCore::ResourceError&) final;
     180    void handleProvisionalLoadFailureFromContentFilter(const URL& blockedPageURL, WebCore::SubstituteData&) final;
     181#endif
    164182
    165183    bool canUseCache(const WebCore::ResourceRequest&) const;
     
    220238
    221239    ResourceLoadInfo resourceLoadInfo();
     240
     241#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     242    void startContentFiltering(WebCore::ResourceRequest&);
     243#endif
    222244
    223245    const NetworkResourceLoadParameters m_parameters;
     
    265287    URL m_firstResponseURL; // First URL in response's URL list (https://fetch.spec.whatwg.org/#concept-response-url-list).
    266288    std::optional<WebCore::CrossOriginOpenerPolicyEnforcementResult> m_currentCoopEnforcementResult;
     289
     290#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     291    std::unique_ptr<WebCore::ContentFilter> m_contentFilter;
     292#endif
     293
    267294    PrivateRelayed m_privateRelayed { PrivateRelayed::No };
    268295};
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r290026 r290189  
    2929#include "APIContentRuleList.h"
    3030#include "APICustomProtocolManagerClient.h"
     31#include "APINavigation.h"
    3132#include "AuthenticationChallengeProxy.h"
    3233#include "AuthenticationManager.h"
     
    605606}
    606607
     608#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     609void NetworkProcessProxy::reloadAfterUnblockedContentFilter(WebPageProxyIdentifier pageID)
     610{
     611    if (auto* page = WebProcessProxy::webPage(pageID))
     612        page->reload({ });
     613}
     614#endif
     615
    607616#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
    608617void NetworkProcessProxy::dumpResourceLoadStatistics(PAL::SessionID sessionID, CompletionHandler<void(String)>&& completionHandler)
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r289508 r290189  
    255255    void resourceLoadDidCompleteWithError(WebPageProxyIdentifier, ResourceLoadInfo&&, WebCore::ResourceResponse&&, WebCore::ResourceError&&);
    256256
     257#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     258    void reloadAfterUnblockedContentFilter(WebPageProxyIdentifier);
     259#endif
     260
    257261#if ENABLE(APP_BOUND_DOMAINS)
    258262    void hasAppBoundSession(PAL::SessionID, CompletionHandler<void(bool)>&&);
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in

    r289508 r290189  
    7777    ResourceLoadDidReceiveResponse(WebKit::WebPageProxyIdentifier pageIdentifier, struct WebKit::ResourceLoadInfo resourceLoadInfo, WebCore::ResourceResponse response)
    7878    ResourceLoadDidCompleteWithError(WebKit::WebPageProxyIdentifier pageIdentifier, struct WebKit::ResourceLoadInfo resourceLoadInfo, WebCore::ResourceResponse response, WebCore::ResourceError error)
     79   
     80#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     81    ReloadAfterUnblockedContentFilter(WebKit::WebPageProxyIdentifier pageIdentifier)
     82#endif
    7983
    8084    TriggerBrowsingContextGroupSwitchForNavigation(WebKit::WebPageProxyIdentifier pageIdentifier, uint64_t navigationID, enum:uint8_t WebCore::BrowsingContextGroupSwitchDecision browsingContextGroupSwitchDecision, WebCore::RegistrableDomain responseDomain, WebKit::NetworkResourceLoadIdentifier existingNetworkResourceLoadIdentifierToResume) -> (bool success) Async
  • trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.cpp

    r289134 r290189  
    5555#include <WebCore/ResourceLoader.h>
    5656#include <WebCore/SubresourceLoader.h>
     57#include <WebCore/SubstituteData.h>
    5758#include <wtf/CompletionHandler.h>
    5859
     
    350351#endif
    351352
     353#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     354void WebResourceLoader::contentFilterDidBlockLoad(const WebCore::ContentFilterUnblockHandler& unblockHandler, String&& unblockRequestDeniedScript)
     355{
     356    if (!m_coreLoader || !m_coreLoader->documentLoader())
     357        return;
     358    m_coreLoader->documentLoader()->handleContentFilterDidBlock(unblockHandler, WTFMove(unblockRequestDeniedScript));
     359}
     360
     361void WebResourceLoader::cancelMainResourceLoadForContentFilter(const WebCore::ResourceError& error)
     362{
     363    if (!m_coreLoader || !m_coreLoader->documentLoader())
     364        return;
     365    m_coreLoader->documentLoader()->cancelMainResourceLoad(error);
     366}
     367
     368void WebResourceLoader::handleProvisionalLoadFailureFromContentFilter(const URL& blockedPageURL, const WebCore::SubstituteData& substituteData)
     369{
     370    if (!m_coreLoader || !m_coreLoader->documentLoader() || !substituteData.isValid())
     371        return;
     372    m_coreLoader->documentLoader()->handleContentFilterProvisionalLoadFailure(blockedPageURL, substituteData);
     373}
     374#endif // ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     375
    352376} // namespace WebKit
    353377
  • trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.h

    r289018 r290189  
    4444
    4545namespace WebCore {
     46class ContentFilterUnblockHandler;
    4647class NetworkLoadMetrics;
    4748class ResourceError;
     
    4950class ResourceRequest;
    5051class ResourceResponse;
     52class SubstituteData;
    5153enum class MainFrameMainResource : bool;
    5254}
     
    100102#endif
    101103
     104#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     105    void contentFilterDidBlockLoad(const WebCore::ContentFilterUnblockHandler&, String&& unblockRequestDeniedScript);
     106    void cancelMainResourceLoadForContentFilter(const WebCore::ResourceError&);
     107    void handleProvisionalLoadFailureFromContentFilter(const URL& blockedPageURL, const WebCore::SubstituteData&);
     108#endif
     109   
    102110    RefPtr<WebCore::ResourceLoader> m_coreLoader;
    103111    TrackingParameters m_trackingParameters;
  • trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.messages.in

    r289018 r290189  
    3838    DidReceiveResource(WebKit::ShareableResource::Handle resource)
    3939#endif
     40
     41#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     42    ContentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler unblockHandler, String unblockRequestDeniedScript)
     43    CancelMainResourceLoadForContentFilter(WebCore::ResourceError error)
     44    HandleProvisionalLoadFailureFromContentFilter(URL blockedPageURL, WebCore::SubstituteData substituteData)
     45#endif
     46
    4047}
Note: See TracChangeset for help on using the changeset viewer.