Java Code Examples for org.chromium.chrome.browser.ChromeFeatureList

The following examples show how to use org.chromium.chrome.browser.ChromeFeatureList. These examples are extracted from open source projects. 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 Project: delion   Source File: PhysicalWeb.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Perform various Physical Web operations that should happen on startup.
 * @param application An instance of {@link ChromeApplication}.
 */
public static void onChromeStart(ChromeApplication application) {
    // The PhysicalWebUma calls in this method should be called only when the native library is
    // loaded.  This is always the case on chrome startup.
    if (featureIsEnabled()
            && (isPhysicalWebPreferenceEnabled(application) || isOnboarding(application))) {
        boolean ignoreOtherClients =
                ChromeFeatureList.isEnabled(IGNORE_OTHER_CLIENTS_FEATURE_NAME);
        ContextUtils.getAppSharedPreferences().edit()
                .putBoolean(PREF_IGNORE_OTHER_CLIENTS, ignoreOtherClients)
                .apply();
        startPhysicalWeb(application);
        PhysicalWebUma.uploadDeferredMetrics(application);
    } else {
        stopPhysicalWeb(application);
    }
}
 
Example 2
Source Project: delion   Source File: SiteSettingsPreferences.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.site_settings_preferences);
    getActivity().setTitle(R.string.prefs_site_settings);

    mProtectedContentMenuAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    String autoplayTrialGroupName =
            FieldTrialList.findFullName("MediaElementGestureOverrideExperiment");
    mAutoplayMenuAvailable = autoplayTrialGroupName.startsWith("Enabled")
            || ChromeFeatureList.isEnabled(AUTOPLAY_MUTED_VIDEOS);

    String category = "";
    if (getArguments() != null) {
        category = getArguments().getString(SingleCategoryPreferences.EXTRA_CATEGORY, "");
        if (MEDIA_KEY.equals(category)) {
            mMediaSubMenu = true;
            getActivity().setTitle(findPreference(MEDIA_KEY).getTitle().toString());
        }
    }

    configurePreferences();
    updatePreferenceStates();
}
 
Example 3
Source Project: AndroidChromium   Source File: PaymentRequestFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public PaymentRequest createImpl() {
    if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEB_PAYMENTS)) {
        return new InvalidPaymentRequest();
    }

    if (mWebContents == null) return new InvalidPaymentRequest();

    ContentViewCore contentViewCore = ContentViewCore.fromWebContents(mWebContents);
    if (contentViewCore == null) return new InvalidPaymentRequest();

    WindowAndroid window = contentViewCore.getWindowAndroid();
    if (window == null) return new InvalidPaymentRequest();

    Activity context = window.getActivity().get();
    if (context == null) return new InvalidPaymentRequest();

    return new PaymentRequestImpl(context, mWebContents);
}
 
Example 4
Source Project: AndroidChromium   Source File: PaymentRequestImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * If no payment methods are supported, disconnect from the client and return true.
 *
 * @return True if no payment methods are supported
 */
private boolean disconnectIfNoPaymentMethodsSupported() {
    boolean waitingForPaymentApps = !isFinishedQueryingPaymentApps();
    boolean foundPaymentMethods =
            mPaymentMethodsSection != null && !mPaymentMethodsSection.isEmpty();
    boolean userCanAddCreditCard = mMerchantSupportsAutofillPaymentInstruments
            && !ChromeFeatureList.isEnabled(ChromeFeatureList.NO_CREDIT_CARD_ABORT);

    if (!mArePaymentMethodsSupported
            || (getIsShowing() && !waitingForPaymentApps && !foundPaymentMethods
                       && !userCanAddCreditCard)) {
        // All payment apps have responded, but none of them have instruments. It's possible to
        // add credit cards, but the merchant does not support them either. The payment request
        // must be rejected.
        disconnectFromClientWithDebugMessage("Requested payment methods have no instruments",
                PaymentErrorReason.NOT_SUPPORTED);
        recordAbortReasonHistogram(mArePaymentMethodsSupported
                        ? PaymentRequestMetrics.ABORT_REASON_NO_MATCHING_PAYMENT_METHOD
                        : PaymentRequestMetrics.ABORT_REASON_NO_SUPPORTED_PAYMENT_METHOD);
        if (sObserverForTest != null) sObserverForTest.onPaymentRequestServiceShowFailed();
        return true;
    }

    return false;
}
 
