Bug 1365599 - Make Tabs use the window event dispatcher rather than global in some instances. r=jchen

This commit is contained in:
Dylan Roeh 2017-06-16 13:40:48 -05:00
Родитель f900ec65e6
Коммит 31216ace5a
4 изменённых файлов: 25 добавлений и 17 удалений

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

@ -1409,7 +1409,7 @@ public abstract class GeckoApp extends GeckoActivity
"ToggleChrome:Show",
null);
Tabs.getInstance().attachToContext(this, mLayerView);
Tabs.getInstance().attachToContext(this, mLayerView, getAppEventDispatcher());
Tabs.registerOnTabsChangedListener(this);
// Use global layout state change to kick off additional initialization
@ -1503,7 +1503,7 @@ public abstract class GeckoApp extends GeckoActivity
// If we are doing a restore, send the parsed session data to Gecko.
if (!mIsRestoringActivity) {
EventDispatcher.getInstance().dispatch("Session:Restore", restoreMessage);
getAppEventDispatcher().dispatch("Session:Restore", restoreMessage);
}
// Make sure sessionstore.old is either updated or deleted as necessary.
@ -2480,6 +2480,7 @@ public abstract class GeckoApp extends GeckoActivity
super.onDestroy();
Tabs.unregisterOnTabsChangedListener(this);
Tabs.getInstance().detachFromContext();
if (mShutdownOnDestroy) {
GeckoApplication.shutdown(!mRestartOnShutdown ? null : new Intent(

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

@ -102,6 +102,7 @@ public class Tabs implements BundleEventListener {
private volatile boolean mInitialTabsAdded;
private Context mAppContext;
private EventDispatcher mEventDispatcher;
private LayerView mLayerView;
private ContentObserver mBookmarksContentObserver;
private PersistTabsRunnable mPersistTabsRunnable;
@ -166,18 +167,11 @@ public class Tabs implements BundleEventListener {
mPrivateClearColor = Color.RED;
}
public synchronized void attachToContext(Context context, LayerView layerView) {
public synchronized void attachToContext(Context context, LayerView layerView, EventDispatcher eventDispatcher) {
final Context appContext = context.getApplicationContext();
if (mAppContext == appContext) {
return;
}
if (mAppContext != null) {
// This should never happen.
Log.w(LOGTAG, "The application context has changed!");
}
mAppContext = appContext;
mEventDispatcher = eventDispatcher;
mLayerView = layerView;
mPrivateClearColor = ContextCompat.getColor(context, R.color.tabs_tray_grey_pressed);
mAccountManager = AccountManager.get(appContext);
@ -199,6 +193,10 @@ public class Tabs implements BundleEventListener {
}
}
public void detachFromContext() {
mLayerView = null;
}
/**
* Gets the tab count corresponding to the category and private state of the
* selected tab.
@ -333,6 +331,7 @@ public class Tabs implements BundleEventListener {
// Pass a message to Gecko to update tab state in BrowserApp.
final GeckoBundle data = new GeckoBundle(1);
data.putInt("id", tab.getId());
mEventDispatcher.dispatch("Tab:Selected", data);
EventDispatcher.getInstance().dispatch("Tab:Selected", data);
return tab;
}
@ -474,7 +473,7 @@ public class Tabs implements BundleEventListener {
final GeckoBundle data = new GeckoBundle(2);
data.putInt("tabId", tabId);
data.putBoolean("showUndoToast", showUndoToast);
EventDispatcher.getInstance().dispatch("Tab:Closed", data);
mEventDispatcher.dispatch("Tab:Closed", data);
}
/** Return the tab that will be selected by default after this one is closed */
@ -1088,7 +1087,7 @@ public class Tabs implements BundleEventListener {
}
}
EventDispatcher.getInstance().dispatch("Tab:Load", data);
mEventDispatcher.dispatch("Tab:Load", data);
if (tabToSelect == null) {
return null;
@ -1282,7 +1281,7 @@ public class Tabs implements BundleEventListener {
data.putInt("fromPosition", fromPosition);
data.putInt("toTabId", toTabId);
data.putInt("toPosition", toPosition);
EventDispatcher.getInstance().dispatch("Tab:Move", data);
mEventDispatcher.dispatch("Tab:Move", data);
}
/**

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

@ -87,7 +87,7 @@ var FindHelper = {
this._initialViewport = JSON.stringify(this._targetTab.getViewport());
this._viewportChanged = false;
GlobalEventDispatcher.registerListener(this, [
WindowEventDispatcher.registerListener(this, [
"Tab:Selected",
]);
},
@ -109,7 +109,7 @@ var FindHelper = {
this._initialViewport = null;
this._viewportChanged = false;
GlobalEventDispatcher.unregisterListener(this, [
WindowEventDispatcher.unregisterListener(this, [
"Tab:Selected",
]);
},

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

@ -388,11 +388,15 @@ var BrowserApp = {
Services.androidBridge.browserApp = this;
GlobalEventDispatcher.registerListener(this, [
WindowEventDispatcher.registerListener(this, [
"Session:Restore",
"Tab:Load",
"Tab:Selected",
"Tab:Closed",
"Tab:Move",
]);
GlobalEventDispatcher.registerListener(this, [
"Browser:LoadManifest",
"Browser:Quit",
"Fonts:Reload",
@ -1850,6 +1854,10 @@ var BrowserApp = {
break;
}
case "Session:Restore":
GlobalEventDispatcher.dispatch("Session:Restore", data);
break;
case "Session:Stop":
browser.stop();
break;