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/PassRefPtr.h"
39 #include "wtf/RefCounted.h"
40 #include "wtf/text/WTFString.h"
44 class CanvasRenderingContext2D;
52 class DocumentFragment;
56 class ExecutionContext;
59 class HTMLMediaElement;
60 class InternalProfilers;
61 class InternalRuntimeFlags;
62 class InternalSettings;
69 class PagePopupController;
70 class PrivateScriptTest;
72 class SerializedScriptValue;
74 class TypeConversions;
76 template <typename NodeType> class StaticNodeTypeList;
77 typedef StaticNodeTypeList<Node> StaticNodeList;
79 class Internals final : public GarbageCollectedFinalized<Internals>, public ScriptWrappable, public ContextLifecycleObserver {
80 DEFINE_WRAPPERTYPEINFO();
82 static Internals* create(Document*);
85 static void resetToConsistentState(Page*);
87 String elementRenderTreeAsText(Element*, ExceptionState&);
89 String address(Node*);
91 GCObservation* observeGC(ScriptValue);
93 bool isPreloaded(const String& url);
94 bool isLoadingFromMemoryCache(const String& url);
96 bool isSharingStyle(Element*, Element*) const;
98 PassRefPtrWillBeRawPtr<CSSStyleDeclaration> computedStyleIncludingVisitedInfo(Node*) const;
100 PassRefPtrWillBeRawPtr<ShadowRoot> createUserAgentShadowRoot(Element* host);
102 ShadowRoot* shadowRoot(Element* host);
103 ShadowRoot* youngestShadowRoot(Element* host);
104 ShadowRoot* oldestShadowRoot(Element* host);
105 ShadowRoot* youngerShadowRoot(Node* shadow, ExceptionState&);
106 String shadowRootType(const Node*, ExceptionState&) const;
107 bool hasShadowInsertionPoint(const Node*, ExceptionState&) const;
108 bool hasContentElement(const Node*, ExceptionState&) const;
109 size_t countElementShadow(const Node*, ExceptionState&) const;
110 const AtomicString& shadowPseudoId(Element*);
112 // CSS Animation / Transition testing.
113 void pauseAnimations(double pauseTime, ExceptionState&);
115 bool isValidContentSelect(Element* insertionPoint, ExceptionState&);
116 Node* treeScopeRootNode(Node*);
117 Node* parentTreeScope(Node*);
118 bool hasSelectorForIdInShadow(Element* host, const AtomicString& idValue, ExceptionState&);
119 bool hasSelectorForClassInShadow(Element* host, const AtomicString& className, ExceptionState&);
120 bool hasSelectorForAttributeInShadow(Element* host, const AtomicString& attributeName, ExceptionState&);
121 bool hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState&);
122 unsigned short compareTreeScopePosition(const Node*, const Node*, ExceptionState&) const;
124 // FIXME: Rename these functions if walker is preferred.
125 Node* nextSiblingByWalker(Node*);
126 Node* firstChildByWalker(Node*);
127 Node* lastChildByWalker(Node*);
128 Node* nextNodeByWalker(Node*);
129 Node* previousNodeByWalker(Node*);
131 unsigned updateStyleAndReturnAffectedElementCount(ExceptionState&) const;
132 unsigned needsLayoutCount(ExceptionState&) const;
133 unsigned hitTestCount(Document*, ExceptionState&) const;
135 String visiblePlaceholder(Element*);
136 void selectColorInColorChooser(Element*, const String& colorValue);
137 void endColorChooser(Element*);
138 bool hasAutofocusRequest(Document*);
139 bool hasAutofocusRequest();
140 Vector<String> formControlStateOfHistoryItem(ExceptionState&);
141 void setFormControlStateOfHistoryItem(const Vector<String>&, ExceptionState&);
142 void setEnableMockPagePopup(bool, ExceptionState&);
143 PassRefPtrWillBeRawPtr<PagePopupController> pagePopupController();
144 LocalDOMWindow* pagePopupWindow() const;
146 PassRefPtrWillBeRawPtr<ClientRect> absoluteCaretBounds(ExceptionState&);
148 PassRefPtrWillBeRawPtr<ClientRect> boundingBox(Element*);
150 unsigned markerCountForNode(Node*, const String&, ExceptionState&);
151 unsigned activeMarkerCountForNode(Node*);
152 PassRefPtrWillBeRawPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
153 String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
154 void addTextMatchMarker(const Range*, bool isActive);
155 void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool);
156 void setMarkedTextMatchesAreHighlighted(Document*, bool);
158 void setFrameViewPosition(Document*, long x, long y, ExceptionState&);
159 String viewportAsText(Document*, float devicePixelRatio, int availableWidth, int availableHeight, ExceptionState&);
161 bool wasLastChangeUserEdit(Element* textField, ExceptionState&);
162 bool elementShouldAutoComplete(Element* inputElement, ExceptionState&);
163 String suggestedValue(Element*, ExceptionState&);
164 void setSuggestedValue(Element*, const String&, ExceptionState&);
165 void setEditingValue(Element* inputElement, const String&, ExceptionState&);
166 void setAutofilled(Element*, bool enabled, ExceptionState&);
167 void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionState&);
169 PassRefPtrWillBeRawPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength);
170 unsigned locationFromRange(Element* scope, const Range*);
171 unsigned lengthFromRange(Element* scope, const Range*);
172 String rangeAsText(const Range*);
174 DOMPoint* touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
175 Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
176 DOMPoint* touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
177 Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
178 PassRefPtrWillBeRawPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionState&);
180 int lastSpellCheckRequestSequence(Document*, ExceptionState&);
181 int lastSpellCheckProcessedSequence(Document*, ExceptionState&);
183 Vector<AtomicString> userPreferredLanguages() const;
184 void setUserPreferredLanguages(const Vector<String>&);
186 unsigned activeDOMObjectCount(Document*);
187 unsigned wheelEventHandlerCount(Document*);
188 unsigned scrollEventHandlerCount(Document*);
189 unsigned touchEventHandlerCount(Document*);
190 LayerRectList* touchEventTargetLayerRects(Document*, ExceptionState&);
192 // This is used to test rect based hit testing like what's done on touch screens.
193 PassRefPtrWillBeRawPtr<StaticNodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding,
194 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowChildFrameContent, ExceptionState&) const;
196 bool hasSpellingMarker(Document*, int from, int length);
197 bool hasGrammarMarker(Document*, int from, int length);
198 void setContinuousSpellCheckingEnabled(bool);
200 bool isOverwriteModeEnabled(Document*);
201 void toggleOverwriteModeEnabled(Document*);
203 unsigned numberOfScrollableAreas(Document*);
205 bool isPageBoxVisible(Document*, int pageNumber);
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 bool scrollsWithRespectTo(Element*, Element*, ExceptionState&);
223 String scrollingStateTreeAsText(Document*) const;
224 String mainThreadScrollingReasons(Document*, ExceptionState&) const;
225 PassRefPtrWillBeRawPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionState&) const;
227 void garbageCollectDocumentResources(Document*) const;
228 void evictAllResources() const;
230 unsigned numberOfLiveNodes() const;
231 unsigned numberOfLiveDocuments() const;
232 String dumpRefCountedInstanceCounts() const;
233 Vector<String> consoleMessageArgumentCounts(Document*) const;
234 PassRefPtrWillBeRawPtr<LocalDOMWindow> openDummyInspectorFrontend(const String& url);
235 void closeDummyInspectorFrontend();
236 Vector<unsigned long> setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes);
237 void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState&);
238 String inspectorHighlightJSON(Node*, ExceptionState&);
240 String counterValue(Element*);
242 int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
243 Vector<String> shortcutIconURLs(Document*) const;
244 Vector<String> allIconURLs(Document*) const;
246 int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
247 String pageProperty(String, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
248 String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
250 void setDeviceScaleFactor(float scaleFactor, ExceptionState&);
252 void setIsCursorVisible(Document*, bool, ExceptionState&);
254 void mediaPlayerRequestFullscreen(HTMLMediaElement*);
255 double effectiveMediaVolume(HTMLMediaElement*);
257 void mediaPlayerRemoteRouteAvailabilityChanged(HTMLMediaElement*, bool);
258 void mediaPlayerPlayingRemotelyChanged(HTMLMediaElement*, bool);
260 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
261 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
263 TypeConversions* typeConversions() const;
264 PrivateScriptTest* privateScriptTest() const;
265 DictionaryTest* dictionaryTest() const;
266 UnionTypesTest* unionTypesTest() const;
268 Vector<String> getReferencedFilePaths() const;
270 void startTrackingRepaints(Document*, ExceptionState&);
271 void stopTrackingRepaints(Document*, ExceptionState&);
272 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState&);
273 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionState&);
274 void forceFullRepaint(Document*, ExceptionState&);
276 PassRefPtrWillBeRawPtr<ClientRectList> draggableRegions(Document*, ExceptionState&);
277 PassRefPtrWillBeRawPtr<ClientRectList> nonDraggableRegions(Document*, ExceptionState&);
279 PassRefPtr<DOMArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
280 PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<DOMArrayBuffer>) const;
282 String getCurrentCursorInfo(Document*, ExceptionState&);
284 String markerTextForListItem(Element*);
286 void forceReload(bool endToEnd);
288 String getImageSourceURL(Element*);
290 bool isSelectPopupVisible(Node*);
291 bool selectPopupItemStyleIsRtl(Node*, int);
292 int selectPopupItemStyleFontHeight(Node*, int);
294 PassRefPtrWillBeRawPtr<ClientRect> selectionBounds(ExceptionState&);
296 bool loseSharedGraphicsContext3D();
298 void forceCompositingUpdate(Document*, ExceptionState&);
300 void setZoomFactor(float);
302 void setShouldRevealPassword(Element*, bool, ExceptionState&);
304 ScriptPromise createResolvedPromise(ScriptState*, ScriptValue);
305 ScriptPromise createRejectedPromise(ScriptState*, ScriptValue);
306 ScriptPromise addOneToPromise(ScriptState*, ScriptPromise);
307 ScriptPromise promiseCheck(ScriptState*, long, bool, const Dictionary&, const String&, const Vector<String>&, ExceptionState&);
308 ScriptPromise promiseCheckWithoutExceptionState(ScriptState*, const Dictionary&, const String&, const Vector<String>&);
309 ScriptPromise promiseCheckRange(ScriptState*, long);
310 ScriptPromise promiseCheckOverload(ScriptState*, Location*);
311 ScriptPromise promiseCheckOverload(ScriptState*, Document*);
312 ScriptPromise promiseCheckOverload(ScriptState*, Location*, long, long);
314 void trace(Visitor*);
316 void setValueForUser(Element*, const String&);
318 String textSurroundingNode(Node*, int x, int y, unsigned long maxLength);
320 void setFocused(bool);
322 bool ignoreLayoutWithPendingStylesheets(Document*);
324 void setNetworkStateNotifierTestOnly(bool);
325 // Test must call setNetworkStateNotifierTestOnly(true) before calling setNetworkConnectionInfo.
326 void setNetworkConnectionInfo(const String&, ExceptionState&);
327 String serializeNavigationMarkup();
328 void hideAllTransitionElements();
330 unsigned countHitRegions(CanvasRenderingContext2D*);
332 void forcePluginPlaceholder(HTMLElement* plugin, PassRefPtrWillBeRawPtr<DocumentFragment>, ExceptionState&);
333 void forcePluginPlaceholder(HTMLElement* plugin, const Dictionary& options, ExceptionState&);
335 Iterator* iterator(ScriptState*, ExceptionState&);
338 explicit Internals(Document*);
339 Document* contextDocument() const;
340 LocalFrame* frame() const;
341 Vector<String> iconURLs(Document*, int iconTypesMask) const;
342 PassRefPtrWillBeRawPtr<ClientRectList> annotatedRegions(Document*, bool draggable, ExceptionState&);
344 DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionState&);
345 Member<InternalRuntimeFlags> m_runtimeFlags;
346 Member<InternalProfilers> m_profilers;
351 #endif // Internals_h