2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013, 2014 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.
30 #include "CSSComputedStyleDeclaration.h"
31 #include "ContextDestructionObserver.h"
32 #include "ExceptionCodePlaceholder.h"
34 #include "PageConsoleClient.h"
35 #include <bindings/ScriptValue.h>
36 #include <runtime/ArrayBuffer.h>
37 #include <runtime/Float32Array.h>
38 #include <wtf/PassRefPtr.h>
39 #include <wtf/RefCounted.h>
40 #include <wtf/text/WTFString.h>
54 class HTMLMediaElement;
55 class InspectorFrontendChannelDummy;
56 class InspectorFrontendClientDummy;
57 class InternalSettings;
58 class MallocStatistics;
64 class RenderedDocumentMarker;
65 class ScriptExecutionContext;
66 class SerializedScriptValue;
69 class TypeConversions;
72 #if ENABLE(CONTENT_FILTERING)
73 class MockContentFilterSettings;
76 typedef int ExceptionCode;
78 class Internals : public RefCounted<Internals>
79 , public ContextDestructionObserver {
81 static PassRefPtr<Internals> create(Document*);
84 static void resetToConsistentState(Page*);
86 String elementRenderTreeAsText(Element*, ExceptionCode&);
87 bool hasPausedImageAnimations(Element*, ExceptionCode&);
89 String address(Node*);
90 bool nodeNeedsStyleRecalc(Node*, ExceptionCode&);
91 String description(Deprecated::ScriptValue);
93 bool isPreloaded(const String& url);
94 bool isLoadingFromMemoryCache(const String& url);
95 String xhrResponseSource(XMLHttpRequest*);
96 bool isSharingStyleSheetContents(Element* linkA, Element* linkB);
97 bool isStyleSheetLoadingSubresources(Element* link);
98 void setOverrideCachePolicy(const String&);
99 void setOverrideResourceLoadPriority(const String&);
101 void clearMemoryCache();
102 void pruneMemoryCacheToSize(unsigned size);
103 unsigned memoryCacheSize() const;
105 void clearPageCache();
106 unsigned pageCacheSize() const;
108 PassRefPtr<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Node*, ExceptionCode&) const;
110 Node* ensureShadowRoot(Element* host, ExceptionCode&);
111 Node* ensureUserAgentShadowRoot(Element* host, ExceptionCode&);
112 Node* createShadowRoot(Element* host, ExceptionCode&);
113 Node* shadowRoot(Element* host, ExceptionCode&);
114 String shadowRootType(const Node*, ExceptionCode&) const;
115 Element* includerFor(Node*, ExceptionCode&);
116 String shadowPseudoId(Element*, ExceptionCode&);
117 void setShadowPseudoId(Element*, const String&, ExceptionCode&);
119 // DOMTimers throttling testing.
120 bool isTimerThrottled(int timeoutId, ExceptionCode&);
121 bool isRequestAnimationFrameThrottled() const;
122 bool areTimersThrottled() const;
124 // Spatial Navigation testing.
125 unsigned lastSpatialNavigationCandidateCount(ExceptionCode&) const;
127 // CSS Animation testing.
128 unsigned numberOfActiveAnimations() const;
129 bool animationsAreSuspended(ExceptionCode&) const;
130 void suspendAnimations(ExceptionCode&) const;
131 void resumeAnimations(ExceptionCode&) const;
132 bool pauseAnimationAtTimeOnElement(const String& animationName, double pauseTime, Element*, ExceptionCode&);
133 bool pauseAnimationAtTimeOnPseudoElement(const String& animationName, double pauseTime, Element*, const String& pseudoId, ExceptionCode&);
135 // CSS Transition testing.
136 bool pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element*, ExceptionCode&);
137 bool pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element*, const String& pseudoId, ExceptionCode&);
139 Node* treeScopeRootNode(Node*, ExceptionCode&);
140 Node* parentTreeScope(Node*, ExceptionCode&);
142 bool attached(Node*, ExceptionCode&);
144 String visiblePlaceholder(Element*);
145 #if ENABLE(INPUT_TYPE_COLOR)
146 void selectColorInColorChooser(Element*, const String& colorValue);
148 Vector<String> formControlStateOfPreviousHistoryItem(ExceptionCode&);
149 void setFormControlStateOfPreviousHistoryItem(const Vector<String>&, ExceptionCode&);
151 Ref<ClientRect> absoluteCaretBounds(ExceptionCode&);
153 Ref<ClientRect> boundingBox(Element*, ExceptionCode&);
155 Ref<ClientRectList> inspectorHighlightRects(ExceptionCode&);
156 String inspectorHighlightObject(ExceptionCode&);
158 unsigned markerCountForNode(Node*, const String&, ExceptionCode&);
159 PassRefPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionCode&);
160 String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionCode&);
161 void addTextMatchMarker(const Range*, bool isActive);
162 void setMarkedTextMatchesAreHighlighted(bool, ExceptionCode&);
164 void invalidateFontCache();
166 void setScrollViewPosition(long x, long y, ExceptionCode&);
167 void setViewBaseBackgroundColor(const String& colorValue, ExceptionCode&);
169 void setPagination(const String& mode, int gap, ExceptionCode& ec) { setPagination(mode, gap, 0, ec); }
170 void setPagination(const String& mode, int gap, int pageLength, ExceptionCode&);
171 String configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode&);
173 bool wasLastChangeUserEdit(Element* textField, ExceptionCode&);
174 bool elementShouldAutoComplete(Element* inputElement, ExceptionCode&);
175 void setEditingValue(Element* inputElement, const String&, ExceptionCode&);
176 void setAutofilled(Element*, bool enabled, ExceptionCode&);
177 void setShowAutoFillButton(Element*, bool enabled, ExceptionCode&);
178 void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionCode&);
180 void paintControlTints(ExceptionCode&);
182 PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionCode&);
183 unsigned locationFromRange(Element* scope, const Range*, ExceptionCode&);
184 unsigned lengthFromRange(Element* scope, const Range*, ExceptionCode&);
185 String rangeAsText(const Range*, ExceptionCode&);
186 PassRefPtr<Range> subrange(Range* range, int rangeLocation, int rangeLength, ExceptionCode&);
187 RefPtr<Range> rangeForDictionaryLookupAtLocation(int x, int y, ExceptionCode&);
189 void setDelegatesScrolling(bool enabled, ExceptionCode&);
191 int lastSpellCheckRequestSequence(ExceptionCode&);
192 int lastSpellCheckProcessedSequence(ExceptionCode&);
194 Vector<String> userPreferredLanguages() const;
195 void setUserPreferredLanguages(const Vector<String>&);
197 Vector<String> userPreferredAudioCharacteristics() const;
198 void setUserPreferredAudioCharacteristic(const String&);
200 unsigned wheelEventHandlerCount(ExceptionCode&);
201 unsigned touchEventHandlerCount(ExceptionCode&);
203 PassRefPtr<NodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding,
204 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionCode&) const;
206 String parserMetaData(Deprecated::ScriptValue = Deprecated::ScriptValue());
208 void updateEditorUINowIfScheduled();
210 bool hasSpellingMarker(int from, int length, ExceptionCode&);
211 bool hasGrammarMarker(int from, int length, ExceptionCode&);
212 bool hasAutocorrectedMarker(int from, int length, ExceptionCode&);
213 void setContinuousSpellCheckingEnabled(bool enabled, ExceptionCode&);
214 void setAutomaticQuoteSubstitutionEnabled(bool enabled, ExceptionCode&);
215 void setAutomaticLinkDetectionEnabled(bool enabled, ExceptionCode&);
216 void setAutomaticDashSubstitutionEnabled(bool enabled, ExceptionCode&);
217 void setAutomaticTextReplacementEnabled(bool enabled, ExceptionCode&);
218 void setAutomaticSpellingCorrectionEnabled(bool enabled, ExceptionCode&);
220 bool isOverwriteModeEnabled(ExceptionCode&);
221 void toggleOverwriteModeEnabled(ExceptionCode&);
223 unsigned countMatchesForText(const String&, unsigned findOptions, const String& markMatches, ExceptionCode&);
225 unsigned numberOfScrollableAreas(ExceptionCode&);
227 bool isPageBoxVisible(int pageNumber, ExceptionCode&);
229 static const char* internalsId;
231 InternalSettings* settings() const;
232 unsigned workerThreadCount() const;
234 void setBatteryStatus(const String& eventType, bool charging, double chargingTime, double dischargingTime, double level, ExceptionCode&);
236 void setDeviceProximity(const String& eventType, double value, double min, double max, ExceptionCode&);
239 // Values need to be kept in sync with Internals.idl.
240 LAYER_TREE_INCLUDES_VISIBLE_RECTS = 1,
241 LAYER_TREE_INCLUDES_TILE_CACHES = 2,
242 LAYER_TREE_INCLUDES_REPAINT_RECTS = 4,
243 LAYER_TREE_INCLUDES_PAINTING_PHASES = 8,
244 LAYER_TREE_INCLUDES_CONTENT_LAYERS = 16
246 String layerTreeAsText(Document*, unsigned flags, ExceptionCode&) const;
247 String layerTreeAsText(Document*, ExceptionCode&) const;
248 String repaintRectsAsText(ExceptionCode&) const;
249 String scrollingStateTreeAsText(ExceptionCode&) const;
250 String mainThreadScrollingReasons(ExceptionCode&) const;
251 RefPtr<ClientRectList> nonFastScrollableRects(ExceptionCode&) const;
253 void garbageCollectDocumentResources(ExceptionCode&) const;
255 void allowRoundingHacks() const;
257 void insertAuthorCSS(const String&, ExceptionCode&) const;
258 void insertUserCSS(const String&, ExceptionCode&) const;
260 const ProfilesArray& consoleProfiles() const;
262 unsigned numberOfLiveNodes() const;
263 unsigned numberOfLiveDocuments() const;
265 Vector<String> consoleMessageArgumentCounts() const;
266 PassRefPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
267 void closeDummyInspectorFrontend();
268 void setJavaScriptProfilingEnabled(bool enabled, ExceptionCode&);
269 void setInspectorIsUnderTest(bool isUnderTest, ExceptionCode&);
271 String counterValue(Element*);
273 int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
274 Vector<String> shortcutIconURLs() const;
276 int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
277 String pageProperty(String, int, ExceptionCode& = ASSERT_NO_EXCEPTION) const;
278 String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionCode& = ASSERT_NO_EXCEPTION) const;
280 void setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode&);
281 void setPageZoomFactor(float zoomFactor, ExceptionCode&);
283 void setUseFixedLayout(bool useFixedLayout, ExceptionCode&);
284 void setFixedLayoutSize(int width, int height, ExceptionCode&);
286 void setHeaderHeight(float);
287 void setFooterHeight(float);
289 void setTopContentInset(float);
291 #if ENABLE(FULLSCREEN_API)
292 void webkitWillEnterFullScreenForElement(Element*);
293 void webkitDidEnterFullScreenForElement(Element*);
294 void webkitWillExitFullScreenForElement(Element*);
295 void webkitDidExitFullScreenForElement(Element*);
298 WEBCORE_TESTSUPPORT_EXPORT void setApplicationCacheOriginQuota(unsigned long long);
300 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
301 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
303 PassRefPtr<MallocStatistics> mallocStatistics() const;
304 PassRefPtr<TypeConversions> typeConversions() const;
305 PassRefPtr<MemoryInfo> memoryInfo() const;
307 Vector<String> getReferencedFilePaths() const;
309 void startTrackingRepaints(ExceptionCode&);
310 void stopTrackingRepaints(ExceptionCode&);
312 void startTrackingLayerFlushes(ExceptionCode&);
313 unsigned long layerFlushCount(ExceptionCode&);
315 void startTrackingStyleRecalcs(ExceptionCode&);
316 unsigned long styleRecalcCount(ExceptionCode&);
318 void startTrackingCompositingUpdates(ExceptionCode&);
319 unsigned long compositingUpdateCount(ExceptionCode&);
321 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionCode&);
322 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionCode&);
323 unsigned layoutCount() const;
325 PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
326 PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const;
328 bool isFromCurrentWorld(Deprecated::ScriptValue) const;
330 void setUsesOverlayScrollbars(bool enabled);
332 String getCurrentCursorInfo(ExceptionCode&);
334 String markerTextForListItem(Element*, ExceptionCode&);
336 String toolTipFromElement(Element*, ExceptionCode&) const;
338 void forceReload(bool endToEnd);
340 #if ENABLE(ENCRYPTED_MEDIA_V2)
341 void initializeMockCDM();
344 #if ENABLE(SPEECH_SYNTHESIS)
345 void enableMockSpeechSynthesizer();
348 #if ENABLE(MEDIA_STREAM)
349 void enableMockRTCPeerConnectionHandler();
352 String getImageSourceURL(Element*, ExceptionCode&);
355 void simulateAudioInterruption(Node*);
356 bool mediaElementHasCharacteristic(Node*, const String&, ExceptionCode&);
359 bool isSelectPopupVisible(Node*);
361 String captionsStyleSheetOverride(ExceptionCode&);
362 void setCaptionsStyleSheetOverride(const String&, ExceptionCode&);
363 void setPrimaryAudioTrackLanguageOverride(const String&, ExceptionCode&);
364 void setCaptionDisplayMode(const String&, ExceptionCode&);
367 PassRefPtr<TimeRanges> createTimeRanges(Float32Array* startTimes, Float32Array* endTimes);
368 double closestTimeToTimeRanges(double time, TimeRanges*);
371 Ref<ClientRect> selectionBounds(ExceptionCode&);
373 #if ENABLE(VIBRATION)
377 bool isPluginUnavailabilityIndicatorObscured(Element*, ExceptionCode&);
378 bool isPluginSnapshotted(Element*, ExceptionCode&);
380 #if ENABLE(MEDIA_SOURCE)
381 WEBCORE_TESTSUPPORT_EXPORT void initializeMockMediaSource();
382 Vector<String> bufferedSamplesForTrackID(SourceBuffer*, const AtomicString&);
386 void beginMediaSessionInterruption();
387 void endMediaSessionInterruption(const String&);
388 void applicationWillEnterForeground() const;
389 void applicationWillEnterBackground() const;
390 void setMediaSessionRestrictions(const String& mediaType, const String& restrictions, ExceptionCode&);
391 void setMediaElementRestrictions(HTMLMediaElement*, const String& restrictions, ExceptionCode&);
392 void postRemoteControlCommand(const String&, ExceptionCode&);
393 bool elementIsBlockingDisplaySleep(Element*) const;
396 #if ENABLE(MEDIA_SESSION)
397 void sendMediaSessionStartOfInterruptionNotification(const String&);
398 void sendMediaSessionEndOfInterruptionNotification(const String&);
399 String mediaSessionCurrentState(MediaSession*) const;
402 #if ENABLE(WEB_AUDIO)
403 void setAudioContextRestrictions(AudioContext*, const String& restrictions, ExceptionCode&);
406 void simulateSystemSleep() const;
407 void simulateSystemWake() const;
409 void installMockPageOverlay(const String& overlayType, ExceptionCode&);
410 String pageOverlayLayerTreeAsText(ExceptionCode&) const;
412 void setPageMuted(bool);
413 bool isPagePlayingAudio();
415 RefPtr<File> createFile(const String&);
416 void queueMicroTask(int);
417 bool testPreloaderSettingViewport();
419 #if ENABLE(CONTENT_FILTERING)
420 MockContentFilterSettings& mockContentFilterSettings();
423 #if ENABLE(CSS_SCROLL_SNAP)
424 String scrollSnapOffsets(Element*, ExceptionCode&);
427 String pathStringWithShrinkWrappedRects(Vector<double> rectComponents, double radius, ExceptionCode&);
430 explicit Internals(Document*);
431 Document* contextDocument() const;
432 Frame* frame() const;
434 RenderedDocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionCode&);
436 RefPtr<DOMWindow> m_frontendWindow;
437 std::unique_ptr<InspectorFrontendClientDummy> m_frontendClient;
438 std::unique_ptr<InspectorFrontendChannelDummy> m_frontendChannel;
441 } // namespace WebCore