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