예제 #1
0
  private void onNativeLibraryReady() {
    mNativeLibraryReady = true;
    mToolbar.onNativeLibraryReady();

    final TemplateUrlService templateUrlService = TemplateUrlService.getInstance();
    TemplateUrlService.LoadListener mTemplateServiceLoadListener =
        new TemplateUrlService.LoadListener() {
          @Override
          public void onTemplateUrlServiceLoaded() {
            registerTemplateUrlObserver();
            templateUrlService.unregisterLoadListener(this);
          }
        };
    templateUrlService.registerLoadListener(mTemplateServiceLoadListener);
    if (templateUrlService.isLoaded()) {
      mTemplateServiceLoadListener.onTemplateUrlServiceLoaded();
    } else {
      templateUrlService.load();
    }

    mTabModelSelector.addObserver(mTabModelSelectorObserver);
    for (TabModel model : mTabModelSelector.getModels()) model.addObserver(mTabModelObserver);

    refreshSelectedTab();
    if (mTabModelSelector.isTabStateInitialized()) mTabRestoreCompleted = true;
    handleTabRestoreCompleted();
  }
  /**
   * Sets the appropriate objects this class should represent.
   *
   * @param tabModelSelector The {@link TabModelSelector} this View should hold and represent.
   * @param tabCreatorManager The {@link TabCreatorManager} for this view.
   * @param tabContentManager The {@link TabContentManager} for the tabs.
   * @param androidContentContainer The {@link ViewGroup} the {@link LayoutManager} should bind
   *     Android content to.
   * @param contextualSearchManager A {@link ContextualSearchManagementDelegate} instance.
   */
  public void onFinishNativeInitialization(
      TabModelSelector tabModelSelector,
      TabCreatorManager tabCreatorManager,
      TabContentManager tabContentManager,
      ViewGroup androidContentContainer,
      ContextualSearchManagementDelegate contextualSearchManager) {
    assert mLayoutManager != null;
    mLayoutManager.init(
        tabModelSelector,
        tabCreatorManager,
        tabContentManager,
        androidContentContainer,
        contextualSearchManager,
        mCompositorView.getResourceManager().getDynamicResourceLoader());
    mTabModelSelector = tabModelSelector;
    tabModelSelector.addObserver(
        new EmptyTabModelSelectorObserver() {
          @Override
          public void onChange() {
            onContentChanged();
          }

          @Override
          public void onNewTabCreated(Tab tab) {
            initializeTab(tab);
          }
        });

    onContentChanged();
  }
예제 #3
0
  /** Triggered when the selected tab has changed. */
  private void refreshSelectedTab() {
    ChromeTab tab = null;
    if (mPreselectedTabId != Tab.INVALID_TAB_ID) {
      tab = ChromeTab.fromTab(mTabModelSelector.getTabById(mPreselectedTabId));
    }
    if (tab == null) tab = ChromeTab.fromTab(mTabModelSelector.getCurrentTab());

    boolean wasIncognito = mToolbarModel.isIncognito();
    ChromeTab previousTab = ChromeTab.fromTab(mToolbarModel.getTab());

    boolean isIncognito = tab != null ? tab.isIncognito() : mTabModelSelector.isIncognitoSelected();
    mToolbarModel.setTab(tab, isIncognito);

    updateCurrentTabDisplayStatus();
    if (previousTab != tab || wasIncognito != isIncognito) {
      if (previousTab != tab) {
        if (previousTab != null) previousTab.removeObserver(mTabObserver);
        if (tab != null) tab.addObserver(mTabObserver);
      }
      int defaultPrimaryColor =
          isIncognito
              ? mToolbar.getResources().getColor(R.color.incognito_primary_color)
              : mToolbar.getResources().getColor(R.color.default_primary_color);
      int primaryColor =
          (tab != null && tab.getWebContents() != null)
              ? tab.getWebContents().getThemeColor(defaultPrimaryColor)
              : defaultPrimaryColor;
      updatePrimaryColor(primaryColor);

      mToolbar.onTabOrModelChanged();

      if (tab != null
          && tab.getWebContents() != null
          && tab.getWebContents().isLoadingToDifferentDocument()) {
        mToolbar.onNavigatedToDifferentPage();
      }
    }

    Profile profile = mTabModelSelector.getModel(isIncognito).getProfile();
    if (mCurrentProfile != profile) {
      if (mBookmarksBridge != null) mBookmarksBridge.destroy();
      mBookmarksBridge = new BookmarksBridge(profile);
      mBookmarksBridge.addObserver(mBookmarksObserver);
      mLocationBar.setAutocompleteProfile(profile);
      mCurrentProfile = profile;
    }
  }
 /** Close a blank tab just opened for the download purpose. */
 private void closeBlankTab() {
   WebContents contents = mTab.getWebContents();
   boolean isInitialNavigation =
       contents == null || contents.getNavigationController().isInitialNavigation();
   if (isInitialNavigation) {
     // Tab is created just for download, close it.
     mTabModelSelector.closeTab(mTab);
   }
 }
 @Override
 public void onContentChanged() {
   if (mTabModelSelector == null) {
     // Not yet initialized, onContentChanged() will eventually get called by
     // setTabModelSelector.
     return;
   }
   Tab tab = mTabModelSelector.getCurrentTab();
   setTab(tab);
 }
 /**
  * Close a blank tab just opened for the download purpose.
  *
  * @return true iff the tab was (already) closed.
  */
 private boolean closeBlankTab() {
   if (mTab == null) {
     // We do not want caller to dismiss infobar.
     return true;
   }
   WebContents contents = mTab.getWebContents();
   boolean isInitialNavigation =
       contents == null || contents.getNavigationController().isInitialNavigation();
   if (isInitialNavigation) {
     // Tab is created just for download, close it.
     return mTabModelSelector.closeTab(mTab);
   }
   return false;
 }
예제 #7
0
 /** Updates the current number of Tabs based on the TabModel this Toolbar contains. */
 private void updateTabCount() {
   if (!mTabRestoreCompleted) return;
   mToolbar.updateTabCountVisuals(mTabModelSelector.getCurrentModel().getCount());
 }