Commit 38d1092e authored by mnaganov's avatar mnaganov Committed by Commit bot

[Android WebView] Send WebChromeClient.onReceivedTitle when navigating back

The usual channel for delivering onReceivedTitle (via updating title for
a NavigationEntry) doesn't work in the case of history navigations, because
WebContentsImpl silences no-op updates of entries titles.

Chrome Browser uses another event for updating the title in this case --
via WebContentsDelegate::LoadingStateChanged. This patch enables WebView to
use it as well.

Note that WebChromeClient.onReceivedIcon doesn't need to be re-sent, as
nobody seems to bother checking whether the icon update is a "no-op", so
updates on history navigations just work.

BUG=481570

Review URL: https://codereview.chromium.org/1126383005

Cr-Commit-Position: refs/heads/master@{#329408}
parent f7ed9b85
...@@ -41,4 +41,9 @@ public abstract class AwWebContentsDelegate extends WebContentsDelegateAndroid { ...@@ -41,4 +41,9 @@ public abstract class AwWebContentsDelegate extends WebContentsDelegateAndroid {
@Override @Override
@CalledByNative @CalledByNative
public abstract void navigationStateChanged(int flags); public abstract void navigationStateChanged(int flags);
// Not an override, because WebContentsDelegateAndroid maps this call
// into onLoad{Started|Stopped}.
@CalledByNative
public abstract void loadingStateChanged();
} }
...@@ -271,6 +271,11 @@ class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { ...@@ -271,6 +271,11 @@ class AwWebContentsDelegateAdapter extends AwWebContentsDelegate {
} }
} }
@Override
public void loadingStateChanged() {
mContentsClient.onReceivedTitle(mAwContents.getTitle());
}
private static class GetDisplayNameTask extends AsyncTask<Void, Void, String[]> { private static class GetDisplayNameTask extends AsyncTask<Void, Void, String[]> {
final int mProcessId; final int mProcessId;
final int mRenderId; final int mRenderId;
......
...@@ -320,4 +320,23 @@ public class NavigationHistoryTest extends AwTestBase { ...@@ -320,4 +320,23 @@ public class NavigationHistoryTest extends AwTestBase {
} }
}); });
} }
// See http://crbug.com/481570
@SmallTest
public void testTitleUpdatedWhenGoingBack() throws Throwable {
final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
mContentsClient.getOnPageFinishedHelper();
NavigationHistory list = getNavigationHistory(mAwContents);
assertEquals(0, list.getEntryCount());
final String page1Url = addPage1ToServer(mWebServer);
final String page2Url = addPage2ToServer(mWebServer);
loadUrlSync(mAwContents, onPageFinishedHelper, page1Url);
loadUrlSync(mAwContents, onPageFinishedHelper, page2Url);
assertEquals(PAGE_2_TITLE, mContentsClient.getUpdatedTitle());
HistoryUtils.goBackSync(getInstrumentation(), mAwContents.getWebContents(),
onPageFinishedHelper);
assertEquals(PAGE_1_TITLE, mContentsClient.getUpdatedTitle());
}
} }
...@@ -204,6 +204,18 @@ void AwWebContentsDelegate::ActivateContents(WebContents* contents) { ...@@ -204,6 +204,18 @@ void AwWebContentsDelegate::ActivateContents(WebContents* contents) {
} }
} }
void AwWebContentsDelegate::LoadingStateChanged(WebContents* source,
bool to_different_document) {
// Page title may have changed, need to inform the embedder.
// |source| may be null if loading has started.
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> java_delegate = GetJavaDelegate(env);
if (java_delegate.obj()) {
Java_AwWebContentsDelegate_loadingStateChanged(env, java_delegate.obj());
}
}
void AwWebContentsDelegate::RequestMediaAccessPermission( void AwWebContentsDelegate::RequestMediaAccessPermission(
WebContents* web_contents, WebContents* web_contents,
const content::MediaStreamRequest& request, const content::MediaStreamRequest& request,
......
...@@ -50,6 +50,8 @@ class AwWebContentsDelegate ...@@ -50,6 +50,8 @@ class AwWebContentsDelegate
void CloseContents(content::WebContents* source) override; void CloseContents(content::WebContents* source) override;
void ActivateContents(content::WebContents* contents) override; void ActivateContents(content::WebContents* contents) override;
void LoadingStateChanged(content::WebContents* source,
bool to_different_document) override;
void RequestMediaAccessPermission( void RequestMediaAccessPermission(
content::WebContents* web_contents, content::WebContents* web_contents,
const content::MediaStreamRequest& request, const content::MediaStreamRequest& request,
......
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