Bug 1004073 - Refactor EventDispatcher usages; r=fennec-team

This commit is contained in:
Jim Chen 2014-05-02 14:34:40 -04:00
Родитель 1b20b99c0a
Коммит 0ff39eef3c
40 изменённых файлов: 345 добавлений и 433 удалений

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

@ -72,7 +72,7 @@ public class FennecNativeActions implements Actions {
}
};
GeckoAppShell.registerEventListener(mGeckoEvent, mListener);
EventDispatcher.getInstance().registerGeckoThreadListener(mListener, mGeckoEvent);
mIsRegistered = true;
}
@ -158,7 +158,7 @@ public class FennecNativeActions implements Actions {
FennecNativeDriver.log(LogLevel.INFO,
"EventExpecter: no longer listening for " + mGeckoEvent);
GeckoAppShell.unregisterEventListener(mGeckoEvent, mListener);
EventDispatcher.getInstance().unregisterGeckoThreadListener(mListener, mGeckoEvent);
mIsRegistered = false;
}

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

@ -234,7 +234,7 @@ public class FennecNativeDriver implements Driver {
}
public void setupScrollHandling() {
GeckoAppShell.registerEventListener("robocop:scroll", new GeckoEventListener() {
EventDispatcher.getInstance().registerGeckoThreadListener(new GeckoEventListener() {
@Override
public void handleMessage(final String event, final JSONObject message) {
try {
@ -250,7 +250,7 @@ public class FennecNativeDriver implements Driver {
"expected fields: " + e);
}
}
});
}, "robocop:scroll");
}
/**

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

@ -526,25 +526,26 @@ abstract public class BrowserApp extends GeckoApp
mFindInPageBar = (FindInPageBar) findViewById(R.id.find_in_page);
mMediaCastingBar = (MediaCastingBar) findViewById(R.id.media_casting);
registerEventListener("CharEncoding:Data");
registerEventListener("CharEncoding:State");
registerEventListener("Feedback:LastUrl");
registerEventListener("Feedback:OpenPlayStore");
registerEventListener("Feedback:MaybeLater");
registerEventListener("Telemetry:Gather");
registerEventListener("Settings:Show");
registerEventListener("Updater:Launch");
registerEventListener("Menu:Add");
registerEventListener("Menu:Remove");
registerEventListener("Menu:Update");
registerEventListener("Accounts:Create");
registerEventListener("Accounts:Exist");
registerEventListener("Prompt:ShowTop");
registerEventListener("Reader:ListStatusRequest");
registerEventListener("Reader:Added");
registerEventListener("Reader:Removed");
registerEventListener("Reader:Share");
registerEventListener("Reader:FaviconRequest");
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"CharEncoding:Data",
"CharEncoding:State",
"Feedback:LastUrl",
"Feedback:OpenPlayStore",
"Feedback:MaybeLater",
"Telemetry:Gather",
"Settings:Show",
"Updater:Launch",
"Menu:Add",
"Menu:Remove",
"Menu:Update",
"Accounts:Create",
"Accounts:Exist",
"Prompt:ShowTop",
"Reader:ListStatusRequest",
"Reader:Added",
"Reader:Removed",
"Reader:Share",
"Reader:FaviconRequest");
Distribution.init(this);
JavaAddonManager.getInstance().init(getApplicationContext());
@ -606,14 +607,14 @@ abstract public class BrowserApp extends GeckoApp
@Override
public void onResume() {
super.onResume();
unregisterEventListener("Prompt:ShowTop");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "Prompt:ShowTop");
}
@Override
public void onPause() {
super.onPause();
// Register for Prompt:ShowTop so we can foreground this activity even if it's hidden.
registerEventListener("Prompt:ShowTop");
EventDispatcher.getInstance().registerGeckoThreadListener(this, "Prompt:ShowTop");
}
private void setBrowserToolbarListeners() {
@ -885,24 +886,26 @@ abstract public class BrowserApp extends GeckoApp
mBrowserHealthReporter = null;
}
unregisterEventListener("CharEncoding:Data");
unregisterEventListener("CharEncoding:State");
unregisterEventListener("Feedback:LastUrl");
unregisterEventListener("Feedback:OpenPlayStore");
unregisterEventListener("Feedback:MaybeLater");
unregisterEventListener("Telemetry:Gather");
unregisterEventListener("Settings:Show");
unregisterEventListener("Updater:Launch");
unregisterEventListener("Menu:Add");
unregisterEventListener("Menu:Remove");
unregisterEventListener("Menu:Update");
unregisterEventListener("Accounts:Create");
unregisterEventListener("Accounts:Exist");
unregisterEventListener("Reader:ListStatusRequest");
unregisterEventListener("Reader:Added");
unregisterEventListener("Reader:Removed");
unregisterEventListener("Reader:Share");
unregisterEventListener("Reader:FaviconRequest");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"CharEncoding:Data",
"CharEncoding:State",
"Feedback:LastUrl",
"Feedback:OpenPlayStore",
"Feedback:MaybeLater",
"Telemetry:Gather",
"Settings:Show",
"Updater:Launch",
"Menu:Add",
"Menu:Remove",
"Menu:Update",
"Accounts:Create",
"Accounts:Exist",
"Prompt:ShowTop",
"Reader:ListStatusRequest",
"Reader:Added",
"Reader:Removed",
"Reader:Share",
"Reader:FaviconRequest");
if (AppConstants.MOZ_ANDROID_BEAM && Build.VERSION.SDK_INT >= 14) {
NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
@ -1687,7 +1690,7 @@ abstract public class BrowserApp extends GeckoApp
message.put("type", BrowserHealthRecorder.EVENT_SEARCH);
message.put("location", where);
message.put("identifier", identifier);
GeckoAppShell.getEventDispatcher().dispatchEvent(message, null);
EventDispatcher.getInstance().dispatchEvent(message, null);
} catch (Exception e) {
Log.w(LOGTAG, "Error recording search.", e);
}

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

@ -99,21 +99,23 @@ public class ContactService implements GeckoEventListener {
mContentResolver = mActivity.getContentResolver();
mGotDeviceAccount = false;
registerEventListener("Android:Contacts:Clear");
registerEventListener("Android:Contacts:Find");
registerEventListener("Android:Contacts:GetAll");
registerEventListener("Android:Contacts:GetCount");
registerEventListener("Android:Contact:Remove");
registerEventListener("Android:Contact:Save");
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"Android:Contacts:Clear",
"Android:Contacts:Find",
"Android:Contacts:GetAll",
"Android:Contacts:GetCount",
"Android:Contact:Remove",
"Android:Contact:Save");
}
public void destroy() {
unregisterEventListener("Android:Contacts:Clear");
unregisterEventListener("Android:Contacts:Find");
unregisterEventListener("Android:Contacts:GetAll");
unregisterEventListener("Android:Contacts:GetCount");
unregisterEventListener("Android:Contact:Remove");
unregisterEventListener("Android:Contact:Save");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"Android:Contacts:Clear",
"Android:Contacts:Find",
"Android:Contacts:GetAll",
"Android:Contacts:GetCount",
"Android:Contact:Remove",
"Android:Contact:Save");
}
@Override
@ -1507,14 +1509,6 @@ public class ContactService implements GeckoEventListener {
}
}
private void registerEventListener(final String event) {
mEventDispatcher.registerEventListener(event, this);
}
private void unregisterEventListener(final String event) {
mEventDispatcher.unregisterEventListener(event, this);
}
private ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) {
try {
return mContentResolver.applyBatch(ContactsContract.AUTHORITY, operations);

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

@ -40,14 +40,16 @@ public class DoorHangerPopup extends ArrowPopup
mDoorHangers = new HashSet<DoorHanger>();
registerEventListener("Doorhanger:Add");
registerEventListener("Doorhanger:Remove");
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"Doorhanger:Add",
"Doorhanger:Remove");
Tabs.registerOnTabsChangedListener(this);
}
void destroy() {
unregisterEventListener("Doorhanger:Add");
unregisterEventListener("Doorhanger:Remove");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"Doorhanger:Add",
"Doorhanger:Remove");
Tabs.unregisterOnTabsChangedListener(this);
}
@ -336,14 +338,6 @@ public class DoorHangerPopup extends ArrowPopup
}
}
private void registerEventListener(String event) {
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
}
private void unregisterEventListener(String event) {
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
}
@Override
public void dismiss() {
// If the popup is focusable while it is hidden, we run into crashes

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

@ -6,6 +6,7 @@ package org.mozilla.gecko;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.mozglue.RobocopTarget;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.NativeEventListener;
@ -21,6 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
@RobocopTarget
public final class EventDispatcher {
private static final String LOGTAG = "GeckoEventDispatcher";
private static final String GUID = "__guid__";
@ -28,6 +30,8 @@ public final class EventDispatcher {
private static final String STATUS_ERROR = "error";
private static final String STATUS_SUCCESS = "success";
private static final EventDispatcher INSTANCE = new EventDispatcher();
/**
* The capacity of a HashMap is rounded up to the next power-of-2. Every time the size
* of the map goes beyond 75% of the capacity, the map is rehashed. Therefore, to
@ -42,6 +46,13 @@ public final class EventDispatcher {
private final Map<String, List<GeckoEventListener>> mGeckoThreadJSONListeners =
new HashMap<String, List<GeckoEventListener>>(GECKO_JSON_EVENTS_COUNT);
public static EventDispatcher getInstance() {
return INSTANCE;
}
private EventDispatcher() {
}
private <T> void registerListener(final Class<? extends List<T>> listType,
final Map<String, List<T>> listenersMap,
final T listener,
@ -109,8 +120,8 @@ public final class EventDispatcher {
@Deprecated // Use NativeEventListener instead
@SuppressWarnings("unchecked")
private void registerGeckoThreadListener(final GeckoEventListener listener,
final String... events) {
public void registerGeckoThreadListener(final GeckoEventListener listener,
final String... events) {
checkNotRegistered(mGeckoThreadNativeListeners, events);
registerListener((Class)CopyOnWriteArrayList.class,
@ -123,21 +134,11 @@ public final class EventDispatcher {
}
@Deprecated // Use NativeEventListener instead
private void unregisterGeckoThreadListener(final GeckoEventListener listener,
final String... events) {
public void unregisterGeckoThreadListener(final GeckoEventListener listener,
final String... events) {
unregisterListener(mGeckoThreadJSONListeners, listener, events);
}
@Deprecated // Use one of the variants above.
public void registerEventListener(final String event, final GeckoEventListener listener) {
registerGeckoThreadListener(listener, event);
}
@Deprecated // Use one of the variants above
public void unregisterEventListener(final String event, final GeckoEventListener listener) {
unregisterGeckoThreadListener(listener, event);
}
public void dispatchEvent(final NativeJSContainer message) {
EventCallback callback = null;
try {

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

@ -47,7 +47,7 @@ public class FilePicker implements GeckoEventListener {
protected FilePicker(Context context) {
this.context = context;
GeckoAppShell.getEventDispatcher().registerEventListener("FilePicker:Show", this);
EventDispatcher.getInstance().registerGeckoThreadListener(this, "FilePicker:Show");
}
@Override

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

@ -59,7 +59,7 @@ public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnC
});
mInflated = true;
GeckoAppShell.getEventDispatcher().registerEventListener("TextSelection:Data", this);
EventDispatcher.getInstance().registerGeckoThreadListener(this, "TextSelection:Data");
}
public void show() {
@ -88,7 +88,7 @@ public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnC
if (!mInflated) {
return;
}
GeckoAppShell.getEventDispatcher().unregisterEventListener("TextSelection:Data", this);
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "TextSelection:Data");
}
// TextWatcher implementation

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

@ -85,15 +85,17 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
setFocusable(false);
registerEventListener("FormAssist:AutoComplete");
registerEventListener("FormAssist:ValidationMessage");
registerEventListener("FormAssist:Hide");
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"FormAssist:AutoComplete",
"FormAssist:ValidationMessage",
"FormAssist:Hide");
}
void destroy() {
unregisterEventListener("FormAssist:AutoComplete");
unregisterEventListener("FormAssist:ValidationMessage");
unregisterEventListener("FormAssist:Hide");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"FormAssist:AutoComplete",
"FormAssist:ValidationMessage",
"FormAssist:Hide");
}
@Override
@ -397,12 +399,4 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
return convertView;
}
}
private void registerEventListener(String event) {
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
}
private void unregisterEventListener(String event) {
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
}
}

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

@ -1269,7 +1269,7 @@ public abstract class GeckoApp
// through "onDestroy" -- essentially the same as the lifecycle
// of the activity itself.
final String profilePath = getProfile().getDir().getAbsolutePath();
final EventDispatcher dispatcher = GeckoAppShell.getEventDispatcher();
final EventDispatcher dispatcher = EventDispatcher.getInstance();
Log.i(LOGTAG, "Creating HealthRecorder.");
final String osLocale = Locale.getDefault().toString();
@ -1350,7 +1350,7 @@ public abstract class GeckoApp
if (mLayerView == null) {
LayerView layerView = (LayerView) findViewById(R.id.layer_view);
layerView.initializeView(GeckoAppShell.getEventDispatcher());
layerView.initializeView(EventDispatcher.getInstance());
mLayerView = layerView;
GeckoAppShell.setLayerView(layerView);
// bind the GeckoEditable instance to the new LayerView
@ -1489,33 +1489,34 @@ public abstract class GeckoApp
mAppStateListeners = new LinkedList<GeckoAppShell.AppStateListener>();
//register for events
registerEventListener("log");
registerEventListener("onCameraCapture");
registerEventListener("Gecko:Ready");
registerEventListener("Gecko:DelayedStartup");
registerEventListener("Toast:Show");
registerEventListener("DOMFullScreen:Start");
registerEventListener("DOMFullScreen:Stop");
registerEventListener("ToggleChrome:Hide");
registerEventListener("ToggleChrome:Show");
registerEventListener("ToggleChrome:Focus");
registerEventListener("Permissions:Data");
registerEventListener("Session:StatePurged");
registerEventListener("Bookmark:Insert");
registerEventListener("Accessibility:Event");
registerEventListener("Accessibility:Ready");
registerEventListener("Shortcut:Remove");
registerEventListener("Share:Text");
registerEventListener("Image:SetAs");
registerEventListener("Sanitize:ClearHistory");
registerEventListener("Update:Check");
registerEventListener("Update:Download");
registerEventListener("Update:Install");
registerEventListener("PrivateBrowsing:Data");
registerEventListener("Contact:Add");
registerEventListener("Locale:Set");
registerEventListener("NativeApp:IsDebuggable");
registerEventListener("SystemUI:Visibility");
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"log",
"onCameraCapture",
"Gecko:Ready",
"Gecko:DelayedStartup",
"Toast:Show",
"DOMFullScreen:Start",
"DOMFullScreen:Stop",
"ToggleChrome:Hide",
"ToggleChrome:Show",
"ToggleChrome:Focus",
"Permissions:Data",
"Session:StatePurged",
"Bookmark:Insert",
"Accessibility:Event",
"Accessibility:Ready",
"Shortcut:Remove",
"Share:Text",
"Image:SetAs",
"Sanitize:ClearHistory",
"Update:Check",
"Update:Download",
"Update:Install",
"PrivateBrowsing:Data",
"Contact:Add",
"Locale:Set",
"NativeApp:IsDebuggable",
"SystemUI:Visibility");
EventListener.registerEvents();
@ -1523,14 +1524,14 @@ public abstract class GeckoApp
SmsManager.getInstance().start();
}
mContactService = new ContactService(GeckoAppShell.getEventDispatcher(), this);
mContactService = new ContactService(EventDispatcher.getInstance(), this);
mPromptService = new PromptService(this);
mTextSelection = new TextSelection((TextSelectionHandle) findViewById(R.id.start_handle),
(TextSelectionHandle) findViewById(R.id.middle_handle),
(TextSelectionHandle) findViewById(R.id.end_handle),
GeckoAppShell.getEventDispatcher(),
EventDispatcher.getInstance(),
this);
PrefsHelper.getPref("app.update.autodownload", new PrefsHelper.PrefHandlerBase() {
@ -2022,33 +2023,34 @@ public abstract class GeckoApp
@Override
public void onDestroy()
{
unregisterEventListener("log");
unregisterEventListener("onCameraCapture");
unregisterEventListener("Gecko:Ready");
unregisterEventListener("Gecko:DelayedStartup");
unregisterEventListener("Toast:Show");
unregisterEventListener("DOMFullScreen:Start");
unregisterEventListener("DOMFullScreen:Stop");
unregisterEventListener("ToggleChrome:Hide");
unregisterEventListener("ToggleChrome:Show");
unregisterEventListener("ToggleChrome:Focus");
unregisterEventListener("Permissions:Data");
unregisterEventListener("Session:StatePurged");
unregisterEventListener("Bookmark:Insert");
unregisterEventListener("Accessibility:Event");
unregisterEventListener("Accessibility:Ready");
unregisterEventListener("Shortcut:Remove");
unregisterEventListener("Share:Text");
unregisterEventListener("Image:SetAs");
unregisterEventListener("Sanitize:ClearHistory");
unregisterEventListener("Update:Check");
unregisterEventListener("Update:Download");
unregisterEventListener("Update:Install");
unregisterEventListener("PrivateBrowsing:Data");
unregisterEventListener("Contact:Add");
unregisterEventListener("Locale:Set");
unregisterEventListener("NativeApp:IsDebuggable");
unregisterEventListener("SystemUI:Visibility");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"log",
"onCameraCapture",
"Gecko:Ready",
"Gecko:DelayedStartup",
"Toast:Show",
"DOMFullScreen:Start",
"DOMFullScreen:Stop",
"ToggleChrome:Hide",
"ToggleChrome:Show",
"ToggleChrome:Focus",
"Permissions:Data",
"Session:StatePurged",
"Bookmark:Insert",
"Accessibility:Event",
"Accessibility:Ready",
"Shortcut:Remove",
"Share:Text",
"Image:SetAs",
"Sanitize:ClearHistory",
"Update:Check",
"Update:Download",
"Update:Install",
"PrivateBrowsing:Data",
"Contact:Add",
"Locale:Set",
"NativeApp:IsDebuggable",
"SystemUI:Visibility");
EventListener.unregisterEvents();
@ -2094,14 +2096,6 @@ public abstract class GeckoApp
Tabs.unregisterOnTabsChangedListener(this);
}
protected void registerEventListener(String event) {
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
}
protected void unregisterEventListener(String event) {
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
}
// Get a temporary directory, may return null
public static File getTempDirectory() {
File dir = GeckoApplication.get().getExternalFilesDir("temp");

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

@ -135,8 +135,6 @@ public class GeckoAppShell
static private int sDensityDpi = 0;
static private int sScreenDepth = 0;
private static final EventDispatcher sEventDispatcher = new EventDispatcher();
/* Default colors. */
private static final float[] DEFAULT_LAUNCHER_ICON_HSV = { 32.0f, 1.0f, 1.0f };
@ -2282,34 +2280,6 @@ public class GeckoAppShell
}
}
/**
* Adds a listener for a gecko event.
* This method is thread-safe and may be called at any time. In particular, calling it
* with an event that is currently being processed has the properly-defined behaviour that
* any added listeners will not be invoked on the event currently being processed, but
* will be invoked on future events of that type.
*/
@RobocopTarget
public static void registerEventListener(String event, GeckoEventListener listener) {
sEventDispatcher.registerEventListener(event, listener);
}
public static EventDispatcher getEventDispatcher() {
return sEventDispatcher;
}
/**
* Remove a previously-registered listener for a gecko event.
* This method is thread-safe and may be called at any time. In particular, calling it
* with an event that is currently being processed has the properly-defined behaviour that
* any removed listeners will still be invoked on the event currently being processed, but
* will not be invoked on future events of that type.
*/
@RobocopTarget
public static void unregisterEventListener(String event, GeckoEventListener listener) {
sEventDispatcher.unregisterEventListener(event, listener);
}
/*
* Battery API related methods.
*/
@ -2320,7 +2290,7 @@ public class GeckoAppShell
@WrapElementForJNI(stubName = "HandleGeckoMessageWrapper")
public static void handleGeckoMessage(final NativeJSContainer message) {
sEventDispatcher.dispatchEvent(message);
EventDispatcher.getInstance().dispatchEvent(message);
message.dispose();
}

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