Example 5
Source Project: AndroidChromium   Source File: PhysicalWeb.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Perform various Physical Web operations that should happen on startup.
 */
public static void onChromeStart() {
    // The PhysicalWebUma calls in this method should be called only when the native library is
    // loaded.  This is always the case on chrome startup.
    if (featureIsEnabled() && (isPhysicalWebPreferenceEnabled() || isOnboarding())) {
        boolean ignoreOtherClients =
                ChromeFeatureList.isEnabled(IGNORE_OTHER_CLIENTS_FEATURE_NAME);
        ContextUtils.getAppSharedPreferences().edit()
                .putBoolean(PREF_IGNORE_OTHER_CLIENTS, ignoreOtherClients)
                .apply();
        startPhysicalWeb();
        PhysicalWebUma.uploadDeferredMetrics();
    } else {
        stopPhysicalWeb();
    }
}
 
Example 6
Source Project: AndroidChromium   Source File: CustomTabsConnection.java    License: Apache License 2.0 6 votes vote down vote up
private boolean validatePostMessageOriginInternal(final CustomTabsSessionToken session) {
    if (!mWarmupHasBeenCalled.get()) return false;
    if (!isCallerForegroundOrSelf()) return false;
    final int uid = Binder.getCallingUid();
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            // If the API is not enabled, we don't set the post message origin, which will
            // avoid PostMessageHandler initialization and disallow postMessage calls.
            if (!ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_POST_MESSAGE_API)) return;
            mClientManager.setPostMessageOriginForSession(
                    session, acquireOriginForSession(session, uid));
        }
    });
    return true;
}
 
Example 7
Source Project: 365browser   Source File: SearchEngineAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private boolean locationEnabled(TemplateUrl templateUrl) {
    String url = getSearchEngineUrl(templateUrl);
    if (url.isEmpty()) return false;

    GeolocationInfo locationSettings = new GeolocationInfo(url, null, false);
    ContentSetting locationPermission = locationSettings.getContentSetting();
    if (locationPermission == ContentSetting.ASK) {
        // Handle the case where the geoHeader being sent when no permission has been specified.
        if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) {
            if (WebsitePreferenceBridge.shouldUseDSEGeolocationSetting(url, false)) {
                return WebsitePreferenceBridge.getDSEGeolocationSetting();
            }
        } else if (GeolocationHeader.isGeoHeaderEnabledForUrl(url, false)) {
            return true;
        }
    }

    return locationPermission == ContentSetting.ALLOW;
}
 
Example 8
Source Project: AndroidChromium   Source File: FeatureUtilities.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Cache whether or not Chrome Home is enabled.
 */
public static void cacheChromeHomeEnabled() {
    Context context = ContextUtils.getApplicationContext();

    // Chrome Home doesn't work with tablets.
    if (DeviceFormFactor.isTablet(context)) return;

    boolean isChromeHomeEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME);
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance(context);
    boolean valueChanged = isChromeHomeEnabled != manager.isChromeHomeEnabled();
    manager.setChromeHomeEnabled(isChromeHomeEnabled);
    sChromeHomeEnabled = isChromeHomeEnabled;

    // If the cached value changed, restart chrome.
    if (valueChanged) ApplicationLifetime.terminate(true);
}
 
Example 9
Source Project: AndroidChromium   Source File: InvalidationController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the instance that will use {@code context} to issue intents.
 *
 * Calling this method will create the instance if it does not yet exist.
 */
