Add runtime flag for lazy image loading
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Aug 2019 14:55:21 +0000 (14:55 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Aug 2019 14:55:21 +0000 (14:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199794

Patch by Rob Buis <rbuis@igalia.com> on 2019-08-08
Reviewed by Darin Adler.

Source/WebCore:

Add loading attribute and expose it on HTMLImageElement.

* html/HTMLAttributeNames.in:
* html/HTMLImageElement.idl:
* page/RuntimeEnabledFeatures.h:
(WebCore::RuntimeEnabledFeatures::setLazyImageLoadingEnabled):
(WebCore::RuntimeEnabledFeatures::lazyImageLoadingEnabled const):

Source/WebKit:

Add LazyImageLoading preference.

* Shared/WebPreferences.yaml:
* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetLazyImageLoadingEnabled):
(WKPreferencesGetLazyImageLoadingEnabled):
* UIProcess/API/C/WKPreferencesRefPrivate.h:

Source/WebKitLegacy/mac:

Set lazyImageLoading runtime flag if preference is set.

* WebView/WebPreferenceKeysPrivate.h:
* WebView/WebPreferences.mm:
(+[WebPreferences initialize]):
(-[WebPreferences lazyImageLoadingEnabled]):
(-[WebPreferences setLazyImageLoadingEnabled:]):
* WebView/WebPreferencesPrivate.h:
* WebView/WebView.mm:
(-[WebView _preferencesChanged:]):

Source/WebKitLegacy/win:

Set lazyImageLoading runtime flag if preference is set.

* Interfaces/IWebPreferencesPrivate.idl:
* WebPreferenceKeysPrivate.h:
* WebPreferences.cpp:
(WebPreferences::initializeDefaultSettings):
(WebPreferences::lazyImageLoadingEnabled):
(WebPreferences::setLazyImageLoadingEnabled):
* WebPreferences.h:
* WebView.cpp:
(WebView::notifyPreferencesChanged):

Tools:

Set lazyImageLoading preference as part of experimental features. Add
TestOption for lazy image loading.

* DumpRenderTree/TestOptions.cpp:
(TestOptions::TestOptions):
* DumpRenderTree/TestOptions.h:
* DumpRenderTree/mac/DumpRenderTree.mm:
(enableExperimentalFeatures):
(setWebPreferencesForTestOptions):
* DumpRenderTree/win/DumpRenderTree.cpp:
(enableExperimentalFeatures):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248409 268f45cc-cd09-0410-ab3c-d52691b4dbfc

26 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLAttributeNames.in
Source/WebCore/html/HTMLImageElement.idl
Source/WebCore/page/RuntimeEnabledFeatures.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferences.yaml
Source/WebKit/UIProcess/API/C/WKPreferences.cpp
Source/WebKit/UIProcess/API/C/WKPreferencesRefPrivate.h
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebView/WebPreferenceKeysPrivate.h
Source/WebKitLegacy/mac/WebView/WebPreferences.mm
Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h
Source/WebKitLegacy/mac/WebView/WebView.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/Interfaces/IWebPreferencesPrivate.idl
Source/WebKitLegacy/win/WebPreferenceKeysPrivate.h
Source/WebKitLegacy/win/WebPreferences.cpp
Source/WebKitLegacy/win/WebPreferences.h
Source/WebKitLegacy/win/WebView.cpp
Tools/ChangeLog
Tools/DumpRenderTree/TestOptions.cpp
Tools/DumpRenderTree/TestOptions.h
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/DumpRenderTree/win/DumpRenderTree.cpp
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestOptions.h

index 383b12a..637d85c 100644 (file)
@@ -1,3 +1,18 @@
+2019-08-08  Rob Buis  <rbuis@igalia.com>
+
+        Add runtime flag for lazy image loading
+        https://bugs.webkit.org/show_bug.cgi?id=199794
+
+        Reviewed by Darin Adler.
+
+        Add loading attribute and expose it on HTMLImageElement.
+
+        * html/HTMLAttributeNames.in:
+        * html/HTMLImageElement.idl:
+        * page/RuntimeEnabledFeatures.h:
+        (WebCore::RuntimeEnabledFeatures::setLazyImageLoadingEnabled):
+        (WebCore::RuntimeEnabledFeatures::lazyImageLoadingEnabled const):
+
 2019-08-08  Miguel Gomez  <magomez@igalia.com>
 
         [GTK][WPE] Remove the reference to WebCore::Animation from TextureMapperAnimation
index 03d6e2c..0924eea 100644 (file)
@@ -44,6 +44,8 @@
 
     [Conditional=ATTACHMENT_ELEMENT, EnabledAtRuntime=AttachmentElement] readonly attribute DOMString attachmentIdentifier;
 
+    [EnabledAtRuntime=LazyImageLoading, CEReactions, Reflect] attribute DOMString loading;
+
     // Extensions
     readonly attribute boolean complete;
     [CEReactions=NotNeeded, Reflect, URL] attribute USVString lowsrc;
index bc3543a..5d288d3 100644 (file)
@@ -364,6 +364,9 @@ public:
     bool linkPreloadResponsiveImagesEnabled() const { return m_linkPreloadResponsiveImagesEnabled; }
     void setLinkPreloadResponsiveImagesEnabled(bool isEnabled) { m_linkPreloadResponsiveImagesEnabled = isEnabled; }
 
+    void setLazyImageLoadingEnabled(bool areEnabled) { m_lazyImageLoadingEnabled = areEnabled; }
+    bool lazyImageLoadingEnabled() const { return m_lazyImageLoadingEnabled; }
+
     WEBCORE_EXPORT static RuntimeEnabledFeatures& sharedFeatures();
 
 #if HAVE(NSURLSESSION_WEBSOCKET)
@@ -558,6 +561,8 @@ private:
     bool m_isNSURLSessionWebSocketEnabled { false };
 #endif
 
+    bool m_lazyImageLoadingEnabled { false };
+
     friend class WTF::NeverDestroyed<RuntimeEnabledFeatures>;
 };
 
