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* ensureShadowRoot(Element* host, ExceptionState&);
99 ShadowRoot* shadowRoot(Element* host, ExceptionState&);
100 ShadowRoot* youngestShadowRoot(Element* host, ExceptionState&);
101 ShadowRoot* oldestShadowRoot(Element* host, ExceptionState&);
102 ShadowRoot* youngerShadowRoot(Node* shadow, ExceptionState&);
103 ShadowRoot* olderShadowRoot(Node* shadow, ExceptionState&);
104 String shadowRootType(const Node*, ExceptionState&) const;
105 bool hasShadowInsertionPoint(const Node*, ExceptionState&) const;
106 bool hasContentElement(const Node*, ExceptionState&) const;
107 size_t countElementShadow(const Node*, ExceptionState&) const;
108 const AtomicString& shadowPseudoId(Element*, ExceptionState&);
109 void setShadowPseudoId(Element*, const AtomicString&, ExceptionState&);
111 // CSS Animation / Transition testing.
112 unsigned numberOfActiveAnimations() const;
113 void pauseAnimations(double pauseTime, ExceptionState&);
115 PassRefPtr<Element> createContentElement(ExceptionState&);
116 bool isValidContentSelect(Element* insertionPoint, ExceptionState&);
117 Node* treeScopeRootNode(Node*, ExceptionState&);
118 Node* parentTreeScope(Node*, ExceptionState&);
119 bool hasSelectorForIdInShadow(Element* host, const AtomicString& idValue, ExceptionState&);
120 bool hasSelectorForClassInShadow(Element* host, const AtomicString& className, ExceptionState&);
121 bool hasSelectorForAttributeInShadow(Element* host, const AtomicString& attributeName, ExceptionState&);
122 bool hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState&);
123 unsigned short compareTreeScopePosition(const Node*, const Node*, ExceptionState&) const;
125 // FIXME: Rename these functions if walker is prefered.
126 Node* nextSiblingByWalker(Node*, ExceptionState&);
127 Node* firstChildByWalker(Node*, ExceptionState&);
128 Node* lastChildByWalker(Node*, ExceptionState&);
129 Node* nextNodeByWalker(Node*, ExceptionState&);
130 Node* previousNodeByWalker(Node*, ExceptionState&);
132 unsigned updateStyleAndReturnAffectedElementCount(ExceptionState&) const;
133 unsigned needsLayoutCount(ExceptionState&) const;
135 String visiblePlaceholder(Element*);
136 void selectColorInColorChooser(Element*, const String& colorValue);
137 bool hasAutofocusRequest(Document*);
138 bool hasAutofocusRequest();
139 Vector<String> formControlStateOfHistoryItem(ExceptionState&);
140 void setFormControlStateOfHistoryItem(const Vector<String>&, ExceptionState&);
141 void setEnableMockPagePopup(bool, ExceptionState&);
142 PassRefPtr<PagePopupController> pagePopupController();
144 PassRefPtr<ClientRect> unscaledViewportRect(ExceptionState&);
146 PassRefPtr<ClientRect> absoluteCaretBounds(ExceptionState&);
148 PassRefPtr<ClientRect> boundingBox(Element*, ExceptionState&);
150 PassRefPtr<ClientRectList> inspectorHighlightRects(Document*, ExceptionState&);
152 unsigned markerCountForNode(Node*, const String&, ExceptionState&);
153 unsigned activeMarkerCountForNode(Node*, ExceptionState&);
154 PassRefPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
155 String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
156 void addTextMatchMarker(const Range*, bool isActive);
157 void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool, ExceptionState&);
159 void setScrollViewPosition(Document*, long x, long y, ExceptionState&);
160 void setPagination(Document* document, const String& mode, int gap, ExceptionState& ec) { setPagination(document, mode, gap, 0, ec); }
161 void setPagination(Document*, const String& mode, int gap, int pageLength, ExceptionState&);
162 String viewportAsText(Document*, float devicePixelRatio, int availableWidth, int availableHeight, ExceptionState&);
164 bool wasLastChangeUserEdit(Element* textField, ExceptionState&);
165 bool elementShouldAutoComplete(Element* inputElement, ExceptionState&);
166 String suggestedValue(Element*, ExceptionState&);
167 void setSuggestedValue(Element*, const String&, ExceptionState&);
168 void setEditingValue(Element* inputElement, const String&, ExceptionState&);
169 void setAutofilled(Element*, bool enabled, ExceptionState&);
170 void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionState&);
172 void paintControlTints(Document*, ExceptionState&);
174 PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionState&);
175 unsigned locationFromRange(Element* scope, const Range*, ExceptionState&);
176 unsigned lengthFromRange(Element* scope, const Range*, ExceptionState&);
177 String rangeAsText(const Range*, ExceptionState&);
179 PassRefPtr<DOMPoint> touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
180 Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
181 PassRefPtr<DOMPoint> touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
182 Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
183 PassRefPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionState&);
185 int lastSpellCheckRequestSequence(Document*, ExceptionState&);
186 int lastSpellCheckProcessedSequence(Document*, ExceptionState&);
188 Vector<AtomicString> userPreferredLanguages() const;
189 void setUserPreferredLanguages(const Vector<String>&);
191 unsigned wheelEventHandlerCount(Document*, ExceptionState&);
192 unsigned touchEventHandlerCount(Document*, ExceptionState&);
193 PassRefPtr<LayerRectList> touchEventTargetLayerRects(Document*, ExceptionState&);
195 // This is used to test rect based hit testing like what's done on touch screens.
196 PassRefPtr<NodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding,
197 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionState&) const;
199 void emitInspectorDidBeginFrame(int frameId = 0);
200 void emitInspectorDidCancelFrame();
202 bool hasSpellingMarker(Document*, int from, int length, ExceptionState&);
203 bool hasGrammarMarker(Document*, int from, int length, ExceptionState&);
204 void setContinuousSpellCheckingEnabled(bool enabled, ExceptionState&);
206 bool isOverwriteModeEnabled(Document*, ExceptionState&);
207 void toggleOverwriteModeEnabled(Document*, ExceptionState&);
209 unsigned numberOfScrollableAreas(Document*, ExceptionState&);
211 bool isPageBoxVisible(Document*, int pageNumber, ExceptionState&);
213 static const char* internalsId;
215 InternalSettings* settings() const;
216 InternalRuntimeFlags* runtimeFlags() const;
217 InternalProfilers* profilers();
218 unsigned workerThreadCount() const;
220 void setDeviceProximity(Document*, const String& eventType, double value, double min, double max, ExceptionState&);
222 String layerTreeAsText(Document*, unsigned flags, ExceptionState&) const;
223 String layerTreeAsText(Document*, ExceptionState&) const;
224 String elementLayerTreeAsText(Element*, unsigned flags, ExceptionState&) const;
225 String elementLayerTreeAsText(Element*, ExceptionState&) const;
227 PassRefPtr<NodeList> paintOrderListBeforePromote(Element*, ExceptionState&);
228 PassRefPtr<NodeList> paintOrderListAfterPromote(Element*, ExceptionState&);
230 bool scrollsWithRespectTo(Element*, Element*, ExceptionState&);
231 bool isUnclippedDescendant(Element*, ExceptionState&);
232 bool needsCompositedScrolling(Element*, ExceptionState&);
234 void setNeedsCompositedScrolling(Element*, unsigned value, ExceptionState&);
236 String repaintRectsAsText(Document*, ExceptionState&) const;
237 PassRefPtr<ClientRectList> repaintRects(Element*, ExceptionState&) const;
239 String scrollingStateTreeAsText(Document*, ExceptionState&) const;
240 String mainThreadScrollingReasons(Document*, ExceptionState&) const;
241 PassRefPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionState&) const;
243 void garbageCollectDocumentResources(Document*, ExceptionState&) const;
244 void evictAllResources() const;
246 void allowRoundingHacks() const;
248 unsigned numberOfLiveNodes() const;
249 unsigned numberOfLiveDocuments() const;
250 String dumpRefCountedInstanceCounts() const;
251 Vector<String> consoleMessageArgumentCounts(Document*) const;
252 PassRefPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
253 void closeDummyInspectorFrontend();
254 Vector<unsigned long> setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes);
255 void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState&);
257 String counterValue(Element*);
259 int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
260 Vector<String> shortcutIconURLs(Document*) const;
261 Vector<String> allIconURLs(Document*) const;
263 int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
264 String pageProperty(String, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
265 String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
267 void setDeviceScaleFactor(float scaleFactor, ExceptionState&);
269 void setIsCursorVisible(Document*, bool, ExceptionState&);
271 void webkitWillEnterFullScreenForElement(Document*, Element*);
272 void webkitDidEnterFullScreenForElement(Document*, Element*);
273 void webkitWillExitFullScreenForElement(Document*, Element*);
274 void webkitDidExitFullScreenForElement(Document*, Element*);
276 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
277 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
279 PassRefPtr<MallocStatistics> mallocStatistics() const;
280 PassRefPtr<TypeConversions> typeConversions() const;
282 Vector<String> getReferencedFilePaths() const;
284 void startTrackingRepaints(Document*, ExceptionState&);
285 void stopTrackingRepaints(Document*, ExceptionState&);
286 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState&);
287 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionState&);
289 PassRefPtr<ClientRectList> draggableRegions(Document*, ExceptionState&);
290 PassRefPtr<ClientRectList> nonDraggableRegions(Document*, ExceptionState&);
292 PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
293 PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const;
295 String getCurrentCursorInfo(Document*, ExceptionState&);
297 String markerTextForListItem(Element*, ExceptionState&);
299 void forceReload(bool endToEnd);
301 String getImageSourceURL(Element*, ExceptionState&);
303 bool isSelectPopupVisible(Node*);
305 PassRefPtr<ClientRect> selectionBounds(ExceptionState&);
306 String baseURL(Document*, ExceptionState&);
308 bool loseSharedGraphicsContext3D();
310 void forceCompositingUpdate(Document*, ExceptionState&);
312 void setZoomFactor(float);
314 ScriptPromise addOneToPromise(ExecutionContext*, ScriptPromise);
317 explicit Internals(Document*);
318 Document* contextDocument() const;
319 Frame* frame() const;
320 Vector<String> iconURLs(Document*, int iconTypesMask) const;
321 PassRefPtr<ClientRectList> annotatedRegions(Document*, bool draggable, ExceptionState&);
323 DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionState&);
324 RefPtr<DOMWindow> m_frontendWindow;
325 OwnPtr<InspectorFrontendChannelDummy> m_frontendChannel;
326 RefPtr<InternalRuntimeFlags> m_runtimeFlags;
327 RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
328 RefPtr<InternalProfilers> m_profilers;
331 } // namespace WebCore