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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 | 553 |
554 // Returns the current entry from the underlying session controller. | 554 // Returns the current entry from the underlying session controller. |
555 // TODO(stuartmorgan): Audit all calls to these methods; these are just wrappers | 555 // TODO(stuartmorgan): Audit all calls to these methods; these are just wrappers |
556 // around the same logic as GetActiveEntry, so should probably not be used for | 556 // around the same logic as GetActiveEntry, so should probably not be used for |
557 // the same reason that GetActiveEntry is deprecated. (E.g., page operations | 557 // the same reason that GetActiveEntry is deprecated. (E.g., page operations |
558 // should generally be dealing with the last commited entry, not a pending | 558 // should generally be dealing with the last commited entry, not a pending |
559 // entry). | 559 // entry). |
560 - (CRWSessionEntry*)currentSessionEntry; | 560 - (CRWSessionEntry*)currentSessionEntry; |
561 // Returns the navigation item for the current page. | 561 // Returns the navigation item for the current page. |
562 - (web::NavigationItem*)currentNavItem; | 562 - (web::NavigationItem*)currentNavItem; |
563 // Returns the URL that the navigation system believes should be currently | |
564 // active. | |
565 // TODO(stuartmorgan):Remove this in favor of more specific getters. | |
566 - (const GURL&)currentNavigationURL; | |
567 // Returns the current transition type. | 563 // Returns the current transition type. |
568 - (ui::PageTransition)currentTransition; | 564 - (ui::PageTransition)currentTransition; |
569 // Returns the referrer for current navigation item. May be empty. | 565 // Returns the referrer for current navigation item. May be empty. |
570 - (web::Referrer)currentSessionEntryReferrer; | 566 - (web::Referrer)currentSessionEntryReferrer; |
571 // The HTTP headers associated with the current navigation item. These are nil | 567 // The HTTP headers associated with the current navigation item. These are nil |
572 // unless the request was a POST. | 568 // unless the request was a POST. |
573 - (NSDictionary*)currentHTTPHeaders; | 569 - (NSDictionary*)currentHTTPHeaders; |
574 | 570 |
575 // Creates a web view if it's not yet created. | 571 // Creates a web view if it's not yet created. |
576 - (void)ensureWebViewCreated; | 572 - (void)ensureWebViewCreated; |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1424 } | 1420 } |
1425 // Any non-web URL source is trusted. | 1421 // Any non-web URL source is trusted. |
1426 *trustLevel = web::URLVerificationTrustLevel::kAbsolute; | 1422 *trustLevel = web::URLVerificationTrustLevel::kAbsolute; |
1427 if (self.nativeController) { | 1423 if (self.nativeController) { |
1428 if ([self.nativeController respondsToSelector:@selector(virtualURL)]) { | 1424 if ([self.nativeController respondsToSelector:@selector(virtualURL)]) { |
1429 return [self.nativeController virtualURL]; | 1425 return [self.nativeController virtualURL]; |
1430 } else { | 1426 } else { |
1431 return [self.nativeController url]; | 1427 return [self.nativeController url]; |
1432 } | 1428 } |
1433 } | 1429 } |
1434 return [self currentNavigationURL]; | 1430 web::NavigationItem* item = [self currentNavItem]; |
| 1431 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
1435 } | 1432 } |
1436 | 1433 |
1437 - (WKWebView*)webView { | 1434 - (WKWebView*)webView { |
1438 return _webView.get(); | 1435 return _webView.get(); |
1439 } | 1436 } |
1440 | 1437 |
1441 - (UIScrollView*)webScrollView { | 1438 - (UIScrollView*)webScrollView { |
1442 return [_webView scrollView]; | 1439 return [_webView scrollView]; |
1443 } | 1440 } |
1444 | 1441 |
1445 - (GURL)currentURL { | 1442 - (GURL)currentURL { |
1446 web::URLVerificationTrustLevel trustLevel = | 1443 web::URLVerificationTrustLevel trustLevel = |
1447 web::URLVerificationTrustLevel::kNone; | 1444 web::URLVerificationTrustLevel::kNone; |
1448 return [self currentURLWithTrustLevel:&trustLevel]; | 1445 return [self currentURLWithTrustLevel:&trustLevel]; |
1449 } | 1446 } |
1450 | 1447 |
1451 - (web::Referrer)currentReferrer { | 1448 - (web::Referrer)currentReferrer { |
1452 // Referrer string doesn't include the fragment, so in cases where the | 1449 // Referrer string doesn't include the fragment, so in cases where the |
1453 // previous URL is equal to the current referrer plus the fragment the | 1450 // previous URL is equal to the current referrer plus the fragment the |
1454 // previous URL is returned as current referrer. | 1451 // previous URL is returned as current referrer. |
1455 NSString* referrerString = _currentReferrerString; | 1452 NSString* referrerString = _currentReferrerString; |
1456 | 1453 |
1457 // In case of an error evaluating the JavaScript simply return empty string. | 1454 // In case of an error evaluating the JavaScript simply return empty string. |
1458 if ([referrerString length] == 0) | 1455 if ([referrerString length] == 0) |
1459 return web::Referrer(); | 1456 return web::Referrer(); |
1460 | 1457 |
1461 NSString* previousURLString = | 1458 web::NavigationItem* item = [self currentNavItem]; |
1462 base::SysUTF8ToNSString([self currentNavigationURL].spec()); | 1459 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| 1460 NSString* previousURLString = base::SysUTF8ToNSString(navigationURL.spec()); |
1463 // Check if the referrer is equal to the previous URL minus the hash symbol. | 1461 // Check if the referrer is equal to the previous URL minus the hash symbol. |
1464 // L'#' is used to convert the char '#' to a unichar. | 1462 // L'#' is used to convert the char '#' to a unichar. |
1465 if ([previousURLString length] > [referrerString length] && | 1463 if ([previousURLString length] > [referrerString length] && |
1466 [previousURLString hasPrefix:referrerString] && | 1464 [previousURLString hasPrefix:referrerString] && |
1467 [previousURLString characterAtIndex:[referrerString length]] == L'#') { | 1465 [previousURLString characterAtIndex:[referrerString length]] == L'#') { |
1468 referrerString = previousURLString; | 1466 referrerString = previousURLString; |
1469 } | 1467 } |
1470 // Since referrer is being extracted from the destination page, the correct | 1468 // Since referrer is being extracted from the destination page, the correct |
1471 // policy from the origin has *already* been applied. Since the extracted URL | 1469 // policy from the origin has *already* been applied. Since the extracted URL |
1472 // is the post-policy value, and the source policy is no longer available, | 1470 // is the post-policy value, and the source policy is no longer available, |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1826 strongSelf.get()->_URLOnStartLoading = URL; | 1824 strongSelf.get()->_URLOnStartLoading = URL; |
1827 strongSelf.get()->_lastRegisteredRequestURL = URL; | 1825 strongSelf.get()->_lastRegisteredRequestURL = URL; |
1828 }]; | 1826 }]; |
1829 } | 1827 } |
1830 | 1828 |
1831 // Load the current URL in a web view, first ensuring the web view is visible. | 1829 // Load the current URL in a web view, first ensuring the web view is visible. |
1832 - (void)loadCurrentURLInWebView { | 1830 - (void)loadCurrentURLInWebView { |
1833 // Clear the set of URLs opened in external applications. | 1831 // Clear the set of URLs opened in external applications. |
1834 _openedApplicationURL.reset([[NSMutableSet alloc] init]); | 1832 _openedApplicationURL.reset([[NSMutableSet alloc] init]); |
1835 | 1833 |
| 1834 web::NavigationItem* item = [self currentNavItem]; |
| 1835 GURL targetURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
1836 // Load the url. The UIWebView delegate callbacks take care of updating the | 1836 // Load the url. The UIWebView delegate callbacks take care of updating the |
1837 // session history and UI. | 1837 // session history and UI. |
1838 const GURL targetURL([self currentNavigationURL]); | |
1839 if (!targetURL.is_valid()) { | 1838 if (!targetURL.is_valid()) { |
1840 [self didFinishWithURL:targetURL loadSuccess:NO]; | 1839 [self didFinishWithURL:targetURL loadSuccess:NO]; |
1841 return; | 1840 return; |
1842 } | 1841 } |
1843 | 1842 |
1844 // JavaScript should never be evaluated here. User-entered JS should be | 1843 // JavaScript should never be evaluated here. User-entered JS should be |
1845 // evaluated via stringByEvaluatingUserJavaScriptFromString. | 1844 // evaluated via stringByEvaluatingUserJavaScriptFromString. |
1846 DCHECK(!targetURL.SchemeIs(url::kJavaScriptScheme)); | 1845 DCHECK(!targetURL.SchemeIs(url::kJavaScriptScheme)); |
1847 | 1846 |
1848 [self ensureWebViewCreated]; | 1847 [self ensureWebViewCreated]; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 if ([_pendingNavigationInfo MIMEType]) { | 1879 if ([_pendingNavigationInfo MIMEType]) { |
1881 self.webStateImpl->SetContentsMimeType( | 1880 self.webStateImpl->SetContentsMimeType( |
1882 base::SysNSStringToUTF8([_pendingNavigationInfo MIMEType])); | 1881 base::SysNSStringToUTF8([_pendingNavigationInfo MIMEType])); |
1883 } | 1882 } |
1884 [self updateCurrentBackForwardListItemHolder]; | 1883 [self updateCurrentBackForwardListItemHolder]; |
1885 | 1884 |
1886 _pendingNavigationInfo.reset(); | 1885 _pendingNavigationInfo.reset(); |
1887 } | 1886 } |
1888 | 1887 |
1889 - (NSMutableURLRequest*)requestForCurrentNavigationItem { | 1888 - (NSMutableURLRequest*)requestForCurrentNavigationItem { |
1890 const GURL currentNavigationURL([self currentNavigationURL]); | 1889 web::NavigationItem* item = [self currentNavItem]; |
| 1890 const GURL currentNavigationURL = |
| 1891 item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
1891 NSMutableURLRequest* request = [NSMutableURLRequest | 1892 NSMutableURLRequest* request = [NSMutableURLRequest |
1892 requestWithURL:net::NSURLWithGURL(currentNavigationURL)]; | 1893 requestWithURL:net::NSURLWithGURL(currentNavigationURL)]; |
1893 const web::Referrer referrer([self currentSessionEntryReferrer]); | 1894 const web::Referrer referrer([self currentSessionEntryReferrer]); |
1894 if (referrer.url.is_valid()) { | 1895 if (referrer.url.is_valid()) { |
1895 std::string referrerValue = | 1896 std::string referrerValue = |
1896 web::ReferrerHeaderValueForNavigation(currentNavigationURL, referrer); | 1897 web::ReferrerHeaderValueForNavigation(currentNavigationURL, referrer); |
1897 if (!referrerValue.empty()) { | 1898 if (!referrerValue.empty()) { |
1898 [request setValue:base::SysUTF8ToNSString(referrerValue) | 1899 [request setValue:base::SysUTF8ToNSString(referrerValue) |
1899 forHTTPHeaderField:kReferrerHeaderName]; | 1900 forHTTPHeaderField:kReferrerHeaderName]; |
1900 } | 1901 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 // If the controller handles title change notification, route those to the | 1966 // If the controller handles title change notification, route those to the |
1966 // delegate. | 1967 // delegate. |
1967 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { | 1968 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { |
1968 [self.nativeController setDelegate:self]; | 1969 [self.nativeController setDelegate:self]; |
1969 } | 1970 } |
1970 } | 1971 } |
1971 } | 1972 } |
1972 | 1973 |
1973 - (void)loadErrorInNativeView:(NSError*)error { | 1974 - (void)loadErrorInNativeView:(NSError*)error { |
1974 [self removeWebViewAllowingCachedReconstruction:NO]; | 1975 [self removeWebViewAllowingCachedReconstruction:NO]; |
1975 | 1976 web::NavigationItem* item = [self currentNavItem]; |
1976 const GURL currentUrl = [self currentNavigationURL]; | 1977 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
1977 | 1978 |
1978 if (web::IsWKWebViewSSLCertError(error)) { | 1979 if (web::IsWKWebViewSSLCertError(error)) { |
1979 // This could happen only if certificate is absent or could not be parsed. | 1980 // This could happen only if certificate is absent or could not be parsed. |
1980 error = web::NetErrorFromError(error, net::ERR_SSL_SERVER_CERT_BAD_FORMAT); | 1981 error = web::NetErrorFromError(error, net::ERR_SSL_SERVER_CERT_BAD_FORMAT); |
1981 #if defined(DEBUG) | 1982 #if defined(DEBUG) |
1982 net::SSLInfo info; | 1983 net::SSLInfo info; |
1983 web::GetSSLInfoFromWKWebViewSSLCertError(error, &info); | 1984 web::GetSSLInfoFromWKWebViewSSLCertError(error, &info); |
1984 CHECK(!error.cert); | 1985 CHECK(!error.cert); |
1985 #endif | 1986 #endif |
1986 } else { | 1987 } else { |
1987 error = web::NetErrorFromError(error); | 1988 error = web::NetErrorFromError(error); |
1988 } | 1989 } |
1989 | 1990 |
1990 BOOL isPost = [self isCurrentNavigationItemPOST]; | 1991 BOOL isPost = [self isCurrentNavigationItemPOST]; |
1991 [self setNativeController:[_nativeProvider controllerForURL:currentUrl | 1992 [self setNativeController:[_nativeProvider controllerForURL:currentURL |
1992 withError:error | 1993 withError:error |
1993 isPost:isPost]]; | 1994 isPost:isPost]]; |
1994 [self loadNativeViewWithSuccess:NO]; | 1995 [self loadNativeViewWithSuccess:NO]; |
1995 } | 1996 } |
1996 | 1997 |
1997 // Load the current URL in a native controller, retrieved from the native | 1998 // Load the current URL in a native controller, retrieved from the native |
1998 // provider. Call |loadNativeViewWithSuccess:YES| to load the native controller. | 1999 // provider. Call |loadNativeViewWithSuccess:YES| to load the native controller. |
1999 - (void)loadCurrentURLInNativeView { | 2000 - (void)loadCurrentURLInNativeView { |
2000 // Free the web view. | 2001 // Free the web view. |
2001 [self removeWebViewAllowingCachedReconstruction:NO]; | 2002 [self removeWebViewAllowingCachedReconstruction:NO]; |
2002 | 2003 |
2003 const GURL targetURL = [self currentNavigationURL]; | 2004 web::NavigationItem* item = [self currentNavItem]; |
| 2005 const GURL targetURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
2004 const web::Referrer referrer; | 2006 const web::Referrer referrer; |
2005 id<CRWNativeContent> nativeContent = | 2007 id<CRWNativeContent> nativeContent = |
2006 [_nativeProvider controllerForURL:targetURL]; | 2008 [_nativeProvider controllerForURL:targetURL]; |
2007 // Unlike the WebView case, always create a new controller and view. | 2009 // Unlike the WebView case, always create a new controller and view. |
2008 // TODO(pinkerton): What to do if this does return nil? | 2010 // TODO(pinkerton): What to do if this does return nil? |
2009 [self setNativeController:nativeContent]; | 2011 [self setNativeController:nativeContent]; |
2010 if ([nativeContent respondsToSelector:@selector(virtualURL)]) { | 2012 if ([nativeContent respondsToSelector:@selector(virtualURL)]) { |
2011 [self currentNavItem]->SetVirtualURL([nativeContent virtualURL]); | 2013 item->SetVirtualURL([nativeContent virtualURL]); |
2012 } | 2014 } |
2013 [self registerLoadRequest:targetURL | 2015 [self registerLoadRequest:targetURL |
2014 referrer:referrer | 2016 referrer:referrer |
2015 transition:[self currentTransition]]; | 2017 transition:[self currentTransition]]; |
2016 [self loadNativeViewWithSuccess:YES]; | 2018 [self loadNativeViewWithSuccess:YES]; |
2017 } | 2019 } |
2018 | 2020 |
2019 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)originalParams { | 2021 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)originalParams { |
2020 // Make a copy of |params|, as some of the delegate methods may modify it. | 2022 // Make a copy of |params|, as some of the delegate methods may modify it. |
2021 NavigationManager::WebLoadParams params(originalParams); | 2023 NavigationManager::WebLoadParams params(originalParams); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2089 | 2091 |
2090 // Abort any outstanding page load. This ensures the delegate gets informed | 2092 // Abort any outstanding page load. This ensures the delegate gets informed |
2091 // about the outgoing page, and further messages from the page are suppressed. | 2093 // about the outgoing page, and further messages from the page are suppressed. |
2092 if (_loadPhase != web::PAGE_LOADED) | 2094 if (_loadPhase != web::PAGE_LOADED) |
2093 [self abortLoad]; | 2095 [self abortLoad]; |
2094 | 2096 |
2095 DCHECK(!_isHalted); | 2097 DCHECK(!_isHalted); |
2096 // Remove the transient content view. | 2098 // Remove the transient content view. |
2097 [self clearTransientContentView]; | 2099 [self clearTransientContentView]; |
2098 | 2100 |
2099 const GURL currentURL = [self currentNavigationURL]; | 2101 web::NavigationItem* item = [self currentNavItem]; |
| 2102 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
2100 // If it's a chrome URL, but not a native one, create the WebUI instance. | 2103 // If it's a chrome URL, but not a native one, create the WebUI instance. |
2101 if (web::GetWebClient()->IsAppSpecificURL(currentURL) && | 2104 if (web::GetWebClient()->IsAppSpecificURL(currentURL) && |
2102 ![_nativeProvider hasControllerForURL:currentURL]) { | 2105 ![_nativeProvider hasControllerForURL:currentURL]) { |
2103 web::NavigationItem* item = [self currentNavItem]; | |
2104 if (!(item->GetTransitionType() & ui::PAGE_TRANSITION_TYPED || | 2106 if (!(item->GetTransitionType() & ui::PAGE_TRANSITION_TYPED || |
2105 item->GetTransitionType() & ui::PAGE_TRANSITION_AUTO_BOOKMARK) && | 2107 item->GetTransitionType() & ui::PAGE_TRANSITION_AUTO_BOOKMARK) && |
2106 self.sessionController.openedByDOM) { | 2108 self.sessionController.openedByDOM) { |
2107 // WebUI URLs can not be opened by DOM to prevent cross-site scripting as | 2109 // WebUI URLs can not be opened by DOM to prevent cross-site scripting as |
2108 // they have increased power. WebUI URLs may only be opened when the user | 2110 // they have increased power. WebUI URLs may only be opened when the user |
2109 // types in the URL or use bookmarks. | 2111 // types in the URL or use bookmarks. |
2110 [[self sessionController] discardNonCommittedEntries]; | 2112 [[self sessionController] discardNonCommittedEntries]; |
2111 return; | 2113 return; |
2112 } else { | 2114 } else { |
2113 [self createWebUIForURL:currentURL]; | 2115 [self createWebUIForURL:currentURL]; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2156 CGRect containerViewFrame = | 2158 CGRect containerViewFrame = |
2157 [UIApplication sharedApplication].keyWindow.bounds; | 2159 [UIApplication sharedApplication].keyWindow.bounds; |
2158 containerViewFrame.origin.y += statusBarHeight; | 2160 containerViewFrame.origin.y += statusBarHeight; |
2159 containerViewFrame.size.height -= statusBarHeight; | 2161 containerViewFrame.size.height -= statusBarHeight; |
2160 _containerView.get().frame = containerViewFrame; | 2162 _containerView.get().frame = containerViewFrame; |
2161 DCHECK(!CGRectIsEmpty(_containerView.get().frame)); | 2163 DCHECK(!CGRectIsEmpty(_containerView.get().frame)); |
2162 | 2164 |
2163 [_containerView addGestureRecognizer:[self touchTrackingRecognizer]]; | 2165 [_containerView addGestureRecognizer:[self touchTrackingRecognizer]]; |
2164 [_containerView setAccessibilityIdentifier:web::kContainerViewID]; | 2166 [_containerView setAccessibilityIdentifier:web::kContainerViewID]; |
2165 // Is |currentUrl| a web scheme or native chrome scheme. | 2167 // Is |currentUrl| a web scheme or native chrome scheme. |
| 2168 web::NavigationItem* item = [self currentNavItem]; |
| 2169 const GURL currentNavigationURL = |
| 2170 item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
2166 BOOL isChromeScheme = | 2171 BOOL isChromeScheme = |
2167 web::GetWebClient()->IsAppSpecificURL([self currentNavigationURL]); | 2172 web::GetWebClient()->IsAppSpecificURL(currentNavigationURL); |
2168 | 2173 |
2169 // Don't immediately load the web page if in overlay mode. Always load if | 2174 // Don't immediately load the web page if in overlay mode. Always load if |
2170 // native. | 2175 // native. |
2171 if (isChromeScheme || !_overlayPreviewMode) { | 2176 if (isChromeScheme || !_overlayPreviewMode) { |
2172 // TODO(jimblackler): end the practice of calling |loadCurrentURL| when it | 2177 // TODO(jimblackler): end the practice of calling |loadCurrentURL| when it |
2173 // is possible there is no current URL. If the call performs necessary | 2178 // is possible there is no current URL. If the call performs necessary |
2174 // initialization, break that out. | 2179 // initialization, break that out. |
2175 [self loadCurrentURL]; | 2180 [self loadCurrentURL]; |
2176 } | 2181 } |
2177 | 2182 |
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3395 | 3400 |
3396 // Check if the link navigation leads to a launch of an external app. | 3401 // Check if the link navigation leads to a launch of an external app. |
3397 // TODO(crbug.com/607780): Revise the logic of allowing external app launch | 3402 // TODO(crbug.com/607780): Revise the logic of allowing external app launch |
3398 // and move it to externalAppLauncher. | 3403 // and move it to externalAppLauncher. |
3399 BOOL isOpenInNewTabNavigation = | 3404 BOOL isOpenInNewTabNavigation = |
3400 !_webStateImpl->GetNavigationManager()->GetItemCount(); | 3405 !_webStateImpl->GetNavigationManager()->GetItemCount(); |
3401 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType]; | 3406 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType]; |
3402 if (isPossibleLinkClick || isOpenInNewTabNavigation || | 3407 if (isPossibleLinkClick || isOpenInNewTabNavigation || |
3403 PageTransitionCoreTypeIs([self currentTransition], | 3408 PageTransitionCoreTypeIs([self currentTransition], |
3404 ui::PAGE_TRANSITION_AUTO_BOOKMARK)) { | 3409 ui::PAGE_TRANSITION_AUTO_BOOKMARK)) { |
| 3410 web::NavigationItem* item = [self currentNavItem]; |
| 3411 const GURL currentNavigationURL = |
| 3412 item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
3405 // Check If the URL is handled by a native app. | 3413 // Check If the URL is handled by a native app. |
3406 if ([self urlTriggersNativeAppLaunch:requestURL | 3414 if ([self urlTriggersNativeAppLaunch:requestURL |
3407 sourceURL:[self currentNavigationURL] | 3415 sourceURL:currentNavigationURL |
3408 linkActivatedNavigation:isNavigationTypeLinkActivated]) { | 3416 linkActivatedNavigation:isNavigationTypeLinkActivated]) { |
3409 // External app has been launched successfully. Stop the current page | 3417 // External app has been launched successfully. Stop the current page |
3410 // load operation (e.g. notifying all observers) and record the URL so | 3418 // load operation (e.g. notifying all observers) and record the URL so |
3411 // that errors reported following the 'NO' reply can be safely ignored. | 3419 // that errors reported following the 'NO' reply can be safely ignored. |
3412 if ([self shouldClosePageOnNativeApplicationLoad]) | 3420 if ([self shouldClosePageOnNativeApplicationLoad]) |
3413 [_delegate webPageOrderedClose]; | 3421 [_delegate webPageOrderedClose]; |
3414 [self stopLoading]; | 3422 [self stopLoading]; |
3415 [_openedApplicationURL addObject:request.URL]; | 3423 [_openedApplicationURL addObject:request.URL]; |
3416 return NO; | 3424 return NO; |
3417 } | 3425 } |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3755 sourceURL:)]) { | 3763 sourceURL:)]) { |
3756 return NO; | 3764 return NO; |
3757 } | 3765 } |
3758 return [_delegate webController:self | 3766 return [_delegate webController:self |
3759 shouldBlockPopupWithURL:popupURL | 3767 shouldBlockPopupWithURL:popupURL |
3760 sourceURL:sourceURL]; | 3768 sourceURL:sourceURL]; |
3761 } | 3769 } |
3762 | 3770 |
3763 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo { | 3771 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo { |
3764 const GURL url(windowInfo.url); | 3772 const GURL url(windowInfo.url); |
3765 const GURL currentURL([self currentNavigationURL]); | 3773 web::NavigationItem* item = [self currentNavItem]; |
| 3774 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
3766 NSString* windowName = windowInfo.window_name.get(); | 3775 NSString* windowName = windowInfo.window_name.get(); |
3767 web::Referrer referrer(currentURL, windowInfo.referrer_policy); | 3776 web::Referrer referrer(currentURL, windowInfo.referrer_policy); |
3768 base::WeakNSObject<CRWWebController> weakSelf(self); | 3777 base::WeakNSObject<CRWWebController> weakSelf(self); |
3769 void (^showPopupHandler)() = ^{ | 3778 void (^showPopupHandler)() = ^{ |
3770 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url | 3779 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url |
3771 referrer:referrer | 3780 referrer:referrer |
3772 windowName:windowName | 3781 windowName:windowName |
3773 inBackground:NO]; | 3782 inBackground:NO]; |
3774 DCHECK(!child || child.sessionController.openedByDOM); | 3783 DCHECK(!child || child.sessionController.openedByDOM); |
3775 }; | 3784 }; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4041 - (web::NavigationItem*)currentNavItem { | 4050 - (web::NavigationItem*)currentNavItem { |
4042 // This goes through the legacy Session* interface rather than Navigation* | 4051 // This goes through the legacy Session* interface rather than Navigation* |
4043 // because it is itself a legacy method that should not exist, and this | 4052 // because it is itself a legacy method that should not exist, and this |
4044 // avoids needing to add a GetActiveItem to NavigationManager. If/when this | 4053 // avoids needing to add a GetActiveItem to NavigationManager. If/when this |
4045 // method chain becomes a blocker to eliminating SessionController, the logic | 4054 // method chain becomes a blocker to eliminating SessionController, the logic |
4046 // can be moved here, using public NavigationManager getters. That's not | 4055 // can be moved here, using public NavigationManager getters. That's not |
4047 // done now in order to avoid code duplication. | 4056 // done now in order to avoid code duplication. |
4048 return [[self currentSessionEntry] navigationItem]; | 4057 return [[self currentSessionEntry] navigationItem]; |
4049 } | 4058 } |
4050 | 4059 |
4051 - (const GURL&)currentNavigationURL { | |
4052 // TODO(stuartmorgan): Fix the fact that this method doesn't have clear usage | |
4053 // delination that would allow changing to one of the non-deprecated URL | |
4054 // calls. | |
4055 web::NavigationItem* item = [self currentNavItem]; | |
4056 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); | |
4057 } | |
4058 | |
4059 - (ui::PageTransition)currentTransition { | 4060 - (ui::PageTransition)currentTransition { |
4060 if ([self currentNavItem]) | 4061 if ([self currentNavItem]) |
4061 return [self currentNavItem]->GetTransitionType(); | 4062 return [self currentNavItem]->GetTransitionType(); |
4062 else | 4063 else |
4063 return ui::PageTransitionFromInt(0); | 4064 return ui::PageTransitionFromInt(0); |
4064 } | 4065 } |
4065 | 4066 |
4066 - (web::Referrer)currentSessionEntryReferrer { | 4067 - (web::Referrer)currentSessionEntryReferrer { |
4067 web::NavigationItem* currentItem = [self currentNavItem]; | 4068 web::NavigationItem* currentItem = [self currentNavItem]; |
4068 return currentItem ? currentItem->GetReferrer() : web::Referrer(); | 4069 return currentItem ? currentItem->GetReferrer() : web::Referrer(); |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4812 | 4813 |
4813 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { | 4814 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { |
4814 if (!_webView) | 4815 if (!_webView) |
4815 return; | 4816 return; |
4816 | 4817 |
4817 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); | 4818 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); |
4818 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) | 4819 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) |
4819 [self.UIDelegate cancelDialogsForWebController:self]; | 4820 [self.UIDelegate cancelDialogsForWebController:self]; |
4820 _webStateImpl->CancelDialogs(); | 4821 _webStateImpl->CancelDialogs(); |
4821 | 4822 |
4822 if (allowCache) | 4823 web::NavigationItem* item = [self currentNavItem]; |
4823 _expectedReconstructionURL = [self currentNavigationURL]; | 4824 if (allowCache && item) { |
4824 else | 4825 _expectedReconstructionURL = item->GetVirtualURL(); |
4825 _expectedReconstructionURL = GURL(); | 4826 } else { |
| 4827 _expectedReconstructionURL = GURL::EmptyGURL(); |
| 4828 } |
4826 | 4829 |
4827 [self abortLoad]; | 4830 [self abortLoad]; |
4828 [_webView removeFromSuperview]; | 4831 [_webView removeFromSuperview]; |
4829 [_containerView resetContent]; | 4832 [_containerView resetContent]; |
4830 [self setWebView:nil]; | 4833 [self setWebView:nil]; |
4831 } | 4834 } |
4832 | 4835 |
4833 - (void)webViewWebProcessDidCrash { | 4836 - (void)webViewWebProcessDidCrash { |
4834 _webProcessIsDead = YES; | 4837 _webProcessIsDead = YES; |
4835 | 4838 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4905 } | 4908 } |
4906 | 4909 |
4907 - (void)stopLoading { | 4910 - (void)stopLoading { |
4908 _stoppedWKNavigation.reset(_latestWKNavigation); | 4911 _stoppedWKNavigation.reset(_latestWKNavigation); |
4909 | 4912 |
4910 base::RecordAction(UserMetricsAction("Stop")); | 4913 base::RecordAction(UserMetricsAction("Stop")); |
4911 // Discard the pending and transient entried before notifying the tab model | 4914 // Discard the pending and transient entried before notifying the tab model |
4912 // observers of the change via |-abortLoad|. | 4915 // observers of the change via |-abortLoad|. |
4913 [[self sessionController] discardNonCommittedEntries]; | 4916 [[self sessionController] discardNonCommittedEntries]; |
4914 [self abortLoad]; | 4917 [self abortLoad]; |
| 4918 web::NavigationItem* item = [self currentNavItem]; |
| 4919 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
4915 // If discarding the non-committed entries results in an app-specific URL, | 4920 // If discarding the non-committed entries results in an app-specific URL, |
4916 // reload it in its native view. | 4921 // reload it in its native view. |
4917 if (!self.nativeController && | 4922 if (!self.nativeController && |
4918 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) { | 4923 [self shouldLoadURLInNativeView:navigationURL]) { |
4919 [self loadCurrentURLInNativeView]; | 4924 [self loadCurrentURLInNativeView]; |
4920 } | 4925 } |
4921 } | 4926 } |
4922 | 4927 |
4923 #pragma mark - | 4928 #pragma mark - |
4924 #pragma mark WKUIDelegate Methods | 4929 #pragma mark WKUIDelegate Methods |
4925 | 4930 |
4926 - (WKWebView*)webView:(WKWebView*)webView | 4931 - (WKWebView*)webView:(WKWebView*)webView |
4927 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration | 4932 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration |
4928 forNavigationAction:(WKNavigationAction*)action | 4933 forNavigationAction:(WKNavigationAction*)action |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5646 [self currentSessionEntry].navigationItemImpl; | 5651 [self currentSessionEntry].navigationItemImpl; |
5647 NSData* POSTData = currentItem->GetPostData(); | 5652 NSData* POSTData = currentItem->GetPostData(); |
5648 NSMutableURLRequest* request = [self requestForCurrentNavigationItem]; | 5653 NSMutableURLRequest* request = [self requestForCurrentNavigationItem]; |
5649 | 5654 |
5650 // If the request has POST data and is not a form resubmission, configure and | 5655 // If the request has POST data and is not a form resubmission, configure and |
5651 // run the POST request. | 5656 // run the POST request. |
5652 if (POSTData.length && !isFormPOSTResubmission) { | 5657 if (POSTData.length && !isFormPOSTResubmission) { |
5653 [request setHTTPMethod:@"POST"]; | 5658 [request setHTTPMethod:@"POST"]; |
5654 [request setHTTPBody:POSTData]; | 5659 [request setHTTPBody:POSTData]; |
5655 [request setAllHTTPHeaderFields:[self currentHTTPHeaders]]; | 5660 [request setAllHTTPHeaderFields:[self currentHTTPHeaders]]; |
5656 [self registerLoadRequest:[self currentNavigationURL] | 5661 GURL navigationURL = |
| 5662 currentItem ? currentItem->GetVirtualURL() : GURL::EmptyGURL(); |
| 5663 [self registerLoadRequest:navigationURL |
5657 referrer:[self currentSessionEntryReferrer] | 5664 referrer:[self currentSessionEntryReferrer] |
5658 transition:[self currentTransition]]; | 5665 transition:[self currentTransition]]; |
5659 [self loadPOSTRequest:request]; | 5666 [self loadPOSTRequest:request]; |
5660 return; | 5667 return; |
5661 } | 5668 } |
5662 | 5669 |
5663 ProceduralBlock defaultNavigationBlock = ^{ | 5670 ProceduralBlock defaultNavigationBlock = ^{ |
5664 [self registerLoadRequest:[self currentNavigationURL] | 5671 web::NavigationItem* item = [self currentNavItem]; |
| 5672 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| 5673 [self registerLoadRequest:navigationURL |
5665 referrer:[self currentSessionEntryReferrer] | 5674 referrer:[self currentSessionEntryReferrer] |
5666 transition:[self currentTransition]]; | 5675 transition:[self currentTransition]]; |
5667 [self loadRequest:request]; | 5676 [self loadRequest:request]; |
5668 }; | 5677 }; |
5669 | 5678 |
5670 // When navigating via WKBackForwardListItem to pages created or updated by | 5679 // When navigating via WKBackForwardListItem to pages created or updated by |
5671 // calls to pushState() and replaceState(), sometimes core.js is not injected | 5680 // calls to pushState() and replaceState(), sometimes core.js is not injected |
5672 // correctly. This means that calling window.history navigation functions | 5681 // correctly. This means that calling window.history navigation functions |
5673 // will invoke WKWebView's non-overridden implementations, causing a mismatch | 5682 // will invoke WKWebView's non-overridden implementations, causing a mismatch |
5674 // between the WKBackForwardList and NavigationManager. | 5683 // between the WKBackForwardList and NavigationManager. |
(...skipping 12 matching lines...) Expand all Loading... |
5687 ![self isBackForwardListItemValid:holder->back_forward_list_item()]) { | 5696 ![self isBackForwardListItemValid:holder->back_forward_list_item()]) { |
5688 defaultNavigationBlock(); | 5697 defaultNavigationBlock(); |
5689 return; | 5698 return; |
5690 } | 5699 } |
5691 | 5700 |
5692 ProceduralBlock webViewNavigationBlock = ^{ | 5701 ProceduralBlock webViewNavigationBlock = ^{ |
5693 // If the current navigation URL is the same as the URL of the visible | 5702 // If the current navigation URL is the same as the URL of the visible |
5694 // page, that means the user requested a reload. |goToBackForwardListItem| | 5703 // page, that means the user requested a reload. |goToBackForwardListItem| |
5695 // will be a no-op when it is passed the current back forward list item, | 5704 // will be a no-op when it is passed the current back forward list item, |
5696 // so |reload| must be explicitly called. | 5705 // so |reload| must be explicitly called. |
5697 [self registerLoadRequest:[self currentNavigationURL] | 5706 web::NavigationItem* item = [self currentNavItem]; |
| 5707 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| 5708 [self registerLoadRequest:navigationURL |
5698 referrer:[self currentSessionEntryReferrer] | 5709 referrer:[self currentSessionEntryReferrer] |
5699 transition:[self currentTransition]]; | 5710 transition:[self currentTransition]]; |
5700 if ([self currentNavigationURL] == net::GURLWithNSURL([_webView URL])) { | 5711 if (navigationURL == net::GURLWithNSURL([_webView URL])) { |
5701 [_webView reload]; | 5712 [_webView reload]; |
5702 } else { | 5713 } else { |
5703 // |didCommitNavigation:| may not be called for fast navigation, so update | 5714 // |didCommitNavigation:| may not be called for fast navigation, so update |
5704 // the navigation type now as it is already known. | 5715 // the navigation type now as it is already known. |
5705 holder->set_navigation_type(WKNavigationTypeBackForward); | 5716 holder->set_navigation_type(WKNavigationTypeBackForward); |
5706 [_webView goToBackForwardListItem:holder->back_forward_list_item()]; | 5717 [_webView goToBackForwardListItem:holder->back_forward_list_item()]; |
5707 } | 5718 } |
5708 }; | 5719 }; |
5709 | 5720 |
5710 // If the request is not a form submission or resubmission, or the user | 5721 // If the request is not a form submission or resubmission, or the user |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5802 } | 5813 } |
5803 | 5814 |
5804 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5815 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
5805 } | 5816 } |
5806 | 5817 |
5807 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5818 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
5808 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5819 return [action.request valueForHTTPHeaderField:@"Referer"]; |
5809 } | 5820 } |
5810 | 5821 |
5811 @end | 5822 @end |
OLD | NEW |