public static InvalidationController get(Context context) {
    synchronized (LOCK) {
        if (sInstance == null) {
            // The PageRevisitInstrumentation trial needs sessions invalidations to be on such
            // that local session data is current and can be used to perform checks.
            boolean requireInvalidationsForInstrumentation =
                    FieldTrialList.findFullName("PageRevisitInstrumentation").equals("Enabled");
            // If the NTP is trying to suggest foreign tabs, then recieving invalidations is
            // vital, otherwise data is stale and less useful.
            boolean requireInvalidationsForSuggestions = ChromeFeatureList.isEnabled(
                    ChromeFeatureList.NTP_FOREIGN_SESSIONS_SUGGESTIONS);
            boolean canDisableSessionInvalidations = !requireInvalidationsForInstrumentation
                    && !requireInvalidationsForSuggestions;

            boolean canUseGcmUpstream =
                    FieldTrialList.findFullName("InvalidationsGCMUpstream").equals("Enabled");
            sInstance = new InvalidationController(
                    context, canDisableSessionInvalidations, canUseGcmUpstream);
        }
        return sInstance;
    }
}
 
Example 10
Source Project: 365browser   Source File: PaymentRequestImpl.java    License: Apache License 2.0 6 votes vote down vote up
/** Updates the modifiers for payment instruments and order summary. */
private void updateInstrumentModifiedTotals() {
    if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEB_PAYMENTS_MODIFIERS)) return;
    if (mModifiers == null) return;
    if (mPaymentMethodsSection == null) return;

    for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) {
        PaymentInstrument instrument = (PaymentInstrument) mPaymentMethodsSection.getItem(i);
        PaymentDetailsModifier modifier = getModifier(instrument);
        instrument.setModifiedTotal(modifier == null || modifier.total == null
                        ? null
                        : getOrCreateCurrencyFormatter(modifier.total.amount)
                                  .format(modifier.total.amount.value));
    }

    updateOrderSummary((PaymentInstrument) mPaymentMethodsSection.getSelectedItem());
}
 
Example 11
Source Project: 365browser   Source File: SearchEngineAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private boolean locationShouldBeShown(TemplateUrl templateUrl) {
    String url = getSearchEngineUrl(templateUrl);
    if (url.isEmpty()) return false;

    // Do not show location if the scheme isn't HTTPS.
    Uri uri = Uri.parse(url);
    if (!UrlConstants.HTTPS_SCHEME.equals(uri.getScheme())) return false;

    // Only show the location setting if it is explicitly enabled or disabled.
    GeolocationInfo locationSettings = new GeolocationInfo(url, null, false);
    ContentSetting locationPermission = locationSettings.getContentSetting();
    if (locationPermission != ContentSetting.ASK) return true;

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) {
        return WebsitePreferenceBridge.shouldUseDSEGeolocationSetting(url, false);
    }

    return GeolocationHeader.isGeoHeaderEnabledForUrl(url, false);
}
 
Example 12
Source Project: 365browser   Source File: DataReductionProxySettings.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the Data Reduction Proxy menu item should be shown in the main menu.
 */
public boolean shouldUseDataReductionMainMenuItem() {
    if (!ChromeFeatureList.isEnabled(ChromeFeatureList.DATA_REDUCTION_MAIN_MENU)) return false;

    if (ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean(
                ChromeFeatureList.DATA_REDUCTION_MAIN_MENU, PARAM_PERSISTENT_MENU_ITEM_ENABLED,
                false)) {
        // If the Data Reduction Proxy is enabled, set the pref storing that the proxy has
        // ever been enabled.
        if (isDataReductionProxyEnabled()) {
            ContextUtils.getAppSharedPreferences()
                    .edit()
                    .putBoolean(DATA_REDUCTION_HAS_EVER_BEEN_ENABLED_PREF, true)
                    .apply();
        }
        return ContextUtils.getAppSharedPreferences().getBoolean(
                DATA_REDUCTION_HAS_EVER_BEEN_ENABLED_PREF, false);
    } else {
        return isDataReductionProxyEnabled();
    }
}
 
Example 13
Source Project: 365browser   Source File: AutofillAndPaymentsPreferences.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceUtils.addPreferencesFromResource(this, R.xml.autofill_and_payments_preferences);
    getActivity().setTitle(R.string.prefs_autofill_and_payments);

    ChromeSwitchPreference autofillSwitch =
            (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PersonalDataManager.setAutofillEnabled((boolean) newValue);
            return true;
        }
    });

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS)) {
        Preference pref = new Preference(getActivity());
        pref.setTitle(getActivity().getString(R.string.payment_apps_title));
        pref.setFragment(AndroidPaymentAppsFragment.class.getCanonicalName());
        pref.setShouldDisableView(true);
        pref.setKey(PREF_ANDROID_PAYMENT_APPS);
        getPreferenceScreen().addPreference(pref);
    }
}
 
