1 /* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Apple Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 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. 14 * 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. 25 */ 26 27 #ifndef Internals_h 28 #define Internals_h 29 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/page/scrolling/ScrollingCoordinator.h" 36 #include "platform/heap/Handle.h" 37 #include "wtf/ArrayBuffer.h" 38 #include "wtf/PassRefPtr.h" 39 #include "wtf/RefCounted.h" 40 #include "wtf/text/WTFString.h" 41 42 namespace WebCore { 43 44 class ClientRect; 45 class ClientRectList; 46 class DOMPoint; 47 class DOMStringList; 48 class LocalDOMWindow; 49 class Document; 50 class DocumentMarker; 51 class Element; 52 class ExceptionState; 53 class ExecutionContext; 54 class GCObservation; 55 class HTMLMediaElement; 56 class InternalProfilers; 57 class InternalRuntimeFlags; 58 class InternalSettings; 59 class LayerRectList; 60 class LocalFrame; 61 class MallocStatistics; 62 class Node; 63 class Page; 64 class PagePopupController; 65 class Range; 66 class SerializedScriptValue; 67 class StaticNodeList; 68 class ShadowRoot; 69 class TypeConversions; 70 71 class Internals FINAL : public RefCountedWillBeGarbageCollectedFinalized<Internals>, public ContextLifecycleObserver { 72 public: 73 static PassRefPtrWillBeRawPtr<Internals> create(Document*); 74 virtual ~Internals(); 75 76 static void resetToConsistentState(Page*); 77 78 String elementRenderTreeAsText(Element*, ExceptionState&); 79 80 String address(Node*); 81 82 PassRefPtrWillBeRawPtr<GCObservation> observeGC(ScriptValue); 83 84 bool isPreloaded(const String& url); 85 bool isLoadingFromMemoryCache(const String& url); 86 87 void crash(); 88 89 void setStyleResolverStatsEnabled(bool); 90 String styleResolverStatsReport(ExceptionState&) const; 91 String styleResolverStatsTotalsReport(ExceptionState&) const; 92 93 bool isSharingStyle(Element*, Element*, ExceptionState&) const; 94 95 PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Node*, ExceptionState&) const; 96 97 ShadowRoot* shadowRoot(Element* host, ExceptionState&); 98 ShadowRoot* youngestShadowRoot(Element* host, ExceptionState&); 99 ShadowRoot* oldestShadowRoot(Element* host, ExceptionState&); 100 ShadowRoot* youngerShadowRoot(Node* shadow, ExceptionState&); 101 String shadowRootType(const Node*, ExceptionState&) const; 102 bool hasShadowInsertionPoint(const Node*, ExceptionState&) const; 103 bool hasContentElement(const Node*, ExceptionState&) const; 104 size_t countElementShadow(const Node*, ExceptionState&) const; 105 const AtomicString& shadowPseudoId(Element*, ExceptionState&); 106 void setShadowPseudoId(Element*, const AtomicString&, ExceptionState&); 107 108 // CSS Animation / Transition testing. 109 unsigned numberOfActiveAnimations() const; 110 void pauseAnimations(double pauseTime, ExceptionState&); 111 112 bool isValidContentSelect(Element* insertionPoint, ExceptionState&); 113 Node* treeScopeRootNode(Node*, ExceptionState&); 114 Node* parentTreeScope(Node*, ExceptionState&); 115 bool hasSelectorForIdInShadow(Element* host, const AtomicString& idValue, ExceptionState&); 116 bool hasSelectorForClassInShadow(Element* host, const AtomicString& className, ExceptionState&); 117 bool hasSelectorForAttributeInShadow(Element* host, const AtomicString& attributeName, ExceptionState&); 118 bool hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState&); 119 unsigned short compareTreeScopePosition(const Node*, const Node*, ExceptionState&) const; 120 121 // FIXME: Rename these functions if walker is prefered. 122 Node* nextSiblingByWalker(Node*, ExceptionState&); 123 Node* firstChildByWalker(Node*, ExceptionState&); 124 Node* lastChildByWalker(Node*, ExceptionState&); 125 Node* nextNodeByWalker(Node*, ExceptionState&); 126 Node* previousNodeByWalker(Node*, ExceptionState&); 127 128 unsigned updateStyleAndReturnAffectedElementCount(ExceptionState&) const; 129 unsigned needsLayoutCount(ExceptionState&) const; 130 131 String visiblePlaceholder(Element*); 132 void selectColorInColorChooser(Element*, const String& colorValue); 133 bool hasAutofocusRequest(Document*); 134 bool hasAutofocusRequest(); 135 Vector<String> formControlStateOfHistoryItem(ExceptionState&); 136 void setFormControlStateOfHistoryItem(const Vector<String>&, ExceptionState&); 137 void setEnableMockPagePopup(bool, ExceptionState&); 138 PassRefPtrWillBeRawPtr<PagePopupController> pagePopupController(); 139 140 PassRefPtrWillBeRawPtr<ClientRect> unscaledViewportRect(ExceptionState&); 141 142 PassRefPtrWillBeRawPtr<ClientRect> absoluteCaretBounds(ExceptionState&); 143 144 PassRefPtrWillBeRawPtr<ClientRect> boundingBox(Element*, ExceptionState&); 145 146 unsigned markerCountForNode(Node*, const String&, ExceptionState&); 147 unsigned activeMarkerCountForNode(Node*, ExceptionState&); 148 PassRefPtrWillBeRawPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionState&); 149 String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionState&); 150 void addTextMatchMarker(const Range*, bool isActive); 151 void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool, ExceptionState&); 152 void setMarkedTextMatchesAreHighlighted(Document*, bool, ExceptionState&); 153 154 void setScrollViewPosition(Document*, long x, long y, ExceptionState&); 155 String viewportAsText(Document*, float devicePixelRatio, int availableWidth, int availableHeight, ExceptionState&); 156 157 bool wasLastChangeUserEdit(Element* textField, ExceptionState&); 158 bool elementShouldAutoComplete(Element* inputElement, ExceptionState&); 159 String suggestedValue(Element*, ExceptionState&); 160 void setSuggestedValue(Element*, const String&, ExceptionState&); 161 void setEditingValue(Element* inputElement, const String&, ExceptionState&); 162 void setAutofilled(Element*, bool enabled, ExceptionState&); 163 void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionState&); 164 165 PassRefPtrWillBeRawPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionState&); 166 unsigned locationFromRange(Element* scope, const Range*, ExceptionState&); 167 unsigned lengthFromRange(Element* scope, const Range*, ExceptionState&); 168 String rangeAsText(const Range*, ExceptionState&); 169 170 PassRefPtrWillBeRawPtr<DOMPoint> touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&); 171 Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&); 172 PassRefPtrWillBeRawPtr<DOMPoint> touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&); 173 Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&); 174 PassRefPtrWillBeRawPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionState&); 175 176 int lastSpellCheckRequestSequence(Document*, ExceptionState&); 177 int lastSpellCheckProcessedSequence(Document*, ExceptionState&); 178 179 Vector<AtomicString> userPreferredLanguages() const; 180 void setUserPreferredLanguages(const Vector<String>&); 181 182 unsigned activeDOMObjectCount(Document*, ExceptionState&); 183 unsigned wheelEventHandlerCount(Document*, ExceptionState&); 184 unsigned scrollEventHandlerCount(Document*, ExceptionState&); 185 unsigned touchEventHandlerCount(Document*, ExceptionState&); 186 PassRefPtrWillBeRawPtr<LayerRectList> touchEventTargetLayerRects(Document*, ExceptionState&); 187 188 // This is used to test rect based hit testing like what's done on touch screens. 189 PassRefPtrWillBeRawPtr<StaticNodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding, 190 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionState&) const; 191 192 void emitInspectorDidBeginFrame(int frameId = 0); 193 void emitInspectorDidCancelFrame(); 194 195 bool hasSpellingMarker(Document*, int from, int length, ExceptionState&); 196 bool hasGrammarMarker(Document*, int from, int length, ExceptionState&); 197 void setContinuousSpellCheckingEnabled(bool enabled, ExceptionState&); 198 199 bool isOverwriteModeEnabled(Document*, ExceptionState&); 200 void toggleOverwriteModeEnabled(Document*, ExceptionState&); 201 202 unsigned numberOfScrollableAreas(Document*, ExceptionState&); 203 204 bool isPageBoxVisible(Document*, int pageNumber, ExceptionState&); 205 206 static const char* internalsId; 207 208 InternalSettings* settings() const; 209 InternalRuntimeFlags* runtimeFlags() const; 210 InternalProfilers* profilers(); 211 unsigned workerThreadCount() const; 212 213 void setDeviceProximity(Document*, const String& eventType, double value, double min, double max, ExceptionState&); 214 215 String layerTreeAsText(Document*, unsigned flags, ExceptionState&) const; 216 String layerTreeAsText(Document*, ExceptionState&) const; 217 String elementLayerTreeAsText(Element*, unsigned flags, ExceptionState&) const; 218 String elementLayerTreeAsText(Element*, ExceptionState&) const; 219 220 bool scrollsWithRespectTo(Element*, Element*, ExceptionState&); 221 bool isUnclippedDescendant(Element*, ExceptionState&); 222 223 String repaintRectsAsText(Document*, ExceptionState&) const; 224 PassRefPtrWillBeRawPtr<ClientRectList> repaintRects(Element*, ExceptionState&) const; 225 226 String scrollingStateTreeAsText(Document*, ExceptionState&) const; 227 String mainThreadScrollingReasons(Document*, ExceptionState&) const; 228 PassRefPtrWillBeRawPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionState&) const; 229 230 void garbageCollectDocumentResources(Document*, ExceptionState&) const; 231 void evictAllResources() const; 232 233 void allowRoundingHacks() const; 234 235 unsigned numberOfLiveNodes() const; 236 unsigned numberOfLiveDocuments() const; 237 String dumpRefCountedInstanceCounts() const; 238 Vector<String> consoleMessageArgumentCounts(Document*) const; 239 PassRefPtrWillBeRawPtr<LocalDOMWindow> openDummyInspectorFrontend(const String& url); 240 void closeDummyInspectorFrontend(); 241 Vector<unsigned long> setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes); 242 void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState&); 243 244 String counterValue(Element*); 245 246 int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600); 247 Vector<String> shortcutIconURLs(Document*) const; 248 Vector<String> allIconURLs(Document*) const; 249 250 int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600); 251 String pageProperty(String, int, ExceptionState& = ASSERT_NO_EXCEPTION) const; 252 String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionState& = ASSERT_NO_EXCEPTION) const; 253 254 void setDeviceScaleFactor(float scaleFactor, ExceptionState&); 255 256 void setIsCursorVisible(Document*, bool, ExceptionState&); 257 258 void webkitWillEnterFullScreenForElement(Document*, Element*); 259 void webkitDidEnterFullScreenForElement(Document*, Element*); 260 void webkitWillExitFullScreenForElement(Document*, Element*); 261 void webkitDidExitFullScreenForElement(Document*, Element*); 262 263 void mediaPlayerRequestFullscreen(HTMLMediaElement*); 264 265 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme); 266 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme); 267 268 PassRefPtrWillBeRawPtr<MallocStatistics> mallocStatistics() const; 269 PassRefPtrWillBeRawPtr<TypeConversions> typeConversions() const; 270 271 Vector<String> getReferencedFilePaths() const; 272 273 void startTrackingRepaints(Document*, ExceptionState&); 274 void stopTrackingRepaints(Document*, ExceptionState&); 275 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState&); 276 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionState&); 277 void forceFullRepaint(Document*, ExceptionState&); 278 279 PassRefPtrWillBeRawPtr<ClientRectList> draggableRegions(Document*, ExceptionState&); 280 PassRefPtrWillBeRawPtr<ClientRectList> nonDraggableRegions(Document*, ExceptionState&); 281 282 PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const; 283 PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const; 284 285 String getCurrentCursorInfo(Document*, ExceptionState&); 286 287 String markerTextForListItem(Element*, ExceptionState&); 288 289 void forceReload(bool endToEnd); 290 291 String getImageSourceURL(Element*, ExceptionState&); 292 293 bool isSelectPopupVisible(Node*); 294 295 PassRefPtrWillBeRawPtr<ClientRect> selectionBounds(ExceptionState&); 296 String baseURL(Document*, ExceptionState&); 297 298 bool loseSharedGraphicsContext3D(); 299 300 void forceCompositingUpdate(Document*, ExceptionState&); 301 302 void setZoomFactor(float); 303 304 void setShouldRevealPassword(Element*, bool, ExceptionState&); 305 306 ScriptPromise createPromise(ScriptState*); 307 ScriptPromise createResolvedPromise(ScriptState*, ScriptValue); 308 ScriptPromise createRejectedPromise(ScriptState*, ScriptValue); 309 ScriptPromise addOneToPromise(ExecutionContext*, ScriptPromise); 310 311 void trace(Visitor*); 312 313 void setValueForUser(Element*, const String&); 314 315 String textSurroundingNode(Node*, int x, int y, unsigned long maxLength); 316 317 void setFocused(bool); 318 319 bool ignoreLayoutWithPendingStylesheets(Document*, ExceptionState&); 320 321 void setNetworkStateNotifierTestOnly(bool); 322 // Test must call setNetworkStateNotifierTestOnly(true) before calling setNetworkConnectionInfo. 323 void setNetworkConnectionInfo(const String&, ExceptionState&); 324 325 private: 326 explicit Internals(Document*); 327 Document* contextDocument() const; 328 LocalFrame* frame() const; 329 Vector<String> iconURLs(Document*, int iconTypesMask) const; 330 PassRefPtrWillBeRawPtr<ClientRectList> annotatedRegions(Document*, bool draggable, ExceptionState&); 331 332 DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionState&); 333 RefPtrWillBeMember<InternalRuntimeFlags> m_runtimeFlags; 334 RefPtrWillBeMember<InternalProfilers> m_profilers; 335 }; 336 337 } // namespace WebCore 338 339 #endif 340