Index: ios/web/web_state/ui/crw_wk_web_view_web_controller.mm |
diff --git a/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm b/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm |
index de29b293c2da896d3da9b639632678324333a1ba..e2d18a492604db1f08047168fd73660d2b4d10f4 100644 |
--- a/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm |
+++ b/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm |
@@ -89,6 +89,23 @@ NSString* GetRefererFromNavigationAction(WKNavigationAction* action) { |
NSString* const kScriptMessageName = @"crwebinvoke"; |
NSString* const kScriptImmediateName = @"crwebinvokeimmediate"; |
+// Key of the UMA Navigation.IOSWKWebViewSlowFastBackForward histogram. |
+const char kUMAWKWebViewSlowFastBackForwardNavigationKey[] = |
+ "Navigation.IOSWKWebViewSlowFastBackForward"; |
+ |
+// Values for the histogram that counts slow/fast back/forward navigations. |
+enum BackForwardNavigationType { |
+ // Fast back navigation through WKWebView back-forward list. |
+ FAST_BACK = 0, |
+ // Slow back navigation when back-forward list navigation is not possible. |
+ SLOW_BACK, |
+ // Fast forward navigation through WKWebView back-forward list. |
+ FAST_FORWARD, |
+ // Slow forward navigation when back-forward list navigation is not possible. |
+ SLOW_FORWARD, |
+ BACK_FORWARD_NAVIGATION_TYPE_COUNT |
+}; |
+ |
// Utility functions for storing the source of NSErrors received by WKWebViews: |
// - Errors received by |-webView:didFailProvisionalNavigation:withError:| are |
// recorded using WKWebViewErrorSource::PROVISIONAL_LOAD. These should be |
@@ -298,6 +315,12 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
// navigation. |
- (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item; |
+// Indicates if navigating using WKBackForwardList API is possible. |
+// Returns YES if there is a corresponding WKBackForwardListItem and it is in |
+// the current WKWebView's back-forward list. |
+- (BOOL)isNavigationPerformedWithBackForwardList: |
+ (web::WKBackForwardListItemHolder*)holder; |
+ |
// Called when web view process has been terminated. |
- (void)webViewWebProcessDidCrash; |
@@ -473,6 +496,33 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
[super stopLoading]; |
} |
+- (void)goDelta:(int)delta { |
+ [super goDelta:delta]; |
+ if (delta == 0) |
+ return; |
+ |
+ // Report slow/fast navigation metric. |
+ web::WKBackForwardListItemHolder* holder = |
+ web::WKBackForwardListItemHolder::FromNavigationItem( |
+ self.currentSessionEntry.navigationItemImpl); |
+ BOOL isFast = [self isNavigationPerformedWithBackForwardList:holder]; |
+ BOOL isBack = (delta < 0); |
+ |
+ BackForwardNavigationType navigationType = |
+ BackForwardNavigationType::FAST_BACK; |
+ if (isBack) { |
+ navigationType = isFast ? BackForwardNavigationType::FAST_BACK |
+ : BackForwardNavigationType::SLOW_BACK; |
+ } else { |
+ navigationType = isFast ? BackForwardNavigationType::FAST_FORWARD |
+ : BackForwardNavigationType::SLOW_FORWARD; |
+ } |
+ |
+ UMA_HISTOGRAM_ENUMERATION( |
+ kUMAWKWebViewSlowFastBackForwardNavigationKey, navigationType, |
+ BackForwardNavigationType::BACK_FORWARD_NAVIGATION_TYPE_COUNT); |
+} |
+ |
#pragma mark - |
#pragma mark Testing-Only Methods |
@@ -619,12 +669,9 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
[self loadRequest:request]; |
}; |
- // If there is no corresponding WKBackForwardListItem, or the item is not in |
- // the current WKWebView's back-forward list, navigating using WKWebView API |
- // is not possible. In this case, fall back to the default navigation |
- // mechanism. |
- if (!holder->back_forward_list_item() || |
- ![self isBackForwardListItemValid:holder->back_forward_list_item()]) { |
+ // If the fast navigation with WKBackForwardList is not possible, fall back to |
+ // the default navigation mechanism. |
+ if ([self isNavigationPerformedWithBackForwardList:holder]) { |
defaultNavigationBlock(); |
return; |
} |
@@ -948,6 +995,12 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
[list.backList indexOfObject:item] != NSNotFound; |
} |
+- (BOOL)isNavigationPerformedWithBackForwardList: |
+ (web::WKBackForwardListItemHolder*)holder { |
+ return (holder->back_forward_list_item() && |
+ [self isBackForwardListItemValid:holder->back_forward_list_item()]); |
+} |
+ |
- (void)webViewWebProcessDidCrash { |
_webProcessIsDead = YES; |