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() .
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: ClientManager.java From delion with Apache License 2.0 | 5 votes |
@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 File: ClientManager.java From AndroidChromium with Apache License 2.0 | 5 votes |
@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
Source File: CustomTabsConnection.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * 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 File: ClientManager.java From 365browser with Apache License 2.0 | 5 votes |
/** * @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 File: CustomTabsConnection.java From 365browser with Apache License 2.0 | 5 votes |
/** * 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 File: CustomTabsConnection.java From delion with Apache License 2.0 | 4 votes |
/** * 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
Source File: ManifestUpgradeDetector.java From AndroidChromium with Apache License 2.0 | 2 votes |
/** * 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 File: WebApkUpdateManager.java From 365browser with Apache License 2.0 | 2 votes |
/** * 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); }