Search in sources :

Example 1 with LoadUrlParams

use of org.chromium.content_public.browser.LoadUrlParams in project AndroidChromium by JackyAndroid.

the class LocationBarLayout method loadUrl.

private void loadUrl(String url, int transition) {
    Tab currentTab = getCurrentTab();
    // side is initialized
    assert mNativeInitialized : "Loading URL before native side initialized";
    if (currentTab != null && (currentTab.isNativePage() || NewTabPage.isNTPUrl(currentTab.getUrl()))) {
        NewTabPageUma.recordOmniboxNavigation(url, transition);
        // the page as it does when you click and press enter on any other site.
        if (url.isEmpty())
            url = currentTab.getUrl();
    }
    // Loads the |url| in the current ContentView and gives focus to the ContentView.
    if (currentTab != null && !url.isEmpty()) {
        LoadUrlParams loadUrlParams = new LoadUrlParams(url);
        loadUrlParams.setVerbatimHeaders(GeolocationHeader.getGeoHeader(getContext(), url, currentTab.isIncognito()));
        loadUrlParams.setTransitionType(transition | PageTransition.FROM_ADDRESS_BAR);
        currentTab.loadUrl(loadUrlParams);
        setUrlToPageUrl();
        RecordUserAction.record("MobileOmniboxUse");
        RecordUserAction.record("MobileTabClobbered");
    } else {
        setUrlToPageUrl();
    }
    if (currentTab != null)
        currentTab.requestFocus();
    // Prevent any upcoming omnibox suggestions from showing. We have to do this after we load
    // the URL as this will hide the suggestions and trigger a cancel of the prerendered page.
    stopAutocomplete(true);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Example 2 with LoadUrlParams

use of org.chromium.content_public.browser.LoadUrlParams in project AndroidChromium by JackyAndroid.

the class EmbedContentViewActivity method finishNativeInitialization.

@Override
public void finishNativeInitialization() {
    super.finishNativeInitialization();
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
    final String titleRes = getIntent().getStringExtra(TITLE_INTENT_EXTRA);
    if (titleRes != null) {
        setTitle(titleRes);
    }
    final String urlRes = getIntent().getStringExtra(URL_INTENT_EXTRA);
    if (urlRes != null) {
        getActivityTab().loadUrl(new LoadUrlParams(urlRes, PageTransition.AUTO_TOPLEVEL));
    }
}
Also used : LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Example 3 with LoadUrlParams

use of org.chromium.content_public.browser.LoadUrlParams in project AndroidChromium by JackyAndroid.

the class ContextualSearchManager method openResolvedSearchUrlInNewTab.

@Override
public void openResolvedSearchUrlInNewTab() {
    if (mSearchRequest != null && mSearchRequest.getSearchUrlForPromotion() != null) {
        TabModelSelector tabModelSelector = mActivity.getTabModelSelector();
        tabModelSelector.openNewTab(new LoadUrlParams(mSearchRequest.getSearchUrlForPromotion()), TabLaunchType.FROM_LINK, tabModelSelector.getCurrentTab(), tabModelSelector.isIncognitoSelected());
    }
}
Also used : TabModelSelector(org.chromium.chrome.browser.tabmodel.TabModelSelector) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Example 4 with LoadUrlParams

use of org.chromium.content_public.browser.LoadUrlParams in project AndroidChromium by JackyAndroid.

the class ExternalNavigationDelegateImpl method loadIntent.

private void loadIntent(Intent intent, String referrerUrl, String fallbackUrl, Tab tab, boolean needsToCloseTab, boolean launchIncogntio) {
    boolean needsToStartIntent = false;
    if (tab == null || tab.isClosing() || !tab.isInitialized()) {
        needsToStartIntent = true;
        needsToCloseTab = false;
    } else if (needsToCloseTab) {
        needsToStartIntent = true;
    }
    String url = fallbackUrl != null ? fallbackUrl : intent.getDataString();
    if (!UrlUtilities.isAcceptedScheme(url)) {
        if (needsToCloseTab)
            closeTab(tab);
        return;
    }
    if (needsToStartIntent) {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
        if (launchIncogntio)
            intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setClassName(getPackageName(), ChromeLauncherActivity.class.getName());
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        IntentHandler.addTrustedIntentExtras(intent, mApplicationContext);
        startActivity(intent, false);
        if (needsToCloseTab)
            closeTab(tab);
        return;
    }
    LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTransition.AUTO_TOPLEVEL);
    if (!TextUtils.isEmpty(referrerUrl)) {
        Referrer referrer = new Referrer(referrerUrl, Referrer.REFERRER_POLICY_ALWAYS);
        loadUrlParams.setReferrer(referrer);
    }
    tab.loadUrl(loadUrlParams);
}
Also used : Referrer(org.chromium.content_public.common.Referrer) Intent(android.content.Intent) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) ChromeLauncherActivity(org.chromium.chrome.browser.document.ChromeLauncherActivity)

