org.chromium.chrome.browser.preferences.PrefServiceBridge Java Examples

The following examples show how to use org.chromium.chrome.browser.preferences.PrefServiceBridge. 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: SingleCategoryPreferences.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Reset the preference screen an initialize it again.
 */
private void resetList() {
    // This will remove the combo box at the top and all the sites listed below it.
    getPreferenceScreen().removeAll();
    // And this will add the filter preference back (combo box).
    addPreferencesFromResource(R.xml.website_preferences);

    configureGlobalToggles();

    if ((mCategory.showAutoplaySites()
                && !PrefServiceBridge.getInstance().isAutoplayEnabled())
            || (mCategory.showJavaScriptSites()
                && !PrefServiceBridge.getInstance().javaScriptEnabled())
            || (mCategory.showBackgroundSyncSites()
                       && !PrefServiceBridge.getInstance().isBackgroundSyncAllowed())) {
        getPreferenceScreen().addPreference(
                new AddExceptionPreference(getActivity(), ADD_EXCEPTION_KEY,
                        getAddExceptionDialogMessage(), this));
    }
}
 
Example #2
Source File: UpdateMenuItemHelper.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Handles a click on the update menu item.
 * @param activity The current {@link ChromeActivity}.
 */
public void onMenuItemClicked(ChromeActivity activity) {
    if (mUpdateUrl == null) return;

    // If the update menu item is showing because it was forced on through about://flags
    // then mLatestVersion may be null.
    if (mLatestVersion != null) {
        PrefServiceBridge.getInstance().setLatestVersionWhenClickedUpdateMenuItem(
                mLatestVersion);
    }

    // Fire an intent to open the URL.
    try {
        Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mUpdateUrl));
        activity.startActivity(launchIntent);
        recordItemClickedHistogram(ITEM_CLICKED_INTENT_LAUNCHED);
        PrefServiceBridge.getInstance().setClickedUpdateMenuItem(true);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Failed to launch Activity for: %s", mUpdateUrl);
        recordItemClickedHistogram(ITEM_CLICKED_INTENT_FAILED);
    }
}
 
