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;
@ -113,6 +118,20 @@ public class ArticleFragment extends Fragment implements OnClickListener {
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>" +
"<head>" +
@ -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);

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);
if (doc != null) {
if (m_prefs.getBoolean("offline_image_cache_enabled", false)) {
Elements images = doc.select("img");
for (Element img : images) {
@ -144,10 +144,16 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
img.attr("src", "file://" + ImageCacheService.getCacheFileName(url));
}
}
}
// thanks webview for crashing on <video> tag
Elements videos = doc.select("video");
for (Element video : videos)
video.remove();
articleContent = doc.toString();
}
}
content =
"<html>" +