Chromium Code Reviews| 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..acf8f921807bdb14c71e8b84f20e75bd33f1a1eb 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,43 @@ 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. |
|
Benoit L
2017/01/25 21:25:03
nit: Perhaps specify where are these constants? (T
Yusuf
2017/01/25 22:02:00
The most viable way to refer to the enum was to re
|
| + */ |
| @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; |
| + } |
| } |
| } |