Changeset 232769 in webkit


Ignore:
Timestamp:
Jun 12, 2018 12:28:38 PM (6 years ago)
Author:
Kocsen Chung
Message:

Cherry-pick r232580. rdar://problem/38881568

Don't start service worker fetch when there is substitute data
https://bugs.webkit.org/show_bug.cgi?id=186349
<rdar://problem/38881568>

Reviewed by Youenn Fablet.

Loading content via WKWebView.loadData may also end up starting a main resource service worker fetch.
This breaks DocumentWriter assumptions.

  • loader/DocumentLoader.cpp: (WebCore::DocumentLoader::tryLoadingRequestFromApplicationCache): (WebCore::DocumentLoader::tryLoadingSubstituteData):

Factor substitute resource loading out from tryLoadingRequestFromApplicationCache.

(WebCore::DocumentLoader::startLoadingMainResource):

If we have substitute data already (typically from WKWebView.loadData), allow service worker registration
but load the main resource using the substitute data.

(WebCore::DocumentLoader::handleSubstituteDataLoadSoon): Deleted.

Merge to tryLoadingSubstituteData.

  • loader/DocumentLoader.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232580 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-606.1.20.40-branch
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-606.1.20.40-branch/Source/WebCore/ChangeLog

    r232586 r232769  
     12018-06-12  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r232580. rdar://problem/38881568
     4
     5    Don't start service worker fetch when there is substitute data
     6    https://bugs.webkit.org/show_bug.cgi?id=186349
     7    <rdar://problem/38881568>
     8   
     9    Reviewed by Youenn Fablet.
     10   
     11    Loading content via WKWebView.loadData may also end up starting a main resource service worker fetch.
     12    This breaks DocumentWriter assumptions.
     13   
     14    * loader/DocumentLoader.cpp:
     15    (WebCore::DocumentLoader::tryLoadingRequestFromApplicationCache):
     16    (WebCore::DocumentLoader::tryLoadingSubstituteData):
     17   
     18    Factor substitute resource loading out from tryLoadingRequestFromApplicationCache.
     19   
     20    (WebCore::DocumentLoader::startLoadingMainResource):
     21   
     22    If we have substitute data already (typically from WKWebView.loadData), allow service worker registration
     23    but load the main resource using the substitute data.
     24   
     25    (WebCore::DocumentLoader::handleSubstituteDataLoadSoon): Deleted.
     26   
     27    Merge to tryLoadingSubstituteData.
     28   
     29    * loader/DocumentLoader.h:
     30   
     31   
     32    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232580 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     33
     34    2018-06-07  Antti Koivisto  <antti@apple.com>
     35
     36            Don't start service worker fetch when there is substitute data
     37            https://bugs.webkit.org/show_bug.cgi?id=186349
     38            <rdar://problem/38881568>
     39
     40            Reviewed by Youenn Fablet.
     41
     42            Loading content via WKWebView.loadData may also end up starting a main resource service worker fetch.
     43            This breaks DocumentWriter assumptions.
     44
     45            * loader/DocumentLoader.cpp:
     46            (WebCore::DocumentLoader::tryLoadingRequestFromApplicationCache):
     47            (WebCore::DocumentLoader::tryLoadingSubstituteData):
     48
     49            Factor substitute resource loading out from tryLoadingRequestFromApplicationCache.
     50
     51            (WebCore::DocumentLoader::startLoadingMainResource):
     52
     53            If we have substitute data already (typically from WKWebView.loadData), allow service worker registration
     54            but load the main resource using the substitute data.
     55
     56            (WebCore::DocumentLoader::handleSubstituteDataLoadSoon): Deleted.
     57
     58            Merge to tryLoadingSubstituteData.
     59
     60            * loader/DocumentLoader.h:
     61
    1622018-06-07  Kocsen Chung  <kocsen_chung@apple.com>
    263
  • branches/safari-606.1.20.40-branch/Source/WebCore/loader/DocumentLoader.cpp

    r232419 r232769  
    479479}
    480480
    481 void DocumentLoader::handleSubstituteDataLoadSoon()
    482 {
    483     if (!m_deferMainResourceDataLoad || frameLoader()->loadsSynchronously())
    484         handleSubstituteDataLoadNow();
    485     else
    486         startDataLoadTimer();
    487 }
    488 
    489481#if ENABLE(SERVICE_WORKER)
    490482void DocumentLoader::matchRegistration(const URL& url, SWClientConnection::RegistrationCallback&& callback)
     
    672664{
    673665    m_applicationCacheHost->maybeLoadMainResource(m_request, m_substituteData);
    674 
     666    return tryLoadingSubstituteData();
     667}
     668
     669bool DocumentLoader::tryLoadingSubstituteData()
     670{
    675671    if (!m_substituteData.isValid() || !m_frame->page())
    676672        return false;
    677673
    678     RELEASE_LOG_IF_ALLOWED("startLoadingMainResource: Returning cached main resource (frame = %p, main = %d)", m_frame, m_frame->isMainFrame());
     674    RELEASE_LOG_IF_ALLOWED("startLoadingMainResource: Returning substitute data (frame = %p, main = %d)", m_frame, m_frame->isMainFrame());
    679675    m_identifierForLoadWithoutResourceLoader = m_frame->page()->progress().createUniqueIdentifier();
    680676    frameLoader()->notifier().assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, this, m_request);
    681677    frameLoader()->notifier().dispatchWillSendRequest(this, m_identifierForLoadWithoutResourceLoader, m_request, ResourceResponse());
    682     handleSubstituteDataLoadSoon();
     678
     679    if (!m_deferMainResourceDataLoad || frameLoader()->loadsSynchronously())
     680        handleSubstituteDataLoadNow();
     681    else
     682        startDataLoadTimer();
     683
    683684    return true;
    684685}
     
    17291730
    17301731            m_serviceWorkerRegistrationData = WTFMove(registrationData);
     1732
     1733            // Prefer existing substitute data (from WKWebView.loadData etc) over service worker fetch.
     1734            if (this->tryLoadingSubstituteData())
     1735                return;
     1736            // Try app cache only if there is no service worker.
    17311737            if (!m_serviceWorkerRegistrationData && this->tryLoadingRequestFromApplicationCache())
    17321738                return;
  • branches/safari-606.1.20.40-branch/Source/WebCore/loader/DocumentLoader.h

    r232419 r232769  
    378378
    379379    bool tryLoadingRequestFromApplicationCache();
     380    bool tryLoadingSubstituteData();
    380381    bool tryLoadingRedirectRequestFromApplicationCache(const ResourceRequest&);
    381382#if ENABLE(SERVICE_WORKER)
     
    392393    typedef Timer DocumentLoaderTimer;
    393394#endif
    394     void handleSubstituteDataLoadSoon();
    395395    void handleSubstituteDataLoadNow();
    396396    void startDataLoadTimer();
  • branches/safari-606.1.20.40-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm

    r229927 r232769  
    13711371}
    13721372
     1373TEST(ServiceWorkers, LoadData)
     1374{
     1375    ASSERT(mainBytes);
     1376    ASSERT(scriptBytes);
     1377
     1378    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
     1379
     1380    // Start with a clean slate data store
     1381    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
     1382        done = true;
     1383    }];
     1384    TestWebKitAPI::Util::run(&done);
     1385    done = false;
     1386
     1387    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1388
     1389    RetainPtr<SWMessageHandler> messageHandler = adoptNS([[SWMessageHandler alloc] init]);
     1390    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
     1391
     1392    RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]);
     1393    handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes });
     1394    handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", scriptBytes });
     1395    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
     1396
     1397    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1398    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
     1399
     1400    auto delegate = adoptNS([[TestSWAsyncNavigationDelegate alloc] init]);
     1401    [webView setNavigationDelegate:delegate.get()];
     1402    [webView setUIDelegate:delegate.get()];
     1403
     1404    done = false;
     1405
     1406    // Normal load to get SW registered.
     1407    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     1408    [webView loadRequest:request];
     1409
     1410    TestWebKitAPI::Util::run(&done);
     1411    done = false;
     1412
     1413    // Now try a data load.
     1414    NSData *data = [NSData dataWithBytes:mainBytes length:strlen(mainBytes)];
     1415    [webView loadData:data MIMEType:@"text/html" characterEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"sw://host/main.html"]];
     1416
     1417    TestWebKitAPI::Util::run(&done);
     1418    done = false;
     1419}
     1420
    13731421#endif // WK_API_ENABLED
Note: See TracChangeset for help on using the changeset viewer.