Bug 729463 - Add back Open in New Tab. r=mfinkle
authorWes Johnston <wjohnston@mozilla.com>
Tue, 30 Apr 2013 10:21:31 -0700
changeset 142408 b7de4b81d211557f23110dbb39465ef22d01dd7b
parent 142407 2834210d62bf428ea1d9a88a2c25b07b29f88419
child 142409 d437af6786ebd3f06f9efff274ab8a7c4cb35af0
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs729463
milestone23.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 729463 - Add back Open in New Tab. r=mfinkle
mobile/android/base/AwesomeBar.java
mobile/android/base/awesomebar/AllPagesTab.java
mobile/android/base/awesomebar/AwesomeBarTab.java
mobile/android/base/awesomebar/BookmarksTab.java
mobile/android/base/awesomebar/HistoryTab.java
mobile/android/base/resources/menu/awesomebar_contextmenu.xml
mobile/android/base/widget/TopSitesView.java
--- a/mobile/android/base/AwesomeBar.java
+++ b/mobile/android/base/AwesomeBar.java
@@ -30,16 +30,17 @@ import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.MenuItem;
+import android.view.MenuInflater;
 import android.view.View;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ImageButton;
 import android.widget.TabWidget;
 import android.widget.Toast;
@@ -586,18 +587,38 @@ public class AwesomeBar extends GeckoAct
         if (mContextMenuSubject == null)
             return false;
 
         final int id = mContextMenuSubject.id;
         final String url = mContextMenuSubject.url;
         final byte[] b = mContextMenuSubject.favicon;
         final String title = mContextMenuSubject.title;
         final String keyword = mContextMenuSubject.keyword;
