OSDN Git Service

Pass attached HTTP headers to WebView from voice search.
authorLeon Scroggins <scroggo@google.com>
Mon, 8 Mar 2010 23:20:35 +0000 (18:20 -0500)
committerLeon Scroggins <scroggo@google.com>
Tue, 9 Mar 2010 00:26:12 +0000 (19:26 -0500)
Fix for http://b/issue?id=2496144

Change-Id: I245e7e47a31158a9082a33c1ebcfb7dcf924ee08

src/com/android/browser/Tab.java

index e502e5b..7bb6ca6 100644 (file)
@@ -18,7 +18,10 @@ package com.android.browser;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.Map;
 import java.util.Vector;
 
 import android.app.AlertDialog;
@@ -221,6 +224,9 @@ class Tab {
             }
             mVoiceSearchData = new VoiceSearchData(results, urls, htmls,
                     baseUrls);
+            mVoiceSearchData.mHeaders = intent.getParcelableArrayListExtra(
+                    RecognizerResultsIntent
+                    .EXTRA_VOICE_SEARCH_RESULT_HTTP_HEADERS);
             mVoiceSearchData.mSourceIsGoogle = intent.getBooleanExtra(
                     VoiceSearchData.SOURCE_IS_GOOGLE, false);
         } else {
@@ -278,7 +284,21 @@ class Tab {
             mVoiceSearchData.mLastVoiceSearchUrl = mActivity.smartUrlFilter(
                     mVoiceSearchData.mLastVoiceSearchTitle);
         }
-        mMainView.loadUrl(mVoiceSearchData.mLastVoiceSearchUrl);
+        Map<String, String> headers = null;
+        if (mVoiceSearchData.mHeaders != null) {
+            int bundleIndex = mVoiceSearchData.mHeaders.size() == 1 ? 0
+                    : index;
+            Bundle bundle = mVoiceSearchData.mHeaders.get(bundleIndex);
+            if (bundle != null && !bundle.isEmpty()) {
+                Iterator<String> iter = bundle.keySet().iterator();
+                headers = new HashMap<String, String>();
+                while (iter.hasNext()) {
+                    String key = iter.next();
+                    headers.put(key, bundle.getString(key));
+                }
+            }
+        }
+        mMainView.loadUrl(mVoiceSearchData.mLastVoiceSearchUrl, headers);
     }
     /* package */ static class VoiceSearchData {
         public VoiceSearchData(ArrayList<String> results,
@@ -327,6 +347,11 @@ class Tab {
          */
         public boolean mSourceIsGoogle;
         /**
+         * List of headers to be passed into the WebView containing location
+         * information
+         */
+        public ArrayList<Bundle> mHeaders;
+        /**
          * The Intent used to invoke voice search.  Placed on the
          * WebHistoryItem so that when coming back to a previous voice search
          * page we can again activate voice search.