index 3cc4898..70c4c1c 100644 (file)
@@ -1,3 +1,18 @@
+2019-08-08  Rob Buis  <rbuis@igalia.com>
+
+        Add runtime flag for lazy image loading
+        https://bugs.webkit.org/show_bug.cgi?id=199794
+
+        Reviewed by Darin Adler.
+
+        Add LazyImageLoading preference.
+
+        * Shared/WebPreferences.yaml:
+        * UIProcess/API/C/WKPreferences.cpp:
+        (WKPreferencesSetLazyImageLoadingEnabled):
+        (WKPreferencesGetLazyImageLoadingEnabled):
+        * UIProcess/API/C/WKPreferencesRefPrivate.h:
+
 2019-08-07  Chris Dumez  <cdumez@apple.com>
 
         Turn some ITP threading ASSERTs into RELEASE_ASSERTs
index 47d2820..03a8ea3 100644 (file)
@@ -1715,6 +1715,14 @@ IsNSURLSessionWebSocketEnabled:
   webcoreBinding: RuntimeEnabledFeatures
   condition: HAVE(NSURLSESSION_WEBSOCKET)
 
+LazyImageLoadingEnabled:
+  type: bool
+  defaultValue: false
+  humanReadableName: "Lazy Image Loading"
+  humanReadableDescription: "Enable Lazy Image Loading support"
+  webcoreBinding: RuntimeEnabledFeatures
+  category: experimental
+
 # Deprecated
 
 ICECandidateFilteringEnabled:
