| Index: content/public/android/java/src/org/chromium/content/browser/AppWebMessagePortService.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/AppWebMessagePortService.java b/content/public/android/java/src/org/chromium/content/browser/AppWebMessagePortService.java
|
| index b908901c253ca0a07d067c4951ebb0b2f1ed75f1..612e5321d445cfc97c9c2394c0392a504d037253 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/AppWebMessagePortService.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/AppWebMessagePortService.java
|
| @@ -4,10 +4,6 @@
|
|
|
| package org.chromium.content.browser;
|
|
|
| -import android.util.SparseArray;
|
| -
|
| -import org.chromium.base.ObserverList;
|
| -import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.base.annotations.JNINamespace;
|
| import org.chromium.content_public.browser.MessagePortService;
|
| @@ -37,120 +33,15 @@ import org.chromium.content_public.browser.MessagePortService;
|
| public class AppWebMessagePortService implements MessagePortService {
|
| private static final String TAG = "AppWebMessagePortService";
|
|
|
| - /**
|
| - * Observer for MessageChannel events.
|
| - */
|
| - public static interface MessageChannelObserver { void onMessageChannelCreated(); }
|
| -
|
| - // A thread safe storage for Message Ports.
|
| - private static class MessagePortStorage {
|
| - private SparseArray<AppWebMessagePort> mMessagePorts = new SparseArray<AppWebMessagePort>();
|
| - private final Object mLock = new Object();
|
| -
|
| - public void remove(int portId) {
|
| - synchronized (mLock) {
|
| - mMessagePorts.remove(portId);
|
| - }
|
| - }
|
| -
|
| - public void put(int portId, AppWebMessagePort m) {
|
| - synchronized (mLock) {
|
| - mMessagePorts.put(portId, m);
|
| - }
|
| - }
|
| - public AppWebMessagePort get(int portId) {
|
| - synchronized (mLock) {
|
| - return mMessagePorts.get(portId);
|
| - }
|
| - }
|
| - }
|
| -
|
| private long mNativeMessagePortService;
|
| - private MessagePortStorage mPortStorage = new MessagePortStorage();
|
| - private ObserverList<MessageChannelObserver> mObserverList =
|
| - new ObserverList<MessageChannelObserver>();
|
|
|
| public AppWebMessagePortService() {
|
| mNativeMessagePortService = nativeInitAppWebMessagePortService();
|
| }
|
|
|
| - public void addObserver(MessageChannelObserver observer) {
|
| - mObserverList.addObserver(observer);
|
| - }
|
| -
|
| - public void removeObserver(MessageChannelObserver observer) {
|
| - mObserverList.removeObserver(observer);
|
| - }
|
| -
|
| - public void closePort(int messagePortId) {
|
| - mPortStorage.remove(messagePortId);
|
| - if (mNativeMessagePortService == 0) return;
|
| - nativeClosePort(mNativeMessagePortService, messagePortId);
|
| - }
|
| -
|
| - public void postMessage(int senderId, String message, int[] sentPorts) {
|
| - // verify that the port is owned by service still (not transferred).
|
| - if (mPortStorage.get(senderId) == null) {
|
| - throw new IllegalStateException("Cannot post to unknown port " + senderId);
|
| - }
|
| - if (mNativeMessagePortService == 0) return;
|
| - nativePostAppToWebMessage(mNativeMessagePortService, senderId, message, sentPorts);
|
| - }
|
| -
|
| - public void removeSentPorts(int[] sentPorts) {
|
| - // verify that this service still owns all the ports that are transferred
|
| - if (sentPorts != null) {
|
| - for (int port : sentPorts) {
|
| - AppWebMessagePort p = mPortStorage.get(port);
|
| - if (p == null) {
|
| - throw new IllegalStateException("Cannot transfer unknown port " + port);
|
| - }
|
| - mPortStorage.remove(port);
|
| - }
|
| - }
|
| - }
|
| -
|
| @Override
|
| public AppWebMessagePort[] createMessageChannel() {
|
| - return new AppWebMessagePort[] {new AppWebMessagePort(this), new AppWebMessagePort(this)};
|
| - }
|
| -
|
| - // Called on UI thread.
|
| - public void releaseMessages(int portId) {
|
| - if (mNativeMessagePortService == 0) return;
|
| - nativeReleaseMessages(mNativeMessagePortService, portId);
|
| - }
|
| -
|
| - private AppWebMessagePort addPort(AppWebMessagePort m, int portId) {
|
| - if (mPortStorage.get(portId) != null) {
|
| - throw new IllegalStateException("Port already exists");
|
| - }
|
| - m.setPortId(portId);
|
| - mPortStorage.put(portId, m);
|
| - return m;
|
| - }
|
| -
|
| - @CalledByNative
|
| - private void onMessageChannelCreated(int portId1, int portId2, AppWebMessagePort[] ports) {
|
| - ThreadUtils.assertOnUiThread();
|
| - addPort(ports[0], portId1);
|
| - addPort(ports[1], portId2);
|
| - for (MessageChannelObserver observer : mObserverList) {
|
| - observer.onMessageChannelCreated();
|
| - }
|
| - }
|
| -
|
| - // Called on IO thread.
|
| - @CalledByNative
|
| - private void onReceivedMessage(int portId, String message, int[] ports) {
|
| - AppWebMessagePort[] messagePorts = null;
|
| - for (int i = 0; i < ports.length; i++) {
|
| - if (messagePorts == null) {
|
| - messagePorts = new AppWebMessagePort[ports.length];
|
| - }
|
| - messagePorts[i] = addPort(new AppWebMessagePort(this), ports[i]);
|
| - }
|
| - mPortStorage.get(portId).onReceivedMessage(message, messagePorts);
|
| + return new AppWebMessagePort[] {new AppWebMessagePort(), new AppWebMessagePort()};
|
| }
|
|
|
| @CalledByNative
|
| @@ -159,9 +50,4 @@ public class AppWebMessagePortService implements MessagePortService {
|
| }
|
|
|
| private native long nativeInitAppWebMessagePortService();
|
| - private native void nativePostAppToWebMessage(
|
| - long nativeAppWebMessagePortServiceImpl, int senderId, String message, int[] portIds);
|
| - private native void nativeClosePort(long nativeAppWebMessagePortServiceImpl, int messagePortId);
|
| - private native void nativeReleaseMessages(
|
| - long nativeAppWebMessagePortServiceImpl, int messagePortId);
|
| }
|
|
|