Search in sources :

Example 1 with TemplateUrlService

use of org.chromium.chrome.browser.search_engines.TemplateUrlService in project AndroidChromium by JackyAndroid.

the class ToolbarManager method registerTemplateUrlObserver.

private void registerTemplateUrlObserver() {
    final TemplateUrlService templateUrlService = TemplateUrlService.getInstance();
    assert mTemplateUrlObserver == null;
    mTemplateUrlObserver = new TemplateUrlServiceObserver() {

        private TemplateUrl mSearchEngine = templateUrlService.getDefaultSearchEngineTemplateUrl();

        @Override
        public void onTemplateURLServiceChanged() {
            TemplateUrl searchEngine = templateUrlService.getDefaultSearchEngineTemplateUrl();
            if ((mSearchEngine == null && searchEngine == null) || (mSearchEngine != null && mSearchEngine.equals(searchEngine))) {
                return;
            }
            mSearchEngine = searchEngine;
            mToolbar.onDefaultSearchEngineChanged();
        }
    };
    templateUrlService.addObserver(mTemplateUrlObserver);
}
Also used : TemplateUrl(org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl) TemplateUrlService(org.chromium.chrome.browser.search_engines.TemplateUrlService) TemplateUrlServiceObserver(org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrlServiceObserver)

Example 2 with TemplateUrlService

use of org.chromium.chrome.browser.search_engines.TemplateUrlService in project AndroidChromium by JackyAndroid.

the class ChromeContextMenuPopulator method buildContextMenu.

