Move didStartProvisionalNavigation to CRWWKNavigationHandler.

This CL moves WKNavigationDelegate.didStartProvisionalNavigation from
CRWWebController into CRWWKNavigationHandler.

Bug: 956511
Change-Id: Ie20352c10350b00842c4ff8ce037f2e2f1df85de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1617354
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Reviewed-by: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661307}
diff --git a/ios/web/navigation/crw_wk_navigation_handler.h b/ios/web/navigation/crw_wk_navigation_handler.h
index 0e891cb..c43b87d 100644
--- a/ios/web/navigation/crw_wk_navigation_handler.h
+++ b/ios/web/navigation/crw_wk_navigation_handler.h
@@ -8,6 +8,8 @@
 #import <UIKit/UIKit.h>
 #import <WebKit/WebKit.h>
 
+#import <memory>
+
 #include "ui/base/page_transition_types.h"
 
 @class CRWWKNavigationHandler;
@@ -18,6 +20,7 @@
 class RepeatingTimer;
 }
 namespace web {
+enum class WKNavigationState;
 struct Referrer;
 class WebStateImpl;
 class NavigationContextImpl;
@@ -64,6 +67,10 @@
 // Stop Loading current page.
 - (void)navigationHandlerStopLoading:(CRWWKNavigationHandler*)navigationHandler;
 
+// Aborts any load for both the web view and its controller.
+- (void)navigationHandlerAbortLoading:
+    (CRWWKNavigationHandler*)navigationHandler;
+
 // Returns YES if |url| should be loaded in a native view.
 - (BOOL)navigationHandler:(CRWWKNavigationHandler*)navigationHandler
     shouldLoadURLInNativeView:(const GURL&)url;
@@ -74,6 +81,14 @@
 - (void)navigationHandlerRequirePageReconstruction:
     (CRWWKNavigationHandler*)navigationHandler;
 
+- (std::unique_ptr<web::NavigationContextImpl>)
+            navigationHandler:(CRWWKNavigationHandler*)navigationHandler
+    registerLoadRequestForURL:(const GURL&)URL
+       sameDocumentNavigation:(BOOL)sameDocumentNavigation
+               hasUserGesture:(BOOL)hasUserGesture
+            rendererInitiated:(BOOL)renderedInitiated
+        placeholderNavigation:(BOOL)placeholderNavigation;
+
 @end
 
 // Handler class for WKNavigationDelegate, deals with navigation callbacks from
@@ -96,6 +111,10 @@
 // flight.
 @property(nonatomic, readonly, strong) CRWWKNavigationStates* navigationStates;
 
+// The current page loading phase.
+// TODO(crbug.com/956511): Remove this once refactor is done.
+@property(nonatomic, readwrite, assign) web::WKNavigationState navigationState;
+
 // The SafeBrowsingDetection timer.
 // TODO(crbug.com/956511): Remove this once refactor is done.
 @property(nonatomic, readonly, assign)
diff --git a/ios/web/navigation/crw_wk_navigation_handler.mm b/ios/web/navigation/crw_wk_navigation_handler.mm
index ba56e46..624dd2d 100644
--- a/ios/web/navigation/crw_wk_navigation_handler.mm
+++ b/ios/web/navigation/crw_wk_navigation_handler.mm
@@ -33,8 +33,10 @@
 #endif
 
 using web::wk_navigation_util::IsPlaceholderUrl;
+using web::wk_navigation_util::CreatePlaceholderUrlForUrl;
 using web::wk_navigation_util::kReferrerHeaderName;
 using web::wk_navigation_util::IsRestoreSessionUrl;
+using web::wk_navigation_util::IsWKInternalUrl;
 
 @interface CRWWKNavigationHandler ()
 
@@ -60,6 +62,9 @@
 - (instancetype)init {
   if (self = [super init]) {
     _navigationStates = [[CRWWKNavigationStates alloc] init];
+    // Load phase when no WebView present is 'loaded' because this represents
+    // the idle state.
+    _navigationState = web::WKNavigationState::FINISHED;
   }
   return self;
 }
@@ -456,6 +461,117 @@
 - (void)webView:(WKWebView*)webView
     didStartProvisionalNavigation:(WKNavigation*)navigation {
   [self didReceiveWKNavigationDelegateCallback];
+
+  GURL webViewURL = net::GURLWithNSURL(webView.URL);
+
+  [self.navigationStates setState:web::WKNavigationState::STARTED
+                    forNavigation:navigation];
+
+  if (webViewURL.is_empty()) {
+    // May happen on iOS9, however in didCommitNavigation: callback the URL
+    // will be "about:blank".
+    webViewURL = GURL(url::kAboutBlankURL);
+  }
+
+  web::NavigationContextImpl* context =
+      [self.navigationStates contextForNavigation:navigation];
+
+  if (context) {
+    // This is already seen and registered navigation.
+
+    if (context->IsLoadingErrorPage()) {
+      // This is loadHTMLString: navigation to display error page in web view.
+      self.navigationState = web::WKNavigationState::REQUESTED;
+      return;
+    }
+
+    if (!context->IsPlaceholderNavigation() &&
+        context->GetUrl() != webViewURL) {
+      // Update last seen URL because it may be changed by WKWebView (f.e. by
+      // performing characters escaping).
+      web::NavigationItem* item =
+          web::GetItemWithUniqueID(self.navigationManagerImpl, context);
+      if (!IsWKInternalUrl(webViewURL)) {
+        if (item) {
+          item->SetURL(webViewURL);
+        }
+        context->SetUrl(webViewURL);
+      }
+    }
+    self.webStateImpl->OnNavigationStarted(context);
+    return;
+  }
+
+  // This is renderer-initiated navigation which was not seen before and
+  // should be registered.
+
+  // When using WKBasedNavigationManager, renderer-initiated app-specific loads
+  // should be allowed in two specific cases:
+  // 1) if |backForwardList.currentItem| is a placeholder URL for the
+  //    provisional load URL (i.e. webView.URL), then this is an in-progress
+  //    app-specific load and should not be restarted.
+  // 2) back/forward navigation to an app-specific URL should be allowed.
+  bool exemptedAppSpecificLoad = false;
+  if (web::GetWebClient()->IsSlimNavigationManagerEnabled()) {
+    bool currentItemIsPlaceholder =
+        CreatePlaceholderUrlForUrl(webViewURL) ==
+        net::GURLWithNSURL(webView.backForwardList.currentItem.URL);
+    bool isBackForward = self.pendingNavigationInfo.navigationType ==
+                         WKNavigationTypeBackForward;
+    bool isRestoringSession =
+        web::GetWebClient()->IsSlimNavigationManagerEnabled() &&
+        IsRestoreSessionUrl([self.delegate navigationHandlerDocumentURL:self]);
+    exemptedAppSpecificLoad =
+        currentItemIsPlaceholder || isBackForward || isRestoringSession;
+  }
+
+  if (!web::GetWebClient()->IsAppSpecificURL(webViewURL) ||
+      !exemptedAppSpecificLoad) {
+    self.webStateImpl->ClearWebUI();
+  }
+
+  if (web::GetWebClient()->IsAppSpecificURL(webViewURL) &&
+      !exemptedAppSpecificLoad) {
+    // Restart app specific URL loads to properly capture state.
+    // TODO(crbug.com/546347): Extract necessary tasks for app specific URL
+    // navigation rather than restarting the load.
+
+    // Renderer-initiated loads of WebUI can be done only from other WebUI
+    // pages. WebUI pages may have increased power and using the same web
+    // process (which may potentially be controller by an attacker) is
+    // dangerous.
+    if (web::GetWebClient()->IsAppSpecificURL(
+            [self.delegate navigationHandlerDocumentURL:self])) {
+      [self.delegate navigationHandlerAbortLoading:self];
+      web::NavigationManager::WebLoadParams params(webViewURL);
+      self.navigationManagerImpl->LoadURLWithParams(params);
+    }
+    return;
+  }
+
+  self.webStateImpl->GetNavigationManagerImpl()
+      .OnRendererInitiatedNavigationStarted(webViewURL);
+
+  // When a client-side redirect occurs while an interstitial warning is
+  // displayed, clear the warning and its navigation item, so that a new
+  // pending item is created for |context| in |registerLoadRequestForURL|. See
+  // crbug.com/861836.
+  self.webStateImpl->ClearTransientContent();
+
+  std::unique_ptr<web::NavigationContextImpl> navigationContext =
+      [self.delegate navigationHandler:self
+             registerLoadRequestForURL:webViewURL
+                sameDocumentNavigation:NO
+                        hasUserGesture:self.pendingNavigationInfo.hasUserGesture
+                     rendererInitiated:YES
+                 placeholderNavigation:IsPlaceholderUrl(webViewURL)];
+  web::NavigationContextImpl* navigationContextPtr = navigationContext.get();
+  // GetPendingItem which may be called inside OnNavigationStarted relies on
+  // association between NavigationContextImpl and WKNavigation.
+  [self.navigationStates setContext:std::move(navigationContext)
+                      forNavigation:navigation];
+  self.webStateImpl->OnNavigationStarted(navigationContextPtr);
+  DCHECK_EQ(web::WKNavigationState::REQUESTED, self.navigationState);
 }
 
 - (void)webView:(WKWebView*)webView
diff --git a/ios/web/web_state/ui/crw_web_controller.h b/ios/web/web_state/ui/crw_web_controller.h
index 60587c7..0701f8bf 100644
--- a/ios/web/web_state/ui/crw_web_controller.h
+++ b/ios/web/web_state/ui/crw_web_controller.h
@@ -66,9 +66,6 @@
 // is not supported.
 @property(weak, nonatomic, readonly) UIView* viewForPrinting;
 
-// Returns the current page loading phase.
-@property(nonatomic, readonly, assign) web::WKNavigationState navigationState;
-
 // The fraction of the page load that has completed as a number between 0.0
 // (nothing loaded) and 1.0 (fully loaded).
 @property(nonatomic, readonly) double loadingProgress;
@@ -212,6 +209,9 @@
 
 @property(nonatomic, readonly) web::WebState* webState;
 @property(nonatomic, readonly) web::WebStateImpl* webStateImpl;
+// Returns the current page loading phase.
+// TODO(crbug.com/956511): Remove this once refactor is done.
+@property(nonatomic, readonly, assign) web::WKNavigationState navigationState;
 
 // Injects a CRWWebViewContentView for testing.  Takes ownership of
 // |webViewContentView|.
diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm
index 6a8e1d9..46be88c 100644
--- a/ios/web/web_state/ui/crw_web_controller.mm
+++ b/ios/web/web_state/ui/crw_web_controller.mm
@@ -317,9 +317,6 @@
 // changed.
 @property(weak, nonatomic, readonly) NSDictionary* WKWebViewObservers;
 
-// Current page navigation state.
-@property(nonatomic, readwrite, assign) web::WKNavigationState navigationState;
-
 // The web view's view of the current URL. During page transitions
 // this may not be the same as the session history's view of the current URL.
 // This method can change the state of the CRWWebController, as it will display
@@ -410,9 +407,10 @@
 // may be called multiple times and thus must be idempotent.
 - (void)loadCompleteWithSuccess:(BOOL)loadSuccess
                      forContext:(web::NavigationContextImpl*)context;
-// Called after URL is finished loading and self.navigationState is set to
-// FINISHED. |context| contains information about the navigation associated
-// with the URL. It is nil if currentURL is invalid.
+// Called after URL is finished loading and
+// self.navigationHandler.navigationState is set to FINISHED. |context| contains
+// information about the navigation associated with the URL. It is nil if
+// currentURL is invalid.
 - (void)didFinishWithURL:(const GURL&)currentURL
              loadSuccess:(BOOL)loadSuccess
                  context:(nullable const web::NavigationContextImpl*)context;
@@ -534,9 +532,6 @@
       _allowsBackForwardNavigationGestures = YES;
 
     DCHECK(_webStateImpl);
-    // Load phase when no WebView present is 'loaded' because this represents
-    // the idle state.
-    _navigationState = web::WKNavigationState::FINISHED;
     // Content area is lazily instantiated.
     _defaultURL = GURL(url::kAboutBlankURL);
     _jsInjector = [[CRWJSInjector alloc] initWithDelegate:self];
@@ -1111,7 +1106,8 @@
 
   // Abort any outstanding page load. This ensures the delegate gets informed
   // about the outgoing page, and further messages from the page are suppressed.
-  if (self.navigationState != web::WKNavigationState::FINISHED)
+  if (self.navigationHandler.navigationState !=
+      web::WKNavigationState::FINISHED)
     [self abortLoad];
 
   DCHECK(!_isHalted);
@@ -1175,7 +1171,7 @@
       self.webStateImpl, URL,
       /*has_user_gesture=*/true, item->GetTransitionType(),
       /*is_renderer_initiated=*/false);
