| Index: customtabs/src/android/support/customtabs/CustomTabsSession.java
|
| diff --git a/customtabs/src/android/support/customtabs/CustomTabsSession.java b/customtabs/src/android/support/customtabs/CustomTabsSession.java
|
| index 290150db1837a46d9a91c9aae52396cbafaf3cf7..fe02bcc7b3c14faaca9b32de622b4baa2a40fcdd 100644
|
| --- a/customtabs/src/android/support/customtabs/CustomTabsSession.java
|
| +++ b/customtabs/src/android/support/customtabs/CustomTabsSession.java
|
| @@ -24,6 +24,7 @@ import android.os.Bundle;
|
| import android.os.IBinder;
|
| import android.os.RemoteException;
|
| import android.support.annotation.NonNull;
|
| +import android.support.customtabs.CustomTabsService.Result;
|
| import android.support.customtabs.CustomTabsSessionToken.DummyCallback;
|
| import android.widget.RemoteViews;
|
|
|
| @@ -150,6 +151,44 @@ public final class CustomTabsSession {
|
| }
|
| }
|
|
|
| + /**
|
| + * Sends a request to the implementation to validate and assign a postMessage origin for the
|
| + * related {@link CustomTabsSession}.
|
| + *
|
| + * <p>This also acts a trigger to setup a postMessage communication channel.
|
| + *
|
| + * @return Whether the implementation accepted the validation request. Note that returning true
|
| + * here doesn't mean an origin has already been assigned as the validation can be
|
| + * asynchronous.
|
| + */
|
| + public boolean validatePostMessageOrigin() {
|
| + try {
|
| + return mService.validatePostMessageOrigin(mCallback);
|
| + } catch (RemoteException e) {
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Sends a postMessage request using the origin that has been validated and communicated via
|
| + * {@link CustomTabsCallback#onMessageChannelReady(Uri, Bundle)}. If postMessage() is called
|
| + * from a single thread, then the messages will be posted in the same order to the web page.
|
| + * Returns false when called without a preceding
|
| + * {@link CustomTabsService#validatePostMessageOrigin(CustomTabsSessionToken)}.
|
| + *
|
| + * @param message The message that is being sent.
|
| + * @param extras Reserved for future use.
|
| + * @return An integer constant about the postMessage request result.
|
| + */
|
| + @Result
|
| + public synchronized int postMessage(String message, Bundle extras) {
|
| + try {
|
| + return mService.postMessage(mCallback, message, extras);
|
| + } catch (RemoteException e) {
|
| + return CustomTabsService.RESULT_FAILURE_REMOTE_ERROR;
|
| + }
|
| + }
|
| +
|
| /* package */ IBinder getBinder() {
|
| return mCallback.asBinder();
|
| }
|
|
|