Example 14
Source Project: 365browser   Source File: InvalidationController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the instance that will use {@code context} to issue intents.
 *
 * Calling this method will create the instance if it does not yet exist.
 */
public static InvalidationController get(Context context) {
    synchronized (LOCK) {
        if (sInstance == null) {
            // The PageRevisitInstrumentation trial needs sessions invalidations to be on such
            // that local session data is current and can be used to perform checks.
            boolean requireInvalidationsForInstrumentation =
                    FieldTrialList.findFullName("PageRevisitInstrumentation").equals("Enabled");
            // If the NTP is trying to suggest foreign tabs, then recieving invalidations is
            // vital, otherwise data is stale and less useful.
            boolean requireInvalidationsForSuggestions = ChromeFeatureList.isEnabled(
                    ChromeFeatureList.NTP_FOREIGN_SESSIONS_SUGGESTIONS);
            boolean canDisableSessionInvalidations = !requireInvalidationsForInstrumentation
                    && !requireInvalidationsForSuggestions;

            sInstance = new InvalidationController(context, canDisableSessionInvalidations);
        }
        return sInstance;
    }
}
 
Example 15
Source Project: delion   Source File: NativePageFactory.java    License: Apache License 2.0 5 votes vote down vote up
private static NativePageType nativePageType(String url, NativePage candidatePage,
        boolean isIncognito) {
    if (url == null) return NativePageType.NONE;

    Uri uri = Uri.parse(url);
    if (!CHROME_NATIVE_SCHEME.equals(uri.getScheme())) {
        return NativePageType.NONE;
    }

    String host = uri.getHost();
    if (candidatePage != null && candidatePage.getHost().equals(host)) {
        return NativePageType.CANDIDATE;
    }

    if (UrlConstants.NTP_HOST.equals(host)) {
        return NativePageType.NTP;
    } else if (UrlConstants.BOOKMARKS_HOST.equals(host)) {
        return NativePageType.BOOKMARKS;
    } else if (UrlConstants.RECENT_TABS_HOST.equals(host) && !isIncognito) {
        return NativePageType.RECENT_TABS;
    } else if (UrlConstants.PHYSICAL_WEB_HOST.equals(host)) {
        if (ChromeFeatureList.isEnabled("PhysicalWeb")) {
            return NativePageType.PHYSICAL_WEB;
        } else {
            return NativePageType.NONE;
        }
    } else {
        return NativePageType.NONE;
    }
}
 
Example 16
Source Project: 365browser   Source File: DataReductionStatsPreference.java    License: Apache License 2.0 5 votes vote down vote up
public DataReductionStatsPreference(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.DATA_REDUCTION_SITE_BREAKDOWN)) {
        setWidgetLayoutResource(R.layout.data_reduction_stats_layout);
    } else {
        setWidgetLayoutResource(R.layout.data_reduction_old_stats_layout);
    }
}
 
Example 17
Source Project: delion   Source File: ExternalNavigationDelegateImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isPdfDownload(String url) {
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.SYSTEM_DOWNLOAD_MANAGER)) return false;

    String fileExtension = MimeTypeMap.getFileExtensionFromUrl(url);
    if (TextUtils.isEmpty(fileExtension)) return false;

    return PDF_EXTENSION.equals(fileExtension);
}
 
Example 18
Source Project: 365browser   Source File: FeatureUtilities.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Cache whether or not Chrome Home is enabled.
 */
public static void cacheChromeHomeEnabled() {
    // Chrome Home doesn't work with tablets.
    if (DeviceFormFactor.isTablet()) return;

    boolean isChromeHomeEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME);
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance();
    boolean valueChanged = isChromeHomeEnabled != manager.isChromeHomeEnabled();
    manager.setChromeHomeEnabled(isChromeHomeEnabled);
    sChromeHomeEnabled = isChromeHomeEnabled;

    // If the cached value changed, restart chrome.
    if (valueChanged) ApplicationLifetime.terminate(true);
}
 
