Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 2581193002: Remove CRWWebController currentNavigationURL (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
Eugene But (OOO till 7-30) 2016/12/16 17:12:48 s/navigationURL/targetURL and drop |targetURL| var
Olivier 2016/12/19 09:51:48 Done.
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]); 1838 const GURL targetURL(navigationURL);
1839 if (!targetURL.is_valid()) { 1839 if (!targetURL.is_valid()) {
1840 [self didFinishWithURL:targetURL loadSuccess:NO]; 1840 [self didFinishWithURL:targetURL loadSuccess:NO];
1841 return; 1841 return;
1842 } 1842 }
1843 1843
1844 // JavaScript should never be evaluated here. User-entered JS should be 1844 // JavaScript should never be evaluated here. User-entered JS should be
1845 // evaluated via stringByEvaluatingUserJavaScriptFromString. 1845 // evaluated via stringByEvaluatingUserJavaScriptFromString.
1846 DCHECK(!targetURL.SchemeIs(url::kJavaScriptScheme)); 1846 DCHECK(!targetURL.SchemeIs(url::kJavaScriptScheme));
1847 1847
1848 [self ensureWebViewCreated]; 1848 [self ensureWebViewCreated];
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 if ([_pendingNavigationInfo MIMEType]) { 1880 if ([_pendingNavigationInfo MIMEType]) {
1881 self.webStateImpl->SetContentsMimeType( 1881 self.webStateImpl->SetContentsMimeType(
1882 base::SysNSStringToUTF8([_pendingNavigationInfo MIMEType])); 1882 base::SysNSStringToUTF8([_pendingNavigationInfo MIMEType]));
1883 } 1883 }
1884 [self updateCurrentBackForwardListItemHolder]; 1884 [self updateCurrentBackForwardListItemHolder];
1885 1885
1886 _pendingNavigationInfo.reset(); 1886 _pendingNavigationInfo.reset();
1887 } 1887 }
1888 1888
1889 - (NSMutableURLRequest*)requestForCurrentNavigationItem { 1889 - (NSMutableURLRequest*)requestForCurrentNavigationItem {
1890 const GURL currentNavigationURL([self currentNavigationURL]); 1890 web::NavigationItem* item = [self currentNavItem];
1891 const GURL currentNavigationURL =
1892 item ? item->GetVirtualURL() : GURL::EmptyGURL();
1891 NSMutableURLRequest* request = [NSMutableURLRequest 1893 NSMutableURLRequest* request = [NSMutableURLRequest
1892 requestWithURL:net::NSURLWithGURL(currentNavigationURL)]; 1894 requestWithURL:net::NSURLWithGURL(currentNavigationURL)];
1893 const web::Referrer referrer([self currentSessionEntryReferrer]); 1895 const web::Referrer referrer([self currentSessionEntryReferrer]);
1894 if (referrer.url.is_valid()) { 1896 if (referrer.url.is_valid()) {
1895 std::string referrerValue = 1897 std::string referrerValue =
1896 web::ReferrerHeaderValueForNavigation(currentNavigationURL, referrer); 1898 web::ReferrerHeaderValueForNavigation(currentNavigationURL, referrer);
1897 if (!referrerValue.empty()) { 1899 if (!referrerValue.empty()) {
1898 [request setValue:base::SysUTF8ToNSString(referrerValue) 1900 [request setValue:base::SysUTF8ToNSString(referrerValue)
1899 forHTTPHeaderField:kReferrerHeaderName]; 1901 forHTTPHeaderField:kReferrerHeaderName];
1900 } 1902 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 // If the controller handles title change notification, route those to the 1967 // If the controller handles title change notification, route those to the
1966 // delegate. 1968 // delegate.
1967 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { 1969 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) {
1968 [self.nativeController setDelegate:self]; 1970 [self.nativeController setDelegate:self];
1969 } 1971 }
1970 } 1972 }
1971 } 1973 }
1972 1974
1973 - (void)loadErrorInNativeView:(NSError*)error { 1975 - (void)loadErrorInNativeView:(NSError*)error {
1974 [self removeWebViewAllowingCachedReconstruction:NO]; 1976 [self removeWebViewAllowingCachedReconstruction:NO];
1975 1977 web::NavigationItem* item = [self currentNavItem];
1976 const GURL currentUrl = [self currentNavigationURL]; 1978 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
1977 1979
1978 if (web::IsWKWebViewSSLCertError(error)) { 1980 if (web::IsWKWebViewSSLCertError(error)) {
1979 // This could happen only if certificate is absent or could not be parsed. 1981 // 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); 1982 error = web::NetErrorFromError(error, net::ERR_SSL_SERVER_CERT_BAD_FORMAT);
1981 #if defined(DEBUG) 1983 #if defined(DEBUG)
1982 net::SSLInfo info; 1984 net::SSLInfo info;
1983 web::GetSSLInfoFromWKWebViewSSLCertError(error, &info); 1985 web::GetSSLInfoFromWKWebViewSSLCertError(error, &info);
1984 CHECK(!error.cert); 1986 CHECK(!error.cert);
1985 #endif 1987 #endif
1986 } else { 1988 } else {
1987 error = web::NetErrorFromError(error); 1989 error = web::NetErrorFromError(error);
1988 } 1990 }
1989 1991
1990 BOOL isPost = [self isCurrentNavigationItemPOST]; 1992 BOOL isPost = [self isCurrentNavigationItemPOST];
1991 [self setNativeController:[_nativeProvider controllerForURL:currentUrl 1993 [self setNativeController:[_nativeProvider controllerForURL:currentURL
1992 withError:error 1994 withError:error
1993 isPost:isPost]]; 1995 isPost:isPost]];
1994 [self loadNativeViewWithSuccess:NO]; 1996 [self loadNativeViewWithSuccess:NO];
1995 } 1997 }
1996 1998
1997 // Load the current URL in a native controller, retrieved from the native 1999 // Load the current URL in a native controller, retrieved from the native
1998 // provider. Call |loadNativeViewWithSuccess:YES| to load the native controller. 2000 // provider. Call |loadNativeViewWithSuccess:YES| to load the native controller.
1999 - (void)loadCurrentURLInNativeView { 2001 - (void)loadCurrentURLInNativeView {
2000 // Free the web view. 2002 // Free the web view.
2001 [self removeWebViewAllowingCachedReconstruction:NO]; 2003 [self removeWebViewAllowingCachedReconstruction:NO];
2002 2004
2003 const GURL targetURL = [self currentNavigationURL]; 2005 web::NavigationItem* item = [self currentNavItem];
2006 const GURL targetURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
2004 const web::Referrer referrer; 2007 const web::Referrer referrer;
2005 id<CRWNativeContent> nativeContent = 2008 id<CRWNativeContent> nativeContent =
2006 [_nativeProvider controllerForURL:targetURL]; 2009 [_nativeProvider controllerForURL:targetURL];
2007 // Unlike the WebView case, always create a new controller and view. 2010 // Unlike the WebView case, always create a new controller and view.
2008 // TODO(pinkerton): What to do if this does return nil? 2011 // TODO(pinkerton): What to do if this does return nil?
2009 [self setNativeController:nativeContent]; 2012 [self setNativeController:nativeContent];
2010 if ([nativeContent respondsToSelector:@selector(virtualURL)]) { 2013 if ([nativeContent respondsToSelector:@selector(virtualURL)]) {
2011 [self currentNavItem]->SetVirtualURL([nativeContent virtualURL]); 2014 [self currentNavItem]->SetVirtualURL([nativeContent virtualURL]);
Eugene But (OOO till 7-30) 2016/12/16 17:12:48 nit: s/[self currentNavItem]/item
Olivier 2016/12/19 09:51:48 Done.
2012 } 2015 }
2013 [self registerLoadRequest:targetURL 2016 [self registerLoadRequest:targetURL
2014 referrer:referrer 2017 referrer:referrer
2015 transition:[self currentTransition]]; 2018 transition:[self currentTransition]];
2016 [self loadNativeViewWithSuccess:YES]; 2019 [self loadNativeViewWithSuccess:YES];
2017 } 2020 }
2018 2021
2019 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)originalParams { 2022 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)originalParams {
2020 // Make a copy of |params|, as some of the delegate methods may modify it. 2023 // Make a copy of |params|, as some of the delegate methods may modify it.
2021 NavigationManager::WebLoadParams params(originalParams); 2024 NavigationManager::WebLoadParams params(originalParams);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 2092
2090 // Abort any outstanding page load. This ensures the delegate gets informed 2093 // Abort any outstanding page load. This ensures the delegate gets informed
2091 // about the outgoing page, and further messages from the page are suppressed. 2094 // about the outgoing page, and further messages from the page are suppressed.
2092 if (_loadPhase != web::PAGE_LOADED) 2095 if (_loadPhase != web::PAGE_LOADED)
2093 [self abortLoad]; 2096 [self abortLoad];
2094 2097
2095 DCHECK(!_isHalted); 2098 DCHECK(!_isHalted);
2096 // Remove the transient content view. 2099 // Remove the transient content view.
2097 [self clearTransientContentView]; 2100 [self clearTransientContentView];
2098 2101
2099 const GURL currentURL = [self currentNavigationURL]; 2102 web::NavigationItem* item = [self currentNavItem];
2103 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
2100 // If it's a chrome URL, but not a native one, create the WebUI instance. 2104 // If it's a chrome URL, but not a native one, create the WebUI instance.
2101 if (web::GetWebClient()->IsAppSpecificURL(currentURL) && 2105 if (web::GetWebClient()->IsAppSpecificURL(currentURL) &&
2102 ![_nativeProvider hasControllerForURL:currentURL]) { 2106 ![_nativeProvider hasControllerForURL:currentURL]) {
2103 web::NavigationItem* item = [self currentNavItem]; 2107 web::NavigationItem* item = [self currentNavItem];
Eugene But (OOO till 7-30) 2016/12/16 17:12:48 Please drop this.
Olivier 2016/12/19 09:51:48 Done.
2104 if (!(item->GetTransitionType() & ui::PAGE_TRANSITION_TYPED || 2108 if (!(item->GetTransitionType() & ui::PAGE_TRANSITION_TYPED ||
2105 item->GetTransitionType() & ui::PAGE_TRANSITION_AUTO_BOOKMARK) && 2109 item->GetTransitionType() & ui::PAGE_TRANSITION_AUTO_BOOKMARK) &&
2106 self.sessionController.openedByDOM) { 2110 self.sessionController.openedByDOM) {
2107 // WebUI URLs can not be opened by DOM to prevent cross-site scripting as 2111 // 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 2112 // they have increased power. WebUI URLs may only be opened when the user
2109 // types in the URL or use bookmarks. 2113 // types in the URL or use bookmarks.
2110 [[self sessionController] discardNonCommittedEntries]; 2114 [[self sessionController] discardNonCommittedEntries];
2111 return; 2115 return;
2112 } else { 2116 } else {
2113 [self createWebUIForURL:currentURL]; 2117 [self createWebUIForURL:currentURL];
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 CGRect containerViewFrame = 2160 CGRect containerViewFrame =
2157 [UIApplication sharedApplication].keyWindow.bounds; 2161 [UIApplication sharedApplication].keyWindow.bounds;
2158 containerViewFrame.origin.y += statusBarHeight; 2162 containerViewFrame.origin.y += statusBarHeight;
2159 containerViewFrame.size.height -= statusBarHeight; 2163 containerViewFrame.size.height -= statusBarHeight;
2160 _containerView.get().frame = containerViewFrame; 2164 _containerView.get().frame = containerViewFrame;
2161 DCHECK(!CGRectIsEmpty(_containerView.get().frame)); 2165 DCHECK(!CGRectIsEmpty(_containerView.get().frame));
2162 2166
2163 [_containerView addGestureRecognizer:[self touchTrackingRecognizer]]; 2167 [_containerView addGestureRecognizer:[self touchTrackingRecognizer]];
2164 [_containerView setAccessibilityIdentifier:web::kContainerViewID]; 2168 [_containerView setAccessibilityIdentifier:web::kContainerViewID];
2165 // Is |currentUrl| a web scheme or native chrome scheme. 2169 // Is |currentUrl| a web scheme or native chrome scheme.
2170 web::NavigationItem* item = [self currentNavItem];
2171 const GURL currentNavigationURL =
2172 item ? item->GetVirtualURL() : GURL::EmptyGURL();
2166 BOOL isChromeScheme = 2173 BOOL isChromeScheme =
2167 web::GetWebClient()->IsAppSpecificURL([self currentNavigationURL]); 2174 web::GetWebClient()->IsAppSpecificURL(currentNavigationURL);
2168 2175
2169 // Don't immediately load the web page if in overlay mode. Always load if 2176 // Don't immediately load the web page if in overlay mode. Always load if
2170 // native. 2177 // native.
2171 if (isChromeScheme || !_overlayPreviewMode) { 2178 if (isChromeScheme || !_overlayPreviewMode) {
2172 // TODO(jimblackler): end the practice of calling |loadCurrentURL| when it 2179 // TODO(jimblackler): end the practice of calling |loadCurrentURL| when it
2173 // is possible there is no current URL. If the call performs necessary 2180 // is possible there is no current URL. If the call performs necessary
2174 // initialization, break that out. 2181 // initialization, break that out.
2175 [self loadCurrentURL]; 2182 [self loadCurrentURL];
2176 } 2183 }
2177 2184
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
3395 3402
3396 // Check if the link navigation leads to a launch of an external app. 3403 // 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 3404 // TODO(crbug.com/607780): Revise the logic of allowing external app launch
3398 // and move it to externalAppLauncher. 3405 // and move it to externalAppLauncher.
3399 BOOL isOpenInNewTabNavigation = 3406 BOOL isOpenInNewTabNavigation =
3400 !_webStateImpl->GetNavigationManager()->GetItemCount(); 3407 !_webStateImpl->GetNavigationManager()->GetItemCount();
3401 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType]; 3408 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType];
3402 if (isPossibleLinkClick || isOpenInNewTabNavigation || 3409 if (isPossibleLinkClick || isOpenInNewTabNavigation ||
3403 PageTransitionCoreTypeIs([self currentTransition], 3410 PageTransitionCoreTypeIs([self currentTransition],
3404 ui::PAGE_TRANSITION_AUTO_BOOKMARK)) { 3411 ui::PAGE_TRANSITION_AUTO_BOOKMARK)) {
3412 web::NavigationItem* item = [self currentNavItem];
3413 const GURL currentNavigationURL =
3414 item ? item->GetVirtualURL() : GURL::EmptyGURL();
3405 // Check If the URL is handled by a native app. 3415 // Check If the URL is handled by a native app.
3406 if ([self urlTriggersNativeAppLaunch:requestURL 3416 if ([self urlTriggersNativeAppLaunch:requestURL
3407 sourceURL:[self currentNavigationURL] 3417 sourceURL:currentNavigationURL
3408 linkActivatedNavigation:isNavigationTypeLinkActivated]) { 3418 linkActivatedNavigation:isNavigationTypeLinkActivated]) {
3409 // External app has been launched successfully. Stop the current page 3419 // External app has been launched successfully. Stop the current page
3410 // load operation (e.g. notifying all observers) and record the URL so 3420 // load operation (e.g. notifying all observers) and record the URL so
3411 // that errors reported following the 'NO' reply can be safely ignored. 3421 // that errors reported following the 'NO' reply can be safely ignored.
3412 if ([self shouldClosePageOnNativeApplicationLoad]) 3422 if ([self shouldClosePageOnNativeApplicationLoad])
3413 [_delegate webPageOrderedClose]; 3423 [_delegate webPageOrderedClose];
3414 [self stopLoading]; 3424 [self stopLoading];
3415 [_openedApplicationURL addObject:request.URL]; 3425 [_openedApplicationURL addObject:request.URL];
3416 return NO; 3426 return NO;
3417 } 3427 }
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
3755 sourceURL:)]) { 3765 sourceURL:)]) {
3756 return NO; 3766 return NO;
3757 } 3767 }
3758 return [_delegate webController:self 3768 return [_delegate webController:self
3759 shouldBlockPopupWithURL:popupURL 3769 shouldBlockPopupWithURL:popupURL
3760 sourceURL:sourceURL]; 3770 sourceURL:sourceURL];
3761 } 3771 }
3762 3772
3763 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo { 3773 - (void)openPopupWithInfo:(const web::NewWindowInfo&)windowInfo {
3764 const GURL url(windowInfo.url); 3774 const GURL url(windowInfo.url);
3765 const GURL currentURL([self currentNavigationURL]); 3775 web::NavigationItem* item = [self currentNavItem];
3776 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
3766 NSString* windowName = windowInfo.window_name.get(); 3777 NSString* windowName = windowInfo.window_name.get();
3767 web::Referrer referrer(currentURL, windowInfo.referrer_policy); 3778 web::Referrer referrer(currentURL, windowInfo.referrer_policy);
3768 base::WeakNSObject<CRWWebController> weakSelf(self); 3779 base::WeakNSObject<CRWWebController> weakSelf(self);
3769 void (^showPopupHandler)() = ^{ 3780 void (^showPopupHandler)() = ^{
3770 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url 3781 CRWWebController* child = [[weakSelf delegate] webPageOrderedOpen:url
3771 referrer:referrer 3782 referrer:referrer
3772 windowName:windowName 3783 windowName:windowName
3773 inBackground:NO]; 3784 inBackground:NO];
3774 DCHECK(!child || child.sessionController.openedByDOM); 3785 DCHECK(!child || child.sessionController.openedByDOM);
3775 }; 3786 };
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
4041 - (web::NavigationItem*)currentNavItem { 4052 - (web::NavigationItem*)currentNavItem {
4042 // This goes through the legacy Session* interface rather than Navigation* 4053 // This goes through the legacy Session* interface rather than Navigation*
4043 // because it is itself a legacy method that should not exist, and this 4054 // 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 4055 // avoids needing to add a GetActiveItem to NavigationManager. If/when this
4045 // method chain becomes a blocker to eliminating SessionController, the logic 4056 // method chain becomes a blocker to eliminating SessionController, the logic
4046 // can be moved here, using public NavigationManager getters. That's not 4057 // can be moved here, using public NavigationManager getters. That's not
4047 // done now in order to avoid code duplication. 4058 // done now in order to avoid code duplication.
4048 return [[self currentSessionEntry] navigationItem]; 4059 return [[self currentSessionEntry] navigationItem];
4049 } 4060 }
4050 4061
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 { 4062 - (ui::PageTransition)currentTransition {
4060 if ([self currentNavItem]) 4063 if ([self currentNavItem])
4061 return [self currentNavItem]->GetTransitionType(); 4064 return [self currentNavItem]->GetTransitionType();
4062 else 4065 else
4063 return ui::PageTransitionFromInt(0); 4066 return ui::PageTransitionFromInt(0);
4064 } 4067 }
4065 4068
4066 - (web::Referrer)currentSessionEntryReferrer { 4069 - (web::Referrer)currentSessionEntryReferrer {
4067 web::NavigationItem* currentItem = [self currentNavItem]; 4070 web::NavigationItem* currentItem = [self currentNavItem];
4068 return currentItem ? currentItem->GetReferrer() : web::Referrer(); 4071 return currentItem ? currentItem->GetReferrer() : web::Referrer();
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
4812 4815
4813 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { 4816 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache {
4814 if (!_webView) 4817 if (!_webView)
4815 return; 4818 return;
4816 4819
4817 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); 4820 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:);
4818 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) 4821 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector])
4819 [self.UIDelegate cancelDialogsForWebController:self]; 4822 [self.UIDelegate cancelDialogsForWebController:self];
4820 _webStateImpl->CancelDialogs(); 4823 _webStateImpl->CancelDialogs();
4821 4824
4822 if (allowCache) 4825 if (allowCache) {
Eugene But (OOO till 7-30) 2016/12/16 17:12:48 How about this?: web::NavigationItem* item = [sel
Olivier 2016/12/19 09:51:48 Done.
4823 _expectedReconstructionURL = [self currentNavigationURL]; 4826 web::NavigationItem* item = [self currentNavItem];
4824 else 4827 _expectedReconstructionURL =
4828 item ? item->GetVirtualURL() : GURL::EmptyGURL();
4829 } else {
4825 _expectedReconstructionURL = GURL(); 4830 _expectedReconstructionURL = GURL();
4831 }
4826 4832
4827 [self abortLoad]; 4833 [self abortLoad];
4828 [_webView removeFromSuperview]; 4834 [_webView removeFromSuperview];
4829 [_containerView resetContent]; 4835 [_containerView resetContent];
4830 [self setWebView:nil]; 4836 [self setWebView:nil];
4831 } 4837 }
4832 4838
4833 - (void)webViewWebProcessDidCrash { 4839 - (void)webViewWebProcessDidCrash {
4834 _webProcessIsDead = YES; 4840 _webProcessIsDead = YES;
4835 4841
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
4905 } 4911 }
4906 4912
4907 - (void)stopLoading { 4913 - (void)stopLoading {
4908 _stoppedWKNavigation.reset(_latestWKNavigation); 4914 _stoppedWKNavigation.reset(_latestWKNavigation);
4909 4915
4910 base::RecordAction(UserMetricsAction("Stop")); 4916 base::RecordAction(UserMetricsAction("Stop"));
4911 // Discard the pending and transient entried before notifying the tab model 4917 // Discard the pending and transient entried before notifying the tab model
4912 // observers of the change via |-abortLoad|. 4918 // observers of the change via |-abortLoad|.
4913 [[self sessionController] discardNonCommittedEntries]; 4919 [[self sessionController] discardNonCommittedEntries];
4914 [self abortLoad]; 4920 [self abortLoad];
4921 web::NavigationItem* item = [self currentNavItem];
4922 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
4915 // If discarding the non-committed entries results in an app-specific URL, 4923 // If discarding the non-committed entries results in an app-specific URL,
4916 // reload it in its native view. 4924 // reload it in its native view.
4917 if (!self.nativeController && 4925 if (!self.nativeController &&
4918 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) { 4926 [self shouldLoadURLInNativeView:navigationURL]) {
4919 [self loadCurrentURLInNativeView]; 4927 [self loadCurrentURLInNativeView];
4920 } 4928 }
4921 } 4929 }
4922 4930
4923 #pragma mark - 4931 #pragma mark -
4924 #pragma mark WKUIDelegate Methods 4932 #pragma mark WKUIDelegate Methods
4925 4933
4926 - (WKWebView*)webView:(WKWebView*)webView 4934 - (WKWebView*)webView:(WKWebView*)webView
4927 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration 4935 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration
4928 forNavigationAction:(WKNavigationAction*)action 4936 forNavigationAction:(WKNavigationAction*)action
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
5646 [self currentSessionEntry].navigationItemImpl; 5654 [self currentSessionEntry].navigationItemImpl;
5647 NSData* POSTData = currentItem->GetPostData(); 5655 NSData* POSTData = currentItem->GetPostData();
5648 NSMutableURLRequest* request = [self requestForCurrentNavigationItem]; 5656 NSMutableURLRequest* request = [self requestForCurrentNavigationItem];
5649 5657
5650 // If the request has POST data and is not a form resubmission, configure and 5658 // If the request has POST data and is not a form resubmission, configure and
5651 // run the POST request. 5659 // run the POST request.
5652 if (POSTData.length && !isFormPOSTResubmission) { 5660 if (POSTData.length && !isFormPOSTResubmission) {
5653 [request setHTTPMethod:@"POST"]; 5661 [request setHTTPMethod:@"POST"];
5654 [request setHTTPBody:POSTData]; 5662 [request setHTTPBody:POSTData];
5655 [request setAllHTTPHeaderFields:[self currentHTTPHeaders]]; 5663 [request setAllHTTPHeaderFields:[self currentHTTPHeaders]];
5656 [self registerLoadRequest:[self currentNavigationURL] 5664 web::NavigationItem* item = [self currentNavItem];
Eugene But (OOO till 7-30) 2016/12/16 17:12:48 Do you need this variable? Can you use use |curren
Olivier 2016/12/19 09:51:48 Done.
5665 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
5666 [self registerLoadRequest:navigationURL
5657 referrer:[self currentSessionEntryReferrer] 5667 referrer:[self currentSessionEntryReferrer]
5658 transition:[self currentTransition]]; 5668 transition:[self currentTransition]];
5659 [self loadPOSTRequest:request]; 5669 [self loadPOSTRequest:request];
5660 return; 5670 return;
5661 } 5671 }
5662 5672
5663 ProceduralBlock defaultNavigationBlock = ^{ 5673 ProceduralBlock defaultNavigationBlock = ^{
5664 [self registerLoadRequest:[self currentNavigationURL] 5674 web::NavigationItem* item = [self currentNavItem];
5675 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
5676 [self registerLoadRequest:navigationURL
5665 referrer:[self currentSessionEntryReferrer] 5677 referrer:[self currentSessionEntryReferrer]
5666 transition:[self currentTransition]]; 5678 transition:[self currentTransition]];
5667 [self loadRequest:request]; 5679 [self loadRequest:request];
5668 }; 5680 };
5669 5681
5670 // When navigating via WKBackForwardListItem to pages created or updated by 5682 // When navigating via WKBackForwardListItem to pages created or updated by
5671 // calls to pushState() and replaceState(), sometimes core.js is not injected 5683 // calls to pushState() and replaceState(), sometimes core.js is not injected
5672 // correctly. This means that calling window.history navigation functions 5684 // correctly. This means that calling window.history navigation functions
5673 // will invoke WKWebView's non-overridden implementations, causing a mismatch 5685 // will invoke WKWebView's non-overridden implementations, causing a mismatch
5674 // between the WKBackForwardList and NavigationManager. 5686 // between the WKBackForwardList and NavigationManager.
(...skipping 12 matching lines...) Expand all
5687 ![self isBackForwardListItemValid:holder->back_forward_list_item()]) { 5699 ![self isBackForwardListItemValid:holder->back_forward_list_item()]) {
5688 defaultNavigationBlock(); 5700 defaultNavigationBlock();
5689 return; 5701 return;
5690 } 5702 }
5691 5703
5692 ProceduralBlock webViewNavigationBlock = ^{ 5704 ProceduralBlock webViewNavigationBlock = ^{
5693 // If the current navigation URL is the same as the URL of the visible 5705 // If the current navigation URL is the same as the URL of the visible
5694 // page, that means the user requested a reload. |goToBackForwardListItem| 5706 // 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, 5707 // will be a no-op when it is passed the current back forward list item,
5696 // so |reload| must be explicitly called. 5708 // so |reload| must be explicitly called.
5697 [self registerLoadRequest:[self currentNavigationURL] 5709 web::NavigationItem* item = [self currentNavItem];
5710 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
5711 [self registerLoadRequest:navigationURL
5698 referrer:[self currentSessionEntryReferrer] 5712 referrer:[self currentSessionEntryReferrer]
5699 transition:[self currentTransition]]; 5713 transition:[self currentTransition]];
5700 if ([self currentNavigationURL] == net::GURLWithNSURL([_webView URL])) { 5714 if (navigationURL == net::GURLWithNSURL([_webView URL])) {
5701 [_webView reload]; 5715 [_webView reload];
5702 } else { 5716 } else {
5703 // |didCommitNavigation:| may not be called for fast navigation, so update 5717 // |didCommitNavigation:| may not be called for fast navigation, so update
5704 // the navigation type now as it is already known. 5718 // the navigation type now as it is already known.
5705 holder->set_navigation_type(WKNavigationTypeBackForward); 5719 holder->set_navigation_type(WKNavigationTypeBackForward);
5706 [_webView goToBackForwardListItem:holder->back_forward_list_item()]; 5720 [_webView goToBackForwardListItem:holder->back_forward_list_item()];
5707 } 5721 }
5708 }; 5722 };
5709 5723
5710 // If the request is not a form submission or resubmission, or the user 5724 // 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
5802 } 5816 }
5803 5817
5804 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 5818 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
5805 } 5819 }
5806 5820
5807 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { 5821 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action {
5808 return [action.request valueForHTTPHeaderField:@"Referer"]; 5822 return [action.request valueForHTTPHeaderField:@"Referer"];
5809 } 5823 }
5810 5824
5811 @end 5825 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698