| 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 8157733298b700d7a0cb65e82d6884b2159460bb..aba737e97c19bd2e77b6241efbdd882a37dd2c8d 100644
|
| --- a/customtabs/src/android/support/customtabs/CustomTabsSession.java
|
| +++ b/customtabs/src/android/support/customtabs/CustomTabsSession.java
|
| @@ -36,6 +36,7 @@ import java.util.List;
|
| */
|
| public final class CustomTabsSession {
|
| private static final String TAG = "CustomTabsSession";
|
| + private final Object mLock = new Object();
|
| private final ICustomTabsService mService;
|
| private final ICustomTabsCallback mCallback;
|
| private final ComponentName mComponentName;
|
| @@ -151,20 +152,44 @@ public final class CustomTabsSession {
|
| }
|
| }
|
|
|
| - public boolean validatePostMessageOrigin() {
|
| + /**
|
| + * Sends a request to create a two way postMessage channel between the client and the browser.
|
| + *
|
| + * @param postMessageOrigin A origin that the client is requesting to be identified as
|
| + * during the postMessage communication.
|
| + * @return Whether the implementation accepted the request. Note that returning true
|
| + * here doesn't mean an origin has already been assigned as the validation is
|
| + * asynchronous.
|
| + */
|
| + public boolean requestPostMessageChannel(Uri postMessageOrigin) {
|
| try {
|
| - return mService.validatePostMessageOrigin(mCallback);
|
| + return mService.requestPostMessageChannel(
|
| + mCallback, postMessageOrigin);
|
| } catch (RemoteException e) {
|
| return false;
|
| }
|
| }
|
|
|
| + /**
|
| + * Sends a postMessage request using the origin communicated via
|
| + * {@link CustomTabsService#requestPostMessageChannel(
|
| + * CustomTabsSessionToken, Uri)}. Fails when called before
|
| + * {@link PostMessageServiceConnection#notifyMessageChannelReady(Bundle)} is received on
|
| + * the client side.
|
| + *
|
| + * @param message The message that is being sent.
|
| + * @param extras Reserved for future use.
|
| + * @return An integer constant about the postMessage request result. Will return
|
| + * {@link CustomTabsService#RESULT_SUCCESS} if successful.
|
| + */
|
| @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;
|
| + public int postMessage(String message, Bundle extras) {
|
| + synchronized (mLock) {
|
| + try {
|
| + return mService.postMessage(mCallback, message, extras);
|
| + } catch (RemoteException e) {
|
| + return CustomTabsService.RESULT_FAILURE_REMOTE_ERROR;
|
| + }
|
| }
|
| }
|
|
|
|
|