Add IDL for requestIdleCallback
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Oct 2019 06:22:46 +0000 (06:22 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Oct 2019 06:22:46 +0000 (06:22 +0000)
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.

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

39 files changed:
LayoutTests/ChangeLog
LayoutTests/requestidlecallback/requestidlecallback-enabled-expected.txt [new file with mode: 0644]
LayoutTests/requestidlecallback/requestidlecallback-enabled.html [new file with mode: 0644]
LayoutTests/requestidlecallback/requestidlecallback-id-expected.txt [new file with mode: 0644]
LayoutTests/requestidlecallback/requestidlecallback-id.html [new file with mode: 0644]
LayoutTests/requestidlecallback/requestidlecallback-not-enabled-expected.txt [new file with mode: 0644]
LayoutTests/requestidlecallback/requestidlecallback-not-enabled.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/WebCoreBuiltinNames.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/IdleCallbackController.cpp [new file with mode: 0644]
Source/WebCore/dom/IdleCallbackController.h [new file with mode: 0644]
Source/WebCore/dom/IdleDeadline.cpp [new file with mode: 0644]
Source/WebCore/dom/IdleDeadline.h [new file with mode: 0644]
Source/WebCore/dom/IdleDeadline.idl [new file with mode: 0644]
Source/WebCore/dom/IdleRequestCallback.h [new file with mode: 0644]
Source/WebCore/dom/IdleRequestCallback.idl [new file with mode: 0644]
Source/WebCore/dom/IdleRequestOptions.h [new file with mode: 0644]
Source/WebCore/dom/IdleRequestOptions.idl [new file with mode: 0644]
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/DOMWindow.idl
Source/WebCore/page/Settings.yaml
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferences.yaml
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
Tools/ChangeLog
Tools/DumpRenderTree/TestOptions.cpp
Tools/DumpRenderTree/TestOptions.h
Tools/DumpRenderTree/mac/DumpRenderTree.mm

index 3a76517..7d91cc7 100644 (file)
@@ -1,3 +1,20 @@
+2019-10-07  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Add IDL for requestIdleCallback
+        https://bugs.webkit.org/show_bug.cgi?id=202653
+
+        Reviewed by Geoffrey Garen.
+
+        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.
+
 2019-10-07  Jiewen Tan  <jiewen_tan@apple.com>
 
         Only wrapping CryptoKeys for IDB during serialization
diff --git a/LayoutTests/requestidlecallback/requestidlecallback-enabled-expected.txt b/LayoutTests/requestidlecallback/requestidlecallback-enabled-expected.txt
new file mode 100644 (file)
index 0000000..ab1e875
--- /dev/null
@@ -0,0 +1,19 @@
+This tests that when requestIdleCallback is enabled, requestIdleCallback and IdleDeadline are defined.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS typeof window.requestIdleCallback is "function"
+PASS window.requestIdleCallback.length is 1
+PASS typeof window.cancelIdleCallback is "function"
+PASS window.cancelIdleCallback.length is 1
+PASS window.IdleDeadline is defined.
+PASS idleDeadlineProperties = Object.getOwnPropertyNames(window.IdleDeadline.prototype); idleDeadlineProperties.length is 3
+PASS JSON.stringify(idleDeadlineProperties.sort()) is "[\"constructor\",\"didTimeout\",\"timeRemaining\"]"
+PASS didTimeoutDescriptor = Object.getOwnPropertyDescriptor(window.IdleDeadline.prototype, "didTimeout"); didTimeoutDescriptor.get is defined.
+PASS didTimeoutDescriptor.set is undefined.
+PASS typeof window.IdleDeadline.prototype.timeRemaining is "function"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/requestidlecallback/requestidlecallback-enabled.html b/LayoutTests/requestidlecallback/requestidlecallback-enabled.html
new file mode 100644 (file)
index 0000000..fa24708
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html><!-- webkit-test-runner [ experimental:RequestIdleCallbackEnabled=true ] -->
+<html>
+<body>
+<script src="../resources/js-test.js"></script>
+<script>
+
+description('This tests that when requestIdleCallback is enabled, requestIdleCallback and IdleDeadline are defined.');
+
+shouldBeEqualToString('typeof window.requestIdleCallback', 'function');
+shouldBe('window.requestIdleCallback.length', '1');
+shouldBeEqualToString('typeof window.cancelIdleCallback', 'function');
+shouldBe('window.cancelIdleCallback.length', '1');
+shouldBeDefined('window.IdleDeadline');
+shouldBe('idleDeadlineProperties = Object.getOwnPropertyNames(window.IdleDeadline.prototype); idleDeadlineProperties.length', '3');
+shouldBeEqualToString('JSON.stringify(idleDeadlineProperties.sort())', '["constructor","didTimeout","timeRemaining"]');
+shouldBeDefined('didTimeoutDescriptor = Object.getOwnPropertyDescriptor(window.IdleDeadline.prototype, "didTimeout"); didTimeoutDescriptor.get');
+shouldBeUndefined('didTimeoutDescriptor.set');
+shouldBeEqualToString('typeof window.IdleDeadline.prototype.timeRemaining', 'function');
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/requestidlecallback/requestidlecallback-id-expected.txt b/LayoutTests/requestidlecallback/requestidlecallback-id-expected.txt
new file mode 100644 (file)
index 0000000..d6a916f
--- /dev/null
@@ -0,0 +1,16 @@
+This tests that requestIdleCallback identifier starts from 1 in each document.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS requestIdleCallback(() => { }) is 1
+PASS requestIdleCallback(() => { }) is 2
+PASS iframe1.contentWindow.requestIdleCallback(() => { }) is 1
+PASS iframe2.contentWindow.requestIdleCallback(() => { }) is 1
+PASS iframe1.contentWindow.requestIdleCallback(() => { }) is 2
+PASS iframe1.contentWindow.requestIdleCallback(() => { }) is 3
+PASS iframe2.contentWindow.requestIdleCallback(() => { }) is 2
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/requestidlecallback/requestidlecallback-id.html b/LayoutTests/requestidlecallback/requestidlecallback-id.html
new file mode 100644 (file)
index 0000000..a698dce
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE html><!-- webkit-test-runner [ experimental:RequestIdleCallbackEnabled=true ] -->
+<html>
+<body>
+<script src="../resources/js-test.js"></script>
+<script>
+
+description('This tests that requestIdleCallback identifier starts from 1 in each document.');
+
+shouldBe('requestIdleCallback(() => { })', '1');
+shouldBe('requestIdleCallback(() => { })', '2');
+
+const iframe1 = document.body.appendChild(document.createElement('iframe'));
+const iframe2 = document.body.appendChild(document.createElement('iframe'));
+
+shouldBe('iframe1.contentWindow.requestIdleCallback(() => { })', '1');
+shouldBe('iframe2.contentWindow.requestIdleCallback(() => { })', '1');
+shouldBe('iframe1.contentWindow.requestIdleCallback(() => { })', '2');
+shouldBe('iframe1.contentWindow.requestIdleCallback(() => { })', '3');
+shouldBe('iframe2.contentWindow.requestIdleCallback(() => { })', '2');
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/requestidlecallback/requestidlecallback-not-enabled-expected.txt b/LayoutTests/requestidlecallback/requestidlecallback-not-enabled-expected.txt
new file mode 100644 (file)
index 0000000..52e12e7
--- /dev/null
@@ -0,0 +1,12 @@
+This tests that when requestIdleCallback is not enabled, requestIdleCallback and IdleDeadline are not defined.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS window.requestIdleCallback is undefined.
+PASS window.cancelIdleCallback is undefined.
+PASS window.IdleDeadline is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/requestidlecallback/requestidlecallback-not-enabled.html b/LayoutTests/requestidlecallback/requestidlecallback-not-enabled.html
new file mode 100644 (file)
index 0000000..eb08415
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html><!-- webkit-test-runner [ experimental:RequestIdleCallbackEnabled=false ] -->
+<html>
+<body>
+<script src="../resources/js-test.js"></script>
+<script>
+
+description('This tests that when requestIdleCallback is not enabled, requestIdleCallback and IdleDeadline are not defined.');
+
+shouldBeUndefined('window.requestIdleCallback');
+shouldBeUndefined('window.cancelIdleCallback');
+shouldBeUndefined('window.IdleDeadline');
+
+</script>
+</body>
+</html>
index 8262be6..1d2f5a5 100644 (file)
@@ -706,6 +706,9 @@ set(WebCore_NON_SVG_IDL_FILES
     dom/FocusEvent.idl
     dom/GlobalEventHandlers.idl
     dom/HashChangeEvent.idl
+    dom/IdleDeadline.idl
+    dom/IdleRequestCallback.idl
+    dom/IdleRequestOptions.idl
     dom/InputEvent.idl
     dom/KeyboardEvent.idl
     dom/MessageChannel.idl
index bebbe05..1968046 100644 (file)
@@ -1,3 +1,49 @@
+2019-10-07  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Add IDL for requestIdleCallback
+        https://bugs.webkit.org/show_bug.cgi?id=202653
+
+        Reviewed by Geoffrey Garen.
+
+        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:
+
 2019-10-07  Jiewen Tan  <jiewen_tan@apple.com>
 
         Only wrapping CryptoKeys for IDB during serialization
index 2840efd..51eaf27 100644 (file)
@@ -606,6 +606,9 @@ JS_BINDING_IDLS = \
     $(WebCore)/dom/FocusEvent.idl \
     $(WebCore)/dom/GlobalEventHandlers.idl \
     $(WebCore)/dom/HashChangeEvent.idl \
+    $(WebCore)/dom/IdleDeadline.idl \
+    $(WebCore)/dom/IdleRequestCallback.idl \
+    $(WebCore)/dom/IdleRequestOptions.idl \
     $(WebCore)/dom/InputEvent.idl \
     $(WebCore)/dom/KeyboardEvent.idl \
     $(WebCore)/dom/MessageChannel.idl \
index 4a81092..520e7c7 100644 (file)
@@ -886,6 +886,8 @@ dom/GenericEventQueue.cpp
 dom/HashChangeEvent.cpp
 dom/IdTargetObserver.cpp
 dom/IdTargetObserverRegistry.cpp
+dom/IdleDeadline.cpp
+dom/IdleCallbackController.cpp
 dom/InlineClassicScript.cpp
 dom/InlineStyleSheetOwner.cpp
 dom/InputEvent.cpp
@@ -2965,6 +2967,9 @@ JSIDBRequest.cpp
 JSIDBTransaction.cpp
 JSIDBTransactionMode.cpp
 JSIDBVersionChangeEvent.cpp
+JSIdleRequestCallback.cpp
+JSIdleRequestOptions.cpp
+JSIdleDeadline.cpp
 JSImageBitmap.cpp
 JSImageBitmapOptions.cpp
 JSImageBitmapRenderingContext.cpp
index 83c9ec7..e15c283 100644 (file)
                9B69D3B91B99100700E3512B /* JSHTMLSlotElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B69D3B71B99100700E3512B /* JSHTMLSlotElement.h */; };
                9B6C41531344949000085B62 /* StringWithDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B6C41521344949000085B62 /* StringWithDirection.h */; settings = {ATTRIBUTES = (Private, ); }; };
                9B714E211C91166900AC0E92 /* EventPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B714E1F1C91166900AC0E92 /* EventPath.h */; };
