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

Unified Diff: java/org/chromium/distiller/webdocument/WebImage.java

Issue 2203563002: Extract image URLs in srcset as well (Closed) Base URL: git@github.com:chromium/dom-distiller.git@master
Patch Set: minor fixes Created 4 years, 5 months 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/webdocument/WebImage.java
diff --git a/java/org/chromium/distiller/webdocument/WebImage.java b/java/org/chromium/distiller/webdocument/WebImage.java
index ceb3a405279c3dbf95c723c6eb9ced12f7a095b6..df50a3587252627a5c89525eeaed13bed835f89c 100644
--- a/java/org/chromium/distiller/webdocument/WebImage.java
+++ b/java/org/chromium/distiller/webdocument/WebImage.java
@@ -10,6 +10,9 @@ import com.google.gwt.dom.client.ImageElement;
import org.chromium.distiller.DomUtil;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* WebImage represents an image in the WebDocument potentially needing extraction.
*/
@@ -22,6 +25,8 @@ public class WebImage extends WebElement {
private int width;
// The original height of the image in pixels.
private int height;
+ // The list of image URLs.
+ private List<String> list;
/**
* Build an image element.
@@ -56,6 +61,10 @@ public class WebImage extends WebElement {
DomUtil.makeSrcSetAbsolute(ie);
DomUtil.stripImageElement(ie);
+ list = new ArrayList<>();
+ list.add(srcUrl);
+ list.addAll(DomUtil.getSrcSetUrls(ie));
+
Element container = Document.get().createDivElement();
container.appendChild(ie);
return container.getInnerHTML();
@@ -86,10 +95,14 @@ public class WebImage extends WebElement {
}
/**
- * Get the source URL of this image.
- * @return Source URL or an empty string.
+ * Get the list of source URLs of this image.
+ * It's more efficient to call after generateOutput().
+ * @return Source URLs or an empty List.
*/
- public String getSrc() {
- return srcUrl;
+ public List<String> getUrlList() {
+ if (list == null) {
+ generateOutput(false);
wychen 2016/08/01 20:59:20 This feels entangled. :(
mdjones 2016/08/01 21:14:35 Can we instead cut the top part of generateOutput
wychen 2016/08/01 21:35:15 Done.
+ }
+ return list;
}
}

Powered by Google App Engine
This is Rietveld 408576698