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