Commit 35882bdc authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

WebLayer: Add Tab#willAutomaticallyReloadAfterCrash

This matches the current logic of the internal TabImpl#isVisible method
(inverted), which is true when a tab is active and in a started
fragment. The name reflects the reason for exposing this method, i.e.
why we think it's notable to clients.

Test coverage will be added in a follow up.

Bug: 1146058
Change-Id: Ibb538fa349623ca214774ef53496fab2414a6c78
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2525848
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826396}
parent c6676dbf
...@@ -458,13 +458,23 @@ public final class TabImpl extends ITab.Stub { ...@@ -458,13 +458,23 @@ public final class TabImpl extends ITab.Stub {
/** /**
* Returns whether this Tab is visible. * Returns whether this Tab is visible.
*/ */
@CalledByNative
public boolean isVisible() { public boolean isVisible() {
return isActiveTab() return isActiveTab()
&& ((mBrowser.isStarted() && mBrowser.isViewAttachedToWindow()) && ((mBrowser.isStarted() && mBrowser.isViewAttachedToWindow())
|| mBrowser.isInConfigurationChangeAndWasAttached()); || mBrowser.isInConfigurationChangeAndWasAttached());
} }
@CalledByNative
public boolean willAutomaticallyReloadAfterCrashImpl() {
return !isVisible();
}
@Override
public boolean willAutomaticallyReloadAfterCrash() {
StrictModeWorkaround.apply();
return willAutomaticallyReloadAfterCrashImpl();
}
public boolean isActiveTab() { public boolean isActiveTab() {
return mBrowser.getActiveTab() == this; return mBrowser.getActiveTab() == this;
} }
......
...@@ -78,4 +78,5 @@ interface ITab { ...@@ -78,4 +78,5 @@ interface ITab {
// Added in 88 // Added in 88
void setFloatingActionModeOverride(in int actionModeItemTypes) = 27; void setFloatingActionModeOverride(in int actionModeItemTypes) = 27;
boolean willAutomaticallyReloadAfterCrash() = 28;
} }
...@@ -1131,8 +1131,7 @@ void TabImpl::RenderProcessGone(base::TerminationStatus status) { ...@@ -1131,8 +1131,7 @@ void TabImpl::RenderProcessGone(base::TerminationStatus status) {
// WebContents that it should automatically reload the next time it becomes // WebContents that it should automatically reload the next time it becomes
// visible. // visible.
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
bool visible = Java_TabImpl_isVisible(env, java_impl_); if (Java_TabImpl_willAutomaticallyReloadAfterCrashImpl(env, java_impl_))
if (!visible)
web_contents()->GetController().SetNeedsReload(); web_contents()->GetController().SetNeedsReload();
#endif #endif
......
...@@ -137,6 +137,27 @@ public class Tab { ...@@ -137,6 +137,27 @@ public class Tab {
return mImpl == null; return mImpl == null;
} }
/**
* Returns whether the tab will automatically reload after its renderer process is lost.
*
* This returns true if the tab is known not to be visible, specifically if the tab is not
* active in its browser or its Fragment is not started. When a tab in this state loses its
* renderer process to a crash (or due to system memory reclamation), it will automatically
* reload next the time it becomes possibly visible.
*/
public boolean willAutomaticallyReloadAfterCrash() {
ThreadCheck.ensureOnUiThread();
throwIfDestroyed();
if (WebLayer.getSupportedMajorVersionInternal() < 88) {
throw new UnsupportedOperationException();
}
try {
return mImpl.willAutomaticallyReloadAfterCrash();
} catch (RemoteException e) {
throw new APICallException(e);
}
}
@NonNull @NonNull
public Browser getBrowser() { public Browser getBrowser() {
ThreadCheck.ensureOnUiThread(); ThreadCheck.ensureOnUiThread();
......
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