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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/AppWebMessagePortService.java

Issue 2375133002: Move MessagePort implementation from android_webview to content (Closed)
Patch Set: Fix compile Created 4 years, 2 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: content/public/android/java/src/org/chromium/content/browser/AppWebMessagePortService.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java b/content/public/android/java/src/org/chromium/content/browser/AppWebMessagePortService.java
similarity index 69%
rename from android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java
rename to content/public/android/java/src/org/chromium/content/browser/AppWebMessagePortService.java
index eec71e1e59ad6d5300647d29aa0e53d6a36c2ef2..9591e957e39e85d2d30e8d39461e0c71a7c7f8c5 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java
+++ b/content/public/android/java/src/org/chromium/content/browser/AppWebMessagePortService.java
@@ -2,7 +2,7 @@
// 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;
+package org.chromium.content.browser;
import android.util.SparseArray;
@@ -12,29 +12,29 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
/**
- * Provides the Message Channel functionality for Android Webview. Specifically
+ * Provides the Message Channel functionality for Android. Specifically
sgurun-gerrit only 2016/10/06 22:57:39 Let's at least mention once that by saying Android
Yusuf 2016/10/07 21:20:27 Done.
* manages the message ports that are associated with a message channel and
* handles posting/receiving messages to/from them.
* See https://html.spec.whatwg.org/multipage/comms.html#messagechannel for
* further information on message channels.
*
- * The message ports have unique IDs. In Android webview implementation,
+ * The message ports have unique IDs. In Android implementation,
* the message ports are only known by their IDs at the native side.
* At the java side, the embedder deals with MessagePort objects. The mapping
- * from an ID to an object is in AwMessagePortService. AwMessagePortService
+ * from an ID to an object is in AppWebMessagePortService. AppWebMessagePortService
* keeps a strong ref to MessagePort objects until they are closed.
*
- * Ownership: The Java AwMessagePortService is owned by Java AwBrowserContext.
- * The native AwMessagePortService is owned by native AwBrowserContext. The
+ * Ownership: The Java AppWebMessagePortService has to be owned by Java side global.
+ * The native AppWebMessagePortService is a singleton. The
* native peer maintains a weak ref to the java object and deregisters itself
* before being deleted.
*
* All methods are called on UI thread except as noted.
*/
-@JNINamespace("android_webview")
-public class AwMessagePortService {
+@JNINamespace("content")
+public class AppWebMessagePortService {
- private static final String TAG = "AwMessagePortService";
+ private static final String TAG = "AppWebMessagePortService";
/**
* Observer for MessageChannel events.
@@ -45,7 +45,7 @@ public class AwMessagePortService {
// A thread safe storage for Message Ports.
private static class MessagePortStorage {
- private SparseArray<AwMessagePort> mMessagePorts = new SparseArray<AwMessagePort>();
+ private SparseArray<AppWebMessagePort> mMessagePorts = new SparseArray<AppWebMessagePort>();
private final Object mLock = new Object();
public void remove(int portId) {
@@ -54,12 +54,12 @@ public class AwMessagePortService {
}
}
- public void put(int portId, AwMessagePort m) {
+ public void put(int portId, AppWebMessagePort m) {
synchronized (mLock) {
mMessagePorts.put(portId, m);
}
}
- public AwMessagePort get(int portId) {
+ public AppWebMessagePort get(int portId) {
synchronized (mLock) {
return mMessagePorts.get(portId);
}
@@ -71,8 +71,8 @@ public class AwMessagePortService {
private ObserverList<MessageChannelObserver> mObserverList =
new ObserverList<MessageChannelObserver>();
- AwMessagePortService() {
- mNativeMessagePortService = nativeInitAwMessagePortService();
+ public AppWebMessagePortService() {
+ mNativeMessagePortService = nativeInitAppWebMessagePortService();
}
public void addObserver(MessageChannelObserver observer) {
@@ -90,7 +90,7 @@ public class AwMessagePortService {
}
public void postMessage(int senderId, String message, int[] sentPorts) {
- // verify that webview still owns the port (not transferred)
+ // verify that the port is owned by service still (not transferred).
if (mPortStorage.get(senderId) == null) {
throw new IllegalStateException("Cannot post to unknown port " + senderId);
}
@@ -99,10 +99,10 @@ public class AwMessagePortService {
}
public void removeSentPorts(int[] sentPorts) {
- // verify that webview owns all the ports that are transferred
+ // verify that this service still owns all the ports that are transferred
if (sentPorts != null) {
for (int port : sentPorts) {
- AwMessagePort p = mPortStorage.get(port);
+ AppWebMessagePort p = mPortStorage.get(port);
if (p == null) {
throw new IllegalStateException("Cannot transfer unknown port " + port);
}
@@ -111,8 +111,8 @@ public class AwMessagePortService {
}
}
- public AwMessagePort[] createMessageChannel() {
- return new AwMessagePort[]{new AwMessagePort(this), new AwMessagePort(this)};
+ public AppWebMessagePort[] createMessageChannel() {
+ return new AppWebMessagePort[]{new AppWebMessagePort(this), new AppWebMessagePort(this)};
}
// Called on UI thread.
@@ -121,7 +121,7 @@ public class AwMessagePortService {
nativeReleaseMessages(mNativeMessagePortService, portId);
}
- private AwMessagePort addPort(AwMessagePort m, int portId) {
+ private AppWebMessagePort addPort(AppWebMessagePort m, int portId) {
if (mPortStorage.get(portId) != null) {
throw new IllegalStateException("Port already exists");
}
@@ -132,7 +132,7 @@ public class AwMessagePortService {
@CalledByNative
private void onMessageChannelCreated(int portId1, int portId2,
- AwMessagePort[] ports) {
+ AppWebMessagePort[] ports) {
ThreadUtils.assertOnUiThread();
addPort(ports[0], portId1);
addPort(ports[1], portId2);
@@ -144,26 +144,26 @@ public class AwMessagePortService {
// Called on IO thread.
@CalledByNative
private void onReceivedMessage(int portId, String message, int[] ports) {
- AwMessagePort[] messagePorts = null;
+ AppWebMessagePort[] messagePorts = null;
for (int i = 0; i < ports.length; i++) {
if (messagePorts == null) {
- messagePorts = new AwMessagePort[ports.length];
+ messagePorts = new AppWebMessagePort[ports.length];
}
- messagePorts[i] = addPort(new AwMessagePort(this), ports[i]);
+ messagePorts[i] = addPort(new AppWebMessagePort(this), ports[i]);
}
mPortStorage.get(portId).onReceivedMessage(message, messagePorts);
}
@CalledByNative
- private void unregisterNativeAwMessagePortService() {
+ private void unregisterNativeAppWebMessagePortService() {
mNativeMessagePortService = 0;
}
- private native long nativeInitAwMessagePortService();
- private native void nativePostAppToWebMessage(long nativeAwMessagePortServiceImpl,
+ private native long nativeInitAppWebMessagePortService();
+ private native void nativePostAppToWebMessage(long nativeAppWebMessagePortServiceImpl,
int senderId, String message, int[] portIds);
- private native void nativeClosePort(long nativeAwMessagePortServiceImpl,
+ private native void nativeClosePort(long nativeAppWebMessagePortServiceImpl,
int messagePortId);
- private native void nativeReleaseMessages(long nativeAwMessagePortServiceImpl,
+ private native void nativeReleaseMessages(long nativeAppWebMessagePortServiceImpl,
int messagePortId);
}

Powered by Google App Engine
This is Rietveld 408576698