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