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