+               9B742605234BE95600DB52E9 /* IdleRequestCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B742603234BE95600DB52E9 /* IdleRequestCallback.h */; };
+               9B74260B234BEA6E00DB52E9 /* IdleDeadline.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B742608234BEA6E00DB52E9 /* IdleDeadline.h */; };
+               9B864F02234C028A006D10EB /* IdleRequestOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B864F00234C028A006D10EB /* IdleRequestOptions.h */; };
+               9B864F06234C0893006D10EB /* IdleCallbackController.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B864F05234C0893006D10EB /* IdleCallbackController.h */; };
                9BA273F4172206BB0097CE47 /* LogicalSelectionOffsetCaches.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BA273F3172206BB0097CE47 /* LogicalSelectionOffsetCaches.h */; };
                9BAAC45C21520128003D4A98 /* GCReachableRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BAAC4562151E39E003D4A98 /* GCReachableRef.h */; settings = {ATTRIBUTES = (Private, ); }; };
                9BAB6C6C12550631001626D4 /* EditingStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BAB6C6A12550631001626D4 /* EditingStyle.h */; settings = {ATTRIBUTES = (Private, ); }; };
                9B6C41521344949000085B62 /* StringWithDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringWithDirection.h; sourceTree = "<group>"; };
                9B714E1E1C91166900AC0E92 /* EventPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventPath.cpp; sourceTree = "<group>"; };
                9B714E1F1C91166900AC0E92 /* EventPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventPath.h; sourceTree = "<group>"; };
+               9B742603234BE95600DB52E9 /* IdleRequestCallback.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IdleRequestCallback.h; sourceTree = "<group>"; };
+               9B742604234BE95600DB52E9 /* IdleRequestCallback.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = IdleRequestCallback.idl; sourceTree = "<group>"; };
+               9B742608234BEA6E00DB52E9 /* IdleDeadline.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IdleDeadline.h; sourceTree = "<group>"; };
+               9B742609234BEA6E00DB52E9 /* IdleDeadline.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = IdleDeadline.cpp; sourceTree = "<group>"; };
+               9B74260A234BEA6E00DB52E9 /* IdleDeadline.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = IdleDeadline.idl; sourceTree = "<group>"; };
                9B85530520E733B5009EEF4F /* EventTargetFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = EventTargetFactory.cpp; path = DerivedSources/WebCore/EventTargetFactory.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
+               9B864F00234C028A006D10EB /* IdleRequestOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IdleRequestOptions.h; sourceTree = "<group>"; };
+               9B864F01234C028A006D10EB /* IdleRequestOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = IdleRequestOptions.idl; sourceTree = "<group>"; };
+               9B864F05234C0893006D10EB /* IdleCallbackController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IdleCallbackController.h; sourceTree = "<group>"; };
+               9B864F07234C08A3006D10EB /* IdleCallbackController.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = IdleCallbackController.cpp; sourceTree = "<group>"; };
                9B9299B01F6796A4006723C2 /* WebContentReaderCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContentReaderCocoa.mm; sourceTree = "<group>"; };
                9B9CADA72165DC7600E8D858 /* JSMutationRecordCustom.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSMutationRecordCustom.cpp; sourceTree = "<group>"; };
                9BA273F3172206BB0097CE47 /* LogicalSelectionOffsetCaches.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogicalSelectionOffsetCaches.h; sourceTree = "<group>"; };
                                E3BF19E622AF302A009C9926 /* HashChangeEvent.cpp */,
                                2442BBF81194C9D300D49469 /* HashChangeEvent.h */,
                                8482B7441198C32E00BFB005 /* HashChangeEvent.idl */,
