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

Move didReceiveWebViewNavigationDelegateCallback into

CRWWKNavigationHandler.

CRWWebController.didReceiveWebViewNavigationDelegateCallback is called
when it receives any callback from WKWebView. This CL moves it into
CRWWKNavigationHandler and delegates all WKNavigationDelegate callbacks
to CRWWKNavigationHandler. This CL also makes
CRWWebController._isBeingDestroyed visible to CRWWKNavigationHandler
through CRWWKNavigationHandlerDelegate protocol.

Bug: 956511
Change-Id: Iecb377c603eb62e3a7265149b9394c8a2310c3ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1599013
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659422}
parent bdd7bca7
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
@class CRWPendingNavigationInfo; @class CRWPendingNavigationInfo;
@class CRWWKNavigationStates; @class CRWWKNavigationStates;
@class CRWWKNavigationHandler;
namespace base { namespace base {
class RepeatingTimer; class RepeatingTimer;
...@@ -18,12 +19,18 @@ class RepeatingTimer; ...@@ -18,12 +19,18 @@ class RepeatingTimer;
// CRWWKNavigationHandler uses this protocol to interact with its owner. // CRWWKNavigationHandler uses this protocol to interact with its owner.
@protocol CRWWKNavigationHandlerDelegate <NSObject> @protocol CRWWKNavigationHandlerDelegate <NSObject>
// Returns YES if WKWebView was deallocated or is being deallocated.
- (BOOL)navigationHandlerWebViewBeingDestroyed:
(CRWWKNavigationHandler*)navigationHandler;
@end @end
// Handler class for WKNavigationDelegate, deals with navigation callbacks from // Handler class for WKNavigationDelegate, deals with navigation callbacks from
// WKWebView and maintains page loading state. // WKWebView and maintains page loading state.
@interface CRWWKNavigationHandler : NSObject <WKNavigationDelegate> @interface CRWWKNavigationHandler : NSObject <WKNavigationDelegate>
@property(nonatomic, weak) id<CRWWKNavigationHandlerDelegate> delegate;
// Pending information for an in-progress page navigation. The lifetime of // Pending information for an in-progress page navigation. The lifetime of
// this object starts at |decidePolicyForNavigationAction| where the info is // this object starts at |decidePolicyForNavigationAction| where the info is
// extracted from the request, and ends at either |didCommitNavigation| or // extracted from the request, and ends at either |didCommitNavigation| or
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/web/navigation/crw_wk_navigation_handler.h" #import "ios/web/navigation/crw_wk_navigation_handler.h"
#include "base/metrics/histogram_macros.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#import "ios/web/navigation/crw_pending_navigation_info.h" #import "ios/web/navigation/crw_pending_navigation_info.h"
#import "ios/web/navigation/crw_wk_navigation_states.h" #import "ios/web/navigation/crw_wk_navigation_states.h"
...@@ -27,6 +28,80 @@ ...@@ -27,6 +28,80 @@
return self; return self;
} }
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView*)webView
decidePolicyForNavigationAction:(WKNavigationAction*)action
decisionHandler:
(void (^)(WKNavigationActionPolicy))decisionHandler {
[self didReceiveWKNavigationDelegateCallback];
}
- (void)webView:(WKWebView*)webView
decidePolicyForNavigationResponse:(WKNavigationResponse*)WKResponse
decisionHandler:
(void (^)(WKNavigationResponsePolicy))handler {
[self didReceiveWKNavigationDelegateCallback];
}
- (void)webView:(WKWebView*)webView
didStartProvisionalNavigation:(WKNavigation*)navigation {
[self didReceiveWKNavigationDelegateCallback];
}
- (void)webView:(WKWebView*)webView
didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation {
[self didReceiveWKNavigationDelegateCallback];
}
- (void)webView:(WKWebView*)webView
didFailProvisionalNavigation:(WKNavigation*)navigation
withError:(NSError*)error {
[self didReceiveWKNavigationDelegateCallback];
}
- (void)webView:(WKWebView*)webView
didCommitNavigation:(WKNavigation*)navigation {
[self didReceiveWKNavigationDelegateCallback];
}
- (void)webView:(WKWebView*)webView
didFinishNavigation:(WKNavigation*)navigation {
[self didReceiveWKNavigationDelegateCallback];
}
- (void)webView:(WKWebView*)webView
didFailNavigation:(WKNavigation*)navigation
withError:(NSError*)error {
[self didReceiveWKNavigationDelegateCallback];
}
- (void)webView:(WKWebView*)webView
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge
completionHandler:
(void (^)(NSURLSessionAuthChallengeDisposition,
NSURLCredential*))completionHandler {
[self didReceiveWKNavigationDelegateCallback];
}
- (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView {
[self didReceiveWKNavigationDelegateCallback];
}
#pragma mark - Private methods
// This method should be called on receiving WKNavigationDelegate callbacks. It
// will log a metric if the callback occurs after the reciever has already been
// closed. It also stops the SafeBrowsing warning detection timer, since after
// this point it's too late for a SafeBrowsing warning to be displayed for the
// navigation for which the timer was started.
- (void)didReceiveWKNavigationDelegateCallback {
if ([self.delegate navigationHandlerWebViewBeingDestroyed:self]) {
UMA_HISTOGRAM_BOOLEAN("Renderer.WKWebViewCallbackAfterDestroy", true);
}
_safeBrowsingWarningDetectionTimer.Stop();
}
#pragma mark - Public methods #pragma mark - Public methods
- (void)stopLoading { - (void)stopLoading {
......
...@@ -229,6 +229,7 @@ bool RequiresContentFilterBlockingWorkaround() { ...@@ -229,6 +229,7 @@ bool RequiresContentFilterBlockingWorkaround() {
} // namespace } // namespace
@interface CRWWebController () <BrowsingDataRemoverObserver, @interface CRWWebController () <BrowsingDataRemoverObserver,
CRWWKNavigationHandlerDelegate,
CRWContextMenuDelegate, CRWContextMenuDelegate,
CRWNativeContentDelegate, CRWNativeContentDelegate,
CRWSSLStatusUpdaterDataSource, CRWSSLStatusUpdaterDataSource,
...@@ -331,6 +332,8 @@ bool RequiresContentFilterBlockingWorkaround() { ...@@ -331,6 +332,8 @@ bool RequiresContentFilterBlockingWorkaround() {
// The WKNavigationDelegate handler class. // The WKNavigationDelegate handler class.
@property(nonatomic, readonly, strong) @property(nonatomic, readonly, strong)
CRWWKNavigationHandler* navigationHandler; CRWWKNavigationHandler* navigationHandler;
// YES if in the process of closing.
@property(nonatomic, readwrite, assign) BOOL beingDestroyed;
// If |contentView_| contains a web view, this is the web view it contains. // If |contentView_| contains a web view, this is the web view it contains.
// If not, it's nil. When setting the property, it performs basic setup. // If not, it's nil. When setting the property, it performs basic setup.
...@@ -617,6 +620,7 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -617,6 +620,7 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
object:nil]; object:nil];
_navigationHandler = [[CRWWKNavigationHandler alloc] init]; _navigationHandler = [[CRWWKNavigationHandler alloc] init];
_navigationHandler.delegate = self;
} }
return self; return self;
} }
...@@ -4039,7 +4043,9 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -4039,7 +4043,9 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
decidePolicyForNavigationAction:(WKNavigationAction*)action decidePolicyForNavigationAction:(WKNavigationAction*)action
decisionHandler: decisionHandler:
(void (^)(WKNavigationActionPolicy))decisionHandler { (void (^)(WKNavigationActionPolicy))decisionHandler {
[self didReceiveWebViewNavigationDelegateCallback]; [self.navigationHandler webView:webView
decidePolicyForNavigationAction:action
decisionHandler:decisionHandler];
_webProcessCrashed = NO; _webProcessCrashed = NO;
if (_isBeingDestroyed) { if (_isBeingDestroyed) {
...@@ -4354,7 +4360,9 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -4354,7 +4360,9 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
decidePolicyForNavigationResponse:(WKNavigationResponse*)WKResponse decidePolicyForNavigationResponse:(WKNavigationResponse*)WKResponse
decisionHandler: decisionHandler:
(void (^)(WKNavigationResponsePolicy))handler { (void (^)(WKNavigationResponsePolicy))handler {
[self didReceiveWebViewNavigationDelegateCallback]; [self.navigationHandler webView:webView
decidePolicyForNavigationResponse:WKResponse
decisionHandler:handler];
// If this is a placeholder navigation, pass through. // If this is a placeholder navigation, pass through.
GURL responseURL = net::GURLWithNSURL(WKResponse.response.URL); GURL responseURL = net::GURLWithNSURL(WKResponse.response.URL);
...@@ -4416,7 +4424,8 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -4416,7 +4424,8 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
- (void)webView:(WKWebView*)webView - (void)webView:(WKWebView*)webView
didStartProvisionalNavigation:(WKNavigation*)navigation { didStartProvisionalNavigation:(WKNavigation*)navigation {
[self didReceiveWebViewNavigationDelegateCallback]; [self.navigationHandler webView:webView
didStartProvisionalNavigation:navigation];
GURL webViewURL = net::GURLWithNSURL(webView.URL); GURL webViewURL = net::GURLWithNSURL(webView.URL);
...@@ -4534,7 +4543,8 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -4534,7 +4543,8 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
- (void)webView:(WKWebView*)webView - (void)webView:(WKWebView*)webView
didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation { didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation {
[self didReceiveWebViewNavigationDelegateCallback]; [self.navigationHandler webView:webView
didReceiveServerRedirectForProvisionalNavigation:navigation];
GURL webViewURL = net::GURLWithNSURL(webView.URL); GURL webViewURL = net::GURLWithNSURL(webView.URL);
...@@ -4554,7 +4564,10 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -4554,7 +4564,10 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
- (void)webView:(WKWebView*)webView - (void)webView:(WKWebView*)webView
didFailProvisionalNavigation:(WKNavigation*)navigation didFailProvisionalNavigation:(WKNavigation*)navigation
withError:(NSError*)error { withError:(NSError*)error {
[self didReceiveWebViewNavigationDelegateCallback]; [self.navigationHandler webView:webView
didFailProvisionalNavigation:navigation
withError:error];
[self.navigationHandler.navigationStates [self.navigationHandler.navigationStates
setState:web::WKNavigationState::PROVISIONALY_FAILED setState:web::WKNavigationState::PROVISIONALY_FAILED
forNavigation:navigation]; forNavigation:navigation];
...@@ -4622,7 +4635,7 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -4622,7 +4635,7 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
- (void)webView:(WKWebView*)webView - (void)webView:(WKWebView*)webView
didCommitNavigation:(WKNavigation*)navigation { didCommitNavigation:(WKNavigation*)navigation {
[self didReceiveWebViewNavigationDelegateCallback]; [self.navigationHandler webView:webView didCommitNavigation:navigation];
// For reasons not yet fully understood, sometimes WKWebView triggers // For reasons not yet fully understood, sometimes WKWebView triggers
// |webView:didFinishNavigation| before |webView:didCommitNavigation|. If a // |webView:didFinishNavigation| before |webView:didCommitNavigation|. If a
...@@ -4844,7 +4857,7 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -4844,7 +4857,7 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
- (void)webView:(WKWebView*)webView - (void)webView:(WKWebView*)webView
didFinishNavigation:(WKNavigation*)navigation { didFinishNavigation:(WKNavigation*)navigation {
[self didReceiveWebViewNavigationDelegateCallback]; [self.navigationHandler webView:webView didFinishNavigation:navigation];
// Sometimes |webView:didFinishNavigation| arrives before // Sometimes |webView:didFinishNavigation| arrives before
// |webView:didCommitNavigation|. Explicitly trigger post-commit processing. // |webView:didCommitNavigation|. Explicitly trigger post-commit processing.
...@@ -4996,7 +5009,9 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -4996,7 +5009,9 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
- (void)webView:(WKWebView*)webView - (void)webView:(WKWebView*)webView
didFailNavigation:(WKNavigation*)navigation didFailNavigation:(WKNavigation*)navigation
withError:(NSError*)error { withError:(NSError*)error {
[self didReceiveWebViewNavigationDelegateCallback]; [self.navigationHandler webView:webView
didFailNavigation:navigation
withError:error];
[self.navigationHandler.navigationStates [self.navigationHandler.navigationStates
setState:web::WKNavigationState::FAILED setState:web::WKNavigationState::FAILED
...@@ -5014,7 +5029,9 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -5014,7 +5029,9 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
completionHandler: completionHandler:
(void (^)(NSURLSessionAuthChallengeDisposition, (void (^)(NSURLSessionAuthChallengeDisposition,
NSURLCredential*))completionHandler { NSURLCredential*))completionHandler {
[self didReceiveWebViewNavigationDelegateCallback]; [self.navigationHandler webView:webView
didReceiveAuthenticationChallenge:challenge
completionHandler:completionHandler];
NSString* authMethod = challenge.protectionSpace.authenticationMethod; NSString* authMethod = challenge.protectionSpace.authenticationMethod;
if ([authMethod isEqual:NSURLAuthenticationMethodHTTPBasic] || if ([authMethod isEqual:NSURLAuthenticationMethodHTTPBasic] ||
...@@ -5053,7 +5070,7 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -5053,7 +5070,7 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
} }
- (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView {
[self didReceiveWebViewNavigationDelegateCallback]; [self.navigationHandler webViewWebContentProcessDidTerminate:webView];
_certVerificationErrors->Clear(); _certVerificationErrors->Clear();
[self removeAllWebFrames]; [self removeAllWebFrames];
...@@ -5387,18 +5404,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -5387,18 +5404,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
return provisionalLoad; return provisionalLoad;
} }
// This method should be called on receiving WKNavigationDelegate callbacks. It
// will log a metric if the callback occurs after the reciever has already been
// closed. It also stops the SafeBrowsing warning detection timer, since after
// this point it's too late for a SafeBrowsing warning to be displayed for the
// navigation for which the timer was started.
- (void)didReceiveWebViewNavigationDelegateCallback {
if (_isBeingDestroyed) {
UMA_HISTOGRAM_BOOLEAN("Renderer.WKWebViewCallbackAfterDestroy", true);
}
self.navigationHandler.safeBrowsingWarningDetectionTimer->Stop();
}
// Returns YES if response should be rendered in WKWebView. // Returns YES if response should be rendered in WKWebView.
- (BOOL)shouldRenderResponse:(WKNavigationResponse*)WKResponse { - (BOOL)shouldRenderResponse:(WKNavigationResponse*)WKResponse {
if (!WKResponse.canShowMIMEType) { if (!WKResponse.canShowMIMEType) {
...@@ -6097,6 +6102,13 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -6097,6 +6102,13 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
} }
} }
#pragma mark - CRWWKNavigationHandlerDelegate
- (BOOL)navigationHandlerWebViewBeingDestroyed:
(CRWWKNavigationHandler*)navigationHandler {
return _beingDestroyed;
}
#pragma mark - Testing-Only Methods #pragma mark - Testing-Only Methods
- (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView { - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView {
......
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