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

Unified Diff: android_webview/java/src/org/chromium/android_webview/MessagePort.java

Issue 831523004: Enable posting a message from JS to Android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix component builds Created 5 years, 11 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: 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..ef0e8d779655c66aa3de642ee04a95c85bf6d227
--- /dev/null
+++ b/android_webview/java/src/org/chromium/android_webview/MessagePort.java
@@ -0,0 +1,46 @@
+// Copyright 2015 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. Called on a background thread.
+ */
+ 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, "No handler set for port [" + mPortId + "], dropping message " + message);
+ return;
+ }
+ mHandler.onMessage(message);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698