| 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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 // TODO(stuartmorgan): Move the pushState/replaceState logic into | 711 // TODO(stuartmorgan): Move the pushState/replaceState logic into |
| 712 // NavigationManager. | 712 // NavigationManager. |
| 713 - (void)pushStateWithPageURL:(const GURL&)pageURL | 713 - (void)pushStateWithPageURL:(const GURL&)pageURL |
| 714 stateObject:(NSString*)stateObject | 714 stateObject:(NSString*)stateObject |
| 715 transition:(ui::PageTransition)transition; | 715 transition:(ui::PageTransition)transition; |
| 716 // Assigns the given URL and state object to the current CRWSessionEntry. | 716 // Assigns the given URL and state object to the current CRWSessionEntry. |
| 717 - (void)replaceStateWithPageURL:(const GURL&)pageUrl | 717 - (void)replaceStateWithPageURL:(const GURL&)pageUrl |
| 718 stateObject:(NSString*)stateObject; | 718 stateObject:(NSString*)stateObject; |
| 719 // Sets _documentURL to newURL, and updates any relevant state information. | 719 // Sets _documentURL to newURL, and updates any relevant state information. |
| 720 - (void)setDocumentURL:(const GURL&)newURL; | 720 - (void)setDocumentURL:(const GURL&)newURL; |
| 721 // Sets WKWebView's title to the last committed navigation item. | |
| 722 - (void)updateNavigationItemTitle; | |
| 723 // Returns YES if the current navigation item corresponds to a web page | 721 // Returns YES if the current navigation item corresponds to a web page |
| 724 // loaded by a POST request. | 722 // loaded by a POST request. |
| 725 - (BOOL)isCurrentNavigationItemPOST; | 723 - (BOOL)isCurrentNavigationItemPOST; |
| 726 // Returns YES if current navigation item is WKNavigationTypeBackForward. | 724 // Returns YES if current navigation item is WKNavigationTypeBackForward. |
| 727 - (BOOL)isCurrentNavigationBackForward; | 725 - (BOOL)isCurrentNavigationBackForward; |
| 728 // Returns whether the given navigation is triggered by a user link click. | 726 // Returns whether the given navigation is triggered by a user link click. |
| 729 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType; | 727 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType; |
| 730 | 728 |
| 731 // Inject windowID if not yet injected. | 729 // Inject windowID if not yet injected. |
| 732 - (void)injectWindowID; | 730 - (void)injectWindowID; |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 [self didUpdateHistoryStateWithPageURL:pageUrl]; | 1372 [self didUpdateHistoryStateWithPageURL:pageUrl]; |
| 1375 } | 1373 } |
| 1376 | 1374 |
| 1377 - (void)setDocumentURL:(const GURL&)newURL { | 1375 - (void)setDocumentURL:(const GURL&)newURL { |
| 1378 if (newURL != _documentURL && newURL.is_valid()) { | 1376 if (newURL != _documentURL && newURL.is_valid()) { |
| 1379 _documentURL = newURL; | 1377 _documentURL = newURL; |
| 1380 _interactionRegisteredSinceLastURLChange = NO; | 1378 _interactionRegisteredSinceLastURLChange = NO; |
| 1381 } | 1379 } |
| 1382 } | 1380 } |
| 1383 | 1381 |
| 1384 - (void)updateNavigationItemTitle { | |
| 1385 NSString* webViewTitle = [_webView title]; | |
| 1386 DCHECK(webViewTitle); | |
| 1387 auto& navigationManager = _webStateImpl->GetNavigationManagerImpl(); | |
| 1388 web::NavigationItem* item = navigationManager.GetLastCommittedItem(); | |
| 1389 if (!item) | |
| 1390 return; | |
| 1391 | |
| 1392 base::string16 newTitle = base::SysNSStringToUTF16(webViewTitle); | |
| 1393 if (item->GetTitle() == newTitle) | |
| 1394 return; | |
| 1395 | |
| 1396 item->SetTitle(newTitle); | |
| 1397 // TODO(crbug.com/546218): See if this can be removed; it's not clear that | |
| 1398 // other platforms send this (tab sync triggers need to be compared against | |
| 1399 // upstream). | |
| 1400 navigationManager.OnNavigationItemChanged(); | |
| 1401 | |
| 1402 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) { | |
| 1403 [_delegate webController:self titleDidChange:webViewTitle]; | |
| 1404 } | |
| 1405 } | |
| 1406 | |
| 1407 - (BOOL)isCurrentNavigationItemPOST { | 1382 - (BOOL)isCurrentNavigationItemPOST { |
| 1408 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods | 1383 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods |
| 1409 // were not called. | 1384 // were not called. |
| 1410 NSString* HTTPMethod = | 1385 NSString* HTTPMethod = |
| 1411 _pendingNavigationInfo | 1386 _pendingNavigationInfo |
| 1412 ? [_pendingNavigationInfo HTTPMethod] | 1387 ? [_pendingNavigationInfo HTTPMethod] |
| 1413 : [self currentBackForwardListItemHolder]->http_method(); | 1388 : [self currentBackForwardListItemHolder]->http_method(); |
| 1414 return [HTTPMethod isEqual:@"POST"]; | 1389 return [HTTPMethod isEqual:@"POST"]; |
| 1415 } | 1390 } |
| 1416 | 1391 |
| (...skipping 3355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4772 } | 4747 } |
| 4773 | 4748 |
| 4774 - (void)webView:(WKWebView*)webView | 4749 - (void)webView:(WKWebView*)webView |
| 4775 didCommitNavigation:(WKNavigation*)navigation { | 4750 didCommitNavigation:(WKNavigation*)navigation { |
| 4776 [_navigationStates setState:web::WKNavigationState::COMMITTED | 4751 [_navigationStates setState:web::WKNavigationState::COMMITTED |
| 4777 forNavigation:navigation]; | 4752 forNavigation:navigation]; |
| 4778 | 4753 |
| 4779 DCHECK_EQ(_webView, webView); | 4754 DCHECK_EQ(_webView, webView); |
| 4780 _certVerificationErrors->Clear(); | 4755 _certVerificationErrors->Clear(); |
| 4781 | 4756 |
| 4782 // This is the point where the document's URL and title have actually changed, | 4757 // This is the point where the document's URL has actually changed, and |
| 4783 // and pending navigation information should be applied to state information. | 4758 // pending navigation information should be applied to state information. |
| 4784 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; | 4759 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; |
| 4785 [self updateNavigationItemTitle]; | |
| 4786 | 4760 |
| 4787 if (!_lastRegisteredRequestURL.is_valid() && | 4761 if (!_lastRegisteredRequestURL.is_valid() && |
| 4788 _documentURL != _lastRegisteredRequestURL) { | 4762 _documentURL != _lastRegisteredRequestURL) { |
| 4789 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL| | 4763 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL| |
| 4790 // will be "about:blank". | 4764 // will be "about:blank". |
| 4791 [[self sessionController] updatePendingItem:_documentURL]; | 4765 [[self sessionController] updatePendingItem:_documentURL]; |
| 4792 } | 4766 } |
| 4793 DCHECK(_documentURL == _lastRegisteredRequestURL || | 4767 DCHECK(_documentURL == _lastRegisteredRequestURL || |
| 4794 (!_lastRegisteredRequestURL.is_valid() && | 4768 (!_lastRegisteredRequestURL.is_valid() && |
| 4795 _documentURL.spec() == url::kAboutBlankURL)); | 4769 _documentURL.spec() == url::kAboutBlankURL)); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5013 } | 4987 } |
| 5014 | 4988 |
| 5015 - (void)webViewTitleDidChange { | 4989 - (void)webViewTitleDidChange { |
| 5016 // WKWebView's title becomes empty when the web process dies; ignore that | 4990 // WKWebView's title becomes empty when the web process dies; ignore that |
| 5017 // update. | 4991 // update. |
| 5018 if (_webProcessIsDead) { | 4992 if (_webProcessIsDead) { |
| 5019 DCHECK_EQ([_webView title].length, 0U); | 4993 DCHECK_EQ([_webView title].length, 0U); |
| 5020 return; | 4994 return; |
| 5021 } | 4995 } |
| 5022 | 4996 |
| 5023 bool hasPendingNavigation = web::WKNavigationState::COMMITTED <= | 4997 if ([self.delegate |
| 5024 [_navigationStates lastAddedNavigationState]; | 4998 respondsToSelector:@selector(webController:titleDidChange:)]) { |
| 5025 if (hasPendingNavigation) { | 4999 DCHECK([_webView title]); |
| 5026 // Do not update the title if there is a navigation in progress because | 5000 [self.delegate webController:self titleDidChange:[_webView title]]; |
| 5027 // there is no way to tell if KVO change fired for new or previous page. | |
| 5028 [self updateNavigationItemTitle]; | |
| 5029 } | 5001 } |
| 5030 } | 5002 } |
| 5031 | 5003 |
| 5032 - (void)webViewURLDidChange { | 5004 - (void)webViewURLDidChange { |
| 5033 // TODO(stuartmorgan): Determine if there are any cases where this still | 5005 // TODO(stuartmorgan): Determine if there are any cases where this still |
| 5034 // happens, and if so whether anything should be done when it does. | 5006 // happens, and if so whether anything should be done when it does. |
| 5035 if (![_webView URL]) { | 5007 if (![_webView URL]) { |
| 5036 DVLOG(1) << "Received nil URL callback"; | 5008 DVLOG(1) << "Received nil URL callback"; |
| 5037 return; | 5009 return; |
| 5038 } | 5010 } |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5351 } | 5323 } |
| 5352 | 5324 |
| 5353 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5325 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
| 5354 } | 5326 } |
| 5355 | 5327 |
| 5356 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5328 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
| 5357 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5329 return [action.request valueForHTTPHeaderField:@"Referer"]; |
| 5358 } | 5330 } |
| 5359 | 5331 |
| 5360 @end | 5332 @end |
| OLD | NEW |