index 91c0a8c..51f4b7b 100644 (file)
@@ -2139,3 +2139,13 @@ bool WKPreferencesGetReferrerPolicyAttributeEnabled(WKPreferencesRef preferences
 {
     return toImpl(preferencesRef)->referrerPolicyAttributeEnabled();
 }
+
+void WKPreferencesSetLazyImageLoadingEnabled(WKPreferencesRef preferencesRef, bool flag)
+{
+    toImpl(preferencesRef)->setLazyImageLoadingEnabled(flag);
+}
+
+bool WKPreferencesGetLazyImageLoadingEnabled(WKPreferencesRef preferencesRef)
+{
+    return toImpl(preferencesRef)->lazyImageLoadingEnabled();
+}
index 2f0419b..58a28a0 100644 (file)
@@ -591,6 +591,10 @@ WK_EXPORT bool WKPreferencesGetPunchOutWhiteBackgroundsInDarkMode(WKPreferencesR
 WK_EXPORT void WKPreferencesSetReferrerPolicyAttributeEnabled(WKPreferencesRef, bool flag);
 WK_EXPORT bool WKPreferencesGetReferrerPolicyAttributeEnabled(WKPreferencesRef);
 
+// Defaults to false
+WK_EXPORT void WKPreferencesSetLazyImageLoadingEnabled(WKPreferencesRef, bool flag);
+WK_EXPORT bool WKPreferencesGetLazyImageLoadingEnabled(WKPreferencesRef);
+
 #ifdef __cplusplus
 }
 #endif
index f6b8485..9449df2 100644 (file)
@@ -1,3 +1,21 @@
+2019-08-08  Rob Buis  <rbuis@igalia.com>
+
+        Add runtime flag for lazy image loading
+        https://bugs.webkit.org/show_bug.cgi?id=199794
+
+        Reviewed by Darin Adler.
+
+        Set lazyImageLoading runtime flag if preference is set.
+
+        * WebView/WebPreferenceKeysPrivate.h:
+        * WebView/WebPreferences.mm:
+        (+[WebPreferences initialize]):
+        (-[WebPreferences lazyImageLoadingEnabled]):
+        (-[WebPreferences setLazyImageLoadingEnabled:]):
+        * WebView/WebPreferencesPrivate.h:
+        * WebView/WebView.mm:
+        (-[WebView _preferencesChanged:]):
+
 2019-08-07  Priyanka Agarwal  <pagarwal999@apple.com>
 
         Allow clients to toggle a text input field between being viewable and having characters hidden while maintaining 
index a4556d7..16328f5 100644 (file)
 #define WebKitResizeObserverEnabledPreferenceKey @"WebKitResizeObserverEnabled"
 #define WebKitCoreMathMLEnabledPreferenceKey @"WebKitCoreMathMLEnabled"
 #define WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey @"WebKitLinkPreloadResponsiveImagesEnabled"
+#define WebKitLazyImageLoadingEnabledPreferenceKey @"WebKitLazyImageLoadingEnabled"
 
index 425e63c..d4f22ba 100644 (file)
@@ -691,6 +691,7 @@ public:
 #if ENABLE(RESIZE_OBSERVER)
         @NO, WebKitResizeObserverEnabledPreferenceKey,
 #endif
+        @NO, WebKitLazyImageLoadingEnabledPreferenceKey,
         @NO, WebKitCoreMathMLEnabledPreferenceKey,
         @NO, WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey,
         nil];
@@ -3499,6 +3500,16 @@ static NSString *classIBCreatorID = nil;
     [self _setBoolValue:flag forKey:WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey];
 }
 
+- (BOOL)lazyImageLoadingEnabled
+{
+    return [self _boolValueForKey:WebKitLazyImageLoadingEnabledPreferenceKey];
+}
+
+- (void)setLazyImageLoadingEnabled:(BOOL)flag
+{
+    [self _setBoolValue:flag forKey:WebKitLazyImageLoadingEnabledPreferenceKey];
+}
+
 @end
 
 @implementation WebPreferences (WebInternal)
index d368b88..b53f7e5 100644 (file)
@@ -649,6 +649,7 @@ extern NSString *WebPreferencesCacheModelChangedInternalNotification WEBKIT_DEPR
 @property (nonatomic) BOOL resizeObserverEnabled;
 @property (nonatomic) BOOL coreMathMLEnabled;
 @property (nonatomic) BOOL linkPreloadResponsiveImagesEnabled;
+@property (nonatomic) BOOL lazyImageLoadingEnabled;
 
 #if TARGET_OS_IPHONE
 @property (nonatomic) BOOL quickLookDocumentSavingEnabled;
index 4ae23e9..bf31088 100644 (file)
@@ -3186,6 +3186,7 @@ static bool needsSelfRetainWhileLoadingQuirk()
     RuntimeEnabledFeatures::sharedFeatures().setReferrerPolicyAttributeEnabled([preferences referrerPolicyAttributeEnabled]);
     RuntimeEnabledFeatures::sharedFeatures().setLinkPreloadResponsiveImagesEnabled([preferences linkPreloadResponsiveImagesEnabled]);
     RuntimeEnabledFeatures::sharedFeatures().setDialogElementEnabled([preferences dialogElementEnabled]);
+    RuntimeEnabledFeatures::sharedFeatures().setLazyImageLoadingEnabled([preferences lazyImageLoadingEnabled]);
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
     RuntimeEnabledFeatures::sharedFeatures().setLegacyEncryptedMediaAPIEnabled(preferences.legacyEncryptedMediaAPIEnabled);
