Merge "Fix sourceid string for psychic."
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index e2ad329..0777efd 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -250,6 +250,10 @@
         boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
         getTitleBar().setIncognitoMode(incognito);
         updateAutoLogin(tab, false);
+        if (web != null && web.getVisibleTitleHeight()
+                != getTitleBar().getEmbeddedHeight()) {
+            showTitleBarForDuration();
+        }
     }
 
     Tab getActiveTab() {
@@ -819,6 +823,13 @@
         }
     }
 
+    private void showTitleBarForDuration() {
+        mHandler.removeMessages(MSG_HIDE_TITLEBAR);
+        showTitleBar();
+        Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
+        mHandler.sendMessageDelayed(msg, HIDE_TITLEBAR_DELAY);
+    }
+
     @Override
     public boolean onTouch(View v, MotionEvent event) {
         switch (event.getAction()) {
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 88fcbd6..2e66c84 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -2189,6 +2189,7 @@
             Tab tab = urlData.getPreloadedTab();
             tab.getWebView().clearHistory();
             mTabControl.addPreloadedTab(tab);
+            addTab(tab);
             setActiveTab(tab);
             return tab;
         } else {
@@ -2348,7 +2349,8 @@
      * @param view The WebView used to load url.
      * @param url The URL to load.
      */
-    protected void loadUrl(Tab tab, String url) {
+    @Override
+    public void loadUrl(Tab tab, String url) {
         loadUrl(tab, url, null);
     }
 
diff --git a/src/com/android/browser/NfcHandler.java b/src/com/android/browser/NfcHandler.java
index bbac640..bc19950 100644
--- a/src/com/android/browser/NfcHandler.java
+++ b/src/com/android/browser/NfcHandler.java
@@ -20,6 +20,7 @@
 import android.nfc.NdefMessage;
 import android.nfc.NdefRecord;
 import android.nfc.NfcAdapter;
+import android.os.AsyncTask;
 
 /** This class implements sharing the URL of the currently
   * shown browser page over NFC. Sharing is only active
@@ -31,6 +32,37 @@
     private Activity mActivity;
     private Controller mController;
 
+    /** We need an async task to check whether the tab is private
+      * on the UI thread.
+      */
+    private class CreateMessageTask extends AsyncTask<Void, Void, NdefMessage> {
+        private boolean mIsPrivate = false;
+        private Tab mCurrentTab;
+
+        @Override
+        protected void onPreExecute() {
+            mCurrentTab = mController.getCurrentTab();
+            if ((mCurrentTab != null) && (mCurrentTab.getWebView() != null)) {
+                mIsPrivate = mCurrentTab.getWebView().isPrivateBrowsingEnabled();
+            }
+        }
+
+        @Override
+        protected NdefMessage doInBackground(Void... params) {
+            if ((mCurrentTab == null) || mIsPrivate) {
+                return null;
+            }
+            String currentUrl = mCurrentTab.getUrl();
+            if (currentUrl != null) {
+                NdefRecord record = NdefRecord.createUri(currentUrl);
+                NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
+                return msg;
+            } else {
+                return null;
+            }
+        }
+    }
+
     public NfcHandler(Activity browser, Controller controller) {
         mActivity = browser;
         mController = controller;
@@ -51,17 +83,11 @@
 
     @Override
     public NdefMessage createMessage() {
-        Tab currentTab = mController.getCurrentTab();
-        if (currentTab == null) {
-            return null;
-        }
-        String currentUrl = currentTab.getUrl();
-        if (currentUrl != null && currentTab.getWebView() != null &&
-                    !currentTab.getWebView().isPrivateBrowsingEnabled()) {
-            NdefRecord record = NdefRecord.createUri(currentUrl);
-            NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
-            return msg;
-        } else {
+        CreateMessageTask task = new CreateMessageTask();
+        task.execute();
+        try {
+            return task.get();
+        } catch (Exception e) {
             return null;
         }
     }
diff --git a/src/com/android/browser/TitleBarBase.java b/src/com/android/browser/TitleBarBase.java
index c7fb9c6..ae11038 100644
--- a/src/com/android/browser/TitleBarBase.java
+++ b/src/com/android/browser/TitleBarBase.java
@@ -554,7 +554,15 @@
     @Override
     public void onAction(String text, String extra, String source) {
         mUiController.getCurrentTopWebView().requestFocus();
-        mBaseUi.hideTitleBar();
+        if (UrlInputView.TYPED.equals(source)) {
+            String url = UrlUtils.smartUrlFilter(text, false);
+            Tab t = mBaseUi.getActiveTab();
+            if (url != null && t != null) {
+                mUiController.loadUrl(t, url);
+                setDisplayTitle(text);
+                return;
+            }
+        }
         Intent i = new Intent();
         String action = null;
         if (UrlInputView.VOICE.equals(source)) {
diff --git a/src/com/android/browser/UiController.java b/src/com/android/browser/UiController.java
index 4550a8a..6045d86 100644
--- a/src/com/android/browser/UiController.java
+++ b/src/com/android/browser/UiController.java
@@ -99,4 +99,6 @@
 
     SnapshotTab createNewSnapshotTab(long snapshotId, boolean setActive);
 
+    void loadUrl(Tab tab, String url);
+
 }
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) {