Changeset 160191 in webkit
- Timestamp:
- Dec 5, 2013 1:38:09 PM (10 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r160187 r160191 1 2013-12-05 Anders Carlsson <andersca@apple.com> 2 3 WebKit2 API should use weak ownership for delegate properties rather than assign 4 https://bugs.webkit.org/show_bug.cgi?id=125316 5 <rdar://problem/15560614> 6 7 Reviewed by Dan Bernstein. 8 9 Use WeakObjCPtr for the delegates. 10 11 * UIProcess/API/Cocoa/WKBrowsingContextController.h: 12 * UIProcess/API/Cocoa/WKBrowsingContextController.mm: 13 (didStartProvisionalLoadForFrame): 14 (didReceiveServerRedirectForProvisionalLoadForFrame): 15 (didFailProvisionalLoadWithErrorForFrame): 16 (didCommitLoadForFrame): 17 (didFinishLoadForFrame): 18 (didFailLoadWithErrorForFrame): 19 (didStartProgress): 20 (didChangeProgress): 21 (didFinishProgress): 22 (didChangeBackForwardList): 23 (setUpPagePolicyClient): 24 (-[WKBrowsingContextController loadDelegate]): 25 (-[WKBrowsingContextController setLoadDelegate:]): 26 (-[WKBrowsingContextController policyDelegate]): 27 (-[WKBrowsingContextController setPolicyDelegate:]): 28 (-[WKBrowsingContextController historyDelegate]): 29 (-[WKBrowsingContextController setHistoryDelegate:]): 30 * UIProcess/API/Cocoa/WKBrowsingContextControllerInternal.h: 31 * UIProcess/API/Cocoa/WKConnection.mm: 32 (didReceiveMessage): 33 (didClose): 34 (-[WKConnection delegate]): 35 (-[WKConnection setDelegate:]): 36 * UIProcess/API/Cocoa/WKProcessGroup.mm: 37 (didCreateConnection): 38 (getInjectedBundleInitializationUserData): 39 (didNavigateWithNavigationData): 40 (didPerformClientRedirect): 41 (didPerformServerRedirect): 42 (didUpdateHistoryTitle): 43 (-[WKProcessGroup delegate]): 44 (-[WKProcessGroup setDelegate:]): 45 1 46 2013-12-05 Anders Carlsson <andersca@apple.com> 2 47 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.h
r160129 r160191 45 45 #pragma mark Delegates 46 46 47 @property ( assign) id <WKBrowsingContextLoadDelegate> loadDelegate;48 @property ( assign) id <WKBrowsingContextPolicyDelegate> policyDelegate;49 @property ( assign) id <WKBrowsingContextHistoryDelegate> historyDelegate;47 @property (weak) id <WKBrowsingContextLoadDelegate> loadDelegate; 48 @property (weak) id <WKBrowsingContextPolicyDelegate> policyDelegate; 49 @property (weak) id <WKBrowsingContextHistoryDelegate> historyDelegate; 50 50 51 51 #pragma mark Loading -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm
r160137 r160191 29 29 #if WK_API_ENABLED 30 30 31 #import "WeakObjCPtr.h" 31 32 #import "ObjCObjectGraph.h" 32 33 #import "WKBackForwardListInternal.h" … … 113 114 API::ObjectStorage<WebPageProxy> _page; 114 115 std::unique_ptr<PageLoadStateObserver> _pageLoadStateObserver; 115 } 116 117 @synthesize loadDelegate = _loadDelegate;118 @synthesize policyDelegate = _policyDelegate; 116 117 WeakObjCPtr<id <WKBrowsingContextLoadDelegate>> _loadDelegate; 118 WeakObjCPtr<id <WKBrowsingContextPolicyDelegate>> _policyDelegate; 119 } 119 120 120 121 - (void)dealloc … … 369 370 370 371 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 371 if ([browsingContext.loadDelegate respondsToSelector:@selector(browsingContextControllerDidStartProvisionalLoad:)]) 372 [browsingContext.loadDelegate browsingContextControllerDidStartProvisionalLoad:browsingContext]; 372 auto loadDelegate = browsingContext->_loadDelegate.get(); 373 374 if ([loadDelegate respondsToSelector:@selector(browsingContextControllerDidStartProvisionalLoad:)]) 375 [loadDelegate browsingContextControllerDidStartProvisionalLoad:browsingContext]; 373 376 } 374 377 … … 379 382 380 383 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 381 if ([browsingContext.loadDelegate respondsToSelector:@selector(browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:)]) 382 [browsingContext.loadDelegate browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:browsingContext]; 384 auto loadDelegate = browsingContext->_loadDelegate.get(); 385 386 if ([loadDelegate respondsToSelector:@selector(browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:)]) 387 [loadDelegate browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:browsingContext]; 383 388 } 384 389 … … 389 394 390 395 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 391 if ([browsingContext.loadDelegate respondsToSelector:@selector(browsingContextController:didFailProvisionalLoadWithError:)]) { 396 auto loadDelegate = browsingContext->_loadDelegate.get(); 397 398 if ([loadDelegate respondsToSelector:@selector(browsingContextController:didFailProvisionalLoadWithError:)]) { 392 399 RetainPtr<NSError> nsError = adoptNS(createErrorWithRecoveryAttempter(error, frame, browsingContext)); 393 [ browsingContext.loadDelegate browsingContextController:browsingContext didFailProvisionalLoadWithError:nsError.get()];400 [loadDelegate browsingContextController:browsingContext didFailProvisionalLoadWithError:nsError.get()]; 394 401 } 395 402 } … … 401 408 402 409 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 403 if ([browsingContext.loadDelegate respondsToSelector:@selector(browsingContextControllerDidCommitLoad:)]) 404 [browsingContext.loadDelegate browsingContextControllerDidCommitLoad:browsingContext]; 410 auto loadDelegate = browsingContext->_loadDelegate.get(); 411 412 if ([loadDelegate respondsToSelector:@selector(browsingContextControllerDidCommitLoad:)]) 413 [loadDelegate browsingContextControllerDidCommitLoad:browsingContext]; 405 414 } 406 415 … … 411 420 412 421 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 413 if ([browsingContext.loadDelegate respondsToSelector:@selector(browsingContextControllerDidFinishLoad:)]) 414 [browsingContext.loadDelegate browsingContextControllerDidFinishLoad:browsingContext]; 422 auto loadDelegate = browsingContext->_loadDelegate.get(); 423 424 if ([loadDelegate respondsToSelector:@selector(browsingContextControllerDidFinishLoad:)]) 425 [loadDelegate browsingContextControllerDidFinishLoad:browsingContext]; 415 426 } 416 427 … … 421 432 422 433 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 423 if ([browsingContext.loadDelegate respondsToSelector:@selector(browsingContextController:didFailLoadWithError:)]) { 434 auto loadDelegate = browsingContext->_loadDelegate.get(); 435 436 if ([loadDelegate respondsToSelector:@selector(browsingContextController:didFailLoadWithError:)]) { 424 437 RetainPtr<NSError> nsError = adoptNS(createErrorWithRecoveryAttempter(error, frame, browsingContext)); 425 [ browsingContext.loadDelegate browsingContextController:browsingContext didFailLoadWithError:nsError.get()];438 [loadDelegate browsingContextController:browsingContext didFailLoadWithError:nsError.get()]; 426 439 } 427 440 } … … 430 443 { 431 444 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 432 if ([browsingContext.loadDelegate respondsToSelector:@selector(browsingContextControllerDidStartProgress:)]) 433 [browsingContext.loadDelegate browsingContextControllerDidStartProgress:browsingContext]; 445 auto loadDelegate = browsingContext->_loadDelegate.get(); 446 447 if ([loadDelegate respondsToSelector:@selector(browsingContextControllerDidStartProgress:)]) 448 [loadDelegate browsingContextControllerDidStartProgress:browsingContext]; 434 449 } 435 450 … … 437 452 { 438 453 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 439 if ([browsingContext.loadDelegate respondsToSelector:@selector(browsingContextController:estimatedProgressChangedTo:)]) 440 [browsingContext.loadDelegate browsingContextController:browsingContext estimatedProgressChangedTo:toImpl(page)->estimatedProgress()]; 454 auto loadDelegate = browsingContext->_loadDelegate.get(); 455 456 if ([loadDelegate respondsToSelector:@selector(browsingContextController:estimatedProgressChangedTo:)]) 457 [loadDelegate browsingContextController:browsingContext estimatedProgressChangedTo:toImpl(page)->estimatedProgress()]; 441 458 } 442 459 … … 444 461 { 445 462 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 446 if ([browsingContext.loadDelegate respondsToSelector:@selector(browsingContextControllerDidFinishProgress:)]) 447 [browsingContext.loadDelegate browsingContextControllerDidFinishProgress:browsingContext]; 463 auto loadDelegate = browsingContext->_loadDelegate.get(); 464 465 if ([loadDelegate respondsToSelector:@selector(browsingContextControllerDidFinishProgress:)]) 466 [loadDelegate browsingContextControllerDidFinishProgress:browsingContext]; 448 467 } 449 468 … … 451 470 { 452 471 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 453 if (![browsingContext.loadDelegate respondsToSelector:@selector(browsingContextControllerDidChangeBackForwardList:addedItem:removedItems:)]) 472 auto loadDelegate = browsingContext->_loadDelegate.get(); 473 474 if (![loadDelegate respondsToSelector:@selector(browsingContextControllerDidChangeBackForwardList:addedItem:removedItems:)]) 454 475 return; 455 476 456 477 WKBackForwardListItem *added = addedItem ? wrapper(*toImpl(addedItem)) : nil; 457 478 NSArray *removed = removedItems ? wrapper(*toImpl(removedItems)) : nil; 458 [ browsingContext.loadDelegate browsingContextControllerDidChangeBackForwardList:browsingContext addedItem:added removedItems:removed];479 [loadDelegate browsingContextControllerDidChangeBackForwardList:browsingContext addedItem:added removedItems:removed]; 459 480 } 460 481 … … 515 536 { 516 537 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 517 if ([browsingContext.policyDelegate respondsToSelector:@selector(browsingContextController:decidePolicyForNavigationAction:decisionHandler:)]) { 538 auto policyDelegate = browsingContext->_policyDelegate.get(); 539 540 if ([policyDelegate respondsToSelector:@selector(browsingContextController:decidePolicyForNavigationAction:decisionHandler:)]) { 518 541 NSDictionary *actionDictionary = @{ 519 542 WKActionIsMainFrameKey: @(WKFrameIsMainFrame(frame)), … … 529 552 } 530 553 531 [ browsingContext.policyDelegate browsingContextController:browsingContext decidePolicyForNavigationAction:actionDictionary decisionHandler:makePolicyDecisionBlock(listener)];554 [policyDelegate browsingContextController:browsingContext decidePolicyForNavigationAction:actionDictionary decisionHandler:makePolicyDecisionBlock(listener)]; 532 555 } else 533 556 WKFramePolicyListenerUse(listener); … … 537 560 { 538 561 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 539 if ([browsingContext.policyDelegate respondsToSelector:@selector(browsingContextController:decidePolicyForNewWindowAction:decisionHandler:)]) { 562 auto policyDelegate = browsingContext->_policyDelegate.get(); 563 564 if ([policyDelegate respondsToSelector:@selector(browsingContextController:decidePolicyForNewWindowAction:decisionHandler:)]) { 540 565 NSDictionary *actionDictionary = @{ 541 566 WKActionIsMainFrameKey: @(WKFrameIsMainFrame(frame)), … … 547 572 }; 548 573 549 [ browsingContext.policyDelegate browsingContextController:browsingContext decidePolicyForNewWindowAction:actionDictionary decisionHandler:makePolicyDecisionBlock(listener)];574 [policyDelegate browsingContextController:browsingContext decidePolicyForNewWindowAction:actionDictionary decisionHandler:makePolicyDecisionBlock(listener)]; 550 575 } else 551 576 WKFramePolicyListenerUse(listener); … … 555 580 { 556 581 WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo; 557 if ([browsingContext.policyDelegate respondsToSelector:@selector(browsingContextController:decidePolicyForResponseAction:decisionHandler:)]) { 582 auto policyDelegate = browsingContext->_policyDelegate.get(); 583 584 if ([policyDelegate respondsToSelector:@selector(browsingContextController:decidePolicyForResponseAction:decisionHandler:)]) { 558 585 NSDictionary *actionDictionary = @{ 559 586 WKActionIsMainFrameKey: @(WKFrameIsMainFrame(frame)), … … 563 590 }; 564 591 565 [ browsingContext.policyDelegate browsingContextController:browsingContext decidePolicyForResponseAction:actionDictionary decisionHandler:makePolicyDecisionBlock(listener)];592 [policyDelegate browsingContextController:browsingContext decidePolicyForResponseAction:actionDictionary decisionHandler:makePolicyDecisionBlock(listener)]; 566 593 } else 567 594 WKFramePolicyListenerUse(listener); … … 573 600 - (id <WKBrowsingContextLoadDelegate>)loadDelegate 574 601 { 575 return _loadDelegate ;602 return _loadDelegate.getAutoreleased(); 576 603 } 577 604 … … 579 606 { 580 607 _loadDelegate = loadDelegate; 581 if (_loadDelegate) 608 609 if (loadDelegate) 582 610 setUpPageLoaderClient(self, *_page); 583 611 else … … 587 615 - (id <WKBrowsingContextPolicyDelegate>)policyDelegate 588 616 { 589 return _policyDelegate ;617 return _policyDelegate.getAutoreleased(); 590 618 } 591 619 … … 593 621 { 594 622 _policyDelegate = policyDelegate; 595 if (_policyDelegate) 623 624 if (policyDelegate) 596 625 setUpPagePolicyClient(self, *_page); 597 626 else 598 627 _page->initializePolicyClient(nullptr); 628 } 629 630 - (id <WKBrowsingContextHistoryDelegate>)historyDelegate 631 { 632 return _historyDelegate.getAutoreleased(); 633 } 634 635 - (void)setHistoryDelegate:(id <WKBrowsingContextHistoryDelegate>)historyDelegate 636 { 637 _historyDelegate = historyDelegate; 599 638 } 600 639 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextControllerInternal.h
r159877 r160191 29 29 30 30 #import "WKObject.h" 31 #import "WeakObjCPtr.h" 31 32 #import "WebPageProxy.h" 32 33 … … 41 42 } 42 43 43 @interface WKBrowsingContextController () <WKObject> 44 @interface WKBrowsingContextController () <WKObject> { 45 @package 46 WebKit::WeakObjCPtr<id <WKBrowsingContextHistoryDelegate>> _historyDelegate; 47 } 44 48 45 49 - (void)_finishInitialization; -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKConnection.mm
r160148 r160191 34 34 #import "WKSharedAPICast.h" 35 35 #import "WKStringCF.h" 36 #import "WeakObjCPtr.h" 36 37 #import <wtf/RetainPtr.h> 37 38 #import <wtf/text/WTFString.h> … … 42 43 API::ObjectStorage<WebConnection> _connection; 43 44 RetainPtr<WKRemoteObjectRegistry> _remoteObjectRegistry; 45 46 WeakObjCPtr<id <WKConnectionDelegate>> _delegate; 44 47 } 45 46 @synthesize delegate = _delegate;47 48 48 49 - (void)dealloc … … 59 60 return; 60 61 61 if ([connection.delegate respondsToSelector:@selector(connection:didReceiveMessageWithName:body:)]) { 62 auto delegate = connection->_delegate.get(); 63 if ([delegate respondsToSelector:@selector(connection:didReceiveMessageWithName:body:)]) { 62 64 RetainPtr<CFStringRef> nsMessageName = adoptCF(WKStringCopyCFString(kCFAllocatorDefault, messageName)); 63 65 RetainPtr<id> nsMessageBody = ((ObjCObjectGraph*)messageBody)->rootObject(); 64 [ connection.delegate connection:connection didReceiveMessageWithName:(NSString *)nsMessageName.get() body:nsMessageBody.get()];66 [delegate connection:connection didReceiveMessageWithName:(NSString *)nsMessageName.get() body:nsMessageBody.get()]; 65 67 } 66 68 } … … 69 71 { 70 72 WKConnection *connection = (WKConnection *)clientInfo; 71 if ([connection.delegate respondsToSelector:@selector(connectionDidClose:)]) 72 [connection.delegate connectionDidClose:connection]; 73 auto delegate = connection->_delegate.get(); 74 75 if ([delegate respondsToSelector:@selector(connectionDidClose:)]) 76 [delegate connectionDidClose:connection]; 73 77 } 74 78 … … 88 92 - (id <WKConnectionDelegate>)delegate 89 93 { 90 return _delegate ;94 return _delegate.getAutoreleased(); 91 95 } 92 96 … … 94 98 { 95 99 _delegate = delegate; 96 if ( _delegate)100 if (delegate) 97 101 setUpClient(self, *_connection); 98 102 else -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessGroup.mm
r160148 r160191 41 41 #import "WKRetainPtr.h" 42 42 #import "WKStringCF.h" 43 #import "WeakObjCPtr.h" 43 44 #import "WebFrameProxy.h" 44 45 #import <wtf/RetainPtr.h> … … 55 56 API::ObjectStorage<WebContext> _context; 56 57 58 WeakObjCPtr<id <WKProcessGroupDelegate>> _delegate; 59 57 60 #if PLATFORM(IOS) 58 61 RetainPtr<WKGeolocationProviderIOS> _geolocationProvider; … … 70 73 { 71 74 WKProcessGroup *processGroup = (WKProcessGroup *)clientInfo; 72 if ([processGroup.delegate respondsToSelector:@selector(processGroup:didCreateConnectionToWebProcessPlugIn:)]) 73 [processGroup.delegate processGroup:processGroup didCreateConnectionToWebProcessPlugIn:wrapper(*toImpl(connectionRef))]; 75 auto delegate = processGroup->_delegate.get(); 76 77 if ([delegate respondsToSelector:@selector(processGroup:didCreateConnectionToWebProcessPlugIn:)]) 78 [delegate processGroup:processGroup didCreateConnectionToWebProcessPlugIn:wrapper(*toImpl(connectionRef))]; 74 79 } 75 80 … … 89 94 { 90 95 WKProcessGroup *processGroup = (WKProcessGroup *)clientInfo; 91 if ([processGroup.delegate respondsToSelector:@selector(processGroupWillCreateConnectionToWebProcessPlugIn:)]) { 92 RetainPtr<id> initializationUserData = [processGroup.delegate processGroupWillCreateConnectionToWebProcessPlugIn:processGroup]; 96 auto delegate = processGroup->_delegate.get(); 97 98 if ([delegate respondsToSelector:@selector(processGroupWillCreateConnectionToWebProcessPlugIn:)]) { 99 RetainPtr<id> initializationUserData = [delegate processGroupWillCreateConnectionToWebProcessPlugIn:processGroup]; 93 100 RefPtr<WebKit::ObjCObjectGraph> wkMessageBody = WebKit::ObjCObjectGraph::create(initializationUserData.get()); 94 101 return (WKTypeRef)wkMessageBody.release().leakRef(); … … 116 123 117 124 WKBrowsingContextController *controller = wrapper(*toImpl(pageRef)); 118 if ([controller.historyDelegate respondsToSelector:@selector(browsingContextController:didNavigateWithNavigationData:)]) 119 [controller.historyDelegate browsingContextController:controller didNavigateWithNavigationData:wrapper(*toImpl(navigationDataRef))]; 125 auto historyDelegate = controller->_historyDelegate.get(); 126 127 if ([historyDelegate respondsToSelector:@selector(browsingContextController:didNavigateWithNavigationData:)]) 128 [historyDelegate browsingContextController:controller didNavigateWithNavigationData:wrapper(*toImpl(navigationDataRef))]; 120 129 } 121 130 … … 126 135 127 136 WKBrowsingContextController *controller = wrapper(*toImpl(pageRef)); 128 if ([controller.historyDelegate respondsToSelector:@selector(browsingContextController:didPerformClientRedirectFromURL:toURL:)]) 129 [controller.historyDelegate browsingContextController:controller didPerformClientRedirectFromURL:wrapper(*toImpl(sourceURLRef)) toURL:wrapper(*toImpl(destinationURLRef))]; 137 auto historyDelegate = controller->_historyDelegate.get(); 138 139 if ([historyDelegate respondsToSelector:@selector(browsingContextController:didPerformClientRedirectFromURL:toURL:)]) 140 [historyDelegate browsingContextController:controller didPerformClientRedirectFromURL:wrapper(*toImpl(sourceURLRef)) toURL:wrapper(*toImpl(destinationURLRef))]; 130 141 } 131 142 … … 136 147 137 148 WKBrowsingContextController *controller = wrapper(*toImpl(pageRef)); 138 if ([controller.historyDelegate respondsToSelector:@selector(browsingContextController:didPerformServerRedirectFromURL:toURL:)]) 139 [controller.historyDelegate browsingContextController:controller didPerformServerRedirectFromURL:wrapper(*toImpl(sourceURLRef)) toURL:wrapper(*toImpl(destinationURLRef))]; 149 auto historyDelegate = controller->_historyDelegate.get(); 150 151 if ([historyDelegate respondsToSelector:@selector(browsingContextController:didPerformServerRedirectFromURL:toURL:)]) 152 [historyDelegate browsingContextController:controller didPerformServerRedirectFromURL:wrapper(*toImpl(sourceURLRef)) toURL:wrapper(*toImpl(destinationURLRef))]; 140 153 } 141 154 … … 146 159 147 160 WKBrowsingContextController *controller = wrapper(*toImpl(pageRef)); 148 if ([controller.historyDelegate respondsToSelector:@selector(browsingContextController:didUpdateHistoryTitle:forURL:)]) 149 [controller.historyDelegate browsingContextController:controller didUpdateHistoryTitle:wrapper(*toImpl(titleRef)) forURL:wrapper(*toImpl(urlRef))]; 161 auto historyDelegate = controller->_historyDelegate.get(); 162 163 if ([historyDelegate respondsToSelector:@selector(browsingContextController:didUpdateHistoryTitle:forURL:)]) 164 [historyDelegate browsingContextController:controller didUpdateHistoryTitle:wrapper(*toImpl(titleRef)) forURL:wrapper(*toImpl(urlRef))]; 150 165 } 151 166 … … 190 205 } 191 206 207 - (id <WKProcessGroupDelegate>)delegate 208 { 209 return _delegate.getAutoreleased(); 210 } 211 212 - (void)setDelegate:(id <WKProcessGroupDelegate>)delegate 213 { 214 _delegate = delegate; 215 } 216 192 217 #pragma mark WKObject protocol implementation 193 218
Note: See TracChangeset
for help on using the changeset viewer.