Search in sources :

Example 36 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class CustomTabAppMenuPropertiesDelegate method prepareMenu.

@Override
public void prepareMenu(Menu menu) {
    Tab currentTab = mActivity.getActivityTab();
    if (currentTab != null) {
        MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id);
        forwardMenuItem.setEnabled(currentTab.canGoForward());
        mReloadMenuItem = menu.findItem(R.id.reload_menu_id);
        mReloadMenuItem.setIcon(R.drawable.btn_reload_stop);
        loadingStateChanged(currentTab.isLoading());
        MenuItem shareItem = menu.findItem(R.id.share_row_menu_id);
        shareItem.setVisible(mShowShare);
        shareItem.setEnabled(mShowShare);
        if (mShowShare) {
            ShareHelper.configureDirectShareMenuItem(mActivity, menu.findItem(R.id.direct_share_menu_id));
        }
        MenuItem iconRow = menu.findItem(R.id.icon_row_menu_id);
        MenuItem openInChromeItem = menu.findItem(R.id.open_in_browser_id);
        if (mIsMediaViewer) {
            // Most of the menu items don't make sense when viewing media.
            iconRow.setVisible(false);
            openInChromeItem.setVisible(false);
        } else {
            try {
                openInChromeItem.setTitle(mDefaultBrowserFetcher.get());
            } catch (InterruptedException | ExecutionException e) {
                openInChromeItem.setTitle(mActivity.getString(R.string.menu_open_in_product_default));
            }
        }
        // Add custom menu items. Make sure they are only added once.
        if (!mIsCustomEntryAdded) {
            mIsCustomEntryAdded = true;
            for (int i = 0; i < mMenuEntries.size(); i++) {
                MenuItem item = menu.add(0, 0, 1, mMenuEntries.get(i));
                mItemToIndexMap.put(item, i);
            }
        }
    }
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) MenuItem(android.view.MenuItem) ExecutionException(java.util.concurrent.ExecutionException)

Example 37 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class CustomTabBottomBarDelegate method sendPendingIntentWithUrl.

private static void sendPendingIntentWithUrl(PendingIntent pendingIntent, Intent extraIntent, ChromeActivity activity) {
    Intent addedIntent = extraIntent == null ? new Intent() : new Intent(extraIntent);
    Tab tab = activity.getActivityTab();
    if (tab != null)
        addedIntent.setData(Uri.parse(tab.getUrl()));
    try {
        pendingIntent.send(activity, 0, addedIntent, null, null);
    } catch (CanceledException e) {
        Log.e(TAG, "CanceledException when sending pending intent.");
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) Tab(org.chromium.chrome.browser.tab.Tab) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 38 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ReaderModeManager method createWebContentsObserver.

protected WebContentsObserver createWebContentsObserver(WebContents webContents) {
    final int readerTabId = mTabModelSelector.getCurrentTabId();
    if (readerTabId == Tab.INVALID_TAB_ID)
        return null;
    return new WebContentsObserver(webContents) {

        @Override
        public void didStartProvisionalLoadForFrame(long frameId, long parentFrameId, boolean isMainFrame, String validatedUrl, boolean isErrorPage, boolean isIframeSrcdoc) {
            if (!isMainFrame)
                return;
            // once the distillability test is successful.
            if (readerTabId == mTabModelSelector.getCurrentTabId()) {
                closeReaderPanel(StateChangeReason.TAB_NAVIGATION, false);
            }
            // Make sure the tab was not destroyed.
            ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId);
            if (tabInfo == null)
                return;
            tabInfo.setUrl(validatedUrl);
            if (DomDistillerUrlUtils.isDistilledPage(validatedUrl)) {
                tabInfo.setStatus(STARTED);
                mReaderModePageUrl = validatedUrl;
            }
        }

        @Override
        public void didNavigateMainFrame(String url, String baseUrl, boolean isNavigationToDifferentPage, boolean isNavigationInPage, int statusCode) {
            // (like those from history.replaceState()).
            if (isNavigationInPage)
                return;
            if (DomDistillerUrlUtils.isDistilledPage(url))
                return;
            // Make sure the tab was not destroyed.
            ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId);
            if (tabInfo == null)
                return;
            tabInfo.setStatus(POSSIBLE);
            if (!TextUtils.equals(url, DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(mReaderModePageUrl))) {
                tabInfo.setStatus(NOT_POSSIBLE);
                mIsUmaRecorded = false;
            }
            mReaderModePageUrl = null;
            if (tabInfo.getStatus() != POSSIBLE) {
                closeReaderPanel(StateChangeReason.UNKNOWN, false);
            } else {
                requestReaderPanelShow(StateChangeReason.UNKNOWN);
            }
        }

        @Override
        public void navigationEntryCommitted() {
            // Make sure the tab was not destroyed.
            ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId);
            if (tabInfo == null)
                return;
            // Reset closed state of reader mode in this tab once we know a navigation is
            // happening.
            tabInfo.setIsDismissed(false);
            // If the panel was not shown for the previous navigation, record it now.
            Tab curTab = mTabModelSelector.getTabById(readerTabId);
            if (curTab != null && !curTab.isNativePage() && !curTab.isBeingRestored()) {
                recordPanelVisibilityForNavigation(false);
            }
            tabInfo.setIsPanelShowRecorded(false);
        }
    };
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) WebContentsObserver(org.chromium.content_public.browser.WebContentsObserver)

