summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeon Scroggins <scroggo@google.com>2011-02-02 12:54:07 -0500
committerLeon Scroggins <scroggo@google.com>2011-02-11 09:23:32 -0500
commitac993841b3f810dd55a985141c574d4dfebd8c1a (patch)
treebdc64ab8ff115ec69973c422a4e955ff3792d785
parent4216b649af17ddc750752d7985edcdb4d240b5c2 (diff)
downloadpackages_apps_Browser-ac993841b3f810dd55a985141c574d4dfebd8c1a.zip
packages_apps_Browser-ac993841b3f810dd55a985141c574d4dfebd8c1a.tar.gz
packages_apps_Browser-ac993841b3f810dd55a985141c574d4dfebd8c1a.tar.bz2
Integrate Save WebArchive with download manager.
Bug:2968359 Bug:2905874 Change-Id: I80f557af415b03698325397d7a10d66bb0c10827
-rw-r--r--res/menu-xlarge/browser.xml2
-rw-r--r--res/menu/browser.xml2
-rw-r--r--res/values/strings.xml2
-rw-r--r--src/com/android/browser/Controller.java48
4 files changed, 52 insertions, 2 deletions
diff --git a/res/menu-xlarge/browser.xml b/res/menu-xlarge/browser.xml
index 1b52c9a..a791cdd 100644
--- a/res/menu-xlarge/browser.xml
+++ b/res/menu-xlarge/browser.xml
@@ -44,6 +44,8 @@
android:title="@string/menu_preferences"
android:icon="@drawable/ic_settings_holo_dark"
android:alphabeticShortcut="p" />
+ <item android:id="@+id/save_webarchive_menu_id"
+ android:title="@string/menu_save_webarchive" />
<!-- followings are debug only -->
<item android:id="@+id/dump_nav_menu_id"
android:title="@string/dump_nav"
diff --git a/res/menu/browser.xml b/res/menu/browser.xml
index beaa8f3..7a59ffd 100644
--- a/res/menu/browser.xml
+++ b/res/menu/browser.xml
@@ -57,6 +57,8 @@
android:title="@string/menu_preferences"
android:icon="@drawable/ic_settings_holo_dark"
android:alphabeticShortcut="p" />
+ <item android:id="@+id/save_webarchive_menu_id"
+ android:title="@string/menu_save_webarchive" />
<!-- followings are debug only -->
<item android:id="@+id/dump_nav_menu_id"
android:title="@string/dump_nav"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 80cb2c8..b84e279 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -234,8 +234,6 @@
<string name="share_page">Share page</string>
<!-- Menu item for saving a page as a web archive. -->
<string name="menu_save_webarchive">Save as Web Archive</string>
- <!-- Toast informing the user that the page has been saved. -->
- <string name="webarchive_saved">Web archive saved.</string>
<!-- Toast informing the user that saving the page has failed. -->
<string name="webarchive_failed">Failed to save web archive.</string>
<!-- The number of bookmarks in a folder [CHAR LIMT=50] -->
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index f4588bd..b01ea54 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -43,6 +43,7 @@ import android.net.Uri;
import android.net.http.SslError;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
@@ -77,6 +78,7 @@ import android.webkit.WebChromeClient;
import android.webkit.WebIconDatabase;
import android.webkit.WebSettings;
import android.webkit.WebView;
+import android.widget.Toast;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -1567,6 +1569,52 @@ public class Controller
getCurrentTopWebView().showFindDialog(null, true);
break;
+ case R.id.save_webarchive_menu_id:
+ String state = Environment.getExternalStorageState();
+ if (!Environment.MEDIA_MOUNTED.equals(state)) {
+ Log.e(LOGTAG, "External storage not mounted");
+ Toast.makeText(mActivity, R.string.webarchive_failed,
+ Toast.LENGTH_SHORT).show();
+ break;
+ }
+ final String directory = Environment.getExternalStoragePublicDirectory(
+ Environment.DIRECTORY_DOWNLOADS) + File.separator;
+ File dir = new File(directory);
+ if (!dir.exists() && !dir.mkdirs()) {
+ Log.e(LOGTAG, "Save as Web Archive: mkdirs for " + directory + " failed!");
+ Toast.makeText(mActivity, R.string.webarchive_failed,
+ Toast.LENGTH_SHORT).show();
+ break;
+ }
+ WebView topWebView = getCurrentTopWebView();
+ final String title = topWebView.getTitle();
+ topWebView.saveWebArchive(directory, true,
+ new ValueCallback<String>() {
+ @Override
+ public void onReceiveValue(final String value) {
+ if (value != null) {
+ File file = new File(value);
+ final long length = file.length();
+ if (file.exists() && length > 0) {
+ final DownloadManager manager = (DownloadManager) mActivity
+ .getSystemService(Context.DOWNLOAD_SERVICE);
+ new Thread("Add WebArchive to download manager") {
+ @Override
+ public void run() {
+ manager.completedDownload(null == title ? value : title,
+ value, true, "application/x-webarchive-xml",
+ value, length, true);
+ }
+ }.start();
+ return;
+ }
+ }
+ Toast.makeText(mActivity,
+ R.string.webarchive_failed, Toast.LENGTH_SHORT).show();
+ }
+ });
+ break;
+
case R.id.page_info_menu_id:
mPageDialogsHandler.showPageInfo(mTabControl.getCurrentTab(),
false);