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.os.Bundle;
20
21/**
22 * A callback class for custom tabs client to get messages regarding events in their custom tabs. In
23 * the implementation, all callbacks are sent to the UI thread for the client.
24 */
25public class CustomTabsCallback {
26    /**
27     * Sent when the tab has started loading a page.
28     */
29    public static final int NAVIGATION_STARTED = 1;
30
31    /**
32     * Sent when the tab has finished loading a page.
33     */
34    public static final int NAVIGATION_FINISHED = 2;
35
36    /**
37     * Sent when the tab couldn't finish loading due to a failure.
38     */
39    public static final int NAVIGATION_FAILED = 3;
40
41    /**
42     * Sent when loading was aborted by a user action before it finishes like clicking on a link
43     * or refreshing the page.
44     */
45    public static final int NAVIGATION_ABORTED = 4;
46
47    /**
48     * Sent when the tab becomes visible.
49     */
50    public static final int TAB_SHOWN = 5;
51
52    /**
53     * Sent when the tab becomes hidden.
54     */
55    public static final int TAB_HIDDEN = 6;
56
57    /**
58     * To be called when a navigation event happens.
59     *
60     * @param navigationEvent The code corresponding to the navigation event.
61     * @param extras Reserved for future use.
62     */
63    public void onNavigationEvent(int navigationEvent, Bundle extras) {}
64
65    /**
66     * Unsupported callbacks that may be provided by the implementation.
67     *
68     * <p>
69     * <strong>Note:</strong>Clients should <strong>never</strong> rely on this callback to be
70     * called and/or to have a defined behavior, as it is entirely implementation-defined and not
71     * supported.
72     *
73     * <p> This can be used by implementations to add extra callbacks, for testing or experimental
74     * purposes.
75     *
76     * @param callbackName Name of the extra callback.
77     * @param args Arguments for the calback
78     */
79    public void extraCallback(String callbackName, Bundle args) {}
80
81    /**
82     * Called when {@link CustomTabsSession} has requested a postMessage channel through
83     * {@link CustomTabsService#requestPostMessageChannel(
84     * CustomTabsSessionToken, android.net.Uri)} and the channel
85     * is ready for sending and receiving messages on both ends.
86     *
87     * @param extras Reserved for future use.
88     */
89    public void onMessageChannelReady(Bundle extras) {}
90
91    /**
92     * Called when a tab controlled by this {@link CustomTabsSession} has sent a postMessage.
93     * If postMessage() is called from a single thread, then the messages will be posted in the
94     * same order. When received on the client side, it is the client's responsibility to preserve
95     * the ordering further.
96     *
97     * @param message The message sent.
98     * @param extras Reserved for future use.
99     */
100    public void onPostMessage(String message, Bundle extras) {}
101}
102