Java Code Examples for org.chromium.chrome.browser.tab.Tab#addObserver()

The following examples show how to use org.chromium.chrome.browser.tab.Tab#addObserver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompositorViewHolder.java    From delion with Apache License 2.0 6 votes vote down vote up
private void setTab(Tab tab) {
    if (tab != null) tab.loadIfNeeded();

    View newView = tab != null ? tab.getView() : null;
    if (mView == newView) return;

    // TODO(dtrainor): Look into changing this only if the views differ, but still parse the
    // ContentViewCore list even if they're the same.
    updateContentOverlayVisibility(false);

    if (mTabVisible != tab) {
        if (mTabVisible != null) mTabVisible.removeObserver(mTabObserver);
        if (tab != null) tab.addObserver(mTabObserver);
    }

    mTabVisible = tab;
    mView = newView;

    updateContentOverlayVisibility(mContentOverlayVisiblity);

    if (mTabVisible != null) initializeTab(mTabVisible);
}
 
Example 2
Source File: OfflinePageTabObserver.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
void startObservingTab(Tab tab) {
    if (!tab.isOfflinePage()) return;

    mCurrentTab = tab;

    // If we are not observing the tab yet, let's.
    if (!isObservingTab(tab)) {
        // Adding a tab happens from inside of onPageLoadFinished, therefore if this is the time
        // we start observing the tab, the page inside of it is already loaded.
        mObservedTabs.put(tab.getId(), new TabState(true));
        tab.addObserver(this);
    }

    // If we are not observing network changes yet, let's.
    if (!isObservingNetworkChanges()) {
        startObservingNetworkChanges();
        mIsObservingNetworkChanges = true;
    }
}
 
Example 3
Source File: CompositorViewHolder.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void setTab(Tab tab) {
    if (tab != null) tab.loadIfNeeded();

    View newView = tab != null ? tab.getView() : null;
    if (mView == newView) return;

    // TODO(dtrainor): Look into changing this only if the views differ, but still parse the
    // ContentViewCore list even if they're the same.
    updateContentOverlayVisibility(false);

    if (mTabVisible != tab) {
        if (mTabVisible != null) mTabVisible.removeObserver(mTabObserver);
        if (tab != null) tab.addObserver(mTabObserver);
    }

    mTabVisible = tab;
    mView = newView;

    updateContentOverlayVisibility(mContentOverlayVisiblity);

    if (mTabVisible != null) initializeTab(mTabVisible);
}
 
Example 4
Source File: InfoBarContainer.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
public InfoBarContainer(Context context, int tabId, TabContentViewParent parentView, Tab tab) {
    super(context, null);
    tab.addObserver(mTabObserver);

    // TODO(newt): move this workaround into the infobar views if/when they're scrollable.
    // Workaround for http://crbug.com/407149. See explanation in onMeasure() below.
    setVerticalScrollBarEnabled(false);

    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
    int topMarginDp = DeviceFormFactor.isTablet(context)
            ? TOP_MARGIN_TABLET_DP : TOP_MARGIN_PHONE_DP;
    lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics().density);
    setLayoutParams(lp);

    mTabId = tabId;
    mParentView = parentView;

    mLayout = new InfoBarContainerLayout(context);
    addView(mLayout, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));

    // Chromium's InfoBarContainer may add an InfoBar immediately during this initialization
    // call, so make sure everything in the InfoBarContainer is completely ready beforehand.
    mNativeInfoBarContainer = nativeInit();
}
 
Example 5
Source File: CustomTabActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
private Tab createMainTab() {
    CustomTabsConnection customTabsConnection =
            CustomTabsConnection.getInstance(getApplication());
    String url = getUrlToLoad();
    // Get any referrer that has been explicitly set by the app.
    String referrerUrl = IntentHandler.getReferrerUrlIncludingExtraHeaders(getIntent(), this);
    if (referrerUrl == null) {
        Referrer referrer = customTabsConnection.getReferrerForSession(mSession);
        if (referrer != null) referrerUrl = referrer.getUrl();
    }
    Tab tab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID),
            Tab.INVALID_TAB_ID, false, this, getWindowAndroid(),
            TabLaunchType.FROM_EXTERNAL_APP, null, null);
    tab.setAppAssociatedWith(customTabsConnection.getClientPackageNameForSession(mSession));

    mPrerenderedUrl = customTabsConnection.getPrerenderedUrl(mSession);
    WebContents webContents =
            customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl);
    mHasPrerendered = webContents != null;
    if (webContents == null) webContents = customTabsConnection.takeSpareWebContents();
    if (webContents == null) webContents = WebContentsFactory.createWebContents(false, false);
    tab.initialize(webContents, getTabContentManager(),
            new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding()), false,
            false);
    tab.getTabRedirectHandler().updateIntent(getIntent());
    tab.getView().requestFocus();
    mTabObserver = new CustomTabObserver(getApplication(), mSession);
    tab.addObserver(mTabObserver);
    return tab;
}
 
Example 6
Source File: OfflinePageUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabModel.TabLaunchType type) {
    tab.addObserver(sTabRestoreTracker);

    Profile profile = mTabModelSelector.getModel(tab.isIncognito()).getProfile();
    OfflinePageBridge bridge = OfflinePageBridge.getForProfile(profile);
    if (bridge == null) return;
    bridge.registerRecentTab(tab.getId());
}
 
