Caret stops blinking after context menu shown
[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     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() const;
356
357     ExceptionOr<String> scrollingStateTreeAsText() const;
358     ExceptionOr<String> mainThreadScrollingReasons() const;
359     ExceptionOr<Ref<DOMRectList>> nonFastScrollableRects() const;
360
361     ExceptionOr<void> setElementUsesDisplayListDrawing(Element&, bool usesDisplayListDrawing);
362     ExceptionOr<void> setElementTracksDisplayListReplay(Element&, bool isTrackingReplay);
363
364     enum {
365         // Values need to be kept in sync with Internals.idl.
366         DISPLAY_LIST_INCLUDES_PLATFORM_OPERATIONS = 1,
367     };
368     ExceptionOr<String> displayListForElement(Element&, unsigned short flags);
369     ExceptionOr<String> replayDisplayListForElement(Element&, unsigned short flags);
370
371     ExceptionOr<void> garbageCollectDocumentResources() const;
372
373     void beginSimulatedMemoryPressure();
374     void endSimulatedMemoryPressure();
375     bool isUnderMemoryPressure();
376
377     ExceptionOr<void> insertAuthorCSS(const String&) const;
378     ExceptionOr<void> insertUserCSS(const String&) const;
379
380     unsigned numberOfLiveNodes() const;
381     unsigned numberOfLiveDocuments() const;
382     unsigned referencingNodeCount(const Document&) const;
383
384 #if ENABLE(INTERSECTION_OBSERVER)
385     unsigned numberOfIntersectionObservers(const Document&) const;
386 #endif
387
388     uint64_t documentIdentifier(const Document&) const;
389     bool isDocumentAlive(uint64_t documentIdentifier) const;
390
391     String serviceWorkerClientIdentifier(const Document&) const;
392
393     RefPtr<WindowProxy> openDummyInspectorFrontend(const String& url);
394     void closeDummyInspectorFrontend();
395     ExceptionOr<void> setInspectorIsUnderTest(bool);
396
397     String counterValue(Element&);
398
399     int pageNumber(Element&, float pageWidth = 800, float pageHeight = 600);
400     Vector<String> shortcutIconURLs() const;
401
402     int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
403     ExceptionOr<String> pageProperty(const String& propertyName, int pageNumber) const;
404     ExceptionOr<String> pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const;
405
406     ExceptionOr<float> pageScaleFactor() const;
407
408     ExceptionOr<void> setPageScaleFactor(float scaleFactor, int x, int y);
409     ExceptionOr<void> setPageZoomFactor(float);
410     ExceptionOr<void> setTextZoomFactor(float);
411
412     ExceptionOr<void> setUseFixedLayout(bool);
413     ExceptionOr<void> setFixedLayoutSize(int width, int height);
414     ExceptionOr<void> setViewExposedRect(float left, float top, float width, float height);
415     void setPrinting(int width, int height);
416
417     void setHeaderHeight(float);
418     void setFooterHeight(float);
419
420     void setTopContentInset(float);
421
422 #if ENABLE(FULLSCREEN_API)
423     void webkitWillEnterFullScreenForElement(Element&);
424     void webkitDidEnterFullScreenForElement(Element&);
425     void webkitWillExitFullScreenForElement(Element&);
426     void webkitDidExitFullScreenForElement(Element&);
427     bool isAnimatingFullScreen() const;
428 #endif
429
430     struct FullscreenInsets {
431         float top { 0 };
432         float left { 0 };
433         float bottom { 0 };
434         float right { 0 };
435     };
436     void setFullscreenInsets(FullscreenInsets);
437     void setFullscreenAutoHideDuration(double);
438     void setFullscreenControlsHidden(bool);
439
440     WEBCORE_TESTSUPPORT_EXPORT void setApplicationCacheOriginQuota(unsigned long long);
441
442     void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
443     void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
444
445     void registerDefaultPortForProtocol(unsigned short port, const String& protocol);
446
447     Ref<MallocStatistics> mallocStatistics() const;
448     Ref<TypeConversions> typeConversions() const;
449     Ref<MemoryInfo> memoryInfo() const;
450
451     Vector<String> getReferencedFilePaths() const;
452
453     ExceptionOr<void> startTrackingRepaints();
454     ExceptionOr<void> stopTrackingRepaints();
455
456     ExceptionOr<void> startTrackingLayerFlushes();
457     ExceptionOr<unsigned> layerFlushCount();
458
459     ExceptionOr<void> startTrackingStyleRecalcs();
460     ExceptionOr<unsigned> styleRecalcCount();
461     unsigned lastStyleUpdateSize() const;
462
463     ExceptionOr<void> startTrackingCompositingUpdates();
464     ExceptionOr<unsigned> compositingUpdateCount();
465
466     enum CompositingPolicy { Normal, Conservative };
467     ExceptionOr<void> setCompositingPolicyOverride(std::optional<CompositingPolicy>);
468     ExceptionOr<std::optional<CompositingPolicy>> compositingPolicyOverride() const;
469
470     ExceptionOr<void> updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*);
471     unsigned layoutCount() const;
472
473     Ref<ArrayBuffer> serializeObject(const RefPtr<SerializedScriptValue>&) const;
474     Ref<SerializedScriptValue> deserializeBuffer(ArrayBuffer&) const;
475
476     bool isFromCurrentWorld(JSC::JSValue) const;
477
478     void setUsesOverlayScrollbars(bool);
479     void setUsesMockScrollAnimator(bool);
480
481     ExceptionOr<String> getCurrentCursorInfo();
482
483     String markerTextForListItem(Element&);
484
485     String toolTipFromElement(Element&) const;
486
487     void forceReload(bool endToEnd);
488     void reloadExpiredOnly();
489
490     void enableAutoSizeMode(bool enabled, int minimumWidth, int minimumHeight, int maximumWidth, int maximumHeight);
491
492 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
493     void initializeMockCDM();
494 #endif
495
496 #if ENABLE(ENCRYPTED_MEDIA)
497     Ref<MockCDMFactory> registerMockCDM();
498 #endif
499
500     void enableMockMediaCapabilities();
501
502 #if ENABLE(SPEECH_SYNTHESIS)
503     void enableMockSpeechSynthesizer();
504 #endif
505
506 #if ENABLE(MEDIA_STREAM)
507     void setMockMediaCaptureDevicesEnabled(bool);
508 #endif
509
510 #if ENABLE(WEB_RTC)
511     void emulateRTCPeerConnectionPlatformEvent(RTCPeerConnection&, const String& action);
512     void useMockRTCPeerConnectionFactory(const String&);
513     void setICECandidateFiltering(bool);
514     void setEnumeratingAllNetworkInterfacesEnabled(bool);
515     void stopPeerConnection(RTCPeerConnection&);
516     void applyRotationForOutgoingVideoSources(RTCPeerConnection&);
517 #endif
518
519     String getImageSourceURL(Element&);
520
521 #if ENABLE(VIDEO)
522     Vector<String> mediaResponseSources(HTMLMediaElement&);
523     Vector<String> mediaResponseContentRanges(HTMLMediaElement&);
524     void simulateAudioInterruption(HTMLMediaElement&);
525     ExceptionOr<bool> mediaElementHasCharacteristic(HTMLMediaElement&, const String&);
526     void beginSimulatedHDCPError(HTMLMediaElement&);
527     void endSimulatedHDCPError(HTMLMediaElement&);
528
529     bool elementShouldBufferData(HTMLMediaElement&);
530 #endif
531
532     bool isSelectPopupVisible(HTMLSelectElement&);
533
534     ExceptionOr<String> captionsStyleSheetOverride();
535     ExceptionOr<void> setCaptionsStyleSheetOverride(const String&);
536     ExceptionOr<void> setPrimaryAudioTrackLanguageOverride(const String&);
537     ExceptionOr<void> setCaptionDisplayMode(const String&);
538
539 #if ENABLE(VIDEO)
540     Ref<TimeRanges> createTimeRanges(Float32Array& startTimes, Float32Array& endTimes);
541     double closestTimeToTimeRanges(double time, TimeRanges&);
542 #endif
543
544     ExceptionOr<Ref<DOMRect>> selectionBounds();
545     void setSelectionWithoutValidation(Ref<Node> baseNode, unsigned baseOffset, RefPtr<Node> extentNode, unsigned extentOffset);
546
547     ExceptionOr<bool> isPluginUnavailabilityIndicatorObscured(Element&);
548     ExceptionOr<String> unavailablePluginReplacementText(Element&);
549     bool isPluginSnapshotted(Element&);
550
551 #if ENABLE(MEDIA_SOURCE)
552     WEBCORE_TESTSUPPORT_EXPORT void initializeMockMediaSource();
553     Vector<String> bufferedSamplesForTrackID(SourceBuffer&, const AtomicString&);
554     Vector<String> enqueuedSamplesForTrackID(SourceBuffer&, const AtomicString&);
555     void setShouldGenerateTimestamps(SourceBuffer&, bool);
556 #endif
557
558 #if ENABLE(VIDEO)
559     ExceptionOr<void> beginMediaSessionInterruption(const String&);
560     void endMediaSessionInterruption(const String&);
561     void applicationWillBecomeInactive();
562     void applicationDidBecomeActive();
563     void applicationWillEnterForeground(bool suspendedUnderLock) const;
564     void applicationDidEnterBackground(bool suspendedUnderLock) const;
565     ExceptionOr<void> setMediaSessionRestrictions(const String& mediaType, StringView restrictionsString);
566     ExceptionOr<String> mediaSessionRestrictions(const String& mediaType) const;
567     void setMediaElementRestrictions(HTMLMediaElement&, StringView restrictionsString);
568     ExceptionOr<void> postRemoteControlCommand(const String&, float argument);
569     bool elementIsBlockingDisplaySleep(HTMLMediaElement&) const;
570 #endif
571
572 #if ENABLE(MEDIA_SESSION)
573     void sendMediaSessionStartOfInterruptionNotification(MediaSessionInterruptingCategory);
574     void sendMediaSessionEndOfInterruptionNotification(MediaSessionInterruptingCategory);
575     String mediaSessionCurrentState(MediaSession&) const;
576     double mediaElementPlayerVolume(HTMLMediaElement&) const;
577     enum class MediaControlEvent { PlayPause, NextTrack, PreviousTrack };
578     void sendMediaControlEvent(MediaControlEvent);
579 #endif
580
581 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
582     void setMockMediaPlaybackTargetPickerEnabled(bool);
583     ExceptionOr<void> setMockMediaPlaybackTargetPickerState(const String& deviceName, const String& deviceState);
584 #endif
585
586 #if ENABLE(WEB_AUDIO)
587     void setAudioContextRestrictions(AudioContext&, StringView restrictionsString);
588 #endif
589
590     void simulateSystemSleep() const;
591     void simulateSystemWake() const;
592
593     enum class PageOverlayType { View, Document };
594     ExceptionOr<Ref<MockPageOverlay>> installMockPageOverlay(PageOverlayType);
595     ExceptionOr<String> pageOverlayLayerTreeAsText(unsigned short flags) const;
596
597     void setPageMuted(StringView);
598     String pageMediaState();
599
600     void setPageDefersLoading(bool);
601     ExceptionOr<bool> pageDefersLoading();
602
603     RefPtr<File> createFile(const String&);
604     void queueMicroTask(int);
605     bool testPreloaderSettingViewport();
606
607 #if ENABLE(CONTENT_FILTERING)
608     MockContentFilterSettings& mockContentFilterSettings();
609 #endif
610
611 #if ENABLE(CSS_SCROLL_SNAP)
612     ExceptionOr<String> scrollSnapOffsets(Element&);
613     void setPlatformMomentumScrollingPredictionEnabled(bool);
614 #endif
615
616     ExceptionOr<String> pathStringWithShrinkWrappedRects(const Vector<double>& rectComponents, double radius);
617
618     String getCurrentMediaControlsStatusForElement(HTMLMediaElement&);
619
620     String userVisibleString(const DOMURL&);
621     void setShowAllPlugins(bool);
622
623     String resourceLoadStatisticsForOrigin(const String& origin);
624     void setResourceLoadStatisticsEnabled(bool);
625     void setUserGrantsStorageAccess(bool);
626
627 #if ENABLE(STREAMS_API)
628     bool isReadableStreamDisturbed(JSC::ExecState&, JSC::JSValue);
629     JSC::JSValue cloneArrayBuffer(JSC::ExecState&, JSC::JSValue, JSC::JSValue, JSC::JSValue);
630 #endif
631
632     String composedTreeAsText(Node&);
633
634     bool isProcessingUserGesture();
635     double lastHandledUserGestureTimestamp();
636
637     void withUserGesture(RefPtr<VoidCallback>&&);
638
639     RefPtr<GCObservation> observeGC(JSC::JSValue);
640
641     enum class UserInterfaceLayoutDirection : uint8_t { LTR, RTL };
642     void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
643
644     bool userPrefersReducedMotion() const;
645
646     void reportBacktrace();
647
648     enum class BaseWritingDirection { Natural, Ltr, Rtl };
649     void setBaseWritingDirection(BaseWritingDirection);
650
651 #if ENABLE(POINTER_LOCK)
652     bool pageHasPendingPointerLock() const;
653     bool pageHasPointerLock() const;
654 #endif
655
656     Vector<String> accessKeyModifiers() const;
657
658     void setQuickLookPassword(const String&);
659
660     void setAsRunningUserScripts(Document&);
661
662 #if ENABLE(WEBGL)
663     void simulateWebGLContextChanged(WebGLRenderingContext&);
664     void failNextGPUStatusCheck(WebGLRenderingContext&);
665     bool hasLowAndHighPowerGPUs();
666 #endif
667
668     void setPageVisibility(bool isVisible);
669     void setPageIsFocusedAndActive(bool);
670
671
672 #if ENABLE(WEB_RTC)
673     void setH264HardwareEncoderAllowed(bool allowed);
674 #endif
675
676 #if ENABLE(MEDIA_STREAM)
677     void setCameraMediaStreamTrackOrientation(MediaStreamTrack&, int orientation);
678     ExceptionOr<void> setMediaDeviceState(const String& id, const String& property, bool value);
679     unsigned long trackAudioSampleCount() const { return m_trackAudioSampleCount; }
680     unsigned long trackVideoSampleCount() const { return m_trackVideoSampleCount; }
681     void observeMediaStreamTrack(MediaStreamTrack&);
682     using TrackFramePromise = DOMPromiseDeferred<IDLInterface<ImageData>>;
683     void grabNextMediaStreamTrackFrame(TrackFramePromise&&);
684     void delayMediaStreamTrackSamples(MediaStreamTrack&, float);
685     void setMediaStreamTrackMuted(MediaStreamTrack&, bool);
686     void removeMediaStreamTrack(MediaStream&, MediaStreamTrack&);
687     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
688     void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
689     void setMediaStreamSourceInterrupted(MediaStreamTrack&, bool);
690 #endif
691
692     String audioSessionCategory() const;
693     double preferredAudioBufferSize() const;
694
695     void clearCacheStorageMemoryRepresentation(DOMPromiseDeferred<void>&&);
696     void cacheStorageEngineRepresentation(DOMPromiseDeferred<IDLDOMString>&&);
697     void setResponseSizeWithPadding(FetchResponse&, uint64_t size);
698     uint64_t responseSizeWithPadding(FetchResponse&) const;
699
700     void setConsoleMessageListener(RefPtr<StringCallback>&&);
701
702 #if ENABLE(SERVICE_WORKER)
703     using HasRegistrationPromise = DOMPromiseDeferred<IDLBoolean>;
704     void hasServiceWorkerRegistration(const String& clientURL, HasRegistrationPromise&&);
705     void terminateServiceWorker(ServiceWorker&);
706     bool hasServiceWorkerConnection();
707 #endif
708
709 #if ENABLE(APPLE_PAY)
710     MockPaymentCoordinator& mockPaymentCoordinator(Document&);
711 #endif
712
713     bool isSystemPreviewLink(Element&) const;
714     bool isSystemPreviewImage(Element&) const;
715
716     bool usingAppleInternalSDK() const;
717
718     struct NowPlayingState {
719         String title;
720         double duration;
721         double elapsedTime;
722         uint64_t uniqueIdentifier;
723         bool hasActiveSession;
724         bool registeredAsNowPlayingApplication;
725     };
726     ExceptionOr<NowPlayingState> nowPlayingState() const;
727
728 #if ENABLE(VIDEO)
729     using PlaybackControlsPurpose = MediaElementSession::PlaybackControlsPurpose;
730     RefPtr<HTMLMediaElement> bestMediaElementForShowingPlaybackControlsManager(PlaybackControlsPurpose);
731
732     using MediaSessionState = PlatformMediaSession::State;
733     MediaSessionState mediaSessionState(HTMLMediaElement&);
734 #endif
735
736     void setCaptureExtraNetworkLoadMetricsEnabled(bool);
737     String ongoingLoadsDescriptions() const;
738
739     void reloadWithoutContentExtensions();
740
741     void setUseSystemAppearance(bool);
742
743     size_t pluginCount();
744
745     void notifyResourceLoadObserver();
746
747     unsigned primaryScreenDisplayID();
748
749     bool capsLockIsOn();
750         
751     bool supportsVCPEncoder();
752         
753     using HEVCParameterSet = WebCore::HEVCParameterSet;
754     std::optional<HEVCParameterSet> parseHEVCCodecParameters(const String& codecString);
755
756     struct CookieData {
757         String name;
758         String value;
759         String domain;
760         // Expiration dates are expressed as milliseconds since the UNIX epoch.
761         double expires { 0 };
762         bool isHttpOnly { false };
763         bool isSecure { false };
764         bool isSession { false };
765         bool isSameSiteLax { false };
766         bool isSameSiteStrict { false };
767
768         CookieData(Cookie cookie)
769             : name(cookie.name)
770             , value(cookie.value)
771             , domain(cookie.domain)
772             , expires(cookie.expires)
773             , isHttpOnly(cookie.httpOnly)
774             , isSecure(cookie.secure)
775             , isSession(cookie.session)
776             , isSameSiteLax(cookie.sameSite == Cookie::SameSitePolicy::Lax)
777             , isSameSiteStrict(cookie.sameSite == Cookie::SameSitePolicy::Strict)
778         {
779             ASSERT(!(isSameSiteLax && isSameSiteStrict));
780         }
781
782         CookieData()
783         {
784         }
785     };
786     Vector<CookieData> getCookies() const;
787
788 private:
789     explicit Internals(Document&);
790     Document* contextDocument() const;
791     Frame* frame() const;
792
793     ExceptionOr<RenderedDocumentMarker*> markerAt(Node&, const String& markerType, unsigned index);
794
795     // RealtimeMediaSource::Observer API
796 #if ENABLE(MEDIA_STREAM)
797     void videoSampleAvailable(MediaSample&) final;
798     void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final { m_trackAudioSampleCount++; }
799
800     OrientationNotifier m_orientationNotifier;
801     unsigned long m_trackVideoSampleCount { 0 };
802     unsigned long m_trackAudioSampleCount { 0 };
803     RefPtr<MediaStreamTrack> m_track;
804     std::optional<TrackFramePromise> m_nextTrackFramePromise;
805 #endif
806
807     std::unique_ptr<InspectorStubFrontend> m_inspectorFrontend;
808     RefPtr<CacheStorageConnection> m_cacheStorageConnection;
809 };
810
811 } // namespace WebCore