Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Side by Side Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 2701463002: Fixed title updating for back forward navigation. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 // TODO(stuartmorgan): Move the pushState/replaceState logic into 732 // TODO(stuartmorgan): Move the pushState/replaceState logic into
733 // NavigationManager. 733 // NavigationManager.
734 - (void)pushStateWithPageURL:(const GURL&)pageURL 734 - (void)pushStateWithPageURL:(const GURL&)pageURL
735 stateObject:(NSString*)stateObject 735 stateObject:(NSString*)stateObject
736 transition:(ui::PageTransition)transition; 736 transition:(ui::PageTransition)transition;
737 // Assigns the given URL and state object to the current CRWSessionEntry. 737 // Assigns the given URL and state object to the current CRWSessionEntry.
738 - (void)replaceStateWithPageURL:(const GURL&)pageUrl 738 - (void)replaceStateWithPageURL:(const GURL&)pageUrl
739 stateObject:(NSString*)stateObject; 739 stateObject:(NSString*)stateObject;
740 // Sets _documentURL to newURL, and updates any relevant state information. 740 // Sets _documentURL to newURL, and updates any relevant state information.
741 - (void)setDocumentURL:(const GURL&)newURL; 741 - (void)setDocumentURL:(const GURL&)newURL;
742 // Sets WKWebView's title to the last committed navigation item.
743 - (void)updateNavigationItemTitle;
742 // Returns YES if the current navigation item corresponds to a web page 744 // Returns YES if the current navigation item corresponds to a web page
743 // loaded by a POST request. 745 // loaded by a POST request.
744 - (BOOL)isCurrentNavigationItemPOST; 746 - (BOOL)isCurrentNavigationItemPOST;
745 // Returns YES if current navigation item is WKNavigationTypeBackForward. 747 // Returns YES if current navigation item is WKNavigationTypeBackForward.
746 - (BOOL)isCurrentNavigationBackForward; 748 - (BOOL)isCurrentNavigationBackForward;
747 // Returns whether the given navigation is triggered by a user link click. 749 // Returns whether the given navigation is triggered by a user link click.
748 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType; 750 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType;
749 751
750 // Inject windowID if not yet injected. 752 // Inject windowID if not yet injected.
751 - (void)injectWindowID; 753 - (void)injectWindowID;
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 [self didUpdateHistoryStateWithPageURL:pageUrl]; 1413 [self didUpdateHistoryStateWithPageURL:pageUrl];
1412 } 1414 }
1413 1415
1414 - (void)setDocumentURL:(const GURL&)newURL { 1416 - (void)setDocumentURL:(const GURL&)newURL {
1415 if (newURL != _documentURL && newURL.is_valid()) { 1417 if (newURL != _documentURL && newURL.is_valid()) {
1416 _documentURL = newURL; 1418 _documentURL = newURL;
1417 _interactionRegisteredSinceLastURLChange = NO; 1419 _interactionRegisteredSinceLastURLChange = NO;
1418 } 1420 }
1419 } 1421 }
1420 1422
1423 - (void)updateNavigationItemTitle {
1424 NSString* webViewTitle = [_webView title];
1425 DCHECK(webViewTitle);
1426 auto& navigationManager = _webStateImpl->GetNavigationManagerImpl();
1427 web::NavigationItem* item = navigationManager.GetLastCommittedItem();
1428 if (!item)
1429 return;
1430
1431 base::string16 newTitle = base::SysNSStringToUTF16(webViewTitle);
1432 if (item->GetTitle() == newTitle)
1433 return;
1434
1435 item->SetTitle(newTitle);
1436 // TODO(crbug.com/546218): See if this can be removed; it's not clear that
1437 // other platforms send this (tab sync triggers need to be compared against
1438 // upstream).
1439 navigationManager.OnNavigationItemChanged();
1440
1441 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) {
1442 [_delegate webController:self titleDidChange:webViewTitle];
1443 }
1444 }
1445
1421 - (BOOL)isCurrentNavigationItemPOST { 1446 - (BOOL)isCurrentNavigationItemPOST {
1422 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods 1447 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods
1423 // were not called. 1448 // were not called.
1424 NSString* HTTPMethod = 1449 NSString* HTTPMethod =
1425 _pendingNavigationInfo 1450 _pendingNavigationInfo
1426 ? [_pendingNavigationInfo HTTPMethod] 1451 ? [_pendingNavigationInfo HTTPMethod]
1427 : [self currentBackForwardListItemHolder]->http_method(); 1452 : [self currentBackForwardListItemHolder]->http_method();
1428 return [HTTPMethod isEqual:@"POST"]; 1453 return [HTTPMethod isEqual:@"POST"];
1429 } 1454 }
1430 1455
(...skipping 3511 matching lines...) Expand 10 before | Expand all | Expand 10 after
4942 } 4967 }
4943 4968
4944 - (void)webView:(WKWebView*)webView 4969 - (void)webView:(WKWebView*)webView
4945 didCommitNavigation:(WKNavigation*)navigation { 4970 didCommitNavigation:(WKNavigation*)navigation {
4946 [_navigationStates setState:web::WKNavigationState::COMMITTED 4971 [_navigationStates setState:web::WKNavigationState::COMMITTED
4947 forNavigation:navigation]; 4972 forNavigation:navigation];
4948 4973
4949 DCHECK_EQ(_webView, webView); 4974 DCHECK_EQ(_webView, webView);
4950 _certVerificationErrors->Clear(); 4975 _certVerificationErrors->Clear();
4951 4976
4952 // This is the point where the document's URL has actually changed, and 4977 // This is the point where the document's URL and title have actually changed,
4953 // pending navigation information should be applied to state information. 4978 // and pending navigation information should be applied to state information.
4954 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; 4979 [self setDocumentURL:net::GURLWithNSURL([_webView URL])];
4980 [self updateNavigationItemTitle];
4955 4981
4956 if (!_lastRegisteredRequestURL.is_valid() && 4982 if (!_lastRegisteredRequestURL.is_valid() &&
4957 _documentURL != _lastRegisteredRequestURL) { 4983 _documentURL != _lastRegisteredRequestURL) {
4958 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL| 4984 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL|
4959 // will be "about:blank". 4985 // will be "about:blank".
4960 [[self sessionController] updatePendingEntry:_documentURL]; 4986 [[self sessionController] updatePendingEntry:_documentURL];
4961 } 4987 }
4962 DCHECK(_documentURL == _lastRegisteredRequestURL || 4988 DCHECK(_documentURL == _lastRegisteredRequestURL ||
4963 (!_lastRegisteredRequestURL.is_valid() && 4989 (!_lastRegisteredRequestURL.is_valid() &&
4964 _documentURL.spec() == url::kAboutBlankURL)); 4990 _documentURL.spec() == url::kAboutBlankURL));
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
5182 } 5208 }
5183 5209
5184 - (void)webViewTitleDidChange { 5210 - (void)webViewTitleDidChange {
5185 // WKWebView's title becomes empty when the web process dies; ignore that 5211 // WKWebView's title becomes empty when the web process dies; ignore that
5186 // update. 5212 // update.
5187 if (_webProcessIsDead) { 5213 if (_webProcessIsDead) {
5188 DCHECK_EQ([_webView title].length, 0U); 5214 DCHECK_EQ([_webView title].length, 0U);
5189 return; 5215 return;
5190 } 5216 }
5191 5217
5192 if ([self.delegate 5218 bool hasPendingNavigation = web::WKNavigationState::COMMITTED <=
5193 respondsToSelector:@selector(webController:titleDidChange:)]) { 5219 [_navigationStates lastAddedNavigationState];
5194 DCHECK([_webView title]); 5220 if (hasPendingNavigation) {
5195 [self.delegate webController:self titleDidChange:[_webView title]]; 5221 // Do not update the title if there is a navigation in progress because
5222 // there is no way to tell if KVO change fired for new or previous page.
5223 [self updateNavigationItemTitle];
5196 } 5224 }
5197 } 5225 }
5198 5226
5199 - (void)webViewURLDidChange { 5227 - (void)webViewURLDidChange {
5200 // TODO(stuartmorgan): Determine if there are any cases where this still 5228 // TODO(stuartmorgan): Determine if there are any cases where this still
5201 // happens, and if so whether anything should be done when it does. 5229 // happens, and if so whether anything should be done when it does.
5202 if (![_webView URL]) { 5230 if (![_webView URL]) {
5203 DVLOG(1) << "Received nil URL callback"; 5231 DVLOG(1) << "Received nil URL callback";
5204 return; 5232 return;
5205 } 5233 }
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
5522 } 5550 }
5523 5551
5524 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 5552 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
5525 } 5553 }
5526 5554
5527 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { 5555 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action {
5528 return [action.request valueForHTTPHeaderField:@"Referer"]; 5556 return [action.request valueForHTTPHeaderField:@"Referer"];
5529 } 5557 }
5530 5558
5531 @end 5559 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/tabs/tab_unittest.mm ('k') | ios/web/web_state/ui/crw_web_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698