Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.android_webview; | 5 package org.chromium.android_webview; |
| 6 | 6 |
| 7 import android.os.Handler; | 7 import android.os.Handler; |
| 8 import android.os.Looper; | 8 import android.os.Looper; |
| 9 import android.os.Message; | 9 import android.os.Message; |
| 10 import android.util.SparseArray; | 10 import android.util.SparseArray; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 } | 116 } |
| 117 | 117 |
| 118 public void addObserver(MessageChannelObserver observer) { | 118 public void addObserver(MessageChannelObserver observer) { |
| 119 mObserverList.addObserver(observer); | 119 mObserverList.addObserver(observer); |
| 120 } | 120 } |
| 121 | 121 |
| 122 public void removeObserver(MessageChannelObserver observer) { | 122 public void removeObserver(MessageChannelObserver observer) { |
| 123 mObserverList.removeObserver(observer); | 123 mObserverList.removeObserver(observer); |
| 124 } | 124 } |
| 125 | 125 |
| 126 public void closePort(int messagePortId) { | |
| 127 mPortStorage.put(messagePortId, null); | |
|
hush (inactive)
2015/02/25 19:44:27
what's different between this and mPortStorage.rem
sgurun-gerrit only
2015/02/25 21:38:53
good catch.
| |
| 128 if (mNativeMessagePortService == 0) return; | |
| 129 nativeClosePort(mNativeMessagePortService, messagePortId); | |
| 130 } | |
| 131 | |
| 126 public void postMessage(int senderId, String message, int[] sentPorts) { | 132 public void postMessage(int senderId, String message, int[] sentPorts) { |
| 127 // verify that webview still owns the port (not transferred) | 133 // verify that webview still owns the port (not transferred) |
| 128 if (mPortStorage.get(senderId) == null) { | 134 if (mPortStorage.get(senderId) == null) { |
| 129 throw new IllegalStateException("Cannot post to unknown port " + sen derId); | 135 throw new IllegalStateException("Cannot post to unknown port " + sen derId); |
| 130 } | 136 } |
| 131 removeSentPorts(sentPorts); | |
|
hush (inactive)
2015/02/25 19:44:27
why is this removed?
sgurun-gerrit only
2015/02/25 21:38:53
this is actually a bug. The ports are removed in P
| |
| 132 if (mNativeMessagePortService == 0) return; | 137 if (mNativeMessagePortService == 0) return; |
| 133 nativePostAppToWebMessage(mNativeMessagePortService, senderId, message, sentPorts); | 138 nativePostAppToWebMessage(mNativeMessagePortService, senderId, message, sentPorts); |
| 134 } | 139 } |
| 135 | 140 |
| 136 public void removeSentPorts(int[] sentPorts) { | 141 public void removeSentPorts(int[] sentPorts) { |
| 137 // verify that webview owns all the ports that are transferred | 142 // verify that webview owns all the ports that are transferred |
| 138 if (sentPorts != null) { | 143 if (sentPorts != null) { |
| 139 for (int port : sentPorts) { | 144 for (int port : sentPorts) { |
| 140 MessagePort p = mPortStorage.get(port); | 145 MessagePort p = mPortStorage.get(port); |
| 141 if (p == null) { | 146 if (p == null) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 } | 188 } |
| 184 | 189 |
| 185 @CalledByNative | 190 @CalledByNative |
| 186 private void unregisterNativeAwMessagePortService() { | 191 private void unregisterNativeAwMessagePortService() { |
| 187 mNativeMessagePortService = 0; | 192 mNativeMessagePortService = 0; |
| 188 } | 193 } |
| 189 | 194 |
| 190 private native long nativeInitAwMessagePortService(); | 195 private native long nativeInitAwMessagePortService(); |
| 191 private native void nativePostAppToWebMessage(long nativeAwMessagePortServic eImpl, | 196 private native void nativePostAppToWebMessage(long nativeAwMessagePortServic eImpl, |
| 192 int senderId, String message, int[] portIds); | 197 int senderId, String message, int[] portIds); |
| 198 private native void nativeClosePort(long nativeAwMessagePortServiceImpl, | |
| 199 int messagePortId); | |
| 193 } | 200 } |
| OLD | NEW |