Example #3
Source File: TranslatePreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_id_targeted_help) {
        HelpAndFeedback.getInstance(getActivity())
                .show(getActivity(), getString(R.string.help_context_translate),
                        Profile.getLastUsedProfile(), null);
        return true;
    } else if (itemId == R.id.menu_id_reset) {
        PrefServiceBridge.getInstance().resetTranslateDefaults();
        Toast.makeText(getActivity(), getString(
                R.string.translate_prefs_toast_description),
                Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
 
Example #4
Source File: AccountSigninView.java    From delion with Apache License 2.0 6 votes vote down vote up
private void showConfirmSigninPagePreviousAccountCheck() {
    String accountName = getSelectedAccountName();
    ConfirmSyncDataStateMachine.run(PrefServiceBridge.getInstance().getSyncLastAccountName(),
            accountName, ImportSyncType.PREVIOUS_DATA_FOUND, mDelegate.getFragmentManager(),
            getContext(), new ConfirmImportSyncDataDialog.Listener() {
                @Override
                public void onConfirm(boolean wipeData) {
                    SigninManager.wipeSyncUserDataIfRequired(wipeData)
                            .then(new Callback<Void>() {
                                @Override
                                public void onResult(Void v) {
                                    showConfirmSigninPage();
                                }
                            });
                }

                @Override
                public void onCancel() {
                    setButtonsEnabled(true);
                }
            });
}
 
Example #5
Source File: ClearBrowsingDataPreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Requests the browsing data corresponding to the given dialog options to be deleted.
 * @param options The dialog options whose corresponding data should be deleted.
 */
private final void clearBrowsingData(EnumSet<DialogOption> options,
        @Nullable String[] blacklistedDomains, @Nullable int[] blacklistedDomainReasons,
        @Nullable String[] ignoredDomains, @Nullable int[] ignoredDomainReasons) {
    showProgressDialog();

    int[] dataTypes = new int[options.size()];
    int i = 0;
    for (DialogOption option : options) {
        dataTypes[i] = option.getDataType();
        ++i;
    }

    Object spinnerSelection =
            ((SpinnerPreference) findPreference(PREF_TIME_RANGE)).getSelectedOption();
    int timePeriod = ((TimePeriodSpinnerOption) spinnerSelection).getTimePeriod();
    if (blacklistedDomains != null && blacklistedDomains.length != 0) {
        PrefServiceBridge.getInstance().clearBrowsingDataExcludingDomains(this, dataTypes,
                timePeriod, blacklistedDomains, blacklistedDomainReasons, ignoredDomains,
                ignoredDomainReasons);
    } else {
        PrefServiceBridge.getInstance().clearBrowsingData(this, dataTypes, timePeriod);
    }
}
 
Example #6
Source File: UpdateMenuItemHelper.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Handles a click on the update menu item.
 * @param activity The current {@link ChromeActivity}.
 */
public void onMenuItemClicked(ChromeActivity activity) {
    if (mUpdateUrl == null) return;

    // If the update menu item is showing because it was forced on through about://flags
    // then mLatestVersion may be null.
    if (mLatestVersion != null) {
        PrefServiceBridge.getInstance().setLatestVersionWhenClickedUpdateMenuItem(
                mLatestVersion);
    }

    // Fire an intent to open the URL.
    try {
        Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mUpdateUrl));
        activity.startActivity(launchIntent);
        recordItemClickedHistogram(ITEM_CLICKED_INTENT_LAUNCHED);
        PrefServiceBridge.getInstance().setClickedUpdateMenuItem(true);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Failed to launch Activity for: %s", mUpdateUrl);
        recordItemClickedHistogram(ITEM_CLICKED_INTENT_FAILED);
    }
}
 
