Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #import <objc/runtime.h> | 9 #import <objc/runtime.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1117 return _UIDelegate.get(); | 1117 return _UIDelegate.get(); |
| 1118 } | 1118 } |
| 1119 | 1119 |
| 1120 - (void)setUIDelegate:(id<CRWWebUserInterfaceDelegate>)UIDelegate { | 1120 - (void)setUIDelegate:(id<CRWWebUserInterfaceDelegate>)UIDelegate { |
| 1121 _UIDelegate.reset(UIDelegate); | 1121 _UIDelegate.reset(UIDelegate); |
| 1122 } | 1122 } |
| 1123 | 1123 |
| 1124 - (void)dealloc { | 1124 - (void)dealloc { |
| 1125 DCHECK([NSThread isMainThread]); | 1125 DCHECK([NSThread isMainThread]); |
| 1126 DCHECK(_isBeingDestroyed); // 'close' must have been called already. | 1126 DCHECK(_isBeingDestroyed); // 'close' must have been called already. |
| 1127 DCHECK(!self.webView); | 1127 DCHECK(!_webView); |
| 1128 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; | 1128 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; |
| 1129 [[_webViewProxy scrollViewProxy] removeObserver:self]; | 1129 [[_webViewProxy scrollViewProxy] removeObserver:self]; |
| 1130 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 1130 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 1131 [super dealloc]; | 1131 [super dealloc]; |
| 1132 } | 1132 } |
| 1133 | 1133 |
| 1134 - (BOOL)runUnloadListenerBeforeClosing { | 1134 - (BOOL)runUnloadListenerBeforeClosing { |
| 1135 // There's not much that can be done since there's limited access to WebKit. | 1135 // There's not much that can be done since there's limited access to WebKit. |
| 1136 // Always return that it's ok to close immediately. | 1136 // Always return that it's ok to close immediately. |
| 1137 return YES; | 1137 return YES; |
| 1138 } | 1138 } |
| 1139 | 1139 |
| 1140 - (void)dismissKeyboard { | 1140 - (void)dismissKeyboard { |
| 1141 [self.webView endEditing:YES]; | 1141 [_webView endEditing:YES]; |
| 1142 if ([self.nativeController respondsToSelector:@selector(dismissKeyboard)]) | 1142 if ([self.nativeController respondsToSelector:@selector(dismissKeyboard)]) |
| 1143 [self.nativeController dismissKeyboard]; | 1143 [self.nativeController dismissKeyboard]; |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 - (id<CRWNativeContent>)nativeController { | 1146 - (id<CRWNativeContent>)nativeController { |
| 1147 return [_containerView nativeController]; | 1147 return [_containerView nativeController]; |
| 1148 } | 1148 } |
| 1149 | 1149 |
| 1150 - (void)setNativeController:(id<CRWNativeContent>)nativeController { | 1150 - (void)setNativeController:(id<CRWNativeContent>)nativeController { |
| 1151 // Check for pointer equality. | 1151 // Check for pointer equality. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1231 | 1231 |
| 1232 - (void)handleLowMemory { | 1232 - (void)handleLowMemory { |
| 1233 [self removeWebViewAllowingCachedReconstruction:YES]; | 1233 [self removeWebViewAllowingCachedReconstruction:YES]; |
| 1234 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; | 1234 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; |
| 1235 _touchTrackingRecognizer.reset(); | 1235 _touchTrackingRecognizer.reset(); |
| 1236 [self resetContainerView]; | 1236 [self resetContainerView]; |
| 1237 _usePlaceholderOverlay = YES; | 1237 _usePlaceholderOverlay = YES; |
| 1238 } | 1238 } |
| 1239 | 1239 |
| 1240 - (void)reinitializeWebViewAndReload:(BOOL)reload { | 1240 - (void)reinitializeWebViewAndReload:(BOOL)reload { |
| 1241 if (self.webView) { | 1241 if (_webView) { |
| 1242 [self removeWebViewAllowingCachedReconstruction:NO]; | 1242 [self removeWebViewAllowingCachedReconstruction:NO]; |
| 1243 if (reload) { | 1243 if (reload) { |
| 1244 [self loadCurrentURLInWebView]; | 1244 [self loadCurrentURLInWebView]; |
| 1245 } else { | 1245 } else { |
| 1246 // Clear the space for the web view to lazy load when needed. | 1246 // Clear the space for the web view to lazy load when needed. |
| 1247 _usePlaceholderOverlay = YES; | 1247 _usePlaceholderOverlay = YES; |
| 1248 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; | 1248 _touchTrackingRecognizer.get().touchTrackingDelegate = nil; |
| 1249 _touchTrackingRecognizer.reset(); | 1249 _touchTrackingRecognizer.reset(); |
| 1250 [self resetContainerView]; | 1250 [self resetContainerView]; |
| 1251 } | 1251 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1306 _isBeingDestroyed = YES; | 1306 _isBeingDestroyed = YES; |
| 1307 | 1307 |
| 1308 // Remove the web view now. Otherwise, delegate callbacks occur. | 1308 // Remove the web view now. Otherwise, delegate callbacks occur. |
| 1309 [self removeWebViewAllowingCachedReconstruction:NO]; | 1309 [self removeWebViewAllowingCachedReconstruction:NO]; |
| 1310 | 1310 |
| 1311 _webStateImpl = nullptr; | 1311 _webStateImpl = nullptr; |
| 1312 } | 1312 } |
| 1313 | 1313 |
| 1314 - (void)checkLinkPresenceUnderGesture:(UIGestureRecognizer*)gestureRecognizer | 1314 - (void)checkLinkPresenceUnderGesture:(UIGestureRecognizer*)gestureRecognizer |
| 1315 completionHandler:(void (^)(BOOL))completionHandler { | 1315 completionHandler:(void (^)(BOOL))completionHandler { |
| 1316 CGPoint webViewPoint = [gestureRecognizer locationInView:self.webView]; | 1316 CGPoint webViewPoint = [gestureRecognizer locationInView:_webView]; |
| 1317 base::WeakNSObject<CRWWebController> weakSelf(self); | 1317 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 1318 [self | 1318 [self |
| 1319 fetchDOMElementAtPoint:webViewPoint | 1319 fetchDOMElementAtPoint:webViewPoint |
| 1320 completionHandler:^(std::unique_ptr<base::DictionaryValue> element) { | 1320 completionHandler:^(std::unique_ptr<base::DictionaryValue> element) { |
| 1321 std::string link; | 1321 std::string link; |
| 1322 BOOL hasLink = | 1322 BOOL hasLink = |
| 1323 element && element->GetString("href", &link) && link.size(); | 1323 element && element->GetString("href", &link) && link.size(); |
| 1324 completionHandler(hasLink); | 1324 completionHandler(hasLink); |
| 1325 }]; | 1325 }]; |
| 1326 } | 1326 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1337 | 1337 |
| 1338 // We don't want ongoing notification that the long press is held. | 1338 // We don't want ongoing notification that the long press is held. |
| 1339 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) | 1339 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) |
| 1340 return; | 1340 return; |
| 1341 | 1341 |
| 1342 if (!_DOMElementForLastTouch || _DOMElementForLastTouch->empty()) | 1342 if (!_DOMElementForLastTouch || _DOMElementForLastTouch->empty()) |
| 1343 return; | 1343 return; |
| 1344 | 1344 |
| 1345 NSDictionary* info = | 1345 NSDictionary* info = |
| 1346 [self contextMenuInfoForElement:_DOMElementForLastTouch.get()]; | 1346 [self contextMenuInfoForElement:_DOMElementForLastTouch.get()]; |
| 1347 CGPoint point = [gestureRecognizer locationInView:self.webView]; | 1347 CGPoint point = [gestureRecognizer locationInView:_webView]; |
| 1348 | 1348 |
| 1349 // Cancelling all touches has the intended side effect of suppressing the | 1349 // Cancelling all touches has the intended side effect of suppressing the |
| 1350 // system's context menu. | 1350 // system's context menu. |
| 1351 [self cancelAllTouches]; | 1351 [self cancelAllTouches]; |
| 1352 [self.UIDelegate webController:self | 1352 [self.UIDelegate webController:self |
| 1353 runContextMenu:info | 1353 runContextMenu:info |
| 1354 atPoint:point | 1354 atPoint:point |
| 1355 inView:self.webView]; | 1355 inView:_webView]; |
| 1356 } | 1356 } |
| 1357 | 1357 |
| 1358 - (BOOL)supportsCustomContextMenu { | 1358 - (BOOL)supportsCustomContextMenu { |
| 1359 SEL runMenuSelector = @selector(webController:runContextMenu:atPoint:inView:); | 1359 SEL runMenuSelector = @selector(webController:runContextMenu:atPoint:inView:); |
| 1360 return [self.UIDelegate respondsToSelector:runMenuSelector]; | 1360 return [self.UIDelegate respondsToSelector:runMenuSelector]; |
| 1361 } | 1361 } |
| 1362 | 1362 |
| 1363 - (void)cancelAllTouches { | 1363 - (void)cancelAllTouches { |
| 1364 // Disable web view scrolling. | 1364 // Disable web view scrolling. |
| 1365 CancelTouches(self.webScrollView.panGestureRecognizer); | 1365 CancelTouches(self.webScrollView.panGestureRecognizer); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1409 } | 1409 } |
| 1410 | 1410 |
| 1411 - (CGPoint)scrollPosition { | 1411 - (CGPoint)scrollPosition { |
| 1412 CGPoint position = CGPointMake(0.0, 0.0); | 1412 CGPoint position = CGPointMake(0.0, 0.0); |
| 1413 if (!self.webScrollView) | 1413 if (!self.webScrollView) |
| 1414 return position; | 1414 return position; |
| 1415 return self.webScrollView.contentOffset; | 1415 return self.webScrollView.contentOffset; |
| 1416 } | 1416 } |
| 1417 | 1417 |
| 1418 - (BOOL)atTop { | 1418 - (BOOL)atTop { |
| 1419 if (!self.webView) | 1419 if (!_webView) |
| 1420 return YES; | 1420 return YES; |
| 1421 UIScrollView* scrollView = self.webScrollView; | 1421 UIScrollView* scrollView = self.webScrollView; |
| 1422 return scrollView.contentOffset.y == -scrollView.contentInset.top; | 1422 return scrollView.contentOffset.y == -scrollView.contentInset.top; |
| 1423 } | 1423 } |
| 1424 | 1424 |
| 1425 - (void)setShouldSuppressDialogs:(BOOL)shouldSuppressDialogs { | 1425 - (void)setShouldSuppressDialogs:(BOOL)shouldSuppressDialogs { |
| 1426 _shouldSuppressDialogs = shouldSuppressDialogs; | 1426 _shouldSuppressDialogs = shouldSuppressDialogs; |
| 1427 if (self.webView) { | 1427 if (_webView) { |
| 1428 NSString* const kSetSuppressDialogs = [NSString | 1428 NSString* const kSetSuppressDialogs = [NSString |
| 1429 stringWithFormat:@"__gCrWeb.setSuppressGeolocationDialogs(%d);", | 1429 stringWithFormat:@"__gCrWeb.setSuppressGeolocationDialogs(%d);", |
| 1430 shouldSuppressDialogs]; | 1430 shouldSuppressDialogs]; |
| 1431 [self evaluateJavaScript:kSetSuppressDialogs stringResultHandler:nil]; | 1431 [self evaluateJavaScript:kSetSuppressDialogs stringResultHandler:nil]; |
| 1432 } else { | 1432 } else { |
| 1433 _shouldSuppressDialogsOnWindowIDInjection = shouldSuppressDialogs; | 1433 _shouldSuppressDialogsOnWindowIDInjection = shouldSuppressDialogs; |
| 1434 } | 1434 } |
| 1435 } | 1435 } |
| 1436 | 1436 |
| 1437 - (GURL)currentURLWithTrustLevel:(web::URLVerificationTrustLevel*)trustLevel { | 1437 - (GURL)currentURLWithTrustLevel:(web::URLVerificationTrustLevel*)trustLevel { |
| 1438 DCHECK(trustLevel) << "Verification of the trustLevel state is mandatory"; | 1438 DCHECK(trustLevel) << "Verification of the trustLevel state is mandatory"; |
| 1439 if (self.webView) { | 1439 if (_webView) { |
| 1440 GURL url([self webURLWithTrustLevel:trustLevel]); | 1440 GURL url([self webURLWithTrustLevel:trustLevel]); |
| 1441 // Web views treat all about: URLs as the same origin, which makes it | 1441 // Web views treat all about: URLs as the same origin, which makes it |
| 1442 // possible for pages to document.write into about:<foo> pages, where <foo> | 1442 // possible for pages to document.write into about:<foo> pages, where <foo> |
| 1443 // can be something misleading. Report any about: URL as about:blank to | 1443 // can be something misleading. Report any about: URL as about:blank to |
| 1444 // prevent that. See crbug.com/326118 | 1444 // prevent that. See crbug.com/326118 |
| 1445 if (url.scheme() == url::kAboutScheme) | 1445 if (url.scheme() == url::kAboutScheme) |
| 1446 return GURL(url::kAboutBlankURL); | 1446 return GURL(url::kAboutBlankURL); |
| 1447 return url; | 1447 return url; |
| 1448 } | 1448 } |
| 1449 // Any non-web URL source is trusted. | 1449 // Any non-web URL source is trusted. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1548 case WKNavigationTypeOther: | 1548 case WKNavigationTypeOther: |
| 1549 return [self userClickedRecently]; | 1549 return [self userClickedRecently]; |
| 1550 default: | 1550 default: |
| 1551 return NO; | 1551 return NO; |
| 1552 } | 1552 } |
| 1553 } | 1553 } |
| 1554 | 1554 |
| 1555 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item { | 1555 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item { |
| 1556 // The current back-forward list item MUST be in the WKWebView's back-forward | 1556 // The current back-forward list item MUST be in the WKWebView's back-forward |
| 1557 // list to be valid. | 1557 // list to be valid. |
| 1558 WKBackForwardList* list = [self.webView backForwardList]; | 1558 WKBackForwardList* list = [_webView backForwardList]; |
| 1559 return list.currentItem == item || | 1559 return list.currentItem == item || |
| 1560 [list.forwardList indexOfObject:item] != NSNotFound || | 1560 [list.forwardList indexOfObject:item] != NSNotFound || |
| 1561 [list.backList indexOfObject:item] != NSNotFound; | 1561 [list.backList indexOfObject:item] != NSNotFound; |
| 1562 } | 1562 } |
| 1563 | 1563 |
| 1564 - (GURL)URLForHistoryNavigationFromItem:(web::NavigationItem*)fromItem | 1564 - (GURL)URLForHistoryNavigationFromItem:(web::NavigationItem*)fromItem |
| 1565 toItem:(web::NavigationItem*)toItem { | 1565 toItem:(web::NavigationItem*)toItem { |
| 1566 // If navigating with native API, i.e. using a back forward list item, | 1566 // If navigating with native API, i.e. using a back forward list item, |
| 1567 // hashchange events will be triggered automatically, so no URL tampering is | 1567 // hashchange events will be triggered automatically, so no URL tampering is |
| 1568 // required. | 1568 // required. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1651 return _containerView; | 1651 return _containerView; |
| 1652 } | 1652 } |
| 1653 | 1653 |
| 1654 - (id<CRWWebViewProxy>)webViewProxy { | 1654 - (id<CRWWebViewProxy>)webViewProxy { |
| 1655 return _webViewProxy.get(); | 1655 return _webViewProxy.get(); |
| 1656 } | 1656 } |
| 1657 | 1657 |
| 1658 - (UIView*)viewForPrinting { | 1658 - (UIView*)viewForPrinting { |
| 1659 // TODO(ios): crbug.com/227944. Printing is not supported for native | 1659 // TODO(ios): crbug.com/227944. Printing is not supported for native |
| 1660 // controllers. | 1660 // controllers. |
| 1661 return self.webView; | 1661 return _webView; |
| 1662 } | 1662 } |
| 1663 | 1663 |
| 1664 - (void)registerLoadRequest:(const GURL&)URL { | 1664 - (void)registerLoadRequest:(const GURL&)URL { |
| 1665 // Get the navigation type from the last main frame load request, and try to | 1665 // Get the navigation type from the last main frame load request, and try to |
| 1666 // map that to a PageTransition. | 1666 // map that to a PageTransition. |
| 1667 WKNavigationType navigationType = | 1667 WKNavigationType navigationType = |
| 1668 _pendingNavigationInfo ? [_pendingNavigationInfo navigationType] | 1668 _pendingNavigationInfo ? [_pendingNavigationInfo navigationType] |
| 1669 : WKNavigationTypeOther; | 1669 : WKNavigationTypeOther; |
| 1670 ui::PageTransition transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; | 1670 ui::PageTransition transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
| 1671 switch (navigationType) { | 1671 switch (navigationType) { |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1878 // page, and should not be associated. | 1878 // page, and should not be associated. |
| 1879 if (_webUIManager) | 1879 if (_webUIManager) |
| 1880 return; | 1880 return; |
| 1881 | 1881 |
| 1882 web::WKBackForwardListItemHolder* holder = | 1882 web::WKBackForwardListItemHolder* holder = |
| 1883 [self currentBackForwardListItemHolder]; | 1883 [self currentBackForwardListItemHolder]; |
| 1884 | 1884 |
| 1885 WKNavigationType navigationType = | 1885 WKNavigationType navigationType = |
| 1886 _pendingNavigationInfo ? [_pendingNavigationInfo navigationType] | 1886 _pendingNavigationInfo ? [_pendingNavigationInfo navigationType] |
| 1887 : WKNavigationTypeOther; | 1887 : WKNavigationTypeOther; |
| 1888 holder->set_back_forward_list_item( | 1888 holder->set_back_forward_list_item([_webView backForwardList].currentItem); |
| 1889 [self.webView backForwardList].currentItem); | |
| 1890 holder->set_navigation_type(navigationType); | 1889 holder->set_navigation_type(navigationType); |
| 1891 | 1890 |
| 1892 // Only update the MIME type in the holder if there was MIME type information | 1891 // Only update the MIME type in the holder if there was MIME type information |
| 1893 // as part of this pending load. It will be nil when doing a fast | 1892 // as part of this pending load. It will be nil when doing a fast |
| 1894 // back/forward navigation, for instance, because the callback that would | 1893 // back/forward navigation, for instance, because the callback that would |
| 1895 // populate it is not called in that flow. | 1894 // populate it is not called in that flow. |
| 1896 if ([_pendingNavigationInfo MIMEType]) | 1895 if ([_pendingNavigationInfo MIMEType]) |
| 1897 holder->set_mime_type([_pendingNavigationInfo MIMEType]); | 1896 holder->set_mime_type([_pendingNavigationInfo MIMEType]); |
| 1898 } | 1897 } |
| 1899 | 1898 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2098 } | 2097 } |
| 2099 | 2098 |
| 2100 // Display overlay view until current url has finished loading or delay and | 2099 // Display overlay view until current url has finished loading or delay and |
| 2101 // then transition away. | 2100 // then transition away. |
| 2102 if ((_overlayPreviewMode || _usePlaceholderOverlay) && !isChromeScheme) | 2101 if ((_overlayPreviewMode || _usePlaceholderOverlay) && !isChromeScheme) |
| 2103 [self addPlaceholderOverlay]; | 2102 [self addPlaceholderOverlay]; |
| 2104 | 2103 |
| 2105 // Don't reset the overlay flag if in preview mode. | 2104 // Don't reset the overlay flag if in preview mode. |
| 2106 if (!_overlayPreviewMode) | 2105 if (!_overlayPreviewMode) |
| 2107 _usePlaceholderOverlay = NO; | 2106 _usePlaceholderOverlay = NO; |
| 2108 } else if (_requireReloadOnDisplay && self.webView) { | 2107 } else if (_requireReloadOnDisplay && _webView) { |
| 2109 _requireReloadOnDisplay = NO; | 2108 _requireReloadOnDisplay = NO; |
| 2110 [self addPlaceholderOverlay]; | 2109 [self addPlaceholderOverlay]; |
| 2111 [self loadCurrentURL]; | 2110 [self loadCurrentURL]; |
| 2112 } | 2111 } |
| 2113 } | 2112 } |
| 2114 | 2113 |
| 2115 - (BOOL)shouldReload:(const GURL&)destinationURL | 2114 - (BOOL)shouldReload:(const GURL&)destinationURL |
| 2116 transition:(ui::PageTransition)transition { | 2115 transition:(ui::PageTransition)transition { |
| 2117 // Do a reload if the user hits enter in the address bar or re-types a URL. | 2116 // Do a reload if the user hits enter in the address bar or re-types a URL. |
| 2118 CRWSessionController* sessionController = | 2117 CRWSessionController* sessionController = |
| 2119 _webStateImpl->GetNavigationManagerImpl().GetSessionController(); | 2118 _webStateImpl->GetNavigationManagerImpl().GetSessionController(); |
| 2120 web::NavigationItem* item = | 2119 web::NavigationItem* item = |
| 2121 _webStateImpl->GetNavigationManagerImpl().GetVisibleItem(); | 2120 _webStateImpl->GetNavigationManagerImpl().GetVisibleItem(); |
| 2122 return (transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) && item && | 2121 return (transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) && item && |
| 2123 (destinationURL == item->GetURL() || | 2122 (destinationURL == item->GetURL() || |
| 2124 destinationURL == [sessionController currentEntry].originalUrl); | 2123 destinationURL == [sessionController currentEntry].originalUrl); |
| 2125 } | 2124 } |
| 2126 | 2125 |
| 2127 // Reload either the web view or the native content depending on which is | 2126 // Reload either the web view or the native content depending on which is |
| 2128 // displayed. | 2127 // displayed. |
| 2129 - (void)reloadInternal { | 2128 - (void)reloadInternal { |
| 2130 // Clear last user interaction. | 2129 // Clear last user interaction. |
| 2131 // TODO(crbug.com/546337): Move to after the load commits, in the subclass | 2130 // TODO(crbug.com/546337): Move to after the load commits, in the subclass |
| 2132 // implementation. This will be inaccurate if the reload fails or is | 2131 // implementation. This will be inaccurate if the reload fails or is |
| 2133 // cancelled. | 2132 // cancelled. |
| 2134 _lastUserInteraction.reset(); | 2133 _lastUserInteraction.reset(); |
| 2135 web::RecordAction(UserMetricsAction("Reload")); | 2134 web::RecordAction(UserMetricsAction("Reload")); |
| 2136 if (self.webView) { | 2135 if (_webView) { |
| 2137 web::NavigationItem* transientItem = | 2136 web::NavigationItem* transientItem = |
| 2138 _webStateImpl->GetNavigationManagerImpl().GetTransientItem(); | 2137 _webStateImpl->GetNavigationManagerImpl().GetTransientItem(); |
| 2139 if (transientItem) { | 2138 if (transientItem) { |
| 2140 // If there's a transient item, a reload is considered a new navigation to | 2139 // If there's a transient item, a reload is considered a new navigation to |
| 2141 // the transient item's URL (as on other platforms). | 2140 // the transient item's URL (as on other platforms). |
| 2142 NavigationManager::WebLoadParams reloadParams(transientItem->GetURL()); | 2141 NavigationManager::WebLoadParams reloadParams(transientItem->GetURL()); |
| 2143 reloadParams.transition_type = ui::PAGE_TRANSITION_RELOAD; | 2142 reloadParams.transition_type = ui::PAGE_TRANSITION_RELOAD; |
| 2144 reloadParams.extra_headers.reset( | 2143 reloadParams.extra_headers.reset( |
| 2145 [transientItem->GetHttpRequestHeaders() copy]); | 2144 [transientItem->GetHttpRequestHeaders() copy]); |
| 2146 [self loadWithParams:reloadParams]; | 2145 [self loadWithParams:reloadParams]; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2201 break; | 2200 break; |
| 2202 case web::PAGE_LOADED: | 2201 case web::PAGE_LOADED: |
| 2203 break; | 2202 break; |
| 2204 } | 2203 } |
| 2205 } | 2204 } |
| 2206 | 2205 |
| 2207 - (void)prepareForGoBack { | 2206 - (void)prepareForGoBack { |
| 2208 // Make sure any transitions that may have occurred have been seen and acted | 2207 // Make sure any transitions that may have occurred have been seen and acted |
| 2209 // on by the CRWWebController, so the history stack and state of the | 2208 // on by the CRWWebController, so the history stack and state of the |
| 2210 // CRWWebController is 100% up to date before the stack navigation starts. | 2209 // CRWWebController is 100% up to date before the stack navigation starts. |
| 2211 if (self.webView) { | 2210 if (_webView) { |
| 2212 [self injectWindowID]; | 2211 [self injectWindowID]; |
| 2213 } | 2212 } |
| 2214 | 2213 |
| 2215 bool wasShowingInterstitial = _webStateImpl->IsShowingWebInterstitial(); | 2214 bool wasShowingInterstitial = _webStateImpl->IsShowingWebInterstitial(); |
| 2216 | 2215 |
| 2217 // Before changing the current session history entry, record the tab state. | 2216 // Before changing the current session history entry, record the tab state. |
| 2218 if (!wasShowingInterstitial) { | 2217 if (!wasShowingInterstitial) { |
| 2219 [self recordStateInHistory]; | 2218 [self recordStateInHistory]; |
| 2220 } | 2219 } |
| 2221 } | 2220 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2271 [self loadCompleteWithSuccess:YES]; | 2270 [self loadCompleteWithSuccess:YES]; |
| 2272 } | 2271 } |
| 2273 | 2272 |
| 2274 - (void)loadCompleteWithSuccess:(BOOL)loadSuccess { | 2273 - (void)loadCompleteWithSuccess:(BOOL)loadSuccess { |
| 2275 [self removePlaceholderOverlay]; | 2274 [self removePlaceholderOverlay]; |
| 2276 // The webView may have been torn down (or replaced by a native view). Be | 2275 // The webView may have been torn down (or replaced by a native view). Be |
| 2277 // safe and do nothing if that's happened. | 2276 // safe and do nothing if that's happened. |
| 2278 if (_loadPhase != web::PAGE_LOADING) | 2277 if (_loadPhase != web::PAGE_LOADING) |
| 2279 return; | 2278 return; |
| 2280 | 2279 |
| 2281 DCHECK(self.webView); | 2280 DCHECK(_webView); |
| 2282 | 2281 |
| 2283 const GURL currentURL([self currentURL]); | 2282 const GURL currentURL([self currentURL]); |
| 2284 | 2283 |
| 2285 _loadPhase = web::PAGE_LOADED; | 2284 _loadPhase = web::PAGE_LOADED; |
| 2286 | 2285 |
| 2287 [self optOutScrollsToTopForSubviews]; | 2286 [self optOutScrollsToTopForSubviews]; |
| 2288 | 2287 |
| 2289 // Ensure the URL is as expected (and already reported to the delegate). | 2288 // Ensure the URL is as expected (and already reported to the delegate). |
| 2290 DCHECK(currentURL == _lastRegisteredRequestURL) | 2289 DCHECK(currentURL == _lastRegisteredRequestURL) |
| 2291 << std::endl | 2290 << std::endl |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2371 base::JSONReader::Read(base::SysNSStringToUTF8(stringResult))); | 2370 base::JSONReader::Read(base::SysNSStringToUTF8(stringResult))); |
| 2372 handler(std::move(result), error); | 2371 handler(std::move(result), error); |
| 2373 } | 2372 } |
| 2374 }]; | 2373 }]; |
| 2375 } | 2374 } |
| 2376 | 2375 |
| 2377 - (void)addGestureRecognizerToWebView:(UIGestureRecognizer*)recognizer { | 2376 - (void)addGestureRecognizerToWebView:(UIGestureRecognizer*)recognizer { |
| 2378 if ([_gestureRecognizers containsObject:recognizer]) | 2377 if ([_gestureRecognizers containsObject:recognizer]) |
| 2379 return; | 2378 return; |
| 2380 | 2379 |
| 2381 [self.webView addGestureRecognizer:recognizer]; | 2380 [_webView addGestureRecognizer:recognizer]; |
| 2382 [_gestureRecognizers addObject:recognizer]; | 2381 [_gestureRecognizers addObject:recognizer]; |
| 2383 } | 2382 } |
| 2384 | 2383 |
| 2385 - (void)removeGestureRecognizerFromWebView:(UIGestureRecognizer*)recognizer { | 2384 - (void)removeGestureRecognizerFromWebView:(UIGestureRecognizer*)recognizer { |
| 2386 if (![_gestureRecognizers containsObject:recognizer]) | 2385 if (![_gestureRecognizers containsObject:recognizer]) |
| 2387 return; | 2386 return; |
| 2388 | 2387 |
| 2389 [self.webView removeGestureRecognizer:recognizer]; | 2388 [_webView removeGestureRecognizer:recognizer]; |
| 2390 [_gestureRecognizers removeObject:recognizer]; | 2389 [_gestureRecognizers removeObject:recognizer]; |
| 2391 } | 2390 } |
| 2392 | 2391 |
| 2393 - (void)addToolbarViewToWebView:(UIView*)toolbarView { | 2392 - (void)addToolbarViewToWebView:(UIView*)toolbarView { |
| 2394 DCHECK(toolbarView); | 2393 DCHECK(toolbarView); |
| 2395 if ([_webViewToolbars containsObject:toolbarView]) | 2394 if ([_webViewToolbars containsObject:toolbarView]) |
| 2396 return; | 2395 return; |
| 2397 [_webViewToolbars addObject:toolbarView]; | 2396 [_webViewToolbars addObject:toolbarView]; |
| 2398 if (self.webView) | 2397 if (_webView) |
| 2399 [_containerView addToolbar:toolbarView]; | 2398 [_containerView addToolbar:toolbarView]; |
| 2400 } | 2399 } |
| 2401 | 2400 |
| 2402 - (void)removeToolbarViewFromWebView:(UIView*)toolbarView { | 2401 - (void)removeToolbarViewFromWebView:(UIView*)toolbarView { |
| 2403 if (![_webViewToolbars containsObject:toolbarView]) | 2402 if (![_webViewToolbars containsObject:toolbarView]) |
| 2404 return; | 2403 return; |
| 2405 [_webViewToolbars removeObject:toolbarView]; | 2404 [_webViewToolbars removeObject:toolbarView]; |
| 2406 if (self.webView) | 2405 if (_webView) |
| 2407 [_containerView removeToolbar:toolbarView]; | 2406 [_containerView removeToolbar:toolbarView]; |
| 2408 } | 2407 } |
| 2409 | 2408 |
| 2410 - (CRWJSInjectionReceiver*)jsInjectionReceiver { | 2409 - (CRWJSInjectionReceiver*)jsInjectionReceiver { |
| 2411 return _jsInjectionReceiver; | 2410 return _jsInjectionReceiver; |
| 2412 } | 2411 } |
| 2413 | 2412 |
| 2414 - (BOOL)shouldClosePageOnNativeApplicationLoad { | 2413 - (BOOL)shouldClosePageOnNativeApplicationLoad { |
| 2415 // The page should be closed if it was initiated by the DOM and there has been | 2414 // The page should be closed if it was initiated by the DOM and there has been |
| 2416 // no user interaction with the page since the web view was created, or if | 2415 // no user interaction with the page since the web view was created, or if |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2467 (CRWWebControllerContainerView*)containerView { | 2466 (CRWWebControllerContainerView*)containerView { |
| 2468 return [self headerHeight]; | 2467 return [self headerHeight]; |
| 2469 } | 2468 } |
| 2470 | 2469 |
| 2471 #pragma mark - | 2470 #pragma mark - |
| 2472 #pragma mark CRWJSInjectionEvaluator Methods | 2471 #pragma mark CRWJSInjectionEvaluator Methods |
| 2473 | 2472 |
| 2474 - (void)evaluateJavaScript:(NSString*)script | 2473 - (void)evaluateJavaScript:(NSString*)script |
| 2475 stringResultHandler:(web::JavaScriptCompletion)handler { | 2474 stringResultHandler:(web::JavaScriptCompletion)handler { |
| 2476 NSString* safeScript = [self scriptByAddingWindowIDCheckForScript:script]; | 2475 NSString* safeScript = [self scriptByAddingWindowIDCheckForScript:script]; |
| 2477 web::EvaluateJavaScript(self.webView, safeScript, handler); | 2476 web::EvaluateJavaScript(_webView, safeScript, handler); |
| 2478 } | 2477 } |
| 2479 | 2478 |
| 2480 - (void)executeJavaScript:(NSString*)script | 2479 - (void)executeJavaScript:(NSString*)script |
| 2481 completionHandler:(web::JavaScriptResultBlock)completionHandler { | 2480 completionHandler:(web::JavaScriptResultBlock)completionHandler { |
| 2482 NSString* safeScript = [self scriptByAddingWindowIDCheckForScript:script]; | 2481 NSString* safeScript = [self scriptByAddingWindowIDCheckForScript:script]; |
| 2483 web::ExecuteJavaScript(self.webView, safeScript, completionHandler); | 2482 web::ExecuteJavaScript(_webView, safeScript, completionHandler); |
| 2484 } | 2483 } |
| 2485 | 2484 |
| 2486 - (BOOL)scriptHasBeenInjectedForClass:(Class)JSInjectionManagerClass | 2485 - (BOOL)scriptHasBeenInjectedForClass:(Class)JSInjectionManagerClass |
| 2487 presenceBeacon:(NSString*)beacon { | 2486 presenceBeacon:(NSString*)beacon { |
| 2488 return [_injectedScriptManagers containsObject:JSInjectionManagerClass]; | 2487 return [_injectedScriptManagers containsObject:JSInjectionManagerClass]; |
| 2489 } | 2488 } |
| 2490 | 2489 |
| 2491 - (void)injectScript:(NSString*)script forClass:(Class)JSInjectionManagerClass { | 2490 - (void)injectScript:(NSString*)script forClass:(Class)JSInjectionManagerClass { |
| 2492 // Skip evaluation if there's no content (e.g., if what's being injected is | 2491 // Skip evaluation if there's no content (e.g., if what's being injected is |
| 2493 // an umbrella manager). | 2492 // an umbrella manager). |
| 2494 if ([script length]) { | 2493 if ([script length]) { |
| 2495 // Every injection except windowID requires windowID check. | 2494 // Every injection except windowID requires windowID check. |
| 2496 if (JSInjectionManagerClass != [CRWJSWindowIdManager class]) | 2495 if (JSInjectionManagerClass != [CRWJSWindowIdManager class]) |
| 2497 script = [self scriptByAddingWindowIDCheckForScript:script]; | 2496 script = [self scriptByAddingWindowIDCheckForScript:script]; |
| 2498 web::ExecuteJavaScript(self.webView, script, nil); | 2497 web::ExecuteJavaScript(_webView, script, nil); |
| 2499 } | 2498 } |
| 2500 [_injectedScriptManagers addObject:JSInjectionManagerClass]; | 2499 [_injectedScriptManagers addObject:JSInjectionManagerClass]; |
| 2501 } | 2500 } |
| 2502 | 2501 |
| 2503 #pragma mark - | 2502 #pragma mark - |
| 2504 | 2503 |
| 2505 - (void)evaluateUserJavaScript:(NSString*)script { | 2504 - (void)evaluateUserJavaScript:(NSString*)script { |
| 2506 [self setUserInteractionRegistered:YES]; | 2505 [self setUserInteractionRegistered:YES]; |
| 2507 web::ExecuteJavaScript(self.webView, script, nil); | 2506 web::ExecuteJavaScript(_webView, script, nil); |
| 2508 } | 2507 } |
| 2509 | 2508 |
| 2510 - (BOOL)respondToMessage:(base::DictionaryValue*)message | 2509 - (BOOL)respondToMessage:(base::DictionaryValue*)message |
| 2511 userIsInteracting:(BOOL)userIsInteracting | 2510 userIsInteracting:(BOOL)userIsInteracting |
| 2512 originURL:(const GURL&)originURL { | 2511 originURL:(const GURL&)originURL { |
| 2513 std::string command; | 2512 std::string command; |
| 2514 if (!message->GetString("command", &command)) { | 2513 if (!message->GetString("command", &command)) { |
| 2515 DLOG(WARNING) << "JS message parameter not found: command"; | 2514 DLOG(WARNING) << "JS message parameter not found: command"; |
| 2516 return NO; | 2515 return NO; |
| 2517 } | 2516 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2630 return NO; | 2629 return NO; |
| 2631 } | 2630 } |
| 2632 base::DictionaryValue* command = nullptr; | 2631 base::DictionaryValue* command = nullptr; |
| 2633 if (!message->GetDictionary("crwCommand", &command)) { | 2632 if (!message->GetDictionary("crwCommand", &command)) { |
| 2634 return NO; | 2633 return NO; |
| 2635 } | 2634 } |
| 2636 if ([scriptMessage.name isEqualToString:kScriptImmediateName] || | 2635 if ([scriptMessage.name isEqualToString:kScriptImmediateName] || |
| 2637 [scriptMessage.name isEqualToString:kScriptMessageName]) { | 2636 [scriptMessage.name isEqualToString:kScriptMessageName]) { |
| 2638 return [self respondToMessage:command | 2637 return [self respondToMessage:command |
| 2639 userIsInteracting:[self userIsInteracting] | 2638 userIsInteracting:[self userIsInteracting] |
| 2640 originURL:net::GURLWithNSURL([self.webView URL])]; | 2639 originURL:net::GURLWithNSURL([_webView URL])]; |
| 2641 } | 2640 } |
| 2642 | 2641 |
| 2643 NOTREACHED(); | 2642 NOTREACHED(); |
| 2644 return NO; | 2643 return NO; |
| 2645 } | 2644 } |
| 2646 | 2645 |
| 2647 #pragma mark - | 2646 #pragma mark - |
| 2648 #pragma mark JavaScript message handlers | 2647 #pragma mark JavaScript message handlers |
| 2649 | 2648 |
| 2650 - (BOOL)handleAddPluginPlaceholdersMessage:(base::DictionaryValue*)message | 2649 - (BOOL)handleAddPluginPlaceholdersMessage:(base::DictionaryValue*)message |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3289 if ([self shouldClosePageOnNativeApplicationLoad]) | 3288 if ([self shouldClosePageOnNativeApplicationLoad]) |
| 3290 [_delegate webPageOrderedClose]; | 3289 [_delegate webPageOrderedClose]; |
| 3291 [self stopLoading]; | 3290 [self stopLoading]; |
| 3292 [_openedApplicationURL addObject:request.URL]; | 3291 [_openedApplicationURL addObject:request.URL]; |
| 3293 return NO; | 3292 return NO; |
| 3294 } | 3293 } |
| 3295 | 3294 |
| 3296 // The WebDelegate may instruct the CRWWebController to stop loading, and | 3295 // The WebDelegate may instruct the CRWWebController to stop loading, and |
| 3297 // instead instruct the next page to be loaded in an animation. | 3296 // instead instruct the next page to be loaded in an animation. |
| 3298 GURL mainDocumentURL = net::GURLWithNSURL(request.mainDocumentURL); | 3297 GURL mainDocumentURL = net::GURLWithNSURL(request.mainDocumentURL); |
| 3299 DCHECK(self.webView); | 3298 DCHECK(_webView); |
| 3300 if (![self shouldOpenURL:requestURL | 3299 if (![self shouldOpenURL:requestURL |
| 3301 mainDocumentURL:mainDocumentURL | 3300 mainDocumentURL:mainDocumentURL |
| 3302 linkClicked:isLinkClick]) { | 3301 linkClicked:isLinkClick]) { |
| 3303 return NO; | 3302 return NO; |
| 3304 } | 3303 } |
| 3305 | 3304 |
| 3306 // If the URL doesn't look like one we can show, try to open the link with an | 3305 // If the URL doesn't look like one we can show, try to open the link with an |
| 3307 // external application. | 3306 // external application. |
| 3308 // TODO(droger): Check transition type before opening an external | 3307 // TODO(droger): Check transition type before opening an external |
| 3309 // application? For example, only allow it for TYPED and LINK transitions. | 3308 // application? For example, only allow it for TYPED and LINK transitions. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3495 } | 3494 } |
| 3496 | 3495 |
| 3497 // This is custom long press gesture recognizer. By the time the gesture is | 3496 // This is custom long press gesture recognizer. By the time the gesture is |
| 3498 // recognized the web controller needs to know if there is a link under the | 3497 // recognized the web controller needs to know if there is a link under the |
| 3499 // touch. If there a link, the web controller will reject system's context | 3498 // touch. If there a link, the web controller will reject system's context |
| 3500 // menu and show another one. If for some reason context menu info is not | 3499 // menu and show another one. If for some reason context menu info is not |
| 3501 // fetched - system context menu will be shown. | 3500 // fetched - system context menu will be shown. |
| 3502 [self setDOMElementForLastTouch:nullptr]; | 3501 [self setDOMElementForLastTouch:nullptr]; |
| 3503 base::WeakNSObject<CRWWebController> weakSelf(self); | 3502 base::WeakNSObject<CRWWebController> weakSelf(self); |
| 3504 [self | 3503 [self |
| 3505 fetchDOMElementAtPoint:[touch locationInView:self.webView] | 3504 fetchDOMElementAtPoint:[touch locationInView:_webView] |
| 3506 completionHandler:^(std::unique_ptr<base::DictionaryValue> element) { | 3505 completionHandler:^(std::unique_ptr<base::DictionaryValue> element) { |
| 3507 [weakSelf setDOMElementForLastTouch:std::move(element)]; | 3506 [weakSelf setDOMElementForLastTouch:std::move(element)]; |
| 3508 }]; | 3507 }]; |
| 3509 return YES; | 3508 return YES; |
| 3510 } | 3509 } |
| 3511 | 3510 |
| 3512 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { | 3511 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { |
| 3513 // Expect only _contextMenuRecognizer. | 3512 // Expect only _contextMenuRecognizer. |
| 3514 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); | 3513 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); |
| 3515 if (!self.webView || ![self supportsCustomContextMenu]) { | 3514 if (!_webView || ![self supportsCustomContextMenu]) { |
| 3516 // Show the context menu iff currently displaying a web view. | 3515 // Show the context menu iff currently displaying a web view. |
| 3517 // Do nothing for native views. | 3516 // Do nothing for native views. |
| 3518 return NO; | 3517 return NO; |
| 3519 } | 3518 } |
| 3520 | 3519 |
| 3521 // Fetching is considered as successful even if |_DOMElementForLastTouch| is | 3520 // Fetching is considered as successful even if |_DOMElementForLastTouch| is |
| 3522 // empty. However if |_DOMElementForLastTouch| is empty then custom context | 3521 // empty. However if |_DOMElementForLastTouch| is empty then custom context |
| 3523 // menu should not be shown. | 3522 // menu should not be shown. |
| 3524 UMA_HISTOGRAM_BOOLEAN("WebController.FetchContextMenuInfoAsyncSucceeded", | 3523 UMA_HISTOGRAM_BOOLEAN("WebController.FetchContextMenuInfoAsyncSucceeded", |
| 3525 !!_DOMElementForLastTouch); | 3524 !!_DOMElementForLastTouch); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3850 if (!_overlayPreviewMode && _placeholderOverlayView) { | 3849 if (!_overlayPreviewMode && _placeholderOverlayView) { |
| 3851 [self resetContainerView]; | 3850 [self resetContainerView]; |
| 3852 // Reset |_placeholderOverlayView| directly instead of calling | 3851 // Reset |_placeholderOverlayView| directly instead of calling |
| 3853 // -removePlaceholderOverlay, which removes |_placeholderOverlayView| in an | 3852 // -removePlaceholderOverlay, which removes |_placeholderOverlayView| in an |
| 3854 // animation. | 3853 // animation. |
| 3855 [_placeholderOverlayView removeFromSuperview]; | 3854 [_placeholderOverlayView removeFromSuperview]; |
| 3856 _placeholderOverlayView.reset(); | 3855 _placeholderOverlayView.reset(); |
| 3857 // There are cases when resetting the contentView, above, may happen after | 3856 // There are cases when resetting the contentView, above, may happen after |
| 3858 // the web view has been created. Re-add it here, rather than | 3857 // the web view has been created. Re-add it here, rather than |
| 3859 // relying on a subsequent call to loadCurrentURLInWebView. | 3858 // relying on a subsequent call to loadCurrentURLInWebView. |
| 3860 if (self.webView) { | 3859 if (_webView) { |
| 3861 [[self view] addSubview:self.webView]; | 3860 [[self view] addSubview:_webView]; |
| 3862 } | 3861 } |
| 3863 } | 3862 } |
| 3864 } | 3863 } |
| 3865 | 3864 |
| 3866 #pragma mark - | 3865 #pragma mark - |
| 3867 #pragma mark Session Information | 3866 #pragma mark Session Information |
| 3868 | 3867 |
| 3869 - (CRWSessionController*)sessionController { | 3868 - (CRWSessionController*)sessionController { |
| 3870 return _webStateImpl | 3869 return _webStateImpl |
| 3871 ? _webStateImpl->GetNavigationManagerImpl().GetSessionController() | 3870 ? _webStateImpl->GetNavigationManagerImpl().GetSessionController() |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3987 } | 3986 } |
| 3988 | 3987 |
| 3989 - (void)restoreStateFromHistory { | 3988 - (void)restoreStateFromHistory { |
| 3990 CRWSessionEntry* current = [self currentSessionEntry]; | 3989 CRWSessionEntry* current = [self currentSessionEntry]; |
| 3991 if ([current navigationItem]) | 3990 if ([current navigationItem]) |
| 3992 self.pageDisplayState = [current navigationItem]->GetPageDisplayState(); | 3991 self.pageDisplayState = [current navigationItem]->GetPageDisplayState(); |
| 3993 } | 3992 } |
| 3994 | 3993 |
| 3995 - (web::PageDisplayState)pageDisplayState { | 3994 - (web::PageDisplayState)pageDisplayState { |
| 3996 web::PageDisplayState displayState; | 3995 web::PageDisplayState displayState; |
| 3997 if (self.webView) { | 3996 if (_webView) { |
| 3998 CGPoint scrollOffset = [self scrollPosition]; | 3997 CGPoint scrollOffset = [self scrollPosition]; |
| 3999 displayState.scroll_state().set_offset_x(std::floor(scrollOffset.x)); | 3998 displayState.scroll_state().set_offset_x(std::floor(scrollOffset.x)); |
| 4000 displayState.scroll_state().set_offset_y(std::floor(scrollOffset.y)); | 3999 displayState.scroll_state().set_offset_y(std::floor(scrollOffset.y)); |
| 4001 UIScrollView* scrollView = self.webScrollView; | 4000 UIScrollView* scrollView = self.webScrollView; |
| 4002 displayState.zoom_state().set_minimum_zoom_scale( | 4001 displayState.zoom_state().set_minimum_zoom_scale( |
| 4003 scrollView.minimumZoomScale); | 4002 scrollView.minimumZoomScale); |
| 4004 displayState.zoom_state().set_maximum_zoom_scale( | 4003 displayState.zoom_state().set_maximum_zoom_scale( |
| 4005 scrollView.maximumZoomScale); | 4004 scrollView.maximumZoomScale); |
| 4006 displayState.zoom_state().set_zoom_scale(scrollView.zoomScale); | 4005 displayState.zoom_state().set_zoom_scale(scrollView.zoomScale); |
| 4007 } else { | 4006 } else { |
| 4008 // TODO(crbug.com/546146): Handle native views. | 4007 // TODO(crbug.com/546146): Handle native views. |
| 4009 } | 4008 } |
| 4010 return displayState; | 4009 return displayState; |
| 4011 } | 4010 } |
| 4012 | 4011 |
| 4013 - (void)setPageDisplayState:(web::PageDisplayState)displayState { | 4012 - (void)setPageDisplayState:(web::PageDisplayState)displayState { |
| 4014 if (!displayState.IsValid()) | 4013 if (!displayState.IsValid()) |
| 4015 return; | 4014 return; |
| 4016 if (self.webView) { | 4015 if (_webView) { |
| 4017 // Page state is restored after a page load completes. If the user has | 4016 // Page state is restored after a page load completes. If the user has |
| 4018 // scrolled or changed the zoom scale while the page is still loading, don't | 4017 // scrolled or changed the zoom scale while the page is still loading, don't |
| 4019 // restore any state since it will confuse the user. | 4018 // restore any state since it will confuse the user. |
| 4020 web::PageDisplayState currentPageDisplayState = self.pageDisplayState; | 4019 web::PageDisplayState currentPageDisplayState = self.pageDisplayState; |
| 4021 if (currentPageDisplayState.scroll_state().offset_x() == | 4020 if (currentPageDisplayState.scroll_state().offset_x() == |
| 4022 _displayStateOnStartLoading.scroll_state().offset_x() && | 4021 _displayStateOnStartLoading.scroll_state().offset_x() && |
| 4023 currentPageDisplayState.scroll_state().offset_y() == | 4022 currentPageDisplayState.scroll_state().offset_y() == |
| 4024 _displayStateOnStartLoading.scroll_state().offset_y() && | 4023 _displayStateOnStartLoading.scroll_state().offset_y() && |
| 4025 !_pageHasZoomed) { | 4024 !_pageHasZoomed) { |
| 4026 [self applyPageDisplayState:displayState]; | 4025 [self applyPageDisplayState:displayState]; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 4054 | 4053 |
| 4055 - (void)orientationDidChange { | 4054 - (void)orientationDidChange { |
| 4056 // When rotating, the available zoom scale range may change, zoomScale's | 4055 // When rotating, the available zoom scale range may change, zoomScale's |
| 4057 // percentage into this range should remain constant. However, there are | 4056 // percentage into this range should remain constant. However, there are |
| 4058 // two known bugs with respect to adjusting the zoomScale on rotation: | 4057 // two known bugs with respect to adjusting the zoomScale on rotation: |
| 4059 // - WKWebView sometimes erroneously resets the scroll view's zoom scale to | 4058 // - WKWebView sometimes erroneously resets the scroll view's zoom scale to |
| 4060 // an incorrect value ( rdar://20100815 ). | 4059 // an incorrect value ( rdar://20100815 ). |
| 4061 // - After zooming occurs in a UIWebView that's displaying a page with a hard- | 4060 // - After zooming occurs in a UIWebView that's displaying a page with a hard- |
| 4062 // coded viewport width, the zoom will not be updated upon rotation | 4061 // coded viewport width, the zoom will not be updated upon rotation |
| 4063 // ( crbug.com/485055 ). | 4062 // ( crbug.com/485055 ). |
| 4064 if (!self.webView) | 4063 if (!_webView) |
| 4065 return; | 4064 return; |
| 4066 web::NavigationItem* currentItem = self.currentNavItem; | 4065 web::NavigationItem* currentItem = self.currentNavItem; |
| 4067 if (!currentItem) | 4066 if (!currentItem) |
| 4068 return; | 4067 return; |
| 4069 web::PageDisplayState displayState = currentItem->GetPageDisplayState(); | 4068 web::PageDisplayState displayState = currentItem->GetPageDisplayState(); |
| 4070 if (!displayState.IsValid()) | 4069 if (!displayState.IsValid()) |
| 4071 return; | 4070 return; |
| 4072 CGFloat zoomPercentage = (displayState.zoom_state().zoom_scale() - | 4071 CGFloat zoomPercentage = (displayState.zoom_state().zoom_scale() - |
| 4073 displayState.zoom_state().minimum_zoom_scale()) / | 4072 displayState.zoom_state().minimum_zoom_scale()) / |
| 4074 displayState.zoom_state().GetMinMaxZoomDifference(); | 4073 displayState.zoom_state().GetMinMaxZoomDifference(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4110 if (isUserScalable) { | 4109 if (isUserScalable) { |
| 4111 [self prepareToApplyWebViewScrollZoomScale]; | 4110 [self prepareToApplyWebViewScrollZoomScale]; |
| 4112 [self applyWebViewScrollZoomScaleFromZoomState:displayState.zoom_state()]; | 4111 [self applyWebViewScrollZoomScaleFromZoomState:displayState.zoom_state()]; |
| 4113 [self finishApplyingWebViewScrollZoomScale]; | 4112 [self finishApplyingWebViewScrollZoomScale]; |
| 4114 } | 4113 } |
| 4115 [self applyWebViewScrollOffsetFromScrollState:displayState.scroll_state()]; | 4114 [self applyWebViewScrollOffsetFromScrollState:displayState.scroll_state()]; |
| 4116 _applyingPageState = NO; | 4115 _applyingPageState = NO; |
| 4117 } | 4116 } |
| 4118 | 4117 |
| 4119 - (void)prepareToApplyWebViewScrollZoomScale { | 4118 - (void)prepareToApplyWebViewScrollZoomScale { |
| 4120 id webView = self.webView; | 4119 id webView = _webView; |
| 4121 if (![webView respondsToSelector:@selector(viewForZoomingInScrollView:)]) { | 4120 if (![webView respondsToSelector:@selector(viewForZoomingInScrollView:)]) { |
| 4122 return; | 4121 return; |
| 4123 } | 4122 } |
| 4124 | 4123 |
| 4125 UIView* contentView = [webView viewForZoomingInScrollView:self.webScrollView]; | 4124 UIView* contentView = [webView viewForZoomingInScrollView:self.webScrollView]; |
| 4126 | 4125 |
| 4127 if ([webView | 4126 if ([webView |
| 4128 respondsToSelector:@selector(scrollViewWillBeginZooming:withView:)]) { | 4127 respondsToSelector:@selector(scrollViewWillBeginZooming:withView:)]) { |
| 4129 [webView scrollViewWillBeginZooming:self.webScrollView | 4128 [webView scrollViewWillBeginZooming:self.webScrollView |
| 4130 withView:contentView]; | 4129 withView:contentView]; |
| 4131 } | 4130 } |
| 4132 } | 4131 } |
| 4133 | 4132 |
| 4134 - (void)finishApplyingWebViewScrollZoomScale { | 4133 - (void)finishApplyingWebViewScrollZoomScale { |
| 4135 id webView = self.webView; | 4134 id webView = _webView; |
| 4136 if ([webView respondsToSelector:@selector(scrollViewDidEndZooming: | 4135 if ([webView respondsToSelector:@selector(scrollViewDidEndZooming: |
| 4137 withView: | 4136 withView: |
| 4138 atScale:)] && | 4137 atScale:)] && |
| 4139 [webView respondsToSelector:@selector(viewForZoomingInScrollView:)]) { | 4138 [webView respondsToSelector:@selector(viewForZoomingInScrollView:)]) { |
| 4140 // This correctly sets the content's frame in the scroll view to | 4139 // This correctly sets the content's frame in the scroll view to |
| 4141 // fit the web page and upscales the content so that it isn't | 4140 // fit the web page and upscales the content so that it isn't |
| 4142 // blurry. | 4141 // blurry. |
| 4143 UIView* contentView = | 4142 UIView* contentView = |
| 4144 [webView viewForZoomingInScrollView:self.webScrollView]; | 4143 [webView viewForZoomingInScrollView:self.webScrollView]; |
| 4145 [webView scrollViewDidEndZooming:self.webScrollView | 4144 [webView scrollViewDidEndZooming:self.webScrollView |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4180 [weakScrollView setContentOffset:scrollOffset]; | 4179 [weakScrollView setContentOffset:scrollOffset]; |
| 4181 } copy]); | 4180 } copy]); |
| 4182 [_pendingLoadCompleteActions addObject:action]; | 4181 [_pendingLoadCompleteActions addObject:action]; |
| 4183 } | 4182 } |
| 4184 } | 4183 } |
| 4185 | 4184 |
| 4186 #pragma mark - | 4185 #pragma mark - |
| 4187 #pragma mark Web Page Features | 4186 #pragma mark Web Page Features |
| 4188 | 4187 |
| 4189 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler { | 4188 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler { |
| 4190 if (!self.webView) { | 4189 if (!_webView) { |
| 4191 handler(0); | 4190 handler(0); |
| 4192 return; | 4191 return; |
| 4193 } | 4192 } |
| 4194 | 4193 |
| 4195 [self evaluateJavaScript:@"__gCrWeb.getPageWidth();" | 4194 [self evaluateJavaScript:@"__gCrWeb.getPageWidth();" |
| 4196 stringResultHandler:^(NSString* pageWidthAsString, NSError*) { | 4195 stringResultHandler:^(NSString* pageWidthAsString, NSError*) { |
| 4197 handler([pageWidthAsString floatValue]); | 4196 handler([pageWidthAsString floatValue]); |
| 4198 }]; | 4197 }]; |
| 4199 } | 4198 } |
| 4200 | 4199 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4436 } | 4435 } |
| 4437 | 4436 |
| 4438 if (!_SSLStatusUpdater) { | 4437 if (!_SSLStatusUpdater) { |
| 4439 _SSLStatusUpdater.reset([[CRWSSLStatusUpdater alloc] | 4438 _SSLStatusUpdater.reset([[CRWSSLStatusUpdater alloc] |
| 4440 initWithDataSource:self | 4439 initWithDataSource:self |
| 4441 navigationManager:navManager | 4440 navigationManager:navManager |
| 4442 certGroupID:self.certGroupID]); | 4441 certGroupID:self.certGroupID]); |
| 4443 [_SSLStatusUpdater setDelegate:self]; | 4442 [_SSLStatusUpdater setDelegate:self]; |
| 4444 } | 4443 } |
| 4445 NSString* host = base::SysUTF8ToNSString(_documentURL.host()); | 4444 NSString* host = base::SysUTF8ToNSString(_documentURL.host()); |
| 4446 NSArray* certChain = [self.webView certificateChain]; | 4445 NSArray* certChain = [_webView certificateChain]; |
| 4447 BOOL hasOnlySecureContent = [self.webView hasOnlySecureContent]; | 4446 BOOL hasOnlySecureContent = [_webView hasOnlySecureContent]; |
| 4448 [_SSLStatusUpdater updateSSLStatusForNavigationItem:currentNavItem | 4447 [_SSLStatusUpdater updateSSLStatusForNavigationItem:currentNavItem |
| 4449 withCertHost:host | 4448 withCertHost:host |
| 4450 certChain:certChain | 4449 certChain:certChain |
| 4451 hasOnlySecureContent:hasOnlySecureContent]; | 4450 hasOnlySecureContent:hasOnlySecureContent]; |
| 4452 } | 4451 } |
| 4453 | 4452 |
| 4454 - (void)didUpdateSSLStatusForCurrentNavigationItem { | 4453 - (void)didUpdateSSLStatusForCurrentNavigationItem { |
| 4455 if ([_delegate respondsToSelector: | 4454 if ([_delegate respondsToSelector: |
| 4456 @selector( | 4455 @selector( |
| 4457 webControllerDidUpdateSSLStatusForCurrentNavigationItem:)]) { | 4456 webControllerDidUpdateSSLStatusForCurrentNavigationItem:)]) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4545 [self ensureWebViewCreatedWithConfiguration:config]; | 4544 [self ensureWebViewCreatedWithConfiguration:config]; |
| 4546 } | 4545 } |
| 4547 | 4546 |
| 4548 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config { | 4547 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config { |
| 4549 if (!_webView) { | 4548 if (!_webView) { |
| 4550 [self setWebView:[self createWebViewWithConfiguration:config]]; | 4549 [self setWebView:[self createWebViewWithConfiguration:config]]; |
| 4551 // The following is not called in -setWebView: as the latter used in unit | 4550 // The following is not called in -setWebView: as the latter used in unit |
| 4552 // tests with fake web view, which cannot be added to view hierarchy. | 4551 // tests with fake web view, which cannot be added to view hierarchy. |
| 4553 CHECK(_webUsageEnabled) << "Tried to create a web view while suspended!"; | 4552 CHECK(_webUsageEnabled) << "Tried to create a web view while suspended!"; |
| 4554 | 4553 |
| 4555 UIView* webView = self.webView; | 4554 DCHECK(_webView); |
| 4556 DCHECK(webView); | |
| 4557 | 4555 |
| 4558 [webView setTag:kWebViewTag]; | 4556 [_webView setTag:kWebViewTag]; |
| 4559 [webView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 4557 [_webView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
| 4560 UIViewAutoresizingFlexibleHeight]; | 4558 UIViewAutoresizingFlexibleHeight]; |
| 4561 [webView setBackgroundColor:[UIColor colorWithWhite:0.2 alpha:1.0]]; | 4559 [_webView setBackgroundColor:[UIColor colorWithWhite:0.2 alpha:1.0]]; |
| 4562 | 4560 |
| 4563 // Create a dependency between the |webView| pan gesture and BVC side swipe | 4561 // Create a dependency between the |webView| pan gesture and BVC side swipe |
| 4564 // gestures. Note: This needs to be added before the longPress recognizers | 4562 // gestures. Note: This needs to be added before the longPress recognizers |
| 4565 // below, or the longPress appears to deadlock the remaining recognizers, | 4563 // below, or the longPress appears to deadlock the remaining recognizers, |
| 4566 // thereby breaking scroll. | 4564 // thereby breaking scroll. |
| 4567 NSSet* recognizers = [_swipeRecognizerProvider swipeRecognizers]; | 4565 NSSet* recognizers = [_swipeRecognizerProvider swipeRecognizers]; |
| 4568 for (UISwipeGestureRecognizer* swipeRecognizer in recognizers) { | 4566 for (UISwipeGestureRecognizer* swipeRecognizer in recognizers) { |
| 4569 [self.webScrollView.panGestureRecognizer | 4567 [self.webScrollView.panGestureRecognizer |
| 4570 requireGestureRecognizerToFail:swipeRecognizer]; | 4568 requireGestureRecognizerToFail:swipeRecognizer]; |
| 4571 } | 4569 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 4583 // detection duration a little lower than that (see | 4581 // detection duration a little lower than that (see |
| 4584 // kLongPressDurationSeconds). It also points the delegate to this class | 4582 // kLongPressDurationSeconds). It also points the delegate to this class |
| 4585 // that | 4583 // that |
| 4586 // allows simultaneously operate along with the other recognizers. | 4584 // allows simultaneously operate along with the other recognizers. |
| 4587 _contextMenuRecognizer.reset([[UILongPressGestureRecognizer alloc] | 4585 _contextMenuRecognizer.reset([[UILongPressGestureRecognizer alloc] |
| 4588 initWithTarget:self | 4586 initWithTarget:self |
| 4589 action:@selector(showContextMenu:)]); | 4587 action:@selector(showContextMenu:)]); |
| 4590 [_contextMenuRecognizer setMinimumPressDuration:kLongPressDurationSeconds]; | 4588 [_contextMenuRecognizer setMinimumPressDuration:kLongPressDurationSeconds]; |
| 4591 [_contextMenuRecognizer setAllowableMovement:kLongPressMoveDeltaPixels]; | 4589 [_contextMenuRecognizer setAllowableMovement:kLongPressMoveDeltaPixels]; |
| 4592 [_contextMenuRecognizer setDelegate:self]; | 4590 [_contextMenuRecognizer setDelegate:self]; |
| 4593 [webView addGestureRecognizer:_contextMenuRecognizer]; | 4591 [_webView addGestureRecognizer:_contextMenuRecognizer]; |
| 4594 // Certain system gesture handlers are known to conflict with our context | 4592 // Certain system gesture handlers are known to conflict with our context |
| 4595 // menu handler, causing extra events to fire when the context menu is | 4593 // menu handler, causing extra events to fire when the context menu is |
| 4596 // active. | 4594 // active. |
| 4597 | 4595 |
| 4598 // A number of solutions have been investigated. The lowest-risk solution | 4596 // A number of solutions have been investigated. The lowest-risk solution |
| 4599 // appears to be to recurse through the web controller's recognizers, | 4597 // appears to be to recurse through the web controller's recognizers, |
| 4600 // looking | 4598 // looking |
| 4601 // for fingerprints of the recognizers known to cause problems, which are | 4599 // for fingerprints of the recognizers known to cause problems, which are |
| 4602 // then | 4600 // then |
| 4603 // de-prioritized (below our own long click handler). | 4601 // de-prioritized (below our own long click handler). |
| 4604 // Hunting for description fragments of system recognizers is undeniably | 4602 // Hunting for description fragments of system recognizers is undeniably |
| 4605 // brittle for future versions of iOS. If it does break the context menu | 4603 // brittle for future versions of iOS. If it does break the context menu |
| 4606 // events may leak (regressing b/5310177), but the app will otherwise work. | 4604 // events may leak (regressing b/5310177), but the app will otherwise work. |
| 4607 [CRWWebController requireGestureRecognizerToFail:_contextMenuRecognizer | 4605 [CRWWebController requireGestureRecognizerToFail:_contextMenuRecognizer |
| 4608 inView:webView | 4606 inView:_webView |
| 4609 containingDescription: | 4607 containingDescription: |
| 4610 @"action=_highlightLongPressRecognized:"]; | 4608 @"action=_highlightLongPressRecognized:"]; |
| 4611 | 4609 |
| 4612 // Add all additional gesture recognizers to the web view. | 4610 // Add all additional gesture recognizers to the web view. |
| 4613 for (UIGestureRecognizer* recognizer in _gestureRecognizers.get()) { | 4611 for (UIGestureRecognizer* recognizer in _gestureRecognizers.get()) { |
| 4614 [webView addGestureRecognizer:recognizer]; | 4612 [_webView addGestureRecognizer:recognizer]; |
| 4615 } | 4613 } |
| 4616 | 4614 |
| 4617 _URLOnStartLoading = _defaultURL; | 4615 _URLOnStartLoading = _defaultURL; |
| 4618 | 4616 |
| 4619 // Add the web toolbars. | 4617 // Add the web toolbars. |
| 4620 [_containerView addToolbars:_webViewToolbars]; | 4618 [_containerView addToolbars:_webViewToolbars]; |
| 4621 | 4619 |
| 4622 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( | 4620 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( |
| 4623 [[CRWWebViewContentView alloc] initWithWebView:self.webView | 4621 [[CRWWebViewContentView alloc] initWithWebView:_webView |
| 4624 scrollView:self.webScrollView]); | 4622 scrollView:self.webScrollView]); |
| 4625 [_containerView displayWebViewContentView:webViewContentView]; | 4623 [_containerView displayWebViewContentView:webViewContentView]; |
| 4626 } | 4624 } |
| 4627 } | 4625 } |
| 4628 | 4626 |
| 4629 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config { | 4627 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config { |
| 4630 return [web::CreateWKWebView(CGRectZero, config, | 4628 return [web::CreateWKWebView(CGRectZero, config, |
| 4631 self.webStateImpl->GetBrowserState(), | 4629 self.webStateImpl->GetBrowserState(), |
| 4632 [self useDesktopUserAgent]) autorelease]; | 4630 [self useDesktopUserAgent]) autorelease]; |
| 4633 } | 4631 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4668 [_webView setNavigationDelegate:self]; | 4666 [_webView setNavigationDelegate:self]; |
| 4669 [_webView setUIDelegate:self]; | 4667 [_webView setUIDelegate:self]; |
| 4670 for (NSString* keyPath in self.WKWebViewObservers) { | 4668 for (NSString* keyPath in self.WKWebViewObservers) { |
| 4671 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; | 4669 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; |
| 4672 } | 4670 } |
| 4673 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); | 4671 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); |
| 4674 [self setDocumentURL:_defaultURL]; | 4672 [self setDocumentURL:_defaultURL]; |
| 4675 } | 4673 } |
| 4676 | 4674 |
| 4677 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { | 4675 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { |
| 4678 if (!self.webView) | 4676 if (!_webView) |
| 4679 return; | 4677 return; |
| 4680 | 4678 |
| 4681 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); | 4679 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); |
| 4682 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) | 4680 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) |
| 4683 [self.UIDelegate cancelDialogsForWebController:self]; | 4681 [self.UIDelegate cancelDialogsForWebController:self]; |
| 4684 | 4682 |
| 4685 if (allowCache) | 4683 if (allowCache) |
| 4686 _expectedReconstructionURL = [self currentNavigationURL]; | 4684 _expectedReconstructionURL = [self currentNavigationURL]; |
| 4687 else | 4685 else |
| 4688 _expectedReconstructionURL = GURL(); | 4686 _expectedReconstructionURL = GURL(); |
| 4689 | 4687 |
| 4690 [self abortLoad]; | 4688 [self abortLoad]; |
| 4691 [self.webView removeFromSuperview]; | 4689 [_webView removeFromSuperview]; |
| 4692 [_containerView resetContent]; | 4690 [_containerView resetContent]; |
| 4693 [self setWebView:nil]; | 4691 [self setWebView:nil]; |
| 4694 } | 4692 } |
| 4695 | 4693 |
| 4696 - (void)webViewWebProcessDidCrash { | 4694 - (void)webViewWebProcessDidCrash { |
| 4697 _webProcessIsDead = YES; | 4695 _webProcessIsDead = YES; |
| 4698 | 4696 |
| 4699 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); | 4697 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); |
| 4700 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) | 4698 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) |
| 4701 [self.UIDelegate cancelDialogsForWebController:self]; | 4699 [self.UIDelegate cancelDialogsForWebController:self]; |
| 4702 | 4700 |
| 4703 SEL rendererCrashSelector = @selector(webControllerWebProcessDidCrash:); | 4701 SEL rendererCrashSelector = @selector(webControllerWebProcessDidCrash:); |
| 4704 if ([self.delegate respondsToSelector:rendererCrashSelector]) | 4702 if ([self.delegate respondsToSelector:rendererCrashSelector]) |
| 4705 [self.delegate webControllerWebProcessDidCrash:self]; | 4703 [self.delegate webControllerWebProcessDidCrash:self]; |
| 4706 } | 4704 } |
| 4707 | 4705 |
| 4708 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider { | 4706 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider { |
| 4709 web::BrowserState* browserState = self.webStateImpl->GetBrowserState(); | 4707 web::BrowserState* browserState = self.webStateImpl->GetBrowserState(); |
| 4710 return web::WKWebViewConfigurationProvider::FromBrowserState(browserState); | 4708 return web::WKWebViewConfigurationProvider::FromBrowserState(browserState); |
| 4711 } | 4709 } |
| 4712 | 4710 |
| 4713 - (web::WebViewDocumentType)webViewDocumentType { | 4711 - (web::WebViewDocumentType)webViewDocumentType { |
| 4714 // This happens during tests. | 4712 // This happens during tests. |
| 4715 if (!self.webView) { | 4713 if (!_webView) { |
| 4716 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 4714 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
| 4717 } | 4715 } |
| 4718 | 4716 |
| 4719 std::string MIMEType = self.webState->GetContentsMimeType(); | 4717 std::string MIMEType = self.webState->GetContentsMimeType(); |
| 4720 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)]; | 4718 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)]; |
| 4721 } | 4719 } |
| 4722 | 4720 |
| 4723 - (void)loadRequest:(NSMutableURLRequest*)request { | 4721 - (void)loadRequest:(NSMutableURLRequest*)request { |
| 4724 _latestWKNavigation.reset([[self.webView loadRequest:request] retain]); | 4722 _latestWKNavigation.reset([[_webView loadRequest:request] retain]); |
| 4725 } | 4723 } |
| 4726 | 4724 |
| 4727 - (void)loadPOSTRequest:(NSMutableURLRequest*)request { | 4725 - (void)loadPOSTRequest:(NSMutableURLRequest*)request { |
| 4728 if (!_POSTRequestLoader) { | 4726 if (!_POSTRequestLoader) { |
| 4729 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]); | 4727 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]); |
| 4730 } | 4728 } |
| 4731 | 4729 |
| 4732 CRWWKScriptMessageRouter* messageRouter = | 4730 CRWWKScriptMessageRouter* messageRouter = |
| 4733 [self webViewConfigurationProvider].GetScriptMessageRouter(); | 4731 [self webViewConfigurationProvider].GetScriptMessageRouter(); |
| 4734 | 4732 |
| 4735 [_POSTRequestLoader loadPOSTRequest:request | 4733 [_POSTRequestLoader loadPOSTRequest:request |
| 4736 inWebView:_webView | 4734 inWebView:_webView |
| 4737 messageRouter:messageRouter | 4735 messageRouter:messageRouter |
| 4738 completionHandler:^(NSError* loadError) { | 4736 completionHandler:^(NSError* loadError) { |
| 4739 if (loadError) | 4737 if (loadError) |
| 4740 [self handleLoadError:loadError inMainFrame:YES]; | 4738 [self handleLoadError:loadError inMainFrame:YES]; |
| 4741 else | 4739 else |
| 4742 self.webStateImpl->SetContentsMimeType("text/html"); | 4740 self.webStateImpl->SetContentsMimeType("text/html"); |
| 4743 }]; | 4741 }]; |
| 4744 } | 4742 } |
| 4745 | 4743 |
| 4746 - (void)loadHTML:(NSString*)HTML forURL:(const GURL&)URL { | 4744 - (void)loadHTML:(NSString*)HTML forURL:(const GURL&)URL { |
| 4747 // Remove the transient content view. | 4745 // Remove the transient content view. |
| 4748 [self clearTransientContentView]; | 4746 [self clearTransientContentView]; |
| 4749 | 4747 |
| 4750 DLOG_IF(WARNING, !self.webView) | 4748 DLOG_IF(WARNING, !_webView) << "_webView null while trying to load HTML"; |
| 4751 << "self.webView null while trying to load HTML"; | |
| 4752 _loadPhase = web::LOAD_REQUESTED; | 4749 _loadPhase = web::LOAD_REQUESTED; |
| 4753 [self.webView loadHTMLString:HTML baseURL:net::NSURLWithGURL(URL)]; | 4750 [_webView loadHTMLString:HTML baseURL:net::NSURLWithGURL(URL)]; |
| 4754 } | 4751 } |
| 4755 | 4752 |
| 4756 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { | 4753 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { |
| 4757 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); | 4754 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); |
| 4758 [self loadHTML:HTML forURL:URL]; | 4755 [self loadHTML:HTML forURL:URL]; |
| 4759 } | 4756 } |
| 4760 | 4757 |
| 4761 - (void)loadHTMLForCurrentURL:(NSString*)HTML { | 4758 - (void)loadHTMLForCurrentURL:(NSString*)HTML { |
| 4762 [self loadHTML:HTML forURL:self.currentURL]; | 4759 [self loadHTML:HTML forURL:self.currentURL]; |
| 4763 } | 4760 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4805 } | 4802 } |
| 4806 | 4803 |
| 4807 CRWWebController* child = [self createChildWebController]; | 4804 CRWWebController* child = [self createChildWebController]; |
| 4808 // WKWebView requires WKUIDelegate to return a child view created with | 4805 // WKWebView requires WKUIDelegate to return a child view created with |
| 4809 // exactly the same |configuration| object (exception is raised if config is | 4806 // exactly the same |configuration| object (exception is raised if config is |
| 4810 // different). |configuration| param and config returned by | 4807 // different). |configuration| param and config returned by |
| 4811 // WKWebViewConfigurationProvider are different objects because WKWebView | 4808 // WKWebViewConfigurationProvider are different objects because WKWebView |
| 4812 // makes a shallow copy of the config inside init, so every WKWebView | 4809 // makes a shallow copy of the config inside init, so every WKWebView |
| 4813 // owns a separate shallow copy of WKWebViewConfiguration. | 4810 // owns a separate shallow copy of WKWebViewConfiguration. |
| 4814 [child ensureWebViewCreatedWithConfiguration:configuration]; | 4811 [child ensureWebViewCreatedWithConfiguration:configuration]; |
| 4815 return [child webView]; | 4812 return child.webView; |
|
Eugene But (OOO till 7-30)
2016/04/26 18:00:41
child->_webView could work, but I would keep webVi
| |
| 4816 } | 4813 } |
| 4817 | 4814 |
| 4818 - (void)webViewDidClose:(WKWebView*)webView { | 4815 - (void)webViewDidClose:(WKWebView*)webView { |
| 4819 if (self.sessionController.openedByDOM) { | 4816 if (self.sessionController.openedByDOM) { |
| 4820 [self.delegate webPageOrderedClose]; | 4817 [self.delegate webPageOrderedClose]; |
| 4821 } | 4818 } |
| 4822 } | 4819 } |
| 4823 | 4820 |
| 4824 - (void)webView:(WKWebView*)webView | 4821 - (void)webView:(WKWebView*)webView |
| 4825 runJavaScriptAlertPanelWithMessage:(NSString*)message | 4822 runJavaScriptAlertPanelWithMessage:(NSString*)message |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5069 } | 5066 } |
| 5070 | 5067 |
| 5071 // This must be reset at the end, since code above may need information about | 5068 // This must be reset at the end, since code above may need information about |
| 5072 // the pending load. | 5069 // the pending load. |
| 5073 _pendingNavigationInfo.reset(); | 5070 _pendingNavigationInfo.reset(); |
| 5074 _certVerificationErrors->Clear(); | 5071 _certVerificationErrors->Clear(); |
| 5075 } | 5072 } |
| 5076 | 5073 |
| 5077 - (void)webView:(WKWebView*)webView | 5074 - (void)webView:(WKWebView*)webView |
| 5078 didCommitNavigation:(WKNavigation*)navigation { | 5075 didCommitNavigation:(WKNavigation*)navigation { |
| 5079 DCHECK_EQ(self.webView, webView); | 5076 DCHECK_EQ(_webView, webView); |
| 5080 _certVerificationErrors->Clear(); | 5077 _certVerificationErrors->Clear(); |
| 5081 // This point should closely approximate the document object change, so reset | 5078 // This point should closely approximate the document object change, so reset |
| 5082 // the list of injected scripts to those that are automatically injected. | 5079 // the list of injected scripts to those that are automatically injected. |
| 5083 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); | 5080 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); |
| 5084 [self injectWindowID]; | 5081 [self injectWindowID]; |
| 5085 | 5082 |
| 5086 // This is the point where the document's URL has actually changed, and | 5083 // This is the point where the document's URL has actually changed, and |
| 5087 // pending navigation information should be applied to state information. | 5084 // pending navigation information should be applied to state information. |
| 5088 [self setDocumentURL:net::GURLWithNSURL([self.webView URL])]; | 5085 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; |
| 5089 DCHECK(_documentURL == _lastRegisteredRequestURL); | 5086 DCHECK(_documentURL == _lastRegisteredRequestURL); |
| 5090 self.webStateImpl->OnNavigationCommitted(_documentURL); | 5087 self.webStateImpl->OnNavigationCommitted(_documentURL); |
| 5091 [self commitPendingNavigationInfo]; | 5088 [self commitPendingNavigationInfo]; |
| 5092 if ([self currentBackForwardListItemHolder]->navigation_type() == | 5089 if ([self currentBackForwardListItemHolder]->navigation_type() == |
| 5093 WKNavigationTypeBackForward) { | 5090 WKNavigationTypeBackForward) { |
| 5094 // A fast back/forward won't call decidePolicyForNavigationResponse, so | 5091 // A fast back/forward won't call decidePolicyForNavigationResponse, so |
| 5095 // the MIME type needs to be updated explicitly. | 5092 // the MIME type needs to be updated explicitly. |
| 5096 NSString* storedMIMEType = | 5093 NSString* storedMIMEType = |
| 5097 [self currentBackForwardListItemHolder]->mime_type(); | 5094 [self currentBackForwardListItemHolder]->mime_type(); |
| 5098 if (storedMIMEType) { | 5095 if (storedMIMEType) { |
| 5099 self.webStateImpl->SetContentsMimeType( | 5096 self.webStateImpl->SetContentsMimeType( |
| 5100 base::SysNSStringToUTF8(storedMIMEType)); | 5097 base::SysNSStringToUTF8(storedMIMEType)); |
| 5101 } | 5098 } |
| 5102 } | 5099 } |
| 5103 [self webPageChanged]; | 5100 [self webPageChanged]; |
| 5104 | 5101 |
| 5105 [self updateSSLStatusForCurrentNavigationItem]; | 5102 [self updateSSLStatusForCurrentNavigationItem]; |
| 5106 | 5103 |
| 5107 // Report cases where SSL cert is missing for a secure connection. | 5104 // Report cases where SSL cert is missing for a secure connection. |
| 5108 if (_documentURL.SchemeIsCryptographic()) { | 5105 if (_documentURL.SchemeIsCryptographic()) { |
| 5109 scoped_refptr<net::X509Certificate> cert = | 5106 scoped_refptr<net::X509Certificate> cert = |
| 5110 web::CreateCertFromChain([self.webView certificateChain]); | 5107 web::CreateCertFromChain([_webView certificateChain]); |
| 5111 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", | 5108 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", |
| 5112 cert); | 5109 cert); |
| 5113 } | 5110 } |
| 5114 } | 5111 } |
| 5115 | 5112 |
| 5116 - (void)webView:(WKWebView*)webView | 5113 - (void)webView:(WKWebView*)webView |
| 5117 didFinishNavigation:(WKNavigation*)navigation { | 5114 didFinishNavigation:(WKNavigation*)navigation { |
| 5118 DCHECK(!_isHalted); | 5115 DCHECK(!_isHalted); |
| 5119 // Trigger JavaScript driven post-document-load-completion tasks. | 5116 // Trigger JavaScript driven post-document-load-completion tasks. |
| 5120 // TODO(crbug.com/546350): Investigate using | 5117 // TODO(crbug.com/546350): Investigate using |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5230 - (void)webViewSecurityFeaturesDidChange { | 5227 - (void)webViewSecurityFeaturesDidChange { |
| 5231 if (self.loadPhase == web::LOAD_REQUESTED) { | 5228 if (self.loadPhase == web::LOAD_REQUESTED) { |
| 5232 // Do not update SSL Status for pending load. It will be updated in | 5229 // Do not update SSL Status for pending load. It will be updated in |
| 5233 // |webView:didCommitNavigation:| callback. | 5230 // |webView:didCommitNavigation:| callback. |
| 5234 return; | 5231 return; |
| 5235 } | 5232 } |
| 5236 [self updateSSLStatusForCurrentNavigationItem]; | 5233 [self updateSSLStatusForCurrentNavigationItem]; |
| 5237 } | 5234 } |
| 5238 | 5235 |
| 5239 - (void)webViewLoadingStateDidChange { | 5236 - (void)webViewLoadingStateDidChange { |
| 5240 if ([self.webView isLoading]) { | 5237 if ([_webView isLoading]) { |
| 5241 [self addActivityIndicatorTask]; | 5238 [self addActivityIndicatorTask]; |
| 5242 } else { | 5239 } else { |
| 5243 [self clearActivityIndicatorTasks]; | 5240 [self clearActivityIndicatorTasks]; |
| 5244 if ([self currentNavItem] && | 5241 if ([self currentNavItem] && |
| 5245 [self currentBackForwardListItemHolder]->navigation_type() == | 5242 [self currentBackForwardListItemHolder]->navigation_type() == |
| 5246 WKNavigationTypeBackForward) { | 5243 WKNavigationTypeBackForward) { |
| 5247 // A fast back/forward may not call |webView:didFinishNavigation:|, so | 5244 // A fast back/forward may not call |webView:didFinishNavigation:|, so |
| 5248 // finishing the navigation should be signalled explicitly. | 5245 // finishing the navigation should be signalled explicitly. |
| 5249 [self didFinishNavigation]; | 5246 [self didFinishNavigation]; |
| 5250 } | 5247 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 5262 if ([self.delegate | 5259 if ([self.delegate |
| 5263 respondsToSelector:@selector(webController:titleDidChange:)]) { | 5260 respondsToSelector:@selector(webController:titleDidChange:)]) { |
| 5264 DCHECK([_webView title]); | 5261 DCHECK([_webView title]); |
| 5265 [self.delegate webController:self titleDidChange:[_webView title]]; | 5262 [self.delegate webController:self titleDidChange:[_webView title]]; |
| 5266 } | 5263 } |
| 5267 } | 5264 } |
| 5268 | 5265 |
| 5269 - (void)webViewURLDidChange { | 5266 - (void)webViewURLDidChange { |
| 5270 // TODO(stuartmorgan): Determine if there are any cases where this still | 5267 // TODO(stuartmorgan): Determine if there are any cases where this still |
| 5271 // happens, and if so whether anything should be done when it does. | 5268 // happens, and if so whether anything should be done when it does. |
| 5272 if (![self.webView URL]) { | 5269 if (![_webView URL]) { |
| 5273 DVLOG(1) << "Received nil URL callback"; | 5270 DVLOG(1) << "Received nil URL callback"; |
| 5274 return; | 5271 return; |
| 5275 } | 5272 } |
| 5276 GURL URL(net::GURLWithNSURL([self.webView URL])); | 5273 GURL URL(net::GURLWithNSURL([_webView URL])); |
| 5277 // URL changes happen at three points: | 5274 // URL changes happen at three points: |
| 5278 // 1) When a load starts; at this point, the load is provisional, and | 5275 // 1) When a load starts; at this point, the load is provisional, and |
| 5279 // it should be ignored until it's committed, since the document/window | 5276 // it should be ignored until it's committed, since the document/window |
| 5280 // objects haven't changed yet. | 5277 // objects haven't changed yet. |
| 5281 // 2) When a non-document-changing URL change happens (hash change, | 5278 // 2) When a non-document-changing URL change happens (hash change, |
| 5282 // history.pushState, etc.). This URL change happens instantly, so should | 5279 // history.pushState, etc.). This URL change happens instantly, so should |
| 5283 // be reported. | 5280 // be reported. |
| 5284 // 3) When a navigation error occurs after provisional navigation starts, | 5281 // 3) When a navigation error occurs after provisional navigation starts, |
| 5285 // the URL reverts to the previous URL without triggering a new navigation. | 5282 // the URL reverts to the previous URL without triggering a new navigation. |
| 5286 // | 5283 // |
| 5287 // If |isLoading| is NO, then it must be case 2 or 3. If the last committed | 5284 // If |isLoading| is NO, then it must be case 2 or 3. If the last committed |
| 5288 // URL (_documentURL) matches the current URL, assume that it is a revert from | 5285 // URL (_documentURL) matches the current URL, assume that it is a revert from |
| 5289 // navigation failure and do nothing. If the URL does not match, assume it is | 5286 // navigation failure and do nothing. If the URL does not match, assume it is |
| 5290 // a non-document-changing URL change, and handle accordingly. | 5287 // a non-document-changing URL change, and handle accordingly. |
| 5291 // | 5288 // |
| 5292 // If |isLoading| is YES, then it could either be case 1, or it could be case | 5289 // If |isLoading| is YES, then it could either be case 1, or it could be case |
| 5293 // 2 on a page that hasn't finished loading yet. If it's possible that it | 5290 // 2 on a page that hasn't finished loading yet. If it's possible that it |
| 5294 // could be a same-page navigation (in which case there may not be any other | 5291 // could be a same-page navigation (in which case there may not be any other |
| 5295 // callback about the URL having changed), then check the actual page URL via | 5292 // callback about the URL having changed), then check the actual page URL via |
| 5296 // JavaScript. If the origin of the new URL matches the last committed URL, | 5293 // JavaScript. If the origin of the new URL matches the last committed URL, |
| 5297 // then check window.location.href, and if it matches, trust it. The origin | 5294 // then check window.location.href, and if it matches, trust it. The origin |
| 5298 // check ensures that if a site somehow corrupts window.location.href it can't | 5295 // check ensures that if a site somehow corrupts window.location.href it can't |
| 5299 // do a redirect to a slow-loading target page while it is still loading to | 5296 // do a redirect to a slow-loading target page while it is still loading to |
| 5300 // spoof the origin. On a document-changing URL change, the | 5297 // spoof the origin. On a document-changing URL change, the |
| 5301 // window.location.href will match the previous URL at this stage, not the web | 5298 // window.location.href will match the previous URL at this stage, not the web |
| 5302 // view's current URL. | 5299 // view's current URL. |
| 5303 if (![self.webView isLoading]) { | 5300 if (![_webView isLoading]) { |
| 5304 if (_documentURL == URL) | 5301 if (_documentURL == URL) |
| 5305 return; | 5302 return; |
| 5306 [self URLDidChangeWithoutDocumentChange:URL]; | 5303 [self URLDidChangeWithoutDocumentChange:URL]; |
| 5307 } else if ([self isKVOChangePotentialSameDocumentNavigationToURL:URL]) { | 5304 } else if ([self isKVOChangePotentialSameDocumentNavigationToURL:URL]) { |
| 5308 [self.webView | 5305 [_webView |
| 5309 evaluateJavaScript:@"window.location.href" | 5306 evaluateJavaScript:@"window.location.href" |
| 5310 completionHandler:^(id result, NSError* error) { | 5307 completionHandler:^(id result, NSError* error) { |
| 5311 // If the web view has gone away, or the location | 5308 // If the web view has gone away, or the location |
| 5312 // couldn't be retrieved, abort. | 5309 // couldn't be retrieved, abort. |
| 5313 if (!self.webView || ![result isKindOfClass:[NSString class]]) { | 5310 if (!_webView || ![result isKindOfClass:[NSString class]]) { |
| 5314 return; | 5311 return; |
| 5315 } | 5312 } |
| 5316 GURL JSURL([result UTF8String]); | 5313 GURL JSURL([result UTF8String]); |
| 5317 // Check that window.location matches the new URL. If | 5314 // Check that window.location matches the new URL. If |
| 5318 // it does not, this is a document-changing URL change as | 5315 // it does not, this is a document-changing URL change as |
| 5319 // the window location would not have changed to the new | 5316 // the window location would not have changed to the new |
| 5320 // URL when the script was called. | 5317 // URL when the script was called. |
| 5321 BOOL windowLocationMatchesNewURL = JSURL == URL; | 5318 BOOL windowLocationMatchesNewURL = JSURL == URL; |
| 5322 // Re-check origin in case navigaton has occured since | 5319 // Re-check origin in case navigaton has occured since |
| 5323 // start of JavaScript evaluation. | 5320 // start of JavaScript evaluation. |
| 5324 BOOL newURLOriginMatchesDocumentURLOrigin = | 5321 BOOL newURLOriginMatchesDocumentURLOrigin = |
| 5325 _documentURL.GetOrigin() == URL.GetOrigin(); | 5322 _documentURL.GetOrigin() == URL.GetOrigin(); |
| 5326 // Check that the web view URL still matches the new URL. | 5323 // Check that the web view URL still matches the new URL. |
| 5327 // TODO(crbug.com/563568): webViewURLMatchesNewURL check | 5324 // TODO(crbug.com/563568): webViewURLMatchesNewURL check |
| 5328 // may drop same document URL changes if pending URL | 5325 // may drop same document URL changes if pending URL |
| 5329 // change occurs immediately after. Revisit heuristics to | 5326 // change occurs immediately after. Revisit heuristics to |
| 5330 // prevent this. | 5327 // prevent this. |
| 5331 BOOL webViewURLMatchesNewURL = | 5328 BOOL webViewURLMatchesNewURL = |
| 5332 net::GURLWithNSURL([self.webView URL]) == URL; | 5329 net::GURLWithNSURL([_webView URL]) == URL; |
| 5333 // Check that the new URL is different from the current | 5330 // Check that the new URL is different from the current |
| 5334 // document URL. If not, URL change should not be reported. | 5331 // document URL. If not, URL change should not be reported. |
| 5335 BOOL URLDidChangeFromDocumentURL = URL != _documentURL; | 5332 BOOL URLDidChangeFromDocumentURL = URL != _documentURL; |
| 5336 if (windowLocationMatchesNewURL && | 5333 if (windowLocationMatchesNewURL && |
| 5337 newURLOriginMatchesDocumentURLOrigin && | 5334 newURLOriginMatchesDocumentURLOrigin && |
| 5338 webViewURLMatchesNewURL && URLDidChangeFromDocumentURL) { | 5335 webViewURLMatchesNewURL && URLDidChangeFromDocumentURL) { |
| 5339 [self URLDidChangeWithoutDocumentChange:URL]; | 5336 [self URLDidChangeWithoutDocumentChange:URL]; |
| 5340 } | 5337 } |
| 5341 }]; | 5338 }]; |
| 5342 } | 5339 } |
| 5343 } | 5340 } |
| 5344 | 5341 |
| 5345 - (BOOL)isKVOChangePotentialSameDocumentNavigationToURL:(const GURL&)newURL { | 5342 - (BOOL)isKVOChangePotentialSameDocumentNavigationToURL:(const GURL&)newURL { |
| 5346 DCHECK([self.webView isLoading]); | 5343 DCHECK([_webView isLoading]); |
| 5347 // If the origin changes, it can't be same-document. | 5344 // If the origin changes, it can't be same-document. |
| 5348 if (_documentURL.GetOrigin().is_empty() || | 5345 if (_documentURL.GetOrigin().is_empty() || |
| 5349 _documentURL.GetOrigin() != newURL.GetOrigin()) { | 5346 _documentURL.GetOrigin() != newURL.GetOrigin()) { |
| 5350 return NO; | 5347 return NO; |
| 5351 } | 5348 } |
| 5352 if (self.loadPhase == web::LOAD_REQUESTED) { | 5349 if (self.loadPhase == web::LOAD_REQUESTED) { |
| 5353 // Normally LOAD_REQUESTED indicates that this is a regular, pending | 5350 // Normally LOAD_REQUESTED indicates that this is a regular, pending |
| 5354 // navigation, but it can also happen during a fast-back navigation across | 5351 // navigation, but it can also happen during a fast-back navigation across |
| 5355 // a hash change, so that case is potentially a same-document navigation. | 5352 // a hash change, so that case is potentially a same-document navigation. |
| 5356 return web::GURLByRemovingRefFromGURL(newURL) == | 5353 return web::GURLByRemovingRefFromGURL(newURL) == |
| 5357 web::GURLByRemovingRefFromGURL(_documentURL); | 5354 web::GURLByRemovingRefFromGURL(_documentURL); |
| 5358 } | 5355 } |
| 5359 // If it passes all the checks above, it might be (but there's no guarantee | 5356 // If it passes all the checks above, it might be (but there's no guarantee |
| 5360 // that it is). | 5357 // that it is). |
| 5361 return YES; | 5358 return YES; |
| 5362 } | 5359 } |
| 5363 | 5360 |
| 5364 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)newURL { | 5361 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)newURL { |
| 5365 DCHECK(newURL == net::GURLWithNSURL([self.webView URL])); | 5362 DCHECK(newURL == net::GURLWithNSURL([_webView URL])); |
| 5366 DCHECK_EQ(_documentURL.host(), newURL.host()); | 5363 DCHECK_EQ(_documentURL.host(), newURL.host()); |
| 5367 DCHECK(_documentURL != newURL); | 5364 DCHECK(_documentURL != newURL); |
| 5368 | 5365 |
| 5369 // If called during window.history.pushState or window.history.replaceState | 5366 // If called during window.history.pushState or window.history.replaceState |
| 5370 // JavaScript evaluation, only update the document URL. This callback does not | 5367 // JavaScript evaluation, only update the document URL. This callback does not |
| 5371 // have any information about the state object and cannot create (or edit) the | 5368 // have any information about the state object and cannot create (or edit) the |
| 5372 // navigation entry for this page change. Web controller will sync with | 5369 // navigation entry for this page change. Web controller will sync with |
| 5373 // history changes when a window.history.didPushState or | 5370 // history changes when a window.history.didPushState or |
| 5374 // window.history.didReplaceState message is received, which should happen in | 5371 // window.history.didReplaceState message is received, which should happen in |
| 5375 // the next runloop. | 5372 // the next runloop. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 5399 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { | 5396 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { |
| 5400 if (self.loadPhase != web::LOAD_REQUESTED) | 5397 if (self.loadPhase != web::LOAD_REQUESTED) |
| 5401 return NO; | 5398 return NO; |
| 5402 | 5399 |
| 5403 web::NavigationItem* pendingItem = | 5400 web::NavigationItem* pendingItem = |
| 5404 self.webState->GetNavigationManager()->GetPendingItem(); | 5401 self.webState->GetNavigationManager()->GetPendingItem(); |
| 5405 return pendingItem && pendingItem->GetURL() == targetURL; | 5402 return pendingItem && pendingItem->GetURL() == targetURL; |
| 5406 } | 5403 } |
| 5407 | 5404 |
| 5408 - (void)loadRequestForCurrentNavigationItem { | 5405 - (void)loadRequestForCurrentNavigationItem { |
| 5409 DCHECK(self.webView && !self.nativeController); | 5406 DCHECK(_webView && !self.nativeController); |
| 5410 DCHECK([self currentSessionEntry]); | 5407 DCHECK([self currentSessionEntry]); |
| 5411 // If a load is kicked off on a WKWebView with a frame whose size is {0, 0} or | 5408 // If a load is kicked off on a WKWebView with a frame whose size is {0, 0} or |
| 5412 // that has a negative dimension for a size, rendering issues occur that | 5409 // that has a negative dimension for a size, rendering issues occur that |
| 5413 // manifest in erroneous scrolling and tap handling (crbug.com/574996, | 5410 // manifest in erroneous scrolling and tap handling (crbug.com/574996, |
| 5414 // crbug.com/577793). | 5411 // crbug.com/577793). |
| 5415 DCHECK_GT(CGRectGetWidth(self.webView.frame), 0.0); | 5412 DCHECK_GT(CGRectGetWidth([_webView frame]), 0.0); |
| 5416 DCHECK_GT(CGRectGetHeight(self.webView.frame), 0.0); | 5413 DCHECK_GT(CGRectGetHeight([_webView frame]), 0.0); |
| 5417 | 5414 |
| 5418 web::WKBackForwardListItemHolder* holder = | 5415 web::WKBackForwardListItemHolder* holder = |
| 5419 [self currentBackForwardListItemHolder]; | 5416 [self currentBackForwardListItemHolder]; |
| 5420 BOOL isFormResubmission = | 5417 BOOL isFormResubmission = |
| 5421 (holder->navigation_type() == WKNavigationTypeFormResubmitted || | 5418 (holder->navigation_type() == WKNavigationTypeFormResubmitted || |
| 5422 holder->navigation_type() == WKNavigationTypeFormSubmitted); | 5419 holder->navigation_type() == WKNavigationTypeFormSubmitted); |
| 5423 web::NavigationItemImpl* currentItem = | 5420 web::NavigationItemImpl* currentItem = |
| 5424 [self currentSessionEntry].navigationItemImpl; | 5421 [self currentSessionEntry].navigationItemImpl; |
| 5425 NSData* POSTData = currentItem->GetPostData(); | 5422 NSData* POSTData = currentItem->GetPostData(); |
| 5426 NSMutableURLRequest* request = [self requestForCurrentNavigationItem]; | 5423 NSMutableURLRequest* request = [self requestForCurrentNavigationItem]; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 5456 } | 5453 } |
| 5457 | 5454 |
| 5458 ProceduralBlock webViewNavigationBlock = ^{ | 5455 ProceduralBlock webViewNavigationBlock = ^{ |
| 5459 // If the current navigation URL is the same as the URL of the visible | 5456 // If the current navigation URL is the same as the URL of the visible |
| 5460 // page, that means the user requested a reload. |goToBackForwardListItem| | 5457 // page, that means the user requested a reload. |goToBackForwardListItem| |
| 5461 // will be a no-op when it is passed the current back forward list item, | 5458 // will be a no-op when it is passed the current back forward list item, |
| 5462 // so |reload| must be explicitly called. | 5459 // so |reload| must be explicitly called. |
| 5463 [self registerLoadRequest:[self currentNavigationURL] | 5460 [self registerLoadRequest:[self currentNavigationURL] |
| 5464 referrer:[self currentSessionEntryReferrer] | 5461 referrer:[self currentSessionEntryReferrer] |
| 5465 transition:[self currentTransition]]; | 5462 transition:[self currentTransition]]; |
| 5466 if ([self currentNavigationURL] == net::GURLWithNSURL([self.webView URL])) { | 5463 if ([self currentNavigationURL] == net::GURLWithNSURL([_webView URL])) { |
| 5467 [self.webView reload]; | 5464 [_webView reload]; |
| 5468 } else { | 5465 } else { |
| 5469 [self.webView goToBackForwardListItem:holder->back_forward_list_item()]; | 5466 [_webView goToBackForwardListItem:holder->back_forward_list_item()]; |
| 5470 } | 5467 } |
| 5471 }; | 5468 }; |
| 5472 | 5469 |
| 5473 // If the request is not a form submission or resubmission, or the user | 5470 // If the request is not a form submission or resubmission, or the user |
| 5474 // doesn't need to confirm the load, then continue right away. | 5471 // doesn't need to confirm the load, then continue right away. |
| 5475 | 5472 |
| 5476 if (!isFormResubmission || | 5473 if (!isFormResubmission || |
| 5477 currentItem->ShouldSkipResubmitDataConfirmation()) { | 5474 currentItem->ShouldSkipResubmitDataConfirmation()) { |
| 5478 webViewNavigationBlock(); | 5475 webViewNavigationBlock(); |
| 5479 return; | 5476 return; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5573 } | 5570 } |
| 5574 | 5571 |
| 5575 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5572 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
| 5576 } | 5573 } |
| 5577 | 5574 |
| 5578 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5575 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
| 5579 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5576 return [action.request valueForHTTPHeaderField:@"Referer"]; |
| 5580 } | 5577 } |
| 5581 | 5578 |
| 5582 @end | 5579 @end |
| OLD | NEW |