| Index: android_webview/java/src/org/chromium/android_webview/MessagePort.java
|
| diff --git a/android_webview/java/src/org/chromium/android_webview/MessagePort.java b/android_webview/java/src/org/chromium/android_webview/MessagePort.java
|
| index ef0e8d779655c66aa3de642ee04a95c85bf6d227..e04035553a03630ff80d886558c469fc9101b7b1 100644
|
| --- a/android_webview/java/src/org/chromium/android_webview/MessagePort.java
|
| +++ b/android_webview/java/src/org/chromium/android_webview/MessagePort.java
|
| @@ -19,28 +19,60 @@ public class MessagePort {
|
| void onMessage(String message);
|
| };
|
|
|
| - private static final String TAG = "AwMessagePortService";
|
| + private static final String TAG = "MessagePort";
|
|
|
| private int mPortId;
|
| private MessageHandler mHandler;
|
| + private AwMessagePortService mMessagePortService;
|
| + // A port is put into a closed state when transferred. Such a port can no longer
|
| + // send or receive messages.
|
| + private boolean mClosed;
|
|
|
| - public MessagePort(int portId) {
|
| + public MessagePort(int portId, AwMessagePortService messagePortService) {
|
| mPortId = portId;
|
| + mMessagePortService = messagePortService;
|
| }
|
|
|
| public int portId() {
|
| return mPortId;
|
| }
|
|
|
| + public void close() {
|
| + assert !mClosed;
|
| + mClosed = true;
|
| + }
|
| +
|
| + public boolean isClosed() {
|
| + return mClosed;
|
| + }
|
| +
|
| public void setMessageHandler(MessageHandler handler) {
|
| mHandler = handler;
|
| }
|
|
|
| public void onMessage(String message) {
|
| + if (isClosed()) {
|
| + Log.w(TAG, "Port [" + mPortId + "] received message in closed state");
|
| + return;
|
| + }
|
| if (mHandler == null) {
|
| Log.w(TAG, "No handler set for port [" + mPortId + "], dropping message " + message);
|
| return;
|
| }
|
| mHandler.onMessage(message);
|
| }
|
| +
|
| + public void postMessage(String message, MessagePort[] msgPorts) throws IllegalStateException {
|
| + if (isClosed()) {
|
| + throw new IllegalStateException("Messageport is already closed");
|
| + }
|
| + int[] portIds = null;
|
| + if (msgPorts != null) {
|
| + portIds = new int[msgPorts.length];
|
| + for (int i = 0; i < msgPorts.length; i++) {
|
| + portIds[i] = msgPorts[i].portId();
|
| + }
|
| + }
|
| + mMessagePortService.postMessage(mPortId, message, portIds);
|
| + }
|
| }
|
|
|