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