+                               9B864F07234C08A3006D10EB /* IdleCallbackController.cpp */,
+                               9B864F05234C0893006D10EB /* IdleCallbackController.h */,
+                               9B742609234BEA6E00DB52E9 /* IdleDeadline.cpp */,
+                               9B742608234BEA6E00DB52E9 /* IdleDeadline.h */,
+                               9B74260A234BEA6E00DB52E9 /* IdleDeadline.idl */,
+                               9B742603234BE95600DB52E9 /* IdleRequestCallback.h */,
+                               9B742604234BE95600DB52E9 /* IdleRequestCallback.idl */,
+                               9B864F00234C028A006D10EB /* IdleRequestOptions.h */,
+                               9B864F01234C028A006D10EB /* IdleRequestOptions.idl */,
                                C3CF17A015B0063F00276D39 /* IdTargetObserver.cpp */,
                                C3CF17A115B0063F00276D39 /* IdTargetObserver.h */,
                                C3CF17A215B0063F00276D39 /* IdTargetObserverRegistry.cpp */,
                                1A71D57C0F33819000F9CE4E /* IdentifierRep.h in Headers */,
                                49E911C50EF86D47009D0CAF /* IdentityTransformOperation.h in Headers */,
                                7CE9A12B1EA2F1DB00651AD1 /* IDLAttributes.json in Headers */,
