Skip to content

Commit

Permalink
[M116 merge 5845] Revert "[Share] Remove TargetChosenReceiver when Wi…
Browse files Browse the repository at this point in the history
…ndowAndroid destroyed"

This reverts commit 0d8a9c0.

Reason for revert: Causing breakage for CCT: crbug/1470978

Original change's description:
> [Share] Remove TargetChosenReceiver when WindowAndroid destroyed
>
> Android share sheet is showing with as ChooserActivity on top of Chrome. When theme switches, Chrome activity is recreated, so the previous stored custom actions should go away since they are referencing the old activity. As a result, the custom actions on the share sheet becomes no-op once selected.
>
> This CL include the fix that:
> * Remove the weak reference to Activity and WindowAndroid once it is removed from the UserDataHost (in WindowAndroid)
> * Close the share sheet. This is done by sending an intent with Intent.FLAG_ACTIVITY_CLEAR_TOP targeting to the dispatching activity.
>
> Bug: 1470036
> Change-Id: Ibb56fd3d57cf48645c23a9f8a17eb95554b7e5a4
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4750566
> Reviewed-by: Theresa Sullivan <twellington@chromium.org>
> Commit-Queue: Wenyu Fu <wenyufu@chromium.org>
> Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
> Cr-Commit-Position: refs/heads/main@{#1179706}

(cherry picked from commit b41d253)

Bug: 1470036
Change-Id: I9552ceb84479a81cf3601b9dacddc16ac751693f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4765216
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Commit-Queue: Wenyu Fu <wenyufu@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Original-Commit-Position: refs/heads/main@{#1181598}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4771256
Reviewed-by: Wenyu Fu <wenyufu@chromium.org>
Reviewed-by: Krishna Govind <govind@chromium.org>
Commit-Queue: Krishna Govind <govind@chromium.org>
Owners-Override: Krishna Govind <govind@chromium.org>
Cr-Commit-Position: refs/branch-heads/5845@{#1350}
Cr-Branched-From: 5a5dff6-refs/heads/main@{#1160321}
  • Loading branch information
Wenyu Fu authored and Chromium LUCI CQ committed Aug 10, 2023
1 parent 9992c6d commit bbf14bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void shareInTwoWindow_CancelFirstFinishSecond() throws SendIntentExceptio
public void shareInTwoWindow_KillFirstWindowThenCompleteSecond() throws SendIntentException {
mWindowFoo.startShare();
mWindowBar.startShare();
mWindowFoo.closeWindow().verifyCleanerIntentDispatched();
mWindowFoo.closeWindow();
mWindowBar.verifyCallbackNotCalled()
.completeShareWithComponent(COMPONENT_NAME_2)
.verifyCallbackState()
Expand All @@ -140,7 +140,7 @@ public void shareInTwoWindow_KillFirstWindowThenCompleteSecond() throws SendInte
@Test
public void shareInTwoWindow_KillSecondWindowThenCompleteFirst() throws SendIntentException {
mWindowFoo.startShare();
mWindowBar.startShare().closeWindow().verifyCleanerIntentDispatched();
mWindowBar.startShare().closeWindow();
mWindowFoo.verifyCallbackNotCalled()
.completeShareWithComponent(COMPONENT_NAME_1)
.verifyCallbackState()
Expand Down Expand Up @@ -240,25 +240,13 @@ public SingleWindowTestInstance verifyCallbackState() {
return this;
}

public SingleWindowTestInstance verifyCleanerIntentDispatched() {
Intent intent = Shadows.shadowOf(mActivity).peekNextStartedActivity();
assertNotNull("Cleaner intent is not sent.", intent);
assertEquals("Cleaner intent does not have the right class name.",
intent.getComponent().getClassName(), mActivity.getClass().getName());
assertTrue("FLAG_ACTIVITY_CLEAR_TOP is not set for cleaner intent.",
(intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0);
return this;
}

public SingleWindowTestInstance closeWindow() {
if (mClosed) return this;
public void closeWindow() {
if (mClosed) return;

mClosed = true;
mWindow.destroy();
mActivity.finish();
mActivityScenario.close();

return this;
}

private ShareParams getTextParams() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.UnownedUserData;
import org.chromium.base.UnownedUserDataHost;
import org.chromium.base.UnownedUserDataKey;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.components.browser_ui.share.ShareParams.TargetChosenCallback;
Expand Down Expand Up @@ -254,13 +253,6 @@ public void onIntentCompleted(int resultCode, Intent data) {
}
}

@Override
public void onDetachedFromHost(UnownedUserDataHost host) {
// Remove the weak reference to the context and window when it is removed from the
// attaching window.
cancel();
}

private boolean isUntrustedIntent(Intent intent) {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
&& !IntentUtils.isTrustedIntentFromSelf(intent);
Expand All @@ -282,14 +274,6 @@ private void detach() {

private void cancel() {
if (mCallback != null) {
// Issue a cleaner intent so the share sheet is cleared. This is a workaround to
// close the top ChooserActivity when share isn't completed.
Intent cleanerIntent = new Intent();
cleanerIntent.setClass(mAttachedContext.get(), mAttachedContext.get().getClass());
cleanerIntent.setFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
mAttachedContext.get().startActivity(cleanerIntent);

mCallback.onCancel();
mCallback = null;
}
Expand Down

0 comments on commit bbf14bd

Please sign in to comment.