| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..40a16eebd61ae01635c3f284eef8cbc55d41edbb
|
| --- /dev/null
|
| +++ b/android_webview/java/src/org/chromium/android_webview/MessagePort.java
|
| @@ -0,0 +1,46 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.android_webview;
|
| +
|
| +import android.util.Log;
|
| +
|
| +/**
|
| + * Represents the MessageChannel MessagePort object. Inspired from
|
| + * http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.html#message-channels
|
| + */
|
| +public class MessagePort {
|
| +
|
| + /**
|
| + * The interface for message handler for receiving messages.
|
| + */
|
| + public static interface MessageHandler {
|
| + void onMessage(String message);
|
| + };
|
| +
|
| + private static final String TAG = "AwMessagePortService";
|
| +
|
| + private int mPortId;
|
| + private MessageHandler mHandler;
|
| +
|
| + public MessagePort(int portId) {
|
| + mPortId = portId;
|
| + }
|
| +
|
| + public int portId() {
|
| + return mPortId;
|
| + }
|
| +
|
| + public void setMessageHandler(MessageHandler handler) {
|
| + mHandler = handler;
|
| + }
|
| +
|
| + public void onMessage(String message) {
|
| + if (mHandler == null) {
|
| + Log.w(TAG, "Invalid state. Port [" + mPortId + "] dropped message " + message);
|
| + return;
|
| + }
|
| + mHandler.onMessage(message);
|
| + }
|
| +}
|
|
|