@Override
public void buildContextMenu(ContextMenu menu, Context context, ContextMenuParams params) {
    if (!TextUtils.isEmpty(params.getLinkUrl()) && !params.getLinkUrl().equals(BLANK_URL)) {
        setHeaderText(context, menu, params.getLinkUrl());
    } else if (!TextUtils.isEmpty(params.getTitleText())) {
        setHeaderText(context, menu, params.getTitleText());
    }
    if (mMenuInflater == null)
        mMenuInflater = new MenuInflater(context);
    mMenuInflater.inflate(R.menu.chrome_context_menu, menu);
    menu.setGroupVisible(R.id.contextmenu_group_anchor, params.isAnchor());
    menu.setGroupVisible(R.id.contextmenu_group_image, params.isImage());
    menu.setGroupVisible(R.id.contextmenu_group_video, params.isVideo());
    if (params.isAnchor() && !mDelegate.isOpenInOtherWindowSupported()) {
        menu.findItem(R.id.contextmenu_open_in_other_window).setVisible(false);
    }
    if (mDelegate.isIncognito() || !mDelegate.isIncognitoSupported()) {
        menu.findItem(R.id.contextmenu_open_in_incognito_tab).setVisible(false);
    }
    if (params.getLinkText().trim().isEmpty() || params.isImage()) {
        menu.findItem(R.id.contextmenu_copy_link_text).setVisible(false);
    }
    if (params.isAnchor() && !UrlUtilities.isAcceptedScheme(params.getLinkUrl())) {
        menu.findItem(R.id.contextmenu_open_in_other_window).setVisible(false);
        menu.findItem(R.id.contextmenu_open_in_new_tab).setVisible(false);
        menu.findItem(R.id.contextmenu_open_in_incognito_tab).setVisible(false);
    }
    if (MailTo.isMailTo(params.getLinkUrl())) {
        menu.findItem(R.id.contextmenu_copy_link_address).setVisible(false);
    } else {
        menu.findItem(R.id.contextmenu_copy_email_address).setVisible(false);
    }
    menu.findItem(R.id.contextmenu_save_link_as).setVisible(UrlUtilities.isDownloadableScheme(params.getLinkUrl()));
    // Only enable the save as offline feature if OfflinePagesBackgroundLoading is enabled, and
    // it looks like a web page.
    boolean showSaveOfflineMenuItem = shouldShowBackgroundLoadingContextMenu(params.getLinkUrl());
    menu.findItem(R.id.contextmenu_save_offline).setVisible(showSaveOfflineMenuItem);
    if (params.imageWasFetchedLoFi() || !DataReductionProxySettings.getInstance().wasLoFiModeActiveOnMainFrame() || !DataReductionProxySettings.getInstance().canUseDataReductionProxy(params.getPageUrl())) {
        menu.findItem(R.id.contextmenu_load_images).setVisible(false);
    } else {
        // Links can have images as backgrounds that aren't recognized here as images. CSS
        // properties can also prevent an image underlying a link from being clickable.
        // When Lo-Fi is active, provide the user with a "Load images" option on links
        // to get the images in these cases.
        DataReductionProxyUma.previewsLoFiContextMenuAction(DataReductionProxyUma.ACTION_LOFI_LOAD_IMAGES_CONTEXT_MENU_SHOWN);
    }
    if (params.isVideo()) {
        menu.findItem(R.id.contextmenu_save_video).setVisible(params.canSaveMedia() && UrlUtilities.isDownloadableScheme(params.getSrcUrl()));
    } else if (params.isImage() && params.imageWasFetchedLoFi()) {
        DataReductionProxyUma.previewsLoFiContextMenuAction(DataReductionProxyUma.ACTION_LOFI_LOAD_IMAGE_CONTEXT_MENU_SHOWN);
        // All image context menu items other than "Load image," "Open original image in
        // new tab," and "Copy image URL" should be disabled on Lo-Fi images.
        menu.findItem(R.id.contextmenu_save_image).setVisible(false);
        menu.findItem(R.id.contextmenu_open_image).setVisible(false);
        menu.findItem(R.id.contextmenu_search_by_image).setVisible(false);
        menu.findItem(R.id.contextmenu_share_image).setVisible(false);
    } else if (params.isImage() && !params.imageWasFetchedLoFi()) {
        menu.findItem(R.id.contextmenu_load_original_image).setVisible(false);
        menu.findItem(R.id.contextmenu_save_image).setVisible(UrlUtilities.isDownloadableScheme(params.getSrcUrl()));
        // Avoid showing open image option for same image which is already opened.
        if (mDelegate.getPageUrl().equals(params.getSrcUrl())) {
            menu.findItem(R.id.contextmenu_open_image).setVisible(false);
        }
        final TemplateUrlService templateUrlServiceInstance = TemplateUrlService.getInstance();
        final boolean isSearchByImageAvailable = UrlUtilities.isDownloadableScheme(params.getSrcUrl()) && templateUrlServiceInstance.isLoaded() && templateUrlServiceInstance.isSearchByImageAvailable() && templateUrlServiceInstance.getDefaultSearchEngineTemplateUrl() != null;
        menu.findItem(R.id.contextmenu_search_by_image).setVisible(isSearchByImageAvailable);
        if (isSearchByImageAvailable) {
            menu.findItem(R.id.contextmenu_search_by_image).setTitle(context.getString(R.string.contextmenu_search_web_for_image, TemplateUrlService.getInstance().getDefaultSearchEngineTemplateUrl().getShortName()));
        }
    }
    if (mMode == FULLSCREEN_TAB_MODE) {
        removeUnsupportedItems(menu, FULLSCREEN_TAB_MODE_WHITELIST);
    } else if (mMode == CUSTOM_TAB_MODE) {
        removeUnsupportedItems(menu, CUSTOM_TAB_MODE_WHITELIST);
    } else {
        removeUnsupportedItems(menu, NORMAL_MODE_WHITELIST);
    }
}
Also used : TemplateUrlService(org.chromium.chrome.browser.search_engines.TemplateUrlService) MenuInflater(android.view.MenuInflater)

Example 3 with TemplateUrlService

use of org.chromium.chrome.browser.search_engines.TemplateUrlService in project AndroidChromium by JackyAndroid.

the class SearchEngineAdapter method initEntries.

/**
     * Initialize the search engine list.
     */
private void initEntries() {
    TemplateUrlService templateUrlService = TemplateUrlService.getInstance();
    if (!templateUrlService.isLoaded()) {
        templateUrlService.registerLoadListener(this);
        templateUrlService.load();
        // Flow continues in onTemplateUrlServiceLoaded below.
        return;
    }
    // Fetch all the search engine info and the currently active one.
    mSearchEngines = templateUrlService.getLocalizedSearchEngines();
    int searchEngineIndex = templateUrlService.getDefaultSearchEngineIndex();
    // Convert the TemplateUrl index into an index into mSearchEngines.
    mSelectedSearchEnginePosition = -1;
    for (int i = 0; i < mSearchEngines.size(); ++i) {
        if (mSearchEngines.get(i).getIndex() == searchEngineIndex) {
            mSelectedSearchEnginePosition = i;
        }
    }
    mInitialEnginePosition = mSelectedSearchEnginePosition;
    // Report back what is selected.
    mCallback.currentSearchEngineDetermined(toIndex(mSelectedSearchEnginePosition));
}
Also used : TemplateUrlService(org.chromium.chrome.browser.search_engines.TemplateUrlService)

