/* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.support.customtabs; import android.content.ComponentName; import android.net.Uri; import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; import java.util.List; /** * A class to be used for Custom Tabs related communication. Clients that want to launch Custom Tabs * can use this class exclusively to handle all related communication. */ public final class CustomTabsSession { private static final String TAG = "CustomTabsSession"; private final ICustomTabsService mService; private final ICustomTabsCallback mCallback; private final ComponentName mComponentName; /* package */ CustomTabsSession( ICustomTabsService service, ICustomTabsCallback callback, ComponentName componentName) { mService = service; mCallback = callback; mComponentName = componentName; } /** * Tells the browser of a likely future navigation to a URL. * The most likely URL has to be specified first. Optionally, a list of * other likely URLs can be provided. They are treated as less likely than * the first one, and have to be sorted in decreasing priority order. These * additional URLs may be ignored. * All previous calls to this method will be deprioritized. * * @param url Most likely URL. * @param extras Reserved for future use. * @param otherLikelyBundles Other likely destinations, sorted in decreasing * likelihood order. Inside each Bundle, the client should provide a * {@link Uri} using {@link CustomTabsService#KEY_URL} with * {@link Bundle#putParcelable(String, android.os.Parcelable)}. * @return true for success. */ public boolean mayLaunchUrl(Uri url, Bundle extras, List<Bundle> otherLikelyBundles) { try { return mService.mayLaunchUrl(mCallback, url, extras, otherLikelyBundles); } catch (RemoteException e) { return false; } } /* package */ IBinder getBinder() { return mCallback.asBinder(); } /* package */ ComponentName getComponentName() { return mComponentName; } }