Bug 1352997 - Part 1 - Register GeckoApp's onTabsChangedListener earlier. r?sebastian,walkingice
For BrowserApp we want to switch the last selected tab tracking to use tab selection events instead, so we need to register the listener earlier in order to catch the initial selection of the startup tab as well.
MozReview-Commit-ID: F7luIE6oNK
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -348,16 +348,21 @@ public class BrowserApp extends GeckoApp
} else {
view = super.onCreateView(name, context, attrs);
}
return view;
}
@Override
public void onTabChanged(Tab tab, TabEvents msg, String data) {
+ if (!mInitialized) {
+ super.onTabChanged(tab, msg, data);
+ return;
+ }
+
if (tab == null) {
// Only RESTORED is allowed a null tab: it's the only event that
// isn't tied to a specific tab.
if (msg != Tabs.TabEvents.RESTORED) {
throw new IllegalArgumentException("onTabChanged:" + msg + " must specify a tab.");
}
final Tab selectedTab = Tabs.getInstance().getSelectedTab();
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -413,32 +413,46 @@ public abstract class GeckoApp
// When we're switching activities because of differing tab types,
// the first statement is not true.
switch (msg) {
case UNSELECTED:
break;
case LOCATION_CHANGE:
// We only care about location change for the selected tab.
- if (!Tabs.getInstance().isSelectedTab(tab))
- break;
- // Fall through...
+ if (Tabs.getInstance().isSelectedTab(tab)) {
+ resetOptionsMenu();
+ resetFormAssistPopup();
+ }
+ break;
+
case SELECTED:
- invalidateOptionsMenu();
- if (mFormAssistPopup != null)
- mFormAssistPopup.hide();
+ resetOptionsMenu();
+ resetFormAssistPopup();
break;
case DESKTOP_MODE_CHANGE:
if (Tabs.getInstance().isSelectedTab(tab))
- invalidateOptionsMenu();
+ resetOptionsMenu();
break;
}
}
+ private void resetOptionsMenu() {
+ if (mInitialized) {
+ invalidateOptionsMenu();
+ }
+ }
+
+ private void resetFormAssistPopup() {
+ if (mInitialized && mFormAssistPopup != null) {
+ mFormAssistPopup.hide();
+ }
+ }
+
public void refreshChrome() { }
@Override
public void invalidateOptionsMenu() {
if (mMenu == null) {
return;
}
@@ -1338,16 +1352,17 @@ public abstract class GeckoApp
"Share:Text",
"SystemUI:Visibility",
"ToggleChrome:Focus",
"ToggleChrome:Hide",
"ToggleChrome:Show",
null);
Tabs.getInstance().attachToContext(this, mLayerView);
+ Tabs.registerOnTabsChangedListener(this);
// Use global layout state change to kick off additional initialization
mMainLayout.getViewTreeObserver().addOnGlobalLayoutListener(this);
if (Versions.preMarshmallow) {
mTextSelection = new ActionBarTextSelection(this, getTextSelectPresenter());
} else {
mTextSelection = new FloatingToolbarTextSelection(this, mLayerView);
@@ -1698,18 +1713,16 @@ public abstract class GeckoApp
final String passedUri = getIntentURI(intent);
final boolean isExternalURL = invokedWithExternalURL(passedUri);
// Start migrating as early as possible, can do this in
// parallel with Gecko load.
checkMigrateProfile();
- Tabs.registerOnTabsChangedListener(this);
-
initializeChrome();
// We need to wait here because mShouldRestore can revert back to
// false if a parsing error occurs and the startup tab we load
// depends on whether we restore tabs or not.
synchronized (this) {
while (!mSessionRestoreParsingFinished) {
try {