Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1488)

Unified Diff: customtabs/src/android/support/customtabs/CustomTabsSession.java

Issue 2438103002: Add postMessage APIs to the support lib (Closed)
Patch Set: Overridden callback in CustomTabsSessionToken Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e7a0a53f944a075700c7e5f89ddfe40eae3de4e6 100644
--- a/customtabs/src/android/support/customtabs/CustomTabsSession.java
+++ b/customtabs/src/android/support/customtabs/CustomTabsSession.java
@@ -150,6 +150,43 @@ public final class CustomTabsSession {
}
}
+ /**
+ * Sends a request to the implementation for validate and assign a postMessage origin for the
Benoit L 2016/11/07 17:50:38 nit: s/for/to/ ? (not a native speaker, so I'm not
Yusuf 2016/11/07 18:56:42 Done.
+ * 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)}. This method is syncronized
Benoit L 2016/11/07 17:50:38 nit: synchronized
Yusuf 2016/11/07 18:56:42 Done.
+ * to preserve the ordering of postMessage requests as they are going through the binder thread
Benoit L 2016/11/07 17:50:38 Also, I'm not sure that we need to explain why a g
Yusuf 2016/11/07 18:56:42 Done.
+ * pool. 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.
Benoit L 2016/11/07 17:50:38 ditto, @IntDef
Yusuf 2016/11/07 18:56:42 Done.
+ */
+ 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();
}

Powered by Google App Engine
This is Rietveld 408576698