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 "CSSComputedStyleDeclaration.h" 31#include "ContextDestructionObserver.h" 32#include "ExceptionCodePlaceholder.h" 33#include "NodeList.h" 34#include <wtf/ArrayBuffer.h> 35#include <wtf/Float32Array.h> 36#include <wtf/PassRefPtr.h> 37#include <wtf/RefCounted.h> 38#include <wtf/text/WTFString.h> 39 40namespace WebCore { 41 42class ClientRect; 43class ClientRectList; 44class DOMStringList; 45class DOMWindow; 46class Document; 47class DocumentMarker; 48class Element; 49class Frame; 50class InspectorFrontendChannelDummy; 51class InternalSettings; 52class MemoryInfo; 53class Node; 54class Page; 55class Range; 56class ScriptExecutionContext; 57class ShadowRoot; 58class WebKitPoint; 59class MallocStatistics; 60class SerializedScriptValue; 61class TimeRanges; 62class TypeConversions; 63 64typedef int ExceptionCode; 65 66class Internals : public RefCounted<Internals> 67 , public ContextDestructionObserver { 68public: 69 static PassRefPtr<Internals> create(Document*); 70 virtual ~Internals(); 71 72 static void resetToConsistentState(Page*); 73 74 String elementRenderTreeAsText(Element*, ExceptionCode&); 75 76 String address(Node*); 77 78 bool isPreloaded(const String& url); 79 bool isLoadingFromMemoryCache(const String& url); 80 81 size_t numberOfScopedHTMLStyleChildren(const Node*, ExceptionCode&) const; 82 PassRefPtr<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Node*, ExceptionCode&) const; 83 84#if ENABLE(SHADOW_DOM) 85 typedef ShadowRoot ShadowRootIfShadowDOMEnabledOrNode; 86#else 87 typedef Node ShadowRootIfShadowDOMEnabledOrNode; 88#endif 89 ShadowRootIfShadowDOMEnabledOrNode* ensureShadowRoot(Element* host, ExceptionCode&); 90 ShadowRootIfShadowDOMEnabledOrNode* createShadowRoot(Element* host, ExceptionCode&); 91 ShadowRootIfShadowDOMEnabledOrNode* shadowRoot(Element* host, ExceptionCode&); 92 String shadowRootType(const Node*, ExceptionCode&) const; 93 Element* includerFor(Node*, ExceptionCode&); 94 String shadowPseudoId(Element*, ExceptionCode&); 95 void setShadowPseudoId(Element*, const String&, ExceptionCode&); 96 97 // CSS Animation testing. 98 unsigned numberOfActiveAnimations() const; 99 bool animationsAreSuspended(Document*, ExceptionCode&) const; 100 void suspendAnimations(Document*, ExceptionCode&) const; 101 void resumeAnimations(Document*, ExceptionCode&) const; 102 bool pauseAnimationAtTimeOnElement(const String& animationName, double pauseTime, Element*, ExceptionCode&); 103 bool pauseAnimationAtTimeOnPseudoElement(const String& animationName, double pauseTime, Element*, const String& pseudoId, ExceptionCode&); 104 105 // CSS Transition testing. 106 bool pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element*, ExceptionCode&); 107 bool pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element*, const String& pseudoId, ExceptionCode&); 108 109 PassRefPtr<Element> createContentElement(ExceptionCode&); 110 bool isValidContentSelect(Element* insertionPoint, ExceptionCode&); 111 Node* treeScopeRootNode(Node*, ExceptionCode&); 112 Node* parentTreeScope(Node*, ExceptionCode&); 113 bool hasSelectorForIdInShadow(Element* host, const String& idValue, ExceptionCode&); 114 bool hasSelectorForClassInShadow(Element* host, const String& className, ExceptionCode&); 115 bool hasSelectorForAttributeInShadow(Element* host, const String& attributeName, ExceptionCode&); 116 bool hasSelectorForPseudoClassInShadow(Element* host, const String& pseudoClass, ExceptionCode&); 117 118 bool attached(Node*, ExceptionCode&); 119 120 // FIXME: Rename these functions if walker is prefered. 121 Node* nextSiblingByWalker(Node*, ExceptionCode&); 122 Node* firstChildByWalker(Node*, ExceptionCode&); 123 Node* lastChildByWalker(Node*, ExceptionCode&); 124 Node* nextNodeByWalker(Node*, ExceptionCode&); 125 Node* previousNodeByWalker(Node*, ExceptionCode&); 126 127 String visiblePlaceholder(Element*); 128#if ENABLE(INPUT_TYPE_COLOR) 129 void selectColorInColorChooser(Element*, const String& colorValue); 130#endif 131 Vector<String> formControlStateOfPreviousHistoryItem(ExceptionCode&); 132 void setFormControlStateOfPreviousHistoryItem(const Vector<String>&, ExceptionCode&); 133 134 PassRefPtr<ClientRect> absoluteCaretBounds(ExceptionCode&); 135 136 PassRefPtr<ClientRect> boundingBox(Element*, ExceptionCode&); 137 138 PassRefPtr<ClientRectList> inspectorHighlightRects(Document*, ExceptionCode&); 139 140 unsigned markerCountForNode(Node*, const String&, ExceptionCode&); 141 PassRefPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionCode&); 142 String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionCode&); 143 void addTextMatchMarker(const Range*, bool isActive); 144 145 void setScrollViewPosition(Document*, long x, long y, ExceptionCode&); 146 void setPagination(Document* document, const String& mode, int gap, ExceptionCode& ec) { setPagination(document, mode, gap, 0, ec); } 147 void setPagination(Document*, const String& mode, int gap, int pageLength, ExceptionCode&); 148 String configurationForViewport(Document*, float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode&); 149 150 bool wasLastChangeUserEdit(Element* textField, ExceptionCode&); 151 bool elementShouldAutoComplete(Element* inputElement, ExceptionCode&); 152 String suggestedValue(Element* inputElement, ExceptionCode&); 153 void setSuggestedValue(Element* inputElement, const String&, ExceptionCode&); 154 void setEditingValue(Element* inputElement, const String&, ExceptionCode&); 155 void setAutofilled(Element*, bool enabled, ExceptionCode&); 156 void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionCode&); 157 158 void paintControlTints(Document*, ExceptionCode&); 159 160 PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionCode&); 161 unsigned locationFromRange(Element* scope, const Range*, ExceptionCode&); 162 unsigned lengthFromRange(Element* scope, const Range*, ExceptionCode&); 163 String rangeAsText(const Range*, ExceptionCode&); 164 165 void setDelegatesScrolling(bool enabled, Document*, ExceptionCode&); 166#if ENABLE(TOUCH_ADJUSTMENT) 167 PassRefPtr<WebKitPoint> touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionCode&); 168 Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionCode&); 169 PassRefPtr<WebKitPoint> touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionCode&); 170 Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionCode&); 171 PassRefPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionCode&); 172#endif 173 174 int lastSpellCheckRequestSequence(Document*, ExceptionCode&); 175 int lastSpellCheckProcessedSequence(Document*, ExceptionCode&); 176 177 Vector<String> userPreferredLanguages() const; 178 void setUserPreferredLanguages(const Vector<String>&); 179 180 unsigned wheelEventHandlerCount(Document*, ExceptionCode&); 181 unsigned touchEventHandlerCount(Document*, ExceptionCode&); 182#if ENABLE(TOUCH_EVENT_TRACKING) 183 PassRefPtr<ClientRectList> touchEventTargetClientRects(Document*, ExceptionCode&); 184#endif 185 186 PassRefPtr<NodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding, 187 unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionCode&) const; 188 189 void emitInspectorDidBeginFrame(); 190 void emitInspectorDidCancelFrame(); 191 192 bool hasSpellingMarker(Document*, int from, int length, ExceptionCode&); 193 bool hasGrammarMarker(Document*, int from, int length, ExceptionCode&); 194 bool hasAutocorrectedMarker(Document*, int from, int length, ExceptionCode&); 195 void setContinuousSpellCheckingEnabled(bool enabled, ExceptionCode&); 196 void setAutomaticQuoteSubstitutionEnabled(bool enabled, ExceptionCode&); 197 void setAutomaticLinkDetectionEnabled(bool enabled, ExceptionCode&); 198 void setAutomaticDashSubstitutionEnabled(bool enabled, ExceptionCode&); 199 void setAutomaticTextReplacementEnabled(bool enabled, ExceptionCode&); 200 void setAutomaticSpellingCorrectionEnabled(bool enabled, ExceptionCode&); 201 202 bool isOverwriteModeEnabled(Document*, ExceptionCode&); 203 void toggleOverwriteModeEnabled(Document*, ExceptionCode&); 204 205 unsigned numberOfScrollableAreas(Document*, ExceptionCode&); 206 207 bool isPageBoxVisible(Document*, int pageNumber, ExceptionCode&); 208 209 static const char* internalsId; 210 211 InternalSettings* settings() const; 212 unsigned workerThreadCount() const; 213 214 void setBatteryStatus(Document*, const String& eventType, bool charging, double chargingTime, double dischargingTime, double level, ExceptionCode&); 215 216 void setNetworkInformation(Document*, const String& eventType, double bandwidth, bool metered, ExceptionCode&); 217 218 void setDeviceProximity(Document*, const String& eventType, double value, double min, double max, ExceptionCode&); 219 220 enum { 221 // Values need to be kept in sync with Internals.idl. 222 LAYER_TREE_INCLUDES_VISIBLE_RECTS = 1, 223 LAYER_TREE_INCLUDES_TILE_CACHES = 2, 224 LAYER_TREE_INCLUDES_REPAINT_RECTS = 4, 225 LAYER_TREE_INCLUDES_PAINTING_PHASES = 8 226 }; 227 String layerTreeAsText(Document*, unsigned flags, ExceptionCode&) const; 228 String layerTreeAsText(Document*, ExceptionCode&) const; 229 String repaintRectsAsText(Document*, ExceptionCode&) const; 230 String scrollingStateTreeAsText(Document*, ExceptionCode&) const; 231 String mainThreadScrollingReasons(Document*, ExceptionCode&) const; 232 PassRefPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionCode&) const; 233 234 void garbageCollectDocumentResources(Document*, ExceptionCode&) const; 235 236 void allowRoundingHacks() const; 237 238 void insertAuthorCSS(Document*, const String&) const; 239 void insertUserCSS(Document*, const String&) const; 240 241#if ENABLE(INSPECTOR) 242 unsigned numberOfLiveNodes() const; 243 unsigned numberOfLiveDocuments() const; 244 Vector<String> consoleMessageArgumentCounts(Document*) const; 245 PassRefPtr<DOMWindow> openDummyInspectorFrontend(const String& url); 246 void closeDummyInspectorFrontend(); 247 void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionCode&); 248 void setJavaScriptProfilingEnabled(bool enabled, ExceptionCode&); 249#endif 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, ExceptionCode& = ASSERT_NO_EXCEPTION) const; 259 String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionCode& = ASSERT_NO_EXCEPTION) const; 260 261 void setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode&); 262 263 void setHeaderHeight(Document*, float); 264 void setFooterHeight(Document*, float); 265 266#if ENABLE(FULLSCREEN_API) 267 void webkitWillEnterFullScreenForElement(Document*, Element*); 268 void webkitDidEnterFullScreenForElement(Document*, Element*); 269 void webkitWillExitFullScreenForElement(Document*, Element*); 270 void webkitDidExitFullScreenForElement(Document*, Element*); 271#endif 272 273 void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme); 274 void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme); 275 276 PassRefPtr<MallocStatistics> mallocStatistics() const; 277 PassRefPtr<TypeConversions> typeConversions() const; 278 PassRefPtr<MemoryInfo> memoryInfo() const; 279 280 Vector<String> getReferencedFilePaths() const; 281 282 void startTrackingRepaints(Document*, ExceptionCode&); 283 void stopTrackingRepaints(Document*, ExceptionCode&); 284 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(ExceptionCode&); 285 void updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(Node*, ExceptionCode&); 286 287 PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const; 288 PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const; 289 290 void setUsesOverlayScrollbars(bool enabled); 291 292 String getCurrentCursorInfo(Document*, ExceptionCode&); 293 294 String markerTextForListItem(Element*, ExceptionCode&); 295 296 void forceReload(bool endToEnd); 297 298#if ENABLE(ENCRYPTED_MEDIA_V2) 299 void initializeMockCDM(); 300#endif 301 302#if ENABLE(SPEECH_SYNTHESIS) 303 void enableMockSpeechSynthesizer(); 304#endif 305 306 String getImageSourceURL(Element*, ExceptionCode&); 307 308#if ENABLE(VIDEO) 309 void simulateAudioInterruption(Node*); 310#endif 311 312 bool isSelectPopupVisible(Node*); 313 314 String captionsStyleSheetOverride(ExceptionCode&); 315 void setCaptionsStyleSheetOverride(const String&, ExceptionCode&); 316 void setPrimaryAudioTrackLanguageOverride(const String&, ExceptionCode&); 317 void setCaptionDisplayMode(const String&, ExceptionCode&); 318 319#if ENABLE(VIDEO) 320 PassRefPtr<TimeRanges> createTimeRanges(Float32Array* startTimes, Float32Array* endTimes); 321 double closestTimeToTimeRanges(double time, TimeRanges*); 322#endif 323 324 PassRefPtr<ClientRect> selectionBounds(ExceptionCode&); 325 326private: 327 explicit Internals(Document*); 328 Document* contextDocument() const; 329 Frame* frame() const; 330 Vector<String> iconURLs(Document*, int iconTypesMask) const; 331 332 DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionCode&); 333#if ENABLE(INSPECTOR) 334 RefPtr<DOMWindow> m_frontendWindow; 335 OwnPtr<InspectorFrontendChannelDummy> m_frontendChannel; 336#endif 337}; 338 339} // namespace WebCore 340 341#endif 342