Example 7
Source File: ContextualSearchTabHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private ContextualSearchTabHelper(Tab tab) {
    mTab = tab;
    tab.addObserver(this);
    // Connect to a network, unless under test.
    if (NetworkChangeNotifier.isInitialized()) {
        NetworkChangeNotifier.addConnectionTypeObserver(this);
    }
}
 
Example 8
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void initializeMainTab(Tab tab) {
    tab.getTabRedirectHandler().updateIntent(getIntent());
    tab.getView().requestFocus();
    mTabObserver = new CustomTabObserver(
            getApplication(), mSession, mIntentDataProvider.isOpenedByChrome());

    mMetricsObserver = new PageLoadMetricsObserver(
            CustomTabsConnection.getInstance(getApplication()), mSession, tab);
    tab.addObserver(mTabObserver);

    prepareTabBackground(tab);
}
 
Example 9
Source File: AccessibilityTabModelListItem.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the {@link Tab} this {@link View} will represent in the list.
 * @param tab     The {@link Tab} to represent.
 * @param canUndo Whether or not closing this {@link Tab} can be undone.
 */
public void setTab(Tab tab, boolean canUndo) {
    if (mTab != null) mTab.removeObserver(mTabObserver);
    mTab = tab;
    tab.addObserver(mTabObserver);
    mCanUndo = canUndo;
    updateTabTitle();
    updateFavicon();
}
 
Example 10
Source File: AccessibilityTabModelListItem.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the {@link Tab} this {@link View} will represent in the list.
 * @param tab     The {@link Tab} to represent.
 * @param canUndo Whether or not closing this {@link Tab} can be undone.
 */
public void setTab(Tab tab, boolean canUndo) {
    if (mTab != null) mTab.removeObserver(mTabObserver);
    mTab = tab;
    tab.addObserver(mTabObserver);
    mCanUndo = canUndo;
    updateTabTitle();
    updateFavicon();
}
 
Example 11
Source File: CustomTabActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void initializeMainTab(Tab tab) {
    tab.getTabRedirectHandler().updateIntent(getIntent());
    tab.getView().requestFocus();
    mTabObserver = new CustomTabObserver(
            getApplication(), mSession, mIntentDataProvider.isOpenedByChrome());

    mMetricsObserver = new PageLoadMetricsObserver(
            CustomTabsConnection.getInstance(getApplication()), mSession, tab);
    tab.addObserver(mTabObserver);

    prepareTabBackground(tab);
}
 
Example 12
Source File: ContextualSearchTabHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private ContextualSearchTabHelper(Tab tab) {
    mTab = tab;
    tab.addObserver(this);
    // Connect to a network, unless under test.
    if (NetworkChangeNotifier.isInitialized()) {
        NetworkChangeNotifier.addConnectionTypeObserver(this);
    }
}
 
Example 13
Source File: AccessibilityTabModelListItem.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the {@link Tab} this {@link View} will represent in the list.
 * @param tab     The {@link Tab} to represent.
 * @param canUndo Whether or not closing this {@link Tab} can be undone.
 */
public void setTab(Tab tab, boolean canUndo) {
    if (mTab != null) mTab.removeObserver(mTabObserver);
    mTab = tab;
    tab.addObserver(mTabObserver);
    mCanUndo = canUndo;
    updateTabTitle();
    updateFavicon();
}
 
Example 14
Source File: OfflinePageTabObserver.java    From delion with Apache License 2.0 4 votes vote down vote up
public void addObserver(Tab tab, TabObserver observer) {
    if (tab != null && observer != null) {
        tab.addObserver(observer);
    }
}
 
Example 15
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType type) {
    PageLoadMetrics.addObserver(mMetricsObserver);
    tab.addObserver(mTabObserver);
}
 
Example 16
Source File: ContextualSearchTabHelper.java    From delion with Apache License 2.0 4 votes vote down vote up
private ContextualSearchTabHelper(Tab tab) {
    mTab = tab;
    tab.addObserver(this);
}
 
Example 17
Source File: CustomTabActivity.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType type) {
    tab.addObserver(mTabObserver);
}
 
Example 18
Source File: NewTabPageUma.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * Records stats related to content suggestion visits, such as the time spent on the website, or
 * if the user comes back to the NTP.
 * @param tab Tab opened to load a content suggestion.
 * @param category The category of the content suggestion.
 */
public static void monitorContentSuggestionVisit(Tab tab, int category) {
    tab.addObserver(new SnippetVisitRecorder(category));
}
 
Example 19
Source File: NewTabPageUma.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Records stats related to content suggestion visits, such as the time spent on the website, or
 * if the user comes back to the NTP.
 * @param tab Tab opened to load a content suggestion.
 * @param category The category of the content suggestion.
 */
public static void monitorContentSuggestionVisit(Tab tab, int category) {
    tab.addObserver(new SnippetVisitRecorder(category));
}
 
Example 20
Source File: NewTabPageUma.java    From delion with Apache License 2.0 2 votes vote down vote up
/**
 * Records stats related to article visits, such as the time spent on the website, or if the
 * user comes back to the NTP.
 * @param tab Tab opened to load an article.
 */
public static void monitorVisit(Tab tab) {
    tab.addObserver(new SnippetVisitRecorder());
}