Chromium Code Reviews| 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..f757cb76c02f73df586e8c393456a1120f303113 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); |
| + stripImageElements(clonedSubtree); |
|
mdjones
2015/12/10 01:12:45
It could be argued that images as part of a table
wychen
2015/12/10 05:39:16
Acknowledged.
|
| if (textOnly) { |
| return DomUtil.getTextFromTree(clonedSubtree); |
| @@ -260,8 +261,14 @@ public class DomUtil { |
| } |
| public static void makeSrcSetAbsolute(ImageElement ie) { |
| + String srcset = ie.getAttribute("srcset"); |
| + if (srcset == "") { |
| + ie.removeAttribute("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; |
| @@ -274,6 +281,27 @@ public class DomUtil { |
| ie.setSrc(oldsrc); |
| } |
| + public static void stripImageElements(Node root) { |
| + NodeList<Element> imgs = DomUtil.querySelectorAll(root, "IMG"); |
| + for (int i = 0; i < imgs.getLength(); i++) { |
| + stripImageElement(ImageElement.as(imgs.getItem(i))); |
| + } |
| + } |
| + |
| + /** |
| + * Only keep src and optionally srcset attributes for image elements. |
| + * @param ie The image element to strip in-place. |
| + */ |
| + public static void stripImageElement(ImageElement imgElement) { |
| + JsArray<Node> attrs = DomUtil.getAttributes(imgElement); |
| + for (int i = 0; i < attrs.length(); i++) { |
| + String name = attrs.get(i).getNodeName(); |
| + if (name != "src" && name != "srcset") { |
| + imgElement.removeAttribute(name); |
| + } |
| + } |
| + } |
| + |
| /** |
| * Makes all "img", "source", "track", and "video" tags have an absolute "src" attribute. |
| * @param root The root element to look through. |