Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Include intent extras to identify moved tabs in multi-window for back…
Browse files Browse the repository at this point in the history
… press

When opening tabs in other windows or moving tabs between windows in Android
N+ multi-window mode, include intent extras so that Chrome knows the intent
came from Chrome and does not close the app when the 'back' button is pressed.

BUG=624022
[email protected]

Review URL: https://codereview.chromium.org/2111323002 .

Original-Review-Url: https://codereview.chromium.org/2106953002
Original-Cr-Commit-Position: refs/heads/master@{#403030}
Cr-Commit-Position: refs/branch-heads/2743@{#558}
Cr-Branched-From: 2b3ae3b-refs/heads/master@{#394939}
  • Loading branch information
Theresa Wellington committed Jun 30, 2016
1 parent 997bb4d commit 909e1d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,7 @@ private void moveTabToOtherWindow(Tab tab) {
if (targetActivity == null) return;

Intent intent = new Intent(this, targetActivity);
intent.setClass(this, targetActivity);
intent.setFlags(MultiWindowUtils.FLAG_ACTIVITY_LAUNCH_ADJACENT);
MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, this, targetActivity);

tab.detachAndStartReparenting(intent, null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.provider.Browser;
import android.text.TextUtils;

import org.chromium.base.ContextUtils;
Expand Down Expand Up @@ -95,6 +96,25 @@ public Class<? extends Activity> getOpenInOtherWindowActivity(Activity current)
}
}

/**
* Sets extras on the intent used when handling "open in other window" or
* "move to other window". Specifically, sets the class, adds the launch adjacent flag, and
* adds extras so that Chrome behaves correctly when the back button is pressed.
* @param intent The intent to set details on.
* @param activity The activity firing the intent.
* @param targetActivity The class of the activity receiving the intent.
*/
public static void setOpenInOtherWindowIntentExtras(
Intent intent, Activity activity, Class<? extends Activity> targetActivity) {
intent.setClass(activity, targetActivity);
intent.addFlags(MultiWindowUtils.FLAG_ACTIVITY_LAUNCH_ADJACENT);

// Let Chrome know that this intent is from Chrome, so that it does not close the app when
// the user presses 'back' button.
intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
}

/**
* @param activity The {@link Activity} to check.
* @return Whether or not {@code activity} is currently in pre-N Samsung multi-window mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@ public void createTabInOtherWindow(LoadUrlParams loadUrlParams, Activity activit
int parentId) {
Intent intent = createNewTabIntent(new AsyncTabCreationParams(loadUrlParams), parentId);

Class<?> targetActivity =
Class<? extends Activity> targetActivity =
MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(activity);
if (targetActivity == null) return;
intent.setClass(activity, targetActivity);

intent.addFlags(MultiWindowUtils.FLAG_ACTIVITY_LAUNCH_ADJACENT);
MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, activity, targetActivity);
IntentHandler.addTrustedIntentExtras(intent, activity);
activity.startActivity(intent);
}
Expand Down

0 comments on commit 909e1d1

Please sign in to comment.