Example 19
Source Project: 365browser   Source File: TileGroup.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param context Used for initialisation and resolving resources.
 * @param uiDelegate Delegate used to interact with the rest of the system.
 * @param contextMenuManager Used to handle context menu invocations on the tiles.
 * @param tileGroupDelegate Used for interactions with the Most Visited backend.
 * @param observer Will be notified of changes to the tile data.
 * @param titleLines The number of text lines to use for each tile title.
 */
public TileGroup(Context context, SuggestionsUiDelegate uiDelegate,
        ContextMenuManager contextMenuManager, Delegate tileGroupDelegate, Observer observer,
        OfflinePageBridge offlinePageBridge, int titleLines) {
    mContext = context;
    mUiDelegate = uiDelegate;
    mContextMenuManager = contextMenuManager;
    mTileGroupDelegate = tileGroupDelegate;
    mObserver = observer;
    mTitleLinesCount = titleLines;

    Resources resources = mContext.getResources();
    mDesiredIconSize = resources.getDimensionPixelSize(R.dimen.tile_view_icon_size);
    // On ldpi devices, mDesiredIconSize could be even smaller than ICON_MIN_SIZE_PX.
    mMinIconSize = Math.min(mDesiredIconSize, ICON_MIN_SIZE_PX);
    int desiredIconSizeDp =
            Math.round(mDesiredIconSize / resources.getDisplayMetrics().density);
    int iconColor =
            ApiCompatibilityUtils.getColor(resources, R.color.default_favicon_background_color);
    mIconGenerator = new RoundedIconGenerator(mContext, desiredIconSizeDp, desiredIconSizeDp,
            ICON_CORNER_RADIUS_DP, iconColor, ICON_TEXT_SIZE_DP);

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_OFFLINE_PAGES_FEATURE_NAME)) {
        mOfflineModelObserver = new OfflineModelObserver(offlinePageBridge);
        mUiDelegate.addDestructionObserver(mOfflineModelObserver);
    } else {
        mOfflineModelObserver = null;
    }
}
 
Example 20
Source Project: AndroidChromium   Source File: LocaleManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether the Chrome instance is running in a special locale.
 */
public boolean isSpecialLocaleEnabled() {
    // If there is a kill switch sent from the server, disable the feature.
    if (!ChromeFeatureList.isEnabled("SpecialLocaleWrapper")) {
        return false;
    }
    boolean inSpecialLocale = ChromeFeatureList.isEnabled("SpecialLocale");
    inSpecialLocale = isReallyInSpecialLocale(inSpecialLocale);
    return inSpecialLocale;
}
 
Example 21
/**
 * Shows the geolocation snackbar if it hasn't already been shown and the geolocation snackbar
 * is currently relevant: i.e. the default search engine is Google, location is enabled
 * for Chrome, the tab is not incognito, etc.
 *
 * @param snackbarManager The SnackbarManager used to show the snackbar.
 * @param view Any view that's attached to the view hierarchy.
 * @param isIncognito Whether the currently visible tab is incognito.
 * @param delayMs The delay in ms before the snackbar should be shown. This is intended to
 *                give the keyboard time to animate in.
 */
public static void maybeShowSnackbar(final SnackbarManager snackbarManager, View view,
        boolean isIncognito, int delayMs) {
    final Context context = view.getContext();
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) return;
    if (getGeolocationSnackbarShown(context)) return;

    // If in incognito mode, don't show the snackbar now, but maybe show it later.
    if (isIncognito) return;

    if (neverShowSnackbar(context)) {
        setGeolocationSnackbarShown(context);
        return;
    }

    Uri searchUri = Uri.parse(TemplateUrlService.getInstance().getUrlForSearchQuery("foo"));
    TypefaceSpan robotoMediumSpan = new TypefaceSpan("sans-serif-medium");
    String messageWithoutSpans = context.getResources().getString(
            R.string.omnibox_geolocation_disclosure, "<b>" + searchUri.getHost() + "</b>");
    SpannableString message = SpanApplier.applySpans(messageWithoutSpans,
            new SpanInfo("<b>", "</b>", robotoMediumSpan));
    String settings = context.getResources().getString(R.string.preferences);
    int durationMs = DeviceClassManager.isAccessibilityModeEnabled(view.getContext())
            ? ACCESSIBILITY_SNACKBAR_DURATION_MS : SNACKBAR_DURATION_MS;
    final GeolocationSnackbarController controller = new GeolocationSnackbarController();
    final Snackbar snackbar = Snackbar
            .make(message, controller, Snackbar.TYPE_ACTION, Snackbar.UMA_OMNIBOX_GEOLOCATION)
            .setAction(settings, view)
            .setSingleLine(false)
            .setDuration(durationMs);

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            snackbarManager.dismissSnackbars(controller);
            snackbarManager.showSnackbar(snackbar);
            setGeolocationSnackbarShown(context);
        }
    }, delayMs);
}
 
