1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.support.customtabs; 18 19import android.content.ComponentName; 20import android.net.Uri; 21import android.os.Bundle; 22import android.os.IBinder; 23import android.os.RemoteException; 24 25import java.util.List; 26 27/** 28 * A class to be used for Custom Tabs related communication. Clients that want to launch Custom Tabs 29 * can use this class exclusively to handle all related communication. 30 */ 31public final class CustomTabsSession { 32 private static final String TAG = "CustomTabsSession"; 33 private final ICustomTabsService mService; 34 private final ICustomTabsCallback mCallback; 35 private final ComponentName mComponentName; 36 37 /* package */ CustomTabsSession( 38 ICustomTabsService service, ICustomTabsCallback callback, ComponentName componentName) { 39 mService = service; 40 mCallback = callback; 41 mComponentName = componentName; 42 } 43 44 /** 45 * Tells the browser of a likely future navigation to a URL. 46 * The most likely URL has to be specified first. Optionally, a list of 47 * other likely URLs can be provided. They are treated as less likely than 48 * the first one, and have to be sorted in decreasing priority order. These 49 * additional URLs may be ignored. 50 * All previous calls to this method will be deprioritized. 51 * 52 * @param url Most likely URL. 53 * @param extras Reserved for future use. 54 * @param otherLikelyBundles Other likely destinations, sorted in decreasing 55 * likelihood order. Inside each Bundle, the client should provide a 56 * {@link Uri} using {@link CustomTabsService#KEY_URL} with 57 * {@link Bundle#putParcelable(String, android.os.Parcelable)}. 58 * @return true for success. 59 */ 60 public boolean mayLaunchUrl(Uri url, Bundle extras, List<Bundle> otherLikelyBundles) { 61 try { 62 return mService.mayLaunchUrl(mCallback, url, extras, otherLikelyBundles); 63 } catch (RemoteException e) { 64 return false; 65 } 66 } 67 68 /* package */ IBinder getBinder() { 69 return mCallback.asBinder(); 70 } 71 72 /* package */ ComponentName getComponentName() { 73 return mComponentName; 74 } 75}