Commit 1529c831 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[WebLayer Shell] Fix call into nullptr when tab is removed

WebLayer Shell listens for notifications that the active tab was changed
and updates the favicon of the active tab in response. However, when
the active tab is removed WebLayer sets the active tab to null, which
also causes an onActiveTabChanged(null) notification to be sent (cf.
[1]). WebLayerShellActivity does not currently guard against this case
(cf. [2]), resulting in a crash. One way to trigger this crash is to
open a tab via a navigation that results in an intent launch, which will
then cause the tab to be closed. Concrete example:

On a device/emulator with the Play Store installed, go to booking.com
and click on the Install icon. This will open a new tab for a navigation
that results in an intent out to the play store, upon which WebLayer
closes the newly-opened tab and the onActiveTabChanged(null) callback is
sent.

[1] https://source.chromium.org/chromium/chromium/src/+/master:weblayer/browser/browser_impl.cc;l=403?q=browser_impl.cc&ss=chromium
[2] https://source.chromium.org/chromium/chromium/src/+/master:weblayer/shell/android/shell_apk/src/org/chromium/weblayer/shell/WebLayerShellActivity.java;l=697?q=WebLayerShellActivity.java&ss=chromium

Bug: 1128607
Change-Id: I787824deeb4a3fea49f52f430c6523bed5258f1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414399
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808526}
parent 5a98f17f
......@@ -45,6 +45,7 @@ android_library("weblayer_shell_java") {
"//base:base_java",
"//third_party/android_deps:android_support_v4_java",
"//third_party/android_deps:android_support_v7_appcompat_java",
"//third_party/android_deps:androidx_annotation_annotation_java",
"//weblayer/public/java",
]
sources = [
......
......@@ -33,6 +33,7 @@ import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.fragment.app.Fragment;
......@@ -396,6 +397,10 @@ public class WebLayerShellActivity extends AppCompatActivity {
@Override
public void onActiveTabChanged(Tab activeTab) {
mUrlViewContainer.setDisplayedChild(NONEDITABLE_URL_TEXT_VIEW);
// This callback is fired with null as the param on removal of the active tab.
if (activeTab == null) return;
updateFavicon(activeTab);
}
@Override
......@@ -663,7 +668,7 @@ public class WebLayerShellActivity extends AppCompatActivity {
System.exit(0);
}
private void updateFavicon(Tab tab) {
private void updateFavicon(@NonNull Tab tab) {
if (tab == mBrowser.getActiveTab()) {
assert mTabToFaviconFetcher.containsKey(tab);
((ImageView) findViewById(R.id.favicon_image_view))
......
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