Bug 1346004 - Part 1 - Keep track of a tab type on the Java tab object. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 11 Mar 2017 20:04:07 +0100
changeset 501095 155a8d2f906b45a8516a3f592afd121515121011
parent 501089 5e7031ef88f33036a0eae4c0d7d0933925b385f8
child 501096 bb7a0b141b355616c8bbe809c080ab7d23a11dcd
push id49873
push usermozilla@buttercookie.de
push dateSat, 18 Mar 2017 12:30:32 +0000
reviewerssebastian
bugs1346004
milestone55.0a1
Bug 1346004 - Part 1 - Keep track of a tab type on the Java tab object. r?sebastian As long as the tabs are opened in the same Gecko browser window, splitting the Java UI tabs list into multiple parts breaks too many assumptions, so the easier solution is to allow setting a type attribute on each tabs object, which will allow filtering of the tabs later on. MozReview-Commit-ID: 1PbxMkWTK47
mobile/android/base/java/org/mozilla/gecko/Tab.java
mobile/android/base/java/org/mozilla/gecko/Tabs.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/java/org/mozilla/gecko/Tab.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tab.java
@@ -33,21 +33,24 @@ import android.graphics.Bitmap;
 import android.graphics.drawable.BitmapDrawable;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.View;
 
+import static org.mozilla.gecko.Tab.TabType.BROWSING;
+
 public class Tab {
     private static final String LOGTAG = "GeckoTab";
 
     private static Pattern sColorPattern;
     private final int mId;
+    private TabType mType;
     private final BrowserDB mDB;
     private long mLastUsed;
     private String mUrl;
     private String mBaseDomain;
     private String mUserRequested; // The original url requested. May be typed by the user or sent by an extneral app for example.
     private String mTitle;
     private Bitmap mFavicon;
     private String mFaviconUrl;
@@ -117,16 +120,17 @@ public class Tab {
         NET_ERROR,   // All other types of error
         NONE         // Non error pages
     }
 
     public Tab(Context context, int id, String url, boolean external, int parentId, String title) {
         mAppContext = context.getApplicationContext();
         mDB = BrowserDB.from(context);
         mId = id;
+        mType = BROWSING;
         mUrl = url;
         mBaseDomain = "";
         mUserRequested = "";
         mExternal = external;
         mParentId = parentId;
         mTitle = title == null ? "" : title;
         mSiteIdentity = new SiteIdentity();
         mContentType = "";
@@ -760,16 +764,30 @@ public class Tab {
     public boolean getDesktopMode() {
         return mDesktopMode;
     }
 
     public boolean isPrivate() {
         return false;
     }
 
+    public void setType(TabType type) {
+        mType = type;
+    }
+
+    public TabType getType() {
+        return mType;
+    }
+
+    public enum TabType {
+        BROWSING,
+        CUSTOMTAB,
+        WEBAPP
+    }
+
     /**
      * Sets the tab load progress to the given percentage.
      *
      * @param progressPercentage Percentage to set progress to (0-100)
      */
     void setLoadProgress(int progressPercentage) {
         mLoadProgress = progressPercentage;
     }
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -37,16 +37,18 @@ import android.database.sqlite.SQLiteExc
 import android.graphics.Color;
 import android.net.Uri;
 import android.os.Handler;
 import android.provider.Browser;
 import android.support.annotation.UiThread;
 import android.support.v4.content.ContextCompat;
 import android.util.Log;
 
+import static org.mozilla.gecko.Tab.TabType;
+
 public class Tabs implements BundleEventListener {
     private static final String LOGTAG = "GeckoTabs";
 
     // mOrder and mTabs are always of the same cardinality, and contain the same values.
     private volatile CopyOnWriteArrayList<Tab> mOrder = new CopyOnWriteArrayList<Tab>();
 
     // A cache that maps a tab ID to an mOrder tab position.  All access should be synchronized.
     private final TabPositionCache tabPositionCache = new TabPositionCache();
@@ -225,19 +227,20 @@ public class Tabs implements BundleEvent
             };
 
             // It's safe to use the db here since we aren't doing any I/O.
             final GeckoProfile profile = GeckoProfile.get(mAppContext);
             BrowserDB.from(profile).registerBookmarkObserver(getContentResolver(), mBookmarksContentObserver);
         }
     }
 
-    private Tab addTab(int id, String url, boolean external, int parentId, String title, boolean isPrivate, int tabIndex) {
+    private Tab addTab(int id, String url, boolean external, int parentId, String title, boolean isPrivate, int tabIndex, TabType type) {
         final Tab tab = isPrivate ? new PrivateTab(mAppContext, id, url, external, parentId, title) :
                                     new Tab(mAppContext, id, url, external, parentId, title);
+        tab.setType(type);
         synchronized (this) {
             lazyRegisterBookmarkObserver();
             mTabs.put(id, tab);
 
             if (tabIndex > -1) {
                 mOrder.add(tabIndex, tab);
                 if (tabPositionCache.mOrderPosition >= tabIndex) {
                     tabPositionCache.mTabId = INVALID_TAB_ID;
@@ -530,17 +533,18 @@ public class Tabs implements BundleEvent
                     // Tab was already closed; abort
                     return;
                 }
             } else {
                 tab = addTab(id, url, message.getBoolean("external"),
                                       message.getInt("parentId"),
                                       message.getString("title"),
                                       message.getBoolean("isPrivate"),
-                                      message.getInt("tabIndex"));
+                                      message.getInt("tabIndex"),
+                                      TabType.valueOf(message.getString("tabType")));
                 // If we added the tab as a stub, we should have already
                 // selected it, so ignore this flag for stubbed tabs.
                 if (message.getBoolean("selected"))
                     selectTab(id);
             }
 
             if (message.getBoolean("delayLoad"))
                 tab.setState(Tab.STATE_DELAYED);
@@ -865,27 +869,27 @@ public class Tabs implements BundleEvent
         }
 
         return null;
     }
 
     /**
      * Loads a tab with the given URL in the currently selected tab.
      *
-     * @param url URL of page to load, or search term used if searchEngine is given
+     * @param url URL of page to load
      */
     @RobocopTarget
     public Tab loadUrl(String url) {
         return loadUrl(url, LOADURL_NONE);
     }
 
     /**
      * Loads a tab with the given URL.
      *
-     * @param url   URL of page to load, or search term used if searchEngine is given
+     * @param url   URL of page to load
      * @param flags flags used to load tab
      *
      * @return      the Tab if a new one was created; null otherwise
      */
     @RobocopTarget
     public Tab loadUrl(String url, int flags) {
         return loadUrl(url, null, -1, null, flags);
     }
@@ -929,16 +933,17 @@ public class Tabs implements BundleEvent
         boolean background = delayLoad || (flags & LOADURL_BACKGROUND) != 0;
 
         boolean isPrivate = (flags & LOADURL_PRIVATE) != 0;
         boolean userEntered = (flags & LOADURL_USER_ENTERED) != 0;
         boolean desktopMode = (flags & LOADURL_DESKTOP) != 0;
         boolean external = (flags & LOADURL_EXTERNAL) != 0;
         final boolean isFirstShownAfterActivityUnhidden = (flags & LOADURL_FIRST_AFTER_ACTIVITY_UNHIDDEN) != 0;
         final boolean customTab = (flags & LOADURL_CUSTOMTAB) != 0;
+        final TabType type = customTab ? TabType.CUSTOMTAB : TabType.BROWSING;
 
         data.putString("url", url);
         data.putString("engine", searchEngine);
         data.putInt("parentId", parentId);
         data.putBoolean("userEntered", userEntered);
         data.putBoolean("isPrivate", isPrivate);
         data.putBoolean("pinned", (flags & LOADURL_PINNED) != 0);
         data.putBoolean("desktopMode", desktopMode);
@@ -986,17 +991,17 @@ public class Tabs implements BundleEvent
             // The URL is updated for the tab once Gecko responds with the
             // Tab:Added data. We can preliminarily set the tab's URL as
             // long as it's a valid URI.
             String tabUrl = (url != null && Uri.parse(url).getScheme() != null) ? url : null;
 
             // Add the new tab to the end of the tab order.
             final int tabIndex = -1;
 
-            tabToSelect = addTab(tabId, tabUrl, external, parentId, url, isPrivate, tabIndex);
+            tabToSelect = addTab(tabId, tabUrl, external, parentId, url, isPrivate, tabIndex, type);
             tabToSelect.setDesktopMode(desktopMode);
             tabToSelect.setApplicationId(applicationId);
             if (isFirstShownAfterActivityUnhidden) {
                 // We just opened Firefox so we want to show
                 // the toolbar but not animate it to avoid jank.
                 tabToSelect.setShouldShowToolbarWithoutAnimationOnFirstSelection(true);
             }
         }
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3573,16 +3573,17 @@ Tab.prototype = {
 
       this.desktopMode = ("desktopMode" in aParams) ? aParams.desktopMode : false;
       this._parentId = ("parentId" in aParams && typeof aParams.parentId == "number")
                       ? aParams.parentId : -1;
 
       let message = {
         type: "Tab:Added",
         tabID: this.id,
+        tabType: "BROWSING",
         uri: truncate(uri, MAX_URI_LENGTH),
         parentId: this.parentId,
         tabIndex: ("tabIndex" in aParams) ? aParams.tabIndex : -1,
         external: ("external" in aParams) ? aParams.external : false,
         selected: ("selected" in aParams || aParams.cancelEditMode === true)
                   ? aParams.selected !== false || aParams.cancelEditMode === true : true,
         cancelEditMode: aParams.cancelEditMode === true,
         title: truncate(title, MAX_TITLE_LENGTH),