+                               9B864F06234C0893006D10EB /* IdleCallbackController.h in Headers */,
+                               9B74260B234BEA6E00DB52E9 /* IdleDeadline.h in Headers */,
+                               9B742605234BE95600DB52E9 /* IdleRequestCallback.h in Headers */,
+                               9B864F02234C028A006D10EB /* IdleRequestOptions.h in Headers */,
                                C0C054CD1118C8E400CE2636 /* IDLParser.pm in Headers */,
                                7C5222961E1DAE03002CB8F7 /* IDLTypes.h in Headers */,
                                C3CF17A515B0063F00276D39 /* IdTargetObserver.h in Headers */,
index ffd3e59..783af48 100644 (file)
@@ -130,6 +130,7 @@ namespace WebCore {
     macro(IDBVersionChangeEvent) \
     macro(ImageBitmap) \
     macro(ImageBitmapRenderingContext) \
+    macro(IdleDeadline) \
     macro(InputEvent) \
     macro(IntersectionObserver) \
     macro(IntersectionObserverEntry) \
@@ -243,6 +244,7 @@ namespace WebCore {
     macro(byobRequest) \
     macro(caches) \
     macro(cancel) \
+    macro(cancelIdleCallback) \
     macro(cloneArrayBuffer) \
     macro(close) \
     macro(closeRequested) \
@@ -317,6 +319,7 @@ namespace WebCore {
     macro(readableStreamController) \
     macro(reader) \
     macro(readyPromiseCapability) \
+    macro(requestIdleCallback) \
     macro(response) \
     macro(responseCacheIsValid) \
     macro(retrieveResponse) \
index a74922d..c8aa92f 100644 (file)
 #include "HashChangeEvent.h"
 #include "History.h"
 #include "HitTestResult.h"
+#include "IdleCallbackController.h"
 #include "ImageBitmapRenderingContext.h"
 #include "ImageLoader.h"
 #include "InspectorInstrumentation.h"
@@ -6361,6 +6362,20 @@ void Document::clearScriptedAnimationController()
     m_scriptedAnimationController = nullptr;
 }
 
+int Document::requestIdleCallback(Ref<IdleRequestCallback>&& callback, Seconds timeout)
+{
+    if (!m_idleCallbackController)
+        m_idleCallbackController = makeUnique<IdleCallbackController>();
+    return m_idleCallbackController->queueIdleCallback(WTFMove(callback), timeout);
+}
+
+void Document::cancelIdleCallback(int id)
+{
+    if (!m_idleCallbackController)
+        return;
+    m_idleCallbackController->removeIdleCallback(id);
+}
+
 void Document::wheelEventHandlersChanged()
 {
     Page* page = this->page();
index 6bf619c..7f8c5f8 100644 (file)
@@ -145,6 +145,8 @@ class HTMLScriptElement;
 class HitTestLocation;
 class HitTestRequest;
 class HitTestResult;
+class IdleCallbackController;
+class IdleRequestCallback;
 class ImageBitmapRenderingContext;
 class IntPoint;
 class JSNode;
@@ -1206,6 +1208,9 @@ public:
     int requestAnimationFrame(Ref<RequestAnimationFrameCallback>&&);
     void cancelAnimationFrame(int id);
 
+    int requestIdleCallback(Ref<IdleRequestCallback>&&, Seconds timeout);
+    void cancelIdleCallback(int id);
+
     EventTarget* errorEventTarget() final;
     void logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, RefPtr<Inspector::ScriptCallStack>&&) final;
 
@@ -1838,6 +1843,8 @@ private:
     void clearScriptedAnimationController();
     RefPtr<ScriptedAnimationController> m_scriptedAnimationController;
 
+    std::unique_ptr<IdleCallbackController> m_idleCallbackController;
+
     void notifyMediaCaptureOfVisibilityChanged();
 
     void didLogMessage(const WTFLogChannel&, WTFLogLevel, Vector<JSONLogValue>&&) final;
diff --git a/Source/WebCore/dom/IdleCallbackController.cpp b/Source/WebCore/dom/IdleCallbackController.cpp
new file mode 100644 (file)
index 0000000..789afb7
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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 "IdleCallbackController.h"
+
+namespace WebCore {
+
+int IdleCallbackController::queueIdleCallback(Ref<IdleRequestCallback>&& callback, Seconds)
+{
+    ++m_idleCallbackIdentifier;
+    auto handle = m_idleCallbackIdentifier;
+
+    m_idleRequests.append({ handle, WTFMove(callback) });
+
+    // FIXME: Queue a task if start_idle_period is true.
+    // FIXME: Queue a task if timeout is positive.
+
+    return handle;
+}
+
+void IdleCallbackController::removeIdleCallback(int signedIdentifier)
+{
+    if (signedIdentifier <= 0)
+        return;
+    unsigned identifier = signedIdentifier;
+    m_idleRequests.removeFirstMatching([identifier](auto& request) {
+        return request.identifier == identifier;
+    });
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/dom/IdleCallbackController.h b/Source/WebCore/dom/IdleCallbackController.h
new file mode 100644 (file)
index 0000000..a027d10
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "IdleRequestCallback.h"
+#include <wtf/Seconds.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class IdleCallbackController {
+    WTF_MAKE_FAST_ALLOCATED;
+
+public:
+    int queueIdleCallback(Ref<IdleRequestCallback>&&, Seconds timeout);
+    void removeIdleCallback(int);
+
+private:
+    unsigned m_idleCallbackIdentifier { 0 };
+
+    struct IdleRequest {
+        unsigned identifier;
+        Ref<IdleRequestCallback> callback;
+    };
+
+    Vector<IdleRequest> m_idleRequests;
+};
+
+} // namespace WebCore
diff --git a/Source/WebCore/dom/IdleDeadline.cpp b/Source/WebCore/dom/IdleDeadline.cpp
new file mode 100644 (file)
index 0000000..a193fb4
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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
diff --git a/Source/WebCore/dom/IdleDeadline.h b/Source/WebCore/dom/IdleDeadline.h
new file mode 100644 (file)
index 0000000..9fe787f
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "DOMHighResTimeStamp.h"
+#include <wtf/MonotonicTime.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class Document;
+
+class IdleDeadline final : public RefCounted<IdleDeadline> {
+public:
+    Ref<IdleDeadline> create(MonotonicTime deadline)
+    {
+        return adoptRef(*new IdleDeadline(deadline));
+    }
+
+    DOMHighResTimeStamp timeRemaining(Document&) const;
+    bool didTimeout(Document&) const;
+
+private:
+    IdleDeadline(MonotonicTime deadline)
+        : m_deadline(deadline)
+    { }
+
+    const MonotonicTime m_deadline;
+};
+
+} // namespace WebCore
diff --git a/Source/WebCore/dom/IdleDeadline.idl b/Source/WebCore/dom/IdleDeadline.idl
new file mode 100644 (file)
index 0000000..099fc8a
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+typedef double DOMHighResTimeStamp;
+
+[
+    EnabledBySetting=requestIdleCallback,
+    ImplementationLacksVTable
+] interface IdleDeadline {
+    [CallWith=Document] DOMHighResTimeStamp timeRemaining();
+    [CallWith=Document] readonly attribute boolean didTimeout;
+};
diff --git a/Source/WebCore/dom/IdleRequestCallback.h b/Source/WebCore/dom/IdleRequestCallback.h
new file mode 100644 (file)
index 0000000..ef8096c
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "ActiveDOMCallback.h"
+#include "CallbackResult.h"
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class IdleDeadline;
+
+class IdleRequestCallback : public RefCounted<IdleRequestCallback>, public ActiveDOMCallback {
+public:
+    using ActiveDOMCallback::ActiveDOMCallback;
+
+    virtual CallbackResult<void> handleEvent(IdleDeadline&) = 0;
+};
+
+} // namespace WebCore
diff --git a/Source/WebCore/dom/IdleRequestCallback.idl b/Source/WebCore/dom/IdleRequestCallback.idl
new file mode 100644 (file)
index 0000000..d5f07ba
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+callback IdleRequestCallback = void (IdleDeadline deadline);
diff --git a/Source/WebCore/dom/IdleRequestOptions.h b/Source/WebCore/dom/IdleRequestOptions.h
new file mode 100644 (file)
index 0000000..a9b7733
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <wtf/Optional.h>
+
+namespace WebCore {
+
+struct IdleRequestOptions {
+    unsigned timeout { 0 }; // Used if positive.
+};
+
+} // namespace WebCore
diff --git a/Source/WebCore/dom/IdleRequestOptions.idl b/Source/WebCore/dom/IdleRequestOptions.idl
new file mode 100644 (file)
index 0000000..bdcf449
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+dictionary IdleRequestOptions {
+    unsigned long timeout;
+};
index df47d8e..a36ab93 100644 (file)
@@ -68,6 +68,7 @@
 #include "FrameView.h"
 #include "HTTPParsers.h"
 #include "History.h"
