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/ScriptValue.h" 32 #include "core/css/CSSComputedStyleDeclaration.h" 33 #include "core/dom/ContextLifecycleObserver.h" 34 #include "core/dom/NodeList.h" 35 #include "core/page/scrolling/ScrollingCoordinator.h" 36 #include "wtf/ArrayBuffer.h" 37 #include "wtf/PassRefPtr.h" 38 #include "wtf/RefCounted.h" 39 #include "wtf/text/WTFString.h" 40 41 namespace WebCore { 42 43 class ClientRect; 44 class ClientRectList; 45 class DOMPoint; 46 class DOMStringList; 47 class DOMWindow; 48 class Document; 49 class DocumentMarker; 50 class Element; 51 class ExceptionState; 52 class Frame; 53 class GCObservation; 54 class InspectorFrontendChannelDummy; 55 class InternalProfilers; 56 class InternalRuntimeFlags; 57 class InternalSettings; 58 class LayerRectList; 59 class MallocStatistics; 60 class Node; 61 class Page; 62 class PagePopupController; 63 class Range; 64 class ExecutionContext; 65 class SerializedScriptValue; 66 class ShadowRoot; 67 class TypeConversions; 68 69 class Internals : public RefCounted<Internals> 70 , public ContextLifecycleObserver { 71 public: 72 static PassRefPtr<Internals> create(Document*); 73 virtual ~Internals(); 74 75 static void resetToConsistentState(Page*); 76 77 String elementRenderTreeAsText(Element*, ExceptionState&); 78 79 String address(Node*); 80 81 PassRefPtr<GCObservation> observeGC(ScriptValue); 82 83 bool isPreloaded(const String& url); 84 bool isLoadingFromMemoryCache(const String& url); 85 86 void crash(); 87 88 void setStyleResolverStatsEnabled(bool); 89 String styleResolverStatsReport(ExceptionState&) const; 90 String styleResolverStatsTotalsReport(ExceptionState&) const; 91 92 size_t numberOfScopedHTMLStyleChildren(const Node*, ExceptionState&) const; 93 PassRefPtr<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Node*, ExceptionState&) const; 94 95 ShadowRoot* ensureShadowRoot(Element* host, ExceptionState&); 96 ShadowRoot* shadowRoot(Element* host, ExceptionState&); 97 ShadowRoot* youngestShadowRoot(Element* host, ExceptionState&); 98 ShadowRoot* oldestShadowRoot(Element* host, ExceptionState&); 99 ShadowRoot* youngerShadowRoot(Node* shadow, ExceptionState&); 100 ShadowRoot* olderShadowRoot(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 String shadowPseudoId(Element*, ExceptionState&); 106 void setShadowPseudoId(Element*, const String&, ExceptionState&); 107 108 // CSS Animation / Transition testing. 109 unsigned numberOfActiveAnimations() const; 110 void pauseAnimations(double pauseTime, ExceptionState&); 111 112 PassRefPtr<Element> createContentElement(ExceptionState&); 113 bool isValidContentSelect(Element* insertionPoint, ExceptionState&); 114 Node* treeScopeRootNode(Node*, ExceptionState&); 115 Node* parentTreeScope(Node*, ExceptionState&); 116 bool hasSelectorForIdInShadow(Element* host, const String& idValue, ExceptionState&); 117 bool hasSelectorForClassInShadow(Element* host, const String& className, ExceptionState&); 118 bool hasSelectorForAttributeInShadow(Element* host, const String& attributeName, ExceptionState&); 119 bool hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionState&); 120 unsigned short compareTreeScopePosition(const Node*, const Node*, ExceptionState&) const; 121 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&); 128 129 unsigned updateStyleAndReturnAffectedElementCount(ExceptionState&) const; 130 131 String visiblePlaceholder(Element*); 132 void selectColorInColorChooser(Element*, const String& colorValue); 133 Vector<String> formControlStateOfHistoryItem(ExceptionState&); 134 void setFormControlStateOfHistoryItem(const Vector<String>&, ExceptionState&); 135 void setEnableMockPagePopup(bool, ExceptionState&); 136 PassRefPtr<PagePopupController> pagePopupController(); 137 138 PassRefPtr<ClientRect> unscaledViewportRect(ExceptionState&); 139 140 PassRefPtr<ClientRect> absoluteCaretBounds(ExceptionState&); 141 142 PassRefPtr<ClientRect> boundingBox(Element*, ExceptionState&); 143 144 PassRefPtr<ClientRectList> inspectorHighlightRects(Document*, ExceptionState&); 145 146 unsigned markerCountForNode(Node*, const String&, ExceptionState&); 147 unsigned activeMarkerCountForNode(Node*, ExceptionState&); 148 PassRefPtr<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 153 void setScrollViewPosition(Document*, long x, long y, ExceptionState&); setPagination(Document * document,const String & mode,int gap,ExceptionState & ec)154 void setPagination(Document* document, const String& mode, int gap, ExceptionState& ec) { setPagination(document, mode, gap, 0, ec); } 155 void setPagination(Document*, const String& mode, int gap, int pageLength, ExceptionState&); 156 String viewportAsText(Document*, float devicePixelRatio, int availableWidth, int availableHeight, ExceptionState&); 157 158 bool wasLastChangeUserEdit(Element* textField, ExceptionState&); 159 bool elementShouldAutoComplete(Element* inputElement, ExceptionState&); 160 String suggestedValue(Element* inputElement, ExceptionState&); 161 void setSuggestedValue(Element* inputElement, 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&); 165 166 void paintControlTints(Document*, ExceptionState&); 167 168 PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionState&); 169 unsigned locationFromRange(Element* scope, const Range*, ExceptionState&); 170 unsigned lengthFromRange(Element* scope, const Range*, ExceptionState&); 171 String rangeAsText(const Range*, ExceptionState&); 172 173 PassRefPtr<DOMPoint> touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&); 174 Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&); 175 PassRefPtr<DOMPoint> touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&); 176 Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&); 177 PassRefPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionState&); 178 179 int lastSpellCheckRequestSequence(Document*, ExceptionState&); 180 int lastSpellCheckProcessedSequence(Document*, ExceptionState&); 181 182 Vector<String> userPreferredLanguages() const; 183 void setUserPreferredLanguages(const Vector<String>&); 184 185 unsigned wheelEventHandlerCount(Document*, ExceptionState&); 186 unsigned touchEventHandlerCount(Document*, ExceptionState&); 187 PassRefPtr<LayerRectList> touchEventTargetLayerRects(Document*, ExceptionState&); 188 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; 192 193 void emitInspectorDidBeginFrame(int frameId = 0); 194 void emitInspectorDidCancelFrame(); 195 196 bool hasSpellingMarker(Document*, int from, int length, ExceptionState&); 197 bool hasGrammarMarker(Document*, int from, int length, ExceptionState&); 198 void setContinuousSpellCheckingEnabled(bool enabled, ExceptionState&); 199 200 bool isOverwriteModeEnabled(Document*, ExceptionState&); 201 void toggleOverwriteModeEnabled(Document*, ExceptionState&); 202 203 unsigned numberOfScrollableAreas(Document*, ExceptionState&); 204 205 bool isPageBoxVisible(Document*, int pageNumber, ExceptionState&); 206 207 static const char* internalsId; 208 209 InternalSettings* settings() const; 210 InternalRuntimeFlags* runtimeFlags() const; 211 InternalProfilers* profilers(); 212 unsigned workerThreadCount() const; 213 214 void setDeviceProximity(Document*, const String& eventType, double value, double min, double max, ExceptionState&); 215 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; 220 221 PassRefPtr<NodeList> paintOrderListBeforePromote(Element*, ExceptionState&); 222 PassRefPtr<NodeList> paintOrderListAfterPromote(Element*, ExceptionState&); 223 224 bool scrollsWithRespectTo(Element*, Element*, ExceptionState&); 225 bool isUnclippedDescendant(Element*, ExceptionState&); 226 bool needsCompositedScrolling(Element*, ExceptionState&); 227 228 void setNeedsCompositedScrolling(Element*, unsigned value, ExceptionState&); 229 230 String repaintRectsAsText(Document*, ExceptionState&) const; 231 PassRefPtr<ClientRectList> repaintRects(Element*, ExceptionState&) const; 232 233 String scrollingStateTreeAsText(Document*, ExceptionState&) const; 234 String mainThreadScrollingReasons(Document*, ExceptionState&) const; 235 PassRefPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionState&) const; 236 237 void garbageCollectDocumentResources(Document*, ExceptionState&) const; 238 void evictAllResources() const; 239 240 void allowRoundingHacks() const; 241 242 unsigned numberOfLiveNodes() const; 243 unsigned numberOfLiveDocuments() const; 244 String dumpRefCountedInstanceCounts() const; 245 Vector<String> consoleMessageArgumentCounts(Document*) const; 246 PassRefPtr<DOMWindow> openDummyInspectorFrontend(const String& url); 247 void closeDummyInspectorFrontend(); 248 Vector<unsigned long> setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes); 249 void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState&); 250 251 String counterValue(Element*); 252 253 int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600); 254 Vector<String> shortcutIconURLs(Document*) const; 255 Vector<String> allIconURLs(Document*) const; 256 257 int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600); 258 String pageProperty(String, int, ExceptionState& = ASSERT_NO_EXCEPTION) const; 259 String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionState& = ASSERT_NO_EXCEPTION) const; 260 261 void setDeviceScaleFactor(float scaleFactor, ExceptionState&); 262 263 void setIsCursorVisible(Document*, bool, ExceptionState&); 264 265 void webkitWillEnterFullScreenForElement(Document*, Element*); 266 void webkitDidEnterFullScreenForElement(Document*, Element*); 267 void webkitWillExitFullScreenForElement(Document*, Element*); 268 void webkitDidExitFullScreenForElement(Document*, Element*); 269 270 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme); 271 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme); 272 273 PassRefPtr<MallocStatistics> mallocStatistics() const; 274 PassRefPtr<TypeConversions> typeConversions() const; 275 276 Vector<String> getReferencedFilePaths() const; 277 278 void startTrackingRepaints(Document*, ExceptionState&); 279 void stopTrackingRepaints(Document*, ExceptionState&); 280 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionState&); 281 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionState&); 282 283 PassRefPtr<ClientRectList> draggableRegions(Document*, ExceptionState&); 284 PassRefPtr<ClientRectList> nonDraggableRegions(Document*, ExceptionState&); 285 286 PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const; 287 PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const; 288 289 String getCurrentCursorInfo(Document*, ExceptionState&); 290 291 String markerTextForListItem(Element*, ExceptionState&); 292 293 void forceReload(bool endToEnd); 294 295 String getImageSourceURL(Element*, ExceptionState&); 296 297 bool isSelectPopupVisible(Node*); 298 299 PassRefPtr<ClientRect> selectionBounds(ExceptionState&); 300 String baseURL(Document*, ExceptionState&); 301 302 bool loseSharedGraphicsContext3D(); 303 304 void forceCompositingUpdate(Document*, ExceptionState&); 305 306 bool isCompositorFramePending(Document*, ExceptionState&); 307 308 void setZoomFactor(float); 309 310 private: 311 explicit Internals(Document*); 312 Document* contextDocument() const; 313 Frame* frame() const; 314 Vector<String> iconURLs(Document*, int iconTypesMask) const; 315 PassRefPtr<ClientRectList> annotatedRegions(Document*, bool draggable, ExceptionState&); 316 317 DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionState&); 318 RefPtr<DOMWindow> m_frontendWindow; 319 OwnPtr<InspectorFrontendChannelDummy> m_frontendChannel; 320 RefPtr<InternalRuntimeFlags> m_runtimeFlags; 321 RefPtr<ScrollingCoordinator> m_scrollingCoordinator; 322 RefPtr<InternalProfilers> m_profilers; 323 }; 324 325 } // namespace WebCore 326 327 #endif 328