diff options
Diffstat (limited to 'src/com/android/browser/Tab.java')
| -rw-r--r-- | src/com/android/browser/Tab.java | 89 |
1 files changed, 69 insertions, 20 deletions
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index acccb3150..c73bdf6b3 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -64,8 +64,8 @@ import android.webkit.WebHistoryItem; import android.webkit.WebResourceResponse; import android.webkit.WebStorage; import android.webkit.WebView; -import android.webkit.WebViewClassic; import android.webkit.WebView.PictureListener; +import android.webkit.WebViewClassic; import android.webkit.WebViewClient; import android.widget.CheckBox; import android.widget.Toast; @@ -76,12 +76,16 @@ import com.android.browser.provider.SnapshotProvider.Snapshots; import com.android.common.speech.LoggingEvents; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; +import java.util.UUID; import java.util.Vector; import java.util.regex.Pattern; import java.util.zip.GZIPOutputStream; @@ -1234,9 +1238,9 @@ class Tab implements PictureListener { } @Override - public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { + public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { if (mInForeground) { - mWebViewController.openFileChooser(uploadMsg, acceptType); + mWebViewController.openFileChooser(uploadMsg, acceptType, capture); } else { uploadMsg.onReceiveValue(null); } @@ -1566,8 +1570,6 @@ class Tab implements PictureListener { void destroy() { if (mMainView != null) { dismissSubWindow(); - // Make sure the embedded title bar isn't still attached - getWebViewClassic().setEmbeddedTitleBar(null); // save the WebView to call destroy() after detach it from the tab WebView webView = mMainView; setWebView(null); @@ -2059,26 +2061,29 @@ class Tab implements PictureListener { return false; } - public ContentValues createSnapshotValues() { - if (mMainView == null) return null; - SnapshotByteArrayOutputStream bos = new SnapshotByteArrayOutputStream(); - try { - GZIPOutputStream stream = new GZIPOutputStream(bos); - if (!getWebViewClassic().saveViewState(stream)) { - return null; + private static class SaveCallback implements ValueCallback<Boolean> { + boolean mResult; + + @Override + public void onReceiveValue(Boolean value) { + mResult = value; + synchronized (this) { + notifyAll(); } - stream.flush(); - stream.close(); - } catch (Exception e) { - Log.w(LOGTAG, "Failed to save view state", e); - return null; } - byte[] data = bos.toByteArray(); + + } + + /** + * Must be called on the UI thread + */ + public ContentValues createSnapshotValues() { + WebViewClassic web = getWebViewClassic(); + if (web == null) return null; ContentValues values = new ContentValues(); values.put(Snapshots.TITLE, mCurrentState.mTitle); values.put(Snapshots.URL, mCurrentState.mUrl); - values.put(Snapshots.VIEWSTATE, data); - values.put(Snapshots.BACKGROUND, getWebViewClassic().getPageBackgroundColor()); + values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor()); values.put(Snapshots.DATE_CREATED, System.currentTimeMillis()); values.put(Snapshots.FAVICON, compressBitmap(getFavicon())); Bitmap screenshot = Controller.createScreenshot(mMainView, @@ -2088,6 +2093,50 @@ class Tab implements PictureListener { return values; } + /** + * Probably want to call this on a background thread + */ + public boolean saveViewState(ContentValues values) { + WebViewClassic web = getWebViewClassic(); + if (web == null) return false; + String path = UUID.randomUUID().toString(); + SaveCallback callback = new SaveCallback(); + OutputStream outs = null; + try { + outs = mContext.openFileOutput(path, Context.MODE_PRIVATE); + GZIPOutputStream stream = new GZIPOutputStream(outs); + synchronized (callback) { + web.saveViewState(stream, callback); + callback.wait(); + } + stream.flush(); + stream.close(); + } catch (Exception e) { + Log.w(LOGTAG, "Failed to save view state", e); + if (outs != null) { + try { + outs.close(); + } catch (IOException ignore) {} + } + File file = mContext.getFileStreamPath(path); + if (file.exists() && !file.delete()) { + file.deleteOnExit(); + } + return false; + } + File savedFile = mContext.getFileStreamPath(path); + if (!callback.mResult) { + if (!savedFile.delete()) { + savedFile.deleteOnExit(); + } + return false; + } + long size = savedFile.length(); + values.put(Snapshots.VIEWSTATE_PATH, path); + values.put(Snapshots.VIEWSTATE_SIZE, size); + return true; + } + public byte[] compressBitmap(Bitmap bitmap) { if (bitmap == null) { return null; |
