Commit 8b7b9e27 authored by Pavel Shmakov's avatar Pavel Shmakov Committed by Commit Bot

Deliver onRenderProcessGone to WebLayer embedders

Discussion:
https://docs.google.com/document/d/1M-ocVxRpj43fGrM4mdBazEgcDa0nbWPxD_NxfsPnrkg/edit?ts=5dc96bc9

This CL implements the short-term solution, i.e. only an onRenderProcessGone
callback.

Change-Id: I51cf71975db4d72e940e15b5f2acca6cde3ff4a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1901083Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarTobias Sargeant <tobiasjs@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Pavel Shmakov <pshmakov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714501}
parent af793f6c
...@@ -36,6 +36,11 @@ public final class TabCallbackProxy { ...@@ -36,6 +36,11 @@ public final class TabCallbackProxy {
mClient.visibleUrlChanged(string); mClient.visibleUrlChanged(string);
} }
@CalledByNative
private void onRenderProcessGone() throws RemoteException {
mClient.onRenderProcessGone();
}
@NativeMethods @NativeMethods
interface Natives { interface Natives {
long createTabCallbackProxy(TabCallbackProxy proxy, long tab); long createTabCallbackProxy(TabCallbackProxy proxy, long tab);
......
...@@ -12,4 +12,6 @@ interface ITabClient { ...@@ -12,4 +12,6 @@ interface ITabClient {
void visibleUrlChanged(in String url) = 0; void visibleUrlChanged(in String url) = 0;
void onNewTab(in int tabId, in int mode) = 1; void onNewTab(in int tabId, in int mode) = 1;
void onRenderProcessGone() = 2;
} }
...@@ -31,6 +31,11 @@ void TabCallbackProxy::DisplayedUrlChanged(const GURL& url) { ...@@ -31,6 +31,11 @@ void TabCallbackProxy::DisplayedUrlChanged(const GURL& url) {
Java_TabCallbackProxy_visibleUrlChanged(env, java_observer_, jstring_url); Java_TabCallbackProxy_visibleUrlChanged(env, java_observer_, jstring_url);
} }
void TabCallbackProxy::OnRenderProcessGone() {
Java_TabCallbackProxy_onRenderProcessGone(AttachCurrentThread(),
java_observer_);
}
static jlong JNI_TabCallbackProxy_CreateTabCallbackProxy( static jlong JNI_TabCallbackProxy_CreateTabCallbackProxy(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& proxy, const base::android::JavaParamRef<jobject>& proxy,
......
...@@ -25,6 +25,8 @@ class TabCallbackProxy : public TabObserver { ...@@ -25,6 +25,8 @@ class TabCallbackProxy : public TabObserver {
// BrowserObserver: // BrowserObserver:
void DisplayedUrlChanged(const GURL& url) override; void DisplayedUrlChanged(const GURL& url) override;
void OnRenderProcessGone() override;
private: private:
Tab* tab_; Tab* tab_;
base::android::ScopedJavaGlobalRef<jobject> java_observer_; base::android::ScopedJavaGlobalRef<jobject> java_observer_;
......
...@@ -362,6 +362,12 @@ void TabImpl::DidFinishNavigation( ...@@ -362,6 +362,12 @@ void TabImpl::DidFinishNavigation(
#endif #endif
} }
void TabImpl::RenderProcessGone(base::TerminationStatus status) {
for (auto& observer : observers_) {
observer.OnRenderProcessGone();
}
}
void TabImpl::OnExitFullscreen() { void TabImpl::OnExitFullscreen() {
// If |processing_enter_fullscreen_| is true, it means the callback is being // If |processing_enter_fullscreen_| is true, it means the callback is being
// called while processing EnterFullscreenModeForTab(). WebContents doesn't // called while processing EnterFullscreenModeForTab(). WebContents doesn't
......
...@@ -125,6 +125,7 @@ class TabImpl : public Tab, ...@@ -125,6 +125,7 @@ class TabImpl : public Tab,
// content::WebContentsObserver: // content::WebContentsObserver:
void DidFinishNavigation( void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override; content::NavigationHandle* navigation_handle) override;
void RenderProcessGone(base::TerminationStatus status) override;
// Called from closure supplied to delegate to exit fullscreen. // Called from closure supplied to delegate to exit fullscreen.
void OnExitFullscreen(); void OnExitFullscreen();
......
...@@ -224,6 +224,13 @@ public final class Tab { ...@@ -224,6 +224,13 @@ public final class Tab {
assert tab.getBrowser() == getBrowser(); assert tab.getBrowser() == getBrowser();
mNewTabCallback.onNewTab(tab, mode); mNewTabCallback.onNewTab(tab, mode);
} }
@Override
public void onRenderProcessGone() {
for (TabCallback callback : mCallbacks) {
callback.onRenderProcessGone();
}
}
} }
private static final class DownloadCallbackClientImpl extends IDownloadCallbackClient.Stub { private static final class DownloadCallbackClientImpl extends IDownloadCallbackClient.Stub {
......
...@@ -18,4 +18,10 @@ public abstract class TabCallback { ...@@ -18,4 +18,10 @@ public abstract class TabCallback {
* @param url The new user-visible url. * @param url The new user-visible url.
*/ */
public void onVisibleUrlChanged(@NonNull Uri url) {} public void onVisibleUrlChanged(@NonNull Uri url) {}
/**
* Triggered when the render process dies, either due to crash or killed by the system to
* reclaim memory.
*/
public void onRenderProcessGone() {}
} }
...@@ -14,6 +14,10 @@ class TabObserver { ...@@ -14,6 +14,10 @@ class TabObserver {
// The URL bar should be updated to |url|. // The URL bar should be updated to |url|.
virtual void DisplayedUrlChanged(const GURL& url) {} virtual void DisplayedUrlChanged(const GURL& url) {}
// Triggered when the render process dies, either due to crash or killed by the system to
// reclaim memory.
virtual void OnRenderProcessGone() {}
protected: protected:
virtual ~TabObserver() {} virtual ~TabObserver() {}
}; };
......
...@@ -12,15 +12,18 @@ import org.junit.Test; ...@@ -12,15 +12,18 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.Tab;
import org.chromium.weblayer.TabCallback; import org.chromium.weblayer.TabCallback;
import org.chromium.weblayer.shell.InstrumentationActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeoutException;
/** /**
* Tests that TabCallback methods are invoked as expected. * Tests that TabCallback methods are invoked as expected.
...@@ -71,14 +74,33 @@ public class TabCallbackTest { ...@@ -71,14 +74,33 @@ public class TabCallbackTest {
String startupUrl = "about:blank"; String startupUrl = "about:blank";
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(startupUrl); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(startupUrl);
Callback calllback = new Callback(); Callback callback = new Callback();
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
() -> { activity.getTab().registerTabCallback(calllback); }); () -> { activity.getTab().registerTabCallback(callback); });
String url = "data:text,foo"; String url = "data:text,foo";
mActivityTestRule.navigateAndWait(url); mActivityTestRule.navigateAndWait(url);
/* Verify that the visible URL changes to the target. */ /* Verify that the visible URL changes to the target. */
calllback.visibleUrlChangedCallback.waitUntilValueObserved(url); callback.visibleUrlChangedCallback.waitUntilValueObserved(url);
}
@Test
@SmallTest
public void testOnRenderProcessGone() throws TimeoutException {
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl("about:blank");
CallbackHelper callbackHelper = new CallbackHelper();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Tab tab = activity.getTab();
TabCallback callback = new TabCallback() {
@Override
public void onRenderProcessGone() {
callbackHelper.notifyCalled();
}
};
tab.registerTabCallback(callback);
tab.getNavigationController().navigate(Uri.parse("chrome://crash"));
});
callbackHelper.waitForFirst();
} }
} }
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