Example #7
Source File: LanguagePreferences.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_id_targeted_help) {
        HelpAndFeedback.getInstance(getActivity())
                .show(getActivity(), getString(R.string.help_context_translate),
                        Profile.getLastUsedProfile(), null);
        return true;
    } else if (itemId == R.id.menu_id_reset) {
        PrefServiceBridge.getInstance().resetTranslateDefaults();
        Toast.makeText(getActivity(), getString(
                R.string.translate_prefs_toast_description),
                Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
 
Example #8
Source File: SingleCategoryPreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Reset the preference screen an initialize it again.
 */
private void resetList() {
    // This will remove the combo box at the top and all the sites listed below it.
    getPreferenceScreen().removeAll();
    // And this will add the filter preference back (combo box).
    addPreferencesFromResource(R.xml.website_preferences);

    configureGlobalToggles();

    if ((mCategory.showAutoplaySites()
                && !PrefServiceBridge.getInstance().isAutoplayEnabled())
            || (mCategory.showJavaScriptSites()
                && !PrefServiceBridge.getInstance().javaScriptEnabled())
            || (mCategory.showBackgroundSyncSites()
                       && !PrefServiceBridge.getInstance().isBackgroundSyncAllowed())) {
        getPreferenceScreen().addPreference(
                new AddExceptionPreference(getActivity(), ADD_EXCEPTION_KEY,
                        getAddExceptionDialogMessage(), this));
    }
}
 
Example #9
Source File: ContextualSearchTabHelper.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * @return whether Contextual Search is enabled and active in this tab.
 */
private boolean isContextualSearchActive(ContentViewCore cvc) {
    ContextualSearchManager manager = getContextualSearchManager();
    if (manager == null) return false;

    return !cvc.getWebContents().isIncognito()
            && FirstRunStatus.getFirstRunFlowComplete()
            && !PrefServiceBridge.getInstance().isContextualSearchDisabled()
            && TemplateUrlService.getInstance().isDefaultSearchEngineGoogle()
            // Svelte and Accessibility devices are incompatible with the first-run flow and
            // Talkback has poor interaction with tap to search (see http://crbug.com/399708 and
            // http://crbug.com/396934).
            && !manager.isRunningInCompatibilityMode()
            && !(mTab.isShowingErrorPage() || mTab.isShowingInterstitialPage())
            && isDeviceOnline(manager);
}
 
Example #10
Source File: AccountSigninView.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void showConfirmSigninPagePreviousAccountCheck(long seedingStartTime) {
    RecordHistogram.recordTimesHistogram("Signin.AndroidAccountSigninViewSeedingTime",
            SystemClock.elapsedRealtime() - seedingStartTime, TimeUnit.MILLISECONDS);
    String accountName = getSelectedAccountName();
    ConfirmSyncDataStateMachine.run(PrefServiceBridge.getInstance().getSyncLastAccountName(),
            accountName, ImportSyncType.PREVIOUS_DATA_FOUND,
            mDelegate.getFragmentManager(),
            getContext(), new ConfirmImportSyncDataDialog.Listener() {
                @Override
                public void onConfirm(boolean wipeData) {
                    SigninManager.wipeSyncUserDataIfRequired(wipeData)
                            .then(new Callback<Void>() {
                                @Override
                                public void onResult(Void v) {
                                    showConfirmSigninPage();
                                }
                            });
                }

                @Override
                public void onCancel() {
                    setButtonsEnabled(true);
                }
            });
}
 
Example #11
Source File: PrivacyPreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private ManagedPreferenceDelegate createManagedPreferenceDelegate() {
    return new ManagedPreferenceDelegate() {
        @Override
        public boolean isPreferenceControlledByPolicy(Preference preference) {
            String key = preference.getKey();
            PrefServiceBridge prefs = PrefServiceBridge.getInstance();
            if (PREF_NAVIGATION_ERROR.equals(key)) {
                return prefs.isResolveNavigationErrorManaged();
            }
            if (PREF_SEARCH_SUGGESTIONS.equals(key)) {
                return prefs.isSearchSuggestManaged();
            }
            if (PREF_SAFE_BROWSING_EXTENDED_REPORTING.equals(key)
                    || PREF_SAFE_BROWSING_SCOUT_REPORTING.equals(key)) {
                return prefs.isSafeBrowsingExtendedReportingManaged();
            }
            if (PREF_SAFE_BROWSING.equals(key)) {
                return prefs.isSafeBrowsingManaged();
            }
            if (PREF_NETWORK_PREDICTIONS.equals(key)) {
                return prefs.isNetworkPredictionManaged();
            }
            return false;
        }
    };
}
 
Example #12
Source File: PrivacyPreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    String key = preference.getKey();
    if (PREF_SEARCH_SUGGESTIONS.equals(key)) {
        PrefServiceBridge.getInstance().setSearchSuggestEnabled((boolean) newValue);
    } else if (PREF_SAFE_BROWSING.equals(key)) {
        PrefServiceBridge.getInstance().setSafeBrowsingEnabled((boolean) newValue);
    } else if (PREF_SAFE_BROWSING_EXTENDED_REPORTING.equals(key)
               || PREF_SAFE_BROWSING_SCOUT_REPORTING.equals(key)) {
        PrefServiceBridge.getInstance().setSafeBrowsingExtendedReportingEnabled(
                (boolean) newValue);
    } else if (PREF_NETWORK_PREDICTIONS.equals(key)) {
        PrefServiceBridge.getInstance().setNetworkPredictionEnabled((boolean) newValue);
        PrecacheLauncher.updatePrecachingEnabled(getActivity());
    } else if (PREF_NAVIGATION_ERROR.equals(key)) {
        PrefServiceBridge.getInstance().setResolveNavigationErrorEnabled((boolean) newValue);
    }

    return true;
}
 
Example #13
Source File: ChromeActivitySessionTracker.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Update the accept languages after changing Android locale setting. Doing so kills the
 * Activities but it doesn't kill the Application, so this should be called in
 * {@link #onStart} instead of {@link #initialize}.
 */
private void updateAcceptLanguages() {
    PrefServiceBridge instance = PrefServiceBridge.getInstance();
    String localeString = LocaleUtils.getDefaultLocaleListString();
    if (hasLocaleChanged(localeString)) {
        instance.resetAcceptLanguages(localeString);
        // Clear cache so that accept-languages change can be applied immediately.
        // TODO(changwan): The underlying BrowsingDataRemover::Remove() is an asynchronous call.
        // So cache-clearing may not be effective if URL rendering can happen before
        // OnBrowsingDataRemoverDone() is called, in which case we may have to reload as well.
        // Check if it can happen.
        instance.clearBrowsingData(
                null, new int[]{ BrowsingDataType.CACHE }, TimePeriod.ALL_TIME);
    }
}
 
Example #14
Source File: ContextualSearchPolicy.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether a promo is needed because the user is still undecided
 *         on enabling or disabling the feature.
 */
private boolean isUserUndecided() {
    // TODO(donnd) use dependency injection for the PrefServiceBridge instead!
    if (mDidOverrideDecidedStateForTesting) return !mDecidedStateForTesting;

    return PrefServiceBridge.getInstance().isContextualSearchUninitialized();
}
 
Example #15
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private boolean mayPrerender(CustomTabsSessionToken session) {
    if (!DeviceClassManager.enablePrerendering()) return false;
    // TODO(yusufo): The check for prerender in PrivacyManager now checks for the network
    // connection type as well, we should either change that or add another check for custom
    // tabs. Then PrivacyManager should be used to make the below check.
    if (!PrefServiceBridge.getInstance().getNetworkPredictionEnabled()) return false;
    if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) return false;
    ConnectivityManager cm =
            (ConnectivityManager) mApplication.getApplicationContext().getSystemService(
                    Context.CONNECTIVITY_SERVICE);
    return !cm.isActiveNetworkMetered() || shouldPrerenderOnCellularForSession(session);
}
 
Example #16
Source File: DataReductionPromoUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Saves shared prefs indicating that the data reduction proxy first run experience or second
 * run promo screen has been displayed at the current time.
 */
public static void saveFreOrSecondRunPromoDisplayed() {
    AboutVersionStrings versionStrings = PrefServiceBridge.getInstance()
            .getAboutVersionStrings();
    ContextUtils.getAppSharedPreferences()
            .edit()
            .putBoolean(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_RUN_PROMO, true)
            .putLong(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_TIME_MS,
                    System.currentTimeMillis())
            .putString(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_VERSION,
                    versionStrings.getApplicationVersion())
            .apply();
}
 
Example #17
Source File: SiteSettingsCategory.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the current category is managed by the custodian (e.g. parent, not an
 * enterprise admin) of the account if the account is supervised.
 */
public boolean isManagedByCustodian() {
    PrefServiceBridge prefs = PrefServiceBridge.getInstance();
    if (showCookiesSites()) return prefs.isAcceptCookiesManagedByCustodian();
    if (showGeolocationSites()) {
        return prefs.isAllowLocationManagedByCustodian();
    }
    if (showCameraSites()) {
        return prefs.isCameraManagedByCustodian();
    }
    if (showMicrophoneSites()) {
        return prefs.isMicManagedByCustodian();
    }
    return false;
}
 
Example #18
Source File: FirstRunFlowSequencer.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Marks a given flow as completed.
 * @param activity An activity.
 * @param data Resulting FRE properties bundle.
 */
public static void markFlowAsCompleted(Activity activity, Bundle data) {
    // When the user accepts ToS in the Setup Wizard (see ToSAckedReceiver), we do not
    // show the ToS page to the user because the user has already accepted one outside FRE.
    if (!PrefServiceBridge.getInstance().isFirstRunEulaAccepted()) {
        PrefServiceBridge.getInstance().setEulaAccepted();
    }

    // Mark the FRE flow as complete and set the sign-in flow preferences if necessary.
    FirstRunSignInProcessor.finalizeFirstRunFlowState(activity, data);
}
 
Example #19
Source File: DataReductionPromoUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Saves shared prefs indicating that the data reduction proxy first run experience or second
 * run promo screen has been displayed at the current time.
 */
public static void saveFreOrSecondRunPromoDisplayed() {
    AboutVersionStrings versionStrings = PrefServiceBridge.getInstance()
            .getAboutVersionStrings();
    ContextUtils.getAppSharedPreferences()
            .edit()
            .putBoolean(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_RUN_PROMO, true)
            .putLong(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_TIME_MS,
                    System.currentTimeMillis())
            .putString(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_VERSION,
                    versionStrings.getApplicationVersion())
            .apply();
}
 
Example #20
Source File: PageInfoPopup.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private boolean hasAndroidPermission(int contentSettingType) {
    String[] androidPermissions =
            PrefServiceBridge.getAndroidPermissionsForContentSetting(contentSettingType);
    if (androidPermissions == null) return true;
    for (int i = 0; i < androidPermissions.length; i++) {
        if (!mWindowAndroid.hasPermission(androidPermissions[i])) {
            return false;
        }
    }
    return true;
}
 
Example #21
Source File: AndroidPermissionRequester.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private static SparseArray<String> generatePermissionsMapping(
        WindowAndroid windowAndroid, int[] contentSettingsTypes) {
    SparseArray<String> permissionsToRequest = new SparseArray<String>();
    for (int i = 0; i < contentSettingsTypes.length; i++) {
        String permission = PrefServiceBridge.getAndroidPermissionForContentSetting(
                contentSettingsTypes[i]);
        if (permission != null && !windowAndroid.hasPermission(permission)) {
            permissionsToRequest.append(contentSettingsTypes[i], permission);
        }
    }
    return permissionsToRequest;
}
 
Example #22
Source File: PrivacyPreferencesManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Update usage and crash preferences based on Android preferences if possible in case they are
 * out of sync.
 */
public void syncUsageAndCrashReportingPrefs() {
    if (PrefServiceBridge.isInitialized()) {
        PrefServiceBridge.getInstance().setMetricsReportingEnabled(
                isUsageAndCrashReportingPermittedByUser());
    }
}
 
Example #23
Source File: HistoryManagerToolbar.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void updateMenuItemVisibility() {
    // Once the selection mode delete or incognito menu options are removed, they will not
    // be added back until the user refreshes the history UI. This could happen if the user is
    // signed in to an account that cannot remove browsing history or has incognito disabled and
    // signs out.
    if (!PrefServiceBridge.getInstance().canDeleteBrowsingHistory()) {
        getMenu().removeItem(R.id.selection_mode_delete_menu_id);
    }
    if (!PrefServiceBridge.getInstance().isIncognitoModeEnabled()) {
        getMenu().removeItem(R.id.selection_mode_open_in_incognito);
    }
}
 
Example #24
Source File: FirstRunGlueImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void acceptTermsOfService(boolean allowCrashUpload) {
    UmaSessionStats.changeMetricsReportingConsent(allowCrashUpload);
    ContextUtils.getAppSharedPreferences()
            .edit()
            .putBoolean(CACHED_TOS_ACCEPTED_PREF, true)
            .apply();
    PrefServiceBridge.getInstance().setEulaAccepted();
}
 
Example #25
Source File: ChromeActivitySessionTracker.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Honor the Android system setting about showing the last character of a password for a short
 * period of time.
 */
private void updatePasswordEchoState() {
    boolean systemEnabled = Settings.System.getInt(mApplication.getContentResolver(),
            Settings.System.TEXT_SHOW_PASSWORD, 1) == 1;
    if (PrefServiceBridge.getInstance().getPasswordEchoEnabled() == systemEnabled) return;

    PrefServiceBridge.getInstance().setPasswordEchoEnabled(systemEnabled);
}
 
Example #26
Source File: SiteSettingsCategory.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the current category is managed by the custodian (e.g. parent, not an
 * enterprise admin) of the account if the account is supervised.
 */
public boolean isManagedByCustodian() {
    PrefServiceBridge prefs = PrefServiceBridge.getInstance();
    if (showGeolocationSites()) {
        return prefs.isAllowLocationManagedByCustodian();
    }
    if (showCameraSites()) {
        return prefs.isCameraManagedByCustodian();
    }
    if (showMicrophoneSites()) {
        return prefs.isMicManagedByCustodian();
    }
    return false;
}
 
Example #27
Source File: SingleCategoryPreferences.java    From delion with Apache License 2.0 5 votes vote down vote up
private void updateThirdPartyCookiesCheckBox() {
    ChromeBaseCheckBoxPreference thirdPartyCookiesPref = (ChromeBaseCheckBoxPreference)
            getPreferenceScreen().findPreference(THIRD_PARTY_COOKIES_TOGGLE_KEY);
    thirdPartyCookiesPref.setEnabled(PrefServiceBridge.getInstance().isAcceptCookiesEnabled());
    thirdPartyCookiesPref.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {
        @Override
        public boolean isPreferenceControlledByPolicy(Preference preference) {
            return PrefServiceBridge.getInstance().isBlockThirdPartyCookiesManaged();
        }
    });
}
 
