Search in sources :

Example 16 with Tab

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

the class ChromeActivity method onMenuOrKeyboardAction.

/**
     * Handles menu item selection and keyboard shortcuts.
     *
     * @param id The ID of the selected menu item (defined in main_menu.xml) or
     *           keyboard shortcut (defined in values.xml).
     * @param fromMenu Whether this was triggered from the menu.
     * @return Whether the action was handled.
     */
public boolean onMenuOrKeyboardAction(int id, boolean fromMenu) {
    if (id == R.id.preferences_id) {
        PreferencesLauncher.launchSettingsPage(this, null);
        RecordUserAction.record("MobileMenuSettings");
    } else if (id == R.id.show_menu) {
        showAppMenuForKeyboardEvent();
    }
    if (id == R.id.update_menu_id) {
        UpdateMenuItemHelper.getInstance().onMenuItemClicked(this);
        return true;
    }
    // All the code below assumes currentTab is not null, so return early if it is null.
    final Tab currentTab = getActivityTab();
    if (currentTab == null) {
        return false;
    } else if (id == R.id.forward_menu_id) {
        if (currentTab.canGoForward()) {
            currentTab.goForward();
            RecordUserAction.record("MobileMenuForward");
            RecordUserAction.record("MobileTabClobbered");
        }
    } else if (id == R.id.bookmark_this_page_id) {
        addOrEditBookmark(currentTab);
        RecordUserAction.record("MobileMenuAddToBookmarks");
    } else if (id == R.id.offline_page_id) {
        DownloadUtils.downloadOfflinePage(this, currentTab);
        RecordUserAction.record("MobileMenuDownloadPage");
    } else if (id == R.id.reload_menu_id) {
        if (currentTab.isLoading()) {
            currentTab.stopLoading();
            RecordUserAction.record("MobileMenuStop");
        } else {
            currentTab.reload();
            RecordUserAction.record("MobileMenuReload");
        }
    } else if (id == R.id.info_menu_id) {
        WebsiteSettingsPopup.show(this, currentTab, null, WebsiteSettingsPopup.OPENED_FROM_MENU);
    } else if (id == R.id.open_history_menu_id) {
        currentTab.loadUrl(new LoadUrlParams(UrlConstants.HISTORY_URL, PageTransition.AUTO_TOPLEVEL));
        RecordUserAction.record("MobileMenuHistory");
        StartupMetrics.getInstance().recordOpenedHistory();
    } else if (id == R.id.share_menu_id || id == R.id.direct_share_menu_id) {
        onShareMenuItemSelected(id == R.id.direct_share_menu_id, getCurrentTabModel().isIncognito());
    } else if (id == R.id.print_id) {
        PrintingController printingController = PrintingControllerImpl.getInstance();
        if (printingController != null && !printingController.isBusy() && PrefServiceBridge.getInstance().isPrintingEnabled()) {
            printingController.startPrint(new TabPrinter(currentTab), new PrintManagerDelegateImpl(this));
            RecordUserAction.record("MobileMenuPrint");
        }
    } else if (id == R.id.add_to_homescreen_id) {
        AddToHomescreenManager addToHomescreenManager = new AddToHomescreenManager(this, currentTab);
        addToHomescreenManager.start();
        RecordUserAction.record("MobileMenuAddToHomescreen");
    } else if (id == R.id.request_desktop_site_id) {
        final boolean reloadOnChange = !currentTab.isNativePage();
        final boolean usingDesktopUserAgent = currentTab.getUseDesktopUserAgent();
        currentTab.setUseDesktopUserAgent(!usingDesktopUserAgent, reloadOnChange);
        RecordUserAction.record("MobileMenuRequestDesktopSite");
    } else if (id == R.id.reader_mode_prefs_id) {
        if (currentTab.getWebContents() != null) {
            RecordUserAction.record("DomDistiller_DistilledPagePrefsOpened");
            AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
            builder.setView(DistilledPagePrefsView.create(this));
            builder.show();
        }
    } else if (id == R.id.help_id) {
        // Since reading back the compositor is asynchronous, we need to do the readback
        // before starting the GoogleHelp.
        String helpContextId = HelpAndFeedback.getHelpContextIdFromUrl(this, currentTab.getUrl(), getCurrentTabModel().isIncognito());
        HelpAndFeedback.getInstance(this).show(this, helpContextId, currentTab.getProfile(), currentTab.getUrl());
        RecordUserAction.record("MobileMenuFeedback");
    } else {
        return false;
    }
    return true;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) PrintManagerDelegateImpl(org.chromium.printing.PrintManagerDelegateImpl) Tab(org.chromium.chrome.browser.tab.Tab) TabPrinter(org.chromium.chrome.browser.printing.TabPrinter) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) PrintingController(org.chromium.printing.PrintingController) AddToHomescreenManager(org.chromium.chrome.browser.webapps.AddToHomescreenManager)

Example 17 with Tab

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

the class ChromeActivity method removeViewObscuringAllTabs.

/**
     * Remove a view that previously obscured the content of all tabs.
     *
     * @param view The view that no longer obscures the contents of all tabs.
     */