+        final int display = mContextMenuSubject.display;
 
         switch (item.getItemId()) {
+            case R.id.open_private_tab:
+            case R.id.open_new_tab: {
+                if (url == null) {
+                    Log.e(LOGTAG, "Can't open in new tab because URL is null");
+                    break;
+                }
+
+                String newTabUrl = url;
+                if (display == Combined.DISPLAY_READER)
+                    newTabUrl = ReaderModeUtils.getAboutReaderForUrl(url, true);
+
+                int flags = Tabs.LOADURL_NEW_TAB;
+                if (item.getItemId() == R.id.open_private_tab)
+                    flags |= Tabs.LOADURL_PRIVATE;
+
+                Tabs.getInstance().loadUrl(newTabUrl, flags);
+                Toast.makeText(this, R.string.new_tab_opened, Toast.LENGTH_SHORT).show();
+                break;
+            }
             case R.id.open_in_reader: {
                 if (url == null) {
                     Log.e(LOGTAG, "Can't open in reader mode because URL is null");
                     break;
                 }
 
                 openUrlAndFinish(ReaderModeUtils.getAboutReaderForUrl(url, true));
                 break;
--- a/mobile/android/base/awesomebar/AllPagesTab.java
+++ b/mobile/android/base/awesomebar/AllPagesTab.java
@@ -823,27 +823,22 @@ public class AllPagesTab extends Awesome
 
         ListView list = (ListView)view;
         AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
         subject = ((AwesomeBarItem) list.getItemAtPosition(info.position)).getSubject();
 
         if (subject == null)
             return subject;
 
-        MenuInflater inflater = new MenuInflater(mContext);
-        inflater.inflate(R.menu.awesomebar_contextmenu, menu);
+        setupMenu(menu, subject);
+
         menu.findItem(R.id.remove_bookmark).setVisible(false);
         menu.findItem(R.id.edit_bookmark).setVisible(false);
         menu.findItem(R.id.open_in_reader).setVisible(subject.display == Combined.DISPLAY_READER);
 
-        // Hide "Remove" item if there isn't a valid history ID
-        if (subject.id < 0)
-            menu.findItem(R.id.remove_history).setVisible(false);
-
-        menu.setHeaderTitle(subject.title);
         return subject;
     }
 
     private void registerEventListener(String event) {
         GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
     }
 
     private void unregisterEventListener(String event) {
--- a/mobile/android/base/awesomebar/AwesomeBarTab.java
+++ b/mobile/android/base/awesomebar/AwesomeBarTab.java
@@ -14,16 +14,17 @@ import android.content.ContentResolver;
 import android.content.Context;
 import android.content.res.Resources;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.text.TextUtils;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.LayoutInflater;
+import android.view.MenuInflater;
 import android.view.View;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.ImageView;
 import android.widget.TextView;
 
 import java.util.HashMap;
 
 abstract public class AwesomeBarTab {
@@ -82,17 +83,17 @@ abstract public class AwesomeBarTab {
 
     protected ContentResolver getContentResolver() {
         if (mContentResolver == null) {
             mContentResolver = mContext.getContentResolver();
         }
         return mContentResolver;
     }
 
-    private HashMap<String, Integer> getOpenTabs() {
+    protected HashMap<String, Integer> getOpenTabs() {
         if (sOpenTabs == null || sOpenTabs.isEmpty()) {
             Iterable<Tab> tabs = Tabs.getInstance().getTabsInOrder();
             sOpenTabs = new HashMap<String, Integer>();
             for (Tab tab : tabs) {
                 sOpenTabs.put(tab.getURL(), tab.getId());
             }
         }
         return sOpenTabs;
@@ -100,16 +101,36 @@ abstract public class AwesomeBarTab {
 
     protected Resources getResources() {
         if (mResources == null) {
             mResources = mContext.getResources();
         }
         return mResources;
     }
 
+    protected void setupMenu(ContextMenu menu, AwesomeBar.ContextMenuSubject subject) {
+        MenuInflater inflater = new MenuInflater(mContext);
+        inflater.inflate(R.menu.awesomebar_contextmenu, menu);
+
+        // Show Open Private Tab if we're in private mode, Open New Tab otherwise
+        boolean isPrivate = false;
+        Tab tab = Tabs.getInstance().getSelectedTab();
+        if (tab != null) {
+            isPrivate = tab.isPrivate();
+        }
+        menu.findItem(R.id.open_new_tab).setVisible(!isPrivate);
+        menu.findItem(R.id.open_private_tab).setVisible(isPrivate);
+
+        // Hide "Remove" item if there isn't a valid history ID
+        if (subject.id < 0) {
+            menu.findItem(R.id.remove_history).setVisible(false);
+        }
+        menu.setHeaderTitle(subject.title);
+    }
+
     protected void updateFavicon(FaviconView faviconView, Bitmap bitmap, String key) {
         faviconView.updateImage(bitmap, key);
     }
 
     protected void updateTitle(TextView titleView, Cursor cursor) {
         int titleIndex = cursor.getColumnIndexOrThrow(URLColumns.TITLE);
         String title = cursor.getString(titleIndex);
         String url = "";
--- a/mobile/android/base/awesomebar/BookmarksTab.java
+++ b/mobile/android/base/awesomebar/BookmarksTab.java
@@ -456,18 +456,16 @@ public class BookmarksTab extends Awesom
                                             cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE)),
                                             keyword,
                                             isInReadingList() ? Combined.DISPLAY_READER : Combined.DISPLAY_NORMAL);
         }
 
         if (subject == null)
             return subject;
 
-        MenuInflater inflater = new MenuInflater(mContext);
-        inflater.inflate(R.menu.awesomebar_contextmenu, menu);
+        setupMenu(menu, subject);
         
         menu.findItem(R.id.remove_history).setVisible(false);
         menu.findItem(R.id.open_in_reader).setVisible(false);
-        menu.setHeaderTitle(subject.title);
 
         return subject;
     }
 }
--- a/mobile/android/base/awesomebar/HistoryTab.java
+++ b/mobile/android/base/awesomebar/HistoryTab.java
@@ -439,23 +439,17 @@ public class HistoryTab extends AwesomeB
         @SuppressWarnings("rawtypes")
         Map map = (Map) exList.getExpandableListAdapter().getChild(groupPosition, childPosition);
         subject = new AwesomeBar.ContextMenuSubject((Integer) map.get(Combined.HISTORY_ID),
                                                      (String) map.get(URLColumns.URL),
                                                      (byte[]) map.get(URLColumns.FAVICON),
                                                      (String) map.get(URLColumns.TITLE),
                                                      null);
 
-        MenuInflater inflater = new MenuInflater(mContext);
-        inflater.inflate(R.menu.awesomebar_contextmenu, menu);
-        
+        setupMenu(menu, subject);
+
         menu.findItem(R.id.remove_bookmark).setVisible(false);
         menu.findItem(R.id.edit_bookmark).setVisible(false);
         menu.findItem(R.id.open_in_reader).setVisible(false);
 
-        // Hide "Remove" item if there isn't a valid history ID
-        if (subject.id < 0)
-            menu.findItem(R.id.remove_history).setVisible(false);
-
-        menu.setHeaderTitle(subject.title);
         return subject;
     }
 }
