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