Example #28
Source File: FirstRunFlowSequencer.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Marks a given flow as completed.
 * @param activity An activity.
 * @param data Resulting FRE properties bundle.
 */
public static void markFlowAsCompleted(Activity activity, Bundle data) {
    // When the user accepts ToS in the Setup Wizard (see ToSAckedReceiver), we do not
    // show the ToS page to the user because the user has already accepted one outside FRE.
    if (!PrefServiceBridge.getInstance().isFirstRunEulaAccepted()) {
        PrefServiceBridge.getInstance().setEulaAccepted();
    }

    // Mark the FRE flow as complete and set the sign-in flow preferences if necessary.
    FirstRunSignInProcessor.finalizeFirstRunFlowState(activity, data);
}
 
Example #29
Source File: ContextualSearchTabHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return whether Contextual Search is enabled and active in this tab.
 */
private boolean isContextualSearchActive(ContentViewCore cvc) {
    ContextualSearchManager manager = getContextualSearchManager();
    if (manager == null) return false;

    return !cvc.getWebContents().isIncognito()
            && !PrefServiceBridge.getInstance().isContextualSearchDisabled()
            && TemplateUrlService.getInstance().isDefaultSearchEngineGoogle()
            // Svelte and Accessibility devices are incompatible with the first-run flow and
            // Talkback has poor interaction with tap to search (see http://crbug.com/399708 and
            // http://crbug.com/396934).
            && !manager.isRunningInCompatibilityMode()
            && !(mTab.isShowingErrorPage() || mTab.isShowingInterstitialPage())
            && isDeviceOnline(manager);
}
 
Example #30
Source File: ContextualSearchPolicy.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return whether or not the Contextual Search Result should be preloaded before the user
 *         explicitly interacts with the feature.
 */
boolean shouldPrefetchSearchResult() {
    if (isMandatoryPromoAvailable()) return false;

    if (!PrefServiceBridge.getInstance().getNetworkPredictionEnabled()) return false;

    // We may not be prefetching due to the resolve/prefetch limit.
    if (isTapBeyondTheLimit()) return false;

    // We never preload on long-press so users can cut & paste without hitting the servers.
    return mSelectionController.getSelectionType() == SelectionType.TAP;
}