示例#1
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);
    }
  }
 /**
  * Generates an ID for a new Tab. Makes sure the DocumentTabModels are loaded beforehand to ensure
  * that the ID counter is properly initialized.
  *
  * @return ID to use for the new Tab.
  */
 public int generateValidTabId() {
   return TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID);
 }
 private void initializeTabIdCounter() {
   int biggestId = getLargestTaskIdFromRecents();
   biggestId = getMaxTabId(mRegularTabModel, biggestId);
   biggestId = getMaxTabId(mIncognitoTabModel, biggestId);
   TabIdManager.getInstance().incrementIdCounterTo(biggestId + 1);
 }