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 "platform/heap/Handle.h"
38 #include "wtf/ArrayBuffer.h"
39 #include "wtf/PassRefPtr.h"
40 #include "wtf/RefCounted.h"
41 #include "wtf/text/WTFString.h"
54 class ExecutionContext;
56 class HTMLMediaElement;
57 class InternalProfilers;
58 class InternalRuntimeFlags;
59 class InternalSettings;
62 class MallocStatistics;
65 class PagePopupController;
67 class SerializedScriptValue;
69 class TypeConversions;
71 class Internals FINAL : public RefCountedWillBeGarbageCollectedFinalized<Internals>, public ContextLifecycleObserver {
73 static PassRefPtrWillBeRawPtr<Internals> create(Document*);
76 static void resetToConsistentState(Page*);
78 String elementRenderTreeAsText(Element*, ExceptionState&);
80 String address(Node*);
82 PassRefPtrWillBeRawPtr<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 PassRefPtrWillBeRawPtr<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 PassRefPtrWillBeRawPtr<PagePopupController> pagePopupController();
141 PassRefPtrWillBeRawPtr<ClientRect> unscaledViewportRect(ExceptionState&);
143 PassRefPtrWillBeRawPtr<ClientRect> absoluteCaretBounds(ExceptionState&);
145 PassRefPtrWillBeRawPtr<ClientRect> boundingBox(Element*, ExceptionState&);
147 unsigned markerCountForNode(Node*, const String&, ExceptionState&);
148 unsigned activeMarkerCountForNode(Node*, ExceptionState&);
149 PassRefPtrWillBeRawPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
150 String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
151 void addTextMatchMarker(const Range*, bool isActive);
152 void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool, ExceptionState&);
153 void setMarkedTextMatchesAreHighlighted(Document*, bool, ExceptionState&);
155 void setScrollViewPosition(Document*, long x, long y, ExceptionState&);
156 String viewportAsText(Document*, float devicePixelRatio, int availableWidth, int availableHeight, ExceptionState&);
158 bool wasLastChangeUserEdit(Element* textField, ExceptionState&);
159 bool elementShouldAutoComplete(Element* inputElement, ExceptionState&);
160 String suggestedValue(Element*, ExceptionState&);
161 void setSuggestedValue(Element*, const String&, ExceptionState&);
162 void setEditingValue(Element* inputElement, const String&, ExceptionState&);
163 void setAutofilled(Element*, bool enabled, ExceptionState&);
164 void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionState&);
166 PassRefPtrWillBeRawPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionState&);
167 unsigned locationFromRange(Element* scope, const Range*, ExceptionState&);
168 unsigned lengthFromRange(Element* scope, const Range*, ExceptionState&);
169 String rangeAsText(const Range*, ExceptionState&);
171 PassRefPtrWillBeRawPtr<DOMPoint> touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
172 Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
173 PassRefPtrWillBeRawPtr<DOMPoint> touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
174 Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
175 PassRefPtrWillBeRawPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionState&);
177 int lastSpellCheckRequestSequence(Document*, ExceptionState&);
178 int lastSpellCheckProcessedSequence(Document*, ExceptionState&);
180 Vector<AtomicString> userPreferredLanguages() const;
181 void setUserPreferredLanguages(const Vector<String>&);
183 unsigned activeDOMObjectCount(Document*, ExceptionState&);
184 unsigned wheelEventHandlerCount(Document*, ExceptionState&);
185 unsigned scrollEventHandlerCount(Document*, ExceptionState&);
186 unsigned touchEventHandlerCount(Document*, ExceptionState&);
187 PassRefPtrWillBeRawPtr<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&);
227 void setNeedsCompositedScrolling(Element*, unsigned value, ExceptionState&);
229 String repaintRectsAsText(Document*, ExceptionState&) const;
230 PassRefPtrWillBeRawPtr<ClientRectList> repaintRects(Element*, ExceptionState&) const;
232 String scrollingStateTreeAsText(Document*, ExceptionState&) const;
233 String mainThreadScrollingReasons(Document*, ExceptionState&) const;
234 PassRefPtrWillBeRawPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionState&) const;
236 void garbageCollectDocumentResources(Document*, ExceptionState&) const;
237 void evictAllResources() const;
239 void allowRoundingHacks() const;
241 unsigned numberOfLiveNodes() const;
242 unsigned numberOfLiveDocuments() const;
243 String dumpRefCountedInstanceCounts() const;
244 Vector<String> consoleMessageArgumentCounts(Document*) const;
245 PassRefPtrWillBeRawPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
246 void closeDummyInspectorFrontend();
247 Vector<unsigned long> setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes);
248 void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState&);
250 String counterValue(Element*);
252 int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
253 Vector<String> shortcutIconURLs(Document*) const;
254 Vector<String> allIconURLs(Document*) const;
256 int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
257 String pageProperty(String, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
258 String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
260 void setDeviceScaleFactor(float scaleFactor, ExceptionState&);
262 void setIsCursorVisible(Document*, bool, ExceptionState&);
264 void webkitWillEnterFullScreenForElement(Document*, Element*);
265 void webkitDidEnterFullScreenForElement(Document*, Element*);
266 void webkitWillExitFullScreenForElement(Document*, Element*);
267 void webkitDidExitFullScreenForElement(Document*, Element*);
269 void mediaPlayerRequestFullscreen(HTMLMediaElement*);
271 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
272 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
274 PassRefPtrWillBeRawPtr<MallocStatistics> mallocStatistics() const;
275 PassRefPtrWillBeRawPtr<TypeConversions> typeConversions() const;
277 Vector<String> getReferencedFilePaths() const;
279 void startTrackingRepaints(Document*, ExceptionState&);
280 void stopTrackingRepaints(Document*, ExceptionState&);
281 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState&);
282 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionState&);
284 PassRefPtrWillBeRawPtr<ClientRectList> draggableRegions(Document*, ExceptionState&);
285 PassRefPtrWillBeRawPtr<ClientRectList> nonDraggableRegions(Document*, ExceptionState&);
287 PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
288 PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const;
290 String getCurrentCursorInfo(Document*, ExceptionState&);
292 String markerTextForListItem(Element*, ExceptionState&);
294 void forceReload(bool endToEnd);
296 String getImageSourceURL(Element*, ExceptionState&);
298 bool isSelectPopupVisible(Node*);
300 PassRefPtrWillBeRawPtr<ClientRect> selectionBounds(ExceptionState&);
301 String baseURL(Document*, ExceptionState&);
303 bool loseSharedGraphicsContext3D();
305 void forceCompositingUpdate(Document*, ExceptionState&);
307 bool isCompositorFramePending(Document*, ExceptionState&);
309 void setZoomFactor(float);
311 void setShouldRevealPassword(Element*, bool, ExceptionState&);
313 ScriptPromise createPromise(ScriptState*);
314 ScriptPromise createResolvedPromise(ScriptState*, ScriptValue);
315 ScriptPromise createRejectedPromise(ScriptState*, ScriptValue);
316 ScriptPromise addOneToPromise(ExecutionContext*, ScriptPromise);
318 void trace(Visitor*);
320 void setValueForUser(Element*, const String&);
322 String textSurroundingNode(Node*, int x, int y, unsigned long maxLength);
325 explicit Internals(Document*);
326 Document* contextDocument() const;
327 LocalFrame* frame() const;
328 Vector<String> iconURLs(Document*, int iconTypesMask) const;
329 PassRefPtrWillBeRawPtr<ClientRectList> annotatedRegions(Document*, bool draggable, ExceptionState&);
331 DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionState&);
332 RefPtrWillBeMember<InternalRuntimeFlags> m_runtimeFlags;
333 RefPtrWillBeMember<InternalProfilers> m_profilers;
336 } // namespace WebCore