@Override
  public void onActivityStateChange(Activity activity, int newState) {
    if (!mActivityDelegate.isDocumentActivity(activity)) return;

    // Tabs swiped away when their Activity is dead don't trigger destruction notifications.
    if (newState == ActivityState.STARTED || newState == ActivityState.DESTROYED) {
      mRegularTabModel.updateRecentlyClosed();
      mIncognitoTabModel.updateRecentlyClosed();
    }
  }
Example #2
0
  /**
   * Creates a Tab to host the given WebContents asynchronously.
   *
   * @param asyncParams Parameters to create the Tab with, including the URL.
   * @param type Information about how the tab was launched.
   * @param parentId ID of the parent tab, if it exists.
   */
  public void createNewTab(AsyncTabCreationParams asyncParams, TabLaunchType type, int parentId) {
    assert asyncParams != null;

    // Tabs should't be launched in affiliated mode when a webcontents exists.
    assert !(type == TabLaunchType.FROM_LONGPRESS_BACKGROUND
        && asyncParams.getWebContents() != null);

    Context context = ApplicationStatus.getApplicationContext();
    Activity parentActivity = ActivityDelegate.getActivityForTabId(parentId);

    boolean mayLaunchDocumentActivity = isAllowedToLaunchDocumentActivity(context);
    assert mayLaunchDocumentActivity || (asyncParams.getWebContents() == null);

    if (FeatureUtilities.isDocumentMode(context) && mayLaunchDocumentActivity) {
      AsyncDocumentLauncher.getInstance().enqueueLaunch(mIsIncognito, parentId, asyncParams);
    } else {
      // TODO(dfalcantara): Is it possible to get rid of this conditional?
      int assignedTabId = TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID);
      AsyncTabCreationParamsManager.add(assignedTabId, asyncParams);

      Intent intent =
          new Intent(Intent.ACTION_VIEW, Uri.parse(asyncParams.getLoadUrlParams().getUrl()));
      intent.setClass(context, ChromeLauncherActivity.class);
      intent.putExtra(IntentHandler.EXTRA_TAB_ID, assignedTabId);
      intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito);
      intent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parentId);

      if (parentActivity != null && parentActivity.getIntent() != null) {
        intent.putExtra(IntentHandler.EXTRA_PARENT_INTENT, parentActivity.getIntent());
      }

      if (asyncParams.getRequestId() != null) {
        intent.putExtra(
            ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA, asyncParams.getRequestId().intValue());
      }

      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      IntentHandler.startActivityForTrustedIntent(intent, context);
    }
  }