Changeset 232580 in webkit
- Timestamp:
- Jun 7, 2018 7:59:03 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r232579 r232580 1 2018-06-07 Antti Koivisto <antti@apple.com> 2 3 Don't start service worker fetch when there is substitute data 4 https://bugs.webkit.org/show_bug.cgi?id=186349 5 <rdar://problem/38881568> 6 7 Reviewed by Youenn Fablet. 8 9 Loading content via WKWebView.loadData may also end up starting a main resource service worker fetch. 10 This breaks DocumentWriter assumptions. 11 12 * loader/DocumentLoader.cpp: 13 (WebCore::DocumentLoader::tryLoadingRequestFromApplicationCache): 14 (WebCore::DocumentLoader::tryLoadingSubstituteData): 15 16 Factor substitute resource loading out from tryLoadingRequestFromApplicationCache. 17 18 (WebCore::DocumentLoader::startLoadingMainResource): 19 20 If we have substitute data already (typically from WKWebView.loadData), allow service worker registration 21 but load the main resource using the substitute data. 22 23 (WebCore::DocumentLoader::handleSubstituteDataLoadSoon): Deleted. 24 25 Merge to tryLoadingSubstituteData. 26 27 * loader/DocumentLoader.h: 28 1 29 2018-06-07 Thibault Saunier <tsaunier@igalia.com> 2 30 -
trunk/Source/WebCore/loader/DocumentLoader.cpp
r232419 r232580 479 479 } 480 480 481 void DocumentLoader::handleSubstituteDataLoadSoon()482 {483 if (!m_deferMainResourceDataLoad || frameLoader()->loadsSynchronously())484 handleSubstituteDataLoadNow();485 else486 startDataLoadTimer();487 }488 489 481 #if ENABLE(SERVICE_WORKER) 490 482 void DocumentLoader::matchRegistration(const URL& url, SWClientConnection::RegistrationCallback&& callback) … … 672 664 { 673 665 m_applicationCacheHost->maybeLoadMainResource(m_request, m_substituteData); 674 666 return tryLoadingSubstituteData(); 667 } 668 669 bool DocumentLoader::tryLoadingSubstituteData() 670 { 675 671 if (!m_substituteData.isValid() || !m_frame->page()) 676 672 return false; 677 673 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()); 679 675 m_identifierForLoadWithoutResourceLoader = m_frame->page()->progress().createUniqueIdentifier(); 680 676 frameLoader()->notifier().assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, this, m_request); 681 677 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 683 684 return true; 684 685 } … … 1729 1730 1730 1731 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. 1731 1737 if (!m_serviceWorkerRegistrationData && this->tryLoadingRequestFromApplicationCache()) 1732 1738 return; -
trunk/Source/WebCore/loader/DocumentLoader.h
r232419 r232580 378 378 379 379 bool tryLoadingRequestFromApplicationCache(); 380 bool tryLoadingSubstituteData(); 380 381 bool tryLoadingRedirectRequestFromApplicationCache(const ResourceRequest&); 381 382 #if ENABLE(SERVICE_WORKER) … … 392 393 typedef Timer DocumentLoaderTimer; 393 394 #endif 394 void handleSubstituteDataLoadSoon();395 395 void handleSubstituteDataLoadNow(); 396 396 void startDataLoadTimer(); -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm
r229927 r232580 1371 1371 } 1372 1372 1373 TEST(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 1373 1421 #endif // WK_API_ENABLED
Note: See TracChangeset
for help on using the changeset viewer.