Shortcut the TYPED url case

 Bug: 4985289
 Don't go through the handleIntent route if the user typed
 something into the omnibox if we don't need to.

Change-Id: I4de8e18c1ca734a0c6bfbca43c9448417cec2057
diff --git a/src/com/android/browser/UrlUtils.java b/src/com/android/browser/UrlUtils.java
index 26f8e0e..c922e55 100644
--- a/src/com/android/browser/UrlUtils.java
+++ b/src/com/android/browser/UrlUtils.java
@@ -85,7 +85,22 @@
      *
      */
     public static String smartUrlFilter(String url) {
+        return smartUrlFilter(url, true);
+    }
 
+    /**
+     * Attempts to determine whether user input is a URL or search
+     * terms.  Anything with a space is passed to search if canBeSearch is true.
+     *
+     * Converts to lowercase any mistakenly uppercased schema (i.e.,
+     * "Http://" converts to "http://"
+     *
+     * @param canBeSearch If true, will return a search url if it isn't a valid
+     *                    URL. If false, invalid URLs will return null
+     * @return Original or modified URL
+     *
+     */
+    public static String smartUrlFilter(String url, boolean canBeSearch) {
         String inUrl = url.trim();
         boolean hasSpace = inUrl.indexOf(' ') != -1;
 
@@ -97,7 +112,7 @@
             if (!lcScheme.equals(scheme)) {
                 inUrl = lcScheme + matcher.group(2);
             }
-            if (hasSpace) {
+            if (hasSpace && Patterns.WEB_URL.matcher(inUrl).matches()) {
                 inUrl = inUrl.replace(" ", "%20");
             }
             return inUrl;
@@ -107,12 +122,11 @@
                 return URLUtil.guessUrl(inUrl);
             }
         }
-
-        // FIXME: Is this the correct place to add to searches?
-        // what if someone else calls this function?
-
-//        Browser.addSearchUrl(mBrowser.getContentResolver(), inUrl);
-        return URLUtil.composeSearchUrl(inUrl, QUICKSEARCH_G, QUERY_PLACE_HOLDER);
+        if (canBeSearch) {
+            return URLUtil.composeSearchUrl(inUrl,
+                    QUICKSEARCH_G, QUERY_PLACE_HOLDER);
+        }
+        return null;
     }
 
     /* package */ static String fixUrl(String inUrl) {