Java Code Examples for org.chromium.chrome.browser.util.UrlUtilities#urlsMatchIgnoringFragments()

The following examples show how to use org.chromium.chrome.browser.util.UrlUtilities#urlsMatchIgnoringFragments() . These examples are extracted from open source projects. 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 Project: delion   File: ClientManager.java    License: Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
synchronized int getPredictionOutcome(CustomTabsSessionToken session, String url) {
    SessionParams params = mSessionParams.get(session);
    if (params == null) return NO_PREDICTION;

    String predictedUrl = params.getPredictedUrl();
    if (predictedUrl == null) return NO_PREDICTION;

    boolean urlsMatch = TextUtils.equals(predictedUrl, url)
            || (params.mIgnoreFragments
                    && UrlUtilities.urlsMatchIgnoringFragments(predictedUrl, url));
    return urlsMatch ? GOOD_PREDICTION : BAD_PREDICTION;
}
 
Example 2
Source Project: AndroidChromium   File: ClientManager.java    License: Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
synchronized int getPredictionOutcome(CustomTabsSessionToken session, String url) {
    SessionParams params = mSessionParams.get(session);
    if (params == null) return NO_PREDICTION;

    String predictedUrl = params.getPredictedUrl();
    if (predictedUrl == null) return NO_PREDICTION;

    boolean urlsMatch = TextUtils.equals(predictedUrl, url)
            || (params.mIgnoreFragments
                    && UrlUtilities.urlsMatchIgnoringFragments(predictedUrl, url));
    return urlsMatch ? GOOD_PREDICTION : BAD_PREDICTION;
}
 
Example 3
/**
 * 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 4
Source Project: 365browser   File: ClientManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return the prediction outcome. NO_PREDICTION if mSessionParams.get(session) returns null.
 */
@VisibleForTesting
synchronized int getPredictionOutcome(CustomTabsSessionToken session, String url) {
    SessionParams params = mSessionParams.get(session);
    if (params == null) return NO_PREDICTION;

    String predictedUrl = params.getPredictedUrl();
    if (predictedUrl == null) return NO_PREDICTION;

    boolean urlsMatch = TextUtils.equals(predictedUrl, url)
            || (params.mIgnoreFragments
                    && UrlUtilities.urlsMatchIgnoringFragments(predictedUrl, url));
    return urlsMatch ? GOOD_PREDICTION : BAD_PREDICTION;
}
 
Example 5
Source Project: 365browser   File: CustomTabsConnection.java    License: 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 6
Source Project: delion   File: CustomTabsConnection.java    License: 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;
}
 
Example 7
/**
 * Returns whether the urls match ignoring fragments. Canonicalizes the URLs prior to doing the
 * comparison.
 */
protected boolean urlsMatchIgnoringFragments(String url1, String url2) {
    return UrlUtilities.urlsMatchIgnoringFragments(url1, url2);
}
 
Example 8
Source Project: 365browser   File: WebApkUpdateManager.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the urls match ignoring fragments. Canonicalizes the URLs prior to doing the
 * comparison.
 */
protected boolean urlsMatchIgnoringFragments(String url1, String url2) {
    return UrlUtilities.urlsMatchIgnoringFragments(url1, url2);
}