haikuwebkit/Source/WebCore/html/LazyLoadFrameObserver.h

58 lines
2.0 KiB
C
Raw Permalink Normal View History

Implement lazy iframe loading https://bugs.webkit.org/show_bug.cgi?id=215442 Patch by Rob Buis <rbuis@igalia.com> on 2020-09-12 Reviewed by Darin Adler. LayoutTests/imported/w3c: Update improved test result. * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-base-url-2.tentative-expected.txt: * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-base-url.tentative-expected.txt: * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-load-event.tentative-expected.txt: * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-multiple-times.tentative-expected.txt: * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-referrerpolicy-change.sub.tentative-expected.txt: * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-to-eager.tentative-expected.txt: Source/WebCore: Implement lazy iframe loading as specified [1, 2]. Lazy iframe loading is controlled by the loading attribute on <iframe>. When the loading attribute is not specified, the behavior is like before this patch, i.e. loading is eager. This changes the way iframe attribute processing is handled as specified here [2]. This implementation relies on Intersection Observer and hence works on WK2 only. [1] https://html.spec.whatwg.org/#attr-iframe-loading [2] https://html.spec.whatwg.org/#process-the-iframe-attributes Tests: imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-base-url-2.tentative.html imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-base-url.tentative.html imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-load-event.tentative.html imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-multiple-times.tentative.html imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-referrerpolicy-change.sub.tentative.html imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-to-eager.tentative.html * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * html/HTMLFrameElementBase.cpp: (WebCore::HTMLFrameElementBase::openURL): * html/HTMLFrameElementBase.h: (WebCore::HTMLFrameElementBase::frameURL const): (WebCore::HTMLFrameElementBase::setFrameURL): * html/HTMLFrameOwnerElement.h: (WebCore::HTMLFrameOwnerElement::shouldLoadFrameLazily): (WebCore::HTMLFrameOwnerElement::isLazyLoadObserverActive const): * html/HTMLIFrameElement.cpp: (WebCore::HTMLIFrameElement::parseAttribute): (WebCore::HTMLIFrameElement::referrerPolicy const): (WebCore::HTMLIFrameElement::loadingForBindings const): (WebCore::HTMLIFrameElement::setLoadingForBindings): (WebCore::isFrameLazyLoadable): (WebCore::HTMLIFrameElement::shouldLoadFrameLazily): (WebCore::HTMLIFrameElement::isLazyLoadObserverActive const): (WebCore::HTMLIFrameElement::loadDeferredFrame): (WebCore::HTMLIFrameElement::lazyLoadFrameObserver): * html/HTMLIFrameElement.h: * html/HTMLIFrameElement.idl: * html/LazyLoadFrameObserver.cpp: Added. (WebCore::LazyLoadFrameObserver::LazyLoadFrameObserver): (WebCore::LazyLoadFrameObserver::observe): (WebCore::LazyLoadFrameObserver::unobserve): (WebCore::LazyLoadFrameObserver::intersectionObserver): (WebCore::LazyLoadFrameObserver::isObserved const): * html/LazyLoadFrameObserver.h: Copied from Source/WebCore/html/canvas/WebGLCompressedTextureETC1.cpp. (WebCore::LazyLoadFrameObserver::frameURL const): (WebCore::LazyLoadFrameObserver::referrerPolicy const): * html/canvas/WebGLCompressedTextureETC1.cpp: * html/shadow/DateTimeFieldElement.cpp: * loader/FrameLoader.cpp: (WebCore::FrameLoader::preventsParentFromBeingComplete const): (WebCore::FrameLoader::allChildrenAreComplete const): * loader/FrameLoader.h: LayoutTests: Unskip iframe-loading-lazy-to-eager.tentative.html and disable lazy iframe loading tests for WK1. * TestExpectations: * platform/mac-wk1/TestExpectations: Canonical link: https://commits.webkit.org/229266@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266976 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-09-12 08:35:27 +00:00
/*
* Copyright (C) 2020 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "IntersectionObserver.h"
namespace WebCore {
class Document;
class Element;
class HTMLIFrameElement;
class LazyLoadFrameObserver {
WTF_MAKE_FAST_ALLOCATED;
public:
LazyLoadFrameObserver(HTMLIFrameElement&);
void observe(const AtomString& frameURL, const ReferrerPolicy&);
void unobserve();
AtomString frameURL() const { return m_frameURL; }
ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; }
private:
IntersectionObserver* intersectionObserver(Document&);
bool isObserved(Element&) const;
HTMLIFrameElement& m_element;
AtomString m_frameURL;
ReferrerPolicy m_referrerPolicy;
RefPtr<IntersectionObserver> m_observer;
Implement lazy iframe loading https://bugs.webkit.org/show_bug.cgi?id=215442 Patch by Rob Buis <rbuis@igalia.com> on 2020-09-12 Reviewed by Darin Adler. LayoutTests/imported/w3c: Update improved test result. * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-base-url-2.tentative-expected.txt: * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-base-url.tentative-expected.txt: * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-load-event.tentative-expected.txt: * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-multiple-times.tentative-expected.txt: * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-referrerpolicy-change.sub.tentative-expected.txt: * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-to-eager.tentative-expected.txt: Source/WebCore: Implement lazy iframe loading as specified [1, 2]. Lazy iframe loading is controlled by the loading attribute on <iframe>. When the loading attribute is not specified, the behavior is like before this patch, i.e. loading is eager. This changes the way iframe attribute processing is handled as specified here [2]. This implementation relies on Intersection Observer and hence works on WK2 only. [1] https://html.spec.whatwg.org/#attr-iframe-loading [2] https://html.spec.whatwg.org/#process-the-iframe-attributes Tests: imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-base-url-2.tentative.html imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-base-url.tentative.html imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-load-event.tentative.html imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-multiple-times.tentative.html imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-referrerpolicy-change.sub.tentative.html imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-to-eager.tentative.html * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * html/HTMLFrameElementBase.cpp: (WebCore::HTMLFrameElementBase::openURL): * html/HTMLFrameElementBase.h: (WebCore::HTMLFrameElementBase::frameURL const): (WebCore::HTMLFrameElementBase::setFrameURL): * html/HTMLFrameOwnerElement.h: (WebCore::HTMLFrameOwnerElement::shouldLoadFrameLazily): (WebCore::HTMLFrameOwnerElement::isLazyLoadObserverActive const): * html/HTMLIFrameElement.cpp: (WebCore::HTMLIFrameElement::parseAttribute): (WebCore::HTMLIFrameElement::referrerPolicy const): (WebCore::HTMLIFrameElement::loadingForBindings const): (WebCore::HTMLIFrameElement::setLoadingForBindings): (WebCore::isFrameLazyLoadable): (WebCore::HTMLIFrameElement::shouldLoadFrameLazily): (WebCore::HTMLIFrameElement::isLazyLoadObserverActive const): (WebCore::HTMLIFrameElement::loadDeferredFrame): (WebCore::HTMLIFrameElement::lazyLoadFrameObserver): * html/HTMLIFrameElement.h: * html/HTMLIFrameElement.idl: * html/LazyLoadFrameObserver.cpp: Added. (WebCore::LazyLoadFrameObserver::LazyLoadFrameObserver): (WebCore::LazyLoadFrameObserver::observe): (WebCore::LazyLoadFrameObserver::unobserve): (WebCore::LazyLoadFrameObserver::intersectionObserver): (WebCore::LazyLoadFrameObserver::isObserved const): * html/LazyLoadFrameObserver.h: Copied from Source/WebCore/html/canvas/WebGLCompressedTextureETC1.cpp. (WebCore::LazyLoadFrameObserver::frameURL const): (WebCore::LazyLoadFrameObserver::referrerPolicy const): * html/canvas/WebGLCompressedTextureETC1.cpp: * html/shadow/DateTimeFieldElement.cpp: * loader/FrameLoader.cpp: (WebCore::FrameLoader::preventsParentFromBeingComplete const): (WebCore::FrameLoader::allChildrenAreComplete const): * loader/FrameLoader.h: LayoutTests: Unskip iframe-loading-lazy-to-eager.tentative.html and disable lazy iframe loading tests for WK1. * TestExpectations: * platform/mac-wk1/TestExpectations: Canonical link: https://commits.webkit.org/229266@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266976 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-09-12 08:35:27 +00:00
};
} // namespace