Commit 08bde513 authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[Nav Experiment] Present native content before placeholder load.

Only for new navigations started with |loadCurrentURLInNativeView|. This
fixes the brief blank screen before NTP is presented. WebStateObserver
callbacks are not moved; they are still only triggered after placeholder
load finishes. This is because navigation manager state (e.g. last
committed item) must only be updated after WKWebView back-forward history
is updated.

Bug: 819606
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ied642aaf0b4fdcab057faea7ee320ad5b5a88478
Reviewed-on: https://chromium-review.googlesource.com/1104301
Commit-Queue: Danyao Wang <danyao@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568266}
parent 09d266ac
...@@ -119,6 +119,8 @@ const GURL& NavigationItemImpl::GetVirtualURL() const { ...@@ -119,6 +119,8 @@ const GURL& NavigationItemImpl::GetVirtualURL() const {
} }
void NavigationItemImpl::SetTitle(const base::string16& title) { void NavigationItemImpl::SetTitle(const base::string16& title) {
if (title_ == title)
return;
title_ = title; title_ = title;
cached_display_title_.clear(); cached_display_title_.clear();
} }
......
...@@ -543,6 +543,10 @@ NSError* WKWebViewErrorWithSource(NSError* error, WKWebViewErrorSource source) { ...@@ -543,6 +543,10 @@ NSError* WKWebViewErrorWithSource(NSError* error, WKWebViewErrorSource source) {
// Updates the WKBackForwardListItemHolder navigation item. // Updates the WKBackForwardListItemHolder navigation item.
- (void)updateCurrentBackForwardListItemHolder; - (void)updateCurrentBackForwardListItemHolder;
// Presents native content using the native controller for |item| without
// notifying WebStateObservers. This is used when loading native view for a new
// navigation to avoid the delay introduced by placeholder navigation.
- (void)presentNativeContentForNavigationItem:(web::NavigationItem*)item;
// Presents native content using the native controller for |item| and notifies // Presents native content using the native controller for |item| and notifies
// WebStateObservers the completion of this navigation. This method does not // WebStateObservers the completion of this navigation. This method does not
// modify the underlying web view. It simply covers the web view with the native // modify the underlying web view. It simply covers the web view with the native
...@@ -1783,13 +1787,15 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -1783,13 +1787,15 @@ registerLoadRequestForURL:(const GURL&)requestURL
[self removeWebView]; [self removeWebView];
[self loadNativeContentForNavigationItem:self.currentNavItem]; [self loadNativeContentForNavigationItem:self.currentNavItem];
} else { } else {
// Just present the native view now. Leave the rest of native content load
// until the placeholder navigation finishes.
[self presentNativeContentForNavigationItem:self.currentNavItem];
[self loadPlaceholderInWebViewForURL:self.currentNavItem->GetVirtualURL()]; [self loadPlaceholderInWebViewForURL:self.currentNavItem->GetVirtualURL()];
} }
} }
- (void)loadNativeContentForNavigationItem:(web::NavigationItem*)item { - (void)presentNativeContentForNavigationItem:(web::NavigationItem*)item {
const GURL targetURL = item ? item->GetURL() : GURL::EmptyGURL(); const GURL targetURL = item ? item->GetURL() : GURL::EmptyGURL();
const web::Referrer referrer;
id<CRWNativeContent> nativeContent = id<CRWNativeContent> nativeContent =
[_nativeProvider controllerForURL:targetURL webState:self.webState]; [_nativeProvider controllerForURL:targetURL webState:self.webState];
// Unlike the WebView case, always create a new controller and view. // Unlike the WebView case, always create a new controller and view.
...@@ -1799,6 +1805,18 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -1799,6 +1805,18 @@ registerLoadRequestForURL:(const GURL&)requestURL
item->SetVirtualURL([nativeContent virtualURL]); item->SetVirtualURL([nativeContent virtualURL]);
} }
NSString* title = [self.nativeController title];
if (title && item) {
base::string16 newTitle = base::SysNSStringToUTF16(title);
item->SetTitle(newTitle);
}
}
- (void)loadNativeContentForNavigationItem:(web::NavigationItem*)item {
[self presentNativeContentForNavigationItem:item];
const GURL targetURL = item ? item->GetURL() : GURL::EmptyGURL();
const web::Referrer referrer;
std::unique_ptr<web::NavigationContextImpl> navigationContext = std::unique_ptr<web::NavigationContextImpl> navigationContext =
[self registerLoadRequestForURL:targetURL [self registerLoadRequestForURL:targetURL
referrer:referrer referrer:referrer
...@@ -4633,7 +4651,10 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -4633,7 +4651,10 @@ registerLoadRequestForURL:(const GURL&)requestURL
webViewURL = currentWKItemURL; webViewURL = currentWKItemURL;
} }
[self displayWebView]; // Don't show webview for placeholder navigation to avoid covering the native
// content, which may have already been shown.
if (!IsPlaceholderUrl(webViewURL))
[self displayWebView];
// Record the navigation state. // Record the navigation state.
[_navigationStates setState:web::WKNavigationState::COMMITTED [_navigationStates setState:web::WKNavigationState::COMMITTED
......
...@@ -333,10 +333,15 @@ const base::string16& WebStateImpl::GetTitle() const { ...@@ -333,10 +333,15 @@ const base::string16& WebStateImpl::GetTitle() const {
// match the WebContents implementation of this method. // match the WebContents implementation of this method.
DCHECK(Configured()); DCHECK(Configured());
web::NavigationItem* item = navigation_manager_->GetLastCommittedItem(); web::NavigationItem* item = navigation_manager_->GetLastCommittedItem();
if (web::GetWebClient()->IsSlimNavigationManagerEnabled() && if (web::GetWebClient()->IsSlimNavigationManagerEnabled()) {
!restored_title_.empty()) { if (!restored_title_.empty()) {
DCHECK(!item); DCHECK(!item);
return restored_title_; return restored_title_;
}
// Display title for the visible item makes more sense. Only do this in
// WKBasedNavigationManager for now to limit impact.
item = navigation_manager_->GetVisibleItem();
} }
return item ? item->GetTitleForDisplay() : empty_string16_; return item ? item->GetTitleForDisplay() : empty_string16_;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment