Fix crash trying to add data: URLs to icon db

 bug: 3291958
 Made it so that only web urls have screenshots added to the database,
 preventing us from trying to query with extremely long data: urls

Change-Id: Iabd3ebd5308d965a0ee383a6cdfbab15c91c5d91
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 4c17308..487c69c 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -57,6 +57,7 @@
 import android.speech.RecognizerResultsIntent;
 import android.text.TextUtils;
 import android.util.Log;
+import android.util.Patterns;
 import android.view.ActionMode;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
@@ -399,6 +400,7 @@
             mDb = db;
         }
 
+        @Override
         protected Void doInBackground(Void... unused) {
             mDb.open(mActivity.getDir("icons", 0).getPath());
             Cursor c = null;
@@ -1891,33 +1893,38 @@
         final String url = view.getUrl();
         final String originalUrl = view.getOriginalUrl();
 
-        new AsyncTask<Void, Void, Void>() {
-            @Override
-            protected Void doInBackground(Void... unused) {
-                Cursor cursor = null;
-                try {
-                    cursor = Bookmarks.queryCombinedForUrl(cr, originalUrl, url);
-                    if (cursor != null && cursor.moveToFirst()) {
-                        final ByteArrayOutputStream os =
-                                new ByteArrayOutputStream();
-                        bm.compress(Bitmap.CompressFormat.PNG, 100, os);
+        // Only update thumbnails for web urls (http(s)://), not for
+        // about:, javascript:, data:, etc...
+        if (Patterns.WEB_URL.matcher(url).matches()) {
+            new AsyncTask<Void, Void, Void>() {
+                @Override
+                protected Void doInBackground(Void... unused) {
+                    Cursor cursor = null;
+                    try {
+                        // TODO: Clean this up
+                        cursor = Bookmarks.queryCombinedForUrl(cr, originalUrl, url);
+                        if (cursor != null && cursor.moveToFirst()) {
+                            final ByteArrayOutputStream os =
+                                    new ByteArrayOutputStream();
+                            bm.compress(Bitmap.CompressFormat.PNG, 100, os);
 
-                        ContentValues values = new ContentValues();
-                        values.put(Images.THUMBNAIL, os.toByteArray());
-                        values.put(Images.URL, cursor.getString(0));
+                            ContentValues values = new ContentValues();
+                            values.put(Images.THUMBNAIL, os.toByteArray());
+                            values.put(Images.URL, cursor.getString(0));
 
-                        do {
-                            cr.update(Images.CONTENT_URI, values, null, null);
-                        } while (cursor.moveToNext());
+                            do {
+                                cr.update(Images.CONTENT_URI, values, null, null);
+                            } while (cursor.moveToNext());
+                        }
+                    } catch (IllegalStateException e) {
+                        // Ignore
+                    } finally {
+                        if (cursor != null) cursor.close();
                     }
-                } catch (IllegalStateException e) {
-                    // Ignore
-                } finally {
-                    if (cursor != null) cursor.close();
+                    return null;
                 }
-                return null;
-            }
-        }.execute();
+            }.execute();
+        }
     }
 
     private class Copy implements OnMenuItemClickListener {