2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013-2016 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 #include "CSSComputedStyleDeclaration.h"
30 #include "ContextDestructionObserver.h"
31 #include "ExceptionOr.h"
32 #include "PageConsoleClient.h"
33 #include <runtime/Float32Array.h>
35 #if ENABLE(MEDIA_SESSION)
36 #include "MediaSessionInterruptionProvider.h"
51 class HTMLImageElement;
52 class HTMLInputElement;
53 class HTMLLinkElement;
54 class HTMLMediaElement;
55 class HTMLSelectElement;
56 class InspectorStubFrontend;
57 class InternalSettings;
58 class MallocStatistics;
61 class MockContentFilterSettings;
62 class MockPageOverlay;
66 class RenderedDocumentMarker;
67 class RTCPeerConnection;
68 class SerializedScriptValue;
71 class TypeConversions;
74 class Internals final : public RefCounted<Internals>, private ContextDestructionObserver {
76 static Ref<Internals> create(Document&);
79 static void resetToConsistentState(Page&);
81 ExceptionOr<String> elementRenderTreeAsText(Element&);
82 bool hasPausedImageAnimations(Element&);
84 String address(Node&);
85 bool nodeNeedsStyleRecalc(Node&);
86 String styleChangeType(Node&);
87 String description(JSC::JSValue);
89 bool isPreloaded(const String& url);
90 bool isLoadingFromMemoryCache(const String& url);
91 String xhrResponseSource(XMLHttpRequest&);
92 bool isSharingStyleSheetContents(HTMLLinkElement&, HTMLLinkElement&);
93 bool isStyleSheetLoadingSubresources(HTMLLinkElement&);
94 enum class CachePolicy { UseProtocolCachePolicy, ReloadIgnoringCacheData, ReturnCacheDataElseLoad, ReturnCacheDataDontLoad };
95 void setOverrideCachePolicy(CachePolicy);
96 ExceptionOr<void> setCanShowModalDialogOverride(bool allow);
97 enum class ResourceLoadPriority { ResourceLoadPriorityVeryLow, ResourceLoadPriorityLow, ResourceLoadPriorityMedium, ResourceLoadPriorityHigh, ResourceLoadPriorityVeryHigh };
98 void setOverrideResourceLoadPriority(ResourceLoadPriority);
99 void setStrictRawResourceValidationPolicyDisabled(bool);
101 void clearMemoryCache();
102 void pruneMemoryCacheToSize(unsigned size);
103 unsigned memoryCacheSize() const;
105 unsigned imageFrameIndex(HTMLImageElement&);
107 void clearPageCache();
108 unsigned pageCacheSize() const;
110 RefPtr<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Element&) const;
112 ExceptionOr<Node*> ensureShadowRoot(Element& host);
113 Node* ensureUserAgentShadowRoot(Element& host);
114 ExceptionOr<Node*> createShadowRoot(Element& host);
115 Node* shadowRoot(Element& host);
116 ExceptionOr<String> shadowRootType(const Node&) const;
117 String shadowPseudoId(Element&);
118 void setShadowPseudoId(Element&, const String&);
120 // DOMTimers throttling testing.
121 ExceptionOr<bool> isTimerThrottled(int timeoutId);
122 bool isRequestAnimationFrameThrottled() const;
123 bool areTimersThrottled() const;
125 // Spatial Navigation testing.
126 ExceptionOr<unsigned> lastSpatialNavigationCandidateCount() const;
128 // CSS Animation testing.
129 unsigned numberOfActiveAnimations() const;
130 ExceptionOr<bool> animationsAreSuspended() const;
131 ExceptionOr<void> suspendAnimations() const;
132 ExceptionOr<void> resumeAnimations() const;
133 ExceptionOr<bool> pauseAnimationAtTimeOnElement(const String& animationName, double pauseTime, Element&);
134 ExceptionOr<bool> pauseAnimationAtTimeOnPseudoElement(const String& animationName, double pauseTime, Element&, const String& pseudoId);
136 // CSS Transition testing.
137 ExceptionOr<bool> pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element&);
138 ExceptionOr<bool> pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element&, const String& pseudoId);
140 Node* treeScopeRootNode(Node&);
141 Node* parentTreeScope(Node&);
143 String visiblePlaceholder(Element&);
144 void selectColorInColorChooser(HTMLInputElement&, const String& colorValue);
145 ExceptionOr<Vector<String>> formControlStateOfPreviousHistoryItem();
146 ExceptionOr<void> setFormControlStateOfPreviousHistoryItem(const Vector<String>&);
148 ExceptionOr<Ref<ClientRect>> absoluteCaretBounds();
150 Ref<ClientRect> boundingBox(Element&);
152 ExceptionOr<Ref<ClientRectList>> inspectorHighlightRects();
153 ExceptionOr<String> inspectorHighlightObject();
155 ExceptionOr<unsigned> markerCountForNode(Node&, const String&);
156 ExceptionOr<RefPtr<Range>> markerRangeForNode(Node&, const String& markerType, unsigned index);
157 ExceptionOr<String> markerDescriptionForNode(Node&, const String& markerType, unsigned index);
158 ExceptionOr<String> dumpMarkerRects(const String& markerType);
159 void addTextMatchMarker(const Range&, bool isActive);
160 ExceptionOr<void> setMarkedTextMatchesAreHighlighted(bool);
162 void invalidateFontCache();
164 ExceptionOr<void> setScrollViewPosition(int x, int y);
165 ExceptionOr<void> setViewBaseBackgroundColor(const String& colorValue);
167 ExceptionOr<void> setPagination(const String& mode, int gap, int pageLength);
168 ExceptionOr<void> setPaginationLineGridEnabled(bool);
169 ExceptionOr<String> configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight);
171 ExceptionOr<bool> wasLastChangeUserEdit(Element& textField);
172 bool elementShouldAutoComplete(HTMLInputElement&);
173 void setEditingValue(HTMLInputElement&, const String&);
174 void setAutofilled(HTMLInputElement&, bool enabled);
175 enum class AutoFillButtonType { AutoFillButtonTypeNone, AutoFillButtonTypeContacts, AutoFillButtonTypeCredentials };
176 void setShowAutoFillButton(HTMLInputElement&, AutoFillButtonType);
177 ExceptionOr<void> scrollElementToRect(Element&, int x, int y, int w, int h);
179 ExceptionOr<String> autofillFieldName(Element&);
181 ExceptionOr<void> paintControlTints();
183 RefPtr<Range> rangeFromLocationAndLength(Element& scope, int rangeLocation, int rangeLength);
184 unsigned locationFromRange(Element& scope, const Range&);
185 unsigned lengthFromRange(Element& scope, const Range&);
186 String rangeAsText(const Range&);
187 RefPtr<Range> subrange(Range&, int rangeLocation, int rangeLength);
188 ExceptionOr<RefPtr<Range>> rangeForDictionaryLookupAtLocation(int x, int y);
190 ExceptionOr<void> setDelegatesScrolling(bool enabled);
192 ExceptionOr<int> lastSpellCheckRequestSequence();
193 ExceptionOr<int> lastSpellCheckProcessedSequence();
195 Vector<String> userPreferredLanguages() const;
196 void setUserPreferredLanguages(const Vector<String>&);
198 Vector<String> userPreferredAudioCharacteristics() const;
199 void setUserPreferredAudioCharacteristic(const String&);
201 ExceptionOr<unsigned> wheelEventHandlerCount();
202 ExceptionOr<unsigned> touchEventHandlerCount();
204 ExceptionOr<RefPtr<NodeList>> nodesFromRect(Document&, int x, int y, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent) const;
206 String parserMetaData(JSC::JSValue = JSC::JSValue::JSUndefined);
208 void updateEditorUINowIfScheduled();
210 bool hasSpellingMarker(int from, int length);
211 bool hasGrammarMarker(int from, int length);
212 bool hasAutocorrectedMarker(int from, int length);
213 void setContinuousSpellCheckingEnabled(bool);
214 void setAutomaticQuoteSubstitutionEnabled(bool);
215 void setAutomaticLinkDetectionEnabled(bool);
216 void setAutomaticDashSubstitutionEnabled(bool);
217 void setAutomaticTextReplacementEnabled(bool);
218 void setAutomaticSpellingCorrectionEnabled(bool);
220 void handleAcceptedCandidate(const String& candidate, unsigned location, unsigned length);
222 bool isOverwriteModeEnabled();
223 void toggleOverwriteModeEnabled();
225 unsigned countMatchesForText(const String&, unsigned findOptions, const String& markMatches);
226 unsigned countFindMatches(const String&, unsigned findOptions);
228 unsigned numberOfScrollableAreas();
230 ExceptionOr<bool> isPageBoxVisible(int pageNumber);
232 static const char* internalsId;
234 InternalSettings* settings() const;
235 unsigned workerThreadCount() const;
237 ExceptionOr<void> setBatteryStatus(const String& eventType, bool charging, double chargingTime, double dischargingTime, double level);
238 ExceptionOr<void> setDeviceProximity(const String& eventType, double value, double min, double max);
241 // Values need to be kept in sync with Internals.idl.
242 LAYER_TREE_INCLUDES_VISIBLE_RECTS = 1,
243 LAYER_TREE_INCLUDES_TILE_CACHES = 2,
244 LAYER_TREE_INCLUDES_REPAINT_RECTS = 4,
245 LAYER_TREE_INCLUDES_PAINTING_PHASES = 8,
246 LAYER_TREE_INCLUDES_CONTENT_LAYERS = 16
248 ExceptionOr<String> layerTreeAsText(Document&, unsigned short flags) const;
249 ExceptionOr<String> repaintRectsAsText() const;
250 ExceptionOr<String> scrollingStateTreeAsText() const;
251 ExceptionOr<String> mainThreadScrollingReasons() const;
252 ExceptionOr<RefPtr<ClientRectList>> nonFastScrollableRects() const;
254 ExceptionOr<void> setElementUsesDisplayListDrawing(Element&, bool usesDisplayListDrawing);
255 ExceptionOr<void> setElementTracksDisplayListReplay(Element&, bool isTrackingReplay);
258 // Values need to be kept in sync with Internals.idl.
259 DISPLAY_LIST_INCLUDES_PLATFORM_OPERATIONS = 1,
261 ExceptionOr<String> displayListForElement(Element&, unsigned short flags);
262 ExceptionOr<String> replayDisplayListForElement(Element&, unsigned short flags);
264 ExceptionOr<void> garbageCollectDocumentResources() const;
266 void beginSimulatedMemoryPressure();
267 void endSimulatedMemoryPressure();
268 bool isUnderMemoryPressure();
270 ExceptionOr<void> insertAuthorCSS(const String&) const;
271 ExceptionOr<void> insertUserCSS(const String&) const;
273 unsigned numberOfLiveNodes() const;
274 unsigned numberOfLiveDocuments() const;
276 RefPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
277 void closeDummyInspectorFrontend();
278 ExceptionOr<void> setInspectorIsUnderTest(bool);
280 String counterValue(Element&);
282 int pageNumber(Element&, float pageWidth = 800, float pageHeight = 600);
283 Vector<String> shortcutIconURLs() const;
285 int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
286 ExceptionOr<String> pageProperty(const String& propertyName, int pageNumber) const;
287 ExceptionOr<String> pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const;
289 ExceptionOr<void> setPageScaleFactor(float scaleFactor, int x, int y);
290 ExceptionOr<void> setPageZoomFactor(float);
291 ExceptionOr<void> setTextZoomFactor(float);
293 ExceptionOr<void> setUseFixedLayout(bool);
294 ExceptionOr<void> setFixedLayoutSize(int width, int height);
295 ExceptionOr<void> setViewExposedRect(float left, float top, float width, float height);
297 void setHeaderHeight(float);
298 void setFooterHeight(float);
300 void setTopContentInset(float);
302 #if ENABLE(FULLSCREEN_API)
303 void webkitWillEnterFullScreenForElement(Element&);
304 void webkitDidEnterFullScreenForElement(Element&);
305 void webkitWillExitFullScreenForElement(Element&);
306 void webkitDidExitFullScreenForElement(Element&);
309 WEBCORE_TESTSUPPORT_EXPORT void setApplicationCacheOriginQuota(unsigned long long);
311 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
312 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
314 Ref<MallocStatistics> mallocStatistics() const;
315 Ref<TypeConversions> typeConversions() const;
316 Ref<MemoryInfo> memoryInfo() const;
318 Vector<String> getReferencedFilePaths() const;
320 ExceptionOr<void> startTrackingRepaints();
321 ExceptionOr<void> stopTrackingRepaints();
323 ExceptionOr<void> startTrackingLayerFlushes();
324 ExceptionOr<unsigned> layerFlushCount();
326 ExceptionOr<void> startTrackingStyleRecalcs();
327 ExceptionOr<unsigned> styleRecalcCount();
328 unsigned lastStyleUpdateSize() const;
330 ExceptionOr<void> startTrackingCompositingUpdates();
331 ExceptionOr<unsigned> compositingUpdateCount();
333 ExceptionOr<void> updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*);
334 unsigned layoutCount() const;
336 RefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
337 RefPtr<SerializedScriptValue> deserializeBuffer(ArrayBuffer&) const;
339 bool isFromCurrentWorld(JSC::JSValue) const;
341 void setUsesOverlayScrollbars(bool);
342 void setUsesMockScrollAnimator(bool);
344 ExceptionOr<String> getCurrentCursorInfo();
346 String markerTextForListItem(Element&);
348 String toolTipFromElement(Element&) const;
350 void forceReload(bool endToEnd);
352 void enableAutoSizeMode(bool enabled, int minimumWidth, int minimumHeight, int maximumWidth, int maximumHeight);
354 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
355 void initializeMockCDM();
358 #if ENABLE(SPEECH_SYNTHESIS)
359 void enableMockSpeechSynthesizer();
362 #if ENABLE(MEDIA_STREAM)
363 void setMockMediaCaptureDevicesEnabled(bool);
367 void enableMockMediaEndpoint();
368 void enableMockRTCPeerConnectionHandler();
369 void emulateRTCPeerConnectionPlatformEvent(RTCPeerConnection&, const String& action);
372 String getImageSourceURL(Element&);
375 void simulateAudioInterruption(HTMLMediaElement&);
376 ExceptionOr<bool> mediaElementHasCharacteristic(HTMLMediaElement&, const String&);
379 bool isSelectPopupVisible(HTMLSelectElement&);
381 ExceptionOr<String> captionsStyleSheetOverride();
382 ExceptionOr<void> setCaptionsStyleSheetOverride(const String&);
383 ExceptionOr<void> setPrimaryAudioTrackLanguageOverride(const String&);
384 ExceptionOr<void> setCaptionDisplayMode(const String&);
387 Ref<TimeRanges> createTimeRanges(Float32Array& startTimes, Float32Array& endTimes);
388 double closestTimeToTimeRanges(double time, TimeRanges&);
391 ExceptionOr<Ref<ClientRect>> selectionBounds();
393 #if ENABLE(VIBRATION)
397 ExceptionOr<bool> isPluginUnavailabilityIndicatorObscured(Element&);
398 bool isPluginSnapshotted(Element&);
400 #if ENABLE(MEDIA_SOURCE)
401 WEBCORE_TESTSUPPORT_EXPORT void initializeMockMediaSource();
402 Vector<String> bufferedSamplesForTrackID(SourceBuffer&, const AtomicString&);
403 Vector<String> enqueuedSamplesForTrackID(SourceBuffer&, const AtomicString&);
404 void setShouldGenerateTimestamps(SourceBuffer&, bool);
408 ExceptionOr<void> beginMediaSessionInterruption(const String&);
409 void endMediaSessionInterruption(const String&);
410 void applicationDidEnterForeground() const;
411 void applicationWillEnterBackground() const;
412 ExceptionOr<void> setMediaSessionRestrictions(const String& mediaType, const String& restrictions);
413 void setMediaElementRestrictions(HTMLMediaElement&, const String& restrictions);
414 ExceptionOr<void> postRemoteControlCommand(const String&, float argument);
415 bool elementIsBlockingDisplaySleep(HTMLMediaElement&) const;
418 #if ENABLE(MEDIA_SESSION)
419 void sendMediaSessionStartOfInterruptionNotification(MediaSessionInterruptingCategory);
420 void sendMediaSessionEndOfInterruptionNotification(MediaSessionInterruptingCategory);
421 String mediaSessionCurrentState(MediaSession&) const;
422 double mediaElementPlayerVolume(HTMLMediaElement&) const;
423 enum class MediaControlEvent { PlayPause, NextTrack, PreviousTrack };
424 void sendMediaControlEvent(MediaControlEvent);
427 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
428 void setMockMediaPlaybackTargetPickerEnabled(bool);
429 ExceptionOr<void> setMockMediaPlaybackTargetPickerState(const String& deviceName, const String& deviceState);
432 #if ENABLE(WEB_AUDIO)
433 void setAudioContextRestrictions(AudioContext&, const String& restrictions);
436 void simulateSystemSleep() const;
437 void simulateSystemWake() const;
439 enum class PageOverlayType { View, Document };
440 ExceptionOr<Ref<MockPageOverlay>> installMockPageOverlay(PageOverlayType);
441 ExceptionOr<String> pageOverlayLayerTreeAsText() const;
443 void setPageMuted(const String&);
444 String pageMediaState();
446 void setPageDefersLoading(bool);
448 RefPtr<File> createFile(const String&);
449 void queueMicroTask(int);
450 bool testPreloaderSettingViewport();
452 #if ENABLE(CONTENT_FILTERING)
453 MockContentFilterSettings& mockContentFilterSettings();
456 #if ENABLE(CSS_SCROLL_SNAP)
457 ExceptionOr<String> scrollSnapOffsets(Element&);
460 ExceptionOr<String> pathStringWithShrinkWrappedRects(const Vector<double>& rectComponents, double radius);
462 String getCurrentMediaControlsStatusForElement(HTMLMediaElement&);
464 String userVisibleString(const DOMURL&);
465 void setShowAllPlugins(bool);
467 String resourceLoadStatisticsForOrigin(const String& origin);
468 void setResourceLoadStatisticsEnabled(bool);
470 #if ENABLE(READABLE_STREAM_API)
471 bool isReadableStreamDisturbed(JSC::ExecState&, JSC::JSValue);
474 String composedTreeAsText(Node&);
476 void setLinkPreloadSupport(bool);
477 void setResourceTimingSupport(bool);
479 #if ENABLE(CSS_GRID_LAYOUT)
480 void setCSSGridLayoutEnabled(bool);
484 bool webGL2Enabled() const;
485 void setWebGL2Enabled(bool);
488 bool isProcessingUserGesture();
490 RefPtr<GCObservation> observeGC(JSC::JSValue);
492 enum class UserInterfaceLayoutDirection { LTR, RTL };
493 void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
495 bool userPrefersReducedMotion() const;
498 explicit Internals(Document&);
499 Document* contextDocument() const;
500 Frame* frame() const;
502 ExceptionOr<RenderedDocumentMarker*> markerAt(Node&, const String& markerType, unsigned index);
504 std::unique_ptr<InspectorStubFrontend> m_inspectorFrontend;
507 } // namespace WebCore