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 java.util.Date;
import org.fox.ttrss.OnlineServices.RelativeArticle; 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.app.Activity;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -12,6 +16,7 @@ import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener; import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -112,6 +117,20 @@ public class ArticleFragment extends Fragment implements OnClickListener {
} else { } else {
cssOverride = ""; 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 = content =
"<html>" + "<html>" +
@ -124,7 +143,7 @@ public class ArticleFragment extends Fragment implements OnClickListener {
"body { text-align : justify; }" + "body { text-align : justify; }" +
"</style>" + "</style>" +
"</head>" + "</head>" +
"<body>" + m_article.content + "</body></html>"; "<body>" + articleContent + "</body></html>";
try { try {
web.loadDataWithBaseURL(null, content, "text/html", "utf-8", null); web.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
@ -206,7 +225,7 @@ public class ArticleFragment extends Fragment implements OnClickListener {
@Override @Override
public void onSaveInstanceState (Bundle out) { public void onSaveInstanceState (Bundle out) {
super.onSaveInstanceState(out); super.onSaveInstanceState(out);
out.putParcelable("article", m_article); 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")); String articleContent = m_cursor.getString(m_cursor.getColumnIndex("content"));
Document doc = Jsoup.parse(articleContent);
if (m_prefs.getBoolean("offline_image_cache_enabled", false)) {
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"); Elements images = doc.select("img");
for (Element img : images) { for (Element img : images) {
@ -144,9 +144,15 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
img.attr("src", "file://" + ImageCacheService.getCacheFileName(url)); 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 = content =