index 4c4016d..0d3cdbd 100644 (file)
@@ -1,3 +1,22 @@
+2019-08-08  Rob Buis  <rbuis@igalia.com>
+
+        Add runtime flag for lazy image loading
+        https://bugs.webkit.org/show_bug.cgi?id=199794
+
+        Reviewed by Darin Adler.
+
+        Set lazyImageLoading runtime flag if preference is set.
+
+        * Interfaces/IWebPreferencesPrivate.idl:
+        * WebPreferenceKeysPrivate.h:
+        * WebPreferences.cpp:
+        (WebPreferences::initializeDefaultSettings):
+        (WebPreferences::lazyImageLoadingEnabled):
+        (WebPreferences::setLazyImageLoadingEnabled):
+        * WebPreferences.h:
+        * WebView.cpp:
+        (WebView::notifyPreferencesChanged):
+
 2019-07-28  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [Win][WK1] Can't change Web Inspector frontend height in high DPI
index cb8dda4..4f3a563 100644 (file)
@@ -242,4 +242,6 @@ interface IWebPreferencesPrivate7 : IWebPreferencesPrivate6
     HRESULT setResizeObserverEnabled([in] BOOL enabled);
     HRESULT coreMathMLEnabled([out, retval] BOOL* enabled);
     HRESULT setCoreMathMLEnabled([in] BOOL enabled);
+    HRESULT lazyImageLoadingEnabled([out, retval] BOOL*);
+    HRESULT setLazyImageLoadingEnabled([in] BOOL enabled);
 }
index ba66270..47ea93b 100644 (file)
 #define WebKitResizeObserverEnabledPreferenceKey "WebKitResizeObserverEnabled"
 
 #define WebKitCoreMathMLEnabledPreferenceKey "WebKitCoreMathMLEnabled"
+
+#define WebKitLazyImageLoadingEnabledPreferenceKey "WebKitLazyImageLoadingEnabled"
index 1394868..c3485d5 100644 (file)
@@ -333,6 +333,8 @@ void WebPreferences::initializeDefaultSettings()
 
     CFDictionaryAddValue(defaults, CFSTR(WebKitCoreMathMLEnabledPreferenceKey), kCFBooleanFalse);
 
+    CFDictionaryAddValue(defaults, CFSTR(WebKitLazyImageLoadingEnabledPreferenceKey), kCFBooleanFalse);
+
     defaultSettings = defaults;
 }
 
@@ -2292,3 +2294,17 @@ HRESULT WebPreferences::setResizeObserverEnabled(BOOL enabled)
     setBoolValue(WebKitResizeObserverEnabledPreferenceKey, enabled);
     return S_OK;
 }
+
+HRESULT WebPreferences::lazyImageLoadingEnabled(_Out_ BOOL* enabled)
+{
+    if (!enabled)
+        return E_POINTER;
+    *enabled = boolValueForKey(WebKitLazyImageLoadingEnabledPreferenceKey);
+    return S_OK;
+}
+
+HRESULT WebPreferences::setLazyImageLoadingEnabled(BOOL enabled)
+{
+    setBoolValue(WebKitLazyImageLoadingEnabledPreferenceKey, enabled);
+    return S_OK;
+}
index 5ee6427..e1ad5cb 100644 (file)
@@ -287,6 +287,8 @@ public:
     virtual HRESULT STDMETHODCALLTYPE setResizeObserverEnabled(BOOL);
     virtual HRESULT STDMETHODCALLTYPE coreMathMLEnabled(_Out_ BOOL*);
     virtual HRESULT STDMETHODCALLTYPE setCoreMathMLEnabled(BOOL);
+    virtual HRESULT STDMETHODCALLTYPE lazyImageLoadingEnabled(_Out_ BOOL*);
+    virtual HRESULT STDMETHODCALLTYPE setLazyImageLoadingEnabled(BOOL);
 
     // WebPreferences
 
index eac5a61..a61e1db 100644 (file)
@@ -5608,6 +5608,11 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification)
         return hr;
     settings.setCoreMathMLEnabled(!!enabled);
 
+    hr = prefsPrivate->lazyImageLoadingEnabled(&enabled);
+    if (FAILED(hr))
+        return hr;
+    RuntimeEnabledFeatures::sharedFeatures().setLazyImageLoadingEnabled(!!enabled);
+
     return S_OK;
 }
 
index 92db1f9..6ea96c5 100644 (file)
@@ -1,5 +1,24 @@
 2019-08-08  Rob Buis  <rbuis@igalia.com>
 
+        Add runtime flag for lazy image loading
+        https://bugs.webkit.org/show_bug.cgi?id=199794
+
+        Reviewed by Darin Adler.
+
+        Set lazyImageLoading preference as part of experimental features. Add
+        TestOption for lazy image loading.
+
+        * DumpRenderTree/TestOptions.cpp:
+        (TestOptions::TestOptions):
+        * DumpRenderTree/TestOptions.h:
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (enableExperimentalFeatures):
+        (setWebPreferencesForTestOptions):
+        * DumpRenderTree/win/DumpRenderTree.cpp:
+        (enableExperimentalFeatures):
+
+2019-08-08  Rob Buis  <rbuis@igalia.com>
+
         Import lazy loading WPT tests
         https://bugs.webkit.org/show_bug.cgi?id=199795
 
