mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
Bug 1317604 - 2. Rip out GeckoView event listeners; r=snorp
GeckoView's GeckoEventListener and NativeEventListener are not actually hooked up to events right now, so it's better to just rip them out until we figure out a better implementation in the future.
This commit is contained in:
parent
bb6f8910a3
commit
c2f64f66ce
@ -15,10 +15,6 @@ import org.mozilla.gecko.annotation.WrapForJNI;
|
||||
import org.mozilla.gecko.gfx.LayerView;
|
||||
import org.mozilla.gecko.mozglue.JNIObject;
|
||||
import org.mozilla.gecko.util.EventCallback;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
import org.mozilla.gecko.util.NativeEventListener;
|
||||
import org.mozilla.gecko.util.NativeJSObject;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
@ -38,7 +34,7 @@ import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
|
||||
public class GeckoView extends LayerView
|
||||
implements ContextGetter, GeckoEventListener, NativeEventListener {
|
||||
implements ContextGetter {
|
||||
|
||||
private static final String DEFAULT_SHARED_PREFERENCES_FILE = "GeckoView";
|
||||
private static final String LOGTAG = "GeckoView";
|
||||
@ -54,65 +50,6 @@ public class GeckoView extends LayerView
|
||||
protected String chromeURI;
|
||||
protected int screenId = 0; // default to the primary screen
|
||||
|
||||
@Override
|
||||
public void handleMessage(final String event, final JSONObject message) {
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (event.equals("Gecko:Ready")) {
|
||||
handleReady(message);
|
||||
} else if (event.equals("Content:StateChange")) {
|
||||
handleStateChange(message);
|
||||
} else if (event.equals("Content:LoadError")) {
|
||||
handleLoadError(message);
|
||||
} else if (event.equals("Content:PageShow")) {
|
||||
handlePageShow(message);
|
||||
} else if (event.equals("DOMTitleChanged")) {
|
||||
handleTitleChanged(message);
|
||||
} else if (event.equals("Link:Favicon")) {
|
||||
handleLinkFavicon(message);
|
||||
} else if (event.equals("Prompt:Show") || event.equals("Prompt:ShowTop")) {
|
||||
handlePrompt(message);
|
||||
} else if (event.equals("Accessibility:Event")) {
|
||||
int mode = getImportantForAccessibility();
|
||||
if (mode == View.IMPORTANT_FOR_ACCESSIBILITY_YES ||
|
||||
mode == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
|
||||
GeckoAccessibility.sendAccessibilityEvent(message);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "handleMessage threw for " + event, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(final String event, final NativeJSObject message, final EventCallback callback) {
|
||||
try {
|
||||
if ("Accessibility:Ready".equals(event)) {
|
||||
GeckoAccessibility.updateAccessibilitySettings(getContext());
|
||||
} else if ("GeckoView:Message".equals(event)) {
|
||||
// We need to pull out the bundle while on the Gecko thread.
|
||||
NativeJSObject json = message.optObject("data", null);
|
||||
if (json == null) {
|
||||
// Must have payload to call the message handler.
|
||||
return;
|
||||
}
|
||||
final Bundle data = json.toBundle();
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handleScriptMessage(data, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(LOGTAG, "handleMessage threw for " + event, e);
|
||||
}
|
||||
}
|
||||
|
||||
@WrapForJNI(dispatchTo = "proxy")
|
||||
protected static final class Window extends JNIObject {
|
||||
@WrapForJNI(skip = true)
|
||||
@ -393,86 +330,6 @@ public class GeckoView extends LayerView
|
||||
throw new IllegalArgumentException("Must import script from 'resources://android/assets/' location.");
|
||||
}
|
||||
|
||||
private void handleReady(final JSONObject message) {
|
||||
if (mChromeDelegate != null) {
|
||||
mChromeDelegate.onReady(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleStateChange(final JSONObject message) throws JSONException {
|
||||
int state = message.getInt("state");
|
||||
if ((state & GeckoAppShell.WPL_STATE_IS_NETWORK) != 0) {
|
||||
if ((state & GeckoAppShell.WPL_STATE_START) != 0) {
|
||||
if (mContentDelegate != null) {
|
||||
int id = message.getInt("tabID");
|
||||
mContentDelegate.onPageStart(this, new Browser(id), message.getString("uri"));
|
||||
}
|
||||
} else if ((state & GeckoAppShell.WPL_STATE_STOP) != 0) {
|
||||
if (mContentDelegate != null) {
|
||||
int id = message.getInt("tabID");
|
||||
mContentDelegate.onPageStop(this, new Browser(id), message.getBoolean("success"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleLoadError(final JSONObject message) throws JSONException {
|
||||
if (mContentDelegate != null) {
|
||||
int id = message.getInt("tabID");
|
||||
mContentDelegate.onPageStop(GeckoView.this, new Browser(id), false);
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePageShow(final JSONObject message) throws JSONException {
|
||||
if (mContentDelegate != null) {
|
||||
int id = message.getInt("tabID");
|
||||
mContentDelegate.onPageShow(GeckoView.this, new Browser(id));
|
||||
}
|
||||
}
|
||||
|
||||
private void handleTitleChanged(final JSONObject message) throws JSONException {
|
||||
if (mContentDelegate != null) {
|
||||
int id = message.getInt("tabID");
|
||||
mContentDelegate.onReceivedTitle(GeckoView.this, new Browser(id), message.getString("title"));
|
||||
}
|
||||
}
|
||||
|
||||
private void handleLinkFavicon(final JSONObject message) throws JSONException {
|
||||
if (mContentDelegate != null) {
|
||||
int id = message.getInt("tabID");
|
||||
mContentDelegate.onReceivedFavicon(GeckoView.this, new Browser(id), message.getString("href"), message.getInt("size"));
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePrompt(final JSONObject message) throws JSONException {
|
||||
if (mChromeDelegate != null) {
|
||||
String hint = message.optString("hint");
|
||||
if ("alert".equals(hint)) {
|
||||
String text = message.optString("text");
|
||||
mChromeDelegate.onAlert(GeckoView.this, null, text, new PromptResult(message));
|
||||
} else if ("confirm".equals(hint)) {
|
||||
String text = message.optString("text");
|
||||
mChromeDelegate.onConfirm(GeckoView.this, null, text, new PromptResult(message));
|
||||
} else if ("prompt".equals(hint)) {
|
||||
String text = message.optString("text");
|
||||
String defaultValue = message.optString("textbox0");
|
||||
mChromeDelegate.onPrompt(GeckoView.this, null, text, defaultValue, new PromptResult(message));
|
||||
} else if ("remotedebug".equals(hint)) {
|
||||
mChromeDelegate.onDebugRequest(GeckoView.this, new PromptResult(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleScriptMessage(final Bundle data, final EventCallback callback) {
|
||||
if (mChromeDelegate != null) {
|
||||
MessageResult result = null;
|
||||
if (callback != null) {
|
||||
result = new MessageResult(callback);
|
||||
}
|
||||
mChromeDelegate.onScriptMessage(GeckoView.this, data, result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the chrome callback handler.
|
||||
* This will replace the current handler.
|
||||
|
Loading…
Reference in New Issue
Block a user