public void removeViewObscuringAllTabs(View view) {
    mViewsObscuringAllTabs.remove(view);
    Tab tab = getActivityTab();
    if (tab != null)
        tab.updateAccessibilityVisibility();
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 18 with Tab

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

the class ChromeActivity method addViewObscuringAllTabs.

/**
     * Add a view to the set of views that obscure the content of all tabs for
     * accessibility. As long as this set is nonempty, all tabs should be
     * hidden from the accessibility tree.
     *
     * @param view The view that obscures the contents of all tabs.
     */
public void addViewObscuringAllTabs(View view) {
    mViewsObscuringAllTabs.add(view);
    Tab tab = getActivityTab();
    if (tab != null)
        tab.updateAccessibilityVisibility();
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 19 with Tab

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

the class ChromeActivity method setTabModelSelector.

/**
     * Sets the {@link TabModelSelector} owned by this {@link ChromeActivity}.
     * @param tabModelSelector A {@link TabModelSelector} instance.
     */
protected void setTabModelSelector(TabModelSelector tabModelSelector) {
    mTabModelSelector = tabModelSelector;
    if (mTabModelSelectorTabObserver != null)
        mTabModelSelectorTabObserver.destroy();
    mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(tabModelSelector) {

        @Override
        public void didFirstVisuallyNonEmptyPaint(Tab tab) {
            if (DataUseTabUIManager.checkAndResetDataUseTrackingStarted(tab) && DataUseTabUIManager.shouldShowDataUseStartedUI()) {
                mDataUseSnackbarController.showDataUseTrackingStartedBar();
            } else if (DataUseTabUIManager.shouldShowDataUseEndedUI() && DataUseTabUIManager.shouldShowDataUseEndedSnackbar(getApplicationContext()) && DataUseTabUIManager.checkAndResetDataUseTrackingEnded(tab)) {
                mDataUseSnackbarController.showDataUseTrackingEndedBar();
            }
        }

        @Override
        public void onShown(Tab tab) {
            setStatusBarColor(tab, tab.getThemeColor());
        }

        @Override
        public void onHidden(Tab tab) {
            mDataUseSnackbarController.dismissDataUseBar();
        }

        @Override
        public void onDestroyed(Tab tab) {
            mDataUseSnackbarController.dismissDataUseBar();
        }

        @Override
        public void onLoadStopped(Tab tab, boolean toDifferentDocument) {
            postDeferredStartupIfNeeded();
        }

        @Override
        public void onPageLoadFinished(Tab tab) {
            postDeferredStartupIfNeeded();
            OfflinePageUtils.showOfflineSnackbarIfNecessary(ChromeActivity.this, tab);
        }

        @Override
        public void onCrash(Tab tab, boolean sadTabShown) {
            postDeferredStartupIfNeeded();
        }

        @Override
        public void onDidChangeThemeColor(Tab tab, int color) {
            if (getActivityTab() != tab)
                return;
            setStatusBarColor(tab, color);
            if (getToolbarManager() == null)
                return;
            getToolbarManager().updatePrimaryColor(color, true);
            ControlContainer controlContainer = (ControlContainer) findViewById(R.id.control_container);
            controlContainer.getToolbarResourceAdapter().invalidate(null);
        }
    };
    if (mAssistStatusHandler != null) {
        mAssistStatusHandler.setTabModelSelector(tabModelSelector);
    }
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) ToolbarControlContainer(org.chromium.chrome.browser.toolbar.ToolbarControlContainer) ControlContainer(org.chromium.chrome.browser.widget.ControlContainer) TabModelSelectorTabObserver(org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver) SuppressLint(android.annotation.SuppressLint)

Example 20 with Tab

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

the class ChromeTabbedActivity method initializeCompositor.

@Override
public void initializeCompositor() {
    try {
        TraceEvent.begin("ChromeTabbedActivity.initializeCompositor");
        super.initializeCompositor();
        mTabModelSelectorImpl.onNativeLibraryReady(getTabContentManager());
        mVrShellDelegate.onNativeLibraryReady();
        mTabModelObserver = new EmptyTabModelObserver() {

            @Override
            public void didCloseTab(int tabId, boolean incognito) {
                closeIfNoTabsAndHomepageEnabled(false);
            }

            @Override
            public void tabPendingClosure(Tab tab) {
                closeIfNoTabsAndHomepageEnabled(true);
            }

            @Override
            public void tabRemoved(Tab tab) {
                closeIfNoTabsAndHomepageEnabled(false);
            }

            private void closeIfNoTabsAndHomepageEnabled(boolean isPendingClosure) {
                if (getTabModelSelector().getTotalTabCount() == 0) {
                    // If the last tab is closed, and homepage is enabled, then exit Chrome.
                    if (HomepageManager.isHomepageEnabled(getApplicationContext())) {
                        finish();
                    } else if (isPendingClosure) {
                        NewTabPageUma.recordNTPImpression(NewTabPageUma.NTP_IMPESSION_POTENTIAL_NOTAB);
                    }
                }
            }

            @Override
            public void didAddTab(Tab tab, TabLaunchType type) {
                if (type == TabLaunchType.FROM_LONGPRESS_BACKGROUND && !DeviceClassManager.enableAnimations(getApplicationContext())) {
                    Toast.makeText(ChromeTabbedActivity.this, R.string.open_in_new_tab_toast, Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void allTabsPendingClosure(List<Integer> tabIds) {
                NewTabPageUma.recordNTPImpression(NewTabPageUma.NTP_IMPESSION_POTENTIAL_NOTAB);
            }
        };
        for (TabModel model : mTabModelSelectorImpl.getModels()) {
            model.addObserver(mTabModelObserver);
        }
        Bundle state = getSavedInstanceState();
        if (state != null && state.containsKey(FRE_RUNNING)) {
            mIsOnFirstRun = state.getBoolean(FRE_RUNNING);
        }
    } finally {
        TraceEvent.end("ChromeTabbedActivity.initializeCompositor");
    }
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) Bundle(android.os.Bundle) TabLaunchType(org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType) SuppressLint(android.annotation.SuppressLint) EmptyTabModelObserver(org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver) TabModel(org.chromium.chrome.browser.tabmodel.TabModel)

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