Search in sources :

Example 11 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 12 with LoadUrlParams

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

the class ChromeTabCreator method launchUrlFromExternalApp.

/**
     * Opens the specified URL into a tab, potentially reusing a tab. Typically if a user opens
     * several link from the same application, we reuse the same tab so as to not open too many
     * tabs.
     * @param url the URL to open
     * @param referer The referer url if provided, null otherwise.
     * @param headers HTTP headers to send alongside the URL.
     * @param appId the ID of the application that triggered that URL navigation.
     * @param forceNewTab whether the URL should be opened in a new tab. If false, an existing tab
     *                    already opened by the same app will be reused.
     * @param intent the source of url if it isn't null.
     * @param intentTimestamp the time the intent was received.
     * @return the tab the URL was opened in, could be a new tab or a reused one.
     */
public Tab launchUrlFromExternalApp(String url, String referer, String headers, String appId, boolean forceNewTab, Intent intent, long intentTimestamp) {
    assert !mIncognito;
    boolean isLaunchedFromChrome = TextUtils.equals(appId, mActivity.getPackageName());
    // pages when he or she could be served a Data Reduction Proxy preview page.
    if (url != null)
        url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(url);
    if (forceNewTab && !isLaunchedFromChrome) {
        // We don't associate the tab with that app ID, as it is assumed that if the
        // application wanted to open this tab as a new tab, it probably does not want it
        // reused either.
        LoadUrlParams loadUrlParams = new LoadUrlParams(url);
        loadUrlParams.setIntentReceivedTimestamp(intentTimestamp);
        loadUrlParams.setVerbatimHeaders(headers);
        if (referer != null) {
            loadUrlParams.setReferrer(new Referrer(referer, Referrer.REFERRER_POLICY_DEFAULT));
        }
        return createNewTab(loadUrlParams, TabLaunchType.FROM_EXTERNAL_APP, null, intent);
    }
    if (appId == null) {
        // If we have no application ID, we use a made-up one so that these tabs can be
        // reused.
        appId = TabModelImpl.UNKNOWN_APP_ID;
    }
    // Let's try to find an existing tab that was started by that app.
    for (int i = 0; i < mTabModel.getCount(); i++) {
        Tab tab = mTabModel.getTabAt(i);
        if (appId.equals(tab.getAppAssociatedWith())) {
            // We don't reuse the tab, we create a new one at the same index instead.
            // Reusing a tab would require clearing the navigation history and clearing the
            // contents (we would not want the previous content to show).
            LoadUrlParams loadUrlParams = new LoadUrlParams(url);
            loadUrlParams.setIntentReceivedTimestamp(intentTimestamp);
            Tab newTab = createNewTab(loadUrlParams, TabLaunchType.FROM_EXTERNAL_APP, null, i, intent);
            newTab.setAppAssociatedWith(appId);
            mTabModel.closeTab(tab, false, false, false);
            return newTab;
        }
    }
    // No tab for that app, we'll have to create a new one.
    Tab tab = launchUrl(url, TabLaunchType.FROM_EXTERNAL_APP, intent, intentTimestamp);
    tab.setAppAssociatedWith(appId);
    return tab;
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) Referrer(org.chromium.content_public.common.Referrer) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Example 13 with LoadUrlParams

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

the class ChromeTabCreator method launchUrl.

/**
     * Creates a new tab and loads the specified URL in it. This is a convenience method for
     * {@link #createNewTab} with the default {@link LoadUrlParams} and no parent tab.
     *
     * @param url the URL to open.
     * @param type the type of action that triggered that launch. Determines how the tab is opened
     *             (for example, in the foreground or background).
     * @param intent the source of url if it isn't null.
     * @param intentTimestamp the time the intent was received.
     * @return the created tab.
     */
public Tab launchUrl(String url, TabModel.TabLaunchType type, Intent intent, long intentTimestamp) {
    LoadUrlParams loadUrlParams = new LoadUrlParams(url);
    loadUrlParams.setIntentReceivedTimestamp(intentTimestamp);
    return createNewTab(loadUrlParams, type, null, intent);
}
Also used : LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Example 14 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)

Example 15 with LoadUrlParams

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

the class TabContextMenuItemDelegate method onOpenInNewIncognitoTab.

@Override
public void onOpenInNewIncognitoTab(String url) {
    RecordUserAction.record("MobileNewTabOpened");
    mTab.getTabModelSelector().openNewTab(new LoadUrlParams(url), TabLaunchType.FROM_LONGPRESS_FOREGROUND, mTab, true);
}
Also used : LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Aggregations

LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)35 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 SharedPreferences (android.content.SharedPreferences)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 SparseIntArray (android.util.SparseIntArray)1