Changeset 244819 in webkit
- Timestamp:
- Apr 30, 2019, 7:45:10 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/UIProcess/WebPageProxy.cpp (modified) (4 diffs)
-
Source/WebKit/UIProcess/WebPageProxy.h (modified) (1 diff)
-
Source/WebKit/UIProcess/WebURLSchemeHandler.cpp (modified) (2 diffs)
-
Source/WebKit/UIProcess/WebURLSchemeHandler.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/WebURLSchemeTask.h (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r244818 r244819 1 2019-04-30 Chris Dumez <cdumez@apple.com> 2 3 Regression(PSON) URL scheme handlers can no longer respond asynchronously 4 https://bugs.webkit.org/show_bug.cgi?id=197426 5 <rdar://problem/50256169> 6 7 Reviewed by Brady Eidson. 8 9 The issue was that when committing the provisional process, we would call WebPageProxy::processDidTerminate() 10 which would call WebPageProxy::stopAllURLSchemeTasks(). This would terminate all URL scheme tasks associated 11 with the page, including the one associated with the provisisional page / process. 12 13 To address the issue, pass m_process to stopAllURLSchemeTasks() in processDidTerminate() and only stop the 14 tasks associated with the m_process (which is the process we're about to swap away from). 15 16 * UIProcess/WebPageProxy.cpp: 17 (WebKit::WebPageProxy::processDidTerminate): 18 (WebKit::WebPageProxy::stopAllURLSchemeTasks): 19 * UIProcess/WebPageProxy.h: 20 * UIProcess/WebURLSchemeHandler.cpp: 21 (WebKit::WebURLSchemeHandler::processForTaskIdentifier): 22 (WebKit::WebURLSchemeHandler::stopAllTasksForPage): 23 * UIProcess/WebURLSchemeHandler.h: 24 * UIProcess/WebURLSchemeTask.h: 25 (WebKit::WebURLSchemeTask::process const): 26 1 27 2019-04-30 John Wilander <wilander@apple.com> 2 28 -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r244812 r244819 6726 6726 6727 6727 resetStateAfterProcessExited(reason); 6728 stopAllURLSchemeTasks(m_process.ptr()); 6728 6729 6729 6730 // For bringup of process swapping, NavigationSwap termination will not go out to clients. … … 6741 6742 automationSession->terminate(); 6742 6743 } 6743 6744 stopAllURLSchemeTasks();6745 6744 } 6746 6745 … … 6802 6801 } 6803 6802 6804 void WebPageProxy::stopAllURLSchemeTasks( )6803 void WebPageProxy::stopAllURLSchemeTasks(WebProcessProxy* process) 6805 6804 { 6806 6805 HashSet<WebURLSchemeHandler*> handlers; … … 6809 6808 6810 6809 for (auto* handler : handlers) 6811 handler->stopAllTasksForPage(*this );6810 handler->stopAllTasksForPage(*this, process); 6812 6811 } 6813 6812 -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r244812 r244819 2002 2002 void viewIsBecomingVisible(); 2003 2003 2004 void stopAllURLSchemeTasks( );2004 void stopAllURLSchemeTasks(WebProcessProxy* = nullptr); 2005 2005 2006 2006 void clearInspectorTargets(); -
trunk/Source/WebKit/UIProcess/WebURLSchemeHandler.cpp
r244812 r244819 61 61 } 62 62 63 void WebURLSchemeHandler::stopAllTasksForPage(WebPageProxy& page) 63 WebProcessProxy* WebURLSchemeHandler::processForTaskIdentifier(uint64_t taskIdentifier) const 64 { 65 auto iterator = m_tasks.find(taskIdentifier); 66 if (iterator == m_tasks.end()) 67 return nullptr; 68 return iterator->value->process(); 69 } 70 71 void WebURLSchemeHandler::stopAllTasksForPage(WebPageProxy& page, WebProcessProxy* process) 64 72 { 65 73 auto iterator = m_tasksByPageIdentifier.find(page.pageID()); … … 68 76 69 77 auto& tasksByPage = iterator->value; 70 while (!tasksByPage.isEmpty()) 71 stopTask(page, *tasksByPage.begin()); 78 Vector<uint64_t> taskIdentifiersToStop; 79 taskIdentifiersToStop.reserveInitialCapacity(tasksByPage.size()); 80 for (auto taskIdentifier : tasksByPage) { 81 if (!process || processForTaskIdentifier(taskIdentifier) == process) 82 taskIdentifiersToStop.uncheckedAppend(taskIdentifier); 83 } 72 84 73 ASSERT(m_tasksByPageIdentifier.find(page.pageID()) == m_tasksByPageIdentifier.end()); 85 for (auto& taskIdentifier : taskIdentifiersToStop) 86 stopTask(page, taskIdentifier); 87 74 88 } 75 89 -
trunk/Source/WebKit/UIProcess/WebURLSchemeHandler.h
r244812 r244819 56 56 void startTask(WebPageProxy&, WebProcessProxy&, uint64_t taskIdentifier, WebCore::ResourceRequest&&, SyncLoadCompletionHandler&&); 57 57 void stopTask(WebPageProxy&, uint64_t taskIdentifier); 58 void stopAllTasksForPage(WebPageProxy& );58 void stopAllTasksForPage(WebPageProxy&, WebProcessProxy*); 59 59 void taskCompleted(WebURLSchemeTask&); 60 60 … … 68 68 69 69 void removeTaskFromPageMap(uint64_t pageID, uint64_t taskID); 70 WebProcessProxy* processForTaskIdentifier(uint64_t) const; 70 71 71 72 uint64_t m_identifier; -
trunk/Source/WebKit/UIProcess/WebURLSchemeTask.h
r244812 r244819 59 59 uint64_t identifier() const { return m_identifier; } 60 60 uint64_t pageID() const { return m_pageIdentifier; } 61 WebProcessProxy* process() const { return m_process.get(); } 61 62 62 63 const WebCore::ResourceRequest& request() const { return m_request; } -
trunk/Tools/ChangeLog
r244812 r244819 1 2019-04-30 Chris Dumez <cdumez@apple.com> 2 3 Regression(PSON) URL scheme handlers can no longer respond asynchronously 4 https://bugs.webkit.org/show_bug.cgi?id=197426 5 <rdar://problem/50256169> 6 7 Reviewed by Brady Eidson. 8 9 Add API test coverage. 10 11 * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm: 12 (-[PSONScheme setShouldRespondAsynchronously:]): 13 (-[PSONScheme webView:startURLSchemeTask:]): 14 (-[PSONScheme webView:stopURLSchemeTask:]): 15 1 16 2019-04-30 Chris Dumez <cdumez@apple.com> 2 17 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm
r244812 r244819 49 49 #import <WebKit/_WKWebsiteDataStoreConfiguration.h> 50 50 #import <WebKit/_WKWebsitePolicies.h> 51 #import <wtf/BlockPtr.h> 51 52 #import <wtf/Deque.h> 52 53 #import <wtf/HashMap.h> … … 239 240 HashMap<String, String> _redirects; 240 241 HashMap<String, RetainPtr<NSData>> _dataMappings; 242 HashSet<id <WKURLSchemeTask>> _runningTasks; 243 bool _shouldRespondAsynchronously; 241 244 } 242 245 - (instancetype)initWithBytes:(const char*)bytes; … … 264 267 } 265 268 269 - (void)setShouldRespondAsynchronously:(BOOL)value 270 { 271 _shouldRespondAsynchronously = value; 272 } 273 266 274 - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task 267 275 { 276 if ([(id<WKURLSchemeTaskPrivate>)task _requestOnlyIfCached]) { 277 [task didFailWithError:[NSError errorWithDomain:@"TestWebKitAPI" code:1 userInfo:nil]]; 278 return; 279 } 280 281 _runningTasks.add(task); 282 283 auto doAsynchronouslyIfNecessary = [self, strongSelf = retainPtr(self), task = retainPtr(task)](Function<void(id <WKURLSchemeTask>)>&& f, double delay) { 284 if (!_shouldRespondAsynchronously) 285 return f(task.get()); 286 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_main_queue(), makeBlockPtr([self, strongSelf, task, f = WTFMove(f)] { 287 if (_runningTasks.contains(task.get())) 288 f(task.get()); 289 }).get()); 290 }; 291 268 292 NSURL *finalURL = task.request.URL; 269 293 auto target = _redirects.get(task.request.URL.absoluteString); … … 277 301 } 278 302 279 if ([(id<WKURLSchemeTaskPrivate>)task _requestOnlyIfCached]) { 280 [task didFailWithError:[NSError errorWithDomain:@"TestWebKitAPI" code:1 userInfo:nil]]; 281 return; 282 } 283 284 RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:finalURL MIMEType:@"text/html" expectedContentLength:1 textEncodingName:nil]); 285 [task didReceiveResponse:response.get()]; 286 287 if (auto data = _dataMappings.get([finalURL absoluteString])) 288 [task didReceiveData:data.get()]; 289 else if (_bytes) { 290 RetainPtr<NSData> data = adoptNS([[NSData alloc] initWithBytesNoCopy:(void *)_bytes length:strlen(_bytes) freeWhenDone:NO]); 291 [task didReceiveData:data.get()]; 292 } else 293 [task didReceiveData:[@"Hello" dataUsingEncoding:NSUTF8StringEncoding]]; 294 295 [task didFinish]; 303 doAsynchronouslyIfNecessary([finalURL = retainPtr(finalURL)](id <WKURLSchemeTask> task) { 304 RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:finalURL.get() MIMEType:@"text/html" expectedContentLength:1 textEncodingName:nil]); 305 [task didReceiveResponse:response.get()]; 306 }, 0.1); 307 308 doAsynchronouslyIfNecessary([self, finalURL = retainPtr(finalURL)](id <WKURLSchemeTask> task) { 309 if (auto data = _dataMappings.get([finalURL absoluteString])) 310 [task didReceiveData:data.get()]; 311 else if (_bytes) { 312 RetainPtr<NSData> data = adoptNS([[NSData alloc] initWithBytesNoCopy:(void *)_bytes length:strlen(_bytes) freeWhenDone:NO]); 313 [task didReceiveData:data.get()]; 314 } else 315 [task didReceiveData:[@"Hello" dataUsingEncoding:NSUTF8StringEncoding]]; 316 }, 0.2); 317 318 doAsynchronouslyIfNecessary([self](id <WKURLSchemeTask> task) { 319 [task didFinish]; 320 _runningTasks.remove(task); 321 }, 0.3); 296 322 } 297 323 298 324 - (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)task 299 325 { 326 _runningTasks.remove(task); 300 327 } 301 328 … … 472 499 } 473 500 474 TEST(ProcessSwap, Basic) 475 { 476 auto processPoolConfiguration = psonProcessPoolConfiguration(); 477 auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]); 478 479 auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]); 480 [webViewConfiguration setProcessPool:processPool.get()]; 481 auto handler = adoptNS([[PSONScheme alloc] init]); 501 enum class SchemeHandlerShouldBeAsync { No, Yes }; 502 static void runBasicTest(SchemeHandlerShouldBeAsync schemeHandlerShouldBeAsync) 503 { 504 auto processPoolConfiguration = psonProcessPoolConfiguration(); 505 auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]); 506 507 auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]); 508 [webViewConfiguration setProcessPool:processPool.get()]; 509 auto handler = adoptNS([[PSONScheme alloc] init]); 510 [handler setShouldRespondAsynchronously:(schemeHandlerShouldBeAsync == SchemeHandlerShouldBeAsync::Yes)]; 482 511 [webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"]; 483 512 … … 515 544 // 3 loads, 3 decidePolicy calls (e.g. the load that did perform a process swap should not have generated an additional decidePolicy call) 516 545 EXPECT_EQ(numberOfDecidePolicyCalls, 3); 546 } 547 548 TEST(ProcessSwap, Basic) 549 { 550 runBasicTest(SchemeHandlerShouldBeAsync::No); 551 } 552 553 TEST(ProcessSwap, BasicWithAsyncSchemeHandler) 554 { 555 runBasicTest(SchemeHandlerShouldBeAsync::Yes); 517 556 } 518 557
Note:
See TracChangeset
for help on using the changeset viewer.