Merge "Fix 3337625 to follow link to Google Images" into honeycomb
diff --git a/src/com/android/browser/UrlHandler.java b/src/com/android/browser/UrlHandler.java
index cd0afeb..f39ac4b 100644
--- a/src/com/android/browser/UrlHandler.java
+++ b/src/com/android/browser/UrlHandler.java
@@ -120,7 +120,7 @@
                 // AsyncTask. Although we are not overriding the URL load synchronously,
                 // we guarantee that we will handle this URL load after the task executes,
                 // so it's safe to just return true to WebCore now to stop its own loading.
-                new RLZTask(siteUri, view).execute();
+                new RLZTask(tab, siteUri, view).execute();
                 return true;
             }
         }
@@ -137,9 +137,7 @@
             return true;
         }
 
-        if (mController.isMenuDown()) {
-            mController.openTab(tab, url, false);
-            mActivity.closeOptionsMenu();
+        if (handleMenuClick(tab, url)) {
             return true;
         }
 
@@ -198,6 +196,19 @@
       return false;
     }
 
+    // In case a physical keyboard is attached, handle clicks with the menu key
+    // depressed by opening in a new tab
+    boolean handleMenuClick(Tab tab, String url)
+    {
+        if (mController.isMenuDown()) {
+            mController.openTab(tab, url, false);
+            mActivity.closeOptionsMenu();
+            return true;
+        }
+
+        return false;
+    }
+
     // Url for issuing the uber token.
     private final static Uri ISSUE_AUTH_TOKEN_URL = Uri.parse(
             "https://www.google.com/accounts/IssueAuthToken?service=gaia&Session=false");
@@ -355,10 +366,12 @@
     }
 
     private class RLZTask extends AsyncTask<Void, Void, String> {
+        private Tab mTab;
         private Uri mSiteUri;
         private WebView mWebView;
 
-        public RLZTask(Uri uri, WebView webView) {
+        public RLZTask(Tab tab, Uri uri, WebView webView) {
+            mTab = tab;
             mSiteUri = uri;
             mWebView = webView;
         }
@@ -383,7 +396,12 @@
         }
 
         protected void onPostExecute(String result) {
-            startActivityForUrl(result);
+            // If the Activity Manager is not invoked, load the URL directly
+            if (!startActivityForUrl(result)) {
+                if (!handleMenuClick(mTab, result)) {
+                    mController.loadUrl(mWebView, result);
+                }
+            }
         }
     }