Java Code Examples for android.support.customtabs.CustomTabsSessionToken#equals()

The following examples show how to use android.support.customtabs.CustomTabsSessionToken#equals() . 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 File: CustomTabActivity.java    From 365browser with Apache License 2.0 7 votes vote down vote up
/**
 * Used to check whether an incoming intent can be handled by the
 * current {@link CustomTabContentHandler}.
 * @return Whether the active {@link CustomTabContentHandler} has handled the intent.
 */
public static boolean handleInActiveContentIfNeeded(Intent intent) {
    if (sActiveContentHandler == null) return false;

    if (sActiveContentHandler.shouldIgnoreIntent(intent)) {
        Log.w(TAG, "Incoming intent to Custom Tab was ignored.");
        return false;
    }

    CustomTabsSessionToken session = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
    if (session == null || !session.equals(sActiveContentHandler.getSession())) return false;

    String url = IntentHandler.getUrlFromIntent(intent);
    if (TextUtils.isEmpty(url)) return false;
    sActiveContentHandler.loadUrlAndTrackFromTimestamp(new LoadUrlParams(url),
            IntentHandler.getTimestampFromIntent(intent));
    return true;
}
 
Example 2
Source File: CustomTabActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Used to check whether an incoming intent can be handled by the
 * current {@link CustomTabContentHandler}.
 * @return Whether the active {@link CustomTabContentHandler} has handled the intent.
 */
public static boolean handleInActiveContentIfNeeded(Intent intent) {
    if (sActiveContentHandler == null) return false;

    if (sActiveContentHandler.shouldIgnoreIntent(intent)) {
        Log.w(TAG, "Incoming intent to Custom Tab was ignored.");
        return false;
    }

    CustomTabsSessionToken session = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
    if (session == null || !session.equals(sActiveContentHandler.getSession())) return false;

    String url = IntentHandler.getUrlFromIntent(intent);
    if (TextUtils.isEmpty(url)) return false;
    sActiveContentHandler.loadUrlAndTrackFromTimestamp(new LoadUrlParams(url),
            IntentHandler.getTimestampFromIntent(intent));
    return true;
}
 
Example 3
Source File: CustomTabActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Used to check whether an incoming intent can be handled by the
 * current {@link CustomTabContentHandler}.
 * @return Whether the active {@link CustomTabContentHandler} has handled the intent.
 */
public static boolean handleInActiveContentIfNeeded(Intent intent) {
    if (sActiveContentHandler == null) return false;

    if (sActiveContentHandler.shouldIgnoreIntent(intent)) {
        Log.w(TAG, "Incoming intent to Custom Tab was ignored.");
        return false;
    }

    CustomTabsSessionToken session = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
    if (session == null || !session.equals(sActiveContentHandler.getSession())) return false;

    String url = IntentHandler.getUrlFromIntent(intent);
    if (TextUtils.isEmpty(url)) return false;
    sActiveContentHandler.loadUrlAndTrackFromTimestamp(new LoadUrlParams(url),
            IntentHandler.getTimestampFromIntent(intent));
    return true;
}
 
Example 4
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** Cancels the speculation for a given session, or any session if null. */
void cancelSpeculation(CustomTabsSessionToken session) {
    ThreadUtils.assertOnUiThread();
    if (mSpeculation == null) return;
    if (session == null || session.equals(mSpeculation.session)) {
        switch (mSpeculation.speculationMode) {
            case SpeculationParams.PRERENDER:
                if (mSpeculation.webContents == null) return;
                mExternalPrerenderHandler.cancelCurrentPrerender();
                mSpeculation.webContents.destroy();
                break;
            case SpeculationParams.PREFETCH:
                Profile profile = Profile.getLastUsedProfile();
                new LoadingPredictor(profile).cancelPageLoadHint(mSpeculation.url);
                break;
            default:
                return;
        }
        mSpeculation = null;
    }
}
 
Example 5
Source File: CustomTabsConnection.java    From delion with Apache License 2.0 5 votes vote down vote up
/** Returns the URL prerendered for a session, or null. */
String getPrerenderedUrl(CustomTabsSessionToken session) {
    if (mPrerender == null || session == null || !session.equals(mPrerender.mSession)) {
        return null;
    }
    return mPrerender.mUrl;
}
 
Example 6
Source File: CustomTabsConnection.java    From delion with Apache License 2.0 5 votes vote down vote up
/** Cancels a prerender for a given session, or any session if null. */
void cancelPrerender(CustomTabsSessionToken session) {
    ThreadUtils.assertOnUiThread();
    if (mPrerender != null && (session == null || session.equals(mPrerender.mSession))) {
        mExternalPrerenderHandler.cancelCurrentPrerender();
        mPrerender.mWebContents.destroy();
        mPrerender = null;
    }
}
 
