Changeset 251409 in webkit


Ignore:
Timestamp:
Oct 21, 2019 6:34:39 PM (4 years ago)
Author:
achristensen@apple.com
Message:

Move service worker registration matching for navigation loads to network process
https://bugs.webkit.org/show_bug.cgi?id=203144

Patch by youenn fablet <youenn@apple.com> on 2019-10-21
Reviewed by Chris Dumez.

Source/WebCore:

For regular loads, we no longer match service worker registration explicitly.
This is now done by NetworkResourceLoader explicitly.
We still need to explicitely match registrations in those two cases:

  • There is an app cache resource that can be used. We will use it only if there is no registration.
  • There is a resource from the meory cache that can be used. We will match the registration to make sure

the document is controlled by the right service worker. The load will still be served from the memory cache.

Since DocumentLoader is no longer matching registration, we need a way from NetworkProcess to inform that there is
a matching registration and that the document is controlled.
For that purpose, DocumentLoader is adding itself in a global map with the temporary document identifier as the key.
Adding to the map happens when loading the main resource and removal from the map happens when destroying the DocumentLoader.
For this to happen properly, the temporary document identifier is kept the same for the lifetime of the DocumentLoader.

Registration matching was postponed until service worker registration is done.
Since we no longer do registration matching in WebProcess, we need to wait in NetworkProcess for that to happen.
We introduce a way for SWServer to notify when import is completed for that purpose.

Covered by existing tests.

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::fromTemporaryDocumentIdentifier):
(WebCore::DocumentLoader::~DocumentLoader):
(WebCore::DocumentLoader::setControllingServiceWorkerRegistration):
(WebCore::DocumentLoader::redirectReceived):
(WebCore::DocumentLoader::responseReceived):
(WebCore::DocumentLoader::startLoadingMainResource):
(WebCore::DocumentLoader::unregisterTemporaryServiceWorkerClient):
(WebCore::DocumentLoader::loadMainResource):

  • loader/DocumentLoader.h:
  • loader/appcache/ApplicationCacheHost.cpp:

(WebCore::ApplicationCacheHost::canLoadMainResource):

  • loader/appcache/ApplicationCacheHost.h:
  • workers/service/server/SWServer.cpp:

(WebCore::SWServer::~SWServer):
(WebCore::SWServer::registrationStoreImportComplete):
(WebCore::SWServer::whenImportIsCompleted):
(WebCore::SWServer::doRegistrationMatching):

  • workers/service/server/SWServer.h:

(WebCore::SWServer::isImportCompleted const):

Source/WebKit:

Create a WebSWServerConnection whenever receiving a load request in NetworkProcess.
This connection is used to check for service worker registration in case of navigation loads.
Similarly, we create a WebSWClientConnection whenever WebProcess needs it, including when receiving WebSWClientConnection messages from NetworkProcess.
This for instance happens when service worker registration import is complete to fill the shared registration origin store.

Delay loads until SWServer has finished importing its registrations.
This is needed since we might otherwise not intercept loads that could be intercepted.
Waiting for importing registrations was previously ensured by WebProcess getting a matching registration in DocumentLoader.

NetworkResourceLoader is now checking for service worker interception in case of redirections for navigations.
This is needed as redirections could end up using a new registration.

  • NetworkProcess/NetworkConnectionToWebProcess.cpp:

(WebKit::NetworkConnectionToWebProcess::NetworkConnectionToWebProcess):
(WebKit::NetworkConnectionToWebProcess::scheduleResourceLoad):
(WebKit::NetworkConnectionToWebProcess::establishSWServerConnection):
(WebKit::NetworkConnectionToWebProcess::swConnection):

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

(WebKit::NetworkResourceLoader::continueWillSendRequest):
(WebKit::NetworkResourceLoader::startWithServiceWorker):
(WebKit::NetworkResourceLoader::serviceWorkerDidNotHandle):

  • NetworkProcess/NetworkResourceLoader.h:
  • NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp:

(WebKit::ServiceWorkerFetchTask::ServiceWorkerFetchTask):
(WebKit::ServiceWorkerFetchTask::start):
(WebKit::ServiceWorkerFetchTask::startFetch):
(WebKit::ServiceWorkerFetchTask::continueFetchTaskWith):

  • NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.h:

(WebKit::ServiceWorkerFetchTask::takeRequest):

  • NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:

(WebKit::WebSWServerConnection::controlClient):
(WebKit::WebSWServerConnection::createFetchTask):

  • NetworkProcess/ServiceWorker/WebSWServerConnection.h:
  • WebProcess/Network/NetworkProcessConnection.cpp:

(WebKit::NetworkProcessConnection::didReceiveMessage):

  • WebProcess/Network/WebLoaderStrategy.cpp:

(WebKit::WebLoaderStrategy::scheduleLoad):

  • WebProcess/Storage/WebSWClientConnection.cpp:

(WebKit::WebSWClientConnection::WebSWClientConnection):
(WebKit::WebSWClientConnection::registrationReady):
(WebKit::WebSWClientConnection::documentIsControlled):

  • WebProcess/Storage/WebSWClientConnection.h:
  • WebProcess/Storage/WebSWClientConnection.messages.in:

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:

We are now creating a WebSWClientConnection whenever receiving a WebSWClientConnection message
from NetworkProcess. It is free to do so given it no longer requires sending some IPC.
Update the tests accordingly.
A future patch will remove the service worker registration bit feature and corresponding test.

