Bug 1359531 - Part 1 - Call GeckoApp's tab event handler from web apps/custom tabs, too. r?sebastian,walkingice draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 28 Apr 2017 20:16:19 +0200
changeset 582509 7df2de7005f7abaa601494e0ac0243bc611544d0
parent 582508 a5f346ba3b45efa8b96890301a331ac4b9c00354
child 582510 7b7e51f8e58974133731a5e260292d61b8de2aa4
push id60121
push usermozilla@buttercookie.de
push dateMon, 22 May 2017 19:37:24 +0000
reviewerssebastian, walkingice
bugs1359531
milestone55.0a1
Bug 1359531 - Part 1 - Call GeckoApp's tab event handler from web apps/custom tabs, too. r?sebastian,walkingice We want to move the activity switching code into the activity (i.e. GeckoApp) itself and run it from its onTabChanged handler in response to the appropriate events (at the moment that's only SELECTED), so we need to ensure that this will actually be called within custom tabs/web apps as well. Additionally, there's no need to separately register the tab events listener from the CustomTabs/WebAppActivity as well if our parent class already does it for us. MozReview-Commit-ID: 6PIq1KncDcA
mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -80,18 +80,16 @@ public class CustomTabsActivity extends 
         setSupportActionBar(toolbar);
         final ActionBar actionBar = getSupportActionBar();
         bindNavigationCallback(toolbar);
 
         actionBarPresenter = new ActionBarPresenter(actionBar, getActionBarTextColor());
         actionBarPresenter.displayUrlOnly(intent.getDataString());
         actionBarPresenter.setBackgroundColor(IntentUtil.getToolbarColor(intent), getWindow());
         actionBarPresenter.setTextLongClickListener(new UrlCopyListener());
-
-        Tabs.registerOnTabsChangedListener(this);
     }
 
     @Override
     protected void onTabOpenFromIntent(Tab tab) {
         super.onTabOpenFromIntent(tab);
 
         final String host = getReferrerHost();
         recordCustomTabUsage(host);
@@ -178,33 +176,29 @@ public class CustomTabsActivity extends 
     }
 
     @Override
     protected int getNewTabFlags() {
         return Tabs.LOADURL_CUSTOMTAB | super.getNewTabFlags();
     }
 
     @Override
-    public void onDestroy() {
-        super.onDestroy();
-        Tabs.unregisterOnTabsChangedListener(this);
-    }
-
-    @Override
     public int getLayout() {
         return R.layout.customtabs_activity;
     }
 
     @Override
     public View getDoorhangerOverlay() {
         return doorhangerOverlay;
     }
 
     @Override
     public void onTabChanged(Tab tab, TabEvents msg, String data) {
+        super.onTabChanged(tab, msg, data);
+
         if (!Tabs.getInstance().isSelectedTab(tab) ||
                 tab.getType() != Tab.TabType.CUSTOMTAB) {
             return;
         }
 
         if (msg == TabEvents.START
                 || msg == TabEvents.STOP
                 || msg == TabEvents.ADDED
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
@@ -91,18 +91,16 @@ public class WebAppActivity extends Sing
 
         final View customView = actionBar.getCustomView();
         mUrlView = (TextView) customView.findViewById(R.id.webapps_action_bar_url);
 
         EventDispatcher.getInstance().registerUiThreadListener(this,
                 "Website:AppEntered",
                 "Website:AppLeft",
                 null);
-
-        Tabs.registerOnTabsChangedListener(this);
     }
 
     @Override
     public View getDoorhangerOverlay() {
         return doorhangerOverlay;
     }
 
     @Override
@@ -128,16 +126,18 @@ public class WebAppActivity extends Sing
             case "Website:AppLeft":
                 getSupportActionBar().show();
                 break;
         }
     }
 
     @Override
     public void onTabChanged(Tab tab, Tabs.TabEvents msg, String data) {
+        super.onTabChanged(tab, msg, data);
+
         if (tab == null || !Tabs.getInstance().isSelectedTab(tab) ||
                 tab.getType() != Tab.TabType.WEBAPP) {
             return;
         }
 
         if (msg == TabEvents.LOCATION_CHANGE ||
                 msg == TabEvents.SELECTED) {
             mUrlView.setText(tab.getURL());
@@ -153,17 +153,16 @@ public class WebAppActivity extends Sing
 
     @Override
     public void onDestroy() {
         super.onDestroy();
         EventDispatcher.getInstance().unregisterUiThreadListener(this,
                 "Website:AppEntered",
                 "Website:AppLeft",
                 null);
-        Tabs.unregisterOnTabsChangedListener(this);
     }
 
     @Override
     protected int getNewTabFlags() {
         return Tabs.LOADURL_WEBAPP | super.getNewTabFlags();
     }
 
     @Override