@ -766,13 +766,13 @@ final class GeckoEditable
// cases, and we don't want to unregister an event that was not registered.
mGeckoFocused = false;
mSuppressCompositions = false;
GeckoAppShell.getEventDispatcher().
unregisterEventListener("TextSelection:DraggingHandle", this);
EventDispatcher.getInstance().
unregisterGeckoThreadListener(this, "TextSelection:DraggingHandle");
} else if (type == NOTIFY_IME_OF_FOCUS) {
mGeckoFocused = true;
mSuppressCompositions = false;
GeckoAppShell.getEventDispatcher().
registerEventListener("TextSelection:DraggingHandle", this);
EventDispatcher.getInstance().
registerGeckoThreadListener(this, "TextSelection:DraggingHandle");
}
}

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

@ -73,7 +73,7 @@ public class GeckoThread extends Thread implements GeckoEventListener {
mAction = action;
mUri = uri;
setName("Gecko");
GeckoAppShell.getEventDispatcher().registerEventListener("Gecko:Ready", this);
EventDispatcher.getInstance().registerGeckoThreadListener(this, "Gecko:Ready");
}
public static boolean isCreated() {
@ -179,7 +179,7 @@ public class GeckoThread extends Thread implements GeckoEventListener {
@Override
public void handleMessage(String event, JSONObject message) {
if ("Gecko:Ready".equals(event)) {
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, event);
setLaunchState(LaunchState.GeckoRunning);
GeckoAppShell.sendPendingEventsToGecko();
}

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

@ -93,17 +93,18 @@ public class GeckoView extends LayerView
tabs.attachToContext(context);
}
GeckoAppShell.registerEventListener("Gecko:Ready", this);
GeckoAppShell.registerEventListener("Content:StateChange", this);
GeckoAppShell.registerEventListener("Content:LoadError", this);
GeckoAppShell.registerEventListener("Content:PageShow", this);
GeckoAppShell.registerEventListener("DOMTitleChanged", this);
GeckoAppShell.registerEventListener("Link:Favicon", this);
GeckoAppShell.registerEventListener("Prompt:Show", this);
GeckoAppShell.registerEventListener("Prompt:ShowTop", this);
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"Gecko:Ready",
"Content:StateChange",
"Content:LoadError",
"Content:PageShow",
"DOMTitleChanged",
"Link:Favicon",
"Prompt:Show",
"Prompt:ShowTop");
ThreadUtils.setUiThread(Thread.currentThread(), new Handler());
initializeView(GeckoAppShell.getEventDispatcher());
initializeView(EventDispatcher.getInstance());
if (GeckoThread.checkAndSetLaunchState(GeckoThread.LaunchState.Launching, GeckoThread.LaunchState.Launched)) {
// This is the first launch, so finish initialization and go.

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

@ -36,9 +36,7 @@ public final class IntentHelper implements GeckoEventListener {
private IntentHelper(Activity activity) {
this.activity = activity;
for (String event : EVENTS) {
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
}
EventDispatcher.getInstance().registerGeckoThreadListener(this, EVENTS);
}
public static IntentHelper init(Activity activity) {
@ -53,10 +51,7 @@ public final class IntentHelper implements GeckoEventListener {
public static void destroy() {
if (instance != null) {
for (String event : EVENTS) {
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, instance);
}
EventDispatcher.getInstance().unregisterGeckoThreadListener(instance, EVENTS);
instance = null;
}
}

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

@ -65,7 +65,7 @@ class JavaAddonManager implements GeckoEventListener {
}
private JavaAddonManager() {
mDispatcher = GeckoAppShell.getEventDispatcher();
mDispatcher = EventDispatcher.getInstance();
mAddonCallbacks = new HashMap<String, Map<String, GeckoEventListener>>();
}
@ -75,8 +75,9 @@ class JavaAddonManager implements GeckoEventListener {
return;
}
mApplicationContext = applicationContext;
mDispatcher.registerEventListener("Dex:Load", this);
mDispatcher.registerEventListener("Dex:Unload", this);
mDispatcher.registerGeckoThreadListener(this,
"Dex:Load",
"Dex:Unload");
}
@Override
@ -121,7 +122,7 @@ class JavaAddonManager implements GeckoEventListener {
addonCallbacks = new HashMap<String, GeckoEventListener>();
for (String event : callbacks.keySet()) {
CallbackWrapper wrapper = new CallbackWrapper(callbacks.get(event));
mDispatcher.registerEventListener(event, wrapper);
mDispatcher.registerGeckoThreadListener(wrapper, event);
addonCallbacks.put(event, wrapper);
}
mAddonCallbacks.put(zipFile, addonCallbacks);
@ -134,7 +135,7 @@ class JavaAddonManager implements GeckoEventListener {
return;
}
for (String event : callbacks.keySet()) {
mDispatcher.unregisterEventListener(event, callbacks.get(event));
mDispatcher.unregisterGeckoThreadListener(callbacks.get(event), event);
}
}

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

@ -57,8 +57,9 @@ public class LightweightTheme implements GeckoEventListener {
mListeners = new ArrayList<OnChangeListener>();
// unregister isn't needed as the lifetime is same as the application.
GeckoAppShell.getEventDispatcher().registerEventListener("LightweightTheme:Update", this);
GeckoAppShell.getEventDispatcher().registerEventListener("LightweightTheme:Disable", this);
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"LightweightTheme:Update",
"LightweightTheme:Disable");
}
public void addListener(final OnChangeListener listener) {

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

@ -32,8 +32,9 @@ public class MediaCastingBar extends RelativeLayout implements View.OnClickListe
public MediaCastingBar(Context context, AttributeSet attrs) {
super(context, attrs);
GeckoAppShell.getEventDispatcher().registerEventListener("Casting:Started", this);
GeckoAppShell.getEventDispatcher().registerEventListener("Casting:Stopped", this);
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"Casting:Started",
"Casting:Stopped");
}
public void inflateContent() {
@ -68,8 +69,9 @@ public class MediaCastingBar extends RelativeLayout implements View.OnClickListe
}
public void onDestroy() {
GeckoAppShell.getEventDispatcher().unregisterEventListener("Casting:Started", this);
GeckoAppShell.getEventDispatcher().unregisterEventListener("Casting:Stopped", this);
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"Casting:Started",
"Casting:Stopped");
}
// View.OnClickListener implementation

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

