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>
53 class HTMLMediaElement;
54 class InspectorFrontendChannelDummy;
55 class InspectorFrontendClientDummy;
56 class InternalSettings;
57 class MallocStatistics;
62 class RenderedDocumentMarker;
63 class ScriptExecutionContext;
64 class SerializedScriptValue;
67 class TypeConversions;
70 #if ENABLE(CONTENT_FILTERING)
71 class MockContentFilterSettings;
74 typedef int ExceptionCode;
76 class Internals : public RefCounted<Internals>
77 , public ContextDestructionObserver {
79 static PassRefPtr<Internals> create(Document*);
82 static void resetToConsistentState(Page*);
84 String elementRenderTreeAsText(Element*, ExceptionCode&);
85 bool hasPausedImageAnimations(Element*, ExceptionCode&);
87 String address(Node*);
88 bool nodeNeedsStyleRecalc(Node*, ExceptionCode&);
89 String description(Deprecated::ScriptValue);
91 bool isPreloaded(const String& url);
92 bool isLoadingFromMemoryCache(const String& url);
93 String xhrResponseSource(XMLHttpRequest*);
94 void setOverrideCachePolicy(const String&);
95 void setOverrideResourceLoadPriority(const String&);
97 void clearMemoryCache();
98 void pruneMemoryCacheToSize(unsigned size);
99 unsigned memoryCacheSize() const;
101 void clearPageCache();
102 unsigned pageCacheSize() const;
104 PassRefPtr<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Node*, ExceptionCode&) const;
106 Node* ensureShadowRoot(Element* host, ExceptionCode&);
107 Node* createShadowRoot(Element* host, ExceptionCode&);
108 Node* shadowRoot(Element* host, ExceptionCode&);
109 String shadowRootType(const Node*, ExceptionCode&) const;
110 Element* includerFor(Node*, ExceptionCode&);
111 String shadowPseudoId(Element*, ExceptionCode&);
112 void setShadowPseudoId(Element*, const String&, ExceptionCode&);
114 // DOMTimers throttling testing.
115 bool isTimerThrottled(int timeoutId, ExceptionCode&);
116 bool isRequestAnimationFrameThrottled() const;
118 // Spatial Navigation testing.
119 unsigned lastSpatialNavigationCandidateCount(ExceptionCode&) const;
121 // CSS Animation testing.
122 unsigned numberOfActiveAnimations() const;
123 bool animationsAreSuspended(ExceptionCode&) const;
124 void suspendAnimations(ExceptionCode&) const;
125 void resumeAnimations(ExceptionCode&) const;
126 bool pauseAnimationAtTimeOnElement(const String& animationName, double pauseTime, Element*, ExceptionCode&);
127 bool pauseAnimationAtTimeOnPseudoElement(const String& animationName, double pauseTime, Element*, const String& pseudoId, ExceptionCode&);
129 // CSS Transition testing.
130 bool pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element*, ExceptionCode&);
131 bool pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element*, const String& pseudoId, ExceptionCode&);
133 Node* treeScopeRootNode(Node*, ExceptionCode&);
134 Node* parentTreeScope(Node*, ExceptionCode&);
136 bool attached(Node*, ExceptionCode&);
138 String visiblePlaceholder(Element*);
139 #if ENABLE(INPUT_TYPE_COLOR)
140 void selectColorInColorChooser(Element*, const String& colorValue);
142 Vector<String> formControlStateOfPreviousHistoryItem(ExceptionCode&);
143 void setFormControlStateOfPreviousHistoryItem(const Vector<String>&, ExceptionCode&);
145 Ref<ClientRect> absoluteCaretBounds(ExceptionCode&);
147 Ref<ClientRect> boundingBox(Element*, ExceptionCode&);
149 Ref<ClientRectList> inspectorHighlightRects(ExceptionCode&);
150 String inspectorHighlightObject(ExceptionCode&);
152 unsigned markerCountForNode(Node*, const String&, ExceptionCode&);
153 PassRefPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionCode&);
154 String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionCode&);
155 void addTextMatchMarker(const Range*, bool isActive);
156 void setMarkedTextMatchesAreHighlighted(bool, ExceptionCode&);
158 void invalidateFontCache();
160 void setScrollViewPosition(long x, long y, ExceptionCode&);
161 void setViewBaseBackgroundColor(const String& colorValue, ExceptionCode&);
163 void setPagination(const String& mode, int gap, ExceptionCode& ec) { setPagination(mode, gap, 0, ec); }
164 void setPagination(const String& mode, int gap, int pageLength, ExceptionCode&);
165 String configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode&);
167 bool wasLastChangeUserEdit(Element* textField, ExceptionCode&);
168 bool elementShouldAutoComplete(Element* inputElement, ExceptionCode&);
169 void setEditingValue(Element* inputElement, const String&, ExceptionCode&);
170 void setAutofilled(Element*, bool enabled, ExceptionCode&);
171 void setShowAutoFillButton(Element*, bool enabled, ExceptionCode&);
172 void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionCode&);
174 void paintControlTints(ExceptionCode&);
176 PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionCode&);
177 unsigned locationFromRange(Element* scope, const Range*, ExceptionCode&);
178 unsigned lengthFromRange(Element* scope, const Range*, ExceptionCode&);
179 String rangeAsText(const Range*, ExceptionCode&);
180 PassRefPtr<Range> subrange(Range* range, int rangeLocation, int rangeLength, ExceptionCode&);
181 RefPtr<Range> rangeForDictionaryLookupAtLocation(int x, int y, ExceptionCode&);
183 void setDelegatesScrolling(bool enabled, ExceptionCode&);
185 int lastSpellCheckRequestSequence(ExceptionCode&);
186 int lastSpellCheckProcessedSequence(ExceptionCode&);
188 Vector<String> userPreferredLanguages() const;
189 void setUserPreferredLanguages(const Vector<String>&);
191 unsigned wheelEventHandlerCount(ExceptionCode&);
192 unsigned touchEventHandlerCount(ExceptionCode&);
194 PassRefPtr<NodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding,
195 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionCode&) const;
197 String parserMetaData(Deprecated::ScriptValue = Deprecated::ScriptValue());
199 void updateEditorUINowIfScheduled();
201 bool hasSpellingMarker(int from, int length, ExceptionCode&);
202 bool hasGrammarMarker(int from, int length, ExceptionCode&);
203 bool hasAutocorrectedMarker(int from, int length, ExceptionCode&);
204 void setContinuousSpellCheckingEnabled(bool enabled, ExceptionCode&);
205 void setAutomaticQuoteSubstitutionEnabled(bool enabled, ExceptionCode&);
206 void setAutomaticLinkDetectionEnabled(bool enabled, ExceptionCode&);
207 void setAutomaticDashSubstitutionEnabled(bool enabled, ExceptionCode&);
208 void setAutomaticTextReplacementEnabled(bool enabled, ExceptionCode&);
209 void setAutomaticSpellingCorrectionEnabled(bool enabled, ExceptionCode&);
211 bool isOverwriteModeEnabled(ExceptionCode&);
212 void toggleOverwriteModeEnabled(ExceptionCode&);
214 unsigned countMatchesForText(const String&, unsigned findOptions, const String& markMatches, ExceptionCode&);
216 unsigned numberOfScrollableAreas(ExceptionCode&);
218 bool isPageBoxVisible(int pageNumber, ExceptionCode&);
220 static const char* internalsId;
222 InternalSettings* settings() const;
223 unsigned workerThreadCount() const;
225 void setBatteryStatus(const String& eventType, bool charging, double chargingTime, double dischargingTime, double level, ExceptionCode&);
227 void setDeviceProximity(const String& eventType, double value, double min, double max, ExceptionCode&);
230 // Values need to be kept in sync with Internals.idl.
231 LAYER_TREE_INCLUDES_VISIBLE_RECTS = 1,
232 LAYER_TREE_INCLUDES_TILE_CACHES = 2,
233 LAYER_TREE_INCLUDES_REPAINT_RECTS = 4,
234 LAYER_TREE_INCLUDES_PAINTING_PHASES = 8,
235 LAYER_TREE_INCLUDES_CONTENT_LAYERS = 16
237 String layerTreeAsText(Document*, unsigned flags, ExceptionCode&) const;
238 String layerTreeAsText(Document*, ExceptionCode&) const;
239 String repaintRectsAsText(ExceptionCode&) const;
240 String scrollingStateTreeAsText(ExceptionCode&) const;
241 String mainThreadScrollingReasons(ExceptionCode&) const;
242 RefPtr<ClientRectList> nonFastScrollableRects(ExceptionCode&) const;
244 void garbageCollectDocumentResources(ExceptionCode&) const;
246 void allowRoundingHacks() const;
248 void insertAuthorCSS(const String&, ExceptionCode&) const;
249 void insertUserCSS(const String&, ExceptionCode&) const;
251 const ProfilesArray& consoleProfiles() const;
253 unsigned numberOfLiveNodes() const;
254 unsigned numberOfLiveDocuments() const;
256 Vector<String> consoleMessageArgumentCounts() const;
257 PassRefPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
258 void closeDummyInspectorFrontend();
259 void setJavaScriptProfilingEnabled(bool enabled, ExceptionCode&);
260 void setInspectorIsUnderTest(bool isUnderTest, ExceptionCode&);
262 String counterValue(Element*);
264 int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
265 Vector<String> shortcutIconURLs() const;
267 int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
268 String pageProperty(String, int, ExceptionCode& = ASSERT_NO_EXCEPTION) const;
269 String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionCode& = ASSERT_NO_EXCEPTION) const;
271 void setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode&);
272 void setPageZoomFactor(float zoomFactor, ExceptionCode&);
274 void setUseFixedLayout(bool useFixedLayout, ExceptionCode&);
275 void setFixedLayoutSize(int width, int height, ExceptionCode&);
277 void setHeaderHeight(float);
278 void setFooterHeight(float);
280 void setTopContentInset(float);
282 #if ENABLE(FULLSCREEN_API)
283 void webkitWillEnterFullScreenForElement(Element*);
284 void webkitDidEnterFullScreenForElement(Element*);
285 void webkitWillExitFullScreenForElement(Element*);
286 void webkitDidExitFullScreenForElement(Element*);
289 WEBCORE_TESTSUPPORT_EXPORT void setApplicationCacheOriginQuota(unsigned long long);
291 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
292 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
294 PassRefPtr<MallocStatistics> mallocStatistics() const;
295 PassRefPtr<TypeConversions> typeConversions() const;
296 PassRefPtr<MemoryInfo> memoryInfo() const;
298 Vector<String> getReferencedFilePaths() const;
300 void startTrackingRepaints(ExceptionCode&);
301 void stopTrackingRepaints(ExceptionCode&);
303 void startTrackingLayerFlushes(ExceptionCode&);
304 unsigned long layerFlushCount(ExceptionCode&);
306 void startTrackingStyleRecalcs(ExceptionCode&);
307 unsigned long styleRecalcCount(ExceptionCode&);
309 void startTrackingCompositingUpdates(ExceptionCode&);
310 unsigned long compositingUpdateCount(ExceptionCode&);
312 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionCode&);
313 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionCode&);
315 PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
316 PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const;
318 void setUsesOverlayScrollbars(bool enabled);
320 String getCurrentCursorInfo(ExceptionCode&);
322 String markerTextForListItem(Element*, ExceptionCode&);
324 String toolTipFromElement(Element*, ExceptionCode&) const;
326 void forceReload(bool endToEnd);
328 #if ENABLE(ENCRYPTED_MEDIA_V2)
329 void initializeMockCDM();
332 #if ENABLE(SPEECH_SYNTHESIS)
333 void enableMockSpeechSynthesizer();
336 #if ENABLE(MEDIA_STREAM)
337 void enableMockRTCPeerConnectionHandler();
340 String getImageSourceURL(Element*, ExceptionCode&);
343 void simulateAudioInterruption(Node*);
344 bool mediaElementHasCharacteristic(Node*, const String&, ExceptionCode&);
347 bool isSelectPopupVisible(Node*);
349 String captionsStyleSheetOverride(ExceptionCode&);
350 void setCaptionsStyleSheetOverride(const String&, ExceptionCode&);
351 void setPrimaryAudioTrackLanguageOverride(const String&, ExceptionCode&);
352 void setCaptionDisplayMode(const String&, ExceptionCode&);
355 PassRefPtr<TimeRanges> createTimeRanges(Float32Array* startTimes, Float32Array* endTimes);
356 double closestTimeToTimeRanges(double time, TimeRanges*);
359 Ref<ClientRect> selectionBounds(ExceptionCode&);
361 #if ENABLE(VIBRATION)
365 bool isPluginUnavailabilityIndicatorObscured(Element*, ExceptionCode&);
366 bool isPluginSnapshotted(Element*, ExceptionCode&);
368 #if ENABLE(MEDIA_SOURCE)
369 WEBCORE_TESTSUPPORT_EXPORT void initializeMockMediaSource();
370 Vector<String> bufferedSamplesForTrackID(SourceBuffer*, const AtomicString&);
374 void beginMediaSessionInterruption();
375 void endMediaSessionInterruption(const String&);
376 void applicationWillEnterForeground() const;
377 void applicationWillEnterBackground() const;
378 void setMediaSessionRestrictions(const String& mediaType, const String& restrictions, ExceptionCode&);
379 void setMediaElementRestrictions(HTMLMediaElement*, const String& restrictions, ExceptionCode&);
380 void postRemoteControlCommand(const String&, ExceptionCode&);
381 bool elementIsBlockingDisplaySleep(Element*) const;
384 #if ENABLE(WEB_AUDIO)
385 void setAudioContextRestrictions(AudioContext*, const String& restrictions, ExceptionCode&);
388 void simulateSystemSleep() const;
389 void simulateSystemWake() const;
391 void installMockPageOverlay(const String& overlayType, ExceptionCode&);
392 String pageOverlayLayerTreeAsText(ExceptionCode&) const;
394 void setPageMuted(bool);
395 bool isPagePlayingAudio();
397 RefPtr<File> createFile(const String&);
398 void queueMicroTask(int);
399 bool testPreloaderSettingViewport();
401 #if ENABLE(CONTENT_FILTERING)
402 MockContentFilterSettings& mockContentFilterSettings();
405 #if ENABLE(CSS_SCROLL_SNAP)
406 String scrollSnapOffsets(Element*, ExceptionCode&);
410 explicit Internals(Document*);
411 Document* contextDocument() const;
412 Frame* frame() const;
414 RenderedDocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionCode&);
416 RefPtr<DOMWindow> m_frontendWindow;
417 std::unique_ptr<InspectorFrontendClientDummy> m_frontendClient;
418 std::unique_ptr<InspectorFrontendChannelDummy> m_frontendChannel;
421 } // namespace WebCore