本文整理汇总了Java中android.support.customtabs.CustomTabsSessionToken类的典型用法代码示例。如果您正苦于以下问题:Java CustomTabsSessionToken类的具体用法?Java CustomTabsSessionToken怎么用?Java CustomTabsSessionToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CustomTabsSessionToken类属于android.support.customtabs包,在下文中一共展示了CustomTabsSessionToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWarmupState
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
@VisibleForTesting
synchronized int getWarmupState(CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session);
boolean hasValidSession = params != null;
boolean hasUidCalledWarmup = hasValidSession && mUidHasCalledWarmup.get(params.uid);
int result = mWarmupHasBeenCalled ? NO_SESSION_WARMUP : NO_SESSION_NO_WARMUP;
if (hasValidSession) {
if (hasUidCalledWarmup) {
result = SESSION_WARMUP;
} else {
result = mWarmupHasBeenCalled ? SESSION_NO_WARMUP_ALREADY_CALLED
: SESSION_NO_WARMUP_NOT_CALLED;
}
}
return result;
}
示例2: registerLaunch
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
/**
* Registers that a client has launched a URL inside a Custom Tab.
*/
public synchronized void registerLaunch(CustomTabsSessionToken session, String url) {
int outcome = getPredictionOutcome(session, url);
RecordHistogram.recordEnumeratedHistogram(
"CustomTabs.PredictionStatus", outcome, PREDICTION_STATUS_COUNT);
SessionParams params = mSessionParams.get(session);
if (outcome == GOOD_PREDICTION) {
long elapsedTimeMs = SystemClock.elapsedRealtime()
- params.getLastMayLaunchUrlTimestamp();
RequestThrottler.getForUid(mContext, params.uid).registerSuccess(
params.mPredictedUrl);
RecordHistogram.recordCustomTimesHistogram("CustomTabs.PredictionToLaunch",
elapsedTimeMs, 1, TimeUnit.MINUTES.toMillis(3), TimeUnit.MILLISECONDS, 100);
}
RecordHistogram.recordEnumeratedHistogram(
"CustomTabs.WarmupStateOnLaunch", getWarmupState(session), SESSION_WARMUP_COUNT);
if (params != null) params.setPredictionMetrics(null, 0);
}
示例3: CustomTabObserver
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
public CustomTabObserver(
Application application, CustomTabsSessionToken session, boolean openedByChrome) {
if (openedByChrome) {
mCustomTabsConnection = null;
} else {
mCustomTabsConnection = CustomTabsConnection.getInstance(application);
}
mSession = session;
if (!openedByChrome && mCustomTabsConnection.shouldSendNavigationInfoForSession(mSession)) {
float desiredWidth = application.getResources().getDimensionPixelSize(
R.dimen.custom_tabs_screenshot_width);
float desiredHeight = application.getResources().getDimensionPixelSize(
R.dimen.custom_tabs_screenshot_height);
Rect bounds = ExternalPrerenderHandler.estimateContentSize(application, false);
mScaleForNavigationInfo = (bounds.width() == 0 || bounds.height() == 0) ? 1f :
Math.min(desiredWidth / bounds.width(), desiredHeight / bounds.height());
}
mOpenedByChrome = openedByChrome;
resetPageLoadTracking();
}
示例4: validatePostMessageOriginInternal
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
private boolean validatePostMessageOriginInternal(final CustomTabsSessionToken session) {
if (!mWarmupHasBeenCalled.get()) return false;
if (!isCallerForegroundOrSelf()) return false;
final int uid = Binder.getCallingUid();
ThreadUtils.postOnUiThread(new Runnable() {
@Override
public void run() {
// If the API is not enabled, we don't set the post message origin, which will
// avoid PostMessageHandler initialization and disallow postMessage calls.
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_POST_MESSAGE_API)) return;
mClientManager.setPostMessageOriginForSession(
session, acquireOriginForSession(session, uid));
}
});
return true;
}
示例5: handleInActiveContentIfNeeded
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
/**
* 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;
}
示例6: registerLaunch
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
/**
* Registers that a client has launched a URL inside a Custom Tab.
*/
public synchronized void registerLaunch(CustomTabsSessionToken session, String url) {
int outcome = getPredictionOutcome(session, url);
RecordHistogram.recordEnumeratedHistogram(
"CustomTabs.PredictionStatus", outcome, PREDICTION_STATUS_COUNT);
SessionParams params = mSessionParams.get(session);
if (outcome == GOOD_PREDICTION) {
long elapsedTimeMs = SystemClock.elapsedRealtime()
- params.getLastMayLaunchUrlTimestamp();
RequestThrottler.getForUid(mContext, params.uid).registerSuccess(
params.mPredictedUrl);
RecordHistogram.recordCustomTimesHistogram("CustomTabs.PredictionToLaunch",
elapsedTimeMs, 1, TimeUnit.MINUTES.toMillis(3), TimeUnit.MILLISECONDS, 100);
}
RecordHistogram.recordEnumeratedHistogram(
"CustomTabs.WarmupStateOnLaunch", getWarmupState(session), SESSION_WARMUP_COUNT);
if (params == null) return;
int value = (params.lowConfidencePrediction ? LOW_CONFIDENCE : 0)
+ (params.highConfidencePrediction ? HIGH_CONFIDENCE : 0);
RecordHistogram.recordEnumeratedHistogram(
"CustomTabs.MayLaunchUrlType", value, MAY_LAUNCH_URL_TYPE_COUNT);
params.resetPredictionMetrics();
}
示例7: keepAliveForSession
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
/** Tries to bind to a client to keep it alive, and returns true for success. */
public synchronized boolean keepAliveForSession(CustomTabsSessionToken session, Intent intent) {
// When an application is bound to a service, its priority is raised to
// be at least equal to the application's one. This binds to a dummy
// service (no calls to this service are made).
if (intent == null || intent.getComponent() == null) return false;
SessionParams params = mSessionParams.get(session);
if (params == null) return false;
KeepAliveServiceConnection connection = params.getKeepAliveConnection();
if (connection == null) {
String packageName = intent.getComponent().getPackageName();
PackageManager pm = mContext.getApplicationContext().getPackageManager();
// Only binds to the application associated to this session.
if (!Arrays.asList(pm.getPackagesForUid(params.uid)).contains(packageName)) {
return false;
}
Intent serviceIntent = new Intent().setComponent(intent.getComponent());
connection = new KeepAliveServiceConnection(mContext, serviceIntent);
}
boolean ok = connection.connect();
if (ok) params.setKeepAliveConnection(connection);
return ok;
}
示例8: highConfidenceMayLaunchUrl
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
/**
* High confidence mayLaunchUrl() call, that is:
* - Tries to prerender if possible.
* - An empty URL cancels the current prerender if any.
* - If prerendering is not possible, makes sure that there is a spare renderer.
*/
private void highConfidenceMayLaunchUrl(CustomTabsSessionToken session,
int uid, String url, Bundle extras, List<Bundle> otherLikelyBundles) {
ThreadUtils.assertOnUiThread();
if (TextUtils.isEmpty(url)) {
cancelSpeculation(session);
return;
}
url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(url);
int debugOverrideValue = NO_OVERRIDE;
if (extras != null) debugOverrideValue = extras.getInt(DEBUG_OVERRIDE_KEY, NO_OVERRIDE);
int speculationMode = getSpeculationMode(session, debugOverrideValue);
if (maySpeculate(session)) startSpeculation(session, url, speculationMode, extras, uid);
preconnectUrls(otherLikelyBundles);
}
示例9: notifyPageLoadMetric
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
/**
* Notifies the application of a page load metric.
*
* TODD(lizeb): Move this to a proper method in {@link CustomTabsCallback} once one is
* available.
*
* @param session Session identifier.
* @param metricName Name of the page load metric.
* @param navigationStartTick Absolute navigation start time, as TimeTicks taken from native.
*
* @param offsetMs Offset in ms from navigationStart.
*/
boolean notifyPageLoadMetric(CustomTabsSessionToken session, String metricName,
long navigationStartTick, long offsetMs) {
CustomTabsCallback callback = mClientManager.getCallbackForSession(session);
if (callback == null) return false;
if (!mNativeTickOffsetUsComputed) {
// Compute offset from time ticks to uptimeMillis.
mNativeTickOffsetUsComputed = true;
long nativeNowUs = TimeUtils.nativeGetTimeTicksNowUs();
long javaNowUs = SystemClock.uptimeMillis() * 1000;
mNativeTickOffsetUs = nativeNowUs - javaNowUs;
}
Bundle args = new Bundle();
args.putLong(PageLoadMetrics.NAVIGATION_START,
(navigationStartTick - mNativeTickOffsetUs) / 1000);
args.putLong(metricName, offsetMs);
try {
callback.extraCallback(PAGE_LOAD_METRICS_CALLBACK, args);
} catch (Exception e) {
// Pokemon exception handling, see above and crbug.com/517023.
return false;
}
return true;
}
示例10: cancelSpeculation
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
/** 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;
}
}
示例11: newSession
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
/** Creates a new session.
*
* @param session Session provided by the client.
* @param uid Client UID, as returned by Binder.getCallingUid(),
* @param onDisconnect To be called on the UI thread when a client gets disconnected.
* @param postMessageHandler The handler to be used for postMessage related operations.
* @return true for success.
*/
public boolean newSession(CustomTabsSessionToken session, int uid,
DisconnectCallback onDisconnect, PostMessageHandler postMessageHandler) {
if (session == null) return false;
SessionParams params = new SessionParams(mContext, uid, onDisconnect, postMessageHandler);
synchronized (this) {
if (mSessionParams.containsKey(session)) return false;
mSessionParams.put(session, params);
}
return true;
}
示例12: updateStatsAndReturnWhetherAllowed
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
/** Updates the client behavior stats and returns whether speculation is allowed.
*
* @param session Client session.
* @param uid As returned by Binder.getCallingUid().
* @param url Predicted URL.
* @return true if speculation is allowed.
*/
public synchronized boolean updateStatsAndReturnWhetherAllowed(
CustomTabsSessionToken session, int uid, String url) {
SessionParams params = mSessionParams.get(session);
if (params == null || params.uid != uid) return false;
params.setPredictionMetrics(url, SystemClock.elapsedRealtime());
RequestThrottler throttler = RequestThrottler.getForUid(mContext, uid);
return throttler.updateStatsAndReturnWhetherAllowed();
}
示例13: getPredictionOutcome
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
@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;
}
示例14: setPostMessageOriginForSession
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
/**
* See {@link PostMessageHandler#setPostMessageOrigin(Uri)}.
*/
public synchronized void setPostMessageOriginForSession(
CustomTabsSessionToken session, Uri origin) {
SessionParams params = mSessionParams.get(session);
if (params == null) return;
params.postMessageHandler.setPostMessageOrigin(origin);
}
示例15: resetPostMessageHandlerForSession
import android.support.customtabs.CustomTabsSessionToken; //导入依赖的package包/类
/**
* See {@link PostMessageHandler#reset(WebContents)}.
*/
public synchronized void resetPostMessageHandlerForSession(
CustomTabsSessionToken session, WebContents webContents) {
SessionParams params = mSessionParams.get(session);
if (params == null) return;
params.postMessageHandler.reset(webContents);
}