LazyLoad: Only lazily load http/https images.

Before this CL, data URI images would be considered for lazy loading,
even though a data URI image would actually be loaded immediately
anyways and not get deferred. For image elements, this pollutes the
Blink.VisibleLoadTime.LazyLoadImages.* metrics with load times of all
these data URI images that aren't actually eligible for lazy loading.
For CSS background images, this causes Chrome to begin montoring the
elements containing these images with an intersection observer until the
user scrolls the viewport down to them, even though the data URI image
loads instantly.

This CL changes the logic to only consider http/https images for lazy
loading, both for image elements and CSS background images.

Bug: 920479
Change-Id: I105db546695c3464789703769013fa955f3bf10c
Reviewed-on: https://chromium-review.googlesource.com/c/1404575
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Scott Little <sclittle@chromium.org>
Cr-Commit-Position: refs/heads/master@{#621758}
diff --git a/third_party/blink/renderer/core/css/css_image_value.cc b/third_party/blink/renderer/core/css/css_image_value.cc
index ac930500..b8521faa 100644
--- a/third_party/blink/renderer/core/css/css_image_value.cc
+++ b/third_party/blink/renderer/core/css/css_image_value.cc
@@ -80,7 +80,9 @@
     }
     cached_image_ = StyleFetchedImage::Create(
         document, params,
-        image_request_optimization == FetchParameters::kDeferImageLoad);
+        // Only http/https images are eligible to be lazily loaded.
+        params.Url().ProtocolIsInHTTPFamily() &&
+            image_request_optimization == FetchParameters::kDeferImageLoad);
   }
 
   return cached_image_.Get();
diff --git a/third_party/blink/renderer/core/loader/image_loader.cc b/third_party/blink/renderer/core/loader/image_loader.cc
index c77936a..8614203 100644
--- a/third_party/blink/renderer/core/loader/image_loader.cc
+++ b/third_party/blink/renderer/core/loader/image_loader.cc
@@ -81,7 +81,8 @@
 }
 
 bool IsLazyLoadableImage(const LocalFrame* frame,
-                         HTMLImageElement* html_image) {
+                         HTMLImageElement* html_image,
+                         const KURL& url) {
   // Minimum width or height attribute of the image to start lazyloading.
   const unsigned kMinDimensionToLazyLoad = 10;
 
@@ -89,6 +90,9 @@
   if (!html_image->ElementCreatedByParser())
     return false;
 
+  if (!url.ProtocolIsInHTTPFamily())
+    return false;
+
   if (EqualIgnoringASCIICase(
           html_image->FastGetAttribute(html_names::kLazyloadAttr), "off") &&
       !frame->GetDocument()->IsLazyLoadPolicyEnforced()) {
@@ -537,7 +541,8 @@
       if (frame->IsClientLoFiAllowed(params.GetResourceRequest())) {
         params.SetClientLoFiPlaceholder();
       } else if (auto* html_image = ToHTMLImageElementOrNull(GetElement())) {
-        if (IsLazyLoadableImage(frame, html_image)) {
+        if (IsLazyLoadableImage(frame, html_image,
+                                params.GetResourceRequest().Url())) {
           if (frame->GetDocument()->GetSettings()->GetLazyLoadEnabled() &&
               frame->IsLazyLoadingImageAllowed()) {
             params.SetLazyImagePlaceholder();