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