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