Java Code Examples for org.chromium.chrome.browser.tab.Tab#isIncognito()
The following examples show how to use
org.chromium.chrome.browser.tab.Tab#isIncognito() .
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: DownloadUtils.java From 365browser with Apache License 2.0 | 6 votes |
/** * Whether the user should be allowed to download the current page. * @param tab Tab displaying the page that will be downloaded. * @return Whether the "Download Page" button should be enabled. */ public static boolean isAllowedToDownloadPage(Tab tab) { if (tab == null) return false; // Offline pages isn't supported in Incognito. This should be checked before calling // OfflinePageBridge.getForProfile because OfflinePageBridge instance will not be found // for incognito profile. if (tab.isIncognito()) return false; // Check if the page url is supported for saving. Only HTTP and HTTPS pages are allowed. if (!OfflinePageBridge.canSavePage(tab.getUrl())) return false; // Download will only be allowed for the error page if download button is shown in the page. if (tab.isShowingErrorPage()) { final OfflinePageBridge bridge = OfflinePageBridge.getForProfile(tab.getProfile()); return bridge.isShowingDownloadButtonInErrorPage(tab.getWebContents()); } if (tab.isShowingInterstitialPage()) return false; // Don't allow re-downloading the currently displayed offline page. if (OfflinePageUtils.isOfflinePage(tab)) return false; return true; }
Example 2
Source File: NativePageFactory.java From 365browser with Apache License 2.0 | 6 votes |
protected NativePage buildNewTabPage(ChromeActivity activity, Tab tab, TabModelSelector tabModelSelector) { if (FeatureUtilities.isChromeHomeEnabled()) { if (tab.isIncognito()) { return new ChromeHomeIncognitoNewTabPage(activity, tab, tabModelSelector, ((ChromeTabbedActivity) activity).getLayoutManager()); } else { return new ChromeHomeNewTabPage(activity, tab, tabModelSelector, ((ChromeTabbedActivity) activity).getLayoutManager()); } } else if (tab.isIncognito()) { return new IncognitoNewTabPage(activity); } else { return new NewTabPage(activity, new TabShim(tab), tabModelSelector); } }
Example 3
Source File: LocationBarLayout.java From 365browser with Apache License 2.0 | 6 votes |
/** * Checks the current specs and updates {@link LocationBar#mUseDarkColors} if necessary. * @return Whether {@link LocationBar#mUseDarkColors} has been updated. */ private boolean updateUseDarkColors() { Tab tab = getCurrentTab(); boolean brandColorNeedsLightText = false; if (getToolbarDataProvider().isUsingBrandColor() && !mUrlHasFocus) { int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor(); brandColorNeedsLightText = ColorUtils.shouldUseLightForegroundOnBackground(currentPrimaryColor); } boolean useDarkColors = (mToolbarDataProvider == null || !mToolbarDataProvider.isIncognito()) && (tab == null || !(tab.isIncognito() || brandColorNeedsLightText)); boolean hasChanged = useDarkColors != mUseDarkColors; mUseDarkColors = useDarkColors; return hasChanged; }
Example 4
Source File: DownloadUtils.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Whether the user should be allowed to download the current page. * @param tab Tab displaying the page that will be downloaded. * @return Whether the "Download Page" button should be enabled. */ public static boolean isAllowedToDownloadPage(Tab tab) { if (tab == null) return false; // Only allow HTTP and HTTPS pages, as that is these are the only scenarios supported by the // background/offline page saving. if (!tab.getUrl().startsWith(UrlConstants.HTTP_SCHEME) && !tab.getUrl().startsWith(UrlConstants.HTTPS_SCHEME)) { return false; } if (tab.isShowingErrorPage()) return false; if (tab.isShowingInterstitialPage()) return false; // Don't allow re-downloading the currently displayed offline page. if (tab.isOfflinePage()) return false; // Offline pages isn't supported in Incognito. if (tab.isIncognito()) return false; return true; }
Example 5
Source File: LayoutManagerChrome.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override public void didAddTab(Tab tab, TabLaunchType launchType) { int tabId = tab.getId(); if (launchType == TabLaunchType.FROM_RESTORE) { getActiveLayout().onTabRestored(time(), tabId); } else { boolean incognito = tab.isIncognito(); boolean willBeSelected = launchType != TabLaunchType.FROM_LONGPRESS_BACKGROUND || (!getTabModelSelector().isIncognitoSelected() && incognito); float lastTapX = LocalizationUtils.isLayoutRtl() ? mLastContentWidthDp : 0.f; float lastTapY = 0.f; if (launchType != TabLaunchType.FROM_CHROME_UI) { float heightDelta = mLastFullscreenViewportDp.height() - mLastVisibleViewportDp.height(); lastTapX = mPxToDp * mLastTapX; lastTapY = mPxToDp * mLastTapY - heightDelta; } tabCreated(tabId, getTabModelSelector().getCurrentTabId(), launchType, incognito, willBeSelected, lastTapX, lastTapY); } }
Example 6
Source File: LocationBarPhone.java From delion with Apache License 2.0 | 6 votes |
@Override public void updateVisualsForState() { super.updateVisualsForState(); Tab tab = getCurrentTab(); boolean isIncognito = tab != null && tab.isIncognito(); mIncognitoBadge.setVisibility(isIncognito ? VISIBLE : GONE); updateIncognitoBadgePadding(); if (showMenuButtonInOmnibox()) { boolean useLightDrawables = shouldUseLightDrawables(); ColorStateList dark = ApiCompatibilityUtils.getColorStateList(getResources(), R.color.dark_mode_tint); ColorStateList white = ApiCompatibilityUtils.getColorStateList(getResources(), R.color.light_mode_tint); mMenuButton.setTint(useLightDrawables ? white : dark); if (mShowMenuBadge) { mMenuBadge.setImageResource(useLightDrawables ? R.drawable.badge_update_light : R.drawable.badge_update_dark); } } }
Example 7
Source File: TabWindowManager.java From 365browser with Apache License 2.0 | 6 votes |
/** * @return The total number of incognito tabs across all tab model selectors. */ public int getIncognitoTabCount() { int count = 0; for (int i = 0; i < mSelectors.size(); i++) { if (mSelectors.get(i) != null) { count += mSelectors.get(i).getModel(true).getCount(); } } // Count tabs that are moving between activities (e.g. a tab that was recently reparented // and hasn't been attached to its new activity yet). SparseArray<AsyncTabParams> asyncTabParams = AsyncTabParamsManager.getAsyncTabParams(); for (int i = 0; i < asyncTabParams.size(); i++) { Tab tab = asyncTabParams.valueAt(i).getTabToReparent(); if (tab != null && tab.isIncognito()) count++; } return count; }
Example 8
Source File: TabWindowManager.java From delion with Apache License 2.0 | 6 votes |
/** * @return The total number of incognito tabs across all tab model selectors. */ public int getIncognitoTabCount() { int count = 0; for (int i = 0; i < mSelectors.size(); i++) { if (mSelectors.get(i) != null) { count += mSelectors.get(i).getModel(true).getCount(); } } // Count tabs that are moving between activities (e.g. a tab that was recently reparented // and hasn't been attached to its new activity yet). SparseArray<AsyncTabParams> asyncTabParams = AsyncTabParamsManager.getAsyncTabParams(); for (int i = 0; i < asyncTabParams.size(); i++) { Tab tab = asyncTabParams.valueAt(i).getTabToReparent(); if (tab != null && tab.isIncognito()) count++; } return count; }
Example 9
Source File: LocationBarPhone.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public void updateVisualsForState() { super.updateVisualsForState(); Tab tab = getCurrentTab(); boolean isIncognito = tab != null && tab.isIncognito(); mIncognitoBadge.setVisibility(isIncognito ? VISIBLE : GONE); updateIncognitoBadgePadding(); }
Example 10
Source File: NativePageFactory.java From delion with Apache License 2.0 | 5 votes |
protected NativePage buildNewTabPage(Activity activity, Tab tab, TabModelSelector tabModelSelector) { if (tab.isIncognito()) { return new IncognitoNewTabPage(activity); } else { return new NewTabPage(activity, tab, tabModelSelector); } }
Example 11
Source File: LayerTitleCache.java From 365browser with Apache License 2.0 | 5 votes |
private String getUpdatedTitleInternal(Tab tab, String titleString, boolean fetchFaviconFromHistory) { final int tabId = tab.getId(); Bitmap originalFavicon = tab.getFavicon(); boolean isDarkTheme = tab.isIncognito(); // The theme might require lighter text. if (!DeviceFormFactor.isTablet()) { isDarkTheme |= ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor()); } ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor()); boolean isRtl = tab.isTitleDirectionRtl(); TitleBitmapFactory titleBitmapFactory = isDarkTheme ? mDarkTitleBitmapFactory : mStandardTitleBitmapFactory; Title title = mTitles.get(tabId); if (title == null) { title = new Title(); mTitles.put(tabId, title); title.register(); } title.set(titleBitmapFactory.getTitleBitmap(mContext, titleString), titleBitmapFactory.getFaviconBitmap(mContext, originalFavicon), fetchFaviconFromHistory); if (mNativeLayerTitleCache != 0) { nativeUpdateLayer(mNativeLayerTitleCache, tabId, title.getTitleResId(), title.getFaviconResId(), isDarkTheme, isRtl); } return titleString; }
Example 12
Source File: LayerTitleCache.java From AndroidChromium with Apache License 2.0 | 5 votes |
private String getUpdatedTitleInternal(Tab tab, String titleString, boolean fetchFaviconFromHistory) { final int tabId = tab.getId(); Bitmap originalFavicon = tab.getFavicon(); boolean isDarkTheme = tab.isIncognito(); // The theme might require lighter text. if (!DeviceFormFactor.isTablet(mContext)) { isDarkTheme |= ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor()); } ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor()); boolean isRtl = tab.isTitleDirectionRtl(); TitleBitmapFactory titleBitmapFactory = isDarkTheme ? mDarkTitleBitmapFactory : mStandardTitleBitmapFactory; Title title = mTitles.get(tabId); if (title == null) { title = new Title(); mTitles.put(tabId, title); title.register(); } title.set(titleBitmapFactory.getTitleBitmap(mContext, titleString), titleBitmapFactory.getFaviconBitmap(mContext, originalFavicon), fetchFaviconFromHistory); if (mNativeLayerTitleCache != 0) { nativeUpdateLayer(mNativeLayerTitleCache, tabId, title.getTitleResId(), title.getFaviconResId(), isDarkTheme, isRtl); } return titleString; }
Example 13
Source File: LocationBarTablet.java From 365browser with Apache License 2.0 | 5 votes |
private boolean shouldShowSaveOfflineButton() { if (!mNativeInitialized || mToolbarDataProvider == null) return false; Tab tab = mToolbarDataProvider.getTab(); if (tab == null) return false; // The save offline button should not be shown on native pages. Currently, trying to // save an offline page in incognito crashes, so don't show it on incognito either. return shouldShowPageActionButtons() && !tab.isIncognito(); }
Example 14
Source File: GeolocationHeader.java From 365browser with Apache License 2.0 | 4 votes |
/** * Returns an X-Geo HTTP header string if: * 1. The current mode is not incognito. * 2. The url is a google search URL (e.g. www.google.co.uk/search?q=cars), and * 3. The user has not disabled sharing location with this url, and * 4. There is a valid and recent location available. * * Returns null otherwise. * * @param url The URL of the request with which this header will be sent. * @param tab The Tab currently being accessed. * @return The X-Geo header string or null. */ public static String getGeoHeader(String url, Tab tab) { // TODO(lbargu): Refactor and simplify flow. boolean isIncognito = tab.isIncognito(); Location locationToAttach = null; VisibleNetworks visibleNetworksToAttach = null; long locationAge = Long.MAX_VALUE; @HeaderState int headerState = geoHeaderStateForUrl(url, isIncognito, true); // XGEO_VISIBLE_NETWORKS // When this feature is enabled, we will send visible WiFi and Cell Access Points as part of // the X-GEO HTTP Header so that we can better position the client server side in the case // where there is no lat/long or it's too old. boolean isXGeoVisibleNetworksEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.XGEO_VISIBLE_NETWORKS); if (headerState == HEADER_ENABLED) { // Only send X-Geo header if there's a fresh location available. // Use flag controlling visible network changes to decide whether GPS location should be // included as a fallback. // TODO(lbargu): Measure timing here and to get visible networks. locationToAttach = GeolocationTracker.getLastKnownLocation( ContextUtils.getApplicationContext(), isXGeoVisibleNetworksEnabled); if (locationToAttach == null) { recordHistogram(UMA_LOCATION_NOT_AVAILABLE); } else { locationAge = GeolocationTracker.getLocationAge(locationToAttach); if (locationAge > MAX_LOCATION_AGE) { // Do not attach the location recordHistogram(UMA_LOCATION_STALE); locationToAttach = null; } else { recordHistogram(UMA_HEADER_SENT); } } // The header state is enabled, so this means we have app permissions, and the url is // allowed to receive location. Before attempting to attach visible networks, check if // network-based location is enabled. if (isXGeoVisibleNetworksEnabled && isNetworkLocationEnabled() && !isLocationFresh(locationToAttach)) { visibleNetworksToAttach = VisibleNetworksTracker.getLastKnownVisibleNetworks( ContextUtils.getApplicationContext()); } } @LocationSource int locationSource = getLocationSource(); @Permission int appPermission = getGeolocationPermission(tab); @Permission int domainPermission = getDomainPermission(url, isIncognito); // Record the permission state with a histogram. recordPermissionHistogram(locationSource, appPermission, domainPermission, locationToAttach != null, headerState); if (locationSource != LOCATION_SOURCE_MASTER_OFF && appPermission != PERMISSION_BLOCKED && domainPermission != PERMISSION_BLOCKED && !isIncognito) { // Record the Location Age with a histogram. recordLocationAgeHistogram(locationSource, locationAge); long duration = sFirstLocationTime == Long.MAX_VALUE ? 0 : SystemClock.elapsedRealtime() - sFirstLocationTime; // Record the Time Listening with a histogram. recordTimeListeningHistogram(locationSource, locationToAttach != null, duration); } if (!isXGeoVisibleNetworksEnabled) { String locationAsciiEncoding = encodeAsciiLocation(locationToAttach); if (locationAsciiEncoding == null) return null; return XGEO_HEADER_PREFIX + LOCATION_SEPARATOR + LOCATION_ASCII_PREFIX + LOCATION_SEPARATOR + locationAsciiEncoding; } // Proto encoding String locationProtoEncoding = encodeProtoLocation(locationToAttach); String visibleNetworksProtoEncoding = encodeProtoVisibleNetworks(visibleNetworksToAttach); if (locationProtoEncoding == null && visibleNetworksProtoEncoding == null) return null; StringBuilder header = new StringBuilder(XGEO_HEADER_PREFIX); if (locationProtoEncoding != null) { header.append(LOCATION_SEPARATOR).append(LOCATION_PROTO_PREFIX) .append(LOCATION_SEPARATOR).append(locationProtoEncoding); } if (visibleNetworksProtoEncoding != null) { header.append(LOCATION_SEPARATOR).append(LOCATION_PROTO_PREFIX) .append(LOCATION_SEPARATOR).append(visibleNetworksProtoEncoding); } return header.toString(); }
Example 15
Source File: AppIndexingUtil.java From 365browser with Apache License 2.0 | 4 votes |
/** * Extracts entities from document metadata and reports it to on-device App Indexing. * This call can cache entities from recently parsed webpages, in which case, only the url and * title of the page is reported to App Indexing. */ public void extractCopylessPasteMetadata(final Tab tab) { final String url = tab.getUrl(); boolean isHttpOrHttps = URLUtil.isHttpsUrl(url) || URLUtil.isHttpUrl(url); if (!isEnabledForDevice() || tab.isIncognito() || !isHttpOrHttps) { return; } // There are three conditions that can occur with respect to the cache. // 1. Cache hit, and an entity was found previously. Report only the page view to App // Indexing. // 2. Cache hit, but no entity was found. Ignore. // 3. Cache miss, we need to parse the page. if (wasPageVisitedRecently(url)) { if (lastPageVisitContainedEntity(url)) { // Condition 1 RecordHistogram.recordEnumeratedHistogram( "CopylessPaste.CacheHit", CACHE_HIT_WITH_ENTITY, CACHE_HISTOGRAM_BOUNDARY); getAppIndexingReporter().reportWebPageView(url, tab.getTitle()); return; } // Condition 2 RecordHistogram.recordEnumeratedHistogram( "CopylessPaste.CacheHit", CACHE_HIT_WITHOUT_ENTITY, CACHE_HISTOGRAM_BOUNDARY); } else { // Condition 3 RecordHistogram.recordEnumeratedHistogram( "CopylessPaste.CacheHit", CACHE_MISS, CACHE_HISTOGRAM_BOUNDARY); CopylessPaste copylessPaste = getCopylessPasteInterface(tab); if (copylessPaste == null) { return; } copylessPaste.getEntities(new CopylessPaste.GetEntitiesResponse() { @Override public void call(WebPage webpage) { putCacheEntry(url, webpage != null); if (sCallbackForTesting != null) { sCallbackForTesting.onResult(webpage); } if (webpage == null) return; getAppIndexingReporter().reportWebPage(webpage); } }); } }
Example 16
Source File: TabModelOrderController.java From delion with Apache License 2.0 | 4 votes |
/** * @return {@code true} If both tabs have the same model type, {@code false} otherwise. */ static boolean sameModelType(TabModel model, Tab tab) { return model.isIncognito() == tab.isIncognito(); }
Example 17
Source File: TabPersistentStore.java From AndroidChromium with Apache License 2.0 | 4 votes |
SaveTabTask(Tab tab) { mTab = tab; mId = tab.getId(); mEncrypted = tab.isIncognito(); }
Example 18
Source File: TabModelOrderController.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * @return {@code true} If both tabs have the same model type, {@code false} otherwise. */ static boolean sameModelType(TabModel model, Tab tab) { return model.isIncognito() == tab.isIncognito(); }
Example 19
Source File: ContextReporter.java From 365browser with Apache License 2.0 | 4 votes |
private void reportUsageOfCurrentContextIfPossible( Tab tab, boolean isTitleChange, @Nullable GSAContextDisplaySelection displaySelection) { Tab currentTab = mActivity.getActivityTab(); if (currentTab == null || currentTab.isIncognito()) { if (currentTab == null) { reportStatus(STATUS_NO_TAB); Log.d(TAG, "Not reporting, tab is null"); } else { reportStatus(STATUS_INCOGNITO); Log.d(TAG, "Not reporting, tab is incognito"); } reportUsageEndedIfNecessary(); return; } String currentUrl = currentTab.getUrl(); if (TextUtils.isEmpty(currentUrl) || !(currentUrl.startsWith(UrlConstants.HTTP_URL_PREFIX) || currentUrl.startsWith(UrlConstants.HTTPS_URL_PREFIX))) { reportStatus(STATUS_INVALID_SCHEME); Log.d(TAG, "Not reporting, URL scheme is invalid"); reportUsageEndedIfNecessary(); return; } // Check whether this is a context change we would like to report. if (currentTab.getId() != tab.getId()) { reportStatus(STATUS_TAB_ID_MISMATCH); Log.d(TAG, "Not reporting, tab ID doesn't match"); return; } if (isTitleChange && mLastContextWasTitleChange) { reportStatus(STATUS_DUP_TITLE_CHANGE); Log.d(TAG, "Not reporting, repeated title update"); return; } reportUsageEndedIfNecessary(); mDelegate.reportContext(currentTab.getUrl(), currentTab.getTitle(), displaySelection); mLastContextWasTitleChange = isTitleChange; mContextInUse.set(true); }
Example 20
Source File: TabModelOrderController.java From 365browser with Apache License 2.0 | 4 votes |
/** * @return {@code true} If both tabs have the same model type, {@code false} otherwise. */ static boolean sameModelType(TabModel model, Tab tab) { return model.isIncognito() == tab.isIncognito(); }