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 5405dbe580cd0c94ffce0a1927bbf93baed96726..a4bc4c44d813e0a49d69823b414e42fc3c8b94fd 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 |
@@ -144,6 +144,9 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
// Cancelled navigations should be simply discarded without handling any |
// specific error. |
BOOL _pendingNavigationCancelled; |
+ |
+ // YES if the user has touched the content area since the last URL change. |
+ BOOL _touchedSinceLastURLChange; |
} |
// Response's MIME type of the last known navigation. |
@@ -368,6 +371,12 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
[super close]; |
} |
+- (void)touched:(BOOL)touched { |
+ [super touched:touched]; |
+ if (touched) |
+ _touchedSinceLastURLChange = YES; |
+} |
+ |
#pragma mark - |
#pragma mark Testing-Only Methods |
@@ -1014,14 +1023,36 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
#endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
- (void)registerLoadRequest:(const GURL&)url { |
- // If load request is registered via WKWebViewWebController, assume transition |
- // is link or client redirect as other transitions will already be registered |
- // by web controller or delegates. |
- // TODO(stuartmorgan): Remove guesswork and replace with information from |
- // decidePolicyForNavigationAction:. |
- ui::PageTransition transition = self.userInteractionRegistered |
- ? ui::PAGE_TRANSITION_LINK |
- : ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
+ // Get the navigation type from the last main frame load request, and try to |
+ // map that to a PageTransition. |
+ WKNavigationType navigationType = _pendingNavigationTypeForMainFrame |
+ ? *_pendingNavigationTypeForMainFrame |
+ : WKNavigationTypeOther; |
+ ui::PageTransition transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
+ switch (navigationType) { |
+ case WKNavigationTypeLinkActivated: |
+ transition = ui::PAGE_TRANSITION_LINK; |
+ break; |
+ case WKNavigationTypeFormSubmitted: |
+ case WKNavigationTypeFormResubmitted: |
+ transition = ui::PAGE_TRANSITION_FORM_SUBMIT; |
+ break; |
+ case WKNavigationTypeBackForward: |
+ transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
+ break; |
+ case WKNavigationTypeReload: |
+ transition = ui::PAGE_TRANSITION_RELOAD; |
+ break; |
+ case WKNavigationTypeOther: |
+ // The "Other" type covers a variety of very different cases, which may |
+ // or may not be the result of user actions. For now, guess based on |
+ // whether there's been a touch since the last URL change. |
+ // TODO(crbug.com/549301): See if this heuristic can be improved. |
+ transition = _touchedSinceLastURLChange |
+ ? ui::PAGE_TRANSITION_LINK |
+ : ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
+ break; |
+ } |
// The referrer is not known yet, and will be updated later. |
const web::Referrer emptyReferrer; |
[self registerLoadRequest:url referrer:emptyReferrer transition:transition]; |
@@ -1226,6 +1257,8 @@ WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
return; |
} |
GURL url(net::GURLWithNSURL([_wkWebView URL])); |
+ if (url != _documentURL) |
+ _touchedSinceLastURLChange = NO; |
Eugene But (OOO till 7-30)
2015/10/30 15:10:47
This is not the only place where _documentURL is c
stuartmorgan
2015/10/30 16:00:01
Originally I didn't do that because of the async c
|
// URL changes happen at three points: |
// 1) When a load starts; at this point, the load is provisional, and |
// it should be ignored until it's committed, since the document/window |