Example 22
/**
 * @return Whether or not single actions based on Contextual Cards is enabled.
 */
static boolean isContextualSearchSingleActionsEnabled() {
    if (sContextualSearchSingleActionsEnabled == null) {
        sContextualSearchSingleActionsEnabled =
                ChromeFeatureList.isEnabled(ChromeFeatureList.CONTEXTUAL_SEARCH_SINGLE_ACTIONS);
    }

    return sContextualSearchSingleActionsEnabled;
}
 
Example 23
Source Project: AndroidChromium   Source File: NativePageFactory.java    License: Apache License 2.0 5 votes vote down vote up
private static NativePageType nativePageType(String url, NativePage candidatePage,
        boolean isIncognito) {
    if (url == null) return NativePageType.NONE;

    Uri uri = Uri.parse(url);
    if (!CHROME_NATIVE_SCHEME.equals(uri.getScheme())) {
        return NativePageType.NONE;
    }

    String host = uri.getHost();
    if (candidatePage != null && candidatePage.getHost().equals(host)) {
        return NativePageType.CANDIDATE;
    }

    if (UrlConstants.NTP_HOST.equals(host)) {
        return NativePageType.NTP;
    } else if (UrlConstants.BOOKMARKS_HOST.equals(host)) {
        return NativePageType.BOOKMARKS;
    } else if (UrlConstants.DOWNLOADS_HOST.equals(host)) {
        return NativePageType.DOWNLOADS;
    } else if (UrlConstants.RECENT_TABS_HOST.equals(host) && !isIncognito) {
        return NativePageType.RECENT_TABS;
    } else if (UrlConstants.PHYSICAL_WEB_HOST.equals(host)) {
        if (ChromeFeatureList.isEnabled("PhysicalWeb")) {
            return NativePageType.PHYSICAL_WEB;
        } else {
            return NativePageType.NONE;
        }
    } else {
        return NativePageType.NONE;
    }
}
 
Example 24
Source Project: 365browser   Source File: ClearBrowsingDataPreferences.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns if we should show the important sites dialog. We check to see if
 * <ol>
 * <li>We've fetched the important sites,
 * <li>there are important sites,
 * <li>the feature is enabled, and
 * <li>we have cache or cookies selected.
 * </ol>
 */
private boolean shouldShowImportantSitesDialog() {
    if (!ChromeFeatureList.isEnabled(ChromeFeatureList.IMPORTANT_SITES_IN_CBD)) return false;
    EnumSet<DialogOption> selectedOptions = getSelectedOptions();
    if (!selectedOptions.contains(DialogOption.CLEAR_CACHE)
            && !selectedOptions.contains(DialogOption.CLEAR_COOKIES_AND_SITE_DATA)) {
        return false;
    }
    boolean haveImportantSites =
            mSortedImportantDomains != null && mSortedImportantDomains.length != 0;
    RecordHistogram.recordBooleanHistogram(
            "History.ClearBrowsingData.ImportantDialogShown", haveImportantSites);
    return haveImportantSites;
}
 
