Changeset 223650 in webkit


Ignore:
Timestamp:
Oct 18, 2017 7:26:00 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Add preliminary support for ServiceWorker Handle Fetch
https://bugs.webkit.org/show_bug.cgi?id=178475

Patch by Youenn Fablet <youenn@apple.com> on 2017-10-18
Reviewed by Chris Dumez.

Source/WebCore:

Test: http/tests/workers/service/basic-fetch.https.html

Adding parameters to allow WebKit to do loading through Service Worker or through regular networking.
A script context is now storing its selected service worker identifier. This should be fully implemented later on.
This selected service worker identifier is passed to loading code as a ResourceLoaderOptions field.
Service workers mode is also added as a ResourceLoaderOptions field so that the service worker can be bypassed.

  • WebCore.xcodeproj/project.pbxproj:
  • dom/ScriptExecutionContext.h:

(WebCore::ScriptExecutionContext::selectedServiceWorkerIdentifier const):
(WebCore::ScriptExecutionContext::setSelectedServiceWorkerIdentifier):

  • loader/DocumentThreadableLoader.cpp:

(WebCore::DocumentThreadableLoader::DocumentThreadableLoader):

  • loader/FetchOptions.h:

(WebCore::isPotentialNavigationOrSubresourceRequest):
(WebCore::isNonSubresourceRequest):

  • loader/ResourceLoaderOptions.h:
  • loader/WorkerThreadableLoader.cpp:

(WebCore::WorkerThreadableLoader::WorkerThreadableLoader):
(WebCore::WorkerThreadableLoader::MainThreadBridge::MainThreadBridge):

  • loader/WorkerThreadableLoader.h:
  • platform/network/ResourceRequestBase.h:
  • platform/network/ResourceResponseBase.h:
  • workers/WorkerThread.h:
  • workers/service/ServiceWorkerContainer.cpp:

(WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):

  • workers/service/ServiceWorkerProvider.h:
  • workers/service/context/SWContextManager.cpp: Removed.
  • workers/service/context/ServiceWorkerThread.h:
  • workers/service/server/SWServer.h:

Source/WebKit:

Preliminary support of Handle Fetch algorithm and integration with fetch spec.
Adding ServiceWorkerClientFetch as the class responsible to do the load through ServiceWorker.
It is similar to WebResourceLoader that do the load through NetworkProcess.
In case ServiceWorkerClientFetch is not able to load through ServiceWorker,
it will fallback to WebResourceLoader through a fallback callback.

Loading through Service Worker is done currently if:

  • There is a service worker registered for that origin
  • Request is a subresource
  • service workers mode is all

There will be cases where the service worker will not do the loading, for instance when fetch event handler is not set.
Future work should try to reduce the cases where the IPC dance is done unnecessarily.

ServiceWorkerClientFetch is responsible to adapt the ServiceWorker response to ResourceLoader.
In particular, it is calling ResourceLoader error callback if response is of type error.
It should call ResourceLoader redirection callback if response is a redirection response.
This will be done as a follow-up.

Implementing the IPC communication dedicated to fetch between WebProcess and ServiceWorker through StorageProcess.
In the future, WebProcess should create a direct IPC communication to the ServiceWorker process.

Moved SWContextManager from WebCore to WebKit and renamed it to ServiceWorkerContextManager.
This class is moved to WebKit as it will have to handle IPC and having a separation will add some unnecessary boilerplate.

  • DerivedSources.make:
  • StorageProcess/ServiceWorker/WebSWServerConnection.cpp:

(WebKit::WebSWServerConnection::startFetch):
(WebKit::WebSWServerConnection::didReceiveFetchResponse):
(WebKit::WebSWServerConnection::didReceiveFetchData):
(WebKit::WebSWServerConnection::didFinishFetch):
(WebKit::WebSWServerConnection::failedFetch):

  • StorageProcess/ServiceWorker/WebSWServerConnection.h:
  • StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
  • StorageProcess/StorageProcess.cpp:

(WebKit::StorageProcess::failedFetch):
(WebKit::StorageProcess::didReceiveFetchResponse):
(WebKit::StorageProcess::didReceiveFetchData):
(WebKit::StorageProcess::didFinishFetch):

  • StorageProcess/StorageProcess.h:
  • StorageProcess/StorageProcess.messages.in:
  • WebKit.xcodeproj/project.pbxproj:
  • WebProcess/Network/WebLoaderStrategy.cpp:

(WebKit::WebLoaderStrategy::scheduleLoad):
(WebKit::WebLoaderStrategy::scheduleLoadFromNetworkProcess):

  • WebProcess/Network/WebLoaderStrategy.h:
  • WebProcess/Storage/ServiceWorkerClientFetch.cpp: Added.

(WebKit::ServiceWorkerClientFetch::didReceiveResponse):
(WebKit::ServiceWorkerClientFetch::didReceiveData):
(WebKit::ServiceWorkerClientFetch::didFinishFetch):
(WebKit::ServiceWorkerClientFetch::didFail):

  • WebProcess/Storage/ServiceWorkerClientFetch.h: Added.
  • WebProcess/Storage/ServiceWorkerClientFetch.messages.in: Added.
  • WebProcess/Storage/ServiceWorkerContextManager.cpp: Renamed from Source/WebCore/workers/service/context/SWContextManager.cpp.

(WebKit::ServiceWorkerContextManager::startServiceWorkerContext):
(WebKit::ServiceWorkerContextManager::startFetch):

  • WebProcess/Storage/ServiceWorkerContextManager.h: Renamed from Source/WebCore/workers/service/context/SWContextManager.h.

(WebKit::ServiceWorkerContextManager::ServiceWorkerContextManager):

  • WebProcess/Storage/WebSWClientConnection.cpp:

(WebKit::WebSWClientConnection::startFetch):

  • WebProcess/Storage/WebSWClientConnection.h:
  • WebProcess/Storage/WebServiceWorkerProvider.cpp:

(WebKit::shouldHandleFetch):
(WebKit::WebServiceWorkerProvider::handleFetch):
(WebKit::WebServiceWorkerProvider::didReceiveServiceWorkerClientFetchMessage):

  • WebProcess/Storage/WebServiceWorkerProvider.h:
  • WebProcess/Storage/WebToStorageProcessConnection.cpp:

(WebKit::WebToStorageProcessConnection::didReceiveMessage):

  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::getWorkerContextConnection):
(WebKit::WebProcess::startServiceWorkerContext):
(WebKit::WebProcess::startFetchInServiceWorker):

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

LayoutTests:

  • http/tests/workers/service/basic-fetch.https-expected.txt: Added.
  • http/tests/workers/service/basic-fetch.https.html: Added.
  • http/tests/workers/service/resources/basic-fetch-worker.js: Added.
  • http/tests/workers/service/resources/basic-fetch.js: Added.
