In the case of a page load error, save a second screenshot in onProgressChanged(100) to ensure that we save the substituted error page rather than the previous page that loaded. Also save the thumbnail for the page if the user creates the bookmark through the add bookmark menu or clicking the add bookmark icon on the bookmarks page.

Change-Id: Ib2b7692a45290f9ce372968e05cde8f6903e4572
diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java
index 2a92dce..7878762 100644
--- a/src/com/android/browser/AddBookmarkPage.java
+++ b/src/com/android/browser/AddBookmarkPage.java
@@ -21,6 +21,7 @@
 import android.content.Intent;
 import android.content.res.Resources;
 import android.database.Cursor;
+import android.graphics.Bitmap;
 import android.net.ParseException;
 import android.net.WebAddress;
 import android.os.Bundle;
@@ -46,6 +47,8 @@
     private boolean     mEditingExisting;
     private Bundle      mMap;
     private String      mTouchIconUrl;
+    private Bitmap      mThumbnail;
+    private String      mOriginalUrl;
 
     private View.OnClickListener mSaveBookmark = new View.OnClickListener() {
         public void onClick(View v) {
@@ -81,8 +84,9 @@
                 setTitle(R.string.edit_bookmark);
             }
             title = mMap.getString("title");
-            url = mMap.getString("url");
+            url = mOriginalUrl = mMap.getString("url");
             mTouchIconUrl = mMap.getString("touch_icon_url");
+            mThumbnail = (Bitmap) mMap.getParcelable("thumbnail");
         }
 
         mTitle = (EditText) findViewById(R.id.title);
@@ -154,7 +158,14 @@
                         getIntent().toString()).putExtras(mMap));
             } else {
                 final ContentResolver cr = getContentResolver();
-                Bookmarks.addBookmark(null, cr, url, title, true);
+
+                // Only use mThumbnail if url and mOriginalUrl are matches.
+                // Otherwise the user edited the url and the thumbnail no longer applies.
+                if (mOriginalUrl.equals(url)) {
+                    Bookmarks.addBookmark(null, cr, url, title, mThumbnail, true);
+                } else {
+                    Bookmarks.addBookmark(null, cr, url, title, null, true);
+                }
                 if (mTouchIconUrl != null) {
                     final Cursor c =
                             BrowserBookmarksAdapter.queryBookmarksForUrl(