[Experiment] Implement code to detect high frequency painting
[WebKit-https.git] / Source / WebCore / testing / Internals.h
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #pragma once
28
29 #include "CSSComputedStyleDeclaration.h"
30 #include "ContextDestructionObserver.h"
31 #include "ExceptionOr.h"
32 #include "JSDOMPromiseDeferred.h"
33 #include "OrientationNotifier.h"
34 #include "PageConsoleClient.h"
35 #include "RealtimeMediaSource.h"
36 #include <runtime/Float32Array.h>
37 #include <wtf/Optional.h>
38
39 #if ENABLE(MEDIA_SESSION)
40 #include "MediaSessionInterruptionProvider.h"
41 #endif
42
43 namespace WebCore {
44
45 class AnimationTimeline;
46 class AudioContext;
47 class CacheStorageConnection;
48 class DOMRect;
49 class DOMRectList;
50 class DOMURL;
51 class DOMWindow;
52 class Document;
53 class Element;
54 class ExtendableEvent;
55 class FetchEvent;
56 class FetchResponse;
57 class File;
58 class Frame;
59 class GCObservation;
60 class HTMLImageElement;
61 class HTMLInputElement;
62 class HTMLLinkElement;
63 class HTMLMediaElement;
64 class HTMLSelectElement;
65 class ImageData;
66 class InspectorStubFrontend;
67 class InternalSettings;
68 class MallocStatistics;
69 class MediaSession;
70 class MediaStream;
71 class MediaStreamTrack;
72 class MemoryInfo;
73 class MockCDMFactory;
74 class MockContentFilterSettings;
75 class MockPageOverlay;
76 class MockPaymentCoordinator;
77 class NodeList;
78 class Page;
79 class Range;
80 class RenderedDocumentMarker;
81 class RTCPeerConnection;
82 class SVGSVGElement;
83 class SerializedScriptValue;
84 class SourceBuffer;
85 class StringCallback;
86 class StyleSheet;
87 class TimeRanges;
88 class TypeConversions;
89 class WebGLRenderingContext;
90 class XMLHttpRequest;
91
92 class Internals final : public RefCounted<Internals>,  private ContextDestructionObserver
93 #if ENABLE(MEDIA_STREAM)
94     , private RealtimeMediaSource::Observer
95 #endif
96     {
97 public:
98     static Ref<Internals> create(Document&);
99     virtual ~Internals();
100
101     static void resetToConsistentState(Page&);
102
103     ExceptionOr<String> elementRenderTreeAsText(Element&);
104     bool hasPausedImageAnimations(Element&);
105
106     bool isPaintingFrequently(Element&);
107     void incrementFrequentPaintCounter(Element&);
108
109     String address(Node&);
110     bool nodeNeedsStyleRecalc(Node&);
111     String styleChangeType(Node&);
112     String description(JSC::JSValue);
113
114     bool isPreloaded(const String& url);
115     bool isLoadingFromMemoryCache(const String& url);
116     String fetchResponseSource(FetchResponse&);
117     String xhrResponseSource(XMLHttpRequest&);
118     bool isSharingStyleSheetContents(HTMLLinkElement&, HTMLLinkElement&);
119     bool isStyleSheetLoadingSubresources(HTMLLinkElement&);
120     enum class CachePolicy { UseProtocolCachePolicy, ReloadIgnoringCacheData, ReturnCacheDataElseLoad, ReturnCacheDataDontLoad };
121     void setOverrideCachePolicy(CachePolicy);
122     ExceptionOr<void> setCanShowModalDialogOverride(bool allow);
123     enum class ResourceLoadPriority { ResourceLoadPriorityVeryLow, ResourceLoadPriorityLow, ResourceLoadPriorityMedium, ResourceLoadPriorityHigh, ResourceLoadPriorityVeryHigh };
124     void setOverrideResourceLoadPriority(ResourceLoadPriority);
125     void setStrictRawResourceValidationPolicyDisabled(bool);
126
127     void clearMemoryCache();
128     void pruneMemoryCacheToSize(unsigned size);
129     void destroyDecodedDataForAllImages();
130     unsigned memoryCacheSize() const;
131
132     unsigned imageFrameIndex(HTMLImageElement&);
133     void setImageFrameDecodingDuration(HTMLImageElement&, float duration);
134     void resetImageAnimation(HTMLImageElement&);
135     bool isImageAnimating(HTMLImageElement&);
136     void setClearDecoderAfterAsyncFrameRequestForTesting(HTMLImageElement&, bool enabled);
137     unsigned imageDecodeCount(HTMLImageElement&);
138     void setLargeImageAsyncDecodingEnabledForTesting(HTMLImageElement&, bool enabled);
139
140     void setGridMaxTracksLimit(unsigned);
141
142     void clearPageCache();
143     unsigned pageCacheSize() const;
144
145     void disableTileSizeUpdateDelay();
146
147     void setSpeculativeTilingDelayDisabledForTesting(bool);
148
149     Ref<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Element&) const;
150
151     Node* ensureUserAgentShadowRoot(Element& host);
152     Node* shadowRoot(Element& host);
153     ExceptionOr<String> shadowRootType(const Node&) const;
154     String shadowPseudoId(Element&);
155     void setShadowPseudoId(Element&, const String&);
156
157     // CSS Deferred Parsing Testing
158     unsigned deferredStyleRulesCount(StyleSheet&);
159     unsigned deferredGroupRulesCount(StyleSheet&);
160     unsigned deferredKeyframesRulesCount(StyleSheet&);
161
162     // DOMTimers throttling testing.
163     ExceptionOr<bool> isTimerThrottled(int timeoutId);
164     bool isRequestAnimationFrameThrottled() const;
165     double requestAnimationFrameInterval() const;
166     bool scriptedAnimationsAreSuspended() const;
167     bool areTimersThrottled() const;
168
169     enum EventThrottlingBehavior { Responsive, Unresponsive };
170     void setEventThrottlingBehaviorOverride(std::optional<EventThrottlingBehavior>);
171     std::optional<EventThrottlingBehavior> eventThrottlingBehaviorOverride() const;
172
173     // Spatial Navigation testing.
174     ExceptionOr<unsigned> lastSpatialNavigationCandidateCount() const;
175
176     // CSS Animation testing.
177     unsigned numberOfActiveAnimations() const;
178     ExceptionOr<bool> animationsAreSuspended() const;
179     ExceptionOr<void> suspendAnimations() const;
180     ExceptionOr<void> resumeAnimations() const;
181     ExceptionOr<bool> pauseAnimationAtTimeOnElement(const String& animationName, double pauseTime, Element&);
182     ExceptionOr<bool> pauseAnimationAtTimeOnPseudoElement(const String& animationName, double pauseTime, Element&, const String& pseudoId);
183     double animationsInterval() const;
184
185     // CSS Transition testing.
186     ExceptionOr<bool> pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element&);
187     ExceptionOr<bool> pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element&, const String& pseudoId);
188
189     Node* treeScopeRootNode(Node&);
190     Node* parentTreeScope(Node&);
191
192     String visiblePlaceholder(Element&);
193     void selectColorInColorChooser(HTMLInputElement&, const String& colorValue);
194     ExceptionOr<Vector<String>> formControlStateOfPreviousHistoryItem();
195     ExceptionOr<void> setFormControlStateOfPreviousHistoryItem(const Vector<String>&);
196
197     ExceptionOr<Ref<DOMRect>> absoluteCaretBounds();
198
199     Ref<DOMRect> boundingBox(Element&);
200
201     ExceptionOr<Ref<DOMRectList>> inspectorHighlightRects();
202     ExceptionOr<String> inspectorHighlightObject();
203
204     ExceptionOr<unsigned> markerCountForNode(Node&, const String&);
205     ExceptionOr<RefPtr<Range>> markerRangeForNode(Node&, const String& markerType, unsigned index);
206     ExceptionOr<String> markerDescriptionForNode(Node&, const String& markerType, unsigned index);
207     ExceptionOr<String> dumpMarkerRects(const String& markerType);
208     void addTextMatchMarker(const Range&, bool isActive);
209     ExceptionOr<void> setMarkedTextMatchesAreHighlighted(bool);
210
211     void invalidateFontCache();
212     void setFontSmoothingEnabled(bool);
213
214     ExceptionOr<void> setLowPowerModeEnabled(bool);
215
216     ExceptionOr<void> setScrollViewPosition(int x, int y);
217     ExceptionOr<void> unconstrainedScrollTo(Element&, double x, double y);
218
219     ExceptionOr<Ref<DOMRect>> layoutViewportRect();
220     ExceptionOr<Ref<DOMRect>> visualViewportRect();
221
222     ExceptionOr<void> setViewBaseBackgroundColor(const String& colorValue);
223
224     ExceptionOr<void> setPagination(const String& mode, int gap, int pageLength);
225     ExceptionOr<void> setPaginationLineGridEnabled(bool);
226     ExceptionOr<String> configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight);
227
228     ExceptionOr<bool> wasLastChangeUserEdit(Element& textField);
229     bool elementShouldAutoComplete(HTMLInputElement&);
230     void setEditingValue(HTMLInputElement&, const String&);
231     void setAutofilled(HTMLInputElement&, bool enabled);
232     enum class AutoFillButtonType { AutoFillButtonTypeNone, AutoFillButtonTypeContacts, AutoFillButtonTypeCredentials };
233     void setShowAutoFillButton(HTMLInputElement&, AutoFillButtonType);
234     ExceptionOr<void> scrollElementToRect(Element&, int x, int y, int w, int h);
235
236     ExceptionOr<String> autofillFieldName(Element&);
237
238     ExceptionOr<void> paintControlTints();
239
240     RefPtr<Range> rangeFromLocationAndLength(Element& scope, int rangeLocation, int rangeLength);
241     unsigned locationFromRange(Element& scope, const Range&);
242     unsigned lengthFromRange(Element& scope, const Range&);
243     String rangeAsText(const Range&);
244     Ref<Range> subrange(Range&, int rangeLocation, int rangeLength);
245     ExceptionOr<RefPtr<Range>> rangeForDictionaryLookupAtLocation(int x, int y);
246     RefPtr<Range> rangeOfStringNearLocation(const Range&, const String&, unsigned);
247
248     ExceptionOr<void> setDelegatesScrolling(bool enabled);
249
250     ExceptionOr<int> lastSpellCheckRequestSequence();
251     ExceptionOr<int> lastSpellCheckProcessedSequence();
252
253     Vector<String> userPreferredLanguages() const;
254     void setUserPreferredLanguages(const Vector<String>&);
255
256     Vector<String> userPreferredAudioCharacteristics() const;
257     void setUserPreferredAudioCharacteristic(const String&);
258
259     ExceptionOr<unsigned> wheelEventHandlerCount();
260     ExceptionOr<unsigned> touchEventHandlerCount();
261
262     ExceptionOr<Ref<DOMRectList>> touchEventRectsForEvent(const String&);
263     ExceptionOr<Ref<DOMRectList>> passiveTouchEventListenerRects();
264
265     ExceptionOr<RefPtr<NodeList>> nodesFromRect(Document&, int x, int y, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowUserAgentShadowContent, bool allowChildFrameContent) const;
266
267     String parserMetaData(JSC::JSValue = JSC::JSValue::JSUndefined);
268
269     void updateEditorUINowIfScheduled();
270
271     bool hasSpellingMarker(int from, int length);
272     bool hasGrammarMarker(int from, int length);
273     bool hasAutocorrectedMarker(int from, int length);
274     void setContinuousSpellCheckingEnabled(bool);
275     void setAutomaticQuoteSubstitutionEnabled(bool);
276     void setAutomaticLinkDetectionEnabled(bool);
277     void setAutomaticDashSubstitutionEnabled(bool);
278     void setAutomaticTextReplacementEnabled(bool);
279     void setAutomaticSpellingCorrectionEnabled(bool);
280
281     void handleAcceptedCandidate(const String& candidate, unsigned location, unsigned length);
282
283     bool isOverwriteModeEnabled();
284     void toggleOverwriteModeEnabled();
285
286     ExceptionOr<RefPtr<Range>> rangeOfString(const String&, RefPtr<Range>&&, const Vector<String>& findOptions);
287     ExceptionOr<unsigned> countMatchesForText(const String&, const Vector<String>& findOptions, const String& markMatches);
288     ExceptionOr<unsigned> countFindMatches(const String&, const Vector<String>& findOptions);
289
290     unsigned numberOfScrollableAreas();
291
292     ExceptionOr<bool> isPageBoxVisible(int pageNumber);
293
294     static const char* internalsId;
295
296     InternalSettings* settings() const;
297     unsigned workerThreadCount() const;
298     ExceptionOr<bool> areSVGAnimationsPaused() const;
299     ExceptionOr<double> svgAnimationsInterval(SVGSVGElement&) const;
300
301     enum {
302         // Values need to be kept in sync with Internals.idl.
303         LAYER_TREE_INCLUDES_VISIBLE_RECTS = 1,
304         LAYER_TREE_INCLUDES_TILE_CACHES = 2,
305         LAYER_TREE_INCLUDES_REPAINT_RECTS = 4,
306         LAYER_TREE_INCLUDES_PAINTING_PHASES = 8,
307         LAYER_TREE_INCLUDES_CONTENT_LAYERS = 16,
308         LAYER_TREE_INCLUDES_ACCELERATES_DRAWING = 32,
309         LAYER_TREE_INCLUDES_BACKING_STORE_ATTACHED = 64,
310     };
311     ExceptionOr<String> layerTreeAsText(Document&, unsigned short flags) const;
312     ExceptionOr<uint64_t> layerIDForElement(Element&);
313     ExceptionOr<String> repaintRectsAsText() const;
314     ExceptionOr<String> scrollingStateTreeAsText() const;
315     ExceptionOr<String> mainThreadScrollingReasons() const;
316     ExceptionOr<Ref<DOMRectList>> nonFastScrollableRects() const;
317
318     ExceptionOr<void> setElementUsesDisplayListDrawing(Element&, bool usesDisplayListDrawing);
319     ExceptionOr<void> setElementTracksDisplayListReplay(Element&, bool isTrackingReplay);
320
321     enum {
322         // Values need to be kept in sync with Internals.idl.
323         DISPLAY_LIST_INCLUDES_PLATFORM_OPERATIONS = 1,
324     };
325     ExceptionOr<String> displayListForElement(Element&, unsigned short flags);
326     ExceptionOr<String> replayDisplayListForElement(Element&, unsigned short flags);
327
328     ExceptionOr<void> garbageCollectDocumentResources() const;
329
330     void beginSimulatedMemoryPressure();
331     void endSimulatedMemoryPressure();
332     bool isUnderMemoryPressure();
333
334     ExceptionOr<void> insertAuthorCSS(const String&) const;
335     ExceptionOr<void> insertUserCSS(const String&) const;
336
337     unsigned numberOfLiveNodes() const;
338     unsigned numberOfLiveDocuments() const;
339     unsigned referencingNodeCount(const Document&) const;
340
341     RefPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
342     void closeDummyInspectorFrontend();
343     ExceptionOr<void> setInspectorIsUnderTest(bool);
344
345     String counterValue(Element&);
346
347     int pageNumber(Element&, float pageWidth = 800, float pageHeight = 600);
348     Vector<String> shortcutIconURLs() const;
349
350     int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
351     ExceptionOr<String> pageProperty(const String& propertyName, int pageNumber) const;
352     ExceptionOr<String> pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const;
353
354     ExceptionOr<float> pageScaleFactor() const;
355
356     ExceptionOr<void> setPageScaleFactor(float scaleFactor, int x, int y);
357     ExceptionOr<void> setPageZoomFactor(float);
358     ExceptionOr<void> setTextZoomFactor(float);
359
360     ExceptionOr<void> setUseFixedLayout(bool);
361     ExceptionOr<void> setFixedLayoutSize(int width, int height);
362     ExceptionOr<void> setViewExposedRect(float left, float top, float width, float height);
363     void setPrinting(int width, int height);
364
365     void setHeaderHeight(float);
366     void setFooterHeight(float);
367
368     void setTopContentInset(float);
369
370 #if ENABLE(FULLSCREEN_API)
371     void webkitWillEnterFullScreenForElement(Element&);
372     void webkitDidEnterFullScreenForElement(Element&);
373     void webkitWillExitFullScreenForElement(Element&);
374     void webkitDidExitFullScreenForElement(Element&);
375 #endif
376
377     WEBCORE_TESTSUPPORT_EXPORT void setApplicationCacheOriginQuota(unsigned long long);
378
379     void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
380     void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
381
382     void registerDefaultPortForProtocol(unsigned short port, const String& protocol);
383
384     Ref<MallocStatistics> mallocStatistics() const;
385     Ref<TypeConversions> typeConversions() const;
386     Ref<MemoryInfo> memoryInfo() const;
387
388     Vector<String> getReferencedFilePaths() const;
389
390     ExceptionOr<void> startTrackingRepaints();
391     ExceptionOr<void> stopTrackingRepaints();
392
393     ExceptionOr<void> startTrackingLayerFlushes();
394     ExceptionOr<unsigned> layerFlushCount();
395
396     ExceptionOr<void> startTrackingStyleRecalcs();
397     ExceptionOr<unsigned> styleRecalcCount();
398     unsigned lastStyleUpdateSize() const;
399
400     ExceptionOr<void> startTrackingCompositingUpdates();
401     ExceptionOr<unsigned> compositingUpdateCount();
402
403     ExceptionOr<void> updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*);
404     unsigned layoutCount() const;
405
406     Ref<ArrayBuffer> serializeObject(const RefPtr<SerializedScriptValue>&) const;
407     Ref<SerializedScriptValue> deserializeBuffer(ArrayBuffer&) const;
408
409     bool isFromCurrentWorld(JSC::JSValue) const;
410
411     void setUsesOverlayScrollbars(bool);
412     void setUsesMockScrollAnimator(bool);
413
414     ExceptionOr<String> getCurrentCursorInfo();
415
416     String markerTextForListItem(Element&);
417
418     String toolTipFromElement(Element&) const;
419
420     void forceReload(bool endToEnd);
421     void reloadExpiredOnly();
422
423     void enableAutoSizeMode(bool enabled, int minimumWidth, int minimumHeight, int maximumWidth, int maximumHeight);
424
425 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
426     void initializeMockCDM();
427 #endif
428
429 #if ENABLE(ENCRYPTED_MEDIA)
430     Ref<MockCDMFactory> registerMockCDM();
431 #endif
432
433 #if ENABLE(SPEECH_SYNTHESIS)
434     void enableMockSpeechSynthesizer();
435 #endif
436
437 #if ENABLE(MEDIA_STREAM)
438     void setMockMediaCaptureDevicesEnabled(bool);
439 #endif
440
441 #if ENABLE(WEB_RTC)
442     void emulateRTCPeerConnectionPlatformEvent(RTCPeerConnection&, const String& action);
443     void useMockRTCPeerConnectionFactory(const String&);
444     void setICECandidateFiltering(bool);
445     void setEnumeratingAllNetworkInterfacesEnabled(bool);
446     void stopPeerConnection(RTCPeerConnection&);
447     void applyRotationForOutgoingVideoSources(RTCPeerConnection&);
448 #endif
449
450     String getImageSourceURL(Element&);
451
452 #if ENABLE(VIDEO)
453     Vector<String> mediaResponseSources(HTMLMediaElement&);
454     Vector<String> mediaResponseContentRanges(HTMLMediaElement&);
455     void simulateAudioInterruption(HTMLMediaElement&);
456     ExceptionOr<bool> mediaElementHasCharacteristic(HTMLMediaElement&, const String&);
457 #endif
458
459     bool isSelectPopupVisible(HTMLSelectElement&);
460
461     ExceptionOr<String> captionsStyleSheetOverride();
462     ExceptionOr<void> setCaptionsStyleSheetOverride(const String&);
463     ExceptionOr<void> setPrimaryAudioTrackLanguageOverride(const String&);
464     ExceptionOr<void> setCaptionDisplayMode(const String&);
465
466 #if ENABLE(VIDEO)
467     Ref<TimeRanges> createTimeRanges(Float32Array& startTimes, Float32Array& endTimes);
468     double closestTimeToTimeRanges(double time, TimeRanges&);
469 #endif
470
471     ExceptionOr<Ref<DOMRect>> selectionBounds();
472
473     ExceptionOr<bool> isPluginUnavailabilityIndicatorObscured(Element&);
474     bool isPluginSnapshotted(Element&);
475
476 #if ENABLE(MEDIA_SOURCE)
477     WEBCORE_TESTSUPPORT_EXPORT void initializeMockMediaSource();
478     Vector<String> bufferedSamplesForTrackID(SourceBuffer&, const AtomicString&);
479     Vector<String> enqueuedSamplesForTrackID(SourceBuffer&, const AtomicString&);
480     void setShouldGenerateTimestamps(SourceBuffer&, bool);
481 #endif
482
483 #if ENABLE(VIDEO)
484     ExceptionOr<void> beginMediaSessionInterruption(const String&);
485     void endMediaSessionInterruption(const String&);
486     void applicationWillBecomeInactive();
487     void applicationDidBecomeActive();
488     void applicationWillEnterForeground(bool suspendedUnderLock) const;
489     void applicationDidEnterBackground(bool suspendedUnderLock) const;
490     ExceptionOr<void> setMediaSessionRestrictions(const String& mediaType, StringView restrictionsString);
491     ExceptionOr<String> mediaSessionRestrictions(const String& mediaType) const;
492     void setMediaElementRestrictions(HTMLMediaElement&, StringView restrictionsString);
493     ExceptionOr<void> postRemoteControlCommand(const String&, float argument);
494     bool elementIsBlockingDisplaySleep(HTMLMediaElement&) const;
495 #endif
496
497 #if ENABLE(MEDIA_SESSION)
498     void sendMediaSessionStartOfInterruptionNotification(MediaSessionInterruptingCategory);
499     void sendMediaSessionEndOfInterruptionNotification(MediaSessionInterruptingCategory);
500     String mediaSessionCurrentState(MediaSession&) const;
501     double mediaElementPlayerVolume(HTMLMediaElement&) const;
502     enum class MediaControlEvent { PlayPause, NextTrack, PreviousTrack };
503     void sendMediaControlEvent(MediaControlEvent);
504 #endif
505
506 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
507     void setMockMediaPlaybackTargetPickerEnabled(bool);
508     ExceptionOr<void> setMockMediaPlaybackTargetPickerState(const String& deviceName, const String& deviceState);
509 #endif
510
511 #if ENABLE(WEB_AUDIO)
512     void setAudioContextRestrictions(AudioContext&, StringView restrictionsString);
513 #endif
514
515     void simulateSystemSleep() const;
516     void simulateSystemWake() const;
517
518     enum class PageOverlayType { View, Document };
519     ExceptionOr<Ref<MockPageOverlay>> installMockPageOverlay(PageOverlayType);
520     ExceptionOr<String> pageOverlayLayerTreeAsText(unsigned short flags) const;
521
522     void setPageMuted(StringView);
523     String pageMediaState();
524
525     void setPageDefersLoading(bool);
526
527     RefPtr<File> createFile(const String&);
528     void queueMicroTask(int);
529     bool testPreloaderSettingViewport();
530
531 #if ENABLE(CONTENT_FILTERING)
532     MockContentFilterSettings& mockContentFilterSettings();
533 #endif
534
535 #if ENABLE(CSS_SCROLL_SNAP)
536     ExceptionOr<String> scrollSnapOffsets(Element&);
537     void setPlatformMomentumScrollingPredictionEnabled(bool);
538 #endif
539
540     ExceptionOr<String> pathStringWithShrinkWrappedRects(const Vector<double>& rectComponents, double radius);
541
542     String getCurrentMediaControlsStatusForElement(HTMLMediaElement&);
543
544     String userVisibleString(const DOMURL&);
545     void setShowAllPlugins(bool);
546
547     String resourceLoadStatisticsForOrigin(const String& origin);
548     void setResourceLoadStatisticsEnabled(bool);
549     void setUserGrantsStorageAccess(bool);
550
551 #if ENABLE(STREAMS_API)
552     bool isReadableStreamDisturbed(JSC::ExecState&, JSC::JSValue);
553     JSC::JSValue cloneArrayBuffer(JSC::ExecState&, JSC::JSValue, JSC::JSValue, JSC::JSValue);
554 #endif
555
556     String composedTreeAsText(Node&);
557
558     bool isProcessingUserGesture();
559     double lastHandledUserGestureTimestamp();
560
561     RefPtr<GCObservation> observeGC(JSC::JSValue);
562
563     enum class UserInterfaceLayoutDirection { LTR, RTL };
564     void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
565
566     bool userPrefersReducedMotion() const;
567
568     void reportBacktrace();
569
570     enum class BaseWritingDirection { Natural, Ltr, Rtl };
571     void setBaseWritingDirection(BaseWritingDirection);
572
573 #if ENABLE(POINTER_LOCK)
574     bool pageHasPendingPointerLock() const;
575     bool pageHasPointerLock() const;
576 #endif
577
578     Vector<String> accessKeyModifiers() const;
579
580     void setQuickLookPassword(const String&);
581
582     void setAsRunningUserScripts(Document&);
583
584 #if ENABLE(WEBGL)
585     void simulateWebGLContextChanged(WebGLRenderingContext&);
586     void failNextGPUStatusCheck(WebGLRenderingContext&);
587 #endif
588
589     void setPageVisibility(bool isVisible);
590
591 #if ENABLE(WEB_RTC)
592     void setH264HardwareEncoderAllowed(bool allowed);
593 #endif
594
595 #if ENABLE(MEDIA_STREAM)
596     void setCameraMediaStreamTrackOrientation(MediaStreamTrack&, int orientation);
597     ExceptionOr<void> setMediaDeviceState(const String& id, const String& property, bool value);
598     unsigned long trackAudioSampleCount() const { return m_trackAudioSampleCount; }
599     unsigned long trackVideoSampleCount() const { return m_trackVideoSampleCount; }
600     void observeMediaStreamTrack(MediaStreamTrack&);
601     using TrackFramePromise = DOMPromiseDeferred<IDLInterface<ImageData>>;
602     void grabNextMediaStreamTrackFrame(TrackFramePromise&&);
603     void delayMediaStreamTrackSamples(MediaStreamTrack&, float);
604     void setMediaStreamTrackMuted(MediaStreamTrack&, bool);
605     void removeMediaStreamTrack(MediaStream&, MediaStreamTrack&);
606     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
607 #endif
608
609     String audioSessionCategory() const;
610
611     void clearCacheStorageMemoryRepresentation(DOMPromiseDeferred<void>&&);
612     void cacheStorageEngineRepresentation(DOMPromiseDeferred<IDLDOMString>&&);
613     void setResponseSizeWithPadding(FetchResponse&, uint64_t size);
614     uint64_t responseSizeWithPadding(FetchResponse&) const;
615
616     void setConsoleMessageListener(RefPtr<StringCallback>&&);
617
618 #if ENABLE(SERVICE_WORKER)
619     void waitForFetchEventToFinish(FetchEvent&, DOMPromiseDeferred<IDLInterface<FetchResponse>>&&);
620     void waitForExtendableEventToFinish(ExtendableEvent&, DOMPromiseDeferred<void>&&);
621     Ref<FetchEvent> createBeingDispatchedFetchEvent(ScriptExecutionContext&);
622     Ref<ExtendableEvent> createTrustedExtendableEvent();
623     using HasRegistrationPromise = DOMPromiseDeferred<IDLBoolean>;
624     void hasServiceWorkerRegistration(const String& clientURL, HasRegistrationPromise&&);
625 #endif
626
627     bool hasServiceWorkerRegisteredForOrigin(const String&);
628
629 #if ENABLE(APPLE_PAY)
630     MockPaymentCoordinator& mockPaymentCoordinator() const;
631 #endif
632
633     String timelineDescription(AnimationTimeline&);
634     void pauseTimeline(AnimationTimeline&);
635     void setTimelineCurrentTime(AnimationTimeline&, double);
636
637 private:
638     explicit Internals(Document&);
639     Document* contextDocument() const;
640     Frame* frame() const;
641
642     ExceptionOr<RenderedDocumentMarker*> markerAt(Node&, const String& markerType, unsigned index);
643
644     // RealtimeMediaSource::Observer API
645 #if ENABLE(MEDIA_STREAM)
646     void videoSampleAvailable(MediaSample&) final;
647     void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final { m_trackAudioSampleCount++; }
648
649     OrientationNotifier m_orientationNotifier;
650     unsigned long m_trackVideoSampleCount { 0 };
651     unsigned long m_trackAudioSampleCount { 0 };
652     RefPtr<MediaStreamTrack> m_track;
653     std::optional<TrackFramePromise> m_nextTrackFramePromise;
654 #endif
655
656     std::unique_ptr<InspectorStubFrontend> m_inspectorFrontend;
657     RefPtr<CacheStorageConnection> m_cacheStorageConnection;
658
659 #if ENABLE(APPLE_PAY)
660     MockPaymentCoordinator* m_mockPaymentCoordinator { nullptr };
661 #endif
662 };
663
664 } // namespace WebCore