Commit 28a55a4a authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android WebAPK] Fix LaunchHostBrowserSelector to call callback just once

This CL fixes a bug where the LaunchHostBrowserSelector would be called
twice when a user selects a host browser:
- once with the host browser package
- once with null.
This CL surpresses the second callback by disabling the OnDismissListener
when a 'button is clicked' or 'host browser is chosen'

This CL also fixes the same bug in InstallHostBrowserDialog

BUG=972922

Change-Id: I6b33cc6a600f170e92e44de329f0d3eb24b6f23b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1652291Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#668401}
parent 2ffda60c
......@@ -12,4 +12,4 @@
# //chrome/android/webapk/shell_apk:webapk is changed. This includes
# Java files, Android resource files and AndroidManifest.xml. Does not affect
# Chrome.apk
current_shell_apk_version = 94
current_shell_apk_version = 95
......@@ -44,6 +44,9 @@ public class ChooseHostBrowserDialog {
void onQuit();
}
/** Checked prior to running the {@link DialogInterface.OnDismissListener}. */
private static class OnDismissListenerCanceler { public boolean canceled; }
/** Stores information about a potential host browser for the WebAPK. */
public static class BrowserItem {
private String mPackageName;
......@@ -107,6 +110,8 @@ public class ChooseHostBrowserDialog {
ListView browserList = (ListView) view.findViewById(R.id.browser_list);
browserList.setAdapter(new BrowserArrayAdapter(context, browserItems));
OnDismissListenerCanceler onDismissCanceler = new OnDismissListenerCanceler();
// The context theme wrapper is needed for pre-L.
AlertDialog.Builder builder = new AlertDialog.Builder(
new ContextThemeWrapper(context, android.R.style.Theme_DeviceDefault_Light_Dialog));
......@@ -114,7 +119,7 @@ public class ChooseHostBrowserDialog {
R.string.choose_host_browser_dialog_quit, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
listener.onQuit();
dialog.cancel();
}
});
......@@ -124,6 +129,7 @@ public class ChooseHostBrowserDialog {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
BrowserItem browserItem = browserItems.get(position);
if (browserItem.supportsWebApks()) {
onDismissCanceler.canceled = true;
listener.onHostBrowserSelected(browserItem.getPackageName());
dialog.cancel();
}
......@@ -133,6 +139,8 @@ public class ChooseHostBrowserDialog {
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
if (onDismissCanceler.canceled) return;
listener.onQuit();
}
});
......
......@@ -24,6 +24,9 @@ public class InstallHostBrowserDialog {
void onConfirmQuit();
}
/** Checked prior to running the {@link DialogInterface.OnDismissListener}. */
private static class OnDismissListenerCanceler { public boolean canceled; }
/**
* Shows the dialog to install a host browser.
* @param context The current context.
......@@ -49,6 +52,8 @@ public class InstallHostBrowserDialog {
WebApkUtils.setPaddingInPixel(name,
context.getResources().getDimensionPixelSize(R.dimen.list_column_padding), 0, 0, 0);
OnDismissListenerCanceler onDismissCanceler = new OnDismissListenerCanceler();
// The context theme wrapper is needed for pre-L.
AlertDialog.Builder builder = new AlertDialog.Builder(
new ContextThemeWrapper(context, android.R.style.Theme_DeviceDefault_Light_Dialog));
......@@ -58,13 +63,14 @@ public class InstallHostBrowserDialog {
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
listener.onConfirmQuit();
dialog.cancel();
}
})
.setPositiveButton(R.string.install_host_browser_dialog_install_button,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onDismissCanceler.canceled = true;
listener.onConfirmInstall(hostBrowserPackageName);
}
});
......@@ -73,6 +79,8 @@ public class InstallHostBrowserDialog {
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
if (onDismissCanceler.canceled) return;
listener.onConfirmQuit();
}
});
......
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