-  self.navigationState = web::WKNavigationState::REQUESTED;
+  self.navigationHandler.navigationState = web::WKNavigationState::REQUESTED;
   navigationContext->SetNavigationItemUniqueID(item->GetUniqueID());
 
   item->SetNavigationInitiationType(
@@ -1216,7 +1212,7 @@
   // Remove the transient content view.
   self.webStateImpl->ClearTransientContent();
 
-  self.navigationState = web::WKNavigationState::REQUESTED;
+  self.navigationHandler.navigationState = web::WKNavigationState::REQUESTED;
 
   // Web View should not be created for App Specific URLs.
   if (!web::GetWebClient()->IsAppSpecificURL(URL)) {
@@ -1358,7 +1354,7 @@
     context->SetIsSameDocument(true);
   } else {
     self.webStateImpl->SetIsLoading(true);
-    self.navigationState = web::WKNavigationState::REQUESTED;
+    self.navigationHandler.navigationState = web::WKNavigationState::REQUESTED;
   }
 
   web::WKBackForwardListItemHolder* holder =
@@ -1648,10 +1644,11 @@
     // Before changing navigation state, the delegate should be informed that
     // any existing request is being cancelled before completion.
     [self loadCancelled];
-    DCHECK_EQ(web::WKNavigationState::FINISHED, self.navigationState);
+    DCHECK_EQ(web::WKNavigationState::FINISHED,
+              self.navigationHandler.navigationState);
   }
 