+#include "IdleRequestOptions.h"
 #include "InspectorInstrumentation.h"
 #include "JSDOMPromiseDeferred.h"
 #include "JSDOMWindowBase.h"
@@ -1781,6 +1782,22 @@ void DOMWindow::cancelAnimationFrame(int id)
     document->cancelAnimationFrame(id);
 }
 
+int DOMWindow::requestIdleCallback(Ref<IdleRequestCallback>&& callback, const IdleRequestOptions& options)
+{
+    auto document = makeRefPtr(this->document());
+    if (!document)
+        return 0;
+    return document->requestIdleCallback(WTFMove(callback), Seconds::fromMilliseconds(options.timeout));
+}
+
+void DOMWindow::cancelIdleCallback(int id)
+{
+    auto document = makeRefPtr(this->document());
+    if (!document)
+        return;
+    return document->cancelIdleCallback(id);
+}
+
 void DOMWindow::createImageBitmap(ImageBitmap::Source&& source, ImageBitmapOptions&& options, ImageBitmap::Promise&& promise)
 {
     auto* document = this->document();
index b48224e..0da4fb0 100644 (file)
@@ -65,6 +65,7 @@ class Element;
 class EventListener;
 class FloatRect;
 class History;
+class IdleRequestCallback;
 class Location;
 class MediaQueryList;
 class Navigator;
@@ -75,6 +76,7 @@ class PageConsoleClient;
 class Performance;
 class PostMessageTimer;
 class RequestAnimationFrameCallback;
+class RequestIdleCallback;
 class ScheduledAction;
 class Screen;
 class Storage;
@@ -88,6 +90,7 @@ class DeviceMotionController;
 class DeviceOrientationController;
 #endif
 
+struct IdleRequestOptions;
 struct ImageBitmapOptions;
 struct WindowFeatures;
 
@@ -276,6 +279,9 @@ public:
     int webkitRequestAnimationFrame(Ref<RequestAnimationFrameCallback>&&);
     void cancelAnimationFrame(int id);
 
+    int requestIdleCallback(Ref<IdleRequestCallback>&&, const IdleRequestOptions&);
+    void cancelIdleCallback(int id);
+
     // ImageBitmap
     void createImageBitmap(ImageBitmap::Source&&, ImageBitmapOptions&&, ImageBitmap::Promise&&);
     void createImageBitmap(ImageBitmap::Source&&, int sx, int sy, int sw, int sh, ImageBitmapOptions&&, ImageBitmap::Promise&&);
index 84f511c..1a5354f 100644 (file)
@@ -93,6 +93,9 @@ typedef USVString CSSOMString;
     long requestAnimationFrame(RequestAnimationFrameCallback callback); // FIXME: Should return an unsigned long.
     void cancelAnimationFrame(long handle); // FIXME: handle should be an unsigned long.
 
+    [EnabledBySetting=requestIdleCallback] unsigned long requestIdleCallback(IdleRequestCallback callback, optional IdleRequestOptions options);
+    [EnabledBySetting=requestIdleCallback] void cancelIdleCallback(unsigned long handle);
+
     [CallWith=ExecState&IncumbentWindow, DoNotCheckSecurity, ForwardDeclareInHeader, MayThrowException] void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer = []);
 
     // Obsolete members, still part of the HTML specification (https://html.spec.whatwg.org/#Window-partial).