Example 5 with LoadUrlParams

use of org.chromium.content_public.browser.LoadUrlParams in project AndroidChromium by JackyAndroid.

the class TabPersistentStore method restoreTab.

private void restoreTab(TabRestoreDetails tabToRestore, TabState tabState, boolean setAsActive) {
    // If we don't have enough information about the Tab, bail out.
    boolean isIncognito = isIncognitoTabBeingRestored(tabToRestore, tabState);
    if (tabState == null) {
        if (tabToRestore.isIncognito == null) {
            Log.w(TAG, "Failed to restore tab: not enough info about its type was available.");
            return;
        } else if (isIncognito) {
            Log.i(TAG, "Failed to restore Incognito tab: its TabState could not be restored.");
            return;
        }
    }
    TabModel model = mTabModelSelector.getModel(isIncognito);
    SparseIntArray restoredTabs = isIncognito ? mIncognitoTabsRestored : mNormalTabsRestored;
    int restoredIndex = 0;
    if (tabToRestore.fromMerge) {
        // Put any tabs being merged into this list at the end.
        restoredIndex = mTabModelSelector.getModel(isIncognito).getCount();
    } else if (restoredTabs.size() > 0 && tabToRestore.originalIndex > restoredTabs.keyAt(restoredTabs.size() - 1)) {
        // If the tab's index is too large, restore it at the end of the list.
        restoredIndex = restoredTabs.size();
    } else {
        // Otherwise try to find the tab we should restore before, if any.
        for (int i = 0; i < restoredTabs.size(); i++) {
            if (restoredTabs.keyAt(i) > tabToRestore.originalIndex) {
                Tab nextTabByIndex = TabModelUtils.getTabById(model, restoredTabs.valueAt(i));
                restoredIndex = nextTabByIndex != null ? model.indexOf(nextTabByIndex) : -1;
                break;
            }
        }
    }
    int tabId = tabToRestore.id;
    if (tabState != null) {
        mTabCreatorManager.getTabCreator(isIncognito).createFrozenTab(tabState, tabToRestore.id, restoredIndex);
    } else {
        Log.w(TAG, "Failed to restore TabState; creating Tab with last known URL.");
        Tab fallbackTab = mTabCreatorManager.getTabCreator(isIncognito).createNewTab(new LoadUrlParams(tabToRestore.url), TabModel.TabLaunchType.FROM_RESTORE, null);
        tabId = fallbackTab.getId();
        model.moveTab(tabId, restoredIndex);
    }
    // was selected in the other model before the merge should be selected after the merge.
    if (setAsActive || (tabToRestore.fromMerge && restoredIndex == 0)) {
        boolean wasIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();
        int selectedModelTabCount = mTabModelSelector.getCurrentModel().getCount();
        TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, tabId));
        boolean isIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();
        // view on tablets).
        if (tabToRestore.fromMerge && wasIncognitoTabModelSelected != isIncognitoTabModelSelected && selectedModelTabCount != 0) {
            mTabModelSelector.selectModel(wasIncognitoTabModelSelected);
        }
    }
    restoredTabs.put(tabToRestore.originalIndex, tabId);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) SparseIntArray(android.util.SparseIntArray) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Aggregations

LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)39 Tab (org.chromium.chrome.browser.tab.Tab)9 Intent (android.content.Intent)6 Referrer (org.chromium.content_public.common.Referrer)5 TabDelegate (org.chromium.chrome.browser.tabmodel.document.TabDelegate)4 PendingIntent (android.app.PendingIntent)3 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)3 Context (android.content.Context)2 CustomTabsSessionToken (android.support.customtabs.CustomTabsSessionToken)2 AlertDialog (android.support.v7.app.AlertDialog)2 View (android.view.View)2 CalledByNative (org.chromium.base.annotations.CalledByNative)2 TabLaunchType (org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType)2 AsyncTabCreationParams (org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams)2 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 SparseIntArray (android.util.SparseIntArray)1 OnClickListener (android.view.View.OnClickListener)1