OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/web/web_state/ui/crw_wk_web_view_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_wk_web_view_web_controller.h" |
6 | 6 |
7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
8 | 8 |
9 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
10 #include "base/ios/weak_nsobject.h" | 10 #include "base/ios/weak_nsobject.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 // bad SSL cert, presenting SSL interstitials and determining SSL status for | 137 // bad SSL cert, presenting SSL interstitials and determining SSL status for |
138 // Navigation Items. | 138 // Navigation Items. |
139 base::scoped_nsobject<CRWCertVerificationController> | 139 base::scoped_nsobject<CRWCertVerificationController> |
140 _certVerificationController; | 140 _certVerificationController; |
141 | 141 |
142 // Whether the pending navigation has been directly cancelled in | 142 // Whether the pending navigation has been directly cancelled in |
143 // |decidePolicyForNavigationAction| or |decidePolicyForNavigationResponse|. | 143 // |decidePolicyForNavigationAction| or |decidePolicyForNavigationResponse|. |
144 // Cancelled navigations should be simply discarded without handling any | 144 // Cancelled navigations should be simply discarded without handling any |
145 // specific error. | 145 // specific error. |
146 BOOL _pendingNavigationCancelled; | 146 BOOL _pendingNavigationCancelled; |
147 | |
148 // YES if the user has touched the content area since the last URL change. | |
149 BOOL _touchedSinceLastURLChange; | |
147 } | 150 } |
148 | 151 |
149 // Response's MIME type of the last known navigation. | 152 // Response's MIME type of the last known navigation. |
150 @property(nonatomic, copy) NSString* documentMIMEType; | 153 @property(nonatomic, copy) NSString* documentMIMEType; |
151 | 154 |
152 // Dictionary where keys are the names of WKWebView properties and values are | 155 // Dictionary where keys are the names of WKWebView properties and values are |
153 // selector names which should be called when a corresponding property has | 156 // selector names which should be called when a corresponding property has |
154 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that | 157 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that |
155 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is | 158 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is |
156 // changed. | 159 // changed. |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 // TODO(eugenebut): implement dialogs/windows suppression using | 364 // TODO(eugenebut): implement dialogs/windows suppression using |
362 // WKNavigationDelegate methods where possible. | 365 // WKNavigationDelegate methods where possible. |
363 [super setPageDialogOpenPolicy:policy]; | 366 [super setPageDialogOpenPolicy:policy]; |
364 } | 367 } |
365 | 368 |
366 - (void)close { | 369 - (void)close { |
367 [_certVerificationController shutDown]; | 370 [_certVerificationController shutDown]; |
368 [super close]; | 371 [super close]; |
369 } | 372 } |
370 | 373 |
374 - (void)touched:(BOOL)touched { | |
375 [super touched:touched]; | |
376 if (touched) | |
377 _touchedSinceLastURLChange = YES; | |
378 } | |
379 | |
371 #pragma mark - | 380 #pragma mark - |
372 #pragma mark Testing-Only Methods | 381 #pragma mark Testing-Only Methods |
373 | 382 |
374 - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView { | 383 - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView { |
375 [super injectWebViewContentView:webViewContentView]; | 384 [super injectWebViewContentView:webViewContentView]; |
376 [self setWebView:static_cast<WKWebView*>(webViewContentView.webView)]; | 385 [self setWebView:static_cast<WKWebView*>(webViewContentView.webView)]; |
377 } | 386 } |
378 | 387 |
379 #pragma mark - Protected property implementations | 388 #pragma mark - Protected property implementations |
380 | 389 |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1007 } | 1016 } |
1008 | 1017 |
1009 if (!previousSSLStatus.Equals(item->GetSSL())) { | 1018 if (!previousSSLStatus.Equals(item->GetSSL())) { |
1010 [self didUpdateSSLStatusForCurrentNavigationItem]; | 1019 [self didUpdateSSLStatusForCurrentNavigationItem]; |
1011 } | 1020 } |
1012 } | 1021 } |
1013 | 1022 |
1014 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 1023 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
1015 | 1024 |
1016 - (void)registerLoadRequest:(const GURL&)url { | 1025 - (void)registerLoadRequest:(const GURL&)url { |
1017 // If load request is registered via WKWebViewWebController, assume transition | 1026 // Get the navigation type from the last main frame load request, and try to |
1018 // is link or client redirect as other transitions will already be registered | 1027 // map that to a PageTransition. |
1019 // by web controller or delegates. | 1028 WKNavigationType navigationType = _pendingNavigationTypeForMainFrame |
1020 // TODO(stuartmorgan): Remove guesswork and replace with information from | 1029 ? *_pendingNavigationTypeForMainFrame |
1021 // decidePolicyForNavigationAction:. | 1030 : WKNavigationTypeOther; |
1022 ui::PageTransition transition = self.userInteractionRegistered | 1031 ui::PageTransition transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
1023 ? ui::PAGE_TRANSITION_LINK | 1032 switch (navigationType) { |
1024 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; | 1033 case WKNavigationTypeLinkActivated: |
1034 transition = ui::PAGE_TRANSITION_LINK; | |
1035 break; | |
1036 case WKNavigationTypeFormSubmitted: | |
1037 case WKNavigationTypeFormResubmitted: | |
1038 transition = ui::PAGE_TRANSITION_FORM_SUBMIT; | |
1039 break; | |
1040 case WKNavigationTypeBackForward: | |
1041 transition = ui::PAGE_TRANSITION_FORWARD_BACK; | |
1042 break; | |
1043 case WKNavigationTypeReload: | |
1044 transition = ui::PAGE_TRANSITION_RELOAD; | |
1045 break; | |
1046 case WKNavigationTypeOther: | |
1047 // The "Other" type covers a variety of very different cases, which may | |
1048 // or may not be the result of user actions. For now, guess based on | |
1049 // whether there's been a touch since the last URL change. | |
1050 // TODO(crbug.com/549301): See if this heuristic can be improved. | |
1051 transition = _touchedSinceLastURLChange | |
1052 ? ui::PAGE_TRANSITION_LINK | |
1053 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; | |
1054 break; | |
1055 } | |
1025 // The referrer is not known yet, and will be updated later. | 1056 // The referrer is not known yet, and will be updated later. |
1026 const web::Referrer emptyReferrer; | 1057 const web::Referrer emptyReferrer; |
1027 [self registerLoadRequest:url referrer:emptyReferrer transition:transition]; | 1058 [self registerLoadRequest:url referrer:emptyReferrer transition:transition]; |
1028 } | 1059 } |
1029 | 1060 |
1030 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)newURL { | 1061 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)newURL { |
1031 DCHECK(newURL == net::GURLWithNSURL([_wkWebView URL])); | 1062 DCHECK(newURL == net::GURLWithNSURL([_wkWebView URL])); |
1032 DCHECK_EQ(_documentURL.host(), newURL.host()); | 1063 DCHECK_EQ(_documentURL.host(), newURL.host()); |
1033 _documentURL = newURL; | 1064 _documentURL = newURL; |
1034 // If called during window.history.pushState or window.history.replaceState | 1065 // If called during window.history.pushState or window.history.replaceState |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1219 } | 1250 } |
1220 | 1251 |
1221 - (void)webViewURLDidChange { | 1252 - (void)webViewURLDidChange { |
1222 // TODO(stuartmorgan): Determine if there are any cases where this still | 1253 // TODO(stuartmorgan): Determine if there are any cases where this still |
1223 // happens, and if so whether anything should be done when it does. | 1254 // happens, and if so whether anything should be done when it does. |
1224 if (![_wkWebView URL]) { | 1255 if (![_wkWebView URL]) { |
1225 DVLOG(1) << "Received nil URL callback"; | 1256 DVLOG(1) << "Received nil URL callback"; |
1226 return; | 1257 return; |
1227 } | 1258 } |
1228 GURL url(net::GURLWithNSURL([_wkWebView URL])); | 1259 GURL url(net::GURLWithNSURL([_wkWebView URL])); |
1260 if (url != _documentURL) | |
1261 _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
| |
1229 // URL changes happen at three points: | 1262 // URL changes happen at three points: |
1230 // 1) When a load starts; at this point, the load is provisional, and | 1263 // 1) When a load starts; at this point, the load is provisional, and |
1231 // it should be ignored until it's committed, since the document/window | 1264 // it should be ignored until it's committed, since the document/window |
1232 // objects haven't changed yet. | 1265 // objects haven't changed yet. |
1233 // 2) When a non-document-changing URL change happens (hash change, | 1266 // 2) When a non-document-changing URL change happens (hash change, |
1234 // history.pushState, etc.). This URL change happens instantly, so should | 1267 // history.pushState, etc.). This URL change happens instantly, so should |
1235 // be reported. | 1268 // be reported. |
1236 // 3) When a navigation error occurs after provisional navigation starts, | 1269 // 3) When a navigation error occurs after provisional navigation starts, |
1237 // the URL reverts to the previous URL without triggering a new navigation. | 1270 // the URL reverts to the previous URL without triggering a new navigation. |
1238 // | 1271 // |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1590 placeholderText:defaultText | 1623 placeholderText:defaultText |
1591 requestURL: | 1624 requestURL: |
1592 net::GURLWithNSURL(frame.request.URL) | 1625 net::GURLWithNSURL(frame.request.URL) |
1593 completionHandler:completionHandler]; | 1626 completionHandler:completionHandler]; |
1594 } else if (completionHandler) { | 1627 } else if (completionHandler) { |
1595 completionHandler(nil); | 1628 completionHandler(nil); |
1596 } | 1629 } |
1597 } | 1630 } |
1598 | 1631 |
1599 @end | 1632 @end |
OLD | NEW |