index 335b78a..1f30f72 100644 (file)
@@ -337,6 +337,8 @@ wantsBalancedSetDefersLoadingBehavior:
   initial: false
 requestAnimationFrameEnabled:
   initial: true
+requestIdleCallbackEnabled:
+  initial: false
 
 HTTPSUpgradeEnabled:
   initial: false
index 12342c7..9011787 100644 (file)
@@ -1,3 +1,12 @@
+2019-10-07  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Add IDL for requestIdleCallback
+        https://bugs.webkit.org/show_bug.cgi?id=202653
+
+        Reviewed by Geoffrey Garen.
+
+        * Shared/WebPreferences.yaml:
+
 2019-10-07  Kate Cheney  <katherine_cheney@apple.com>
 
         Domain relationships in the ITP Database should be inserted in a single query and ignore repeat insert attempts. (202604)
index bb88967..7de1f77 100644 (file)
@@ -362,6 +362,13 @@ RequestAnimationFrameEnabled:
   type: bool
   defaultValue: true
 
+RequestIdleCallbackEnabled:
+  type: bool
+  defaultValue: false
+  humanReadableName: "requestIdleCallback"
+  humanReadableDescription: "Enable requestIdleCallback support"
+  category: experimental
+
 DiagnosticLoggingEnabled:
   type: bool
   defaultValue: false