-  self.navigationState = web::WKNavigationState::REQUESTED;
+  self.navigationHandler.navigationState = web::WKNavigationState::REQUESTED;
 
   // Record the state of outgoing web view. Do nothing if native controller
   // exists, because in that case recordStateInHistory will record the state
@@ -2032,8 +2029,9 @@
 
 - (void)loadCancelled {
   // TODO(crbug.com/821995):  Check if this function should be removed.
-  if (self.navigationState != web::WKNavigationState::FINISHED) {
-    self.navigationState = web::WKNavigationState::FINISHED;
+  if (self.navigationHandler.navigationState !=
+      web::WKNavigationState::FINISHED) {
+    self.navigationHandler.navigationState = web::WKNavigationState::FINISHED;
     if (!_isHalted) {
       self.webStateImpl->SetIsLoading(false);
     }
@@ -2043,7 +2041,8 @@
 - (void)didFinishNavigation:(web::NavigationContextImpl*)context {
   // This can be called at multiple times after the document has loaded. Do
   // nothing if the document has already loaded.
-  if (self.navigationState == web::WKNavigationState::FINISHED)
+  if (self.navigationHandler.navigationState ==
+      web::WKNavigationState::FINISHED)
     return;
 
   // Restore allowsBackForwardNavigationGestures and the scroll proxy once
@@ -2070,12 +2069,12 @@
                      forContext:(web::NavigationContextImpl*)context {
   // The webView may have been torn down (or replaced by a native view). Be
   // safe and do nothing if that's happened.
-  if (self.navigationState != web::WKNavigationState::STARTED)
+  if (self.navigationHandler.navigationState != web::WKNavigationState::STARTED)
     return;
 
   const GURL currentURL([self currentURL]);
 
-  self.navigationState = web::WKNavigationState::FINISHED;
+  self.navigationHandler.navigationState = web::WKNavigationState::FINISHED;
 
   [self optOutScrollsToTopForSubviews];
 
@@ -2092,7 +2091,8 @@
 - (void)didFinishWithURL:(const GURL&)currentURL
              loadSuccess:(BOOL)loadSuccess
                  context:(nullable const web::NavigationContextImpl*)context {
-  DCHECK_EQ(web::WKNavigationState::FINISHED, self.navigationState);
+  DCHECK_EQ(web::WKNavigationState::FINISHED,
+            self.navigationHandler.navigationState);
 
   [self restoreStateFromHistory];
 
@@ -2502,7 +2502,7 @@
     [self.nativeController setDelegate:self];
   }
 
-  self.navigationState = web::WKNavigationState::FINISHED;
+  self.navigationHandler.navigationState = web::WKNavigationState::FINISHED;
   [self didFinishWithURL:targetURL loadSuccess:YES context:context.get()];
 }
 
@@ -3374,7 +3374,8 @@
   DCHECK(scrollState.IsValid());
   CGPoint contentOffset = scrollState.GetEffectiveContentOffsetForContentInset(
       self.webScrollView.contentInset);
-  if (self.navigationState == web::WKNavigationState::FINISHED) {
+  if (self.navigationHandler.navigationState ==
+      web::WKNavigationState::FINISHED) {
     // If the page is loaded, update the scroll immediately.
     self.webScrollView.contentOffset = contentOffset;
   } else {
@@ -3881,119 +3882,6 @@
     didStartProvisionalNavigation:(WKNavigation*)navigation {
   [self.navigationHandler webView:webView
       didStartProvisionalNavigation:navigation];
-
-  GURL webViewURL = net::GURLWithNSURL(webView.URL);
-
-  [self.navigationHandler.navigationStates
-           setState:web::WKNavigationState::STARTED
-      forNavigation:navigation];
-
-  if (webViewURL.is_empty()) {
-    // May happen on iOS9, however in didCommitNavigation: callback the URL
-    // will be "about:blank".
-    webViewURL = GURL(url::kAboutBlankURL);
-  }
-
-  web::NavigationContextImpl* context =
-      [self.navigationHandler.navigationStates contextForNavigation:navigation];
-
-  if (context) {
-    // This is already seen and registered navigation.
-
-    if (context->IsLoadingErrorPage()) {
-      // This is loadHTMLString: navigation to display error page in web view.
-      self.navigationState = web::WKNavigationState::REQUESTED;
-      return;
-    }
-
-    if (!context->IsPlaceholderNavigation() &&
-        context->GetUrl() != webViewURL) {
-      // Update last seen URL because it may be changed by WKWebView (f.e. by
-      // performing characters escaping).
-      web::NavigationItem* item =
-          web::GetItemWithUniqueID(self.navigationManagerImpl, context);
-      if (!IsWKInternalUrl(webViewURL)) {
-        if (item) {
-          item->SetURL(webViewURL);
-        }
-        context->SetUrl(webViewURL);
-      }
-    }
-    self.webStateImpl->OnNavigationStarted(context);
-    return;
-  }
-
-  // This is renderer-initiated navigation which was not seen before and
-  // should be registered.
-
-  // When using WKBasedNavigationManager, renderer-initiated app-specific loads
-  // should be allowed in two specific cases:
-  // 1) if |backForwardList.currentItem| is a placeholder URL for the
-  //    provisional load URL (i.e. webView.URL), then this is an in-progress
-  //    app-specific load and should not be restarted.
-  // 2) back/forward navigation to an app-specific URL should be allowed.
-  bool exemptedAppSpecificLoad = false;
-  if (web::GetWebClient()->IsSlimNavigationManagerEnabled()) {
-    bool currentItemIsPlaceholder =
-        CreatePlaceholderUrlForUrl(webViewURL) ==
-        net::GURLWithNSURL(webView.backForwardList.currentItem.URL);
-    bool isBackForward =
-        self.navigationHandler.pendingNavigationInfo.navigationType ==
-        WKNavigationTypeBackForward;
-    bool isRestoringSession =
-        web::GetWebClient()->IsSlimNavigationManagerEnabled() &&
-        IsRestoreSessionUrl(_documentURL);
-    exemptedAppSpecificLoad =
-        currentItemIsPlaceholder || isBackForward || isRestoringSession;
-  }
-
-  if (!web::GetWebClient()->IsAppSpecificURL(webViewURL) ||
-      !exemptedAppSpecificLoad) {
-    [self clearWebUI];
-  }
-
-  if (web::GetWebClient()->IsAppSpecificURL(webViewURL) &&
-      !exemptedAppSpecificLoad) {
-    // Restart app specific URL loads to properly capture state.
-    // TODO(crbug.com/546347): Extract necessary tasks for app specific URL
-    // navigation rather than restarting the load.
-
-    // Renderer-initiated loads of WebUI can be done only from other WebUI
-    // pages. WebUI pages may have increased power and using the same web
-    // process (which may potentially be controller by an attacker) is
-    // dangerous.
-    if (web::GetWebClient()->IsAppSpecificURL(_documentURL)) {
-      [self abortLoad];
-      NavigationManager::WebLoadParams params(webViewURL);
-      self.webState->GetNavigationManager()->LoadURLWithParams(params);
-    }
-    return;
-  }
-
-  self.webStateImpl->GetNavigationManagerImpl()
-      .OnRendererInitiatedNavigationStarted(webViewURL);
-
-  // When a client-side redirect occurs while an interstitial warning is
-  // displayed, clear the warning and its navigation item, so that a new
-  // pending item is created for |context| in |registerLoadRequestForURL|. See
-  // crbug.com/861836.
-  self.webStateImpl->ClearTransientContent();
-
-  std::unique_ptr<web::NavigationContextImpl> navigationContext =
-      [self registerLoadRequestForURL:webViewURL
-               sameDocumentNavigation:NO
-                       hasUserGesture:self.navigationHandler
-                                          .pendingNavigationInfo.hasUserGesture
-                    rendererInitiated:YES
-                placeholderNavigation:IsPlaceholderUrl(webViewURL)];
-  web::NavigationContextImpl* navigationContextPtr = navigationContext.get();
-  // GetPendingItem which may be called inside OnNavigationStarted relies on
-  // association between NavigationContextImpl and WKNavigation.
-  [self.navigationHandler.navigationStates
-         setContext:std::move(navigationContext)
-      forNavigation:navigation];
-  self.webStateImpl->OnNavigationStarted(navigationContextPtr);
-  DCHECK_EQ(web::WKNavigationState::REQUESTED, self.navigationState);
 }
 
 - (void)webView:(WKWebView*)webView
@@ -4589,7 +4477,7 @@
 // been registered for a non-document-changing URL change. Updates internal
 // state not specific to web pages.
 - (void)didStartLoading {
-  self.navigationState = web::WKNavigationState::STARTED;
+  self.navigationHandler.navigationState = web::WKNavigationState::STARTED;
   _displayStateOnStartLoading = self.pageDisplayState;
 
   _userInteractionState.SetUserInteractionRegisteredSincePageLoaded(false);
@@ -4959,7 +4847,8 @@
 // Called when WKWebView certificateChain or hasOnlySecureContent property has
 // changed.
 - (void)webViewSecurityFeaturesDidChange {
-  if (self.navigationState == web::WKNavigationState::REQUESTED) {
+  if (self.navigationHandler.navigationState ==
+      web::WKNavigationState::REQUESTED) {
     // Do not update SSL Status for pending load. It will be updated in
     // |webView:didCommitNavigation:| callback.
     return;
@@ -4998,7 +4887,8 @@
       IsRestoreSessionUrl(webViewURL)) {
     if (previousURLHasAboutScheme || is_back_forward_navigation) {
       [self.webView reload];
-      self.navigationState = web::WKNavigationState::REQUESTED;
+      self.navigationHandler.navigationState =
+          web::WKNavigationState::REQUESTED;
       return;
     }
   }
@@ -5007,8 +4897,8 @@
   // before committing the current navigation or resetting the web view's
   // |isLoading| property to NO.  If this is the first navigation for the web
   // view, this will result in an empty URL.
-  BOOL navigationWasCommitted =
-      self.navigationState != web::WKNavigationState::REQUESTED;
+  BOOL navigationWasCommitted = self.navigationHandler.navigationState !=
+                                web::WKNavigationState::REQUESTED;
   if (!navigationWasCommitted &&
       (webViewURL.is_empty() || webViewURL == _documentURL)) {
     return;
@@ -5259,7 +5149,8 @@
       _documentURL.GetOrigin() != newURL.GetOrigin()) {
     return NO;
   }
-  if (self.navigationState == web::WKNavigationState::REQUESTED) {
+  if (self.navigationHandler.navigationState ==
+      web::WKNavigationState::REQUESTED) {
     // Normally LOAD_REQUESTED indicates that this is a regular, pending
     // navigation, but it can also happen during a fast-back navigation across
     // a hash change, so that case is potentially a same-document navigation.
@@ -5408,6 +5299,11 @@
   [self stopLoading];
 }
 
+- (void)navigationHandlerAbortLoading:
+    (CRWWKNavigationHandler*)navigationHandler {
+  [self abortLoad];
+}
+
 - (void)navigationHandler:(CRWWKNavigationHandler*)navigationHandler
            setDocumentURL:(const GURL&)newURL
                   context:(web::NavigationContextImpl*)context {
@@ -5424,6 +5320,20 @@
   [self requirePageReconstruction];
 }
 
+- (std::unique_ptr<web::NavigationContextImpl>)
+            navigationHandler:(CRWWKNavigationHandler*)navigationHandler
+    registerLoadRequestForURL:(const GURL&)URL
+       sameDocumentNavigation:(BOOL)sameDocumentNavigation
+               hasUserGesture:(BOOL)hasUserGesture
+            rendererInitiated:(BOOL)renderedInitiated
+        placeholderNavigation:(BOOL)placeholderNavigation {
+  return [self registerLoadRequestForURL:URL
+                  sameDocumentNavigation:sameDocumentNavigation
+                          hasUserGesture:hasUserGesture
+                       rendererInitiated:renderedInitiated
+                   placeholderNavigation:placeholderNavigation];
+}
+
 #pragma mark - Testing-Only Methods
 
 - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView {
@@ -5441,4 +5351,8 @@
   _containerView = nil;
 }
 
+- (web::WKNavigationState)navigationState {
+  return self.navigationHandler.navigationState;
+}
+
 @end