use of org.chromium.chrome.browser.tabmodel.TabModelSelector in project AndroidChromium by JackyAndroid.
the class Tab method detachAndStartReparenting.
/**
* Begins the tab reparenting process. Detaches the tab from its current activity and fires
* an Intent to reparent the tab into its new host activity.
*
* @param intent An optional intent with the desired component, flags, or extras to use when
* launching the new host activity. This intent's URI and action will be
* overriden. This may be null if no intent customization is needed.
* @param startActivityOptions Options to pass to {@link Activity#startActivity(Intent, Bundle)}
* @param finalizeCallback A callback that will be called after the tab is attached to the new
* host activity in {@link #attachAndFinishReparenting}.
* @return Whether reparenting succeeded. If false, the tab was not removed and the intent was
* not fired.
*/
public boolean detachAndStartReparenting(Intent intent, Bundle startActivityOptions, Runnable finalizeCallback) {
ChromeActivity activity = getActivity();
if (activity == null)
return false;
if (intent == null)
intent = new Intent();
if (intent.getComponent() == null) {
intent.setClass(mThemedApplicationContext, ChromeLauncherActivity.class);
}
intent.setAction(Intent.ACTION_VIEW);
if (TextUtils.isEmpty(intent.getDataString()))
intent.setData(Uri.parse(getUrl()));
if (isIncognito()) {
intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
}
IntentHandler.addTrustedIntentExtras(intent, activity);
if (ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_REPARENTING)) {
TabModelSelector tabModelSelector = getTabModelSelector();
if (tabModelSelector == null)
return false;
mIsDetachedForReparenting = true;
// Add the tab to AsyncTabParamsManager before removing it from the current model to
// ensure the global count of tabs is correct. See crbug.com/611806.
intent.putExtra(IntentHandler.EXTRA_TAB_ID, mId);
AsyncTabParamsManager.add(mId, new TabReparentingParams(this, intent, finalizeCallback));
tabModelSelector.getModel(mIncognito).removeTab(this);
// TODO(mthiesse): File a bug when crbug isn't down.
if (mContentViewCore != null)
mContentViewCore.updateWindowAndroid(null);
attachTabContentManager(null);
}
activity.startActivity(intent, startActivityOptions);
return true;
}
use of org.chromium.chrome.browser.tabmodel.TabModelSelector in project AndroidChromium by JackyAndroid.
the class ChromeActivitySessionTracker method onForegroundSessionEnd.
/**
* Called when last of Chrome activities is stopped, ending the foreground session. This will
* not be called when a Chrome activity is stopped because another Chrome activity takes over.
* This is ensured by ActivityStatus, which switches to track new activity when its started and
* will not report the old one being stopped (see createStateListener() below).
*/
private void onForegroundSessionEnd() {
if (!mIsStarted)
return;
ChromeApplication.flushPersistentData();
mIsStarted = false;
mPowerBroadcastReceiver.onForegroundSessionEnd();
ChildProcessLauncher.onSentToBackground();
IntentHandler.clearPendingReferrer();
IntentHandler.clearPendingIncognitoUrl();
int totalTabCount = 0;
for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) {
Activity activity = reference.get();
if (activity instanceof ChromeActivity) {
TabModelSelector tabModelSelector = ((ChromeActivity) activity).getTabModelSelector();
if (tabModelSelector != null) {
totalTabCount += tabModelSelector.getTotalTabCount();
}
}
}
RecordHistogram.recordCountHistogram("Tab.TotalTabCount.BeforeLeavingApp", totalTabCount);
}
use of org.chromium.chrome.browser.tabmodel.TabModelSelector in project AndroidChromium by JackyAndroid.
the class ChromeActivity method onDestroy.
/**
* This cannot be overridden in order to preserve destruction order. Override
* {@link #onDestroyInternal()} instead to perform clean up tasks.
*/
@SuppressLint("NewApi")
@Override
protected final void onDestroy() {
if (mReaderModeManager != null) {
mReaderModeManager.destroy();
mReaderModeManager = null;
}
if (mContextualSearchManager != null) {
mContextualSearchManager.destroy();
mContextualSearchManager = null;
}
if (mTabModelSelectorTabObserver != null) {
mTabModelSelectorTabObserver.destroy();
mTabModelSelectorTabObserver = null;
}
if (mCompositorViewHolder != null) {
if (mCompositorViewHolder.getLayoutManager() != null) {
mCompositorViewHolder.getLayoutManager().removeSceneChangeObserver(this);
}
mCompositorViewHolder.shutDown();
mCompositorViewHolder = null;
}
onDestroyInternal();
if (mToolbarManager != null) {
mToolbarManager.destroy();
mToolbarManager = null;
}
TabModelSelector selector = getTabModelSelector();
if (selector != null)
selector.destroy();
if (mWindowAndroid != null) {
mWindowAndroid.destroy();
mWindowAndroid = null;
}
CombinedPolicyProvider.get().removePolicyChangeListener(this);
if (mTabContentManager != null) {
mTabContentManager.destroy();
mTabContentManager = null;
}
AccessibilityManager manager = (AccessibilityManager) getBaseContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
manager.removeAccessibilityStateChangeListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
manager.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
}
if (mBlimpClientContextDelegate != null) {
mBlimpClientContextDelegate.destroy();
mBlimpClientContextDelegate = null;
}
super.onDestroy();
}
use of org.chromium.chrome.browser.tabmodel.TabModelSelector in project AndroidChromium by JackyAndroid.
the class CustomTabTabPersistencePolicy method getAllTabIdsForActivity.
/**
* Get all current Tab IDs used by the specified activity.
*
* @param activity The activity whose tab IDs are to be collected from.
* @param tabIds Where the tab IDs should be added to.
*/
private static void getAllTabIdsForActivity(CustomTabActivity activity, Set<Integer> tabIds) {
if (activity == null)
return;
TabModelSelector selector = activity.getTabModelSelector();
if (selector == null)
return;
List<TabModel> models = selector.getModels();
for (int i = 0; i < models.size(); i++) {
TabModel model = models.get(i);
for (int j = 0; j < model.getCount(); j++) {
tabIds.add(model.getTabAt(j).getId());
}
}
}
use of org.chromium.chrome.browser.tabmodel.TabModelSelector in project AndroidChromium by JackyAndroid.
the class ContextReporter method enable.
/**
* Starts reporting context.
*/
public void enable() {
Tab currentTab = mActivity.getActivityTab();
reportUsageOfCurrentContextIfPossible(currentTab, false, null);
TabModelSelector selector = mActivity.getTabModelSelector();
assert selector != null;
if (mSelectorTabObserver == null) {
mSelectorTabObserver = new TabModelSelectorTabObserver(selector) {
@Override
public void onTitleUpdated(Tab tab) {
// Report usage declaring this as a title change.
reportUsageOfCurrentContextIfPossible(tab, true, null);
}
@Override
public void onUrlUpdated(Tab tab) {
reportUsageOfCurrentContextIfPossible(tab, false, null);
}
};
}
if (mModelObserver == null) {
assert !selector.getModels().isEmpty();
mModelObserver = new EmptyTabModelObserver() {
@Override
public void didSelectTab(Tab tab, TabSelectionType type, int lastId) {
reportUsageOfCurrentContextIfPossible(tab, false, null);
}
};
for (TabModel model : selector.getModels()) {
model.addObserver(mModelObserver);
}
}
if (mContextualSearchObserver == null && mActivity.getContextualSearchManager() != null) {
mContextualSearchObserver = new ContextualSearchObserver() {
@Override
public void onShowContextualSearch(GSAContextDisplaySelection contextSelection) {
if (contextSelection != null)
reportDisplaySelection(contextSelection);
}
@Override
public void onHideContextualSearch() {
reportDisplaySelection(null);
}
};
mActivity.getContextualSearchManager().addObserver(mContextualSearchObserver);
}
}
Aggregations