Bug 820576 - Part 2: Open URL for suggestions that look like URLs. r=mfinkle
authorBrian Nicholson <bnicholson@mozilla.com>
Wed, 12 Dec 2012 13:21:41 -0800
changeset 115838 1ce57f5cca0bad1f0bd036338a3638e38cbb7e15
parent 115837 e14b7800ae0159f10d21ccad0d388a073c66dd8d
child 115839 b7a58a0e50664f4ffed5f5eea86c7f69acb56644
push id19572
push userbnicholson@mozilla.com
push dateWed, 12 Dec 2012 21:21:55 +0000
treeherdermozilla-inbound@1ce57f5cca0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs820576
milestone20.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 820576 - Part 2: Open URL for suggestions that look like URLs. r=mfinkle
mobile/android/base/awesomebar/AllPagesTab.java
--- a/mobile/android/base/awesomebar/AllPagesTab.java
+++ b/mobile/android/base/awesomebar/AllPagesTab.java
@@ -7,16 +7,17 @@ package org.mozilla.gecko;
 
 import org.mozilla.gecko.AwesomeBar.ContextMenuSubject;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.BrowserDB.URLColumns;
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.util.GeckoAsyncTask;
 import org.mozilla.gecko.util.GeckoEventListener;
+import org.mozilla.gecko.util.StringUtils;
 
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
 import android.app.Activity;
 import android.content.Context;
 import android.database.Cursor;
@@ -441,24 +442,33 @@ public class AllPagesTab extends Awesome
                 updateUrl(viewHolder.urlView, cursor);
                 updateBookmarkIcon(viewHolder.bookmarkIconView, cursor);
                 displayFavicon(viewHolder);
             }
 
             return convertView;
         }
 
-        private void bindSearchEngineView(final SearchEngine engine, SearchEntryViewHolder viewHolder) {
+        private void bindSearchEngineView(final SearchEngine engine, final SearchEntryViewHolder viewHolder) {
             // when a suggestion is clicked, do a search
             OnClickListener clickListener = new OnClickListener() {
                 public void onClick(View v) {
                     AwesomeBarTabs.OnUrlOpenListener listener = getUrlListener();
                     if (listener != null) {
                         String suggestion = ((TextView) v.findViewById(R.id.suggestion_text)).getText().toString();
-                        listener.onSearch(engine.name, suggestion);
+
+                        // If we're not clicking the user-entered view (the
+                        // first suggestion item) and the search matches a URL
+                        // pattern, go to that URL. Otherwise, do a search for
+                        // the term.
+                        if (v != viewHolder.userEnteredView && !StringUtils.isSearchQuery(suggestion)) {
+                            listener.onUrlOpen(suggestion);
+                        } else {
+                            listener.onSearch(engine.name, suggestion);
+                        }
                     }
                 }
             };
 
             // when a suggestion is long-clicked, copy the suggestion into the URL EditText
             OnLongClickListener longClickListener = new OnLongClickListener() {
                 public boolean onLongClick(View v) {
                     AwesomeBarTabs.OnUrlOpenListener listener = getUrlListener();