Internals.h 15 KB

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