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

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

Issue 2685803002: Fixed title updating for back forward navigation. (Closed)
Patch Set: Stubbed title call 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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 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
1382 - (BOOL)isCurrentNavigationItemPOST { 1407 - (BOOL)isCurrentNavigationItemPOST {
1383 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods 1408 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods
1384 // were not called. 1409 // were not called.
1385 NSString* HTTPMethod = 1410 NSString* HTTPMethod =
1386 _pendingNavigationInfo 1411 _pendingNavigationInfo
1387 ? [_pendingNavigationInfo HTTPMethod] 1412 ? [_pendingNavigationInfo HTTPMethod]
1388 : [self currentBackForwardListItemHolder]->http_method(); 1413 : [self currentBackForwardListItemHolder]->http_method();
1389 return [HTTPMethod isEqual:@"POST"]; 1414 return [HTTPMethod isEqual:@"POST"];
1390 } 1415 }
1391 1416
(...skipping 3355 matching lines...) Expand 10 before | Expand all | Expand 10 after
4747 } 4772 }
4748 4773
4749 - (void)webView:(WKWebView*)webView 4774 - (void)webView:(WKWebView*)webView
4750 didCommitNavigation:(WKNavigation*)navigation { 4775 didCommitNavigation:(WKNavigation*)navigation {
4751 [_navigationStates setState:web::WKNavigationState::COMMITTED 4776 [_navigationStates setState:web::WKNavigationState::COMMITTED
4752 forNavigation:navigation]; 4777 forNavigation:navigation];
4753 4778
4754 DCHECK_EQ(_webView, webView); 4779 DCHECK_EQ(_webView, webView);
4755 _certVerificationErrors->Clear(); 4780 _certVerificationErrors->Clear();
4756 4781
4757 // This is the point where the document's URL has actually changed, and 4782 // This is the point where the document's URL and title have actually changed,
4758 // pending navigation information should be applied to state information. 4783 // and pending navigation information should be applied to state information.
4759 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; 4784 [self setDocumentURL:net::GURLWithNSURL([_webView URL])];
4785 [self updateNavigationItemTitle];
4760 4786
4761 if (!_lastRegisteredRequestURL.is_valid() && 4787 if (!_lastRegisteredRequestURL.is_valid() &&
4762 _documentURL != _lastRegisteredRequestURL) { 4788 _documentURL != _lastRegisteredRequestURL) {
4763 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL| 4789 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL|
4764 // will be "about:blank". 4790 // will be "about:blank".
4765 [[self sessionController] updatePendingItem:_documentURL]; 4791 [[self sessionController] updatePendingItem:_documentURL];
4766 } 4792 }
4767 DCHECK(_documentURL == _lastRegisteredRequestURL || 4793 DCHECK(_documentURL == _lastRegisteredRequestURL ||
4768 (!_lastRegisteredRequestURL.is_valid() && 4794 (!_lastRegisteredRequestURL.is_valid() &&
4769 _documentURL.spec() == url::kAboutBlankURL)); 4795 _documentURL.spec() == url::kAboutBlankURL));
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4987 } 5013 }
4988 5014
4989 - (void)webViewTitleDidChange { 5015 - (void)webViewTitleDidChange {
4990 // WKWebView's title becomes empty when the web process dies; ignore that 5016 // WKWebView's title becomes empty when the web process dies; ignore that
4991 // update. 5017 // update.
4992 if (_webProcessIsDead) { 5018 if (_webProcessIsDead) {
4993 DCHECK_EQ([_webView title].length, 0U); 5019 DCHECK_EQ([_webView title].length, 0U);
4994 return; 5020 return;
4995 } 5021 }
4996 5022
4997 if ([self.delegate 5023 bool hasPendingNavigation = web::WKNavigationState::COMMITTED <=
4998 respondsToSelector:@selector(webController:titleDidChange:)]) { 5024 [_navigationStates lastAddedNavigationState];
4999 DCHECK([_webView title]); 5025 if (hasPendingNavigation) {
5000 [self.delegate webController:self titleDidChange:[_webView title]]; 5026 // Do not update the title if there is a navigation in progress because
5027 // there is no way to tell if KVO change fired for new or previous page.
5028 [self updateNavigationItemTitle];
5001 } 5029 }
5002 } 5030 }
5003 5031
5004 - (void)webViewURLDidChange { 5032 - (void)webViewURLDidChange {
5005 // TODO(stuartmorgan): Determine if there are any cases where this still 5033 // TODO(stuartmorgan): Determine if there are any cases where this still
5006 // happens, and if so whether anything should be done when it does. 5034 // happens, and if so whether anything should be done when it does.
5007 if (![_webView URL]) { 5035 if (![_webView URL]) {
5008 DVLOG(1) << "Received nil URL callback"; 5036 DVLOG(1) << "Received nil URL callback";
5009 return; 5037 return;
5010 } 5038 }
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
5323 } 5351 }
5324 5352
5325 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 5353 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
5326 } 5354 }
5327 5355
5328 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { 5356 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action {
5329 return [action.request valueForHTTPHeaderField:@"Referer"]; 5357 return [action.request valueForHTTPHeaderField:@"Referer"];
5330 } 5358 }
5331 5359
5332 @end 5360 @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