Chromium Code Reviews| Index: android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java |
| diff --git a/android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java b/android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java |
| index 2f34e250fe624539a0930f4ec8eb0d3979ca318f..59bf114d66e4631ab0ccc6d498c3ff5709c4b508 100644 |
| --- a/android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java |
| +++ b/android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java |
| @@ -106,11 +106,36 @@ public class AwMessagePortService { |
| mMessageHandlerThread.start(); |
| } |
| + public void postMessage(int senderId, String message, int[] sentPorts) { |
| + // verify that webview still owns the port (not transferred) |
| + if (mPortStorage.get(senderId) == null) { |
| + throw new IllegalStateException(" Cannot post to unknown port " + senderId); |
|
mnaganov (inactive)
2015/01/27 13:30:17
nit: extra leading space in the message
sgurun-gerrit only
2015/01/29 03:06:08
Done.
|
| + } |
| + removeSentPorts(sentPorts); |
| + if (mNativeMessagePortService == 0) return; |
| + nativePostOutMessage(mNativeMessagePortService, senderId, message, sentPorts); |
| + } |
| + |
| + public void removeSentPorts(int[] sentPorts) { |
| + // verify that webview owns all the ports that are transferred |
| + if (sentPorts != null) { |
| + for (int port : sentPorts) { |
| + MessagePort p = mPortStorage.get(port); |
| + if (p == null) { |
| + throw new IllegalStateException("Cannot transfer unknown port " + port); |
| + } |
| + p.close(); |
| + // close the port so users can get feedback if they use in future. |
| + mPortStorage.put(port, null); |
| + } |
| + } |
| + } |
| + |
| private MessagePort addPort(int portId) { |
| if (mPortStorage.get(portId) != null) { |
| throw new IllegalStateException("Port already exists"); |
| } |
| - MessagePort m = new MessagePort(portId); |
| + MessagePort m = new MessagePort(portId, this); |
| mPortStorage.put(portId, m); |
| return m; |
| } |
| @@ -136,4 +161,6 @@ public class AwMessagePortService { |
| } |
| private native long nativeInitAwMessagePortService(); |
| + private native void nativePostOutMessage(long nativeAwMessagePortServiceImpl, |
| + int senderId, String message, int[] portIds); |
| } |