2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 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 "bindings/v8/ExceptionStatePlaceholder.h"
31 #include "bindings/v8/ScriptPromise.h"
32 #include "bindings/v8/ScriptValue.h"
33 #include "core/css/CSSComputedStyleDeclaration.h"
34 #include "core/dom/ContextLifecycleObserver.h"
35 #include "core/dom/NodeList.h"
36 #include "core/page/scrolling/ScrollingCoordinator.h"
37 #include "wtf/ArrayBuffer.h"
38 #include "wtf/PassRefPtr.h"
39 #include "wtf/RefCounted.h"
40 #include "wtf/text/WTFString.h"
55 class InspectorFrontendChannelDummy;
56 class InternalProfilers;
57 class InternalRuntimeFlags;
58 class InternalSettings;
60 class MallocStatistics;
63 class PagePopupController;
65 class ExecutionContext;
66 class SerializedScriptValue;
68 class TypeConversions;
70 class Internals FINAL : public RefCounted<Internals>
71 , public ContextLifecycleObserver {
73 static PassRefPtr<Internals> create(Document*);
76 static void resetToConsistentState(Page*);
78 String elementRenderTreeAsText(Element*, ExceptionState&);
80 String address(Node*);
82 PassRefPtr<GCObservation> observeGC(ScriptValue);
84 bool isPreloaded(const String& url);
85 bool isLoadingFromMemoryCache(const String& url);
89 void setStyleResolverStatsEnabled(bool);
90 String styleResolverStatsReport(ExceptionState&) const;
91 String styleResolverStatsTotalsReport(ExceptionState&) const;
93 bool isSharingStyle(Element*, Element*, ExceptionState&) const;
95 size_t numberOfScopedHTMLStyleChildren(const Node*, ExceptionState&) const;
96 PassRefPtr<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Node*, ExceptionState&) const;
98 ShadowRoot* shadowRoot(Element* host, ExceptionState&);
99 ShadowRoot* youngestShadowRoot(Element* host, ExceptionState&);
100 ShadowRoot* oldestShadowRoot(Element* host, ExceptionState&);
101 ShadowRoot* youngerShadowRoot(Node* shadow, ExceptionState&);
102 String shadowRootType(const Node*, ExceptionState&) const;
103 bool hasShadowInsertionPoint(const Node*, ExceptionState&) const;
104 bool hasContentElement(const Node*, ExceptionState&) const;
105 size_t countElementShadow(const Node*, ExceptionState&) const;
106 const AtomicString& shadowPseudoId(Element*, ExceptionState&);
107 void setShadowPseudoId(Element*, const AtomicString&, ExceptionState&);
109 // CSS Animation / Transition testing.
110 unsigned numberOfActiveAnimations() const;
111 void pauseAnimations(double pauseTime, ExceptionState&);
113 bool isValidContentSelect(Element* insertionPoint, ExceptionState&);
114 Node* treeScopeRootNode(Node*, ExceptionState&);
115 Node* parentTreeScope(Node*, ExceptionState&);
116 bool hasSelectorForIdInShadow(Element* host, const AtomicString& idValue, ExceptionState&);
117 bool hasSelectorForClassInShadow(Element* host, const AtomicString& className, ExceptionState&);
118 bool hasSelectorForAttributeInShadow(Element* host, const AtomicString& attributeName, ExceptionState&);
119 bool hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState&);
120 unsigned short compareTreeScopePosition(const Node*, const Node*, ExceptionState&) const;
122 // FIXME: Rename these functions if walker is prefered.
123 Node* nextSiblingByWalker(Node*, ExceptionState&);
124 Node* firstChildByWalker(Node*, ExceptionState&);
125 Node* lastChildByWalker(Node*, ExceptionState&);
126 Node* nextNodeByWalker(Node*, ExceptionState&);
127 Node* previousNodeByWalker(Node*, ExceptionState&);
129 unsigned updateStyleAndReturnAffectedElementCount(ExceptionState&) const;
130 unsigned needsLayoutCount(ExceptionState&) const;
132 String visiblePlaceholder(Element*);
133 void selectColorInColorChooser(Element*, const String& colorValue);
134 bool hasAutofocusRequest(Document*);
135 bool hasAutofocusRequest();
136 Vector<String> formControlStateOfHistoryItem(ExceptionState&);
137 void setFormControlStateOfHistoryItem(const Vector<String>&, ExceptionState&);
138 void setEnableMockPagePopup(bool, ExceptionState&);
139 PassRefPtr<PagePopupController> pagePopupController();
141 PassRefPtr<ClientRect> unscaledViewportRect(ExceptionState&);
143 PassRefPtr<ClientRect> absoluteCaretBounds(ExceptionState&);
145 PassRefPtr<ClientRect> boundingBox(Element*, ExceptionState&);
147 PassRefPtr<ClientRectList> inspectorHighlightRects(Document*, ExceptionState&);
149 unsigned markerCountForNode(Node*, const String&, ExceptionState&);
150 unsigned activeMarkerCountForNode(Node*, ExceptionState&);
151 PassRefPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
152 String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
153 void addTextMatchMarker(const Range*, bool isActive);
154 void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool, ExceptionState&);
155 void setMarkedTextMatchesAreHighlighted(Document*, bool, ExceptionState&);
157 void setScrollViewPosition(Document*, long x, long y, ExceptionState&);
158 String viewportAsText(Document*, float devicePixelRatio, int availableWidth, int availableHeight, ExceptionState&);
160 bool wasLastChangeUserEdit(Element* textField, ExceptionState&);
161 bool elementShouldAutoComplete(Element* inputElement, ExceptionState&);
162 String suggestedValue(Element*, ExceptionState&);
163 void setSuggestedValue(Element*, const String&, ExceptionState&);
164 void setEditingValue(Element* inputElement, const String&, ExceptionState&);
165 void setAutofilled(Element*, bool enabled, ExceptionState&);
166 void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionState&);
168 PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionState&);
169 unsigned locationFromRange(Element* scope, const Range*, ExceptionState&);
170 unsigned lengthFromRange(Element* scope, const Range*, ExceptionState&);
171 String rangeAsText(const Range*, ExceptionState&);
173 PassRefPtr<DOMPoint> touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
174 Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
175 PassRefPtr<DOMPoint> touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
176 Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
177 PassRefPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionState&);
179 int lastSpellCheckRequestSequence(Document*, ExceptionState&);
180 int lastSpellCheckProcessedSequence(Document*, ExceptionState&);
182 Vector<AtomicString> userPreferredLanguages() const;
183 void setUserPreferredLanguages(const Vector<String>&);
185 unsigned wheelEventHandlerCount(Document*, ExceptionState&);
186 unsigned touchEventHandlerCount(Document*, ExceptionState&);
187 PassRefPtr<LayerRectList> touchEventTargetLayerRects(Document*, ExceptionState&);
189 // This is used to test rect based hit testing like what's done on touch screens.
190 PassRefPtr<NodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding,
191 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionState&) const;
193 void emitInspectorDidBeginFrame(int frameId = 0);
194 void emitInspectorDidCancelFrame();
196 bool hasSpellingMarker(Document*, int from, int length, ExceptionState&);
197 bool hasGrammarMarker(Document*, int from, int length, ExceptionState&);
198 void setContinuousSpellCheckingEnabled(bool enabled, ExceptionState&);
200 bool isOverwriteModeEnabled(Document*, ExceptionState&);
201 void toggleOverwriteModeEnabled(Document*, ExceptionState&);
203 unsigned numberOfScrollableAreas(Document*, ExceptionState&);
205 bool isPageBoxVisible(Document*, int pageNumber, ExceptionState&);
207 static const char* internalsId;
209 InternalSettings* settings() const;
210 InternalRuntimeFlags* runtimeFlags() const;
211 InternalProfilers* profilers();
212 unsigned workerThreadCount() const;
214 void setDeviceProximity(Document*, const String& eventType, double value, double min, double max, ExceptionState&);
216 String layerTreeAsText(Document*, unsigned flags, ExceptionState&) const;
217 String layerTreeAsText(Document*, ExceptionState&) const;
218 String elementLayerTreeAsText(Element*, unsigned flags, ExceptionState&) const;
219 String elementLayerTreeAsText(Element*, ExceptionState&) const;
221 PassRefPtr<NodeList> paintOrderListBeforePromote(Element*, ExceptionState&);
222 PassRefPtr<NodeList> paintOrderListAfterPromote(Element*, ExceptionState&);
224 bool scrollsWithRespectTo(Element*, Element*, ExceptionState&);
225 bool isUnclippedDescendant(Element*, ExceptionState&);
226 bool needsCompositedScrolling(Element*, ExceptionState&);
228 void setNeedsCompositedScrolling(Element*, unsigned value, ExceptionState&);
230 String repaintRectsAsText(Document*, ExceptionState&) const;
231 PassRefPtr<ClientRectList> repaintRects(Element*, ExceptionState&) const;
233 String scrollingStateTreeAsText(Document*, ExceptionState&) const;
234 String mainThreadScrollingReasons(Document*, ExceptionState&) const;
235 PassRefPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionState&) const;
237 void garbageCollectDocumentResources(Document*, ExceptionState&) const;
238 void evictAllResources() const;
240 void allowRoundingHacks() const;
242 unsigned numberOfLiveNodes() const;
243 unsigned numberOfLiveDocuments() const;
244 String dumpRefCountedInstanceCounts() const;
245 Vector<String> consoleMessageArgumentCounts(Document*) const;
246 PassRefPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
247 void closeDummyInspectorFrontend();
248 Vector<unsigned long> setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes);
249 void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState&);
251 String counterValue(Element*);
253 int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
254 Vector<String> shortcutIconURLs(Document*) const;
255 Vector<String> allIconURLs(Document*) const;
257 int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
258 String pageProperty(String, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
259 String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
261 void setDeviceScaleFactor(float scaleFactor, ExceptionState&);
263 void setIsCursorVisible(Document*, bool, ExceptionState&);
265 void webkitWillEnterFullScreenForElement(Document*, Element*);
266 void webkitDidEnterFullScreenForElement(Document*, Element*);
267 void webkitWillExitFullScreenForElement(Document*, Element*);
268 void webkitDidExitFullScreenForElement(Document*, Element*);
270 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
271 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
273 PassRefPtr<MallocStatistics> mallocStatistics() const;
274 PassRefPtr<TypeConversions> typeConversions() const;
276 Vector<String> getReferencedFilePaths() const;
278 void startTrackingRepaints(Document*, ExceptionState&);
279 void stopTrackingRepaints(Document*, ExceptionState&);
280 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState&);
281 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionState&);
283 PassRefPtr<ClientRectList> draggableRegions(Document*, ExceptionState&);
284 PassRefPtr<ClientRectList> nonDraggableRegions(Document*, ExceptionState&);
286 PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
287 PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const;
289 String getCurrentCursorInfo(Document*, ExceptionState&);
291 String markerTextForListItem(Element*, ExceptionState&);
293 void forceReload(bool endToEnd);
295 String getImageSourceURL(Element*, ExceptionState&);
297 bool isSelectPopupVisible(Node*);
299 PassRefPtr<ClientRect> selectionBounds(ExceptionState&);
300 String baseURL(Document*, ExceptionState&);
302 bool loseSharedGraphicsContext3D();
304 void forceCompositingUpdate(Document*, ExceptionState&);
306 bool isCompositorFramePending(Document*, ExceptionState&);
308 void setZoomFactor(float);
310 void setShouldRevealPassword(Element*, bool, ExceptionState&);
312 ScriptPromise addOneToPromise(ExecutionContext*, ScriptPromise);
315 explicit Internals(Document*);
316 Document* contextDocument() const;
317 Frame* frame() const;
318 Vector<String> iconURLs(Document*, int iconTypesMask) const;
319 PassRefPtr<ClientRectList> annotatedRegions(Document*, bool draggable, ExceptionState&);
321 DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionState&);
322 RefPtr<DOMWindow> m_frontendWindow;
323 OwnPtr<InspectorFrontendChannelDummy> m_frontendChannel;
324 RefPtr<InternalRuntimeFlags> m_runtimeFlags;
325 RefPtr<InternalProfilers> m_profilers;
328 } // namespace WebCore