org.chromium.chrome.browser.tab.Tab Java Examples
The following examples show how to use
org.chromium.chrome.browser.tab.Tab.
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: ExternalNavigationParams.java From delion with Apache License 2.0 | 6 votes |
private ExternalNavigationParams(String url, boolean isIncognito, String referrerUrl, int pageTransition, boolean isRedirect, boolean appMustBeInForeground, TabRedirectHandler redirectHandler, Tab tab, boolean openInNewTab, boolean isBackgroundTabNavigation, boolean isMainFrame, String webApkPackageName, boolean hasUserGesture, boolean shouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent) { mUrl = url; mIsIncognito = isIncognito; mPageTransition = pageTransition; mReferrerUrl = referrerUrl; mIsRedirect = isRedirect; mApplicationMustBeInForeground = appMustBeInForeground; mRedirectHandler = redirectHandler; mTab = tab; mOpenInNewTab = openInNewTab; mIsBackgroundTabNavigation = isBackgroundTabNavigation; mIsMainFrame = isMainFrame; mWebApkPackageName = webApkPackageName; mHasUserGesture = hasUserGesture; mShouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent = shouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent; }
Example #2
Source File: TabModelImpl.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override public void openMostRecentlyClosedTab() { // First try to recover tab from rewound list, same as {@link UndoBarController}. if (mRewoundList.hasPendingClosures()) { Tab tab = mRewoundList.getNextRewindableTab(); if (tab == null) return; cancelTabClosure(tab.getId()); return; } // If there are no pending closures in the rewound list, // then try to restore the tab from the native tab restore service. mRecentlyClosedBridge.openRecentlyClosedTab(); // If there is only one tab, select it. if (getCount() == 1) setIndex(0, TabSelectionType.FROM_NEW); }
Example #3
Source File: LayoutManagerChromePhone.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override protected void tabClosed(int id, int nextId, boolean incognito, boolean tabRemoved) { boolean showOverview = nextId == Tab.INVALID_TAB_ID; Layout overviewLayout = useAccessibilityLayout() ? mOverviewListLayout : mOverviewLayout; if (getActiveLayout() != overviewLayout && showOverview) { // Since there will be no 'next' tab to display, switch to // overview mode when the animation is finished. setNextLayout(overviewLayout); } getActiveLayout().onTabClosed(time(), id, nextId, incognito); Tab nextTab = getTabById(nextId); if (nextTab != null) nextTab.requestFocus(); boolean animate = !tabRemoved && animationsEnabled(); if (getActiveLayout() != overviewLayout && showOverview && !animate) { startShowing(overviewLayout, false); } }
Example #4
Source File: ChromeTabCreator.java From 365browser with Apache License 2.0 | 6 votes |
@Override public boolean createTabWithWebContents(Tab parent, WebContents webContents, int parentId, TabLaunchType type, String url) { // The parent tab was already closed. Do not open child tabs. if (mTabModel.isClosurePending(parentId)) return false; // If parent is in the same tab model, place the new tab next to it. int position = TabModel.INVALID_TAB_INDEX; int index = TabModelUtils.getTabIndexById(mTabModel, parentId); if (index != TabModel.INVALID_TAB_INDEX) position = index + 1; boolean openInForeground = mOrderController.willOpenInForeground(type, mIncognito); TabDelegateFactory delegateFactory = parent == null ? createDefaultTabDelegateFactory() : parent.getDelegateFactory(); Tab tab = Tab.createLiveTab(Tab.INVALID_TAB_ID, mActivity, mIncognito, mNativeWindow, type, parentId, !openInForeground); tab.initialize(webContents, mTabContentManager, delegateFactory, !openInForeground, false); mTabModel.addTab(tab, position, type); return true; }
Example #5
Source File: TabPersistentStore.java From 365browser with Apache License 2.0 | 5 votes |
/** * Serializes {@code selector} to a byte array, copying out the data pertaining to tab ordering * and selected indices. * @param selector The {@link TabModelSelector} to serialize. * @param tabsBeingRestored Tabs that are in the process of being restored. * @return {@code byte[]} containing the serialized state of {@code selector}. */ @VisibleForTesting public static byte[] serializeTabModelSelector(TabModelSelector selector, List<TabRestoreDetails> tabsBeingRestored) throws IOException { ThreadUtils.assertOnUiThread(); TabModel incognitoModel = selector.getModel(true); TabModelMetadata incognitoInfo = new TabModelMetadata(incognitoModel.index()); for (int i = 0; i < incognitoModel.getCount(); i++) { incognitoInfo.ids.add(incognitoModel.getTabAt(i).getId()); incognitoInfo.urls.add(incognitoModel.getTabAt(i).getUrl()); } TabModel normalModel = selector.getModel(false); TabModelMetadata normalInfo = new TabModelMetadata(normalModel.index()); for (int i = 0; i < normalModel.getCount(); i++) { normalInfo.ids.add(normalModel.getTabAt(i).getId()); normalInfo.urls.add(normalModel.getTabAt(i).getUrl()); } // Cache the active tab id to be pre-loaded next launch. int activeTabId = Tab.INVALID_TAB_ID; int activeIndex = normalModel.index(); if (activeIndex != TabList.INVALID_TAB_INDEX) { activeTabId = normalModel.getTabAt(activeIndex).getId(); } // Always override the existing value in case there is no active tab. ContextUtils.getAppSharedPreferences().edit().putInt( PREF_ACTIVE_TAB_ID, activeTabId).apply(); return serializeMetadata(normalInfo, incognitoInfo, tabsBeingRestored); }
Example #6
Source File: ToolbarModelImpl.java From delion with Apache License 2.0 | 5 votes |
/** * Sets the tab that contains the information to be displayed in the toolbar. * @param tab The tab associated currently with the toolbar. * @param isIncognito Whether the incognito model is currently selected, which must match the * passed in tab if non-null. */ public void setTab(Tab tab, boolean isIncognito) { mTab = tab; if (mTab != null) { assert mTab.isIncognito() == isIncognito; } mIsIncognito = isIncognito; }
Example #7
Source File: ToolbarManager.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Updates the current button states and calls appropriate abstract visibility methods, giving * inheriting classes the chance to update the button visuals as well. */ private void updateButtonStatus() { Tab currentTab = mToolbarModel.getTab(); boolean tabCrashed = currentTab != null && currentTab.isShowingSadTab(); mToolbar.updateButtonVisibility(); mToolbar.updateBackButtonVisibility(currentTab != null && currentTab.canGoBack()); mToolbar.updateForwardButtonVisibility(currentTab != null && currentTab.canGoForward()); updateReloadState(tabCrashed); updateBookmarkButtonStatus(); mToolbar.getMenuButtonWrapper().setVisibility(View.VISIBLE); }
Example #8
Source File: TabModelUtils.java From 365browser with Apache License 2.0 | 5 votes |
/** * @param model The {@link TabModel} to act on. * @param tabId The id of the {@link Tab} to close. * @param canUndo Whether or not this closure can be undone. * @return {@code true} if the {@link Tab} was found. */ public static boolean closeTabById(TabModel model, int tabId, boolean canUndo) { Tab tab = TabModelUtils.getTabById(model, tabId); if (tab == null) return false; return model.closeTab(tab, true, false, canUndo); }
Example #9
Source File: ChromeActivity.java From delion with Apache License 2.0 | 5 votes |
/** * 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(); }
Example #10
Source File: ReaderModeManager.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void onDestroyed(Tab tab) { if (tab == null) return; if (tab.getInfoBarContainer() != null) { tab.getInfoBarContainer().removeObserver(this); } // If the panel was not shown for the previous navigation, record it now. ReaderModeTabInfo info = mTabStatusMap.get(tab.getId()); if (info != null && !info.isPanelShowRecorded()) { recordPanelVisibilityForNavigation(false); } removeTabState(tab.getId()); }
Example #11
Source File: TabModelImpl.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Actually closes and cleans up {@code tab}. * @param tab The {@link Tab} to close. */ private void finalizeTabClosure(Tab tab) { if (mTabContentManager != null) mTabContentManager.removeTabThumbnail(tab.getId()); mTabSaver.removeTabFromQueues(tab); if (!isIncognito()) tab.createHistoricalTab(); tab.destroy(); for (TabModelObserver obs : mObservers) obs.didCloseTab(tab.getId(), tab.isIncognito()); }
Example #12
Source File: ToolbarModelImpl.java From 365browser with Apache License 2.0 | 5 votes |
@Override public Tab getTab() { // TODO(dtrainor, tedchoc): Remove the isInitialized() check when we no longer wait for // TAB_CLOSED events to remove this tab. Otherwise there is a chance we use this tab after // {@link ChromeTab#destroy()} is called. if (mBottomSheet != null && mBottomSheet.isShowingNewTab()) { return null; } return (mTab == null || !mTab.isInitialized()) ? null : mTab; }
Example #13
Source File: LayoutManagerChrome.java From delion with Apache License 2.0 | 5 votes |
@Override public void willAddTab(Tab tab, TabLaunchType type) { // Open the new tab if (type == TabLaunchType.FROM_RESTORE) return; if (type == TabLaunchType.FROM_REPARENTING) return; tabCreating(getTabModelSelector().getCurrentTabId(), tab.getUrl(), tab.isIncognito()); }
Example #14
Source File: ToolbarManager.java From 365browser with Apache License 2.0 | 5 votes |
@Override public boolean forward() { Tab tab = mToolbarModel.getTab(); if (tab != null && tab.canGoForward()) { tab.goForward(); updateButtonStatus(); return true; } return false; }
Example #15
Source File: StackLayout.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Get the tab stack state for the specified tab id. * * @param tabId The id of the tab to lookup. * @return The tab stack index for the given tab id. * @VisibleForTesting */ protected int getTabStackIndex(int tabId) { if (tabId == Tab.INVALID_TAB_ID) { boolean incognito = mTemporarySelectedStack != null ? mTemporarySelectedStack : mTabModelSelector.isIncognitoSelected(); return incognito ? 1 : 0; } else { return TabModelUtils.getTabById(mTabModelSelector.getModel(true), tabId) != null ? 1 : 0; } }
Example #16
Source File: PreferencesLauncher.java From 365browser with Apache License 2.0 | 5 votes |
/** * Opens the UI to clear browsing data. * @param tab The tab that triggered the request. */ @CalledByNative private static void openClearBrowsingData(Tab tab) { Activity activity = tab.getWindowAndroid().getActivity().get(); if (activity == null) { Log.e(TAG, "Attempting to open clear browsing data for a tab without a valid activity"); return; } Intent intent = createIntentForClearBrowsingDataPage(activity); activity.startActivity(intent); }
Example #17
Source File: TabModelImpl.java From delion with Apache License 2.0 | 5 votes |
/** * Close all tabs on this model without notifying observers about pending tab closures. * * @param animate true iff the closing animation should be displayed * @param uponExit true iff the tabs are being closed upon application exit (after user presses * the system back button) * @param canUndo Whether or not this action can be undone. If this is {@code true} and * {@link #supportsPendingClosures()} is {@code true}, these {@link Tab}s * will not actually be closed until {@link #commitTabClosure(int)} or * {@link #commitAllTabClosures()} is called, but they will be effectively * removed from this list. */ public void closeAllTabs(boolean animate, boolean uponExit, boolean canUndo) { for (int i = 0; i < getCount(); i++) getTabAt(i).setClosing(true); ArrayList<Integer> closedTabs = new ArrayList<Integer>(); while (getCount() > 0) { Tab tab = getTabAt(0); closedTabs.add(tab.getId()); closeTab(tab, animate, uponExit, canUndo, false); } if (!uponExit && canUndo && supportsPendingClosures()) { for (TabModelObserver obs : mObservers) obs.allTabsPendingClosure(closedTabs); } }
Example #18
Source File: LayoutManagerChromePhone.java From delion with Apache License 2.0 | 5 votes |
@Override protected void tabCreated(int id, int sourceId, TabLaunchType launchType, boolean isIncognito, boolean willBeSelected, float originX, float originY) { super.tabCreated(id, sourceId, launchType, isIncognito, willBeSelected, originX, originY); if (willBeSelected) { Tab newTab = TabModelUtils.getTabById(getTabModelSelector().getModel(isIncognito), id); if (newTab != null) newTab.requestFocus(); } }
Example #19
Source File: TabModelImpl.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public void moveTab(int id, int newIndex) { newIndex = MathUtils.clamp(newIndex, 0, mTabs.size()); int curIndex = TabModelUtils.getTabIndexById(this, id); if (curIndex == INVALID_TAB_INDEX || curIndex == newIndex || curIndex + 1 == newIndex) { return; } // TODO(dtrainor): Update the list of undoable tabs instead of committing it. commitAllTabClosures(); Tab tab = mTabs.remove(curIndex); if (curIndex < newIndex) --newIndex; mTabs.add(newIndex, tab); if (curIndex == mIndex) { mIndex = newIndex; } else if (curIndex < mIndex && newIndex >= mIndex) { --mIndex; } else if (curIndex > mIndex && newIndex <= mIndex) { ++mIndex; } mRewoundList.resetRewoundState(); for (TabModelObserver obs : mObservers) obs.didMoveTab(tab, newIndex, curIndex); }
Example #20
Source File: TabModelUtils.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * @param model The {@link TabModel} to act on. * @param index The index of the {@link Tab} to close. * @return {@code true} if the {@link Tab} was found. */ public static boolean closeTabByIndex(TabModel model, int index) { Tab tab = model.getTabAt(index); if (tab == null) return false; return model.closeTab(tab); }
Example #21
Source File: CompositorViewHolder.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public void onContentChanged() { if (mTabModelSelector == null) { // Not yet initialized, onContentChanged() will eventually get called by // setTabModelSelector. return; } Tab tab = mTabModelSelector.getCurrentTab(); setTab(tab); }
Example #22
Source File: SimpleAnimationLayout.java From delion with Apache License 2.0 | 5 votes |
@Override public void show(long time, boolean animate) { super.show(time, animate); if (mTabModelSelector != null && mTabContentManager != null) { Tab tab = mTabModelSelector.getCurrentTab(); if (tab != null && tab.isNativePage()) mTabContentManager.cacheTabThumbnail(tab); } reset(); }
Example #23
Source File: ReaderModeManager.java From 365browser with Apache License 2.0 | 5 votes |
public ReaderModeManager(TabModelSelector selector, ChromeActivity activity) { super(selector); mTabId = Tab.INVALID_TAB_ID; mTabModelSelector = selector; mChromeActivity = activity; mTabStatusMap = new HashMap<>(); mIsReaderHeuristicAlwaysTrue = isDistillerHeuristicAlwaysTrue(); }
Example #24
Source File: LayerTitleCache.java From AndroidChromium with Apache License 2.0 | 5 votes |
private void updateFaviconFromHistory(Tab tab, Bitmap faviconBitmap) { if (!tab.isInitialized()) return; int tabId = tab.getId(); Title title = mTitles.get(tabId); if (title == null) return; if (!title.updateFaviconFromHistory(faviconBitmap)) return; if (mNativeLayerTitleCache != 0) { nativeUpdateFavicon(mNativeLayerTitleCache, tabId, title.getFaviconResId()); } }
Example #25
Source File: ActivityDelegate.java From delion with Apache License 2.0 | 5 votes |
/** * @return Running Activity that owns the given Tab, null if the Activity couldn't be found. */ public static Activity getActivityForTabId(int id) { if (id == Tab.INVALID_TAB_ID) return null; for (WeakReference<Activity> ref : ApplicationStatus.getRunningActivities()) { if (!(ref.get() instanceof ChromeActivity)) continue; ChromeActivity activity = (ChromeActivity) ref.get(); if (activity == null) continue; if (activity.getTabModelSelector().getTabById(id) != null) return activity; } return null; }
Example #26
Source File: CustomTabActivity.java From delion with Apache License 2.0 | 5 votes |
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 #27
Source File: OfflinePageTabObserver.java From 365browser with Apache License 2.0 | 5 votes |
/** * Create and attach a tab observer if we don't already have one, otherwise update it. * @param tab The tab we are adding an observer for. */ public static void addObserverForTab(Tab tab) { OfflinePageTabObserver observer = getObserverForActivity(tab.getActivity()); assert observer != null; observer.startObservingTab(tab); observer.maybeShowReloadSnackbar(tab, false); }
Example #28
Source File: ChromeFullscreenManager.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void setPositionsForTabToNonFullscreen() { Tab tab = getTab(); if (tab == null || tab.isShowingBrowserControlsEnabled()) { setPositionsForTab(0, 0, getTopControlsHeight()); } else { setPositionsForTab(-getTopControlsHeight(), getBottomControlsHeight(), 0); } }
Example #29
Source File: NewTabPageUma.java From 365browser with Apache License 2.0 | 4 votes |
@Override public void onDestroyed(Tab tab) { endRecording(null); }
Example #30
Source File: CastSessionImpl.java From delion with Apache License 2.0 | 4 votes |
/** * Initializes a new {@link CastSessionImpl} instance. * @param apiClient The Google Play Services client used to create the session. * @param sessionId The session identifier to use with the Cast SDK. * @param origin The origin of the frame requesting the route. * @param tabId The id of the tab containing the frame requesting the route. * @param isIncognito Whether the route is beging requested from an Incognito profile. * @param source The {@link MediaSource} corresponding to this session. * @param routeProvider The {@link CastMediaRouteProvider} instance managing this session. */ public CastSessionImpl( GoogleApiClient apiClient, String sessionId, ApplicationMetadata metadata, String applicationStatus, CastDevice castDevice, String origin, int tabId, boolean isIncognito, MediaSource source, CastMediaRouteProvider routeProvider) { mSessionId = sessionId; mRouteProvider = routeProvider; mApiClient = apiClient; mSource = source; mApplicationMetadata = metadata; mApplicationStatus = applicationStatus; mCastDevice = castDevice; mMessageHandler = mRouteProvider.getMessageHandler(); mMessageChannel = new CastMessagingChannel(this); updateNamespaces(); final Context context = ContextUtils.getApplicationContext(); if (mNamespaces.contains(CastMessageHandler.MEDIA_NAMESPACE)) { mMediaPlayer = new RemoteMediaPlayer(); mMediaPlayer.setOnStatusUpdatedListener( new RemoteMediaPlayer.OnStatusUpdatedListener() { @Override public void onStatusUpdated() { MediaStatus mediaStatus = mMediaPlayer.getMediaStatus(); if (mediaStatus == null) return; int playerState = mediaStatus.getPlayerState(); if (playerState == MediaStatus.PLAYER_STATE_PAUSED || playerState == MediaStatus.PLAYER_STATE_PLAYING) { mNotificationBuilder.setPaused( playerState != MediaStatus.PLAYER_STATE_PLAYING); mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP | MediaNotificationInfo.ACTION_PLAY_PAUSE); } else { mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP); } MediaNotificationManager.show(context, mNotificationBuilder.build()); } }); mMediaPlayer.setOnMetadataUpdatedListener( new RemoteMediaPlayer.OnMetadataUpdatedListener() { @Override public void onMetadataUpdated() { setNotificationMetadata(mNotificationBuilder); MediaNotificationManager.show(context, mNotificationBuilder.build()); } }); } Intent contentIntent = Tab.createBringTabToFrontIntent(tabId); if (contentIntent != null) { contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME, MediaNotificationUma.SOURCE_PRESENTATION); } mNotificationBuilder = new MediaNotificationInfo.Builder() .setPaused(false) .setOrigin(origin) // TODO(avayvod): the same session might have more than one tab id. Should we track // the last foreground alive tab and update the notification with it? .setTabId(tabId) .setPrivate(isIncognito) .setActions(MediaNotificationInfo.ACTION_STOP) .setContentIntent(contentIntent) .setIcon(R.drawable.ic_notification_media_route) .setDefaultLargeIcon(R.drawable.cast_playing_square) .setId(R.id.presentation_notification) .setListener(this); setNotificationMetadata(mNotificationBuilder); MediaNotificationManager.show(context, mNotificationBuilder.build()); }