Bug 877469: Add back "switch to tab" functionality for home page. [r=lucasr]
authorSriram Ramasubramanian <sriram@mozilla.com>
Mon, 10 Jun 2013 17:17:13 -0700
changeset 143395 95d4652040a644772a431aa4d24a68efd7fc6ff7
parent 143394 478e2819dbf732bd594e3fb8c19e2a14234a3c6d
child 143396 13e4b6ac54104dcb5e70ea9aaa7c0866e9dbcb19
push id32723
push useremorley@mozilla.com
push dateWed, 21 Aug 2013 12:10:14 +0000
treeherdermozilla-inbound@ab6bc4d9e4c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs877469
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 877469: Add back "switch to tab" functionality for home page. [r=lucasr]
mobile/android/base/Tabs.java
mobile/android/base/home/TwoLinePageRow.java
--- a/mobile/android/base/Tabs.java
+++ b/mobile/android/base/Tabs.java
@@ -16,16 +16,17 @@ import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.accounts.OnAccountsUpdateListener;
 import android.app.Activity;
 import android.content.ContentResolver;
 import android.database.ContentObserver;
 import android.graphics.Color;
 import android.net.Uri;
 import android.os.Handler;
+import android.text.TextUtils;
 import android.util.Log;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -593,16 +594,31 @@ public class Tabs implements GeckoEventL
         backgroundHandler.postDelayed(mPersistTabsRunnable, PERSIST_TABS_AFTER_MILLISECONDS);
     }
 
     private void registerEventListener(String event) {
         GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
     }
 
     /**
+     * Returns true if any of the tabs has the requested url.
+     * 
+     * @return true if the url is open currently, false otherwise.
+     */
+    public boolean hasUrl(String url) {
+        for (Tab tab : mOrder) {
+            if (TextUtils.equals(tab.getURL(), url)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
      * 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
      */
     public void loadUrl(String url) {
         loadUrl(url, LOADURL_NONE);
     }
 
--- a/mobile/android/base/home/TwoLinePageRow.java
+++ b/mobile/android/base/home/TwoLinePageRow.java
@@ -2,29 +2,28 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.home;
 
 import org.mozilla.gecko.Favicons;
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.db.BrowserDB.URLColumns;
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.widget.FaviconView;
 
 import android.content.Context;
-import android.content.res.TypedArray;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.Gravity;
 import android.view.LayoutInflater;
-import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
 public class TwoLinePageRow extends LinearLayout {
 
     private final TextView mTitle;
     private final TextView mUrl;
     private final FaviconView mFavicon;
@@ -75,19 +74,17 @@ public class TwoLinePageRow extends Line
         int urlIndex = cursor.getColumnIndexOrThrow(URLColumns.URL);
         final String url = cursor.getString(urlIndex);
 
         // Use the URL instead of an empty title for consistency with the normal URL
         // bar view - this is the equivalent of getDisplayTitle() in Tab.java
         setTitle(TextUtils.isEmpty(title) ? url : title);
 
         // Update the url with "Switch to tab" if needed.
-        // FIXME: Bug 877469: Add back switch to tab functionality.
-        Integer tabId = null;
-        if (tabId != null) {
+        if (Tabs.getInstance().hasUrl(url)) {
             setUrl(R.string.switch_to_tab);
             setUrlIcon(R.drawable.ic_url_bar_tab);
         } else {
             setUrl(url);
             setUrlIcon(0);
         }
 
         int faviconIndex = cursor.getColumnIndex(URLColumns.FAVICON);