Search in sources :

Example 1 with Referrer

use of org.chromium.content_public.common.Referrer in project AndroidChromium by JackyAndroid.

the class IntentHandler method addReferrerAndHeaders.

/**
     * Add referrer and extra headers to a {@link LoadUrlParams}, if we managed to parse them from
     * the intent.
     * @param params The {@link LoadUrlParams} to add referrer and headers.
     * @param intent The intent we use to parse the extras.
     */
public static void addReferrerAndHeaders(LoadUrlParams params, Intent intent, Context context) {
    String referrer = getReferrerUrlIncludingExtraHeaders(intent, context);
    if (referrer != null) {
        params.setReferrer(new Referrer(referrer, Referrer.REFERRER_POLICY_DEFAULT));
    }
    String headers = getExtraHeadersFromIntent(intent);
    if (headers != null)
        params.setVerbatimHeaders(headers);
}
Also used : Referrer(org.chromium.content_public.common.Referrer)

Example 2 with Referrer

use of org.chromium.content_public.common.Referrer in project AndroidChromium by JackyAndroid.

the class CustomTabActivity method createMainTab.

private Tab createMainTab() {
    CustomTabsConnection customTabsConnection = CustomTabsConnection.getInstance(getApplication());
    String url = getUrlToLoad();
    // Get any referrer that has been explicitly set by the app.
    String referrerUrl = IntentHandler.getReferrerUrlIncludingExtraHeaders(getIntent(), this);
    if (referrerUrl == null) {
        Referrer referrer = customTabsConnection.getReferrerForSession(mSession);
        if (referrer != null)
            referrerUrl = referrer.getUrl();
    }
    Tab tab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID), Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_EXTERNAL_APP, null, null);
    tab.setAppAssociatedWith(customTabsConnection.getClientPackageNameForSession(mSession));
    mPrerenderedUrl = customTabsConnection.getPrerenderedUrl(mSession);
    WebContents webContents = customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl);
    mHasPrerendered = webContents != null;
    if (!mHasPrerendered) {
        webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
    }
    if (webContents == null)
        webContents = WebContentsFactory.createWebContents(false, false);
    tab.initialize(webContents, getTabContentManager(), new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding(), mIntentDataProvider.isOpenedByChrome()), false, false);
    initializeMainTab(tab);
    return tab;
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) Tab(org.chromium.chrome.browser.tab.Tab) Referrer(org.chromium.content_public.common.Referrer)

Example 3 with Referrer

use of org.chromium.content_public.common.Referrer in project AndroidChromium by JackyAndroid.

the class DataUseTabUIManager method startDataUseDialog.

/**
     * Shows a dialog with the option to cancel the navigation or continue. Also allows the user to
     * opt out of seeing this dialog again.
     *
     * @param activity Current activity.
     * @param tab The tab loading the url.
     * @param url URL that is pending.
     * @param pageTransitionType The type of transition. see
     *            {@link org.chromium.content.browser.PageTransition} for valid values.
     * @param referrerUrl URL for the referrer.
     */
private static void startDataUseDialog(final Activity activity, final Tab tab, final String url, final int pageTransitionType, final String referrerUrl) {
    View dataUseDialogView = View.inflate(activity, R.layout.data_use_dialog, null);
    final TextView textView = (TextView) dataUseDialogView.findViewById(R.id.data_use_message);
    textView.setText(getDataUseUIString(DataUseUIMessage.DATA_USE_TRACKING_ENDED_MESSAGE));
    final CheckBox checkBox = (CheckBox) dataUseDialogView.findViewById(R.id.data_use_checkbox);
    checkBox.setText(getDataUseUIString(DataUseUIMessage.DATA_USE_TRACKING_ENDED_CHECKBOX_MESSAGE));
    View learnMore = dataUseDialogView.findViewById(R.id.learn_more);
    learnMore.setOnClickListener(new android.view.View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EmbedContentViewActivity.show(activity, getDataUseUIString(DataUseUIMessage.DATA_USE_LEARN_MORE_TITLE), getDataUseUIString(DataUseUIMessage.DATA_USE_LEARN_MORE_LINK_URL));
            recordDataUseUIAction(DataUsageUIAction.DIALOG_LEARN_MORE_CLICKED);
        }
    });
    new AlertDialog.Builder(activity, R.style.AlertDialogTheme).setTitle(getDataUseUIString(DataUseUIMessage.DATA_USE_TRACKING_ENDED_TITLE)).setView(dataUseDialogView).setPositiveButton(getDataUseUIString(DataUseUIMessage.DATA_USE_TRACKING_ENDED_CONTINUE), new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            setOptedOutOfDataUseDialog(activity, checkBox.isChecked());
            LoadUrlParams loadUrlParams = new LoadUrlParams(url, pageTransitionType);
            if (!TextUtils.isEmpty(referrerUrl)) {
                Referrer referrer = new Referrer(referrerUrl, Referrer.REFERRER_POLICY_ALWAYS);
                loadUrlParams.setReferrer(referrer);
            }
            tab.loadUrl(loadUrlParams);
            recordDataUseUIAction(DataUsageUIAction.DIALOG_CONTINUE_CLICKED);
            userClickedContinueOnDialogBox(tab);
        }
    }).setNegativeButton(R.string.cancel, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            setOptedOutOfDataUseDialog(activity, checkBox.isChecked());
            recordDataUseUIAction(DataUsageUIAction.DIALOG_CANCEL_CLICKED);
        }
    }).show();
    recordDataUseUIAction(DataUsageUIAction.DIALOG_SHOWN);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) TextView(android.widget.TextView) View(android.view.View) CheckBox(android.widget.CheckBox) Referrer(org.chromium.content_public.common.Referrer) OnClickListener(android.content.DialogInterface.OnClickListener) TextView(android.widget.TextView) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Example 4 with Referrer

use of org.chromium.content_public.common.Referrer 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 Referrer

use of org.chromium.content_public.common.Referrer 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)

Aggregations

Referrer (org.chromium.content_public.common.Referrer)7 LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)5 Intent (android.content.Intent)3 Tab (org.chromium.chrome.browser.tab.Tab)2 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Uri (android.net.Uri)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 CheckBox (android.widget.CheckBox)1 TextView (android.widget.TextView)1 CalledByNative (org.chromium.base.annotations.CalledByNative)1 ChromeLauncherActivity (org.chromium.chrome.browser.document.ChromeLauncherActivity)1 AsyncTabCreationParams (org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams)1 TabDelegate (org.chromium.chrome.browser.tabmodel.document.TabDelegate)1 WebappDataStorage (org.chromium.chrome.browser.webapps.WebappDataStorage)1 FetchWebappDataStorageCallback (org.chromium.chrome.browser.webapps.WebappRegistry.FetchWebappDataStorageCallback)1 WebContents (org.chromium.content_public.browser.WebContents)1