index aaa5e72..24623b1 100644 (file)
@@ -117,6 +117,8 @@ TestOptions::TestOptions(const std::string& pathOrURL, const std::string& absolu
             enableResizeObserver = parseBooleanTestHeaderValue(value);
         else if (key == "experimental:CoreMathMLEnabled")
             enableCoreMathML = parseBooleanTestHeaderValue(value);
+        else if (key == "experimental:LazyImageLoadingEnabled")
+            enableLazyImageLoading = parseBooleanTestHeaderValue(value);
         pairStart = pairEnd + 1;
     }
 }
index d16f758..558aaba 100644 (file)
@@ -48,6 +48,7 @@ struct TestOptions {
     bool adClickAttributionEnabled { false };
     bool enableResizeObserver { false };
     bool enableCoreMathML { false };
+    bool enableLazyImageLoading { false };
     std::string jscOptions;
     std::string additionalSupportedImageTypes;
 
index 8745140..2e9397f 100644 (file)
@@ -877,8 +877,8 @@ static void enableExperimentalFeatures(WebPreferences* preferences)
     [preferences setCSSOMViewScrollingAPIEnabled:YES];
     [preferences setMediaRecorderEnabled:YES];
     [preferences setReferrerPolicyAttributeEnabled:YES];
-    [preferences setReferrerPolicyAttributeEnabled:YES];
     [preferences setLinkPreloadResponsiveImagesEnabled:YES];
+    [preferences setLazyImageLoadingEnabled:YES];
 }
 
 // Called before each test.
@@ -1025,6 +1025,7 @@ static void setWebPreferencesForTestOptions(const TestOptions& options)
     preferences.adClickAttributionEnabled = options.adClickAttributionEnabled;
     preferences.resizeObserverEnabled = options.enableResizeObserver;
     preferences.coreMathMLEnabled = options.enableCoreMathML;
+    preferences.lazyImageLoadingEnabled = options.enableLazyImageLoading;
 }
 
 // Called once on DumpRenderTree startup.
index 3a35347..2fb0fdd 100644 (file)
@@ -795,6 +795,7 @@ static void enableExperimentalFeatures(IWebPreferences* preferences)
     prefsPrivate->setResizeObserverEnabled(TRUE);
     prefsPrivate->setWebAnimationsEnabled(TRUE);
     prefsPrivate->setServerTimingEnabled(TRUE);
+    prefsPrivate->setLazyImageLoadingEnabled(TRUE);
     // FIXME: WebGL2
     // FIXME: WebRTC
 }
index 7957dc6..99118e7 100644 (file)
@@ -821,6 +821,7 @@ void TestController::resetPreferencesToConsistentValues(const TestOptions& optio
     WKPreferencesSetColorFilterEnabled(preferences, options.enableColorFilter);
     WKPreferencesSetPunchOutWhiteBackgroundsInDarkMode(preferences, options.punchOutWhiteBackgroundsInDarkMode);
     WKPreferencesSetPageCacheEnabled(preferences, options.enablePageCache);
+    WKPreferencesSetLazyImageLoadingEnabled(preferences, options.enableLazyImageLoading);
 
     static WKStringRef defaultTextEncoding = WKStringCreateWithUTF8CString("ISO-8859-1");
     WKPreferencesSetDefaultTextEncodingName(preferences, defaultTextEncoding);
@@ -1401,6 +1402,8 @@ static void updateTestOptionsFromTestHeader(TestOptions& testOptions, const std:
             testOptions.enableAppNap = parseBooleanTestHeaderValue(value);
         else if (key == "enablePageCache")
             testOptions.enablePageCache = parseBooleanTestHeaderValue(value);
+        else if (key == "enableLazyImageLoading")
+            testOptions.enableLazyImageLoading = parseBooleanTestHeaderValue(value);
         pairStart = pairEnd + 1;
     }
 }
index 309d40f..db432c3 100644 (file)
@@ -93,6 +93,7 @@ struct TestOptions {
     bool shouldPresentPopovers { true };
     bool enableAppNap { false };
     bool enablePageCache { false };
+    bool enableLazyImageLoading { false };
 
     double contentInsetTop { 0 };