Example 7
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Transfers a prerendered WebContents if one exists.
 *
 * This resets the internal WebContents; a subsequent call to this method
 * returns null. Must be called from the UI thread.
 * If a prerender exists for a different URL with the same sessionId or with
 * a different referrer, then this is treated as a mispredict from the
 * client application, and cancels the previous prerender. This is done to
 * avoid keeping resources laying around for too long, but is subject to a
 * race condition, as the following scenario is possible:
 * The application calls:
 * 1. mayLaunchUrl(url1) <- IPC
 * 2. loadUrl(url2) <- Intent
 * 3. mayLaunchUrl(url3) <- IPC
 * If the IPC for url3 arrives before the intent for url2, then this methods
 * cancels the prerender for url3, which is unexpected. On the other
 * hand, not cancelling the previous prerender leads to wasted resources, as
 * a WebContents is lingering. This can be solved by requiring applications
 * to call mayLaunchUrl(null) to cancel a current prerender before 2, that
 * is for a mispredict.
 *
 * Note that this methods accepts URLs that don't exactly match the initially
 * prerendered URL. More precisely, the #fragment is ignored. In this case,
 * the client needs to navigate to the correct URL after the WebContents
 * swap. This can be tested using {@link UrlUtilities#urlsFragmentsDiffer()}.
 *
 * @param session The Binder object identifying a session.
 * @param url The URL the WebContents is for.
 * @param referrer The referrer to use for |url|.
 * @return The prerendered WebContents, or null.
 */
WebContents takePrerenderedUrl(CustomTabsSessionToken session, String url, String referrer) {
    ThreadUtils.assertOnUiThread();
    if (mSpeculation == null || session == null || !session.equals(mSpeculation.session)) {
        return null;
    }

    if (mSpeculation.prefetchOnly) {
        Profile profile = Profile.getLastUsedProfile();
        new ResourcePrefetchPredictor(profile).stopPrefetching(mSpeculation.url);
        mSpeculation = null;
        return null;
    }

    WebContents webContents = mSpeculation.webContents;
    String prerenderedUrl = mSpeculation.url;
    String prerenderReferrer = mSpeculation.referrer;
    if (referrer == null) referrer = "";
    boolean ignoreFragments = mClientManager.getIgnoreFragmentsForSession(session);
    boolean urlsMatch = TextUtils.equals(prerenderedUrl, url)
            || (ignoreFragments
                    && UrlUtilities.urlsMatchIgnoringFragments(prerenderedUrl, url));
    WebContents result = null;
    if (urlsMatch && TextUtils.equals(prerenderReferrer, referrer)) {
        result = webContents;
        mSpeculation = null;
    } else {
        cancelPrerender(session);
    }
    if (!mClientManager.usesDefaultSessionParameters(session) && webContents != null) {
        RecordHistogram.recordBooleanHistogram(
                "CustomTabs.NonDefaultSessionPrerenderMatched", result != null);
    }

    return result;
}
 
Example 8
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Returns the URL prerendered for a session, or null. */
String getPrerenderedUrl(CustomTabsSessionToken session) {
    if (mSpeculation == null || session == null || !session.equals(mSpeculation.session)) {
        return null;
    }
    return mSpeculation.webContents != null ? mSpeculation.url : null;
}
 
Example 9
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Cancels a prerender for a given session, or any session if null. */
void cancelPrerender(CustomTabsSessionToken session) {
    ThreadUtils.assertOnUiThread();
    if (mSpeculation != null && (session == null || session.equals(mSpeculation.session))
            && mSpeculation.webContents != null) {
        mExternalPrerenderHandler.cancelCurrentPrerender();
        mSpeculation.webContents.destroy();
        mSpeculation = null;
    }
}
 
Example 10
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Transfers a prerendered WebContents if one exists.
 *
 * This resets the internal WebContents; a subsequent call to this method
 * returns null. Must be called from the UI thread.
 * If a prerender exists for a different URL with the same sessionId or with
 * a different referrer, then this is treated as a mispredict from the
 * client application, and cancels the previous prerender. This is done to
 * avoid keeping resources laying around for too long, but is subject to a
 * race condition, as the following scenario is possible:
 * The application calls:
 * 1. mayLaunchUrl(url1) <- IPC
 * 2. loadUrl(url2) <- Intent
 * 3. mayLaunchUrl(url3) <- IPC
 * If the IPC for url3 arrives before the intent for url2, then this methods
 * cancels the prerender for url3, which is unexpected. On the other
 * hand, not cancelling the previous prerender leads to wasted resources, as
 * a WebContents is lingering. This can be solved by requiring applications
 * to call mayLaunchUrl(null) to cancel a current prerender before 2, that
 * is for a mispredict.
 *
 * Note that this methods accepts URLs that don't exactly match the initially
 * prerendered URL. More precisely, the #fragment is ignored. In this case,
 * the client needs to navigate to the correct URL after the WebContents
 * swap. This can be tested using {@link UrlUtilities#urlsFragmentsDiffer()}.
 *
 * @param session The Binder object identifying a session.
 * @param url The URL the WebContents is for.
 * @param referrer The referrer to use for |url|.
 * @return The prerendered WebContents, or null.
 */
WebContents takePrerenderedUrl(CustomTabsSessionToken session, String url, String referrer) {
    ThreadUtils.assertOnUiThread();
    if (mSpeculation == null || session == null || !session.equals(mSpeculation.session)) {
        return null;
    }

    if (mSpeculation.speculationMode == SpeculationParams.PREFETCH) {
        cancelSpeculation(session);
        return null;
    }

    WebContents webContents = mSpeculation.webContents;
    String prerenderedUrl = mSpeculation.url;
    String prerenderReferrer = mSpeculation.referrer;
    if (referrer == null) referrer = "";
    boolean ignoreFragments = mClientManager.getIgnoreFragmentsForSession(session);
    boolean urlsMatch = TextUtils.equals(prerenderedUrl, url)
            || (ignoreFragments
                    && UrlUtilities.urlsMatchIgnoringFragments(prerenderedUrl, url));
    WebContents result = null;
    if (urlsMatch && TextUtils.equals(prerenderReferrer, referrer)) {
        result = webContents;
        mSpeculation = null;
    } else {
        cancelSpeculation(session);
    }
    if (!mClientManager.usesDefaultSessionParameters(session) && webContents != null) {
        RecordHistogram.recordBooleanHistogram(
                "CustomTabs.NonDefaultSessionPrerenderMatched", result != null);
    }

    return result;
}
 
Example 11
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
String getSpeculatedUrl(CustomTabsSessionToken session) {
    if (mSpeculation == null || session == null || !session.equals(mSpeculation.session)) {
        return null;
    }
    switch (mSpeculation.speculationMode) {
        case SpeculationParams.PRERENDER:
            return mSpeculation.webContents != null ? mSpeculation.url : null;
        case SpeculationParams.HIDDEN_TAB:
            return mSpeculation.tab != null ? mSpeculation.url : null;
        default:
            return null;
    }
}
 
Example 12
Source File: CustomTabsConnection.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Transfers a prerendered WebContents if one exists.
 *
 * This resets the internal WebContents; a subsequent call to this method
 * returns null. Must be called from the UI thread.
 * If a prerender exists for a different URL with the same sessionId or with
 * a different referrer, then this is treated as a mispredict from the
 * client application, and cancels the previous prerender. This is done to
 * avoid keeping resources laying around for too long, but is subject to a
 * race condition, as the following scenario is possible:
 * The application calls:
 * 1. mayLaunchUrl(url1) <- IPC
 * 2. loadUrl(url2) <- Intent
 * 3. mayLaunchUrl(url3) <- IPC
 * If the IPC for url3 arrives before the intent for url2, then this methods
 * cancels the prerender for url3, which is unexpected. On the other
 * hand, not cancelling the previous prerender leads to wasted resources, as
 * a WebContents is lingering. This can be solved by requiring applications
 * to call mayLaunchUrl(null) to cancel a current prerender before 2, that
 * is for a mispredict.
 *
 * Note that this methods accepts URLs that don't exactly match the initially
 * prerendered URL. More precisely, the #fragment is ignored. In this case,
 * the client needs to navigate to the correct URL after the WebContents
 * swap. This can be tested using {@link UrlUtilities#urlsFragmentsDiffer()}.
 *
 * @param session The Binder object identifying a session.
 * @param url The URL the WebContents is for.
 * @param referrer The referrer to use for |url|.
 * @return The prerendered WebContents, or null.
 */
WebContents takePrerenderedUrl(CustomTabsSessionToken session, String url, String referrer) {
    ThreadUtils.assertOnUiThread();
    if (mPrerender == null || session == null || !session.equals(mPrerender.mSession)) {
        return null;
    }
    WebContents webContents = mPrerender.mWebContents;
    String prerenderedUrl = mPrerender.mUrl;
    String prerenderReferrer = mPrerender.mReferrer;
    if (referrer == null) referrer = "";
    boolean ignoreFragments = mClientManager.getIgnoreFragmentsForSession(session);
    boolean urlsMatch = TextUtils.equals(prerenderedUrl, url)
            || (ignoreFragments
                    && UrlUtilities.urlsMatchIgnoringFragments(prerenderedUrl, url));
    if (urlsMatch && TextUtils.equals(prerenderReferrer, referrer)) {
        mPrerender = null;
        return webContents;
    } else {
        cancelPrerender(session);
    }
    return null;
}