@ -78,15 +78,12 @@ public final class NotificationHelper implements GeckoEventListener {
mInstance = new NotificationHelper();
mContext = context;
mClearableNotifications = new HashSet<String>();
registerEventListener("Notification:Show");
registerEventListener("Notification:Hide");
EventDispatcher.getInstance().registerGeckoThreadListener(mInstance,
"Notification:Show",
"Notification:Hide");
registerReceiver(context);
}
private static void registerEventListener(String event) {
GeckoAppShell.getEventDispatcher().registerEventListener(event, mInstance);
}
@Override
public void handleMessage(String event, JSONObject message) {
if (event.equals("Notification:Show")) {

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

@ -35,21 +35,21 @@ public final class OrderedBroadcastHelper
public OrderedBroadcastHelper(Context context) {
mContext = context;
EventDispatcher dispatcher = GeckoAppShell.getEventDispatcher();
EventDispatcher dispatcher = EventDispatcher.getInstance();
if (dispatcher == null) {
Log.e(LOGTAG, "Gecko event dispatcher must not be null", new RuntimeException());
return;
}
dispatcher.registerEventListener(SEND_EVENT, this);
dispatcher.registerGeckoThreadListener(this, SEND_EVENT);
}
public synchronized void uninit() {
EventDispatcher dispatcher = GeckoAppShell.getEventDispatcher();
EventDispatcher dispatcher = EventDispatcher.getInstance();
if (dispatcher == null) {
Log.e(LOGTAG, "Gecko event dispatcher must not be null", new RuntimeException());
return;
}
dispatcher.unregisterEventListener(SEND_EVENT, this);
dispatcher.unregisterGeckoThreadListener(this, SEND_EVENT);
}
@Override

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

@ -63,7 +63,7 @@ public final class PrefsHelper {
return;
}
GeckoAppShell.getEventDispatcher().registerEventListener("Preferences:Data", new GeckoEventListener() {
EventDispatcher.getInstance().registerGeckoThreadListener(new GeckoEventListener() {
@Override public void handleMessage(String event, JSONObject message) {
try {
PrefHandler callback;
@ -107,7 +107,7 @@ public final class PrefsHelper {
Log.e(LOGTAG, "Error handling Preferences:Data message", e);
}
}
});
}, "Preferences:Data");
sRegistered = true;
}

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

@ -38,26 +38,27 @@ public final class SharedPreferencesHelper
mListeners = new HashMap<String, SharedPreferences.OnSharedPreferenceChangeListener>();
EventDispatcher dispatcher = GeckoAppShell.getEventDispatcher();
EventDispatcher dispatcher = EventDispatcher.getInstance();
if (dispatcher == null) {
Log.e(LOGTAG, "Gecko event dispatcher must not be null", new RuntimeException());
return;
}
dispatcher.registerEventListener("SharedPreferences:Set", this);
dispatcher.registerEventListener("SharedPreferences:Get", this);
dispatcher.registerEventListener("SharedPreferences:Observe", this);
dispatcher.registerGeckoThreadListener(this,
"SharedPreferences:Set",
"SharedPreferences:Get",
"SharedPreferences:Observe");
}
public synchronized void uninit() {
EventDispatcher dispatcher = GeckoAppShell.getEventDispatcher();
EventDispatcher dispatcher = EventDispatcher.getInstance();
if (dispatcher == null) {
Log.e(LOGTAG, "Gecko event dispatcher must not be null", new RuntimeException());
return;
}
dispatcher.unregisterEventListener("SharedPreferences:Set", this);
dispatcher.unregisterEventListener("SharedPreferences:Get", this);
dispatcher.unregisterEventListener("SharedPreferences:Observe", this);
dispatcher.unregisterGeckoThreadListener(this,
"SharedPreferences:Set",
"SharedPreferences:Get",
"SharedPreferences:Observe");
}
private SharedPreferences getSharedPreferences(String branch) {

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

@ -82,30 +82,31 @@ public class Tabs implements GeckoEventListener {
};
private Tabs() {
registerEventListener("Session:RestoreEnd");
registerEventListener("SessionHistory:New");
registerEventListener("SessionHistory:Back");
registerEventListener("SessionHistory:Forward");
registerEventListener("SessionHistory:Goto");
registerEventListener("SessionHistory:Purge");
registerEventListener("Tab:Added");
registerEventListener("Tab:Close");
registerEventListener("Tab:Select");
registerEventListener("Content:LocationChange");
registerEventListener("Content:SecurityChange");
registerEventListener("Content:ReaderEnabled");
registerEventListener("Content:StateChange");
registerEventListener("Content:LoadError");
registerEventListener("Content:PageShow");
registerEventListener("DOMContentLoaded");
registerEventListener("DOMTitleChanged");
registerEventListener("Link:Favicon");
registerEventListener("Link:Feed");
registerEventListener("Link:OpenSearch");
registerEventListener("DesktopMode:Changed");
registerEventListener("Tab:ViewportMetadata");
registerEventListener("Tab:StreamStart");
registerEventListener("Tab:StreamStop");
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"Session:RestoreEnd",
"SessionHistory:New",
"SessionHistory:Back",
"SessionHistory:Forward",
"SessionHistory:Goto",
"SessionHistory:Purge",
"Tab:Added",
"Tab:Close",
"Tab:Select",
"Content:LocationChange",
"Content:SecurityChange",
"Content:ReaderEnabled",
"Content:StateChange",
"Content:LoadError",
"Content:PageShow",
"DOMContentLoaded",
"DOMTitleChanged",
"Link:Favicon",
"Link:Feed",
"Link:OpenSearch",
"DesktopMode:Changed",
"Tab:ViewportMetadata",
"Tab:StreamStart",
"Tab:StreamStop");
}
@ -636,10 +637,6 @@ public class Tabs implements GeckoEventListener {
backgroundHandler.postDelayed(mPersistTabsRunnable, PERSIST_TABS_AFTER_MILLISECONDS);
}
private void registerEventListener(String event) {
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
}
/**
* Looks for an open tab with the given URL.
* @param url the URL of the tab we're looking for

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

@ -91,20 +91,22 @@ class TextSelection extends Layer implements GeckoEventListener {
if (mStartHandle == null || mMiddleHandle == null || mEndHandle == null) {
Log.e(LOGTAG, "Failed to initialize text selection because at least one handle is null");
} else {
registerEventListener("TextSelection:ShowHandles");
registerEventListener("TextSelection:HideHandles");
registerEventListener("TextSelection:PositionHandles");
registerEventListener("TextSelection:Update");
registerEventListener("TextSelection:DraggingHandle");
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"TextSelection:ShowHandles",
"TextSelection:HideHandles",
"TextSelection:PositionHandles",
"TextSelection:Update",
"TextSelection:DraggingHandle");
}
}
void destroy() {
unregisterEventListener("TextSelection:ShowHandles");
unregisterEventListener("TextSelection:HideHandles");
unregisterEventListener("TextSelection:PositionHandles");
unregisterEventListener("TextSelection:Update");
unregisterEventListener("TextSelection:DraggingHandle");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"TextSelection:ShowHandles",
"TextSelection:HideHandles",
"TextSelection:PositionHandles",
"TextSelection:Update",
"TextSelection:DraggingHandle");
}
private TextSelectionHandle getHandle(String name) {
@ -243,14 +245,6 @@ class TextSelection extends Layer implements GeckoEventListener {
});
}
private void registerEventListener(String event) {
mEventDispatcher.registerEventListener(event, this);
}
private void unregisterEventListener(String event) {
mEventDispatcher.unregisterEventListener(event, this);
}
private class TextSelectionActionModeCallback implements Callback {
private JSONArray mItems;
private ActionModeCompat mActionMode;

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

@ -146,9 +146,10 @@ class JavaPanZoomController
setState(PanZoomState.NOTHING);
mEventDispatcher = eventDispatcher;
registerEventListener(MESSAGE_ZOOM_RECT);
registerEventListener(MESSAGE_ZOOM_PAGE);
registerEventListener(MESSAGE_TOUCH_LISTENER);
mEventDispatcher.registerGeckoThreadListener(this,
MESSAGE_ZOOM_RECT,
MESSAGE_ZOOM_PAGE,
MESSAGE_TOUCH_LISTENER);
mMode = AxisLockMode.STANDARD;
@ -193,9 +194,10 @@ class JavaPanZoomController
@Override
public void destroy() {
unregisterEventListener(MESSAGE_ZOOM_RECT);
unregisterEventListener(MESSAGE_ZOOM_PAGE);
unregisterEventListener(MESSAGE_TOUCH_LISTENER);
mEventDispatcher.unregisterGeckoThreadListener(this,
MESSAGE_ZOOM_RECT,
MESSAGE_ZOOM_PAGE,
MESSAGE_TOUCH_LISTENER);
mSubscroller.destroy();
mTouchEventHandler.destroy();
}
@ -207,14 +209,6 @@ class JavaPanZoomController
return -t*t+1;
}
private void registerEventListener(String event) {
mEventDispatcher.registerEventListener(event, this);
}
private void unregisterEventListener(String event) {
mEventDispatcher.unregisterEventListener(event, this);
}
private void setState(PanZoomState state) {
if (state != mState) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("PanZoom:StateChange", state.toString()));

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

@ -30,13 +30,13 @@ class NativePanZoomController implements PanZoomController, GeckoEventListener {
if (GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) {
init();
} else {
mDispatcher.registerEventListener("Gecko:Ready", this);
mDispatcher.registerGeckoThreadListener(this, "Gecko:Ready");
}
}
public void handleMessage(String event, JSONObject message) {
if ("Gecko:Ready".equals(event)) {
mDispatcher.unregisterEventListener("Gecko:Ready", this);
mDispatcher.unregisterGeckoThreadListener(this, "Gecko:Ready");
init();
}
}

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

@ -54,23 +54,17 @@ class SubdocumentScrollHelper implements GeckoEventListener {
mPendingDisplacement = new PointF();
mEventDispatcher = eventDispatcher;
registerEventListener(MESSAGE_PANNING_OVERRIDE);
registerEventListener(MESSAGE_CANCEL_OVERRIDE);
registerEventListener(MESSAGE_SCROLL_ACK);
mEventDispatcher.registerGeckoThreadListener(this,
MESSAGE_PANNING_OVERRIDE,
MESSAGE_CANCEL_OVERRIDE,
MESSAGE_SCROLL_ACK);
}
void destroy() {
unregisterEventListener(MESSAGE_PANNING_OVERRIDE);
unregisterEventListener(MESSAGE_CANCEL_OVERRIDE);
unregisterEventListener(MESSAGE_SCROLL_ACK);
}
private void registerEventListener(String event) {
mEventDispatcher.registerEventListener(event, this);
}
private void unregisterEventListener(String event) {
mEventDispatcher.unregisterEventListener(event, this);
mEventDispatcher.unregisterGeckoThreadListener(this,
MESSAGE_PANNING_OVERRIDE,
MESSAGE_CANCEL_OVERRIDE,
MESSAGE_SCROLL_ACK);
}
boolean scrollBy(PointF displacement) {

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

@ -193,12 +193,13 @@ public class BrowserHealthRecorder implements HealthRecorder, GeckoEventListener
if (state != State.INITIALIZED) {
return;
}
this.dispatcher.unregisterEventListener(EVENT_SNAPSHOT, this);
this.dispatcher.unregisterEventListener(EVENT_ADDONS_CHANGE, this);
this.dispatcher.unregisterEventListener(EVENT_ADDONS_UNINSTALLING, this);
this.dispatcher.unregisterEventListener(EVENT_PREF_CHANGE, this);
this.dispatcher.unregisterEventListener(EVENT_KEYWORD_SEARCH, this);
this.dispatcher.unregisterEventListener(EVENT_SEARCH, this);
dispatcher.unregisterGeckoThreadListener(this,
EVENT_SNAPSHOT,
EVENT_ADDONS_CHANGE,
EVENT_ADDONS_UNINSTALLING,
EVENT_PREF_CHANGE,
EVENT_KEYWORD_SEARCH,
EVENT_SEARCH);
}
public void onAppLocaleChanged(String to) {
@ -459,9 +460,10 @@ public class BrowserHealthRecorder implements HealthRecorder, GeckoEventListener
try {
// Listen for add-ons and prefs changes.
dispatcher.registerEventListener(EVENT_ADDONS_UNINSTALLING, self);
dispatcher.registerEventListener(EVENT_ADDONS_CHANGE, self);
dispatcher.registerEventListener(EVENT_PREF_CHANGE, self);
dispatcher.registerGeckoThreadListener(self,
EVENT_ADDONS_UNINSTALLING,
EVENT_ADDONS_CHANGE,
EVENT_PREF_CHANGE);
// Initialize each provider here.
initializeSessionsProvider();
@ -526,7 +528,7 @@ public class BrowserHealthRecorder implements HealthRecorder, GeckoEventListener
profileCache.setDistributionString(desc.id, desc.version);
}
Log.d(LOG_TAG, "Requesting all add-ons and FHR prefs from Gecko.");
dispatcher.registerEventListener(EVENT_SNAPSHOT, self);
dispatcher.registerGeckoThreadListener(self, EVENT_SNAPSHOT);
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("HealthReport:RequestSnapshot", null));
}
});
@ -669,8 +671,9 @@ public class BrowserHealthRecorder implements HealthRecorder, GeckoEventListener
// Do this here, rather than in a centralized registration spot, in
// case the above throws and we wind up handling events that we can't
// store.
this.dispatcher.registerEventListener(EVENT_KEYWORD_SEARCH, this);
this.dispatcher.registerEventListener(EVENT_SEARCH, this);
this.dispatcher.registerGeckoThreadListener(this,
EVENT_KEYWORD_SEARCH,
EVENT_SEARCH);
}
/**

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

@ -9,6 +9,7 @@ import android.content.ContentProviderClient;
import android.content.Context;
import android.util.Log;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoProfile;
@ -42,7 +43,7 @@ public class BrowserHealthReporter implements GeckoEventListener {
protected final Context context;
public BrowserHealthReporter() {
GeckoAppShell.registerEventListener(EVENT_REQUEST, this);
EventDispatcher.getInstance().registerGeckoThreadListener(this, EVENT_REQUEST);
context = GeckoAppShell.getContext();
if (context == null) {
@ -51,7 +52,7 @@ public class BrowserHealthReporter implements GeckoEventListener {
}
public void uninit() {
GeckoAppShell.unregisterEventListener(EVENT_REQUEST, this);
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, EVENT_REQUEST);
}
/**

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

@ -5,6 +5,7 @@
package org.mozilla.gecko.home;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.PrefsHelper;
@ -250,7 +251,8 @@ public class BrowserSearch extends HomeFragment
public void onDestroyView() {
super.onDestroyView();
unregisterEventListener("SearchEngines:Data");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"SearchEngines:Data");
mList.setAdapter(null);
mList = null;
@ -321,7 +323,8 @@ public class BrowserSearch extends HomeFragment
});
registerForContextMenu(mList);
registerEventListener("SearchEngines:Data");
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"SearchEngines:Data");
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:GetVisible", null));
}
@ -707,14 +710,6 @@ public class BrowserSearch extends HomeFragment
return (TextUtils.isEmpty(mSearchTerm) || mSuggestClient == null || !mSuggestionsEnabled) ? 0 : 1;
}
private void registerEventListener(String eventName) {
GeckoAppShell.registerEventListener(eventName, this);
}
private void unregisterEventListener(String eventName) {
GeckoAppShell.unregisterEventListener(eventName, this);
}
private void restartSearchLoader() {
SearchLoader.restart(getLoaderManager(), LOADER_ID_SEARCH, mCursorLoaderCallbacks, mSearchTerm);
}

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

@ -7,6 +7,7 @@ package org.mozilla.gecko.home;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.R;
@ -118,14 +119,14 @@ public class HomeBanner extends LinearLayout
}
});
GeckoAppShell.getEventDispatcher().registerEventListener("HomeBanner:Data", this);
EventDispatcher.getInstance().registerGeckoThreadListener(this, "HomeBanner:Data");
}
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
GeckoAppShell.getEventDispatcher().unregisterEventListener("HomeBanner:Data", this);
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "HomeBanner:Data");
}
@Override

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

@ -17,7 +17,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.db.HomeProvider;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.home.HomeConfig.PanelConfig;
import org.mozilla.gecko.home.PanelInfoManager.PanelInfo;
import org.mozilla.gecko.home.PanelInfoManager.RequestCallback;
@ -85,10 +85,11 @@ public class HomePanelsManager implements GeckoEventListener {
mContext = context;
mHomeConfig = HomeConfig.getDefault(context);
GeckoAppShell.getEventDispatcher().registerEventListener(EVENT_HOMEPANELS_INSTALL, this);
GeckoAppShell.getEventDispatcher().registerEventListener(EVENT_HOMEPANELS_UNINSTALL, this);
GeckoAppShell.getEventDispatcher().registerEventListener(EVENT_HOMEPANELS_UPDATE, this);
GeckoAppShell.getEventDispatcher().registerEventListener(EVENT_HOMEPANELS_REFRESH, this);
EventDispatcher.getInstance().registerGeckoThreadListener(this,
EVENT_HOMEPANELS_INSTALL,
EVENT_HOMEPANELS_UNINSTALL,
EVENT_HOMEPANELS_UPDATE,
EVENT_HOMEPANELS_REFRESH);
}
public void onLocaleReady(final String locale) {

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

@ -13,6 +13,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.home.HomeConfig.PanelConfig;
@ -77,7 +78,8 @@ public class PanelInfoManager implements GeckoEventListener {
synchronized(sCallbacks) {
// If there are no pending callbacks, register the event listener.
if (sCallbacks.size() == 0) {
GeckoAppShell.getEventDispatcher().registerEventListener("HomePanels:Data", this);
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"HomePanels:Data");
}
sCallbacks.put(requestId, callback);
}
@ -135,7 +137,8 @@ public class PanelInfoManager implements GeckoEventListener {
// Unregister the event listener if there are no more pending callbacks.
if (sCallbacks.size() == 0) {
GeckoAppShell.getEventDispatcher().unregisterEventListener("HomePanels:Data", this);
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"HomePanels:Data");
}
}

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

@ -11,6 +11,7 @@ import java.util.List;
import org.json.JSONObject;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.DataReportingNotification;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoActivityStatus;
import org.mozilla.gecko.GeckoApp;
import org.mozilla.gecko.GeckoAppShell;
@ -145,7 +146,8 @@ public class GeckoPreferences
addPreferencesFromResource(res);
}
registerEventListener("Sanitize:Finished");
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"Sanitize:Finished");
// Add handling for long-press click.
// This is only for Android 3.0 and below (which use the long-press-context-menu paradigm).
@ -223,7 +225,8 @@ public class GeckoPreferences
@Override
protected void onDestroy() {
super.onDestroy();
unregisterEventListener("Sanitize:Finished");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"Sanitize:Finished");
if (mPrefsRequestId > 0) {
PrefsHelper.removeObserver(mPrefsRequestId);
}
@ -900,14 +903,6 @@ public class GeckoPreferences
});
}
private void registerEventListener(String event) {
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
}
private void unregisterEventListener(String event) {
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
}
@Override
public boolean isGeckoActivityOpened() {
return false;

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

@ -13,6 +13,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.util.GeckoEventListener;
@ -38,13 +39,13 @@ public class SearchPreferenceCategory extends CustomListCategory implements Geck
super.onAttachedToActivity();
// Register for SearchEngines messages and request list of search engines from Gecko.
GeckoAppShell.registerEventListener("SearchEngines:Data", this);
EventDispatcher.getInstance().registerGeckoThreadListener(this, "SearchEngines:Data");
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:GetVisible", null));
}
@Override
protected void onPrepareForRemoval() {
GeckoAppShell.unregisterEventListener("SearchEngines:Data", this);
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "SearchEngines:Data");
}
@Override

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

@ -21,14 +21,16 @@ public class PromptService implements GeckoEventListener {
private final Context mContext;
public PromptService(Context context) {
GeckoAppShell.getEventDispatcher().registerEventListener("Prompt:Show", this);
GeckoAppShell.getEventDispatcher().registerEventListener("Prompt:ShowTop", this);
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"Prompt:Show",
"Prompt:ShowTop");
mContext = context;
}
public void destroy() {
GeckoAppShell.getEventDispatcher().unregisterEventListener("Prompt:Show", this);
GeckoAppShell.getEventDispatcher().unregisterEventListener("Prompt:ShowTop", this);
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"Prompt:Show",
"Prompt:ShowTop");
}
public void show(final String aTitle, final String aText, final PromptListItem[] aMenuList,

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

@ -12,6 +12,7 @@ import java.util.List;
import org.json.JSONObject;
import org.mozilla.gecko.BrowserApp;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
@ -180,8 +181,9 @@ public class BrowserToolbar extends ThemedRelativeLayout
isSwitchingTabs = true;
isAnimatingEntry = false;
registerEventListener("Reader:Click");
registerEventListener("Reader:LongClick");
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"Reader:Click",
"Reader:LongClick");
final Resources res = getResources();
urlBarViewOffset = res.getDimensionPixelSize(R.dimen.url_bar_offset_left);
@ -1358,8 +1360,9 @@ public class BrowserToolbar extends ThemedRelativeLayout
public void onDestroy() {
Tabs.unregisterOnTabsChangedListener(this);
unregisterEventListener("Reader:Click");
unregisterEventListener("Reader:LongClick");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"Reader:Click",
"Reader:LongClick");
}
public boolean openOptionsMenu() {
@ -1401,14 +1404,6 @@ public class BrowserToolbar extends ThemedRelativeLayout
return true;
}
private void registerEventListener(String event) {
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
}
private void unregisterEventListener(String event) {
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
}
@Override
public void handleMessage(String event, JSONObject message) {
Log.d(LOGTAG, "handleMessage: " + event);

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

@ -5,6 +5,7 @@
package org.mozilla.gecko.toolbar;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.R;
@ -60,8 +61,9 @@ public class PageActionLayout extends LinearLayout implements GeckoEventListener
setNumberShown(DEFAULT_PAGE_ACTIONS_SHOWN);
refreshPageActionIcons();
registerEventListener("PageActions:Add");
registerEventListener("PageActions:Remove");
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"PageActions:Add",
"PageActions:Remove");
}
private void setNumberShown(int count) {
@ -75,16 +77,9 @@ public class PageActionLayout extends LinearLayout implements GeckoEventListener
}
public void onDestroy() {
unregisterEventListener("PageActions:Add");
unregisterEventListener("PageActions:Remove");
}
protected void registerEventListener(String event) {
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
}
protected void unregisterEventListener(String event) {
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"PageActions:Add",
"PageActions:Remove");
}
@Override

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

@ -53,30 +53,26 @@ public class EventListener implements GeckoEventListener {
return mEventListener;
}
private static void registerEventListener(String event) {
GeckoAppShell.getEventDispatcher().registerEventListener(event, EventListener.getEventListener());
}
private static void unregisterEventListener(String event) {
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, EventListener.getEventListener());
}
public static void registerEvents() {
registerEventListener("Webapps:Preinstall");
registerEventListener("Webapps:InstallApk");
registerEventListener("Webapps:Postinstall");
registerEventListener("Webapps:Open");
registerEventListener("Webapps:Uninstall");
registerEventListener("Webapps:GetApkVersions");
EventDispatcher.getInstance().registerGeckoThreadListener(
EventListener.getEventListener(),
"Webapps:Preinstall",
"Webapps:InstallApk",
"Webapps:Postinstall",
"Webapps:Open",
"Webapps:Uninstall",
"Webapps:GetApkVersions");
}
public static void unregisterEvents() {
unregisterEventListener("Webapps:Preinstall");
unregisterEventListener("Webapps:InstallApk");
unregisterEventListener("Webapps:Postinstall");
unregisterEventListener("Webapps:Open");
unregisterEventListener("Webapps:Uninstall");
unregisterEventListener("Webapps:GetApkVersions");
EventDispatcher.getInstance().unregisterGeckoThreadListener(
EventListener.getEventListener(),
"Webapps:Preinstall",
"Webapps:InstallApk",
"Webapps:Postinstall",
"Webapps:Open",
"Webapps:Uninstall",
"Webapps:GetApkVersions");
}
@Override

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

@ -14,6 +14,7 @@ import java.io.OutputStream;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoProfile;
@ -149,9 +150,7 @@ public class InstallHelper implements GeckoEventListener {
}
public void registerGeckoListener() {
for (String eventName : INSTALL_EVENT_NAMES) {
GeckoAppShell.registerEventListener(eventName, this);
}
EventDispatcher.getInstance().registerGeckoThreadListener(this, INSTALL_EVENT_NAMES);
}
private void calculateColor() {
@ -164,9 +163,7 @@ public class InstallHelper implements GeckoEventListener {
@Override
public void handleMessage(String event, JSONObject message) {
for (String eventName : INSTALL_EVENT_NAMES) {
GeckoAppShell.unregisterEventListener(eventName, this);
}
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, INSTALL_EVENT_NAMES);
if (mCallback != null) {
mCallback.installCompleted(this, event, message);