Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(797)

Unified Diff: java/org/chromium/distiller/DomUtil.java

Issue 1507373003: Clean up attributes of image elements (Closed) Base URL: git@github.com:chromium/dom-distiller.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: java/org/chromium/distiller/DomUtil.java
diff --git a/java/org/chromium/distiller/DomUtil.java b/java/org/chromium/distiller/DomUtil.java
index d0bcb1bfd7330c1cc8c56be59fdbc6320918284f..973fd62290ca8b1a61b3636f24ea9f2eca539e5f 100644
--- a/java/org/chromium/distiller/DomUtil.java
+++ b/java/org/chromium/distiller/DomUtil.java
@@ -216,6 +216,7 @@ public class DomUtil {
stripFontColorAttributes(clonedSubtree);
stripTableBackgroundColorAttributes(clonedSubtree);
stripStyleAttributes(clonedSubtree);
+ stripAlignAttributes(clonedSubtree);
if (textOnly) {
return DomUtil.getTextFromTree(clonedSubtree);
@@ -260,8 +261,11 @@ public class DomUtil {
}
public static void makeSrcSetAbsolute(ImageElement ie) {
+ String srcset = ie.getAttribute("srcset");
+ if (srcset == "") return;
+
String oldsrc = ie.getSrc();
- String[] sizes = StringUtil.jsSplit(ie.getAttribute("srcset"), ",");
+ String[] sizes = StringUtil.jsSplit(srcset, ",");
for(int i = 0; i < sizes.length; i++) {
String size = StringUtil.jsTrim(sizes[i]);
if (size.isEmpty()) continue;
@@ -338,6 +342,13 @@ public class DomUtil {
}
/**
+ * Strips all "align" attributes from image elements in the tree rooted at |rootNode|
+ */
+ public static void stripAlignAttributes(Node rootNode) {
+ stripAttributeFromTags(rootNode, "ALIGN", new String[]{"IMG"});
+ }
+
+ /**
* Get a list of relevant nodes from a subtree.
* @param root The root of the subtree.
* @return A list of relevant nodes.

Powered by Google App Engine
This is Rietveld 408576698