コード例 #1
0
  @Override
  public void requestToShowTab(Tab tab, TabSelectionType type) {
    boolean isFromExternalApp =
        tab != null && tab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP;

    if (mVisibleTab != tab && tab != null && !tab.isNativePage()) {
      TabModelBase.startTabSwitchLatencyTiming(type);
    }
    if (mVisibleTab != null && mVisibleTab != tab && !mVisibleTab.needsReload()) {
      if (mVisibleTab.isInitialized()) {
        // TODO(dtrainor): Once we figure out why we can't grab a snapshot from the current
        // tab when we have other tabs loading from external apps remove the checks for
        // FROM_EXTERNAL_APP/FROM_NEW.
        if (!mVisibleTab.isClosing() && (!isFromExternalApp || type != TabSelectionType.FROM_NEW)) {
          cacheTabBitmap(mVisibleTab);
        }
        mVisibleTab.hide();
        mVisibleTab.setFullscreenManager(null);
        mTabSaver.addTabToSaveQueue(mVisibleTab);
      }
      mVisibleTab = null;
    }

    if (tab == null) {
      notifyChanged();
      return;
    }

    // We hit this case when the user enters tab switcher and comes back to the current tab
    // without actual tab switch.
    if (mVisibleTab == tab && !mVisibleTab.isHidden()) {
      // The current tab might have been killed by the os while in tab switcher.
      tab.loadIfNeeded();
      return;
    }

    tab.setFullscreenManager(mActivity.getFullscreenManager());
    mVisibleTab = tab;

    // Don't execute the tab display part if Chrome has just been sent to background. This
    // avoids uneccessary work (tab restore) and prevents pollution of tab display metrics - see
    // http://crbug.com/316166.
    if (type != TabSelectionType.FROM_EXIT) {
      tab.show(type);
      mUma.onShowTab(tab.getId(), tab.isBeingRestored());
    }
  }
コード例 #2
0
  /**
   * Creates a new tab and posts to UI.
   *
   * @param loadUrlParams parameters of the url load.
   * @param type Information about how the tab was launched.
   * @param parent the parent tab, if present.
   * @param position the requested position (index in the tab model)
   * @param intent the source of the url if it isn't null.
   * @return The new tab.
   */
  public ChromeTab createNewTab(
      LoadUrlParams loadUrlParams,
      TabModel.TabLaunchType type,
      Tab parent,
      int position,
      Intent intent) {
    try {
      TraceEvent.begin("ChromeTabCreator.createNewTab");
      int parentId = parent != null ? parent.getId() : Tab.INVALID_TAB_ID;
      WebContents webContents = IntentHandler.getWebContentsFromIntent(intent);
      boolean isWebContentsPaused = false;
      if (webContents != null) {
        // The WebContents comes with additional data, but it shouldn't be used if the
        // WebContents itself couldn't be parsed out.
        parentId =
            IntentUtils.safeGetIntExtra(
                intent, IntentHandler.EXTRA_PARENT_TAB_ID, Tab.INVALID_TAB_ID);
        isWebContentsPaused =
            IntentUtils.safeGetBooleanExtra(intent, IntentHandler.EXTRA_WEB_CONTENTS_PAUSED, false);
      }

      // Sanitize the url.
      loadUrlParams.setUrl(UrlUtilities.fixupUrl(loadUrlParams.getUrl()));
      loadUrlParams.setTransitionType(getTransitionType(type));

      boolean openInForeground =
          mOrderController.willOpenInForeground(type, mIncognito) || webContents != null;
      ChromeTab tab;
      if (webContents != null) {
        tab =
            ChromeTab.createLiveTab(
                Tab.INVALID_TAB_ID,
                mActivity,
                mIncognito,
                mNativeWindow,
                type,
                parentId,
                !openInForeground);
        tab.initialize(webContents, mTabContentManager, !openInForeground);
        tab.getTabRedirectHandler().updateIntent(intent);

        if (isWebContentsPaused) webContents.resumeLoadingCreatedWebContents();
      } else if (!openInForeground && SysUtils.isLowEndDevice()) {
        // On low memory devices the tabs opened in background are not loaded automatically
        // to preserve resources (cpu, memory, strong renderer binding) for the foreground
        // tab.
        tab =
            ChromeTab.createTabForLazyLoad(
                mActivity, mIncognito, mNativeWindow, type, parentId, loadUrlParams);
        tab.initialize(null, mTabContentManager, !openInForeground);
        mTabSaver.addTabToSaveQueue(tab);
        tab.getTabRedirectHandler().updateIntent(intent);
      } else {
        tab =
            ChromeTab.createLiveTab(
                Tab.INVALID_TAB_ID,
                mActivity,
                mIncognito,
                mNativeWindow,
                type,
                parentId,
                !openInForeground);

        webContents =
            WarmupManager.getInstance().hasPrerenderedUrl(loadUrlParams.getUrl())
                ? WarmupManager.getInstance().takePrerenderedWebContents()
                : null;
        tab.initialize(webContents, mTabContentManager, !openInForeground);
        tab.getTabRedirectHandler().updateIntent(intent);
        tab.loadUrl(loadUrlParams);
      }

      if (intent != null && intent.hasExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA)) {
        ServiceTabLauncher.onWebContentsForRequestAvailable(
            intent.getIntExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA, 0),
            tab.getWebContents());
      }

      mTabModel.addTab(tab, position, type);

      return tab;
    } finally {
      TraceEvent.end("ChromeTabCreator.createNewTab");
    }
  }
コード例 #3
0
 private void handleOnPageLoadStopped(Tab tab) {
   if (tab != null) mTabSaver.addTabToSaveQueue(tab);
 }