Skip to content

Commit

Permalink
Cherry-picked remaining parts of 'Fixed title updating for back forwa…
Browse files Browse the repository at this point in the history
…rd navigation.'

Cherry-picked patchset #1 and #2 from cl/2691693002

BUG=688047, 677356
Review-Url: https://codereview.chromium.org/2685803002
NOTRY=true
NOPRESUBMIT=true

Review-Url: https://codereview.chromium.org/2711123004
Cr-Commit-Position: refs/branch-heads/2987@{#666}
Cr-Branched-From: ad51088-refs/heads/master@{#444943}
  • Loading branch information
eugenebut authored and Commit bot committed Feb 23, 2017
1 parent 029de77 commit 7756937
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions ios/web/web_state/ui/crw_web_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,9 @@ - (void)replaceStateWithPageURL:(const GURL&)pageUrl
stateObject:(NSString*)stateObject;
// Sets _documentURL to newURL, and updates any relevant state information.
- (void)setDocumentURL:(const GURL&)newURL;
// Sets WKWebView's title to the last committed navigation item.
- (void)updateNavigationItemTitle;
// Sets last committed NavigationItem's title to the given |title|, which can
// not be nil.
- (void)setNavigationItemTitle:(NSString*)title;
// Returns YES if the current navigation item corresponds to a web page
// loaded by a POST request.
- (BOOL)isCurrentNavigationItemPOST;
Expand Down Expand Up @@ -1423,15 +1424,14 @@ - (void)setDocumentURL:(const GURL&)newURL {
}
}

- (void)updateNavigationItemTitle {
NSString* webViewTitle = [_webView title];
DCHECK(webViewTitle);
- (void)setNavigationItemTitle:(NSString*)title {
DCHECK(title);
auto& navigationManager = _webStateImpl->GetNavigationManagerImpl();
web::NavigationItem* item = navigationManager.GetLastCommittedItem();
if (!item)
return;

base::string16 newTitle = base::SysNSStringToUTF16(webViewTitle);
base::string16 newTitle = base::SysNSStringToUTF16(title);
if (item->GetTitle() == newTitle)
return;

Expand All @@ -1442,7 +1442,7 @@ - (void)updateNavigationItemTitle {
navigationManager.OnNavigationItemChanged();

if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) {
[_delegate webController:self titleDidChange:webViewTitle];
[_delegate webController:self titleDidChange:title];
}
}

Expand Down Expand Up @@ -1870,14 +1870,13 @@ - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess {
// Perform post-load-finished updates.
[self didFinishWithURL:currentURL loadSuccess:loadSuccess];

// Inform the embedder the title changed.
NSString* title = [self.nativeController title];
if (title)
[self setNavigationItemTitle:title];

// If the controller handles title change notification, route those to the
// delegate.
if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) {
NSString* title = [self.nativeController title];
// If a title is present, notify the delegate.
if (title)
[_delegate webController:self titleDidChange:title];
// If the controller handles title change notification, route those to the
// delegate.
if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) {
[self.nativeController setDelegate:self];
}
Expand Down Expand Up @@ -4982,7 +4981,6 @@ - (void)webView:(WKWebView*)webView
// This is the point where the document's URL and title have actually changed,
// and pending navigation information should be applied to state information.
[self setDocumentURL:net::GURLWithNSURL([_webView URL])];
[self updateNavigationItemTitle];

if (!_lastRegisteredRequestURL.is_valid() &&
_documentURL != _lastRegisteredRequestURL) {
Expand Down Expand Up @@ -5025,6 +5023,10 @@ - (void)webView:(WKWebView*)webView
// Attempt to update the HTML5 history state.
[self updateHTML5HistoryState];

// This is the point where pending entry has been committed, and navigation
// item title should be updated.
[self setNavigationItemTitle:[_webView title]];

// Report cases where SSL cert is missing for a secure connection.
if (_documentURL.SchemeIsCryptographic()) {
scoped_refptr<net::X509Certificate> cert =
Expand Down Expand Up @@ -5225,7 +5227,7 @@ - (void)webViewTitleDidChange {
if (hasPendingNavigation) {
// Do not update the title if there is a navigation in progress because
// there is no way to tell if KVO change fired for new or previous page.
[self updateNavigationItemTitle];
[self setNavigationItemTitle:[_webView title]];
}
}

Expand Down

0 comments on commit 7756937

Please sign in to comment.