remove <video> tags from webviews

This commit is contained in:
Andrew Dolgov 2011-12-07 15:25:50 +03:00
parent 59839b7e08
commit cbabbf099f
2 changed files with 33 additions and 8 deletions

View File

@ -4,6 +4,10 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import org.fox.ttrss.OnlineServices.RelativeArticle;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.content.SharedPreferences;
@ -12,6 +16,7 @@ import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.LayoutInflater;
@ -112,6 +117,20 @@ public class ArticleFragment extends Fragment implements OnClickListener {
} else {
cssOverride = "";
}
String articleContent = m_article.content;
Document doc = Jsoup.parse(articleContent);
if (doc != null) {
// thanks webview for crashing on <video> tag
Elements videos = doc.select("video");
for (Element video : videos)
video.remove();
articleContent = doc.toString();
}
content =
"<html>" +
@ -124,7 +143,7 @@ public class ArticleFragment extends Fragment implements OnClickListener {
"body { text-align : justify; }" +
"</style>" +
"</head>" +
"<body>" + m_article.content + "</body></html>";
"<body>" + articleContent + "</body></html>";
try {
web.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
@ -206,7 +225,7 @@ public class ArticleFragment extends Fragment implements OnClickListener {
@Override
public void onSaveInstanceState (Bundle out) {
super.onSaveInstanceState(out);
out.putParcelable("article", m_article);
}

View File

@ -130,11 +130,11 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
}
String articleContent = m_cursor.getString(m_cursor.getColumnIndex("content"));
if (m_prefs.getBoolean("offline_image_cache_enabled", false)) {
Document doc = Jsoup.parse(articleContent);
Document doc = Jsoup.parse(articleContent);
if (doc != null) {
if (doc != null) {
if (m_prefs.getBoolean("offline_image_cache_enabled", false)) {
Elements images = doc.select("img");
for (Element img : images) {
@ -144,9 +144,15 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
img.attr("src", "file://" + ImageCacheService.getCacheFileName(url));
}
}
articleContent = doc.toString();
}
// thanks webview for crashing on <video> tag
Elements videos = doc.select("video");
for (Element video : videos)
video.remove();
articleContent = doc.toString();
}
content =