Commit f873445b authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

[WebLayer] Fix crash when showing blocked permission interaction dialog

WebLayer wraps the Activity in a ContextWrapper that allows accessing
chromium resources. When accessing resources that context needs to be
used instead of the activity.

Bug: 1111109
Change-Id: Id2e465264e5dc90591d4a1a8c74b7e786aeba512
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2327958
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Auto-Submit: Clark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarAndy Paicu <andypaicu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793197}
parent a9b388e8
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package org.chromium.components.permissions; package org.chromium.components.permissions;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
...@@ -15,6 +14,7 @@ import androidx.annotation.IntDef; ...@@ -15,6 +14,7 @@ import androidx.annotation.IntDef;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.BuildInfo; import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.ui.modaldialog.DialogDismissalCause; import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager; import org.chromium.ui.modaldialog.ModalDialogManager;
...@@ -144,12 +144,14 @@ public class PermissionDialogController ...@@ -144,12 +144,14 @@ public class PermissionDialogController
assert mState == State.NOT_SHOWING; assert mState == State.NOT_SHOWING;
mDialogDelegate = mRequestQueue.remove(0); mDialogDelegate = mRequestQueue.remove(0);
Activity activity = mDialogDelegate.getWindow().getActivity().get(); // Use the context to access resources instead of the activity because the activity may not
// have the correct resources in some cases (e.g. WebLayer).
Context context = mDialogDelegate.getWindow().getContext().get();
// It's possible for the activity to be null if we reach here just after the user // It's possible for the activity to be null if we reach here just after the user
// backgrounds the browser and cleanup has happened. In that case, we can't show a prompt, // backgrounds the browser and cleanup has happened. In that case, we can't show a prompt,
// so act as though the user dismissed it. // so act as though the user dismissed it.
if (activity == null) { if (ContextUtils.activityFromContext(context) == null) {
// TODO(timloh): This probably doesn't work, as this happens synchronously when creating // TODO(timloh): This probably doesn't work, as this happens synchronously when creating
// the PermissionPromptAndroid, so the PermissionRequestManager won't be ready yet. // the PermissionPromptAndroid, so the PermissionRequestManager won't be ready yet.
mDialogDelegate.onDismiss(); mDialogDelegate.onDismiss();
...@@ -167,7 +169,7 @@ public class PermissionDialogController ...@@ -167,7 +169,7 @@ public class PermissionDialogController
mModalDialogManager = mDialogDelegate.getWindow().getModalDialogManager(); mModalDialogManager = mDialogDelegate.getWindow().getModalDialogManager();
mDialogModel = PermissionDialogModel.getModel( mDialogModel = PermissionDialogModel.getModel(
this, mDialogDelegate, () -> showFilteredTouchEventDialog(activity)); this, mDialogDelegate, () -> showFilteredTouchEventDialog(context));
mModalDialogManager.showDialog(mDialogModel, ModalDialogManager.ModalDialogType.TAB); mModalDialogManager.showDialog(mDialogModel, ModalDialogManager.ModalDialogType.TAB);
mState = State.PROMPT_OPEN; mState = State.PROMPT_OPEN;
} }
......
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