Exemple #1
0
  @Override
  public Tab createNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent) {
    AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlParams);

    // Figure out how the page will be launched.
    if (TextUtils.equals(UrlConstants.NTP_URL, loadUrlParams.getUrl())) {
      asyncParams.setDocumentLaunchMode(ChromeLauncherActivity.LAUNCH_MODE_RETARGET);
    } else if (type == TabLaunchType.FROM_LONGPRESS_BACKGROUND) {
      if (!parent.isIncognito() && mIsIncognito) {
        // Incognito tabs opened from regular tabs open in the foreground for privacy
        // concerns.
        asyncParams.setDocumentLaunchMode(ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND);
      } else {
        asyncParams.setDocumentLaunchMode(ChromeLauncherActivity.LAUNCH_MODE_AFFILIATED);
      }
    }

    // Classify the startup type.
    if (parent != null && TextUtils.equals(UrlConstants.NTP_URL, parent.getUrl())) {
      asyncParams.setDocumentStartedBy(DocumentMetricIds.STARTED_BY_CHROME_HOME_MOST_VISITED);
    } else if (type == TabLaunchType.FROM_LONGPRESS_BACKGROUND
        || type == TabLaunchType.FROM_LONGPRESS_FOREGROUND) {
      asyncParams.setDocumentStartedBy(DocumentMetricIds.STARTED_BY_CONTEXT_MENU);
    } else if (type == TabLaunchType.FROM_MENU_OR_OVERVIEW) {
      asyncParams.setDocumentStartedBy(DocumentMetricIds.STARTED_BY_OPTIONS_MENU);
    }

    // Tab is created aysnchronously.  Can't return anything, yet.
    createNewTab(asyncParams, type, parent == null ? Tab.INVALID_TAB_ID : parent.getId());
    return null;
  }
Exemple #2
0
  /**
   * Creates a Tab to host the given WebContents asynchronously.
   *
   * @param webContents WebContents that has been pre-created.
   * @param parentId ID of the parent Tab.
   * @param type Launch type for the Tab.
   * @param url URL that the WebContents was opened for.
   * @param startedBy See {@link DocumentMetricIds}.
   */
  public boolean createTabWithWebContents(
      WebContents webContents, int parentId, TabLaunchType type, String url, int startedBy) {
    if (url == null) url = "";

    // TODO(dfalcantara): Does this transition make sense? (crbug.com/509886)
    int pageTransition =
        startedBy == DocumentMetricIds.STARTED_BY_CHROME_HOME_RECENT_TABS
            ? PageTransition.RELOAD
            : PageTransition.AUTO_TOPLEVEL;

    AsyncTabCreationParams asyncParams =
        new AsyncTabCreationParams(new LoadUrlParams(url, pageTransition), webContents);
    asyncParams.setDocumentStartedBy(startedBy);
    createNewTab(asyncParams, type, parentId);
    return true;
  }