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/core/v8/ExceptionStatePlaceholder.h"
31 #include "bindings/core/v8/ScriptPromise.h"
32 #include "bindings/core/v8/ScriptValue.h"
33 #include "bindings/core/v8/ScriptWrappable.h"
34 #include "core/css/CSSComputedStyleDeclaration.h"
35 #include "core/dom/ContextLifecycleObserver.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"
45 class CanvasRenderingContext2D;
56 class ExecutionContext;
59 class HTMLMediaElement;
60 class InternalProfilers;
61 class InternalRuntimeFlags;
62 class InternalSettings;
68 class PagePopupController;
69 class PrivateScriptTest;
71 class SerializedScriptValue;
73 template <typename NodeType> class StaticNodeTypeList;
74 typedef StaticNodeTypeList<Node> StaticNodeList;
75 class TypeConversions;
77 class Internals FINAL : public GarbageCollectedFinalized<Internals>, public ScriptWrappable, public ContextLifecycleObserver {
78 DEFINE_WRAPPERTYPEINFO();
80 static Internals* create(Document*);
83 static void resetToConsistentState(Page*);
85 String elementRenderTreeAsText(Element*, ExceptionState&);
87 String address(Node*);
89 GCObservation* observeGC(ScriptValue);
91 bool isPreloaded(const String& url);
92 bool isLoadingFromMemoryCache(const String& url);
94 bool isSharingStyle(Element*, Element*) const;
96 PassRefPtrWillBeRawPtr<CSSStyleDeclaration> computedStyleIncludingVisitedInfo(Node*) const;
98 ShadowRoot* shadowRoot(Element* host);
99 ShadowRoot* youngestShadowRoot(Element* host);
100 ShadowRoot* oldestShadowRoot(Element* host);
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*);
108 // CSS Animation / Transition testing.
109 void pauseAnimations(double pauseTime, ExceptionState&);
111 bool isValidContentSelect(Element* insertionPoint, ExceptionState&);
112 Node* treeScopeRootNode(Node*);
113 Node* parentTreeScope(Node*);
114 bool hasSelectorForIdInShadow(Element* host, const AtomicString& idValue, ExceptionState&);
115 bool hasSelectorForClassInShadow(Element* host, const AtomicString& className, ExceptionState&);
116 bool hasSelectorForAttributeInShadow(Element* host, const AtomicString& attributeName, ExceptionState&);
117 bool hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState&);
118 unsigned short compareTreeScopePosition(const Node*, const Node*, ExceptionState&) const;
120 // FIXME: Rename these functions if walker is preferred.
121 Node* nextSiblingByWalker(Node*);
122 Node* firstChildByWalker(Node*);
123 Node* lastChildByWalker(Node*);
124 Node* nextNodeByWalker(Node*);
125 Node* previousNodeByWalker(Node*);
127 unsigned updateStyleAndReturnAffectedElementCount(ExceptionState&) const;
128 unsigned needsLayoutCount(ExceptionState&) const;
129 unsigned hitTestCount(Document*, ExceptionState&) const;
131 String visiblePlaceholder(Element*);
132 void selectColorInColorChooser(Element*, const String& colorValue);
133 void endColorChooser(Element*);
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> absoluteCaretBounds(ExceptionState&);
143 PassRefPtrWillBeRawPtr<ClientRect> boundingBox(Element*);
145 unsigned markerCountForNode(Node*, const String&, ExceptionState&);
146 unsigned activeMarkerCountForNode(Node*);
147 PassRefPtrWillBeRawPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
148 String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
149 void addTextMatchMarker(const Range*, bool isActive);
150 void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool);
151 void setMarkedTextMatchesAreHighlighted(Document*, bool);
153 void setScrollViewPosition(Document*, long x, long y, ExceptionState&);
154 String viewportAsText(Document*, float devicePixelRatio, int availableWidth, int availableHeight, ExceptionState&);
156 bool wasLastChangeUserEdit(Element* textField, ExceptionState&);
157 bool elementShouldAutoComplete(Element* inputElement, ExceptionState&);
158 String suggestedValue(Element*, ExceptionState&);
159 void setSuggestedValue(Element*, const String&, ExceptionState&);
160 void setEditingValue(Element* inputElement, const String&, ExceptionState&);
161 void setAutofilled(Element*, bool enabled, ExceptionState&);
162 void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionState&);
164 PassRefPtrWillBeRawPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength);
165 unsigned locationFromRange(Element* scope, const Range*);
166 unsigned lengthFromRange(Element* scope, const Range*);
167 String rangeAsText(const Range*);
169 DOMPoint* touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
170 Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
171 DOMPoint* touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
172 Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
173 PassRefPtrWillBeRawPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionState&);
175 int lastSpellCheckRequestSequence(Document*, ExceptionState&);
176 int lastSpellCheckProcessedSequence(Document*, ExceptionState&);
178 Vector<AtomicString> userPreferredLanguages() const;
179 void setUserPreferredLanguages(const Vector<String>&);
181 unsigned activeDOMObjectCount(Document*);
182 unsigned wheelEventHandlerCount(Document*);
183 unsigned scrollEventHandlerCount(Document*);
184 unsigned touchEventHandlerCount(Document*);
185 LayerRectList* touchEventTargetLayerRects(Document*, ExceptionState&);
187 // This is used to test rect based hit testing like what's done on touch screens.
188 PassRefPtrWillBeRawPtr<StaticNodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding,
189 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowChildFrameContent, ExceptionState&) const;
191 bool hasSpellingMarker(Document*, int from, int length);
192 bool hasGrammarMarker(Document*, int from, int length);
193 void setContinuousSpellCheckingEnabled(bool);
195 bool isOverwriteModeEnabled(Document*);
196 void toggleOverwriteModeEnabled(Document*);
198 unsigned numberOfScrollableAreas(Document*);
200 bool isPageBoxVisible(Document*, int pageNumber);
202 static const char* internalsId;
204 InternalSettings* settings() const;
205 InternalRuntimeFlags* runtimeFlags() const;
206 InternalProfilers* profilers();
207 unsigned workerThreadCount() const;
209 void setDeviceProximity(Document*, const String& eventType, double value, double min, double max, ExceptionState&);
211 String layerTreeAsText(Document*, unsigned flags, ExceptionState&) const;
212 String layerTreeAsText(Document*, ExceptionState&) const;
213 String elementLayerTreeAsText(Element*, unsigned flags, ExceptionState&) const;
214 String elementLayerTreeAsText(Element*, ExceptionState&) const;
216 bool scrollsWithRespectTo(Element*, Element*, ExceptionState&);
217 bool isUnclippedDescendant(Element*, ExceptionState&);
219 String scrollingStateTreeAsText(Document*) const;
220 String mainThreadScrollingReasons(Document*, ExceptionState&) const;
221 PassRefPtrWillBeRawPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionState&) const;
223 void garbageCollectDocumentResources(Document*) const;
224 void evictAllResources() const;
226 unsigned numberOfLiveNodes() const;
227 unsigned numberOfLiveDocuments() const;
228 String dumpRefCountedInstanceCounts() const;
229 Vector<String> consoleMessageArgumentCounts(Document*) const;
230 PassRefPtrWillBeRawPtr<LocalDOMWindow> openDummyInspectorFrontend(const String& url);
231 void closeDummyInspectorFrontend();
232 Vector<unsigned long> setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes);
233 void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState&);
235 String counterValue(Element*);
237 int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
238 Vector<String> shortcutIconURLs(Document*) const;
239 Vector<String> allIconURLs(Document*) const;
241 int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
242 String pageProperty(String, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
243 String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
245 void setDeviceScaleFactor(float scaleFactor, ExceptionState&);
247 void setIsCursorVisible(Document*, bool, ExceptionState&);
249 void mediaPlayerRequestFullscreen(HTMLMediaElement*);
250 double effectiveMediaVolume(HTMLMediaElement*);
252 void mediaPlayerRemoteRouteAvailabilityChanged(HTMLMediaElement *, bool);
254 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
255 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
257 TypeConversions* typeConversions() const;
258 PrivateScriptTest* privateScriptTest() const;
259 DictionaryTest* dictionaryTest() const;
261 Vector<String> getReferencedFilePaths() const;
263 void startTrackingRepaints(Document*, ExceptionState&);
264 void stopTrackingRepaints(Document*, ExceptionState&);
265 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState&);
266 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionState&);
267 void forceFullRepaint(Document*, ExceptionState&);
269 PassRefPtrWillBeRawPtr<ClientRectList> draggableRegions(Document*, ExceptionState&);
270 PassRefPtrWillBeRawPtr<ClientRectList> nonDraggableRegions(Document*, ExceptionState&);
272 PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
273 PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const;
275 String getCurrentCursorInfo(Document*, ExceptionState&);
277 String markerTextForListItem(Element*);
279 void forceReload(bool endToEnd);
281 String getImageSourceURL(Element*);
283 bool isSelectPopupVisible(Node*);
284 bool selectPopupItemStyleIsRtl(Node*, int);
285 int selectPopupItemStyleFontHeight(Node*, int);
287 PassRefPtrWillBeRawPtr<ClientRect> selectionBounds(ExceptionState&);
289 bool loseSharedGraphicsContext3D();
291 void forceCompositingUpdate(Document*, ExceptionState&);
293 void setZoomFactor(float);
295 void setShouldRevealPassword(Element*, bool, ExceptionState&);
297 ScriptPromise createResolvedPromise(ScriptState*, ScriptValue);
298 ScriptPromise createRejectedPromise(ScriptState*, ScriptValue);
299 ScriptPromise addOneToPromise(ScriptState*, ScriptPromise);
300 ScriptPromise promiseCheck(ScriptState*, long, bool, const Dictionary&, const String&, const Vector<String>&, ExceptionState&);
301 ScriptPromise promiseCheckWithoutExceptionState(ScriptState*, const Dictionary&, const String&, const Vector<String>&);
302 ScriptPromise promiseCheckRange(ScriptState*, long);
304 void trace(Visitor*);
306 void setValueForUser(Element*, const String&);
308 String textSurroundingNode(Node*, int x, int y, unsigned long maxLength);
310 void setFocused(bool);
312 bool ignoreLayoutWithPendingStylesheets(Document*);
314 void setNetworkStateNotifierTestOnly(bool);
315 // Test must call setNetworkStateNotifierTestOnly(true) before calling setNetworkConnectionInfo.
316 void setNetworkConnectionInfo(const String&, ExceptionState&);
317 String serializeNavigationMarkup();
318 void hideAllTransitionElements();
320 unsigned countHitRegions(CanvasRenderingContext2D*);
322 void forcePluginPlaceholder(HTMLElement* plugin, const String& htmlSource, ExceptionState&);
323 void forcePluginPlaceholder(HTMLElement* plugin, const Dictionary& options, ExceptionState&);
325 Iterator* iterator(ScriptState*, ExceptionState&);
328 explicit Internals(Document*);
329 Document* contextDocument() const;
330 LocalFrame* frame() const;
331 Vector<String> iconURLs(Document*, int iconTypesMask) const;
332 PassRefPtrWillBeRawPtr<ClientRectList> annotatedRegions(Document*, bool draggable, ExceptionState&);
334 DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionState&);
335 Member<InternalRuntimeFlags> m_runtimeFlags;
336 Member<InternalProfilers> m_profilers;
341 #endif // Internals_h