index b34cd05..b24ec14 100644 (file)
@@ -1,3 +1,17 @@
+2019-10-07  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Add IDL for requestIdleCallback
+        https://bugs.webkit.org/show_bug.cgi?id=202653
+
+        Reviewed by Geoffrey Garen.
+
+        * WebView/WebPreferenceKeysPrivate.h:
+        * WebView/WebPreferences.mm:
+        (+[WebPreferences initialize]):
+        * WebView/WebPreferencesPrivate.h:
+        * WebView/WebView.mm:
+        (-[WebView _preferencesChanged:]):
+
 2019-10-07  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [JSC] Change signature of HostFunction to (JSGlobalObject*, CallFrame*)
index fe356c9..2358eef 100644 (file)
 #define WebKitReferrerPolicyAttributeEnabledPreferenceKey @"WebKitReferrerPolicyAttributeEnabled"
 #define WebKitResizeObserverEnabledPreferenceKey @"WebKitResizeObserverEnabled"
 #define WebKitCoreMathMLEnabledPreferenceKey @"WebKitCoreMathMLEnabled"
+#define WebKitRequestIdleCallbackEnabledPreferenceKey @"WebKitRequestIdleCallbackEnabled"
 #define WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey @"WebKitLinkPreloadResponsiveImagesEnabled"
 
index 04a6f36..e6f266c 100644 (file)
@@ -690,6 +690,7 @@ public:
         @NO, WebKitResizeObserverEnabledPreferenceKey,
 #endif
         @NO, WebKitCoreMathMLEnabledPreferenceKey,
