Chromium Code Reviews| Index: customtabs/src/android/support/customtabs/CustomTabsClient.java |
| diff --git a/customtabs/src/android/support/customtabs/CustomTabsClient.java b/customtabs/src/android/support/customtabs/CustomTabsClient.java |
| index f743c7dde92ee3f73648368dc239181506af09e7..d6973e3c2edefc2a9bfea3588106803f2f4e3b58 100644 |
| --- a/customtabs/src/android/support/customtabs/CustomTabsClient.java |
| +++ b/customtabs/src/android/support/customtabs/CustomTabsClient.java |
| @@ -24,6 +24,8 @@ import android.content.pm.PackageManager; |
| import android.content.pm.ResolveInfo; |
| import android.net.Uri; |
| import android.os.Bundle; |
| +import android.os.Handler; |
| +import android.os.Looper; |
| import android.os.RemoteException; |
| import android.support.annotation.Nullable; |
| import android.text.TextUtils; |
| @@ -173,21 +175,58 @@ public class CustomTabsClient { |
| * then later with a Custom Tab. The client can then send later service calls or intents to |
| * through same session-intent-Custom Tab association. |
| * @param callback The callback through which the client will receive updates about the created |
| - * session. Can be null. |
| + * session. Can be null. All the callbacks will be received on the UI thread. |
| * @return The session object that was created as a result of the transaction. The client can |
| - * use this to relay {@link CustomTabsSession#mayLaunchUrl(Uri, Bundle, List)} calls. |
| + * use this to relay session specific calls. |
| * Null on error. |
| */ |
| public CustomTabsSession newSession(final CustomTabsCallback callback) { |
| ICustomTabsCallback.Stub wrapper = new ICustomTabsCallback.Stub() { |
| + private Handler mHandler = new Handler(Looper.getMainLooper()); |
|
Benoit L
2016/11/09 10:11:00
nit: This can be made final as well.
Yusuf
2016/11/09 18:29:21
Done.
|
| + |
| + @Override |
| + public void onNavigationEvent(final int navigationEvent, final Bundle extras) { |
| + if (callback == null) return; |
| + mHandler.post(new Runnable() { |
| + @Override |
| + public void run() { |
| + callback.onNavigationEvent(navigationEvent, extras); |
| + } |
| + }); |
| + } |
| + |
| + @Override |
| + public void onMessageChannelReady(final Uri origin, final Bundle extras) { |
| + if (callback == null) return; |
| + mHandler.post(new Runnable() { |
| + @Override |
| + public void run() { |
| + callback.onMessageChannelReady(origin, extras); |
| + } |
| + }); |
| + } |
| + |
| @Override |
| - public void onNavigationEvent(int navigationEvent, Bundle extras) { |
| - if (callback != null) callback.onNavigationEvent(navigationEvent, extras); |
| + public void onPostMessage(final String message, final Bundle extras) { |
| + if (callback == null) return; |
| + mHandler.post(new Runnable() { |
| + @Override |
| + public void run() { |
| + callback.onPostMessage(message, extras); |
| + } |
| + }); |
| } |
| @Override |
| - public void extraCallback(String callbackName, Bundle args) throws RemoteException { |
| - if (callback != null) callback.extraCallback(callbackName, args); |
| + public void extraCallback(final String callbackName, final Bundle args) |
| + throws RemoteException { |
| + if (callback == null) return; |
| + mHandler.post(new Runnable() { |
| + @Override |
| + public void run() { |
| + callback.extraCallback(callbackName, args); |
| + } |
| + }); |
| } |
| }; |