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