Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Unified Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 2950853002: Gracefully handle didCommitNavigation: call after didFinishNavigation: (Closed)
Patch Set: Updated comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_wk_navigation_states.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/ui/crw_web_controller.mm
diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm
index 49e05b2de8f502e2749c905d6061bec48b62bf71..f0cd6cea6d037fdbbe61c7ceba402c4dabaa84fa 100644
--- a/ios/web/web_state/ui/crw_web_controller.mm
+++ b/ios/web/web_state/ui/crw_web_controller.mm
@@ -4538,6 +4538,9 @@ registerLoadRequestForURL:(const GURL&)requestURL
didCommitNavigation:(WKNavigation*)navigation {
[self displayWebView];
+ bool navigationFinished = [_navigationStates stateForNavigation:navigation] ==
+ web::WKNavigationState::FINISHED;
+
// Record the navigation state.
[_navigationStates setState:web::WKNavigationState::COMMITTED
forNavigation:navigation];
@@ -4629,10 +4632,21 @@ registerLoadRequestForURL:(const GURL&)requestURL
UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection",
static_cast<bool>(cert));
}
+
+ if (navigationFinished) {
+ // webView:didFinishNavigation: was called before
+ // webView:didCommitNavigation:, so remove the navigation now and signal
+ // that navigation was finished.
+ [_navigationStates removeNavigation:navigation];
+ [self didFinishNavigation:navigation];
+ }
}
- (void)webView:(WKWebView*)webView
didFinishNavigation:(WKNavigation*)navigation {
+ bool navigationCommitted =
+ [_navigationStates stateForNavigation:navigation] ==
+ web::WKNavigationState::COMMITTED;
[_navigationStates setState:web::WKNavigationState::FINISHED
forNavigation:navigation];
@@ -4643,7 +4657,12 @@ registerLoadRequestForURL:(const GURL&)requestURL
// appropriate time rather than invoking here.
web::ExecuteJavaScript(webView, @"__gCrWeb.didFinishNavigation()", nil);
[self didFinishNavigation:navigation];
- [_navigationStates removeNavigation:navigation];
+
+ // Remove navigation only if it has been committed. Otherwise it will be
+ // removed in webView:didCommitNavigation: callback.
+ if (navigationCommitted) {
+ [_navigationStates removeNavigation:navigation];
+ }
}
- (void)webView:(WKWebView*)webView
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_wk_navigation_states.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698