| 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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 // TODO(stuartmorgan): Move the pushState/replaceState logic into | 695 // TODO(stuartmorgan): Move the pushState/replaceState logic into |
| 696 // NavigationManager. | 696 // NavigationManager. |
| 697 - (void)pushStateWithPageURL:(const GURL&)pageURL | 697 - (void)pushStateWithPageURL:(const GURL&)pageURL |
| 698 stateObject:(NSString*)stateObject | 698 stateObject:(NSString*)stateObject |
| 699 transition:(ui::PageTransition)transition; | 699 transition:(ui::PageTransition)transition; |
| 700 // Assigns the given URL and state object to the current CRWSessionEntry. | 700 // Assigns the given URL and state object to the current CRWSessionEntry. |
| 701 - (void)replaceStateWithPageURL:(const GURL&)pageUrl | 701 - (void)replaceStateWithPageURL:(const GURL&)pageUrl |
| 702 stateObject:(NSString*)stateObject; | 702 stateObject:(NSString*)stateObject; |
| 703 // Sets _documentURL to newURL, and updates any relevant state information. | 703 // Sets _documentURL to newURL, and updates any relevant state information. |
| 704 - (void)setDocumentURL:(const GURL&)newURL; | 704 - (void)setDocumentURL:(const GURL&)newURL; |
| 705 // Sets last committed NavigationItem's title to the given |title|, which can | |
| 706 // not be nil. | |
| 707 - (void)setNavigationItemTitle:(NSString*)title; | |
| 708 // Returns YES if the current navigation item corresponds to a web page | 705 // Returns YES if the current navigation item corresponds to a web page |
| 709 // loaded by a POST request. | 706 // loaded by a POST request. |
| 710 - (BOOL)isCurrentNavigationItemPOST; | 707 - (BOOL)isCurrentNavigationItemPOST; |
| 711 // Returns YES if current navigation item is WKNavigationTypeBackForward. | 708 // Returns YES if current navigation item is WKNavigationTypeBackForward. |
| 712 - (BOOL)isCurrentNavigationBackForward; | 709 - (BOOL)isCurrentNavigationBackForward; |
| 713 // Returns whether the given navigation is triggered by a user link click. | 710 // Returns whether the given navigation is triggered by a user link click. |
| 714 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType; | 711 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType; |
| 715 | 712 |
| 716 // Inject windowID if not yet injected. | 713 // Inject windowID if not yet injected. |
| 717 - (void)injectWindowID; | 714 - (void)injectWindowID; |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 [self didUpdateHistoryStateWithPageURL:pageUrl]; | 1361 [self didUpdateHistoryStateWithPageURL:pageUrl]; |
| 1365 } | 1362 } |
| 1366 | 1363 |
| 1367 - (void)setDocumentURL:(const GURL&)newURL { | 1364 - (void)setDocumentURL:(const GURL&)newURL { |
| 1368 if (newURL != _documentURL && newURL.is_valid()) { | 1365 if (newURL != _documentURL && newURL.is_valid()) { |
| 1369 _documentURL = newURL; | 1366 _documentURL = newURL; |
| 1370 _interactionRegisteredSinceLastURLChange = NO; | 1367 _interactionRegisteredSinceLastURLChange = NO; |
| 1371 } | 1368 } |
| 1372 } | 1369 } |
| 1373 | 1370 |
| 1374 - (void)setNavigationItemTitle:(NSString*)title { | |
| 1375 DCHECK(title); | |
| 1376 auto& navigationManager = _webStateImpl->GetNavigationManagerImpl(); | |
| 1377 web::NavigationItem* item = navigationManager.GetLastCommittedItem(); | |
| 1378 if (!item) | |
| 1379 return; | |
| 1380 | |
| 1381 base::string16 newTitle = base::SysNSStringToUTF16(title); | |
| 1382 if (item->GetTitle() == newTitle) | |
| 1383 return; | |
| 1384 | |
| 1385 item->SetTitle(newTitle); | |
| 1386 // TODO(crbug.com/546218): See if this can be removed; it's not clear that | |
| 1387 // other platforms send this (tab sync triggers need to be compared against | |
| 1388 // upstream). | |
| 1389 navigationManager.OnNavigationItemChanged(); | |
| 1390 | |
| 1391 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) { | |
| 1392 [_delegate webController:self titleDidChange:title]; | |
| 1393 } | |
| 1394 } | |
| 1395 | |
| 1396 - (BOOL)isCurrentNavigationItemPOST { | 1371 - (BOOL)isCurrentNavigationItemPOST { |
| 1397 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods | 1372 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods |
| 1398 // were not called. | 1373 // were not called. |
| 1399 NSString* HTTPMethod = | 1374 NSString* HTTPMethod = |
| 1400 _pendingNavigationInfo | 1375 _pendingNavigationInfo |
| 1401 ? [_pendingNavigationInfo HTTPMethod] | 1376 ? [_pendingNavigationInfo HTTPMethod] |
| 1402 : [self currentBackForwardListItemHolder]->http_method(); | 1377 : [self currentBackForwardListItemHolder]->http_method(); |
| 1403 return [HTTPMethod isEqual:@"POST"]; | 1378 return [HTTPMethod isEqual:@"POST"]; |
| 1404 } | 1379 } |
| 1405 | 1380 |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 } | 1785 } |
| 1811 | 1786 |
| 1812 - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess { | 1787 - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess { |
| 1813 const GURL currentURL([self currentURL]); | 1788 const GURL currentURL([self currentURL]); |
| 1814 [self didStartLoadingURL:currentURL updateHistory:loadSuccess]; | 1789 [self didStartLoadingURL:currentURL updateHistory:loadSuccess]; |
| 1815 _loadPhase = web::PAGE_LOADED; | 1790 _loadPhase = web::PAGE_LOADED; |
| 1816 | 1791 |
| 1817 // Perform post-load-finished updates. | 1792 // Perform post-load-finished updates. |
| 1818 [self didFinishWithURL:currentURL loadSuccess:loadSuccess]; | 1793 [self didFinishWithURL:currentURL loadSuccess:loadSuccess]; |
| 1819 | 1794 |
| 1820 NSString* title = [self.nativeController title]; | 1795 // Inform the embedder the title changed. |
| 1821 if (title) | |
| 1822 [self setNavigationItemTitle:title]; | |
| 1823 | |
| 1824 // If the controller handles title change notification, route those to the | |
| 1825 // delegate. | |
| 1826 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) { | 1796 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) { |
| 1797 NSString* title = [self.nativeController title]; |
| 1798 // If a title is present, notify the delegate. |
| 1799 if (title) |
| 1800 [_delegate webController:self titleDidChange:title]; |
| 1801 // If the controller handles title change notification, route those to the |
| 1802 // delegate. |
| 1827 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { | 1803 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { |
| 1828 [self.nativeController setDelegate:self]; | 1804 [self.nativeController setDelegate:self]; |
| 1829 } | 1805 } |
| 1830 } | 1806 } |
| 1831 } | 1807 } |
| 1832 | 1808 |
| 1833 - (void)loadErrorInNativeView:(NSError*)error { | 1809 - (void)loadErrorInNativeView:(NSError*)error { |
| 1834 [self removeWebViewAllowingCachedReconstruction:NO]; | 1810 [self removeWebViewAllowingCachedReconstruction:NO]; |
| 1835 web::NavigationItem* item = [self currentNavItem]; | 1811 web::NavigationItem* item = [self currentNavItem]; |
| 1836 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 1812 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| (...skipping 2954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4791 [self injectWindowID]; | 4767 [self injectWindowID]; |
| 4792 } | 4768 } |
| 4793 | 4769 |
| 4794 [self webPageChanged]; | 4770 [self webPageChanged]; |
| 4795 | 4771 |
| 4796 [self updateSSLStatusForCurrentNavigationItem]; | 4772 [self updateSSLStatusForCurrentNavigationItem]; |
| 4797 | 4773 |
| 4798 // Attempt to update the HTML5 history state. | 4774 // Attempt to update the HTML5 history state. |
| 4799 [self updateHTML5HistoryState]; | 4775 [self updateHTML5HistoryState]; |
| 4800 | 4776 |
| 4801 // This is the point where pending entry has been committed, and navigation | |
| 4802 // item title should be updated. | |
| 4803 [self setNavigationItemTitle:[_webView title]]; | |
| 4804 | |
| 4805 // Report cases where SSL cert is missing for a secure connection. | 4777 // Report cases where SSL cert is missing for a secure connection. |
| 4806 if (_documentURL.SchemeIsCryptographic()) { | 4778 if (_documentURL.SchemeIsCryptographic()) { |
| 4807 scoped_refptr<net::X509Certificate> cert = | 4779 scoped_refptr<net::X509Certificate> cert = |
| 4808 web::CreateCertFromChain([_webView certificateChain]); | 4780 web::CreateCertFromChain([_webView certificateChain]); |
| 4809 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", | 4781 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", |
| 4810 static_cast<bool>(cert)); | 4782 static_cast<bool>(cert)); |
| 4811 } | 4783 } |
| 4812 } | 4784 } |
| 4813 | 4785 |
| 4814 - (void)webView:(WKWebView*)webView | 4786 - (void)webView:(WKWebView*)webView |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4990 } | 4962 } |
| 4991 | 4963 |
| 4992 - (void)webViewTitleDidChange { | 4964 - (void)webViewTitleDidChange { |
| 4993 // WKWebView's title becomes empty when the web process dies; ignore that | 4965 // WKWebView's title becomes empty when the web process dies; ignore that |
| 4994 // update. | 4966 // update. |
| 4995 if (_webProcessIsDead) { | 4967 if (_webProcessIsDead) { |
| 4996 DCHECK_EQ([_webView title].length, 0U); | 4968 DCHECK_EQ([_webView title].length, 0U); |
| 4997 return; | 4969 return; |
| 4998 } | 4970 } |
| 4999 | 4971 |
| 5000 bool hasPendingNavigation = web::WKNavigationState::COMMITTED <= | 4972 if ([self.delegate |
| 5001 [_navigationStates lastAddedNavigationState]; | 4973 respondsToSelector:@selector(webController:titleDidChange:)]) { |
| 5002 if (hasPendingNavigation) { | 4974 DCHECK([_webView title]); |
| 5003 // Do not update the title if there is a navigation in progress because | 4975 [self.delegate webController:self titleDidChange:[_webView title]]; |
| 5004 // there is no way to tell if KVO change fired for new or previous page. | |
| 5005 [self setNavigationItemTitle:[_webView title]]; | |
| 5006 } | 4976 } |
| 5007 } | 4977 } |
| 5008 | 4978 |
| 5009 - (void)webViewURLDidChange { | 4979 - (void)webViewURLDidChange { |
| 5010 // TODO(stuartmorgan): Determine if there are any cases where this still | 4980 // TODO(stuartmorgan): Determine if there are any cases where this still |
| 5011 // happens, and if so whether anything should be done when it does. | 4981 // happens, and if so whether anything should be done when it does. |
| 5012 if (![_webView URL]) { | 4982 if (![_webView URL]) { |
| 5013 DVLOG(1) << "Received nil URL callback"; | 4983 DVLOG(1) << "Received nil URL callback"; |
| 5014 return; | 4984 return; |
| 5015 } | 4985 } |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5314 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5284 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
| 5315 _lastRegisteredRequestURL = URL; | 5285 _lastRegisteredRequestURL = URL; |
| 5316 _loadPhase = web::LOAD_REQUESTED; | 5286 _loadPhase = web::LOAD_REQUESTED; |
| 5317 } | 5287 } |
| 5318 | 5288 |
| 5319 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5289 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
| 5320 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5290 return [action.request valueForHTTPHeaderField:@"Referer"]; |
| 5321 } | 5291 } |
| 5322 | 5292 |
| 5323 @end | 5293 @end |
| OLD | NEW |