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