Example 4 with TemplateUrlService

use of org.chromium.chrome.browser.search_engines.TemplateUrlService in project AndroidChromium by JackyAndroid.

the class PrefServiceBridge method maybeCreatePermissionForDefaultSearchEngine.

/**
     * Add a permission entry for Location for the default search engine.
     * @param allowed Whether to create an Allowed permission or a Denied permission.
     * @param context The current context to use.
     */
public static void maybeCreatePermissionForDefaultSearchEngine(boolean allowed, Context context) {
    TemplateUrlService templateUrlService = TemplateUrlService.getInstance();
    String url = templateUrlService.getSearchEngineUrlFromTemplateUrl(templateUrlService.getDefaultSearchEngineIndex());
    if (allowed && !url.startsWith("https:"))
        return;
    GeolocationInfo locationSettings = new GeolocationInfo(url, null, false);
    ContentSetting locationPermission = locationSettings.getContentSetting();
    if (locationPermission == null || locationPermission == ContentSetting.ASK) {
        WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin(url, url, allowed ? ContentSetting.ALLOW.toInt() : ContentSetting.BLOCK.toInt(), false);
        SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences();
        sharedPreferences.edit().putBoolean(LOCATION_AUTO_ALLOWED, true).apply();
    }
}
Also used : TemplateUrlService(org.chromium.chrome.browser.search_engines.TemplateUrlService) ContentSetting(org.chromium.chrome.browser.preferences.website.ContentSetting) SharedPreferences(android.content.SharedPreferences) GeolocationInfo(org.chromium.chrome.browser.preferences.website.GeolocationInfo)

Example 5 with TemplateUrlService

use of org.chromium.chrome.browser.search_engines.TemplateUrlService in project AndroidChromium by JackyAndroid.

the class ToolbarManager method onNativeLibraryReady.

private void onNativeLibraryReady() {
    mNativeLibraryReady = true;
    mToolbar.onNativeLibraryReady();
    final TemplateUrlService templateUrlService = TemplateUrlService.getInstance();
    TemplateUrlService.LoadListener mTemplateServiceLoadListener = new TemplateUrlService.LoadListener() {

        @Override
        public void onTemplateUrlServiceLoaded() {
            registerTemplateUrlObserver();
            templateUrlService.unregisterLoadListener(this);
        }
    };
    templateUrlService.registerLoadListener(mTemplateServiceLoadListener);
    if (templateUrlService.isLoaded()) {
        mTemplateServiceLoadListener.onTemplateUrlServiceLoaded();
    } else {
        templateUrlService.load();
    }
    mTabModelSelector.addObserver(mTabModelSelectorObserver);
    for (TabModel model : mTabModelSelector.getModels()) model.addObserver(mTabModelObserver);
    refreshSelectedTab();
    if (mTabModelSelector.isTabStateInitialized())
        mTabRestoreCompleted = true;
    handleTabRestoreCompleted();
}
Also used : TemplateUrlService(org.chromium.chrome.browser.search_engines.TemplateUrlService) TabModel(org.chromium.chrome.browser.tabmodel.TabModel)

Aggregations

TemplateUrlService (org.chromium.chrome.browser.search_engines.TemplateUrlService)5 SharedPreferences (android.content.SharedPreferences)1 MenuInflater (android.view.MenuInflater)1 ContentSetting (org.chromium.chrome.browser.preferences.website.ContentSetting)1 GeolocationInfo (org.chromium.chrome.browser.preferences.website.GeolocationInfo)1 TemplateUrl (org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl)1 TemplateUrlServiceObserver (org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrlServiceObserver)1 TabModel (org.chromium.chrome.browser.tabmodel.TabModel)1