+        @NO, WebKitRequestIdleCallbackEnabledPreferenceKey,
         @NO, WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey,
         @NO, WebKitCSSShadowPartsEnabledPreferenceKey,
         nil];
@@ -3498,6 +3499,16 @@ static NSString *classIBCreatorID = nil;
     [self _setBoolValue:flag forKey:WebKitCoreMathMLEnabledPreferenceKey];
 }
 
+- (BOOL)requestIdleCallbackEnabled
+{
+    return [self _boolValueForKey:WebKitRequestIdleCallbackEnabledPreferenceKey];
+}
+
+- (void)setRequestIdleCallbackEnabled:(BOOL)flag
+{
+    [self _setBoolValue:flag forKey:WebKitRequestIdleCallbackEnabledPreferenceKey];
+}
+
 - (BOOL)linkPreloadResponsiveImagesEnabled
 {
     return [self _boolValueForKey:WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey];
index cdaf7c2..41d5591 100644 (file)
@@ -612,6 +612,9 @@ extern NSString *WebPreferencesCacheModelChangedInternalNotification WEBKIT_DEPR
 - (void)setCoreMathMLEnabled:(BOOL)flag;
 - (BOOL)coreMathMLEnabled;
 
+- (void)setRequestIdleCallbackEnabled:(BOOL)flag;
+- (BOOL)requestIdleCallbackEnabled;
+
 - (void)setLinkPreloadResponsiveImagesEnabled:(BOOL)flag;
 - (BOOL)linkPreloadResponsiveImagesEnabled;
 
@@ -652,6 +655,7 @@ extern NSString *WebPreferencesCacheModelChangedInternalNotification WEBKIT_DEPR
 @property (nonatomic) BOOL referrerPolicyAttributeEnabled;
 @property (nonatomic) BOOL resizeObserverEnabled;
 @property (nonatomic) BOOL coreMathMLEnabled;
+@property (nonatomic) BOOL requestIdleCallbackEnabled;
 @property (nonatomic) BOOL linkPreloadResponsiveImagesEnabled;
 
 #if TARGET_OS_IPHONE
index 11c683e..61dbc93 100644 (file)
@@ -3235,6 +3235,7 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings.setMediaCapabilitiesEnabled([preferences mediaCapabilitiesEnabled]);
 
     settings.setCoreMathMLEnabled([preferences coreMathMLEnabled]);
+    settings.setRequestIdleCallbackEnabled([preferences requestIdleCallbackEnabled]);
 
     RuntimeEnabledFeatures::sharedFeatures().setServerTimingEnabled([preferences serverTimingEnabled]);
 
index 8fb986e..c0ed1e9 100644 (file)
@@ -1,3 +1,16 @@
+2019-10-07  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Add IDL for requestIdleCallback
+        https://bugs.webkit.org/show_bug.cgi?id=202653
+
+        Reviewed by Geoffrey Garen.
+
+        * DumpRenderTree/TestOptions.cpp:
+        (TestOptions::TestOptions):
+        * DumpRenderTree/TestOptions.h:
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (setWebPreferencesForTestOptions):
+
 2019-10-07  Jiewen Tan  <jiewen_tan@apple.com>
 
         Only wrapping CryptoKeys for IDB during serialization
index 294d14a..6282d72 100644 (file)
@@ -123,6 +123,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:RequestIdleCallbackEnabled")
+            enableRequestIdleCallback = parseBooleanTestHeaderValue(value);
         pairStart = pairEnd + 1;
     }
 }
index 1a9d85b..37a3b4b 100644 (file)
@@ -51,6 +51,7 @@ struct TestOptions {
     bool adClickAttributionEnabled { false };
     bool enableResizeObserver { false };
     bool enableCoreMathML { false };
+    bool enableRequestIdleCallback { false };
     std::string jscOptions;
     std::string additionalSupportedImageTypes;
 
index 8295a3b..35d2641 100644 (file)
@@ -1028,6 +1028,7 @@ static void setWebPreferencesForTestOptions(const TestOptions& options)
     preferences.adClickAttributionEnabled = options.adClickAttributionEnabled;
     preferences.resizeObserverEnabled = options.enableResizeObserver;
     preferences.coreMathMLEnabled = options.enableCoreMathML;
+    preferences.requestIdleCallbackEnabled = options.enableRequestIdleCallback;
     preferences.privateBrowsingEnabled = options.useEphemeralSession;
     preferences.usesPageCache = options.enablePageCache;
 }