Bug 857335 - Add EventDispatcher warnings about events with no listeners. r=mfinkle r=kats

This commit is contained in:
Chris Peterson 2013-04-02 14:28:59 -07:00
Родитель 472a77bd58
Коммит 9e0505b1b8
1 изменённых файлов: 17 добавлений и 6 удалений

Просмотреть файл

@ -27,7 +27,7 @@ public final class EventDispatcher {
// Otherwise we could end up throwing a ConcurrentModificationException.
listeners = new CopyOnWriteArrayList<GeckoEventListener>();
} else if (listeners.contains(listener)) {
Log.w(LOGTAG, "EventListener already registered for event \"" + event + "\"",
Log.w(LOGTAG, "EventListener already registered for event '" + event + "'",
new IllegalArgumentException());
}
listeners.add(listener);
@ -39,9 +39,13 @@ public final class EventDispatcher {
synchronized (mEventListeners) {
CopyOnWriteArrayList<GeckoEventListener> listeners = mEventListeners.get(event);
if (listeners == null) {
Log.w(LOGTAG, "unregisterEventListener: event '" + event + "' has no listeners");
return;
}
listeners.remove(listener);
if (!listeners.remove(listener)) {
Log.w(LOGTAG, "unregisterEventListener: tried to remove an unregistered listener " +
"for event '" + event + "'");
}
if (listeners.size() == 0) {
mEventListeners.remove(event);
}
@ -55,19 +59,26 @@ public final class EventDispatcher {
// ...
try {
JSONObject json = new JSONObject(message);
if (json.has("gecko")) {
json = json.getJSONObject("gecko");
Log.w(LOGTAG, "The 'gecko' property of the sendMessageToJava parameter is deprecated; message of type " + json.getString("type"));
JSONObject gecko = json.has("gecko") ? json.getJSONObject("gecko") : null;
if (gecko != null) {
json = gecko;
}
String type = json.getString("type");
if (gecko != null) {
Log.w(LOGTAG, "Message '" + type + "' has deprecated 'gecko' property!");
}
CopyOnWriteArrayList<GeckoEventListener> listeners;
synchronized (mEventListeners) {
listeners = mEventListeners.get(type);
}
if (listeners == null)
if (listeners == null || listeners.size() == 0) {
Log.d(LOGTAG, "dispatchEvent: no listeners registered for event '" + type + "'");
return "";
}
String response = null;