Location:
trunk
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r251404 r251409  
     12019-10-21  youenn fablet  <youenn@apple.com>
     2
     3        Move service worker registration matching for navigation loads to network process
     4        https://bugs.webkit.org/show_bug.cgi?id=203144
     5
     6        Reviewed by Chris Dumez.
     7
     8        For regular loads, we no longer match service worker registration explicitly.
     9        This is now done by NetworkResourceLoader explicitly.
     10        We still need to explicitely match registrations in those two cases:
     11        - There is an app cache resource that can be used. We will use it only if there is no registration.
     12        - There is a resource from the meory cache that can be used. We will match the registration to make sure
     13        the document is controlled by the right service worker. The load will still be served from the memory cache.
     14
     15        Since DocumentLoader is no longer matching registration, we need a way from NetworkProcess to inform that there is
     16        a matching registration and that the document is controlled.
     17        For that purpose, DocumentLoader is adding itself in a global map with the temporary document identifier as the key.
     18        Adding to the map happens when loading the main resource and removal from the map happens when destroying the DocumentLoader.
     19        For this to happen properly, the temporary document identifier is kept the same for the lifetime of the DocumentLoader.
     20
     21        Registration matching was postponed until service worker registration is done.
     22        Since we no longer do registration matching in WebProcess, we need to wait in NetworkProcess for that to happen.
     23        We introduce a way for SWServer to notify when import is completed for that purpose.
     24
     25        Covered by existing tests.
     26
     27        * loader/DocumentLoader.cpp:
     28        (WebCore::DocumentLoader::fromTemporaryDocumentIdentifier):
     29        (WebCore::DocumentLoader::~DocumentLoader):
     30        (WebCore::DocumentLoader::setControllingServiceWorkerRegistration):
     31        (WebCore::DocumentLoader::redirectReceived):
     32        (WebCore::DocumentLoader::responseReceived):
     33        (WebCore::DocumentLoader::startLoadingMainResource):
     34        (WebCore::DocumentLoader::unregisterTemporaryServiceWorkerClient):
     35        (WebCore::DocumentLoader::loadMainResource):
     36        * loader/DocumentLoader.h:
     37        * loader/appcache/ApplicationCacheHost.cpp:
     38        (WebCore::ApplicationCacheHost::canLoadMainResource):
     39        * loader/appcache/ApplicationCacheHost.h:
     40        * workers/service/server/SWServer.cpp:
     41        (WebCore::SWServer::~SWServer):
     42        (WebCore::SWServer::registrationStoreImportComplete):
     43        (WebCore::SWServer::whenImportIsCompleted):
     44        (WebCore::SWServer::doRegistrationMatching):
     45        * workers/service/server/SWServer.h:
     46        (WebCore::SWServer::isImportCompleted const):
     47
    1482019-10-21  Sihui Liu  <sihui_liu@apple.com>
    249
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r251220 r251409  
    126126}
    127127
     128static HashMap<DocumentIdentifier, DocumentLoader*>& temporaryIdentifierToLoaderMap()
     129{
     130    static NeverDestroyed<HashMap<DocumentIdentifier, DocumentLoader*>> map;
     131    return map.get();
     132}
     133
     134DocumentLoader* DocumentLoader::fromTemporaryDocumentIdentifier(DocumentIdentifier identifier)
     135{
     136    return temporaryIdentifierToLoaderMap().get(identifier);
     137}
     138
    128139DocumentLoader::DocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
    129140    : FrameDestructionObserver(nullptr)
     
    162173    m_cachedResourceLoader->clearDocumentLoader();
    163174    clearMainResource();
     175
     176#if ENABLE(SERVICE_WORKER)
     177    if (m_temporaryServiceWorkerClient) {
     178        ASSERT(temporaryIdentifierToLoaderMap().contains(*m_temporaryServiceWorkerClient));
     179        temporaryIdentifierToLoaderMap().remove(*m_temporaryServiceWorkerClient);
     180    }
     181#endif
    164182}
    165183
     
    469487
    470488#if ENABLE(SERVICE_WORKER)
     489bool DocumentLoader::setControllingServiceWorkerRegistration(ServiceWorkerRegistrationData&& data)
     490{
     491    if (!m_loadingMainResource)
     492        return false;
     493
     494    ASSERT(!m_gotFirstByte);
     495    m_serviceWorkerRegistrationData = WTFMove(data);
     496    return true;
     497}
     498
    471499void DocumentLoader::matchRegistration(const URL& url, SWClientConnection::RegistrationCallback&& callback)
    472500{
     
    502530    ASSERT_UNUSED(resource, &resource == m_mainResource);
    503531#if ENABLE(SERVICE_WORKER)
    504     bool isRedirectionFromServiceWorker = redirectResponse.source() == ResourceResponse::Source::ServiceWorker;
    505     willSendRequest(WTFMove(request), redirectResponse, [isRedirectionFromServiceWorker, completionHandler = WTFMove(completionHandler), protectedThis = makeRef(*this), this] (auto&& request) mutable {
     532    if (m_serviceWorkerRegistrationData) {
     533        m_serviceWorkerRegistrationData = { };
     534        unregisterTemporaryServiceWorkerClient();
     535    }
     536    willSendRequest(WTFMove(request), redirectResponse, [completionHandler = WTFMove(completionHandler), protectedThis = makeRef(*this), this] (auto&& request) mutable {
    506537        ASSERT(!m_substituteData.isValid());
    507538        if (request.isNull() || !m_mainDocumentError.isNull() || !m_frame) {
     
    510541        }
    511542
    512         auto url = request.url();
    513         this->matchRegistration(url, [request = WTFMove(request), isRedirectionFromServiceWorker, completionHandler = WTFMove(completionHandler), protectedThis = WTFMove(protectedThis), this] (auto&& registrationData) mutable {
    514             if (!m_mainDocumentError.isNull() || !m_frame) {
    515                 completionHandler({ });
    516                 return;
    517             }
    518 
    519             if (!registrationData && this->tryLoadingRedirectRequestFromApplicationCache(request)) {
    520                 completionHandler({ });
    521                 return;
    522             }
    523 
    524             bool shouldContinueLoad = areRegistrationsEqual(m_serviceWorkerRegistrationData, registrationData)
    525                 && isRedirectionFromServiceWorker == !!registrationData;
    526 
    527             if (shouldContinueLoad) {
     543        if (m_applicationCacheHost->canLoadMainResource(request)) {
     544            auto url = request.url();
     545            // Let's check service worker registration to see whether loading from network or not.
     546            this->matchRegistration(url, [request = WTFMove(request), completionHandler = WTFMove(completionHandler), protectedThis = WTFMove(protectedThis), this](auto&& registrationData) mutable {
     547                if (!m_mainDocumentError.isNull() || !m_frame) {
     548                    completionHandler({ });
     549                    return;
     550                }
     551                if (!registrationData && this->tryLoadingRedirectRequestFromApplicationCache(request)) {
     552                    completionHandler({ });
     553                    return;
     554                }
    528555                completionHandler(WTFMove(request));
    529                 return;
    530             }
    531 
    532             this->restartLoadingDueToServiceWorkerRegistrationChange(WTFMove(request), WTFMove(registrationData));
    533             completionHandler({ });
     556            });
    534557            return;
    535         });
     558        }
     559        completionHandler(WTFMove(request));
    536560    });
    537561#else
     
    696720}
    697721
    698 #if ENABLE(SERVICE_WORKER)
    699 void DocumentLoader::restartLoadingDueToServiceWorkerRegistrationChange(ResourceRequest&& request, Optional<ServiceWorkerRegistrationData>&& registrationData)
    700 {
    701     clearMainResource();
    702 
    703     ASSERT(!isCommitted());
    704     m_serviceWorkerRegistrationData = WTFMove(registrationData);
    705     loadMainResource(WTFMove(request));
    706 
    707     if (m_mainResource)
    708         frameLoader()->client().dispatchDidReceiveServerRedirectForProvisionalLoad();
    709 }
    710 #endif
    711 
    712722void DocumentLoader::stopLoadingAfterXFrameOptionsOrContentSecurityPolicyDenied(unsigned long identifier, const ResourceResponse& response)
    713723{
     
    726736{
    727737    ASSERT_UNUSED(resource, m_mainResource == &resource);
     738#if ENABLE(SERVICE_WORKER)
     739    if (RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled() && response.source() == ResourceResponse::Source::MemoryCache) {
     740        matchRegistration(response.url(), [this, protectedThis = makeRef(*this), response, completionHandler = WTFMove(completionHandler)](auto&& registrationData) mutable {
     741            if (!m_mainDocumentError.isNull() || !m_frame) {
     742                completionHandler();
     743                return;
     744            }
     745            m_serviceWorkerRegistrationData = WTFMove(registrationData);
     746            responseReceived(response, WTFMove(completionHandler));
     747        });
     748        return;
     749    }
     750#endif
    728751    responseReceived(response, WTFMove(completionHandler));
    729752}
     
    17551778    willSendRequest(ResourceRequest(m_request), ResourceResponse(), [this, protectedThis = WTFMove(protectedThis)] (ResourceRequest&& request) mutable {
    17561779        m_request = request;
     1780        // FIXME: Implement local URL interception by getting the service worker of the parent.
    17571781
    17581782        // willSendRequest() may lead to our Frame being detached or cancelling the load via nulling the ResourceRequest.
     
    17691793
    17701794#if ENABLE(SERVICE_WORKER)
    1771         // FIXME: Implement local URL interception by getting the service worker of the parent.
    1772         auto url = request.url();
    1773         matchRegistration(url, [request = WTFMove(request), protectedThis = WTFMove(protectedThis), this] (auto&& registrationData) mutable {
    1774             if (!m_mainDocumentError.isNull() || !m_frame) {
    1775                 RELEASE_LOG_IF_ALLOWED("startLoadingMainResource callback: Load canceled because of main document error (frame = %p, main = %d)", m_frame, m_frame ? m_frame->isMainFrame() : false);
    1776                 return;
    1777             }
    1778 
    1779             m_serviceWorkerRegistrationData = WTFMove(registrationData);
    1780 
    1781             // Prefer existing substitute data (from WKWebView.loadData etc) over service worker fetch.
    1782             if (this->tryLoadingSubstituteData()) {
    1783                 RELEASE_LOG_IF_ALLOWED("startLoadingMainResource callback: Load canceled because of substitute data (frame = %p, main = %d)", m_frame, m_frame ? m_frame->isMainFrame() : false);
    1784                 return;
    1785             }
    1786             // Try app cache only if there is no service worker.
    1787             if (!m_serviceWorkerRegistrationData && this->tryLoadingRequestFromApplicationCache()) {
    1788                 RELEASE_LOG_IF_ALLOWED("startLoadingMainResource callback: Loaded from Application Cache (frame = %p, main = %d)", m_frame, m_frame->isMainFrame());
    1789                 return;
    1790             }
    1791             this->loadMainResource(WTFMove(request));
    1792         });
     1795        if (m_applicationCacheHost->canLoadMainResource(request) || m_substituteData.isValid()) {
     1796            auto url = request.url();
     1797            matchRegistration(url, [request = WTFMove(request), protectedThis = WTFMove(protectedThis), this] (auto&& registrationData) mutable {
     1798                if (!m_mainDocumentError.isNull() || !m_frame) {
     1799                    RELEASE_LOG_IF_ALLOWED("startLoadingMainResource callback: Load canceled because of main document error (frame = %p, main = %d)", m_frame, m_frame ? m_frame->isMainFrame() : false);
     1800                    return;
     1801                }
     1802
     1803                m_serviceWorkerRegistrationData = WTFMove(registrationData);
     1804                // Prefer existing substitute data (from WKWebView.loadData etc) over service worker fetch.
     1805                if (this->tryLoadingSubstituteData()) {
     1806                    RELEASE_LOG_IF_ALLOWED("startLoadingMainResource callback: Load canceled because of substitute data (frame = %p, main = %d)", m_frame, m_frame ? m_frame->isMainFrame() : false);
     1807                    return;
     1808                }
     1809
     1810                if (!m_serviceWorkerRegistrationData && this->tryLoadingRequestFromApplicationCache()) {
     1811                    RELEASE_LOG_IF_ALLOWED("startLoadingMainResource callback: Loaded from Application Cache (frame = %p, main = %d)", m_frame, m_frame->isMainFrame());
     1812                    return;
     1813                }
     1814                this->loadMainResource(WTFMove(request));
     1815            });
     1816            return;
     1817        }
    17931818#else
    17941819        if (tryLoadingRequestFromApplicationCache()) {
     
    17961821            return;
    17971822        }
     1823#endif
    17981824        loadMainResource(WTFMove(request));
    1799 #endif
    18001825    });
    18011826}
    18021827
    1803 void DocumentLoader::registerTemporaryServiceWorkerClient(const URL& url)
     1828void DocumentLoader::unregisterTemporaryServiceWorkerClient()
    18041829{
    18051830#if ENABLE(SERVICE_WORKER)
    1806     ASSERT(!m_temporaryServiceWorkerClient);
    1807 
    1808     if (!m_serviceWorkerRegistrationData)
    1809         return;
    1810 
    1811     m_temporaryServiceWorkerClient = DocumentIdentifier::generate();
    1812 
    1813     auto& serviceWorkerConnection = ServiceWorkerProvider::singleton().serviceWorkerConnection();
    1814 
    1815     // FIXME: Compute ServiceWorkerClientFrameType appropriately.
    1816     ServiceWorkerClientData data { { serviceWorkerConnection.serverConnectionIdentifier(), *m_temporaryServiceWorkerClient }, ServiceWorkerClientType::Window, ServiceWorkerClientFrameType::None, url };
    1817 
    1818     RefPtr<SecurityOrigin> topOrigin;
    1819     if (m_frame->isMainFrame())
    1820         topOrigin = SecurityOrigin::create(url);
    1821     else
    1822         topOrigin = &m_frame->mainFrame().document()->topOrigin();
    1823     serviceWorkerConnection.registerServiceWorkerClient(*topOrigin, WTFMove(data), m_serviceWorkerRegistrationData->identifier, m_frame->loader().userAgent(url));
    1824 #else
    1825     UNUSED_PARAM(url);
    1826 #endif
    1827 }
    1828 
    1829 void DocumentLoader::unregisterTemporaryServiceWorkerClient()
    1830 {
    1831 #if ENABLE(SERVICE_WORKER)
    1832     if (!m_temporaryServiceWorkerClient)
     1831    if (!m_temporaryServiceWorkerClient || !RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled())
    18331832        return;
    18341833
    18351834    auto& serviceWorkerConnection = ServiceWorkerProvider::singleton().serviceWorkerConnection();
    18361835    serviceWorkerConnection.unregisterServiceWorkerClient(*m_temporaryServiceWorkerClient);
    1837     m_temporaryServiceWorkerClient = WTF::nullopt;
    18381836#endif
    18391837}
     
    18411839void DocumentLoader::loadMainResource(ResourceRequest&& request)
    18421840{
    1843     static NeverDestroyed<ResourceLoaderOptions> mainResourceLoadOptions(
     1841    ResourceLoaderOptions mainResourceLoadOptions(
    18441842        SendCallbackPolicy::SendCallbacks,
    18451843        ContentSniffingPolicy::SniffContent,
     
    18541852        DefersLoadingPolicy::AllowDefersLoading,
    18551853        CachingPolicy::AllowCaching);
     1854#if ENABLE(SERVICE_WORKER)
     1855    if (!m_temporaryServiceWorkerClient) {
     1856        // The main navigation load will trigger the registration of the temp client.
     1857        m_temporaryServiceWorkerClient = DocumentIdentifier::generate();
     1858        ASSERT(!temporaryIdentifierToLoaderMap().contains(*m_temporaryServiceWorkerClient));
     1859        temporaryIdentifierToLoaderMap().add(*m_temporaryServiceWorkerClient, this);
     1860    }
     1861    mainResourceLoadOptions.clientIdentifier = m_temporaryServiceWorkerClient;
     1862#endif
    18561863    CachedResourceRequest mainResourceRequest(WTFMove(request), mainResourceLoadOptions);
    18571864    if (!m_frame->isMainFrame() && m_frame->document()) {
     
    18641871    }
    18651872
    1866 #if ENABLE(SERVICE_WORKER)
    1867     mainResourceRequest.setNavigationServiceWorkerRegistrationData(m_serviceWorkerRegistrationData);
    1868     if (mainResourceRequest.options().serviceWorkersMode != ServiceWorkersMode::None) {
    1869         // As per step 12 of https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm, the active service worker should be controlling the document.
    1870         // Since we did not yet create the document, we register a temporary service worker client instead.
    1871         registerTemporaryServiceWorkerClient(mainResourceRequest.resourceRequest().url());
    1872     }
    1873 #endif
    1874 
    18751873    m_mainResource = m_cachedResourceLoader->requestMainResource(WTFMove(mainResourceRequest)).value_or(nullptr);
    18761874
  • trunk/Source/WebCore/loader/DocumentLoader.h

    r251220 r251409  
    150150        return adoptRef(*new DocumentLoader(request, data));
    151151    }
     152
     153    WEBCORE_EXPORT static DocumentLoader* fromTemporaryDocumentIdentifier(DocumentIdentifier);
     154
    152155    WEBCORE_EXPORT virtual ~DocumentLoader();
    153156
     
    393396    bool allowContentChangeObserverQuirk() const { return m_allowContentChangeObserverQuirk; }
    394397
     398#if ENABLE(SERVICE_WORKER)
     399    WEBCORE_EXPORT bool setControllingServiceWorkerRegistration(ServiceWorkerRegistrationData&&);
     400#endif
     401
    395402protected:
    396403    WEBCORE_EXPORT DocumentLoader(const ResourceRequest&, const SubstituteData&);
     
    406413    void matchRegistration(const URL&, CompletionHandler<void(Optional<ServiceWorkerRegistrationData>&&)>&&);
    407414#endif
    408     void registerTemporaryServiceWorkerClient(const URL&);
    409415    void unregisterTemporaryServiceWorkerClient();
    410416
     
    448454    bool tryLoadingSubstituteData();
    449455    bool tryLoadingRedirectRequestFromApplicationCache(const ResourceRequest&);
    450 #if ENABLE(SERVICE_WORKER)
    451     void restartLoadingDueToServiceWorkerRegistrationChange(ResourceRequest&&, Optional<ServiceWorkerRegistrationData>&&);
    452 #endif
    453456    void continueAfterContentPolicy(PolicyAction);
    454457
  • trunk/Source/WebCore/loader/appcache/ApplicationCacheHost.cpp

    r251220 r251409  
    8181}
    8282
     83bool ApplicationCacheHost::canLoadMainResource(const ResourceRequest& request)
     84{
     85    if (!isApplicationCacheEnabled() || isApplicationCacheBlockedForRequest(request))
     86        return false;
     87    return !!ApplicationCacheGroup::cacheForMainRequest(request, &m_documentLoader);
     88}
     89
    8390void ApplicationCacheHost::maybeLoadMainResource(const ResourceRequest& request, SubstituteData& substituteData)
    8491{
  • trunk/Source/WebCore/loader/appcache/ApplicationCacheHost.h

    r251220 r251409  
    9191    void selectCacheWithManifest(const URL& manifestURL);
    9292
     93    bool canLoadMainResource(const ResourceRequest&);
     94
    9395    void maybeLoadMainResource(const ResourceRequest&, SubstituteData&);
    9496    void maybeLoadMainResourceForRedirect(const ResourceRequest&, SubstituteData&);
  • trunk/Source/WebCore/workers/service/server/SWServer.cpp

    r251384 r251409  
    7070    connections.clear();
    7171
     72    for (auto& callback : std::exchange(m_importCompletedCallbacks, { }))
     73        callback();
     74
    7275    Vector<SWServerWorker*> runningWorkers;
    7376    for (auto& worker : m_runningOrTerminatingWorkers.values()) {
     
    132135
    133136    performGetOriginsWithRegistrationsCallbacks();
    134 }
     137
     138    for (auto& callback : std::exchange(m_importCompletedCallbacks, { }))
     139        callback();
     140}
     141
     142void SWServer::whenImportIsCompleted(CompletionHandler<void()>&& callback)
     143{
     144    ASSERT(!m_importCompleted);
     145    m_importCompletedCallbacks.append(WTFMove(callback));
     146}
     147
    135148
    136149void SWServer::registrationStoreDatabaseFailedToOpen()
     
    758771SWServerRegistration* SWServer::doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL)
    759772{
     773    ASSERT(isImportCompleted());
    760774    SWServerRegistration* selectedRegistration = nullptr;
    761775    for (auto& pair : m_scopeToRegistrationMap) {
  • trunk/Source/WebCore/workers/service/server/SWServer.h

    r251384 r251409  
    204204    WEBCORE_EXPORT void createContextConnection(const RegistrableDomain&);
    205205
     206    bool isImportCompleted() const { return m_importCompleted; }
     207    WEBCORE_EXPORT void whenImportIsCompleted(CompletionHandler<void()>&&);
     208
    206209private:
    207210    void scriptFetchFinished(Connection&, const ServiceWorkerFetchResult&);
     
    263266    CreateContextConnectionCallback m_createContextConnectionCallback;
    264267    HashSet<WebCore::RegistrableDomain> m_pendingConnectionDomains;
     268    Vector<CompletionHandler<void()>> m_importCompletedCallbacks;
    265269};
    266270
  • trunk/Source/WebKit/ChangeLog

    r251404 r251409  
     12019-10-21  youenn fablet  <youenn@apple.com>
     2
     3        Move service worker registration matching for navigation loads to network process
     4        https://bugs.webkit.org/show_bug.cgi?id=203144
     5
     6        Reviewed by Chris Dumez.
     7
     8        Create a WebSWServerConnection whenever receiving a load request in NetworkProcess.
     9        This connection is used to check for service worker registration in case of navigation loads.
     10        Similarly, we create a WebSWClientConnection whenever WebProcess needs it, including when receiving WebSWClientConnection messages from NetworkProcess.
     11        This for instance happens when service worker registration import is complete to fill the shared registration origin store.
     12
     13        Delay loads until SWServer has finished importing its registrations.
     14        This is needed since we might otherwise not intercept loads that could be intercepted.
     15        Waiting for importing registrations was previously ensured by WebProcess getting a matching registration in DocumentLoader.
     16
     17        NetworkResourceLoader is now checking for service worker interception in case of redirections for navigations.
     18        This is needed as redirections could end up using a new registration.
     19
     20        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
     21        (WebKit::NetworkConnectionToWebProcess::NetworkConnectionToWebProcess):
     22        (WebKit::NetworkConnectionToWebProcess::scheduleResourceLoad):
     23        (WebKit::NetworkConnectionToWebProcess::establishSWServerConnection):
     24        (WebKit::NetworkConnectionToWebProcess::swConnection):
     25        * NetworkProcess/NetworkConnectionToWebProcess.h:
     26        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
     27        * NetworkProcess/NetworkResourceLoader.cpp:
     28        (WebKit::NetworkResourceLoader::continueWillSendRequest):
     29        (WebKit::NetworkResourceLoader::startWithServiceWorker):
     30        (WebKit::NetworkResourceLoader::serviceWorkerDidNotHandle):
     31        * NetworkProcess/NetworkResourceLoader.h:
     32        * NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp:
     33        (WebKit::ServiceWorkerFetchTask::ServiceWorkerFetchTask):
     34        (WebKit::ServiceWorkerFetchTask::start):
     35        (WebKit::ServiceWorkerFetchTask::startFetch):
     36        (WebKit::ServiceWorkerFetchTask::continueFetchTaskWith):
     37        * NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.h:
     38        (WebKit::ServiceWorkerFetchTask::takeRequest):
     39        * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
     40        (WebKit::WebSWServerConnection::controlClient):
     41        (WebKit::WebSWServerConnection::createFetchTask):
     42        * NetworkProcess/ServiceWorker/WebSWServerConnection.h:
     43        * WebProcess/Network/NetworkProcessConnection.cpp:
     44        (WebKit::NetworkProcessConnection::didReceiveMessage):
     45        * WebProcess/Network/WebLoaderStrategy.cpp:
     46        (WebKit::WebLoaderStrategy::scheduleLoad):
     47        * WebProcess/Storage/WebSWClientConnection.cpp:
     48        (WebKit::WebSWClientConnection::WebSWClientConnection):
     49        (WebKit::WebSWClientConnection::registrationReady):
     50        (WebKit::WebSWClientConnection::documentIsControlled):
     51        * WebProcess/Storage/WebSWClientConnection.h:
     52        * WebProcess/Storage/WebSWClientConnection.messages.in:
     53
    1542019-10-21  Sihui Liu  <sihui_liu@apple.com>
    255
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp

    r251146 r251409  
    102102    m_connection->setOnlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage(true);
    103103    m_connection->open();
     104
     105#if ENABLE(SERVICE_WORKER)
     106    establishSWServerConnection();
     107#endif
    104108}
    105109
     
    401405void NetworkConnectionToWebProcess::scheduleResourceLoad(NetworkResourceLoadParameters&& loadParameters)
    402406{
     407#if ENABLE(SERVICE_WORKER)
     408    auto& server = m_networkProcess->swServerForSession(m_sessionID);
     409    if (!server.isImportCompleted()) {
     410        server.whenImportIsCompleted([this, protectedThis = makeRef(*this), loadParameters = WTFMove(loadParameters)]() mutable {
     411            if (!m_networkProcess->webProcessConnection(webProcessIdentifier()))
     412                return;
     413            ASSERT(m_networkProcess->swServerForSession(m_sessionID).isImportCompleted());
     414            scheduleResourceLoad(WTFMove(loadParameters));
     415        });
     416        return;
     417    }
     418#endif
    403419    auto identifier = loadParameters.identifier;
    404420    RELEASE_ASSERT(identifier);
     
    409425
    410426#if ENABLE(SERVICE_WORKER)
    411     loader->startWithServiceWorker(m_swConnection.get());
     427    loader->startWithServiceWorker();
    412428#else
    413429    loader->start();
     
    880896void NetworkConnectionToWebProcess::establishSWServerConnection()
    881897{
     898    if (m_swConnection)
     899        return;
     900
    882901    auto& server = m_networkProcess->swServerForSession(m_sessionID);
    883902    auto connection = makeUnique<WebSWServerConnection>(m_networkProcess, server, m_connection.get(), m_webProcessIdentifier);
    884903
    885     ASSERT(!m_swConnection);
    886904    m_swConnection = makeWeakPtr(*connection);
    887905    server.addConnection(WTFMove(connection));
     
    905923
    906924    m_swContextConnection = nullptr;
     925}
     926
     927WebSWServerConnection& NetworkConnectionToWebProcess::swConnection()
     928{
     929    if (!m_swConnection)
     930        establishSWServerConnection();
     931    return *m_swConnection;
    907932}
    908933#endif
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h

    r251146 r251409  
    158158#if ENABLE(SERVICE_WORKER)
    159159    void serverToContextConnectionNoLongerNeeded();
     160    WebSWServerConnection& swConnection();
    160161#endif
    161162
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in

    r251146 r251409  
    8080
    8181#if ENABLE(SERVICE_WORKER)
    82     EstablishSWServerConnection()
    8382    EstablishSWContextConnection(WebCore::RegistrableDomain domain)
    8483    CloseSWContextConnection()
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp

    r251146 r251409  
    762762{
    763763#if ENABLE(SERVICE_WORKER)
     764    if (parameters().options.mode == FetchOptions::Mode::Navigate) {
     765        if (auto serviceWorkerFetchTask = m_connection->swConnection().createFetchTask(*this, newRequest)) {
     766            m_networkLoad = nullptr;
     767            m_serviceWorkerFetchTask = WTFMove(serviceWorkerFetchTask);
     768            return;
     769        }
     770        m_shouldRestartLoad = !!m_serviceWorkerFetchTask;
     771        m_serviceWorkerFetchTask = nullptr;
     772    }
    764773    if (m_serviceWorkerFetchTask) {
    765774        m_serviceWorkerFetchTask->continueFetchTaskWith(WTFMove(newRequest));
     
    767776    }
    768777#endif
     778
    769779    if (m_shouldRestartLoad) {
    770780        m_shouldRestartLoad = false;
     
    12241234
    12251235#if ENABLE(SERVICE_WORKER)
    1226 void NetworkResourceLoader::startWithServiceWorker(WebSWServerConnection* swConnection)
     1236void NetworkResourceLoader::startWithServiceWorker()
    12271237{
    12281238    ASSERT(!m_serviceWorkerFetchTask);
    1229     m_serviceWorkerFetchTask = swConnection ? swConnection->createFetchTask(*this) : nullptr;
     1239    m_serviceWorkerFetchTask = m_connection->swConnection().createFetchTask(*this, originalRequest());
    12301240    if (m_serviceWorkerFetchTask)
    12311241        return;
     
    12421252    }
    12431253
    1244     m_serviceWorkerFetchTask = nullptr;
     1254    if (m_serviceWorkerFetchTask) {
     1255        auto newRequest = m_serviceWorkerFetchTask->takeRequest();
     1256        m_serviceWorkerFetchTask = nullptr;
     1257
     1258        if (m_networkLoad)
     1259            m_networkLoad->updateRequestAfterRedirection(newRequest);
     1260        restartNetworkLoad(WTFMove(newRequest));
     1261        return;
     1262    }
    12451263    start();
    12461264}
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h

    r251124 r251409  
    127127
    128128#if ENABLE(SERVICE_WORKER)
    129     void startWithServiceWorker(WebSWServerConnection*);
     129    void startWithServiceWorker();
    130130    void serviceWorkerDidNotHandle();
    131131#endif
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp

    r251124 r251409  
    3939#include "WebResourceLoaderMessages.h"
    4040#include "WebSWContextManagerConnectionMessages.h"
     41#include "WebSWServerConnection.h"
    4142#include "WebSWServerToContextConnection.h"
    4243#include <WebCore/CrossOriginAccessControl.h>
     
    4950namespace WebKit {
    5051
    51 ServiceWorkerFetchTask::ServiceWorkerFetchTask(PAL::SessionID sessionID, NetworkResourceLoader& loader, SWServerConnectionIdentifier serverConnectionIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier)
     52ServiceWorkerFetchTask::ServiceWorkerFetchTask(PAL::SessionID sessionID, NetworkResourceLoader& loader, ResourceRequest&& request, SWServerConnectionIdentifier serverConnectionIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier)
    5253    : m_sessionID(sessionID)
    5354    , m_loader(loader)
     
    5556    , m_serverConnectionIdentifier(serverConnectionIdentifier)
    5657    , m_serviceWorkerIdentifier(serviceWorkerIdentifier)
     58    , m_currentRequest(WTFMove(request))
    5759    , m_timeoutTimer(*this, &ServiceWorkerFetchTask::timeoutTimerFired)
    5860{
     
    8183    serviceWorkerConnection.registerFetch(*this);
    8284
    83     startFetch(ResourceRequest { m_loader.originalRequest() }, serviceWorkerConnection);
     85    startFetch();
    8486}
    8587
    86 void ServiceWorkerFetchTask::startFetch(ResourceRequest&& request, WebSWServerToContextConnection& serviceWorkerConnection)
     88void ServiceWorkerFetchTask::startFetch()
    8789{
    88     m_currentRequest = WTFMove(request);
    89 
    9090    auto& options = m_loader.parameters().options;
    9191    auto referrer = m_currentRequest.httpReferrer();
    9292
    9393    // We are intercepting fetch calls after going through the HTTP layer, which may add some specific headers.
    94     cleanHTTPRequestHeadersForAccessControl(m_currentRequest, m_loader.parameters().httpHeadersToKeep);
     94    auto request = m_currentRequest;
     95    cleanHTTPRequestHeadersForAccessControl(request, m_loader.parameters().httpHeadersToKeep);
    9596
    96     bool isSent = sendToServiceWorker(Messages::WebSWContextManagerConnection::StartFetch { m_serverConnectionIdentifier, m_serviceWorkerIdentifier, m_fetchIdentifier, m_currentRequest, options, IPC::FormDataReference { m_currentRequest.httpBody() }, referrer });
     97    bool isSent = sendToServiceWorker(Messages::WebSWContextManagerConnection::StartFetch { m_serverConnectionIdentifier, m_serviceWorkerIdentifier, m_fetchIdentifier, request, options, IPC::FormDataReference { m_currentRequest.httpBody() }, referrer });
    9798    ASSERT_UNUSED(isSent, isSent);
    9899}
     
    170171        return;
    171172    }
    172     startFetch(WTFMove(request), *m_serviceWorkerConnection);
     173    m_currentRequest = WTFMove(request);
     174    startFetch();
    173175}
    174176
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.h

    r251124 r251409  
    3030#include <WebCore/FetchIdentifier.h>
    3131#include <WebCore/ResourceRequest.h>
     32#include <WebCore/ServiceWorkerClientIdentifier.h>
    3233#include <WebCore/ServiceWorkerTypes.h>
    3334#include <WebCore/Timer.h>
     
    5354class WebSWServerToContextConnection;
    5455
    55 class NetworkResourceLoader;
    56 class WebSWServerToContextConnection;
    57 
    5856class ServiceWorkerFetchTask : public CanMakeWeakPtr<ServiceWorkerFetchTask> {
    5957    WTF_MAKE_FAST_ALLOCATED;
    6058public:
    61     ServiceWorkerFetchTask(PAL::SessionID, NetworkResourceLoader&, WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier);
     59    ServiceWorkerFetchTask(PAL::SessionID, NetworkResourceLoader&, WebCore::ResourceRequest&&, WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::ServiceWorkerRegistrationIdentifier);
    6260    ~ServiceWorkerFetchTask();
    6361
     
    7573    void didNotHandle();
    7674
     75    WebCore::ResourceRequest takeRequest() { return WTFMove(m_currentRequest); }
    7776    bool wasHandled() const { return m_wasHandled; }
    7877
     
    8584    void didFail(const WebCore::ResourceError&);
    8685
    87     void startFetch(WebCore::ResourceRequest&&, WebSWServerToContextConnection&);
     86    void startFetch();
    8887
    8988    void timeoutTimerFired();
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp

    r251278 r251409  
    129129}
    130130
    131 std::unique_ptr<ServiceWorkerFetchTask> WebSWServerConnection::createFetchTask(NetworkResourceLoader& loader)
    132 {
    133     if (!loader.parameters().serviceWorkerRegistrationIdentifier)
    134         return nullptr;
    135 
     131void WebSWServerConnection::controlClient(ServiceWorkerClientIdentifier clientIdentifier, SWServerRegistration& registration, const ResourceRequest& request)
     132{
     133    // As per step 12 of https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm, the active service worker should be controlling the document.
     134    // We register a temporary service worker client using the identifier provided by DocumentLoader and notify DocumentLoader about it.
     135    // If notification is successful, DocumentLoader will unregister the temporary service worker client just after the document is created and registered as a client.
     136    sendWithAsyncReply(Messages::WebSWClientConnection::SetDocumentIsControlled { clientIdentifier.contextIdentifier, registration.data() }, [weakThis = makeWeakPtr(this), this, clientIdentifier](bool isSuccess) {
     137        if (!weakThis || isSuccess)
     138            return;
     139        unregisterServiceWorkerClient(clientIdentifier);
     140    });
     141
     142    ServiceWorkerClientData data { clientIdentifier, ServiceWorkerClientType::Window, ServiceWorkerClientFrameType::None, request.url() };
     143    registerServiceWorkerClient(SecurityOriginData { registration.key().topOrigin() }, WTFMove(data), registration.identifier(), request.httpUserAgent());
     144}
     145
     146std::unique_ptr<ServiceWorkerFetchTask> WebSWServerConnection::createFetchTask(NetworkResourceLoader& loader, const ResourceRequest& request)
     147{
    136148    if (loader.parameters().serviceWorkersMode == ServiceWorkersMode::None)
    137149        return nullptr;
    138150
    139     if (isPotentialNavigationOrSubresourceRequest(loader.parameters().options.destination))
    140         return nullptr;
    141 
    142151    if (!server().canHandleScheme(loader.originalRequest().url().protocol()))
    143152        return nullptr;
    144153
    145     auto* worker = server().activeWorkerFromRegistrationID(*loader.parameters().serviceWorkerRegistrationIdentifier);
     154    Optional<ServiceWorkerRegistrationIdentifier> serviceWorkerRegistrationIdentifier;
     155    if (loader.parameters().options.mode == FetchOptions::Mode::Navigate) {
     156        auto topOrigin = loader.parameters().isMainFrameNavigation ? SecurityOriginData::fromURL(request.url()) : loader.parameters().topOrigin->data();
     157        auto* registration = doRegistrationMatching(topOrigin, request.url());
     158        if (!registration)
     159            return nullptr;
     160
     161        serviceWorkerRegistrationIdentifier = registration->identifier();
     162        controlClient(ServiceWorkerClientIdentifier { loader.connectionToWebProcess().webProcessIdentifier(), *loader.parameters().options.clientIdentifier }, *registration, request);
     163    } else {
     164        if (!loader.parameters().serviceWorkerRegistrationIdentifier)
     165            return nullptr;
     166
     167        if (isPotentialNavigationOrSubresourceRequest(loader.parameters().options.destination))
     168            return nullptr;
     169
     170        serviceWorkerRegistrationIdentifier = *loader.parameters().serviceWorkerRegistrationIdentifier;
     171    }
     172
     173    auto* worker = server().activeWorkerFromRegistrationID(*serviceWorkerRegistrationIdentifier);
    146174    if (!worker) {
    147         SWSERVERCONNECTION_RELEASE_LOG_ERROR_IF_ALLOWED("startFetch: DidNotHandle because no active worker %s", loader.parameters().serviceWorkerRegistrationIdentifier->loggingString().utf8().data());
     175        SWSERVERCONNECTION_RELEASE_LOG_ERROR_IF_ALLOWED("startFetch: DidNotHandle because no active worker %s", serviceWorkerRegistrationIdentifier->loggingString().utf8().data());
    148176        return nullptr;
    149177    }
     
    156184    }
    157185
    158     auto task = makeUnique<ServiceWorkerFetchTask>(sessionID(), loader, identifier(), worker->identifier());
     186    auto task = makeUnique<ServiceWorkerFetchTask>(sessionID(), loader, ResourceRequest { request }, identifier(), worker->identifier(), *serviceWorkerRegistrationIdentifier);
    159187    startFetch(*task, *worker);
    160188    return task;
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h

    r251124 r251409  
    6969    PAL::SessionID sessionID() const;
    7070
    71     std::unique_ptr<ServiceWorkerFetchTask> createFetchTask(NetworkResourceLoader&);
     71    std::unique_ptr<ServiceWorkerFetchTask> createFetchTask(NetworkResourceLoader&, const WebCore::ResourceRequest&);
    7272
    7373private:
     
    8686
    8787    void scheduleJobInServer(WebCore::ServiceWorkerJobData&&);
    88 
    89     bool handleFetch(NetworkResourceLoader&);
    9088
    9189    void startFetch(ServiceWorkerFetchTask&, WebCore::SWServerWorker&);
     
    109107
    110108    void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source);
     109    void controlClient(WebCore::ServiceWorkerClientIdentifier, WebCore::SWServerRegistration&, const WebCore::ResourceRequest&);
    111110
    112111    IPC::Connection* messageSenderConnection() const final { return m_contentConnection.ptr(); }
  • trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp

    r251361 r251409  
    138138#if ENABLE(SERVICE_WORKER)
    139139    if (decoder.messageReceiverName() == Messages::WebSWClientConnection::messageReceiverName()) {
    140         if (m_swConnection)
    141             m_swConnection->didReceiveMessage(connection, decoder);
     140        serviceWorkerConnection().didReceiveMessage(connection, decoder);
    142141        return;
    143142    }
  • trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp

    r251124 r251409  
    221221        url.string();
    222222
    223     if ((resourceLoader.options().serviceWorkerRegistrationIdentifier && resourceLoader.options().serviceWorkersMode != ServiceWorkersMode::None) || !tryLoadingUsingURLSchemeHandler(resourceLoader)) {
     223    bool canbeLoadedThroughServiceWorkers = resourceLoader.options().serviceWorkersMode != ServiceWorkersMode::None && (resourceLoader.options().serviceWorkerRegistrationIdentifier || resourceLoader.options().mode == FetchOptions::Mode::Navigate);
     224    if (canbeLoadedThroughServiceWorkers || !tryLoadingUsingURLSchemeHandler(resourceLoader)) {
    224225#else
    225226    if (!tryLoadingUsingURLSchemeHandler(resourceLoader)) {
     
    288289#if ENABLE(SERVICE_WORKER)
    289290    // In case of URL scheme handler, we will try to load on service workers and if unhandled, fallback to URL scheme handler.
    290     if (resourceLoader.options().serviceWorkersMode == ServiceWorkersMode::All && webPage && webPage->urlSchemeHandlerForScheme(resourceLoader.request().url().protocol().toStringWithoutCopying()))
     291    if (webPage && webPage->urlSchemeHandlerForScheme(resourceLoader.request().url().protocol().toStringWithoutCopying()))
    291292        loadParameters.serviceWorkersMode = ServiceWorkersMode::Only;
    292293    else
  • trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp

    r251152 r251409  
    4141#include "WebSWServerConnectionMessages.h"
    4242#include <WebCore/Document.h>
     43#include <WebCore/DocumentLoader.h>
    4344#include <WebCore/ProcessIdentifier.h>
    4445#include <WebCore/SecurityOrigin.h>
     
    5960    , m_swOriginTable(makeUniqueRef<WebSWOriginTable>())
    6061{
    61     send(Messages::NetworkConnectionToWebProcess::EstablishSWServerConnection { });
    6262}
    6363
     
    182182}
    183183
    184 void WebSWClientConnection::registrationReady(uint64_t callbackID, WebCore::ServiceWorkerRegistrationData&& registrationData)
     184void WebSWClientConnection::registrationReady(uint64_t callbackID, ServiceWorkerRegistrationData&& registrationData)
    185185{
    186186    ASSERT(registrationData.activeWorker);
    187187    if (auto callback = m_ongoingRegistrationReadyTasks.take(callbackID))
    188188        callback(WTFMove(registrationData));
     189}
     190
     191void WebSWClientConnection::setDocumentIsControlled(DocumentIdentifier documentIdentifier, ServiceWorkerRegistrationData&& data, CompletionHandler<void(bool)>&& completionHandler)
     192{
     193    auto* documentLoader = DocumentLoader::fromTemporaryDocumentIdentifier(documentIdentifier);
     194    bool result = documentLoader ? documentLoader->setControllingServiceWorkerRegistration(WTFMove(data)) : false;
     195    completionHandler(result);
    189196}
    190197
  • trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h

    r251124 r251409  
    8080    void registrationReady(uint64_t callbackID, WebCore::ServiceWorkerRegistrationData&&);
    8181
     82    void setDocumentIsControlled(WebCore::DocumentIdentifier, WebCore::ServiceWorkerRegistrationData&&, CompletionHandler<void(bool)>&&);
     83
    8284    void getRegistrations(WebCore::SecurityOriginData&& topOrigin, const URL& clientURL, GetRegistrationsCallback&&) final;
    8385
  • trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in

    r239427 r251409  
    4343    DidGetRegistrations(uint64_t matchRequestIdentifier, Vector<WebCore::ServiceWorkerRegistrationData> registrations)
    4444    RegistrationReady(uint64_t registrationReadyRequestIdentifier, struct WebCore::ServiceWorkerRegistrationData data)
     45
     46    SetDocumentIsControlled(WebCore::DocumentIdentifier temporaryDocumentIdentifier, struct WebCore::ServiceWorkerRegistrationData data) -> (bool isSuccess) Async
    4547}
    4648
  • trunk/Tools/ChangeLog

    r251407 r251409  
     12019-10-21  youenn fablet  <youenn@apple.com>
     2
     3        Move service worker registration matching for navigation loads to network process
     4        https://bugs.webkit.org/show_bug.cgi?id=203144
     5
     6        Reviewed by Chris Dumez.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
     9        We are now creating a WebSWClientConnection whenever receiving a WebSWClientConnection message
     10        from NetworkProcess. It is free to do so given it no longer requires sending some IPC.
     11        Update the tests accordingly.
     12        A future patch will remove the service worker registration bit feature and corresponding test.
     13
    1142019-10-21  Simon Fraser  <simon.fraser@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm

    r251384 r251409  
    865865@end
    866866
    867 static const char* regularPageWithoutConnectionBytes = R"SWRESOURCE(
    868 <script>
    869 var result = window.internals.hasServiceWorkerConnection() ? "FAIL" : "PASS";
    870 window.webkit.messageHandlers.regularPage.postMessage(result);
    871 </script>
    872 )SWRESOURCE";
    873 
    874867static const char* regularPageWithConnectionBytes = R"SWRESOURCE(
    875868<script>
     
    908901
    909902    ServiceWorkerTCPServer server({
    910         { "text/html", regularPageWithoutConnectionBytes },
     903        { "text/html", regularPageWithConnectionBytes },
    911904        { "text/html", mainBytes },
    912905        { "application/javascript", scriptBytes },
     
    10911084        { "application/javascript", scriptBytes },
    10921085    }, {
    1093         { "text/html", regularPageWithoutConnectionBytes },
     1086        { "text/html", regularPageWithConnectionBytes },
    10941087    }, {
    10951088        { "text/html", regularPageWithConnectionBytes }
Note: See TracChangeset for help on using the changeset viewer.