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&);
117 // Spatial Navigation testing.
118 unsigned lastSpatialNavigationCandidateCount(ExceptionCode&) const;
120 // CSS Animation testing.
121 unsigned numberOfActiveAnimations() const;
122 bool animationsAreSuspended(ExceptionCode&) const;
123 void suspendAnimations(ExceptionCode&) const;
124 void resumeAnimations(ExceptionCode&) const;
125 bool pauseAnimationAtTimeOnElement(const String& animationName, double pauseTime, Element*, ExceptionCode&);
126 bool pauseAnimationAtTimeOnPseudoElement(const String& animationName, double pauseTime, Element*, const String& pseudoId, ExceptionCode&);
128 // CSS Transition testing.
129 bool pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element*, ExceptionCode&);
130 bool pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element*, const String& pseudoId, ExceptionCode&);
132 Node* treeScopeRootNode(Node*, ExceptionCode&);
133 Node* parentTreeScope(Node*, ExceptionCode&);
135 bool attached(Node*, ExceptionCode&);
137 String visiblePlaceholder(Element*);
138 #if ENABLE(INPUT_TYPE_COLOR)
139 void selectColorInColorChooser(Element*, const String& colorValue);
141 Vector<String> formControlStateOfPreviousHistoryItem(ExceptionCode&);
142 void setFormControlStateOfPreviousHistoryItem(const Vector<String>&, ExceptionCode&);
144 Ref<ClientRect> absoluteCaretBounds(ExceptionCode&);
146 Ref<ClientRect> boundingBox(Element*, ExceptionCode&);
148 Ref<ClientRectList> inspectorHighlightRects(ExceptionCode&);
149 String inspectorHighlightObject(ExceptionCode&);
151 unsigned markerCountForNode(Node*, const String&, ExceptionCode&);
152 PassRefPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionCode&);
153 String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionCode&);
154 void addTextMatchMarker(const Range*, bool isActive);
155 void setMarkedTextMatchesAreHighlighted(bool, ExceptionCode&);
157 void invalidateFontCache();
159 void setScrollViewPosition(long x, long y, ExceptionCode&);
160 void setViewBaseBackgroundColor(const String& colorValue, ExceptionCode&);
162 void setPagination(const String& mode, int gap, ExceptionCode& ec) { setPagination(mode, gap, 0, ec); }
163 void setPagination(const String& mode, int gap, int pageLength, ExceptionCode&);
164 String configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode&);
166 bool wasLastChangeUserEdit(Element* textField, ExceptionCode&);
167 bool elementShouldAutoComplete(Element* inputElement, ExceptionCode&);
168 void setEditingValue(Element* inputElement, const String&, ExceptionCode&);
169 void setAutofilled(Element*, bool enabled, ExceptionCode&);
170 void setShowAutoFillButton(Element*, bool enabled, ExceptionCode&);
171 void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionCode&);
173 void paintControlTints(ExceptionCode&);
175 PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionCode&);
176 unsigned locationFromRange(Element* scope, const Range*, ExceptionCode&);
177 unsigned lengthFromRange(Element* scope, const Range*, ExceptionCode&);
178 String rangeAsText(const Range*, ExceptionCode&);
179 PassRefPtr<Range> subrange(Range* range, int rangeLocation, int rangeLength, ExceptionCode&);
180 RefPtr<Range> rangeForDictionaryLookupAtLocation(int x, int y, ExceptionCode&);
182 void setDelegatesScrolling(bool enabled, ExceptionCode&);
184 int lastSpellCheckRequestSequence(ExceptionCode&);
185 int lastSpellCheckProcessedSequence(ExceptionCode&);
187 Vector<String> userPreferredLanguages() const;
188 void setUserPreferredLanguages(const Vector<String>&);
190 unsigned wheelEventHandlerCount(ExceptionCode&);
191 unsigned touchEventHandlerCount(ExceptionCode&);
193 PassRefPtr<NodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding,
194 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionCode&) const;
196 String parserMetaData(Deprecated::ScriptValue = Deprecated::ScriptValue());
198 void updateEditorUINowIfScheduled();
200 bool hasSpellingMarker(int from, int length, ExceptionCode&);
201 bool hasGrammarMarker(int from, int length, ExceptionCode&);
202 bool hasAutocorrectedMarker(int from, int length, ExceptionCode&);
203 void setContinuousSpellCheckingEnabled(bool enabled, ExceptionCode&);
204 void setAutomaticQuoteSubstitutionEnabled(bool enabled, ExceptionCode&);
205 void setAutomaticLinkDetectionEnabled(bool enabled, ExceptionCode&);
206 void setAutomaticDashSubstitutionEnabled(bool enabled, ExceptionCode&);
207 void setAutomaticTextReplacementEnabled(bool enabled, ExceptionCode&);
208 void setAutomaticSpellingCorrectionEnabled(bool enabled, ExceptionCode&);
210 bool isOverwriteModeEnabled(ExceptionCode&);
211 void toggleOverwriteModeEnabled(ExceptionCode&);
213 unsigned countMatchesForText(const String&, unsigned findOptions, const String& markMatches, ExceptionCode&);
215 unsigned numberOfScrollableAreas(ExceptionCode&);
217 bool isPageBoxVisible(int pageNumber, ExceptionCode&);
219 static const char* internalsId;
221 InternalSettings* settings() const;
222 unsigned workerThreadCount() const;
224 void setBatteryStatus(const String& eventType, bool charging, double chargingTime, double dischargingTime, double level, ExceptionCode&);
226 void setDeviceProximity(const String& eventType, double value, double min, double max, ExceptionCode&);
229 // Values need to be kept in sync with Internals.idl.
230 LAYER_TREE_INCLUDES_VISIBLE_RECTS = 1,
231 LAYER_TREE_INCLUDES_TILE_CACHES = 2,
232 LAYER_TREE_INCLUDES_REPAINT_RECTS = 4,
233 LAYER_TREE_INCLUDES_PAINTING_PHASES = 8,
234 LAYER_TREE_INCLUDES_CONTENT_LAYERS = 16
236 String layerTreeAsText(Document*, unsigned flags, ExceptionCode&) const;
237 String layerTreeAsText(Document*, ExceptionCode&) const;
238 String repaintRectsAsText(ExceptionCode&) const;
239 String scrollingStateTreeAsText(ExceptionCode&) const;
240 String mainThreadScrollingReasons(ExceptionCode&) const;
241 RefPtr<ClientRectList> nonFastScrollableRects(ExceptionCode&) const;
243 void garbageCollectDocumentResources(ExceptionCode&) const;
245 void allowRoundingHacks() const;
247 void insertAuthorCSS(const String&, ExceptionCode&) const;
248 void insertUserCSS(const String&, ExceptionCode&) const;
250 const ProfilesArray& consoleProfiles() const;
252 unsigned numberOfLiveNodes() const;
253 unsigned numberOfLiveDocuments() const;
255 Vector<String> consoleMessageArgumentCounts() const;
256 PassRefPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
257 void closeDummyInspectorFrontend();
258 void setJavaScriptProfilingEnabled(bool enabled, ExceptionCode&);
259 void setInspectorIsUnderTest(bool isUnderTest, ExceptionCode&);
261 String counterValue(Element*);
263 int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
264 Vector<String> shortcutIconURLs() const;
266 int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
267 String pageProperty(String, int, ExceptionCode& = ASSERT_NO_EXCEPTION) const;
268 String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionCode& = ASSERT_NO_EXCEPTION) const;
270 void setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode&);
271 void setPageZoomFactor(float zoomFactor, ExceptionCode&);
273 void setUseFixedLayout(bool useFixedLayout, ExceptionCode&);
274 void setFixedLayoutSize(int width, int height, ExceptionCode&);
276 void setHeaderHeight(float);
277 void setFooterHeight(float);
279 void setTopContentInset(float);
281 #if ENABLE(FULLSCREEN_API)
282 void webkitWillEnterFullScreenForElement(Element*);
283 void webkitDidEnterFullScreenForElement(Element*);
284 void webkitWillExitFullScreenForElement(Element*);
285 void webkitDidExitFullScreenForElement(Element*);
288 WEBCORE_TESTSUPPORT_EXPORT void setApplicationCacheOriginQuota(unsigned long long);
290 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
291 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
293 PassRefPtr<MallocStatistics> mallocStatistics() const;
294 PassRefPtr<TypeConversions> typeConversions() const;
295 PassRefPtr<MemoryInfo> memoryInfo() const;
297 Vector<String> getReferencedFilePaths() const;
299 void startTrackingRepaints(ExceptionCode&);
300 void stopTrackingRepaints(ExceptionCode&);
302 void startTrackingLayerFlushes(ExceptionCode&);
303 unsigned long layerFlushCount(ExceptionCode&);
305 void startTrackingStyleRecalcs(ExceptionCode&);
306 unsigned long styleRecalcCount(ExceptionCode&);
308 void startTrackingCompositingUpdates(ExceptionCode&);
309 unsigned long compositingUpdateCount(ExceptionCode&);
311 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionCode&);
312 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionCode&);
314 PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
315 PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const;
317 void setUsesOverlayScrollbars(bool enabled);
319 String getCurrentCursorInfo(ExceptionCode&);
321 String markerTextForListItem(Element*, ExceptionCode&);
323 String toolTipFromElement(Element*, ExceptionCode&) const;
325 void forceReload(bool endToEnd);
327 #if ENABLE(ENCRYPTED_MEDIA_V2)
328 void initializeMockCDM();
331 #if ENABLE(SPEECH_SYNTHESIS)
332 void enableMockSpeechSynthesizer();
335 #if ENABLE(MEDIA_STREAM)
336 void enableMockRTCPeerConnectionHandler();
339 String getImageSourceURL(Element*, ExceptionCode&);
342 void simulateAudioInterruption(Node*);
343 bool mediaElementHasCharacteristic(Node*, const String&, ExceptionCode&);
346 bool isSelectPopupVisible(Node*);
348 String captionsStyleSheetOverride(ExceptionCode&);
349 void setCaptionsStyleSheetOverride(const String&, ExceptionCode&);
350 void setPrimaryAudioTrackLanguageOverride(const String&, ExceptionCode&);
351 void setCaptionDisplayMode(const String&, ExceptionCode&);
354 PassRefPtr<TimeRanges> createTimeRanges(Float32Array* startTimes, Float32Array* endTimes);
355 double closestTimeToTimeRanges(double time, TimeRanges*);
358 Ref<ClientRect> selectionBounds(ExceptionCode&);
360 #if ENABLE(VIBRATION)
364 bool isPluginUnavailabilityIndicatorObscured(Element*, ExceptionCode&);
365 bool isPluginSnapshotted(Element*, ExceptionCode&);
367 #if ENABLE(MEDIA_SOURCE)
368 WEBCORE_TESTSUPPORT_EXPORT void initializeMockMediaSource();
369 Vector<String> bufferedSamplesForTrackID(SourceBuffer*, const AtomicString&);
373 void beginMediaSessionInterruption();
374 void endMediaSessionInterruption(const String&);
375 void applicationWillEnterForeground() const;
376 void applicationWillEnterBackground() const;
377 void setMediaSessionRestrictions(const String& mediaType, const String& restrictions, ExceptionCode&);
378 void setMediaElementRestrictions(HTMLMediaElement*, const String& restrictions, ExceptionCode&);
379 void postRemoteControlCommand(const String&, ExceptionCode&);
380 bool elementIsBlockingDisplaySleep(Element*) const;
383 #if ENABLE(WEB_AUDIO)
384 void setAudioContextRestrictions(AudioContext*, const String& restrictions, ExceptionCode&);
387 void simulateSystemSleep() const;
388 void simulateSystemWake() const;
390 void installMockPageOverlay(const String& overlayType, ExceptionCode&);
391 String pageOverlayLayerTreeAsText(ExceptionCode&) const;
393 void setPageMuted(bool);
394 bool isPagePlayingAudio();
396 RefPtr<File> createFile(const String&);
397 void queueMicroTask(int);
398 bool testPreloaderSettingViewport();
400 #if ENABLE(CONTENT_FILTERING)
401 MockContentFilterSettings& mockContentFilterSettings();
404 #if ENABLE(CSS_SCROLL_SNAP)
405 String scrollSnapOffsets(Element*, ExceptionCode&);
409 explicit Internals(Document*);
410 Document* contextDocument() const;
411 Frame* frame() const;
413 RenderedDocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionCode&);
415 RefPtr<DOMWindow> m_frontendWindow;
416 std::unique_ptr<InspectorFrontendClientDummy> m_frontendClient;
417 std::unique_ptr<InspectorFrontendChannelDummy> m_frontendChannel;
420 } // namespace WebCore