Location:
trunk
Files:
6 added
1 deleted
34 edited
2 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r223648 r223650  
     12017-10-18  Youenn Fablet  <youenn@apple.com>
     2
     3        Add preliminary support for ServiceWorker Handle Fetch
     4        https://bugs.webkit.org/show_bug.cgi?id=178475
     5
     6        Reviewed by Chris Dumez.
     7
     8        * http/tests/workers/service/basic-fetch.https-expected.txt: Added.
     9        * http/tests/workers/service/basic-fetch.https.html: Added.
     10        * http/tests/workers/service/resources/basic-fetch-worker.js: Added.
     11        * http/tests/workers/service/resources/basic-fetch.js: Added.
     12
    1132017-10-18  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r223649 r223650  
     12017-10-18  Youenn Fablet  <youenn@apple.com>
     2
     3        Add preliminary support for ServiceWorker Handle Fetch
     4        https://bugs.webkit.org/show_bug.cgi?id=178475
     5
     6        Reviewed by Chris Dumez.
     7
     8        Test: http/tests/workers/service/basic-fetch.https.html
     9
     10        Adding parameters to allow WebKit to do loading through Service Worker or through regular networking.
     11        A script context is now storing its selected service worker identifier. This should be fully implemented later on.
     12        This selected service worker identifier is passed to loading code as a ResourceLoaderOptions field.
     13        Service workers mode is also added as a ResourceLoaderOptions field so that the service worker can be bypassed.
     14
     15        * WebCore.xcodeproj/project.pbxproj:
     16        * dom/ScriptExecutionContext.h:
     17        (WebCore::ScriptExecutionContext::selectedServiceWorkerIdentifier const):
     18        (WebCore::ScriptExecutionContext::setSelectedServiceWorkerIdentifier):
     19        * loader/DocumentThreadableLoader.cpp:
     20        (WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
     21        * loader/FetchOptions.h:
     22        (WebCore::isPotentialNavigationOrSubresourceRequest):
     23        (WebCore::isNonSubresourceRequest):
     24        * loader/ResourceLoaderOptions.h:
     25        * loader/WorkerThreadableLoader.cpp:
     26        (WebCore::WorkerThreadableLoader::WorkerThreadableLoader):
     27        (WebCore::WorkerThreadableLoader::MainThreadBridge::MainThreadBridge):
     28        * loader/WorkerThreadableLoader.h:
     29        * platform/network/ResourceRequestBase.h:
     30        * platform/network/ResourceResponseBase.h:
     31        * workers/WorkerThread.h:
     32        * workers/service/ServiceWorkerContainer.cpp:
     33        (WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
     34        * workers/service/ServiceWorkerProvider.h:
     35        * workers/service/context/SWContextManager.cpp: Removed.
     36        * workers/service/context/ServiceWorkerThread.h:
     37        * workers/service/server/SWServer.h:
     38
    1392017-10-18  Zalan Bujtas  <zalan@apple.com>
    240
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r223634 r223650  
    23282328                517B25A91CC82B2A0061C011 /* IDBConnectionProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517B25A71CC820320061C011 /* IDBConnectionProxy.cpp */; };
    23292329                517B25AA1CC82B2A0061C011 /* IDBConnectionProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 517B25A81CC820320061C011 /* IDBConnectionProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
    2330                 517C870A1F8EBB2500EB8076 /* SWContextManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517C87081F8EB9BF00EB8076 /* SWContextManager.cpp */; };
    2331                 517C870B1F8EBB2500EB8076 /* SWContextManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 517C87091F8EB9C000EB8076 /* SWContextManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
    23322330                517C87181F8FD4D900EB8076 /* ServiceWorkerContextData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517C87161F8FD4D300EB8076 /* ServiceWorkerContextData.cpp */; };
    23332331                517DEEE51DE94ADC00B91644 /* ScrollingMomentumCalculatorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 517DEEE31DE94ADC00B91644 /* ScrollingMomentumCalculatorMac.mm */; };
     
    1023110229                517B25A71CC820320061C011 /* IDBConnectionProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBConnectionProxy.cpp; sourceTree = "<group>"; };
    1023210230                517B25A81CC820320061C011 /* IDBConnectionProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBConnectionProxy.h; sourceTree = "<group>"; };
    10233                 517C87081F8EB9BF00EB8076 /* SWContextManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SWContextManager.cpp; path = workers/service/context/SWContextManager.cpp; sourceTree = SOURCE_ROOT; };
    10234                 517C87091F8EB9C000EB8076 /* SWContextManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SWContextManager.h; path = workers/service/context/SWContextManager.h; sourceTree = SOURCE_ROOT; };
    1023510231                517C87101F8EE72E00EB8076 /* ServiceWorkerThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ServiceWorkerThread.h; path = workers/service/context/ServiceWorkerThread.h; sourceTree = SOURCE_ROOT; };
    1023610232                517C87111F8EE72F00EB8076 /* ServiceWorkerThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ServiceWorkerThread.cpp; path = workers/service/context/ServiceWorkerThread.cpp; sourceTree = SOURCE_ROOT; };
     
    1909019086                                517C87111F8EE72F00EB8076 /* ServiceWorkerThread.cpp */,
    1909119087                                517C87101F8EE72E00EB8076 /* ServiceWorkerThread.h */,
    19092                                 517C87081F8EB9BF00EB8076 /* SWContextManager.cpp */,
    19093                                 517C87091F8EB9C000EB8076 /* SWContextManager.h */,
    1909419088                        );
    1909519089                        path = context;
     
    3063730631                                B2E4EC980D00C22B00432643 /* SVGZoomEvent.h in Headers */,
    3063830632                                517A531D1F4B53B100DCDC0A /* SWClientConnection.h in Headers */,
    30639                                 517C870B1F8EBB2500EB8076 /* SWContextManager.h in Headers */,
    3064030633                                517A52F01F47535B00DCDC0A /* SWServer.h in Headers */,
    3064130634                                51F645971F4A686F00B54DED /* SWServerRegistration.h in Headers */,
     
    3436934362                                B2E4EC970D00C22B00432643 /* SVGZoomEvent.cpp in Sources */,
    3437034363                                517A531C1F4B53B100DCDC0A /* SWClientConnection.cpp in Sources */,
    34371                                 517C870A1F8EBB2500EB8076 /* SWContextManager.cpp in Sources */,
    3437234364                                517A52F11F4754E700DCDC0A /* SWServer.cpp in Sources */,
    3437334365                                51F645961F4A686F00B54DED /* SWServerRegistration.cpp in Sources */,
  • trunk/Source/WebCore/dom/ScriptExecutionContext.h

    r220857 r223650  
    231231    JSC::ExecState* execState();
    232232
     233#if ENABLE(SERVICE_WORKER)
     234    uint64_t selectedServiceWorkerIdentifier() const { return m_serviceWorkerIdentifier; }
     235    void setSelectedServiceWorkerIdentifier(uint64_t identifier) { m_serviceWorkerIdentifier = identifier; }
     236#endif
     237
    233238protected:
    234239    class AddConsoleMessageTask : public Task {
     
    298303    bool m_activeDOMObjectRemovalForbidden { false };
    299304#endif
     305
     306#if ENABLE(SERVICE_WORKER)
     307    uint64_t m_serviceWorkerIdentifier { 0 };
     308#endif
    300309};
    301310
  • trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp

    r222467 r223650  
    104104    relaxAdoptionRequirement();
    105105
     106#if ENABLE(SERVICE_WORKER)
     107    if (m_options.serviceWorkersMode == ServiceWorkersMode::All && !m_options.serviceWorkerIdentifier)
     108        m_options.serviceWorkerIdentifier = document.selectedServiceWorkerIdentifier();
     109#endif
     110
    106111    // Setting a referrer header is only supported in the async code path.
    107112    ASSERT(m_async || m_referrer.isEmpty());
  • trunk/Source/WebCore/loader/FetchOptions.h

    r223441 r223650  
    7070}
    7171
     72inline bool isPotentialNavigationOrSubresourceRequest(FetchOptions::Destination destination)
     73{
     74    return destination == FetchOptions::Destination::Object
     75        || destination == FetchOptions::Destination::Embed;
     76}
     77
     78inline bool isNonSubresourceRequest(FetchOptions::Destination destination)
     79{
     80    return destination == FetchOptions::Destination::Document
     81        || destination == FetchOptions::Destination::Report
     82        || destination == FetchOptions::Destination::Serviceworker
     83        || destination == FetchOptions::Destination::Sharedworker
     84        || destination == FetchOptions::Destination::Worker;
     85}
     86
    7287}
    7388
  • trunk/Source/WebCore/loader/ResourceLoaderOptions.h

    r222467 r223650  
    9393};
    9494
     95enum class ServiceWorkersMode {
     96    All,
     97    None,
     98};
     99
    95100struct ResourceLoaderOptions : public FetchOptions {
    96101    ResourceLoaderOptions() { }
     
    125130    SameOriginDataURLFlag sameOriginDataURLFlag { SameOriginDataURLFlag::Unset };
    126131    InitiatorContext initiatorContext { InitiatorContext::Document };
     132    ServiceWorkersMode serviceWorkersMode { ServiceWorkersMode::All };
     133    uint64_t serviceWorkerIdentifier { 0 };
    127134
    128135    ClientCredentialPolicy clientCredentialPolicy { ClientCredentialPolicy::CannotAskClientForCredentials };
  • trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp

    r219954 r223650  
    5656    : m_workerGlobalScope(workerGlobalScope)
    5757    , m_workerClientWrapper(ThreadableLoaderClientWrapper::create(client, options.initiator))
    58     , m_bridge(*new MainThreadBridge(m_workerClientWrapper.get(), workerGlobalScope.thread().workerLoaderProxy(), taskMode, WTFMove(request), options, referrer.isEmpty() ? workerGlobalScope.url().strippedForUseAsReferrer() : referrer, workerGlobalScope.securityOrigin(), workerGlobalScope.contentSecurityPolicy()))
     58    , m_bridge(*new MainThreadBridge(m_workerClientWrapper.get(), workerGlobalScope.thread().workerLoaderProxy(), taskMode, WTFMove(request), options, referrer.isEmpty() ? workerGlobalScope.url().strippedForUseAsReferrer() : referrer, workerGlobalScope))
    5959{
    6060}
     
    102102
    103103WorkerThreadableLoader::MainThreadBridge::MainThreadBridge(ThreadableLoaderClientWrapper& workerClientWrapper, WorkerLoaderProxy& loaderProxy, const String& taskMode,
    104     ResourceRequest&& request, const ThreadableLoaderOptions& options, const String& outgoingReferrer,
    105     const SecurityOrigin* securityOrigin, const ContentSecurityPolicy* contentSecurityPolicy)
     104    ResourceRequest&& request, const ThreadableLoaderOptions& options, const String& outgoingReferrer, WorkerGlobalScope& globalScope)
    106105    : m_workerClientWrapper(&workerClientWrapper)
    107106    , m_loaderProxy(loaderProxy)
    108107    , m_taskMode(taskMode.isolatedCopy())
    109108{
     109
     110    auto* securityOrigin = globalScope.securityOrigin();
     111    auto* contentSecurityPolicy = globalScope.contentSecurityPolicy();
     112
    110113    ASSERT(securityOrigin);
    111114    ASSERT(contentSecurityPolicy);
     
    121124    ASSERT(optionsCopy->options.initiatorContext == InitiatorContext::Document);
    122125    optionsCopy->options.initiatorContext = InitiatorContext::Worker;
     126
     127#if ENABLE(SERVICE_WORKER)
     128    optionsCopy->options.serviceWorkersMode = globalScope.isServiceWorkerGlobalScope() ? ServiceWorkersMode::None : ServiceWorkersMode::All;
     129    optionsCopy->options.serviceWorkerIdentifier = globalScope.selectedServiceWorkerIdentifier();
     130#endif
    123131
    124132    // Can we benefit from request being an r-value to create more efficiently its isolated copy?
  • trunk/Source/WebCore/loader/WorkerThreadableLoader.h

    r219954 r223650  
    8989        public:
    9090            // All executed on the worker context's thread.
    91             MainThreadBridge(ThreadableLoaderClientWrapper&, WorkerLoaderProxy&, const String& taskMode, ResourceRequest&&, const ThreadableLoaderOptions&, const String& outgoingReferrer, const SecurityOrigin*, const ContentSecurityPolicy*);
     91            MainThreadBridge(ThreadableLoaderClientWrapper&, WorkerLoaderProxy&, const String& taskMode, ResourceRequest&&, const ThreadableLoaderOptions&, const String& outgoingReferrer, WorkerGlobalScope&);
    9292            void cancel();
    9393            void destroy();
  • trunk/Source/WebCore/platform/network/ResourceRequestBase.h

    r220632 r223650  
    101101    WEBCORE_EXPORT String httpContentType() const;
    102102    WEBCORE_EXPORT void setHTTPContentType(const String&);
    103     void clearHTTPContentType();
     103    WEBCORE_EXPORT void clearHTTPContentType();
    104104
    105105    bool hasHTTPHeader(HTTPHeaderName) const;
  • trunk/Source/WebCore/platform/network/ResourceResponseBase.h

    r220764 r223650  
    154154    }
    155155
    156     void setType(Type);
     156    WEBCORE_EXPORT void setType(Type);
    157157    Type type() const { return m_type; }
    158158
  • trunk/Source/WebCore/workers/WorkerThread.h

    r220857 r223650  
    6262    virtual ~WorkerThread();
    6363
    64     bool start();
     64    WEBCORE_EXPORT bool start();
    6565    void stop();
    6666
  • trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp

    r222980 r223650  
    180180    }
    181181
     182    // FIXME: Implement proper selection of service workers.
     183    context->setSelectedServiceWorkerIdentifier(data.identifier);
     184
    182185    auto registration = ServiceWorkerRegistration::create(*context, data);
    183186    job.promise().resolve<IDLInterface<ServiceWorkerRegistration>>(registration.get());
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h

    r223277 r223650  
    5353
    5454private:
    55     ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID);
     55    WEBCORE_EXPORT ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID);
    5656
    5757    uint64_t m_serverConnectionIdentifier;
  • trunk/Source/WebKit/CMakeLists.txt

    r223608 r223650  
    684684    WebProcess/Plugins/PluginProxy.messages.in
    685685
     686    WebProcess/Storage/ServiceWorkerClientFetch.messages.in
    686687    WebProcess/Storage/WebSWClientConnection.messages.in
    687688
  • trunk/Source/WebKit/ChangeLog

    r223647 r223650  
     12017-10-18  Youenn Fablet  <youenn@apple.com>
     2
     3        Add preliminary support for ServiceWorker Handle Fetch
     4        https://bugs.webkit.org/show_bug.cgi?id=178475
     5
     6        Reviewed by Chris Dumez.
     7
     8        Preliminary support of Handle Fetch algorithm and integration with fetch spec.
     9        Adding ServiceWorkerClientFetch as the class responsible to do the load through ServiceWorker.
     10        It is similar to WebResourceLoader that do the load through NetworkProcess.
     11        In case ServiceWorkerClientFetch is not able to load through ServiceWorker,
     12        it will fallback to WebResourceLoader through a fallback callback.
     13
     14        Loading through Service Worker is done currently if:
     15        - There is a service worker registered for that origin
     16        - Request is a subresource
     17        - service workers mode is all
     18        There will be cases where the service worker will not do the loading, for instance when fetch event handler is not set.
     19        Future work should try to reduce the cases where the IPC dance is done unnecessarily.
     20
     21        ServiceWorkerClientFetch is responsible to adapt the ServiceWorker response to ResourceLoader.
     22        In particular, it is calling ResourceLoader error callback if response is of type error.
     23        It should call ResourceLoader redirection callback if response is a redirection response.
     24        This will be done as a follow-up.
     25
     26        Implementing the IPC communication dedicated to fetch between WebProcess and ServiceWorker through StorageProcess.
     27        In the future, WebProcess should create a direct IPC communication to the ServiceWorker process.
     28
     29        Moved SWContextManager from WebCore to WebKit and renamed it to ServiceWorkerContextManager.
     30        This class is moved to WebKit as it will have to handle IPC and having a separation will add some unnecessary boilerplate.
     31
     32        * DerivedSources.make:
     33        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
     34        (WebKit::WebSWServerConnection::startFetch):
     35        (WebKit::WebSWServerConnection::didReceiveFetchResponse):
     36        (WebKit::WebSWServerConnection::didReceiveFetchData):
     37        (WebKit::WebSWServerConnection::didFinishFetch):
     38        (WebKit::WebSWServerConnection::failedFetch):
     39        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
     40        * StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
     41        * StorageProcess/StorageProcess.cpp:
     42        (WebKit::StorageProcess::failedFetch):
     43        (WebKit::StorageProcess::didReceiveFetchResponse):
     44        (WebKit::StorageProcess::didReceiveFetchData):
     45        (WebKit::StorageProcess::didFinishFetch):
     46        * StorageProcess/StorageProcess.h:
     47        * StorageProcess/StorageProcess.messages.in:
     48        * WebKit.xcodeproj/project.pbxproj:
     49        * WebProcess/Network/WebLoaderStrategy.cpp:
     50        (WebKit::WebLoaderStrategy::scheduleLoad):
     51        (WebKit::WebLoaderStrategy::scheduleLoadFromNetworkProcess):
     52        * WebProcess/Network/WebLoaderStrategy.h:
     53        * WebProcess/Storage/ServiceWorkerClientFetch.cpp: Added.
     54        (WebKit::ServiceWorkerClientFetch::didReceiveResponse):
     55        (WebKit::ServiceWorkerClientFetch::didReceiveData):
     56        (WebKit::ServiceWorkerClientFetch::didFinishFetch):
     57        (WebKit::ServiceWorkerClientFetch::didFail):
     58        * WebProcess/Storage/ServiceWorkerClientFetch.h: Added.
     59        * WebProcess/Storage/ServiceWorkerClientFetch.messages.in: Added.
     60        * WebProcess/Storage/ServiceWorkerContextManager.cpp: Renamed from Source/WebCore/workers/service/context/SWContextManager.cpp.
     61        (WebKit::ServiceWorkerContextManager::startServiceWorkerContext):
     62        (WebKit::ServiceWorkerContextManager::startFetch):
     63        * WebProcess/Storage/ServiceWorkerContextManager.h: Renamed from Source/WebCore/workers/service/context/SWContextManager.h.
     64        (WebKit::ServiceWorkerContextManager::ServiceWorkerContextManager):
     65        * WebProcess/Storage/WebSWClientConnection.cpp:
     66        (WebKit::WebSWClientConnection::startFetch):
     67        * WebProcess/Storage/WebSWClientConnection.h:
     68        * WebProcess/Storage/WebServiceWorkerProvider.cpp:
     69        (WebKit::shouldHandleFetch):
     70        (WebKit::WebServiceWorkerProvider::handleFetch):
     71        (WebKit::WebServiceWorkerProvider::didReceiveServiceWorkerClientFetchMessage):
     72        * WebProcess/Storage/WebServiceWorkerProvider.h:
     73        * WebProcess/Storage/WebToStorageProcessConnection.cpp:
     74        (WebKit::WebToStorageProcessConnection::didReceiveMessage):
     75        * WebProcess/WebProcess.cpp:
     76        (WebKit::WebProcess::getWorkerContextConnection):
     77        (WebKit::WebProcess::startServiceWorkerContext):
     78        (WebKit::WebProcess::startFetchInServiceWorker):
     79        * WebProcess/WebProcess.h:
     80        * WebProcess/WebProcess.messages.in:
     81
    1822017-10-18  Chelsea Pugh  <cpugh@apple.com>
    283
  • trunk/Source/WebKit/DerivedSources.make

    r221541 r223650  
    126126    RemoteWebInspectorUI \
    127127    SecItemShimProxy \
     128    ServiceWorkerClientFetch \
    128129    SmartMagnificationController \
    129130    StorageAreaMap \
  • trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp

    r223608 r223650  
    3131#include "DataReference.h"
    3232#include "Logging.h"
     33#include "ServiceWorkerClientFetchMessages.h"
    3334#include "StorageProcess.h"
    3435#include "StorageToWebProcessConnectionMessages.h"
     36#include "WebCoreArgumentCoders.h"
    3537#include "WebProcess.h"
    3638#include "WebProcessMessages.h"
     
    9395}
    9496
     97void WebSWServerConnection::startFetch(uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, const ResourceRequest& request, const FetchOptions& options)
     98{
     99    sendToContextProcess(Messages::WebProcess::StartFetchInServiceWorker(identifier(), fetchIdentifier, serviceWorkerIdentifier, request, options));
     100}
     101
     102void WebSWServerConnection::didReceiveFetchResponse(uint64_t fetchIdentifier, const ResourceResponse& response)
     103{
     104    m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidReceiveResponse { response }, fetchIdentifier);
     105}
     106
     107void WebSWServerConnection::didReceiveFetchData(uint64_t fetchIdentifier, const IPC::DataReference& data, int64_t encodedDataLength)
     108{
     109    m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidReceiveData { data, encodedDataLength }, fetchIdentifier);
     110}
     111
     112void WebSWServerConnection::didFinishFetch(uint64_t fetchIdentifier)
     113{
     114    m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidFinish { }, fetchIdentifier);
     115}
     116
     117void WebSWServerConnection::didFailFetch(uint64_t fetchIdentifier)
     118{
     119    m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidFail { }, fetchIdentifier);
     120}
     121
    95122template<typename U> bool WebSWServerConnection::sendToContextProcess(U&& message)
    96123{
  • trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h

    r223608 r223650  
    5252    PAL::SessionID sessionID() const { return m_sessionID; }
    5353
     54    void didReceiveFetchResponse(uint64_t fetchIdentifier, const WebCore::ResourceResponse&);
     55    void didReceiveFetchData(uint64_t fetchIdentifier, const IPC::DataReference&, int64_t encodedDataLength);
     56    void didFinishFetch(uint64_t fetchIdentifier);
     57    void didFailFetch(uint64_t fetchIdentifier);
     58
    5459private:
    5560    // Implement SWServer::Connection (Messages to the client WebProcess)
     
    5863    void startScriptFetchInClient(uint64_t jobIdentifier) final;
    5964
     65    void startFetch(uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, const WebCore::ResourceRequest&, const WebCore::FetchOptions&);
     66
    6067    // Messages to the SW context WebProcess
    6168    void startServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;
    62    
     69
    6370    IPC::Connection* messageSenderConnection() final { return m_contentConnection.ptr(); }
    6471    uint64_t messageSenderDestinationID() final { return identifier(); }
  • trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in

    r222980 r223650  
    2727    ScheduleJobInServer(struct WebCore::ServiceWorkerJobData jobData)
    2828    FinishFetchingScriptInServer(struct WebCore::ServiceWorkerFetchResult result)
     29
     30    StartFetch(uint64_t identifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
    2931}
    3032
  • trunk/Source/WebKit/StorageProcess/StorageProcess.cpp

    r223610 r223650  
    406406}
    407407
     408void StorageProcess::didFailFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
     409{
     410    if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
     411        connection->didFailFetch(fetchIdentifier);
     412}
     413
     414void StorageProcess::didReceiveFetchResponse(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, const WebCore::ResourceResponse& response)
     415{
     416    if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
     417        connection->didReceiveFetchResponse(fetchIdentifier, response);
     418}
     419
     420void StorageProcess::didReceiveFetchData(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, const IPC::DataReference& data, int64_t encodedDataLength)
     421{
     422    if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
     423        connection->didReceiveFetchData(fetchIdentifier, data, encodedDataLength);
     424}
     425
     426void StorageProcess::didFinishFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
     427{
     428    if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
     429        connection->didFinishFetch(fetchIdentifier);
     430}
     431
    408432void StorageProcess::registerSWServerConnection(WebSWServerConnection& connection)
    409433{
  • trunk/Source/WebKit/StorageProcess/StorageProcess.h

    r223608 r223650  
    120120    void serviceWorkerContextFailedToStart(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerRegistrationKey&, const String& workerID, const String& message);
    121121    void serviceWorkerContextStarted(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerRegistrationKey&, uint64_t identifier, const String& workerID);
     122
     123    void didReceiveFetchResponse(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, const WebCore::ResourceResponse&);
     124    void didReceiveFetchData(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, const IPC::DataReference&, int64_t encodedDataLength);
     125    void didFinishFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier);
     126    void didFailFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier);
    122127#endif
    123128#if ENABLE(INDEXED_DATABASE)
  • trunk/Source/WebKit/StorageProcess/StorageProcess.messages.in

    r223608 r223650  
    3838#if ENABLE(SERVICE_WORKER)
    3939    DidGetWorkerContextProcessConnection(IPC::Attachment connectionHandle)
     40
    4041    ServiceWorkerContextFailedToStart(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerRegistrationKey registrationKey, String workerID, String message)
    4142    ServiceWorkerContextStarted(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerRegistrationKey registrationKey, uint64_t identifier, String workerID)
     43
     44    DidFailFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
     45    DidReceiveFetchResponse(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, WebCore::ResourceResponse response)
     46    DidReceiveFetchData(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, IPC::DataReference data, int64_t encodedDataLength)
     47    DidFinishFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
    4248#endif
    4349}
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r223608 r223650  
    891891                413075B31DE85F580039EC69 /* LibWebRTCProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 413075A71DE85EE70039EC69 /* LibWebRTCProvider.cpp */; };
    892892                413075B41DE85F580039EC69 /* LibWebRTCProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 413075A81DE85EE70039EC69 /* LibWebRTCProvider.h */; };
     893                4131F3D11F96BCCC0059995A /* ServiceWorkerClientFetch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4131F3D01F96BCC80059995A /* ServiceWorkerClientFetch.cpp */; };
     894                4131F3D41F96E9350059995A /* ServiceWorkerContextManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4131F3D31F96E9310059995A /* ServiceWorkerContextManager.cpp */; };
     895                4131F3D51F96E9350059995A /* ServiceWorkerContextManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4131F3D21F96E9300059995A /* ServiceWorkerContextManager.h */; };
    893896                4135FBD11F4FB8090074C47B /* CacheStorageEngineCaches.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4135FBCF1F4FB7F20074C47B /* CacheStorageEngineCaches.cpp */; };
    894897                41897ECF1F415D620016FA42 /* WebCacheStorageConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41897ECE1F415D5C0016FA42 /* WebCacheStorageConnection.cpp */; };
     
    10301033                5179556D162877B100FA43B6 /* NetworkProcessProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 510CC7EA16138E7200D03ED3 /* NetworkProcessProxy.cpp */; };
    10311034                5179556E162877B300FA43B6 /* NetworkProcessProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 510CC7EB16138E7200D03ED3 /* NetworkProcessProxy.h */; };
     1035                617A52D81F43A9DA00DCDC0A /* ServiceWorkerClientFetchMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 617A52D71F43A9B600DCDC0A /* ServiceWorkerClientFetchConnectionMessageReceiver.cpp */; };
    10321036                517A52D81F43A9DA00DCDC0A /* WebSWServerConnectionMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A52D71F43A9B600DCDC0A /* WebSWServerConnectionMessageReceiver.cpp */; };
     1037                617A52D91F43A9DA00DCDC0A /* ServiceWorkerClientFetchMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 617A52D61F43A9B600DCDC0A /* ServiceWorkerClientFetchMessages.h */; };
    10331038                517A52D91F43A9DA00DCDC0A /* WebSWServerConnectionMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A52D61F43A9B600DCDC0A /* WebSWServerConnectionMessages.h */; };
    10341039                517A53041F4793C600DCDC0A /* WebSWClientConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A53031F4793B200DCDC0A /* WebSWClientConnection.cpp */; };
     
    31793184                413075A71DE85EE70039EC69 /* LibWebRTCProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = LibWebRTCProvider.cpp; path = Network/webrtc/LibWebRTCProvider.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
    31803185                413075A81DE85EE70039EC69 /* LibWebRTCProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = LibWebRTCProvider.h; path = Network/webrtc/LibWebRTCProvider.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
     3186                4131F3CE1F96A4950059995A /* ServiceWorkerClientFetch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerClientFetch.h; sourceTree = "<group>"; };
     3187                4131F3CF1F96A9360059995A /* ServiceWorkerClientFetch.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ServiceWorkerClientFetch.messages.in; sourceTree = "<group>"; };
     3188                4131F3D01F96BCC80059995A /* ServiceWorkerClientFetch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerClientFetch.cpp; sourceTree = "<group>"; };
     3189                4131F3D21F96E9300059995A /* ServiceWorkerContextManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerContextManager.h; sourceTree = "<group>"; };
     3190                4131F3D31F96E9310059995A /* ServiceWorkerContextManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerContextManager.cpp; sourceTree = "<group>"; };
    31813191                4135FBCF1F4FB7F20074C47B /* CacheStorageEngineCaches.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CacheStorageEngineCaches.cpp; sourceTree = "<group>"; };
    31823192                4135FBD01F4FB7F20074C47B /* CacheStorageEngineCaches.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheStorageEngineCaches.h; sourceTree = "<group>"; };
     
    33353345                517A33B3130B308C00F80CB5 /* WKApplicationCacheManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKApplicationCacheManager.cpp; sourceTree = "<group>"; };
    33363346                517A33B4130B308C00F80CB5 /* WKApplicationCacheManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKApplicationCacheManager.h; sourceTree = "<group>"; };
     3347                617A52D61F43A9B600DCDC0A /* ServiceWorkerFetchClientMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSWServerConnectionMessages.h; sourceTree = "<group>"; };
    33373348                517A52D61F43A9B600DCDC0A /* WebSWServerConnectionMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSWServerConnectionMessages.h; sourceTree = "<group>"; };
     3349                617A52D71F43A9B600DCDC0A /* ServiceWorkerClientFetchMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerClientFetchMessageReceiver.cpp; sourceTree = "<group>"; };
    33383350                517A52D71F43A9B600DCDC0A /* WebSWServerConnectionMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSWServerConnectionMessageReceiver.cpp; sourceTree = "<group>"; };
    33393351                517A53021F4793B200DCDC0A /* WebSWClientConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSWClientConnection.h; sourceTree = "<group>"; };
     
    61696181                        isa = PBXGroup;
    61706182                        children = (
     6183                                4131F3D01F96BCC80059995A /* ServiceWorkerClientFetch.cpp */,
     6184                                4131F3CE1F96A4950059995A /* ServiceWorkerClientFetch.h */,
     6185                                4131F3CF1F96A9360059995A /* ServiceWorkerClientFetch.messages.in */,
     6186                                4131F3D31F96E9310059995A /* ServiceWorkerContextManager.cpp */,
     6187                                4131F3D21F96E9300059995A /* ServiceWorkerContextManager.h */,
    61716188                                51BEB6291F3A5ACD005029B9 /* WebServiceWorkerProvider.cpp */,
    61726189                                51BEB62A1F3A5ACD005029B9 /* WebServiceWorkerProvider.h */,
     
    80118028                                E18E6913169B667B009B6670 /* SecItemShimProxyMessageReceiver.cpp */,
    80128029                                E18E6914169B667B009B6670 /* SecItemShimProxyMessages.h */,
     8030                                617A52D71F43A9B600DCDC0A /* ServiceWorkerClientFetchConnectionMessageReceiver.cpp */,
    80138031                                2DE6943B18BD2A68005C15E5 /* SmartMagnificationControllerMessageReceiver.cpp */,
    80148032                                2DE6943C18BD2A68005C15E5 /* SmartMagnificationControllerMessages.h */,
     
    87828800                                E18E6918169B667B009B6670 /* SecItemShimProxyMessages.h in Headers */,
    87838801                                514D9F5719119D35000063A7 /* ServicesController.h in Headers */,
     8802                                4131F3D51F96E9350059995A /* ServiceWorkerContextManager.h in Headers */,
    87848803                                1AFDE65A1954A42B00C48FFA /* SessionState.h in Headers */,
    87858804                                1A002D49196B345D00B9AD44 /* SessionStateCoding.h in Headers */,
     
    1037110390                                E18E6917169B667B009B6670 /* SecItemShimProxyMessageReceiver.cpp in Sources */,
    1037210391                                514D9F5819119D35000063A7 /* ServicesController.mm in Sources */,
     10392                                4131F3D11F96BCCC0059995A /* ServiceWorkerClientFetch.cpp in Sources */,
     10393                                617A52D81F43A9DA00DCDC0A /* ServiceWorkerClientFetchConnectionMessageReceiver.cpp in Sources */,
     10394                                4131F3D41F96E9350059995A /* ServiceWorkerContextManager.cpp in Sources */,
    1037310395                                1AFDE6591954A42B00C48FFA /* SessionState.cpp in Sources */,
    1037410396                                1A002D48196B345D00B9AD44 /* SessionStateCoding.mm in Sources */,
  • trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp

    r223238 r223650  
    4444#include "WebProcess.h"
    4545#include "WebResourceLoader.h"
     46#include "WebServiceWorkerProvider.h"
    4647#include "WebURLSchemeHandlerProxy.h"
    4748#include "WebURLSchemeTaskProxy.h"
     
    216217    }
    217218
     219#if ENABLE(SERVICE_WORKER)
     220    WebServiceWorkerProvider::singleton().handleFetch(resourceLoader, resource, webPage ? webPage->sessionID() : PAL::SessionID::defaultSessionID(), [trackingParameters, shouldClearReferrerOnHTTPSToHTTPRedirect, maximumBufferingTime = maximumBufferingTime(resource), resourceLoader = makeRef(resourceLoader)] (ServiceWorkerClientFetch::Result result) mutable {
     221        if (result != ServiceWorkerClientFetch::Result::Unhandled)
     222            return;
     223
     224        LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be scheduled through ServiceWorker handle fetch algorithm", resourceLoader->url().string().latin1().data());
     225        WebProcess::singleton().webLoaderStrategy().scheduleLoadFromNetworkProcess(resourceLoader.get(), resourceLoader->originalRequest(), WTFMove(trackingParameters), shouldClearReferrerOnHTTPSToHTTPRedirect, maximumBufferingTime);
     226    });
     227#else
     228    LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be scheduled through ServiceWorker handle fetch algorithm", resourceLoader.url().string().latin1().data());
     229    scheduleLoadFromNetworkProcess(resourceLoader, resourceLoader.request(), trackingParameters, shouldClearReferrerOnHTTPSToHTTPRedirect, maximumBufferingTime(resource));
     230#endif
     231}
     232
     233void WebLoaderStrategy::scheduleLoadFromNetworkProcess(ResourceLoader& resourceLoader, const ResourceRequest& request, const WebResourceLoader::TrackingParameters& trackingParameters, bool shouldClearReferrerOnHTTPSToHTTPRedirect, Seconds maximumBufferingTime)
     234{
     235    ResourceLoadIdentifier identifier = resourceLoader.identifier();
     236    ASSERT(identifier);
     237
     238    WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(resourceLoader.frameLoader()->client());
     239    WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : nullptr;
     240    WebPage* webPage = webFrame ? webFrame->page() : nullptr;
     241
    218242    LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be scheduled with the NetworkProcess with priority %d", resourceLoader.url().string().latin1().data(), static_cast<int>(resourceLoader.request().priority()));
    219243
     
    226250    loadParameters.webFrameID = webFrame ? webFrame->frameID() : 0;
    227251    loadParameters.sessionID = webPage ? webPage->sessionID() : PAL::SessionID::defaultSessionID();
    228     loadParameters.request = resourceLoader.request();
     252    loadParameters.request = request;
    229253    loadParameters.contentSniffingPolicy = contentSniffingPolicy;
    230254    loadParameters.storedCredentialsPolicy = storedCredentialsPolicy;
     
    234258    loadParameters.defersLoading = resourceLoader.defersLoading();
    235259    loadParameters.needsCertificateInfo = resourceLoader.shouldIncludeCertificateInfo();
    236     loadParameters.maximumBufferingTime = maximumBufferingTime(resource);
     260    loadParameters.maximumBufferingTime = maximumBufferingTime;
    237261    loadParameters.derivedCachedDataTypesToRetrieve = resourceLoader.options().derivedCachedDataTypesToRetrieve;
    238262
     
    301325        return;
    302326    }
    303    
     327
     328#if ENABLE(SERVICE_WORKER)
     329    if (WebServiceWorkerProvider::singleton().cancelFetch(identifier))
     330        return;
     331#endif
     332
    304333    RefPtr<WebResourceLoader> loader = m_webResourceLoaders.take(identifier);
    305334    // Loader may not be registered if we created it, but haven't scheduled yet (a bundle client can decide to cancel such request via willSendRequest).
  • trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.h

    r222739 r223650  
    7878    void removeURLSchemeTaskProxy(WebURLSchemeTaskProxy&);
    7979
     80    void scheduleLoadFromNetworkProcess(WebCore::ResourceLoader&, const WebCore::ResourceRequest&, const WebResourceLoader::TrackingParameters&, bool shouldClearReferrerOnHTTPSToHTTPRedirect, Seconds maximumBufferingTime);
     81
    8082private:
    8183    void scheduleLoad(WebCore::ResourceLoader&, WebCore::CachedResource*, bool shouldClearReferrerOnHTTPSToHTTPRedirect);
  • trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.h

    r223649 r223650  
    2828#if ENABLE(SERVICE_WORKER)
    2929
    30 #include "Connection.h"
    3130#include "MessageReceiver.h"
    3231#include "MessageSender.h"
    33 #include "SharedMemory.h"
    34 #include <WebCore/SWClientConnection.h>
    35 #include <pal/SessionID.h>
    36 #include <wtf/UniqueRef.h>
    37 
    38 namespace WebCore {
    39 struct ExceptionData;
    40 }
     32#include <WebCore/ResourceLoader.h>
     33#include <wtf/CompletionHandler.h>
    4134
    4235namespace WebKit {
    4336
    44 class WebSWOriginTable;
     37class WebServiceWorkerProvider;
    4538
    46 class WebSWClientConnection : public WebCore::SWClientConnection, public IPC::MessageSender, public IPC::MessageReceiver {
     39class ServiceWorkerClientFetch final : public RefCounted<ServiceWorkerClientFetch>, public IPC::MessageSender, public IPC::MessageReceiver {
    4740public:
    48     WebSWClientConnection(IPC::Connection&, PAL::SessionID);
    49     WebSWClientConnection(const WebSWClientConnection&) = delete;
    50     ~WebSWClientConnection() final;
     41    enum class Result { Succeeded, Cancelled, Unhandled };
     42    using Callback = WTF::CompletionHandler<void(Result)>;
    5143
    52     uint64_t identifier() const final { return m_identifier; }
     44    static Ref<ServiceWorkerClientFetch> create(WebServiceWorkerProvider& serviceWorkerProvider, Ref<WebCore::ResourceLoader>&& loader, uint64_t identifier, Ref<IPC::Connection>&& connection, Callback&& callback)
     45    {
     46        return adoptRef(*new ServiceWorkerClientFetch { serviceWorkerProvider, WTFMove(loader), identifier, WTFMove(connection), WTFMove(callback) });
     47    }
    5348
    54     void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final;
    55     void finishFetchingScriptInServer(const WebCore::ServiceWorkerFetchResult&) final;
     49    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
     50    void cancel();
    5651
    57     void disconnectedFromWebProcess();
    58     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
    59 
    60     bool hasServiceWorkerRegisteredForOrigin(const WebCore::SecurityOrigin&) const final;
     52    bool isOngoing() const { return !!m_callback; }
    6153
    6254private:
    63     void scheduleStorageJob(const WebCore::ServiceWorkerJobData&);
     55    ServiceWorkerClientFetch(WebServiceWorkerProvider&, Ref<WebCore::ResourceLoader>&&, uint64_t identifier, Ref<IPC::Connection>&&, Callback&&);
     56
     57    void didReceiveResponse(const WebCore::ResourceResponse&);
     58    void didReceiveData(const IPC::DataReference&, int64_t encodedDataLength);
     59    void didFinish();
     60    void didFail();
    6461
    6562    IPC::Connection* messageSenderConnection() final { return m_connection.ptr(); }
    6663    uint64_t messageSenderDestinationID() final { return m_identifier; }
    6764
    68     void setSWOriginTableSharedMemory(const SharedMemory::Handle&);
    69 
    70     PAL::SessionID m_sessionID;
    71     uint64_t m_identifier;
    72 
     65    WebServiceWorkerProvider& m_serviceWorkerProvider;
     66    Ref<WebCore::ResourceLoader> m_loader;
     67    uint64_t m_identifier { 0 };
    7368    Ref<IPC::Connection> m_connection;
    74     UniqueRef<WebSWOriginTable> m_swOriginTable;
    75 }; // class WebSWServerConnection
     69    Callback m_callback;
     70};
    7671
    7772} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.messages.in

    r223649 r223650  
    2323#if ENABLE(SERVICE_WORKER)
    2424
    25 messages -> WebSWServerConnection {
    26     # When possible, these messages can be implemented directly by WebCore::SWClientConnection
    27     ScheduleJobInServer(struct WebCore::ServiceWorkerJobData jobData)
    28     FinishFetchingScriptInServer(struct WebCore::ServiceWorkerFetchResult result)
     25messages -> ServiceWorkerClientFetch {
     26    DidReceiveResponse(WebCore::ResourceResponse response)
     27    DidReceiveData(IPC::DataReference data, int64_t encodedDataLength)
     28    DidFinish()
     29    DidFail()
    2930}
    3031
  • trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h

    r223649 r223650  
    2828#if ENABLE(SERVICE_WORKER)
    2929
    30 #include "ExceptionOr.h"
    31 #include "ServiceWorkerThread.h"
     30#include "Connection.h"
     31#include <WebCore/ServiceWorkerThread.h>
    3232#include <wtf/HashMap.h>
    3333
    3434namespace WebCore {
     35struct FetchOptions;
     36class ResourceRequest;
     37struct ServiceWorkerContextData;
     38}
    3539
    36 struct ServiceWorkerContextData;
     40namespace WebKit {
    3741
    38 class SWContextManager {
     42class ServiceWorkerContextManager {
    3943public:
    40     WEBCORE_EXPORT static SWContextManager& singleton();
     44    explicit ServiceWorkerContextManager(Ref<IPC::Connection>&& connection)
     45        : m_connectionToStorageProcess(WTFMove(connection))
     46    {
     47    }
    4148
    42     WEBCORE_EXPORT ExceptionOr<uint64_t> startServiceWorkerContext(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&);
     49    void startServiceWorkerContext(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
     50    void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, const WebCore::ResourceRequest&, const WebCore::FetchOptions&);
    4351
    4452private:
    45     SWContextManager();
    46    
    47     HashMap<uint64_t, RefPtr<ServiceWorkerThread>> m_workerThreadMap;
     53    Ref<IPC::Connection> m_connectionToStorageProcess;
     54    HashMap<uint64_t, RefPtr<WebCore::ServiceWorkerThread>> m_workerThreadMap;
    4855};
    4956
    50 } // namespace WebCore
     57} // namespace WebKit
    5158
    5259#endif // ENABLE(SERVICE_WORKER)
  • trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp

    r223608 r223650  
    3030
    3131#include "Logging.h"
     32#include "ServiceWorkerClientFetch.h"
    3233#include "StorageToWebProcessConnectionMessages.h"
    3334#include "WebCoreArgumentCoders.h"
     
    7677}
    7778
     79Ref<ServiceWorkerClientFetch> WebSWClientConnection::startFetch(WebServiceWorkerProvider& provider, Ref<WebCore::ResourceLoader>&& loader, uint64_t identifier, ServiceWorkerClientFetch::Callback&& callback)
     80{
     81    ASSERT(loader->options().serviceWorkersMode == ServiceWorkersMode::All);
     82    // FIXME: Decide whether to assert for loader->options().serviceWorkerIdentifier once we have a story for navigation loads.
     83
     84    send(Messages::WebSWServerConnection::StartFetch(identifier, loader->options().serviceWorkerIdentifier, loader->originalRequest(), loader->options()));
     85    return ServiceWorkerClientFetch::create(provider, WTFMove(loader), identifier, m_connection.get(), WTFMove(callback));
     86}
     87
    7888} // namespace WebKit
    7989
  • trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h

    r223608 r223650  
    3131#include "MessageReceiver.h"
    3232#include "MessageSender.h"
     33#include "ServiceWorkerClientFetch.h"
    3334#include "SharedMemory.h"
    3435#include <WebCore/SWClientConnection.h>
     
    3839namespace WebCore {
    3940struct ExceptionData;
     41class ResourceLoader;
    4042}
    4143
     
    4345
    4446class WebSWOriginTable;
     47class WebServiceWorkerProvider;
    4548
    4649class WebSWClientConnection : public WebCore::SWClientConnection, public IPC::MessageSender, public IPC::MessageReceiver {
     
    5962
    6063    bool hasServiceWorkerRegisteredForOrigin(const WebCore::SecurityOrigin&) const final;
     64    Ref<ServiceWorkerClientFetch> startFetch(WebServiceWorkerProvider&, Ref<WebCore::ResourceLoader>&&, uint64_t identifier, ServiceWorkerClientFetch::Callback&&);
    6165
    6266private:
  • trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp

    r223608 r223650  
    5959}
    6060
     61static inline bool shouldHandleFetch(const WebSWClientConnection& connection, CachedResource* resource, const ResourceLoaderOptions& options)
     62{
     63    if (options.serviceWorkersMode != ServiceWorkersMode::All)
     64        return false;
     65
     66    // FIXME: We should probably assert that options.serviceWorkersIdentifier is not null.
     67    if (isPotentialNavigationOrSubresourceRequest(options.destination))
     68        return false;
     69
     70    // FIXME: Implement non-subresource request loads.
     71    if (isNonSubresourceRequest(options.destination))
     72        return false;
     73
     74    if (!resource)
     75        return false;
     76
     77    return connection.hasServiceWorkerRegisteredForOrigin(*resource->origin());
     78}
     79
     80void WebServiceWorkerProvider::handleFetch(ResourceLoader& loader, CachedResource* resource, PAL::SessionID sessionID, ServiceWorkerClientFetch::Callback&& callback)
     81{
     82    auto& connection = WebProcess::singleton().webToStorageProcessConnection()->serviceWorkerConnectionForSession(sessionID);
     83
     84    if (!shouldHandleFetch(connection, resource, loader.options())) {
     85        // FIXME: Add an option to error resource load for DTL to actually go through preflight.
     86        callback(ServiceWorkerClientFetch::Result::Unhandled);
     87        return;
     88    }
     89
     90    auto fetch = connection.startFetch(*this, loader, loader.identifier(), WTFMove(callback));
     91    ASSERT(fetch->isOngoing());
     92
     93    m_ongoingFetchTasks.add(loader.identifier(), WTFMove(fetch));
     94}
     95
     96bool WebServiceWorkerProvider::cancelFetch(uint64_t fetchIdentifier)
     97{
     98    auto fetch = m_ongoingFetchTasks.take(fetchIdentifier);
     99    if (fetch)
     100        (*fetch)->cancel();
     101    return !!fetch;
     102}
     103
     104void WebServiceWorkerProvider::fetchFinished(uint64_t fetchIdentifier)
     105{
     106    m_ongoingFetchTasks.take(fetchIdentifier);
     107}
     108
     109void WebServiceWorkerProvider::didReceiveServiceWorkerClientFetchMessage(IPC::Connection& connection, IPC::Decoder& decoder)
     110{
     111    if (auto fetch = m_ongoingFetchTasks.get(decoder.destinationID()))
     112        fetch->didReceiveMessage(connection, decoder);
     113}
     114
    61115} // namespace WebKit
    62116
  • trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.h

    r223608 r223650  
    2828#if ENABLE(SERVICE_WORKER)
    2929
     30#include "ServiceWorkerClientFetch.h"
    3031#include <WebCore/ServiceWorkerProvider.h>
    3132#include <wtf/NeverDestroyed.h>
     
    3738    static WebServiceWorkerProvider& singleton();
    3839
     40    void handleFetch(WebCore::ResourceLoader&, WebCore::CachedResource*, PAL::SessionID, ServiceWorkerClientFetch::Callback&&);
     41    bool cancelFetch(uint64_t fetchIdentifier);
     42    void fetchFinished(uint64_t fetchIdentifier);
     43
     44    void didReceiveServiceWorkerClientFetchMessage(IPC::Connection&, IPC::Decoder&);
     45
    3946private:
    4047    friend NeverDestroyed<WebServiceWorkerProvider>;
     
    4350    WebCore::SWClientConnection& serviceWorkerConnectionForSession(PAL::SessionID) final;
    4451
     52    HashMap<uint64_t, Ref<ServiceWorkerClientFetch>> m_ongoingFetchTasks;
    4553}; // class WebServiceWorkerProvider
    4654
  • trunk/Source/WebKit/WebProcess/Storage/WebToStorageProcessConnection.cpp

    r223608 r223650  
    2828#include "WebToStorageProcessConnection.h"
    2929
     30#include "ServiceWorkerClientFetchMessages.h"
    3031#include "StorageToWebProcessConnectionMessages.h"
    3132#include "WebIDBConnectionToServerMessages.h"
     
    3334#include "WebSWClientConnection.h"
    3435#include "WebSWClientConnectionMessages.h"
     36#include "WebServiceWorkerProvider.h"
    3537
    3638using namespace PAL;
     
    6668        if (serviceWorkerConnection)
    6769            serviceWorkerConnection->didReceiveMessage(connection, decoder);
     70        return;
     71    }
     72    if (decoder.messageReceiverName() == Messages::ServiceWorkerClientFetch::messageReceiverName()) {
     73        WebServiceWorkerProvider::singleton().didReceiveServiceWorkerClientFetchMessage(connection, decoder);
    6874        return;
    6975    }
  • trunk/Source/WebKit/WebProcess/WebProcess.cpp

    r223608 r223650  
    4141#include "NetworkSession.h"
    4242#include "PluginProcessConnectionManager.h"
     43#include "ServiceWorkerContextManager.h"
    4344#include "SessionTracker.h"
    4445#include "StatisticsData.h"
     
    106107#include <WebCore/ResourceLoadStatistics.h>
    107108#include <WebCore/RuntimeApplicationChecks.h>
    108 #include <WebCore/SWContextManager.h>
    109109#include <WebCore/SchemeRegistry.h>
    110110#include <WebCore/SecurityOrigin.h>
     
    16231623void WebProcess::getWorkerContextConnection()
    16241624{
    1625     ASSERT(!m_workerContextConnection);
     1625    ASSERT(!m_serviceWorkerManager);
    16261626
    16271627#if USE(UNIX_DOMAIN_SOCKETS)
     
    16431643#endif
    16441644
    1645     m_workerContextConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
    1646     m_workerContextConnection->open();
    1647 
     1645    auto workerContextConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
     1646    workerContextConnection->open();
     1647    m_serviceWorkerManager =  ServiceWorkerContextManager(WTFMove(workerContextConnection));
    16481648    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidGetWorkerContextConnection(connectionClientPort), 0);
    16491649}
     
    16511651void WebProcess::startServiceWorkerContext(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data)
    16521652{
    1653     auto contextResult = SWContextManager::singleton().startServiceWorkerContext(serverConnectionIdentifier, data);
    1654    
    1655     if (contextResult.hasException())
    1656         m_workerContextConnection->send(Messages::StorageProcess::ServiceWorkerContextFailedToStart(serverConnectionIdentifier, data.registrationKey, data.workerID, contextResult.exception().message()), 0);
    1657     else
    1658         m_workerContextConnection->send(Messages::StorageProcess::ServiceWorkerContextStarted(serverConnectionIdentifier, data.registrationKey, contextResult.returnValue(), data.workerID), 0);
     1653    ASSERT(m_serviceWorkerManager);
     1654    if (!m_serviceWorkerManager)
     1655        return;
     1656
     1657    m_serviceWorkerManager->startServiceWorkerContext(serverConnectionIdentifier, data);
     1658}
     1659
     1660void WebProcess::startFetchInServiceWorker(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, const ResourceRequest& request, const FetchOptions& options)
     1661{
     1662    if (!m_serviceWorkerManager)
     1663        return;
     1664
     1665    m_serviceWorkerManager->startFetch(serverConnectionIdentifier, fetchIdentifier, serviceWorkerIdentifier, request, options);
    16591666}
    16601667
  • trunk/Source/WebKit/WebProcess/WebProcess.h

    r223191 r223650  
    3131#include "ResourceCachesToClear.h"
    3232#include "SandboxExtension.h"
     33#include "ServiceWorkerContextManager.h"
    3334#include "TextCheckerState.h"
    3435#include "ViewUpdateDispatcher.h"
     
    301302    void getWorkerContextConnection();
    302303    void startServiceWorkerContext(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
    303     RefPtr<IPC::Connection> m_workerContextConnection;
     304    void startFetchInServiceWorker(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, const WebCore::ResourceRequest&, const WebCore::FetchOptions&);
    304305#endif
    305306
     
    439440    std::unique_ptr<WaylandCompositorDisplay> m_waylandCompositorDisplay;
    440441#endif
     442#if ENABLE(SERVICE_WORKER)
     443    std::optional<ServiceWorkerContextManager> m_serviceWorkerManager;
     444#endif
    441445};
    442446
  • trunk/Source/WebKit/WebProcess/WebProcess.messages.in

    r223191 r223650  
    118118    GetWorkerContextConnection()
    119119    StartServiceWorkerContext(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerContextData contextData)
     120    StartFetchInServiceWorker(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
    120121#endif
    121122}
Note: See TracChangeset for help on using the changeset viewer.