Example 25
Source Project: AndroidChromium   Source File: TabRedirectHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Updates |mIntentHistory| and |mLastIntentUpdatedTime|. If |intent| comes from chrome and
 * currently |mIsOnEffectiveIntentRedirectChain| is true, that means |intent| was sent from
 * this tab because only the front tab or a new tab can receive an intent from chrome. In that
 * case, |intent| is added to |mIntentHistory|.
 * Otherwise, |mIntentHistory| and |mPreviousResolvers| are cleared, and then |intent| is put
 * into |mIntentHistory|.
 */
public void updateIntent(Intent intent) {
    clear();

    if (mContext == null || intent == null || !Intent.ACTION_VIEW.equals(intent.getAction())) {
        return;
    }

    mIsCustomTabIntent = ChromeLauncherActivity.isCustomTabIntent(intent);
    boolean checkIsToChrome = true;
    // All custom tabs VIEW intents are by design explicit intents, so the presence of package
    // name doesn't imply they have to be handled by Chrome explicitly. Check if external apps
    // should be checked for handling the initial redirect chain.
    if (mIsCustomTabIntent) {
        boolean sendToExternalApps = IntentUtils.safeGetBooleanExtra(intent,
                CustomTabIntentDataProvider.EXTRA_SEND_TO_EXTERNAL_DEFAULT_HANDLER, false);
        checkIsToChrome = !(sendToExternalApps
                && ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_EXTERNAL_LINK_HANDLING));
    }

    if (checkIsToChrome) mIsInitialIntentHeadingToChrome = isIntentToChrome(mContext, intent);

    // A copy of the intent with component cleared to find resolvers.
    mInitialIntent = new Intent(intent).setComponent(null);
    Intent selector = mInitialIntent.getSelector();
    if (selector != null) selector.setComponent(null);
}
 
Example 26
Source Project: 365browser   Source File: SingleWebsitePreferences.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the current host matches the default search engine host and location for the
 * default search engine is being granted via x-geo.
 * @param context The current context.
 */
private boolean hasXGeoLocationPermission(Context context) {
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) {
        return false;
    }

    String searchUrl = TemplateUrlService.getInstance().getUrlForSearchQuery("foo");
    return mSite.getAddress().matches(searchUrl)
            && GeolocationHeader.isGeoHeaderEnabledForUrl(searchUrl, false);
}
 
Example 27
Source Project: 365browser   Source File: PasswordEntryEditor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (ChromeFeatureList.isEnabled(VIEW_PASSWORDS)) {
        setHasOptionsMenu(true);
    }
}
 
Example 28
Source Project: 365browser   Source File: PaymentRequestFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PaymentRequest createImpl() {
    if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEB_PAYMENTS)) {
        return new InvalidPaymentRequest();
    }

    if (mRenderFrameHost == null) return new InvalidPaymentRequest();

    return new PaymentRequestImpl(mRenderFrameHost);
}
 
Example 29
Source Project: 365browser   Source File: PaymentRequestImpl.java    License: Apache License 2.0 5 votes vote down vote up
/** Sets the modifier for the order summary based on the given instrument, if any. */
private void updateOrderSummary(@Nullable PaymentInstrument instrument) {
    if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEB_PAYMENTS_MODIFIERS)) return;

    PaymentDetailsModifier modifier = getModifier(instrument);
    PaymentItem total = modifier == null ? null : modifier.total;
    if (total == null) total = mRawTotal;

    CurrencyFormatter formatter = getOrCreateCurrencyFormatter(total.amount);
    mUiShoppingCart.setTotal(new LineItem(total.label, formatter.getFormattedCurrencyCode(),
            formatter.format(total.amount.value), false /* isPending */));
    mUiShoppingCart.setAdditionalContents(
            modifier == null ? null : getLineItems(modifier.additionalDisplayItems));
    if (mUI != null) mUI.updateOrderSummarySection(mUiShoppingCart);
}
 
Example 30
Source Project: 365browser   Source File: PaymentAppFactory.java    License: Apache License 2.0 5 votes vote down vote up
private PaymentAppFactory() {
    mAdditionalFactories = new ArrayList<>();

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS)) {
        mAdditionalFactories.add(new AndroidPaymentAppFactory());
    }

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.SERVICE_WORKER_PAYMENT_APPS)) {
        mAdditionalFactories.add(new ServiceWorkerPaymentAppBridge());
    }
}