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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/PostMessageHandler.java

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Eliminate unnecessary PostTask Created 3 years, 10 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: chrome/android/java/src/org/chromium/chrome/browser/customtabs/PostMessageHandler.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/PostMessageHandler.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/PostMessageHandler.java
index 8c3437c24c9494a488e00d351a499214e4933db3..3a5f28e4c62202c7698e9e63313779aa73ba3be4 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/PostMessageHandler.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/PostMessageHandler.java
@@ -14,10 +14,6 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.content.browser.AppWebMessagePort;
-import org.chromium.content.browser.AppWebMessagePortService;
-import org.chromium.content.browser.AppWebMessagePortService.MessageChannelObserver;
-import org.chromium.content.browser.PostMessageSender;
-import org.chromium.content.browser.PostMessageSender.PostMessageSenderDelegate;
import org.chromium.content_public.browser.MessagePort;
import org.chromium.content_public.browser.MessagePort.MessageCallback;
import org.chromium.content_public.browser.WebContents;
@@ -27,22 +23,13 @@ import org.chromium.content_public.browser.WebContentsObserver;
* A class that handles postMessage communications with a designated {@link CustomTabsSessionToken}.
*/
public class PostMessageHandler extends PostMessageServiceConnection {
- private static AppWebMessagePortService sService;
-
private final MessageCallback mMessageCallback;
private WebContents mWebContents;
private boolean mMessageChannelCreated;
private boolean mBoundToService;
private AppWebMessagePort[] mChannel;
- private PostMessageSender mPostMessageSender;
- private PostMessageSenderDelegate mSenderDelegate;
private Uri mOrigin;
- private static AppWebMessagePortService getAppWebMessagePortService() {
- if (sService == null) sService = new AppWebMessagePortService();
- return sService;
- }
-
/**
* Basic constructor. Everytime the given {@link CustomTabsSessionToken} is associated with a
* new {@link WebContents},
@@ -109,52 +96,20 @@ public class PostMessageHandler extends PostMessageServiceConnection {
}
private void initializeWithWebContents(final WebContents webContents) {
- final AppWebMessagePortService service = getAppWebMessagePortService();
- mChannel = (AppWebMessagePort[]) webContents.createMessageChannel(service);
+ mChannel = (AppWebMessagePort[]) webContents.createMessageChannel();
mChannel[0].setMessageCallback(mMessageCallback, null);
- mSenderDelegate = new PostMessageSenderDelegate() {
- @Override
- public void postMessageToWeb(
- String frameName, String message, String targetOrigin,
- int[] sentPortIds) {
- if (webContents.isDestroyed()) {
- disconnectChannel();
- unbindFromContext(ContextUtils.getApplicationContext());
- return;
- }
- webContents.postMessageToFrame(
- frameName, message, mOrigin.toString(), targetOrigin, sentPortIds);
- }
- @Override
- public void onPostMessageQueueEmpty() {}
+ webContents.postMessageToFrame(
+ null, "", mOrigin.toString(), "", new AppWebMessagePort[] {mChannel[1]});
- @Override
- public boolean isPostMessageSenderReady() {
- return true;
- }
- };
- mPostMessageSender = new PostMessageSender(
- mSenderDelegate, getAppWebMessagePortService());
- service.addObserver(new MessageChannelObserver() {
- @Override
- public void onMessageChannelCreated() {
- service.removeObserver(this);
- if (mChannel == null) return;
- mPostMessageSender.postMessage(
- null, "", "", new AppWebMessagePort[] {mChannel[1]});
- mMessageChannelCreated = true;
- if (mBoundToService) notifyMessageChannelReady(null);
- }
- });
+ mMessageChannelCreated = true;
+ if (mBoundToService) notifyMessageChannelReady(null);
}
private void disconnectChannel() {
if (mChannel == null) return;
mChannel[0].close();
mChannel = null;
- mSenderDelegate = null;
- mPostMessageSender = null;
mWebContents = null;
}

Powered by Google App Engine
This is Rietveld 408576698