Commit bffb5fa8 authored by Yi Su's avatar Yi Su Committed by Commit Bot

Clean up "isBeingDestroyed" from CRWWebController

Many classes in //ios/web use delegate method to get "IsBeingDestroyed"
state from CRWWebController. It can be either simplified by |close|
method or just removed because unnecessary.

Bug: 956511
Change-Id: I0850bb55c2de57087593a3685700c134761c75a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1688950
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#675986}
parent c2d3f186
...@@ -124,9 +124,7 @@ using web::wk_navigation_util::IsPlaceholderUrl; ...@@ -124,9 +124,7 @@ using web::wk_navigation_util::IsPlaceholderUrl;
// Called when WKWebView estimatedProgress has been changed. // Called when WKWebView estimatedProgress has been changed.
- (void)webViewEstimatedProgressDidChange { - (void)webViewEstimatedProgressDidChange {
if (![self.delegate webViewIsBeingDestroyed:self]) { self.webStateImpl->SendChangeLoadProgress(self.webView.estimatedProgress);
self.webStateImpl->SendChangeLoadProgress(self.webView.estimatedProgress);
}
} }
// Called when WKWebView loading state has been changed. // Called when WKWebView loading state has been changed.
......
...@@ -16,10 +16,6 @@ class WebStateImpl; ...@@ -16,10 +16,6 @@ class WebStateImpl;
// Delegate for the NavigationObserver. // Delegate for the NavigationObserver.
@protocol CRWWebViewNavigationObserverDelegate @protocol CRWWebViewNavigationObserverDelegate
// Whether the the web view is being closed.
- (BOOL)webViewIsBeingDestroyed:
(CRWWebViewNavigationObserver*)navigationObserver;
// The WebState. // The WebState.
- (web::WebStateImpl*)webStateImplForNavigationObserver: - (web::WebStateImpl*)webStateImplForNavigationObserver:
(CRWWebViewNavigationObserver*)navigationObserver; (CRWWebViewNavigationObserver*)navigationObserver;
......
...@@ -55,10 +55,6 @@ class WKBackForwardListItemHolder; ...@@ -55,10 +55,6 @@ class WKBackForwardListItemHolder;
legacyNativeContentControllerForNavigationHandler: legacyNativeContentControllerForNavigationHandler:
(CRWWKNavigationHandler*)navigationHandler; (CRWWKNavigationHandler*)navigationHandler;
// Returns YES if WKWebView was deallocated or is being deallocated.
- (BOOL)navigationHandlerWebViewBeingDestroyed:
(CRWWKNavigationHandler*)navigationHandler;
// Returns the actual URL of the document object (i.e., the last committed URL // Returns the actual URL of the document object (i.e., the last committed URL
// of the main frame). // of the main frame).
- (GURL)navigationHandlerDocumentURL:(CRWWKNavigationHandler*)navigationHandler; - (GURL)navigationHandlerDocumentURL:(CRWWKNavigationHandler*)navigationHandler;
...@@ -164,6 +160,9 @@ class WKBackForwardListItemHolder; ...@@ -164,6 +160,9 @@ class WKBackForwardListItemHolder;
// Returns the referrer for the current page. // Returns the referrer for the current page.
@property(nonatomic, readonly, assign) web::Referrer currentReferrer; @property(nonatomic, readonly, assign) web::Referrer currentReferrer;
// Instructs this handler to close.
- (void)close;
// Instructs this handler to stop loading. // Instructs this handler to stop loading.
- (void)stopLoading; - (void)stopLoading;
......
...@@ -120,6 +120,9 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation( ...@@ -120,6 +120,9 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation(
@property(nonatomic, readonly, weak) @property(nonatomic, readonly, weak)
CRWLegacyNativeContentController* legacyNativeContentController; CRWLegacyNativeContentController* legacyNativeContentController;
// Set to YES when [self close] is called.
@property(nonatomic, assign) BOOL beingDestroyed;
@end @end
@implementation CRWWKNavigationHandler @implementation CRWWKNavigationHandler
...@@ -149,7 +152,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation( ...@@ -149,7 +152,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation(
[self didReceiveWKNavigationDelegateCallback]; [self didReceiveWKNavigationDelegateCallback];
self.webProcessCrashed = NO; self.webProcessCrashed = NO;
if ([self.delegate navigationHandlerWebViewBeingDestroyed:self]) { if (self.beingDestroyed) {
decisionHandler(WKNavigationActionPolicyCancel); decisionHandler(WKNavigationActionPolicyCancel);
return; return;
} }
...@@ -243,7 +246,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation( ...@@ -243,7 +246,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation(
(action.navigationType == WKNavigationTypeFormResubmitted)) { (action.navigationType == WKNavigationTypeFormResubmitted)) {
self.webStateImpl->ShowRepostFormWarningDialog( self.webStateImpl->ShowRepostFormWarningDialog(
base::BindOnce(^(bool shouldContinue) { base::BindOnce(^(bool shouldContinue) {
if ([self.delegate navigationHandlerWebViewBeingDestroyed:self]) { if (self.beingDestroyed) {
decisionHandler(WKNavigationActionPolicyCancel); decisionHandler(WKNavigationActionPolicyCancel);
} else if (shouldContinue) { } else if (shouldContinue) {
decisionHandler(WKNavigationActionPolicyAllow); decisionHandler(WKNavigationActionPolicyAllow);
...@@ -340,7 +343,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation( ...@@ -340,7 +343,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation(
allowLoad = allowLoad =
self.webStateImpl->ShouldAllowRequest(action.request, requestInfo); self.webStateImpl->ShouldAllowRequest(action.request, requestInfo);
// The WebState may have been closed in the ShouldAllowRequest callback. // The WebState may have been closed in the ShouldAllowRequest callback.
if ([self.delegate navigationHandlerWebViewBeingDestroyed:self]) { if (self.beingDestroyed) {
decisionHandler(WKNavigationActionPolicyCancel); decisionHandler(WKNavigationActionPolicyCancel);
return; return;
} }
...@@ -379,7 +382,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation( ...@@ -379,7 +382,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation(
context->ReleaseItem(); context->ReleaseItem();
} }
if (![self.delegate navigationHandlerWebViewBeingDestroyed:self] && if (!self.beingDestroyed &&
[self shouldClosePageOnNativeApplicationLoad]) { [self shouldClosePageOnNativeApplicationLoad]) {
// Loading was started for user initiated navigations and should be // Loading was started for user initiated navigations and should be
// stopped because no other WKWebView callbacks are called. // stopped because no other WKWebView callbacks are called.
...@@ -392,7 +395,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation( ...@@ -392,7 +395,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation(
} }
} }
if (![self.delegate navigationHandlerWebViewBeingDestroyed:self]) { if (!self.beingDestroyed) {
// Loading was started for user initiated navigations and should be // Loading was started for user initiated navigations and should be
// stopped because no other WKWebView callbacks are called. // stopped because no other WKWebView callbacks are called.
// TODO(crbug.com/767092): Loading should not start until webView.loading // TODO(crbug.com/767092): Loading should not start until webView.loading
...@@ -1214,7 +1217,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation( ...@@ -1214,7 +1217,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation(
// this point it's too late for a SafeBrowsing warning to be displayed for the // this point it's too late for a SafeBrowsing warning to be displayed for the
// navigation for which the timer was started. // navigation for which the timer was started.
- (void)didReceiveWKNavigationDelegateCallback { - (void)didReceiveWKNavigationDelegateCallback {
if ([self.delegate navigationHandlerWebViewBeingDestroyed:self]) { if (self.beingDestroyed) {
UMA_HISTOGRAM_BOOLEAN("Renderer.WKWebViewCallbackAfterDestroy", true); UMA_HISTOGRAM_BOOLEAN("Renderer.WKWebViewCallbackAfterDestroy", true);
} }
_safeBrowsingWarningDetectionTimer.Stop(); _safeBrowsingWarningDetectionTimer.Stop();
...@@ -2033,6 +2036,10 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation( ...@@ -2033,6 +2036,10 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation(
#pragma mark - Public methods #pragma mark - Public methods
- (void)close {
self.beingDestroyed = YES;
}
- (void)stopLoading { - (void)stopLoading {
_stoppedWKNavigation = [self.navigationStates lastAddedNavigation]; _stoppedWKNavigation = [self.navigationStates lastAddedNavigation];
self.pendingNavigationInfo.cancelled = YES; self.pendingNavigationInfo.cancelled = YES;
...@@ -2045,7 +2052,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation( ...@@ -2045,7 +2052,7 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation(
// TODO(crbug.com/821995): Check if this function should be removed. // TODO(crbug.com/821995): Check if this function should be removed.
if (self.navigationState != web::WKNavigationState::FINISHED) { if (self.navigationState != web::WKNavigationState::FINISHED) {
self.navigationState = web::WKNavigationState::FINISHED; self.navigationState = web::WKNavigationState::FINISHED;
if (![self.delegate navigationHandlerWebViewBeingDestroyed:self]) { if (!self.beingDestroyed) {
self.webStateImpl->SetIsLoading(false); self.webStateImpl->SetIsLoading(false);
} }
} }
......
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
@property(nonatomic, assign, readonly) @property(nonatomic, assign, readonly)
web::NavigationManagerImpl* navigationManagerImpl; web::NavigationManagerImpl* navigationManagerImpl;
@property(nonatomic, assign, readonly) web::NavigationItemImpl* currentNavItem; @property(nonatomic, assign, readonly) web::NavigationItemImpl* currentNavItem;
// Set to YES when [self close] is called.
@property(nonatomic, assign) BOOL beingDestroyed;
@end @end
@implementation CRWLegacyNativeContentController @implementation CRWLegacyNativeContentController
...@@ -194,6 +197,7 @@ ...@@ -194,6 +197,7 @@
} }
- (void)close { - (void)close {
self.beingDestroyed = YES;
self.nativeProvider = nil; self.nativeProvider = nil;
if ([self.nativeController respondsToSelector:@selector(close)]) if ([self.nativeController respondsToSelector:@selector(close)])
[self.nativeController close]; [self.nativeController close];
...@@ -234,7 +238,7 @@ ...@@ -234,7 +238,7 @@
- (void)nativeContent:(id)content - (void)nativeContent:(id)content
handleContextMenu:(const web::ContextMenuParams&)params { handleContextMenu:(const web::ContextMenuParams&)params {
if ([self.delegate legacyNativeContentControllerIsBeingDestroyed:self]) { if (self.beingDestroyed) {
return; return;
} }
self.webStateImpl->HandleContextMenu(params); self.webStateImpl->HandleContextMenu(params);
......
...@@ -22,10 +22,6 @@ class GURL; ...@@ -22,10 +22,6 @@ class GURL;
- (BOOL)legacyNativeContentControllerWebUsageEnabled: - (BOOL)legacyNativeContentControllerWebUsageEnabled:
(CRWLegacyNativeContentController*)contentController; (CRWLegacyNativeContentController*)contentController;
// Whether the delegate is being destroyed.
- (BOOL)legacyNativeContentControllerIsBeingDestroyed:
(CRWLegacyNativeContentController*)contentController;
// Asks the delegate to remove the web view. // Asks the delegate to remove the web view.
- (void)legacyNativeContentControllerRemoveWebView: - (void)legacyNativeContentControllerRemoveWebView:
(CRWLegacyNativeContentController*)contentController; (CRWLegacyNativeContentController*)contentController;
......
...@@ -598,8 +598,10 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -598,8 +598,10 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
self.webStateImpl->CancelDialogs(); self.webStateImpl->CancelDialogs();
_SSLStatusUpdater = nil; _SSLStatusUpdater = nil;
[self.navigationHandler close];
[self.UIHandler close]; [self.UIHandler close];
[self.JSNavigationHandler close]; [self.JSNavigationHandler close];
[self.requestController close];
_faviconManager.reset(); _faviconManager.reset();
_jsWindowErrorManager.reset(); _jsWindowErrorManager.reset();
self.swipeRecognizerProvider = nil; self.swipeRecognizerProvider = nil;
...@@ -1255,11 +1257,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -1255,11 +1257,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
return [self webUsageEnabled]; return [self webUsageEnabled];
} }
- (BOOL)legacyNativeContentControllerIsBeingDestroyed:
(CRWLegacyNativeContentController*)contentController {
return _isBeingDestroyed;
}
- (void)legacyNativeContentControllerRemoveWebView: - (void)legacyNativeContentControllerRemoveWebView:
(CRWLegacyNativeContentController*)contentController { (CRWLegacyNativeContentController*)contentController {
[self removeWebView]; [self removeWebView];
...@@ -1986,11 +1983,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -1986,11 +1983,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
#pragma mark - CRWWebViewNavigationObserverDelegate #pragma mark - CRWWebViewNavigationObserverDelegate
- (BOOL)webViewIsBeingDestroyed:
(CRWWebViewNavigationObserver*)navigationObserver {
return _isBeingDestroyed;
}
- (web::WebStateImpl*)webStateImplForNavigationObserver: - (web::WebStateImpl*)webStateImplForNavigationObserver:
(CRWWebViewNavigationObserver*)navigationObserver { (CRWWebViewNavigationObserver*)navigationObserver {
return self.webStateImpl; return self.webStateImpl;
...@@ -2149,11 +2141,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -2149,11 +2141,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
#pragma mark - CRWWKNavigationHandlerDelegate #pragma mark - CRWWKNavigationHandlerDelegate
- (BOOL)navigationHandlerWebViewBeingDestroyed:
(CRWWKNavigationHandler*)navigationHandler {
return _isBeingDestroyed;
}
- (web::WebStateImpl*)webStateImplForNavigationHandler: - (web::WebStateImpl*)webStateImplForNavigationHandler:
(CRWWKNavigationHandler*)navigationHandler { (CRWWKNavigationHandler*)navigationHandler {
return self.webStateImpl; return self.webStateImpl;
...@@ -2276,11 +2263,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -2276,11 +2263,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
#pragma mark - CRWWebRequestControllerDelegate #pragma mark - CRWWebRequestControllerDelegate
- (BOOL)webRequestControllerIsBeingDestroyed:
(CRWWebRequestController*)requestController {
return _isBeingDestroyed;
}
- (void)webRequestControllerStopLoading: - (void)webRequestControllerStopLoading:
(CRWWebRequestController*)requestController { (CRWWebRequestController*)requestController {
[self stopLoading]; [self stopLoading];
......
...@@ -28,10 +28,6 @@ class UserInteractionState; ...@@ -28,10 +28,6 @@ class UserInteractionState;
- (void)webRequestControllerStopLoading: - (void)webRequestControllerStopLoading:
(CRWWebRequestController*)requestController; (CRWWebRequestController*)requestController;
// Whether the delegate is being destroyed.
- (BOOL)webRequestControllerIsBeingDestroyed:
(CRWWebRequestController*)requestController;
// Asks proxy to disconnect scroll proxy if needed. // Asks proxy to disconnect scroll proxy if needed.
- (void)webRequestControllerDisconnectScrollViewProxy: - (void)webRequestControllerDisconnectScrollViewProxy:
(CRWWebRequestController*)requestController; (CRWWebRequestController*)requestController;
...@@ -75,6 +71,11 @@ class UserInteractionState; ...@@ -75,6 +71,11 @@ class UserInteractionState;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
// Instructs the receiver to close. This should be called when the receiver's
// owner is being destroyed. The state of the receiver will be set to
// "isBeingDestroyed" after this is called.
- (void)close;
// Checks if a load request of the current navigation item should proceed. If // Checks if a load request of the current navigation item should proceed. If
// this returns |YES|, caller should create a webView and call // this returns |YES|, caller should create a webView and call
// |loadRequestForCurrentNavigationItem|. Otherwise this will set the request // |loadRequestForCurrentNavigationItem|. Otherwise this will set the request
......
...@@ -66,6 +66,9 @@ enum class BackForwardNavigationType { ...@@ -66,6 +66,9 @@ enum class BackForwardNavigationType {
// Returns The WKNavigationDelegate handler class from delegate. // Returns The WKNavigationDelegate handler class from delegate.
@property(nonatomic, readonly) CRWWKNavigationHandler* navigationHandler; @property(nonatomic, readonly) CRWWKNavigationHandler* navigationHandler;
// Set to YES when [self close] is called.
@property(nonatomic, assign) BOOL beingDestroyed;
@end @end
@implementation CRWWebRequestController @implementation CRWWebRequestController
...@@ -78,6 +81,10 @@ enum class BackForwardNavigationType { ...@@ -78,6 +81,10 @@ enum class BackForwardNavigationType {
return self; return self;
} }
- (void)close {
self.beingDestroyed = YES;
}
- (BOOL)maybeLoadRequestForCurrentNavigationItem { - (BOOL)maybeLoadRequestForCurrentNavigationItem {
web::NavigationItem* item = self.currentNavItem; web::NavigationItem* item = self.currentNavItem;
GURL targetURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); GURL targetURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
...@@ -275,7 +282,7 @@ enum class BackForwardNavigationType { ...@@ -275,7 +282,7 @@ enum class BackForwardNavigationType {
DCHECK(!web::GetWebClient()->IsSlimNavigationManagerEnabled()); DCHECK(!web::GetWebClient()->IsSlimNavigationManagerEnabled());
self.webState->ShowRepostFormWarningDialog( self.webState->ShowRepostFormWarningDialog(
base::BindOnce(^(bool shouldContinue) { base::BindOnce(^(bool shouldContinue) {
if ([_delegate webRequestControllerIsBeingDestroyed:self]) if (self.beingDestroyed)
return; return;
if (shouldContinue) if (shouldContinue)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment