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

Side by Side 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: rebase 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.android_webview;
6
7 import android.util.Log;
8
9 /**
10 * Represents the MessageChannel MessagePort object. Inspired from
11 * http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.htm l#message-channels
12 */
13 public class MessagePort {
14
15 /**
16 * The interface for message handler for receiving messages. Called on a bac kground thread.
17 */
18 public static interface MessageHandler {
19 void onMessage(String message);
20 };
21
22 private static final String TAG = "AwMessagePortService";
23
24 private int mPortId;
25 private MessageHandler mHandler;
26
27 public MessagePort(int portId) {
28 mPortId = portId;
29 }
30
31 public int portId() {
32 return mPortId;
33 }
34
35 public void setMessageHandler(MessageHandler handler) {
36 mHandler = handler;
37 }
38
39 public void onMessage(String message) {
40 if (mHandler == null) {
41 Log.w(TAG, "No handler set for port [" + mPortId + "], dropping mess age " + message);
42 return;
43 }
44 mHandler.onMessage(message);
45 }
46 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698