haikuwebkit/Source/WebCore/dom/IdleDeadline.cpp

57 lines
2.2 KiB
C++
Raw Permalink Normal View History

Add IDL for requestIdleCallback https://bugs.webkit.org/show_bug.cgi?id=202653 Reviewed by Geoffrey Garen. Source/WebCore: Added the basic scaffolding for implementing requestIdleCallback disabled by default: https://w3c.github.io/requestidlecallback/ This patch just adds the support for calling requestIdleCallback which generates a monotonically increasing number. The callback is never called for now. Tests: requestidlecallback/requestidlecallback-enabled.html requestidlecallback/requestidlecallback-id.html requestidlecallback/requestidlecallback-not-enabled.html * CMakeLists.txt: * DerivedSources.make: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * bindings/js/WebCoreBuiltinNames.h: * dom/Document.cpp: (WebCore::Document::requestIdleCallback): (WebCore::Document::cancelIdleCallback): * dom/Document.h: * dom/IdleCallbackController.cpp: Added. (WebCore::IdleCallbackController::queueIdleCallback): (WebCore::IdleCallbackController::removeIdleCallback): * dom/IdleCallbackController.h: Added. * dom/IdleDeadline.cpp: Added. (WebCore::IdleDeadline::timeRemaining const): (WebCore::IdleDeadline::didTimeout const): * dom/IdleDeadline.h: Added. * dom/IdleDeadline.idl: Added. * dom/IdleRequestCallback.h: Added. * dom/IdleRequestCallback.idl: Added. * dom/IdleRequestOptions.h: Added. * dom/IdleRequestOptions.idl: Added. * page/DOMWindow.cpp: (WebCore::DOMWindow::requestIdleCallback): (WebCore::DOMWindow::cancelIdleCallback): * page/DOMWindow.h: * page/DOMWindow.idl: * page/Settings.yaml: Source/WebKit: * Shared/WebPreferences.yaml: Source/WebKitLegacy/mac: * WebView/WebPreferenceKeysPrivate.h: * WebView/WebPreferences.mm: (+[WebPreferences initialize]): * WebView/WebPreferencesPrivate.h: * WebView/WebView.mm: (-[WebView _preferencesChanged:]): Tools: * DumpRenderTree/TestOptions.cpp: (TestOptions::TestOptions): * DumpRenderTree/TestOptions.h: * DumpRenderTree/mac/DumpRenderTree.mm: (setWebPreferencesForTestOptions): LayoutTests: Added basic tests for validating requestIdleCallback is enabled or disabled, and its identifier starts at 1 in each document. * requestidlecallback: Added. * requestidlecallback/requestidlecallback-enabled-expected.txt: Added. * requestidlecallback/requestidlecallback-enabled.html: Added. * requestidlecallback/requestidlecallback-id-expected.txt: Added. * requestidlecallback/requestidlecallback-id.html: Added. * requestidlecallback/requestidlecallback-not-enabled-expected.txt: Added. * requestidlecallback/requestidlecallback-not-enabled.html: Added. Canonical link: https://commits.webkit.org/216137@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250816 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-10-08 06:22:46 +00:00
/*
* Copyright (C) 2019 Apple Inc. All rights reserved.
*
* 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.
*/
#include "config.h"
#include "IdleDeadline.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Performance.h"
#include <wtf/RefPtr.h>
namespace WebCore {
DOMHighResTimeStamp IdleDeadline::timeRemaining(Document& document) const
{
auto window = makeRefPtr(document.domWindow());
if (!window)
return 0;
return window->performance().relativeTimeFromTimeOriginInReducedResolution(m_deadline);
}
bool IdleDeadline::didTimeout(Document& document) const
{
auto window = makeRefPtr(document.domWindow());
if (!window)
return true;
// Reduce the resolution before the comparision to prevent resolution leakage.
auto deadline = window->performance().relativeTimeFromTimeOriginInReducedResolution(m_deadline);
auto now = window->performance().now();
return deadline >= now;
}
} // namespace WebCore