Example 39 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ReaderModeManager method restoreInfobars.

/**
     * Restore any infobars that may have been hidden by Reader Mode.
     */
private void restoreInfobars() {
    if (!mIsInfoBarContainerShown)
        return;
    Tab curTab = mTabModelSelector.getCurrentTab();
    if (curTab == null)
        return;
    InfoBarContainer container = curTab.getInfoBarContainer();
    if (container == null)
        return;
    container.setIsObscuredByOtherView(false);
    // Temporarily hides the reader mode button while the infobars are shown.
    closeReaderPanel(StateChangeReason.INFOBAR_SHOWN, false);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) InfoBarContainer(org.chromium.chrome.browser.infobar.InfoBarContainer)

Example 40 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ReaderModeManager method onShown.

// TabModelSelectorTabObserver:
@Override
public void onShown(Tab shownTab) {
    int shownTabId = shownTab.getId();
    Tab previousTab = mTabModelSelector.getTabById(mTabId);
    mTabId = shownTabId;
    // If the reader panel was dismissed, stop here.
    if (mTabStatusMap.containsKey(shownTabId) && mTabStatusMap.get(shownTabId).isDismissed()) {
        return;
    }
    // Set this manager as the active one for the UI utils.
    DomDistillerUIUtils.setReaderModeManagerDelegate(this);
    // Update infobar state based on current tab.
    if (shownTab.getInfoBarContainer() != null) {
        mIsInfoBarContainerShown = shownTab.getInfoBarContainer().hasInfoBars();
    }
    // Remove the infobar observer from the previous tab and attach it to the current one.
    if (previousTab != null && previousTab.getInfoBarContainer() != null) {
        previousTab.getInfoBarContainer().removeObserver(this);
    }
    if (shownTab.getInfoBarContainer() != null) {
        shownTab.getInfoBarContainer().addObserver(this);
    }
    // If there is no state info for this tab, create it.
    ReaderModeTabInfo tabInfo = mTabStatusMap.get(shownTabId);
    if (tabInfo == null) {
        tabInfo = new ReaderModeTabInfo();
        tabInfo.setStatus(NOT_POSSIBLE);
        tabInfo.setUrl(shownTab.getUrl());
        mTabStatusMap.put(shownTabId, tabInfo);
    }
    // Make sure there is a WebContentsObserver on this tab's WebContents.
    if (tabInfo.getWebContentsObserver() == null) {
        tabInfo.setWebContentsObserver(createWebContentsObserver(shownTab.getWebContents()));
    }
    // Make sure there is a distillability delegate set on the WebContents.
    setDistillabilityCallback(shownTabId);
    requestReaderPanelShow(StateChangeReason.UNKNOWN);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Aggregations

Tab (org.chromium.chrome.browser.tab.Tab)116 LayoutTab (org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)13 TabModel (org.chromium.chrome.browser.tabmodel.TabModel)10 LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)9 SuppressLint (android.annotation.SuppressLint)8 TabModelSelectorTabObserver (org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver)8 Intent (android.content.Intent)5 FrameLayout (android.widget.FrameLayout)4 ContentViewCore (org.chromium.content.browser.ContentViewCore)4 WebContents (org.chromium.content_public.browser.WebContents)4 Activity (android.app.Activity)3 Bitmap (android.graphics.Bitmap)3 TabLaunchType (org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType)3 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 Bundle (android.os.Bundle)2 StrictMode (android.os.StrictMode)2 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2