--- a/mobile/android/base/resources/menu/awesomebar_contextmenu.xml
+++ b/mobile/android/base/resources/menu/awesomebar_contextmenu.xml
@@ -1,15 +1,21 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- 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/. -->
 
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
 
+    <item android:id="@+id/open_new_tab"
+          android:title="@string/contextmenu_open_new_tab"/>
+
+    <item android:id="@+id/open_private_tab"
+          android:title="@string/contextmenu_open_private_tab"/>
+
     <item android:id="@+id/open_in_reader"
           android:title="@string/contextmenu_open_in_reader"/>
 
     <item android:id="@+id/share"
           android:title="@string/contextmenu_share"/>
 
     <item android:id="@+id/edit_bookmark"
           android:title="@string/contextmenu_edit_bookmark"/>
--- a/mobile/android/base/widget/TopSitesView.java
+++ b/mobile/android/base/widget/TopSitesView.java
@@ -378,45 +378,49 @@ public class TopSitesView extends GridVi
 
         public TopSitesViewHolder(View v) {
             titleView = (TextView) v.findViewById(R.id.title);
             thumbnailView = (ImageView) v.findViewById(R.id.thumbnail);
             pinnedView = (ImageView) v.findViewById(R.id.pinned);
         }
 
         public void setTitle(String title) {
+            Log.i(LOGTAG, "setTitle " + title + " from " + mTitle);
             if (mTitle != null && mTitle.equals(title))
                 return;
             mTitle = title;
             updateTitleView();
         }
 
         public String getTitle() {
             return (!TextUtils.isEmpty(mTitle) ? mTitle : mUrl);
         }
 
         public void setUrl(String url) {
-            if (mUrl != null && mUrl.equals(url))
+            Log.i(LOGTAG, "setUrl " + url + " from " + mUrl);
+            if (mUrl != null && mUrl.equals(url)) {
                 return;
+            }
             mUrl = url;
             updateTitleView();
         }
 
         public String getUrl() {
             return mUrl;
         }
 
         public void updateTitleView() {
             String title = getTitle();
             if (!TextUtils.isEmpty(title)) {
                 titleView.setText(title);
                 titleView.setVisibility(View.VISIBLE);
             } else {
                 titleView.setVisibility(View.INVISIBLE);
             }
+            titleView.invalidate();
         }
 
         private Drawable getPinDrawable() {
             if (sPinDrawable == null) {
                 int size = mContext.getResources().getDimensionPixelSize(R.dimen.abouthome_topsite_pinsize);
 
                 // Draw a little triangle in the upper right corner
                 Path path = new Path();
@@ -466,16 +470,17 @@ public class TopSitesView extends GridVi
                 convertView = LayoutInflater.from(mContext).inflate(R.layout.abouthome_topsite_item, null);
 
                 viewHolder = new TopSitesViewHolder(convertView);
                 convertView.setTag(viewHolder);
             } else {
                 viewHolder = (TopSitesViewHolder) convertView.getTag();
             }
 
+            Log.i(LOGTAG, "Build");
             viewHolder.setTitle(title);
             viewHolder.setUrl(url);
             viewHolder.setPinned(pinned);
 
             // Force the view to fit inside this slot in the grid
             convertView.setLayoutParams(new AbsListView.LayoutParams(getColumnWidth(),
                         Math.round(getColumnWidth()*ThumbnailHelper.THUMBNAIL_ASPECT_RATIO)));
 
@@ -628,16 +633,17 @@ public class TopSitesView extends GridVi
                 // a special URI until we can get a valid URL for this bookmark.
                 if (data.getBooleanExtra(AwesomeBar.USER_ENTERED_KEY, false)) {
                     // Store what the user typed as the bookmark's title.
                     title = url;
                     url = encodeUserEnteredUrl(url);
                 }
 
                 clearThumbnailsWithUrl(url);
+                Log.i(LOGTAG, "Edit done: " + url + " " + title);
 
                 holder.setUrl(url);
                 holder.setTitle(title);
                 holder.setPinned(true);
 
                 // update the database on a background thread
                 (new UiAsyncTask<Void, Void, Bitmap>(ThreadUtils.getBackgroundHandler()) {
                     @Override