[MediaStream] An audio track should be muted when capture is interrupted by the OS.
[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 "Cookie.h"
32 #include "ExceptionOr.h"
33 #include "HEVCUtilities.h"
34 #include "JSDOMPromiseDeferred.h"
35 #include "OrientationNotifier.h"
36 #include "PageConsoleClient.h"
37 #include "RealtimeMediaSource.h"
38 #include <JavaScriptCore/Float32Array.h>
39 #include <wtf/Optional.h>
40
41 #if ENABLE(MEDIA_SESSION)
42 #include "MediaSessionInterruptionProvider.h"
43 #endif
44
45 #if ENABLE(VIDEO)
46 #include "MediaElementSession.h"
47 #endif
48
49 namespace WebCore {
50
51 class AnimationTimeline;
52 class AudioContext;
53 class CacheStorageConnection;
54 class DOMRect;
55 class DOMRectList;
56 class DOMURL;
57 class DOMWindow;
58 class Document;
59 class Element;
60 class ExtendableEvent;
61 class FetchResponse;
62 class File;
63 class Frame;
64 class GCObservation;
65 class HTMLAnchorElement;
66 class HTMLImageElement;
67 class HTMLInputElement;
68 class HTMLLinkElement;
69 class HTMLMediaElement;
70 class HTMLPictureElement;
71 class HTMLSelectElement;
72 class ImageData;
73 class InspectorStubFrontend;
74 class InternalSettings;
75 class MallocStatistics;
76 class MediaSession;
77 class MediaStream;
78 class MediaStreamTrack;
79 class MemoryInfo;
80 class MockCDMFactory;
81 class MockContentFilterSettings;
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     // Web Animations testing.
204     struct AcceleratedAnimation {
205         String property;
206         double speed;
207     };
208     Vector<AcceleratedAnimation> acceleratedAnimationsForElement(Element&);
209     unsigned numberOfAnimationTimelineInvalidations() const;
210
211     // For animations testing, we need a way to get at pseudo elements.
212     ExceptionOr<RefPtr<Element>> pseudoElement(Element&, const String&);
213
214     Node* treeScopeRootNode(Node&);
215     Node* parentTreeScope(Node&);
216
217     String visiblePlaceholder(Element&);
218     void selectColorInColorChooser(HTMLInputElement&, const String& colorValue);
219     ExceptionOr<Vector<String>> formControlStateOfPreviousHistoryItem();
220     ExceptionOr<void> setFormControlStateOfPreviousHistoryItem(const Vector<String>&);
221
222     ExceptionOr<Ref<DOMRect>> absoluteCaretBounds();
223
224     Ref<DOMRect> boundingBox(Element&);
225
226     ExceptionOr<Ref<DOMRectList>> inspectorHighlightRects();
227     ExceptionOr<String> inspectorHighlightObject();
228
229     ExceptionOr<unsigned> markerCountForNode(Node&, const String&);
230     ExceptionOr<RefPtr<Range>> markerRangeForNode(Node&, const String& markerType, unsigned index);
231     ExceptionOr<String> markerDescriptionForNode(Node&, const String& markerType, unsigned index);
232     ExceptionOr<String> dumpMarkerRects(const String& markerType);
233     void addTextMatchMarker(const Range&, bool isActive);
234     ExceptionOr<void> setMarkedTextMatchesAreHighlighted(bool);
235
236     void invalidateFontCache();
237     void setFontSmoothingEnabled(bool);
238
239     ExceptionOr<void> setLowPowerModeEnabled(bool);
240
241     ExceptionOr<void> setScrollViewPosition(int x, int y);
242     ExceptionOr<void> unconstrainedScrollTo(Element&, double x, double y);
243
244     ExceptionOr<Ref<DOMRect>> layoutViewportRect();
245     ExceptionOr<Ref<DOMRect>> visualViewportRect();
246
247     ExceptionOr<void> setViewBaseBackgroundColor(const String& colorValue);
248
249     ExceptionOr<void> setPagination(const String& mode, int gap, int pageLength);
250     ExceptionOr<void> setPaginationLineGridEnabled(bool);
251     ExceptionOr<String> configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight);
252
253     ExceptionOr<bool> wasLastChangeUserEdit(Element& textField);
254     bool elementShouldAutoComplete(HTMLInputElement&);
255     void setEditingValue(HTMLInputElement&, const String&);
256     void setAutofilled(HTMLInputElement&, bool enabled);
257     enum class AutoFillButtonType { None, Contacts, Credentials, StrongPassword, CreditCard };
258     void setShowAutoFillButton(HTMLInputElement&, AutoFillButtonType);
259     AutoFillButtonType autoFillButtonType(const HTMLInputElement&);
260     AutoFillButtonType lastAutoFillButtonType(const HTMLInputElement&);
261     ExceptionOr<void> scrollElementToRect(Element&, int x, int y, int w, int h);
262
263     ExceptionOr<String> autofillFieldName(Element&);
264
265     ExceptionOr<void> invalidateControlTints();
266
267     RefPtr<Range> rangeFromLocationAndLength(Element& scope, int rangeLocation, int rangeLength);
268     unsigned locationFromRange(Element& scope, const Range&);
269     unsigned lengthFromRange(Element& scope, const Range&);
270     String rangeAsText(const Range&);
271     Ref<Range> subrange(Range&, int rangeLocation, int rangeLength);
272     ExceptionOr<RefPtr<Range>> rangeForDictionaryLookupAtLocation(int x, int y);
273     RefPtr<Range> rangeOfStringNearLocation(const Range&, const String&, unsigned);
274
275     ExceptionOr<void> setDelegatesScrolling(bool enabled);
276
277     ExceptionOr<int> lastSpellCheckRequestSequence();
278     ExceptionOr<int> lastSpellCheckProcessedSequence();
279
280     Vector<String> userPreferredLanguages() const;
281     void setUserPreferredLanguages(const Vector<String>&);
282
283     Vector<String> userPreferredAudioCharacteristics() const;
284     void setUserPreferredAudioCharacteristic(const String&);
285
286     ExceptionOr<unsigned> wheelEventHandlerCount();
287     ExceptionOr<unsigned> touchEventHandlerCount();
288
289     ExceptionOr<Ref<DOMRectList>> touchEventRectsForEvent(const String&);
290     ExceptionOr<Ref<DOMRectList>> passiveTouchEventListenerRects();
291
292     ExceptionOr<RefPtr<NodeList>> nodesFromRect(Document&, int x, int y, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowUserAgentShadowContent, bool allowChildFrameContent) const;
293
294     String parserMetaData(JSC::JSValue = JSC::JSValue::JSUndefined);
295
296     void updateEditorUINowIfScheduled();
297
298     bool sentenceRetroCorrectionEnabled() const
299     {
300 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
301         return true;
302 #else
303         return false;
304 #endif
305     }
306     bool hasSpellingMarker(int from, int length);
307     bool hasGrammarMarker(int from, int length);
308     bool hasAutocorrectedMarker(int from, int length);
309     void setContinuousSpellCheckingEnabled(bool);
310     void setAutomaticQuoteSubstitutionEnabled(bool);
311     void setAutomaticLinkDetectionEnabled(bool);
312     void setAutomaticDashSubstitutionEnabled(bool);
313     void setAutomaticTextReplacementEnabled(bool);
314     void setAutomaticSpellingCorrectionEnabled(bool);
315
316     void handleAcceptedCandidate(const String& candidate, unsigned location, unsigned length);
317
318     bool isOverwriteModeEnabled();
319     void toggleOverwriteModeEnabled();
320
321     ExceptionOr<RefPtr<Range>> rangeOfString(const String&, RefPtr<Range>&&, const Vector<String>& findOptions);
322     ExceptionOr<unsigned> countMatchesForText(const String&, const Vector<String>& findOptions, const String& markMatches);
323     ExceptionOr<unsigned> countFindMatches(const String&, const Vector<String>& findOptions);
324
325     unsigned numberOfScrollableAreas();
326
327     ExceptionOr<bool> isPageBoxVisible(int pageNumber);
328
329     static const char* internalsId;
330
331     InternalSettings* settings() const;
332     unsigned workerThreadCount() const;
333     ExceptionOr<bool> areSVGAnimationsPaused() const;
334     ExceptionOr<double> svgAnimationsInterval(SVGSVGElement&) const;
335
336     enum {
337         // Values need to be kept in sync with Internals.idl.
338         LAYER_TREE_INCLUDES_VISIBLE_RECTS = 1,
339         LAYER_TREE_INCLUDES_TILE_CACHES = 2,
340         LAYER_TREE_INCLUDES_REPAINT_RECTS = 4,
341         LAYER_TREE_INCLUDES_PAINTING_PHASES = 8,
342         LAYER_TREE_INCLUDES_CONTENT_LAYERS = 16,
343         LAYER_TREE_INCLUDES_ACCELERATES_DRAWING = 32,
344         LAYER_TREE_INCLUDES_BACKING_STORE_ATTACHED = 64,
345     };
346     ExceptionOr<String> layerTreeAsText(Document&, unsigned short flags) const;
347     ExceptionOr<uint64_t> layerIDForElement(Element&);
348     ExceptionOr<String> repaintRectsAsText() const;
349     ExceptionOr<String> scrollingStateTreeAsText() const;
350     ExceptionOr<String> mainThreadScrollingReasons() const;
351     ExceptionOr<Ref<DOMRectList>> nonFastScrollableRects() const;
352
353     ExceptionOr<void> setElementUsesDisplayListDrawing(Element&, bool usesDisplayListDrawing);
354     ExceptionOr<void> setElementTracksDisplayListReplay(Element&, bool isTrackingReplay);
355
356     enum {
357         // Values need to be kept in sync with Internals.idl.
358         DISPLAY_LIST_INCLUDES_PLATFORM_OPERATIONS = 1,
359     };
360     ExceptionOr<String> displayListForElement(Element&, unsigned short flags);
361     ExceptionOr<String> replayDisplayListForElement(Element&, unsigned short flags);
362
363     ExceptionOr<void> garbageCollectDocumentResources() const;
364
365     void beginSimulatedMemoryPressure();
366     void endSimulatedMemoryPressure();
367     bool isUnderMemoryPressure();
368
369     ExceptionOr<void> insertAuthorCSS(const String&) const;
370     ExceptionOr<void> insertUserCSS(const String&) const;
371
372     unsigned numberOfLiveNodes() const;
373     unsigned numberOfLiveDocuments() const;
374     unsigned referencingNodeCount(const Document&) const;
375
376 #if ENABLE(INTERSECTION_OBSERVER)
377     unsigned numberOfIntersectionObservers(const Document&) const;
378 #endif
379
380     uint64_t documentIdentifier(const Document&) const;
381     bool isDocumentAlive(uint64_t documentIdentifier) const;
382
383     String serviceWorkerClientIdentifier(const Document&) const;
384
385     RefPtr<WindowProxy> openDummyInspectorFrontend(const String& url);
386     void closeDummyInspectorFrontend();
387     ExceptionOr<void> setInspectorIsUnderTest(bool);
388
389     String counterValue(Element&);
390
391     int pageNumber(Element&, float pageWidth = 800, float pageHeight = 600);
392     Vector<String> shortcutIconURLs() const;
393
394     int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
395     ExceptionOr<String> pageProperty(const String& propertyName, int pageNumber) const;
396     ExceptionOr<String> pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const;
397
398     ExceptionOr<float> pageScaleFactor() const;
399
400     ExceptionOr<void> setPageScaleFactor(float scaleFactor, int x, int y);
401     ExceptionOr<void> setPageZoomFactor(float);
402     ExceptionOr<void> setTextZoomFactor(float);
403
404     ExceptionOr<void> setUseFixedLayout(bool);
405     ExceptionOr<void> setFixedLayoutSize(int width, int height);
406     ExceptionOr<void> setViewExposedRect(float left, float top, float width, float height);
407     void setPrinting(int width, int height);
408
409     void setHeaderHeight(float);
410     void setFooterHeight(float);
411
412     void setTopContentInset(float);
413
414 #if ENABLE(FULLSCREEN_API)
415     void webkitWillEnterFullScreenForElement(Element&);
416     void webkitDidEnterFullScreenForElement(Element&);
417     void webkitWillExitFullScreenForElement(Element&);
418     void webkitDidExitFullScreenForElement(Element&);
419     bool isAnimatingFullScreen() const;
420 #endif
421
422     struct FullscreenInsets {
423         float top { 0 };
424         float left { 0 };
425         float bottom { 0 };
426         float right { 0 };
427     };
428     void setFullscreenInsets(FullscreenInsets);
429     void setFullscreenAutoHideDuration(double);
430     void setFullscreenControlsHidden(bool);
431
432     WEBCORE_TESTSUPPORT_EXPORT void setApplicationCacheOriginQuota(unsigned long long);
433
434     void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
435     void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
436
437     void registerDefaultPortForProtocol(unsigned short port, const String& protocol);
438
439     Ref<MallocStatistics> mallocStatistics() const;
440     Ref<TypeConversions> typeConversions() const;
441     Ref<MemoryInfo> memoryInfo() const;
442
443     Vector<String> getReferencedFilePaths() const;
444
445     ExceptionOr<void> startTrackingRepaints();
446     ExceptionOr<void> stopTrackingRepaints();
447
448     ExceptionOr<void> startTrackingLayerFlushes();
449     ExceptionOr<unsigned> layerFlushCount();
450
451     ExceptionOr<void> startTrackingStyleRecalcs();
452     ExceptionOr<unsigned> styleRecalcCount();
453     unsigned lastStyleUpdateSize() const;
454
455     ExceptionOr<void> startTrackingCompositingUpdates();
456     ExceptionOr<unsigned> compositingUpdateCount();
457
458     enum CompositingPolicy { Normal, Conservative };
459     ExceptionOr<void> setCompositingPolicyOverride(std::optional<CompositingPolicy>);
460     ExceptionOr<std::optional<CompositingPolicy>> compositingPolicyOverride() const;
461
462     ExceptionOr<void> updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*);
463     unsigned layoutCount() const;
464
465     Ref<ArrayBuffer> serializeObject(const RefPtr<SerializedScriptValue>&) const;
466     Ref<SerializedScriptValue> deserializeBuffer(ArrayBuffer&) const;
467
468     bool isFromCurrentWorld(JSC::JSValue) const;
469
470     void setUsesOverlayScrollbars(bool);
471     void setUsesMockScrollAnimator(bool);
472
473     ExceptionOr<String> getCurrentCursorInfo();
474
475     String markerTextForListItem(Element&);
476
477     String toolTipFromElement(Element&) const;
478
479     void forceReload(bool endToEnd);
480     void reloadExpiredOnly();
481
482     void enableAutoSizeMode(bool enabled, int minimumWidth, int minimumHeight, int maximumWidth, int maximumHeight);
483
484 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
485     void initializeMockCDM();
486 #endif
487
488 #if ENABLE(ENCRYPTED_MEDIA)
489     Ref<MockCDMFactory> registerMockCDM();
490 #endif
491
492     void enableMockMediaCapabilities();
493
494 #if ENABLE(SPEECH_SYNTHESIS)
495     void enableMockSpeechSynthesizer();
496 #endif
497
498 #if ENABLE(MEDIA_STREAM)
499     void setMockMediaCaptureDevicesEnabled(bool);
500 #endif
501
502 #if ENABLE(WEB_RTC)
503     void emulateRTCPeerConnectionPlatformEvent(RTCPeerConnection&, const String& action);
504     void useMockRTCPeerConnectionFactory(const String&);
505     void setICECandidateFiltering(bool);
506     void setEnumeratingAllNetworkInterfacesEnabled(bool);
507     void stopPeerConnection(RTCPeerConnection&);
508     void applyRotationForOutgoingVideoSources(RTCPeerConnection&);
509 #endif
510
511     String getImageSourceURL(Element&);
512
513 #if ENABLE(VIDEO)
514     Vector<String> mediaResponseSources(HTMLMediaElement&);
515     Vector<String> mediaResponseContentRanges(HTMLMediaElement&);
516     void simulateAudioInterruption(HTMLMediaElement&);
517     ExceptionOr<bool> mediaElementHasCharacteristic(HTMLMediaElement&, const String&);
518     void beginSimulatedHDCPError(HTMLMediaElement&);
519     void endSimulatedHDCPError(HTMLMediaElement&);
520
521     bool elementShouldBufferData(HTMLMediaElement&);
522 #endif
523
524     bool isSelectPopupVisible(HTMLSelectElement&);
525
526     ExceptionOr<String> captionsStyleSheetOverride();
527     ExceptionOr<void> setCaptionsStyleSheetOverride(const String&);
528     ExceptionOr<void> setPrimaryAudioTrackLanguageOverride(const String&);
529     ExceptionOr<void> setCaptionDisplayMode(const String&);
530
531 #if ENABLE(VIDEO)
532     Ref<TimeRanges> createTimeRanges(Float32Array& startTimes, Float32Array& endTimes);
533     double closestTimeToTimeRanges(double time, TimeRanges&);
534 #endif
535
536     ExceptionOr<Ref<DOMRect>> selectionBounds();
537     void setSelectionWithoutValidation(Ref<Node> baseNode, unsigned baseOffset, RefPtr<Node> extentNode, unsigned extentOffset);
538
539     ExceptionOr<bool> isPluginUnavailabilityIndicatorObscured(Element&);
540     ExceptionOr<String> unavailablePluginReplacementText(Element&);
541     bool isPluginSnapshotted(Element&);
542
543 #if ENABLE(MEDIA_SOURCE)
544     WEBCORE_TESTSUPPORT_EXPORT void initializeMockMediaSource();
545     Vector<String> bufferedSamplesForTrackID(SourceBuffer&, const AtomicString&);
546     Vector<String> enqueuedSamplesForTrackID(SourceBuffer&, const AtomicString&);
547     void setShouldGenerateTimestamps(SourceBuffer&, bool);
548 #endif
549
550 #if ENABLE(VIDEO)
551     ExceptionOr<void> beginMediaSessionInterruption(const String&);
552     void endMediaSessionInterruption(const String&);
553     void applicationWillBecomeInactive();
554     void applicationDidBecomeActive();
555     void applicationWillEnterForeground(bool suspendedUnderLock) const;
556     void applicationDidEnterBackground(bool suspendedUnderLock) const;
557     ExceptionOr<void> setMediaSessionRestrictions(const String& mediaType, StringView restrictionsString);
558     ExceptionOr<String> mediaSessionRestrictions(const String& mediaType) const;
559     void setMediaElementRestrictions(HTMLMediaElement&, StringView restrictionsString);
560     ExceptionOr<void> postRemoteControlCommand(const String&, float argument);
561     bool elementIsBlockingDisplaySleep(HTMLMediaElement&) const;
562 #endif
563
564 #if ENABLE(MEDIA_SESSION)
565     void sendMediaSessionStartOfInterruptionNotification(MediaSessionInterruptingCategory);
566     void sendMediaSessionEndOfInterruptionNotification(MediaSessionInterruptingCategory);
567     String mediaSessionCurrentState(MediaSession&) const;
568     double mediaElementPlayerVolume(HTMLMediaElement&) const;
569     enum class MediaControlEvent { PlayPause, NextTrack, PreviousTrack };
570     void sendMediaControlEvent(MediaControlEvent);
571 #endif
572
573 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
574     void setMockMediaPlaybackTargetPickerEnabled(bool);
575     ExceptionOr<void> setMockMediaPlaybackTargetPickerState(const String& deviceName, const String& deviceState);
576 #endif
577
578 #if ENABLE(WEB_AUDIO)
579     void setAudioContextRestrictions(AudioContext&, StringView restrictionsString);
580 #endif
581
582     void simulateSystemSleep() const;
583     void simulateSystemWake() const;
584
585     enum class PageOverlayType { View, Document };
586     ExceptionOr<Ref<MockPageOverlay>> installMockPageOverlay(PageOverlayType);
587     ExceptionOr<String> pageOverlayLayerTreeAsText(unsigned short flags) const;
588
589     void setPageMuted(StringView);
590     String pageMediaState();
591
592     void setPageDefersLoading(bool);
593     ExceptionOr<bool> pageDefersLoading();
594
595     RefPtr<File> createFile(const String&);
596     void queueMicroTask(int);
597     bool testPreloaderSettingViewport();
598
599 #if ENABLE(CONTENT_FILTERING)
600     MockContentFilterSettings& mockContentFilterSettings();
601 #endif
602
603 #if ENABLE(CSS_SCROLL_SNAP)
604     ExceptionOr<String> scrollSnapOffsets(Element&);
605     void setPlatformMomentumScrollingPredictionEnabled(bool);
606 #endif
607
608     ExceptionOr<String> pathStringWithShrinkWrappedRects(const Vector<double>& rectComponents, double radius);
609
610     String getCurrentMediaControlsStatusForElement(HTMLMediaElement&);
611
612     String userVisibleString(const DOMURL&);
613     void setShowAllPlugins(bool);
614
615     String resourceLoadStatisticsForOrigin(const String& origin);
616     void setResourceLoadStatisticsEnabled(bool);
617     void setUserGrantsStorageAccess(bool);
618
619 #if ENABLE(STREAMS_API)
620     bool isReadableStreamDisturbed(JSC::ExecState&, JSC::JSValue);
621     JSC::JSValue cloneArrayBuffer(JSC::ExecState&, JSC::JSValue, JSC::JSValue, JSC::JSValue);
622 #endif
623
624     String composedTreeAsText(Node&);
625
626     bool isProcessingUserGesture();
627     double lastHandledUserGestureTimestamp();
628
629     void withUserGesture(RefPtr<VoidCallback>&&);
630
631     RefPtr<GCObservation> observeGC(JSC::JSValue);
632
633     enum class UserInterfaceLayoutDirection : uint8_t { LTR, RTL };
634     void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
635
636     bool userPrefersReducedMotion() const;
637
638     void reportBacktrace();
639
640     enum class BaseWritingDirection { Natural, Ltr, Rtl };
641     void setBaseWritingDirection(BaseWritingDirection);
642
643 #if ENABLE(POINTER_LOCK)
644     bool pageHasPendingPointerLock() const;
645     bool pageHasPointerLock() const;
646 #endif
647
648     Vector<String> accessKeyModifiers() const;
649
650     void setQuickLookPassword(const String&);
651
652     void setAsRunningUserScripts(Document&);
653
654 #if ENABLE(WEBGL)
655     void simulateWebGLContextChanged(WebGLRenderingContext&);
656     void failNextGPUStatusCheck(WebGLRenderingContext&);
657     bool hasLowAndHighPowerGPUs();
658 #endif
659
660     void setPageVisibility(bool isVisible);
661     void setPageIsFocusedAndActive(bool);
662
663
664 #if ENABLE(WEB_RTC)
665     void setH264HardwareEncoderAllowed(bool allowed);
666 #endif
667
668 #if ENABLE(MEDIA_STREAM)
669     void setCameraMediaStreamTrackOrientation(MediaStreamTrack&, int orientation);
670     ExceptionOr<void> setMediaDeviceState(const String& id, const String& property, bool value);
671     unsigned long trackAudioSampleCount() const { return m_trackAudioSampleCount; }
672     unsigned long trackVideoSampleCount() const { return m_trackVideoSampleCount; }
673     void observeMediaStreamTrack(MediaStreamTrack&);
674     using TrackFramePromise = DOMPromiseDeferred<IDLInterface<ImageData>>;
675     void grabNextMediaStreamTrackFrame(TrackFramePromise&&);
676     void delayMediaStreamTrackSamples(MediaStreamTrack&, float);
677     void setMediaStreamTrackMuted(MediaStreamTrack&, bool);
678     void removeMediaStreamTrack(MediaStream&, MediaStreamTrack&);
679     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
680     void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
681     void setMediaStreamSourceInterrupted(MediaStreamTrack&, bool);
682 #endif
683
684     String audioSessionCategory() const;
685     double preferredAudioBufferSize() const;
686
687     void clearCacheStorageMemoryRepresentation(DOMPromiseDeferred<void>&&);
688     void cacheStorageEngineRepresentation(DOMPromiseDeferred<IDLDOMString>&&);
689     void setResponseSizeWithPadding(FetchResponse&, uint64_t size);
690     uint64_t responseSizeWithPadding(FetchResponse&) const;
691
692     void setConsoleMessageListener(RefPtr<StringCallback>&&);
693
694 #if ENABLE(SERVICE_WORKER)
695     using HasRegistrationPromise = DOMPromiseDeferred<IDLBoolean>;
696     void hasServiceWorkerRegistration(const String& clientURL, HasRegistrationPromise&&);
697     void terminateServiceWorker(ServiceWorker&);
698     bool hasServiceWorkerConnection();
699 #endif
700
701 #if ENABLE(APPLE_PAY)
702     MockPaymentCoordinator& mockPaymentCoordinator(Document&);
703 #endif
704
705     bool isSystemPreviewLink(Element&) const;
706     bool isSystemPreviewImage(Element&) const;
707
708     bool usingAppleInternalSDK() const;
709
710     struct NowPlayingState {
711         String title;
712         double duration;
713         double elapsedTime;
714         uint64_t uniqueIdentifier;
715         bool hasActiveSession;
716         bool registeredAsNowPlayingApplication;
717     };
718     ExceptionOr<NowPlayingState> nowPlayingState() const;
719
720 #if ENABLE(VIDEO)
721     using PlaybackControlsPurpose = MediaElementSession::PlaybackControlsPurpose;
722     RefPtr<HTMLMediaElement> bestMediaElementForShowingPlaybackControlsManager(PlaybackControlsPurpose);
723
724     using MediaSessionState = PlatformMediaSession::State;
725     MediaSessionState mediaSessionState(HTMLMediaElement&);
726 #endif
727
728     void setCaptureExtraNetworkLoadMetricsEnabled(bool);
729     String ongoingLoadsDescriptions() const;
730
731     void reloadWithoutContentExtensions();
732
733     void setUseSystemAppearance(bool);
734
735     size_t pluginCount();
736
737     void notifyResourceLoadObserver();
738
739     unsigned primaryScreenDisplayID();
740
741     bool supportsVCPEncoder();
742         
743     using HEVCParameterSet = WebCore::HEVCParameterSet;
744     std::optional<HEVCParameterSet> parseHEVCCodecParameters(const String& codecString);
745
746     struct CookieData {
747         String name;
748         String value;
749         String domain;
750         // Expiration dates are expressed as milliseconds since the UNIX epoch.
751         double expires { 0 };
752         bool isHttpOnly { false };
753         bool isSecure { false };
754         bool isSession { false };
755         bool isSameSiteLax { false };
756         bool isSameSiteStrict { false };
757
758         CookieData(Cookie cookie)
759             : name(cookie.name)
760             , value(cookie.value)
761             , domain(cookie.domain)
762             , expires(cookie.expires)
763             , isHttpOnly(cookie.httpOnly)
764             , isSecure(cookie.secure)
765             , isSession(cookie.session)
766             , isSameSiteLax(cookie.sameSite == Cookie::SameSitePolicy::Lax)
767             , isSameSiteStrict(cookie.sameSite == Cookie::SameSitePolicy::Strict)
768         {
769             ASSERT(!(isSameSiteLax && isSameSiteStrict));
770         }
771
772         CookieData()
773         {
774         }
775     };
776     Vector<CookieData> getCookies() const;
777
778 private:
779     explicit Internals(Document&);
780     Document* contextDocument() const;
781     Frame* frame() const;
782
783     ExceptionOr<RenderedDocumentMarker*> markerAt(Node&, const String& markerType, unsigned index);
784
785     // RealtimeMediaSource::Observer API
786 #if ENABLE(MEDIA_STREAM)
787     void videoSampleAvailable(MediaSample&) final;
788     void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final { m_trackAudioSampleCount++; }
789
790     OrientationNotifier m_orientationNotifier;
791     unsigned long m_trackVideoSampleCount { 0 };
792     unsigned long m_trackAudioSampleCount { 0 };
793     RefPtr<MediaStreamTrack> m_track;
794     std::optional<TrackFramePromise> m_nextTrackFramePromise;
795 #endif
796
797     std::unique_ptr<InspectorStubFrontend> m_inspectorFrontend;
798     RefPtr<CacheStorageConnection> m_cacheStorageConnection;
799 };
800
801 } // namespace WebCore