Skip to content

Commit

Permalink
Don't put every <img> in the page in a WebVector in AwRenderViewExt::…
Browse files Browse the repository at this point in the history
…OnDocumentHasImagesRequest.

This method was doing:

  blink::WebVector<blink::WebElement> images;
  webview->mainFrame()->document().images(images);
  hasImages = !images.isEmpty();

which meant Blink would walk the entire document putting every <img>
into a Vector, then it would copy that Vector into this WebVector all
so this code could check if the Vector wasn't empty.

Instead just use the NodeList version of getElementsByHTMLTagName,
which we can already just call in this file with GetImgChild. This
only walks until it finds the first <img> and doesn't need additional
storage.

Review URL: https://codereview.chromium.org/1220333011

Cr-Commit-Position: refs/heads/master@{#337920}
  • Loading branch information
esprehn authored and Commit bot committed Jul 8, 2015
1 parent 196e25d commit fa3437e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions android_webview/renderer/aw_render_view_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ GURL GetAbsoluteSrcUrl(const blink::WebElement& element) {
return GetAbsoluteUrl(element, element.getAttribute("src"));
}

blink::WebElement GetImgChild(const blink::WebElement& element) {
blink::WebElement GetImgChild(const blink::WebNode& node) {
// This implementation is incomplete (for example if is an area tag) but
// matches the original WebViewClassic implementation.

blink::WebElementCollection collection =
element.getElementsByHTMLTagName("img");
blink::WebElementCollection collection = node.getElementsByHTMLTagName("img");
DCHECK(!collection.isNull());
return collection.firstItem();
}
Expand Down Expand Up @@ -179,9 +178,9 @@ void AwRenderViewExt::OnDocumentHasImagesRequest(int id) {
if (render_view()) {
blink::WebView* webview = render_view()->GetWebView();
if (webview) {
blink::WebVector<blink::WebElement> images;
webview->mainFrame()->document().images(images);
hasImages = !images.isEmpty();
blink::WebDocument document = webview->mainFrame()->document();
const blink::WebElement child_img = GetImgChild(document);
hasImages = !child_img.isNull();
}
}
Send(new AwViewHostMsg_DocumentHasImagesResponse(routing_id(), id,
Expand Down

0 comments on commit fa3437e

Please sign in to comment.