Home | History | Annotate | Download | only in testing
      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 ScriptExecutionContext;
     65 class SerializedScriptValue;
     66 class ShadowRoot;
     67 class TypeConversions;
     68 
     69 class Internals : public RefCounted<Internals>
     70     , public ContextLifecycleObserver
     71     , public ScrollingCoordinator::TouchEventTargetRectsObserver {
     72 public:
     73     static PassRefPtr<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     PassRefPtr<GCObservation> observeGC(ScriptValue);
     83 
     84     bool isPreloaded(const String& url);
     85     bool isLoadingFromMemoryCache(const String& url);
     86 
     87     void crash();
     88 
     89     size_t numberOfScopedHTMLStyleChildren(const Node*, ExceptionState&) const;
     90     PassRefPtr<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Node*, ExceptionState&) const;
     91 
     92     ShadowRoot* ensureShadowRoot(Element* host, ExceptionState&);
     93     ShadowRoot* shadowRoot(Element* host, ExceptionState&);
     94     ShadowRoot* youngestShadowRoot(Element* host, ExceptionState&);
     95     ShadowRoot* oldestShadowRoot(Element* host, ExceptionState&);
     96     ShadowRoot* youngerShadowRoot(Node* shadow, ExceptionState&);
     97     ShadowRoot* olderShadowRoot(Node* shadow, ExceptionState&);
     98     String shadowRootType(const Node*, ExceptionState&) const;
     99     bool hasShadowInsertionPoint(const Node*, ExceptionState&) const;
    100     bool hasContentElement(const Node*, ExceptionState&) const;
    101     size_t countElementShadow(const Node*, ExceptionState&) const;
    102     Element* includerFor(Node*, ExceptionState&);
    103     String shadowPseudoId(Element*, ExceptionState&);
    104     void setShadowPseudoId(Element*, const String&, ExceptionState&);
    105 
    106     // CSS Animation / Transition testing.
    107     unsigned numberOfActiveAnimations() const;
    108     void suspendAnimations(Document*, ExceptionState&) const;
    109     void resumeAnimations(Document*, ExceptionState&) 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     bool attached(Node*, ExceptionState&);
    123 
    124     // FIXME: Rename these functions if walker is prefered.
    125     Node* nextSiblingByWalker(Node*, ExceptionState&);
    126     Node* firstChildByWalker(Node*, ExceptionState&);
    127     Node* lastChildByWalker(Node*, ExceptionState&);
    128     Node* nextNodeByWalker(Node*, ExceptionState&);
    129     Node* previousNodeByWalker(Node*, ExceptionState&);
    130 
    131     String visiblePlaceholder(Element*);
    132     void selectColorInColorChooser(Element*, const String& colorValue);
    133     Vector<String> formControlStateOfPreviousHistoryItem(ExceptionState&);
    134     void setFormControlStateOfPreviousHistoryItem(const Vector<String>&, ExceptionState&);
    135     void setEnableMockPagePopup(bool, ExceptionState&);
    136     PassRefPtr<PagePopupController> pagePopupController();
    137 
    138     PassRefPtr<ClientRect> absoluteCaretBounds(ExceptionState&);
    139 
    140     PassRefPtr<ClientRect> boundingBox(Element*, ExceptionState&);
    141 
    142     PassRefPtr<ClientRectList> inspectorHighlightRects(Document*, ExceptionState&);
    143 
    144     unsigned markerCountForNode(Node*, const String&, ExceptionState&);
    145     PassRefPtr<Range> markerRangeForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
    146     String markerDescriptionForNode(Node*, const String& markerType, unsigned index, ExceptionState&);
    147     void addTextMatchMarker(const Range*, bool isActive);
    148 
    149     void setScrollViewPosition(Document*, long x, long y, ExceptionState&);
    150     void setPagination(Document* document, const String& mode, int gap, ExceptionState& ec) { setPagination(document, mode, gap, 0, ec); }
    151     void setPagination(Document*, const String& mode, int gap, int pageLength, ExceptionState&);
    152     String configurationForViewport(Document*, float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionState&);
    153 
    154     bool wasLastChangeUserEdit(Element* textField, ExceptionState&);
    155     bool elementShouldAutoComplete(Element* inputElement, ExceptionState&);
    156     String suggestedValue(Element* inputElement, ExceptionState&);
    157     void setSuggestedValue(Element* inputElement, const String&, ExceptionState&);
    158     void setEditingValue(Element* inputElement, const String&, ExceptionState&);
    159     void setAutofilled(Element*, bool enabled, ExceptionState&);
    160     void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionState&);
    161 
    162     void paintControlTints(Document*, ExceptionState&);
    163 
    164     PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionState&);
    165     unsigned locationFromRange(Element* scope, const Range*, ExceptionState&);
    166     unsigned lengthFromRange(Element* scope, const Range*, ExceptionState&);
    167     String rangeAsText(const Range*, ExceptionState&);
    168 
    169     PassRefPtr<DOMPoint> touchPositionAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
    170     Node* touchNodeAdjustedToBestClickableNode(long x, long y, long width, long height, Document*, ExceptionState&);
    171     PassRefPtr<DOMPoint> touchPositionAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
    172     Node* touchNodeAdjustedToBestContextMenuNode(long x, long y, long width, long height, Document*, ExceptionState&);
    173     PassRefPtr<ClientRect> bestZoomableAreaForTouchPoint(long x, long y, long width, long height, Document*, ExceptionState&);
    174 
    175     int lastSpellCheckRequestSequence(Document*, ExceptionState&);
    176     int lastSpellCheckProcessedSequence(Document*, ExceptionState&);
    177 
    178     Vector<String> userPreferredLanguages() const;
    179     void setUserPreferredLanguages(const Vector<String>&);
    180 
    181     unsigned wheelEventHandlerCount(Document*, ExceptionState&);
    182     unsigned touchEventHandlerCount(Document*, ExceptionState&);
    183     LayerRectList* touchEventTargetLayerRects(Document*, ExceptionState&);
    184     unsigned touchEventTargetLayerRectsUpdateCount(Document*, ExceptionState&);
    185     virtual void touchEventTargetRectsChanged(const LayerHitTestRects&);
    186 
    187     // This is used to test rect based hit testing like what's done on touch screens.
    188     PassRefPtr<NodeList> nodesFromRect(Document*, int x, int y, unsigned topPadding, unsigned rightPadding,
    189         unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent, ExceptionState&) const;
    190 
    191     void emitInspectorDidBeginFrame();
    192     void emitInspectorDidCancelFrame();
    193 
    194     bool hasSpellingMarker(Document*, int from, int length, ExceptionState&);
    195     bool hasGrammarMarker(Document*, int from, int length, ExceptionState&);
    196     void setContinuousSpellCheckingEnabled(bool enabled, ExceptionState&);
    197 
    198     bool isOverwriteModeEnabled(Document*, ExceptionState&);
    199     void toggleOverwriteModeEnabled(Document*, ExceptionState&);
    200 
    201     unsigned numberOfScrollableAreas(Document*, ExceptionState&);
    202 
    203     bool isPageBoxVisible(Document*, int pageNumber, ExceptionState&);
    204 
    205     static const char* internalsId;
    206 
    207     InternalSettings* settings() const;
    208     InternalRuntimeFlags* runtimeFlags() const;
    209     InternalProfilers* profilers();
    210     unsigned workerThreadCount() const;
    211 
    212     void setDeviceProximity(Document*, const String& eventType, double value, double min, double max, ExceptionState&);
    213 
    214     String layerTreeAsText(Document*, unsigned flags, ExceptionState&) const;
    215     String layerTreeAsText(Document*, ExceptionState&) const;
    216     String elementLayerTreeAsText(Element*, unsigned flags, ExceptionState&) const;
    217     String elementLayerTreeAsText(Element*, ExceptionState&) const;
    218 
    219     PassRefPtr<NodeList> paintOrderListBeforePromote(Element*, ExceptionState&);
    220     PassRefPtr<NodeList> paintOrderListAfterPromote(Element*, ExceptionState&);
    221 
    222     void setNeedsCompositedScrolling(Element*, unsigned value, ExceptionState&);
    223 
    224     String repaintRectsAsText(Document*, ExceptionState&) const;
    225     String scrollingStateTreeAsText(Document*, ExceptionState&) const;
    226     String mainThreadScrollingReasons(Document*, ExceptionState&) const;
    227     PassRefPtr<ClientRectList> nonFastScrollableRects(Document*, ExceptionState&) const;
    228 
    229     void garbageCollectDocumentResources(Document*, ExceptionState&) const;
    230     void evictAllResources() const;
    231 
    232     void allowRoundingHacks() const;
    233 
    234     void insertAuthorCSS(Document*, const String&) const;
    235     void insertUserCSS(Document*, const String&) const;
    236 
    237     unsigned numberOfLiveNodes() const;
    238     unsigned numberOfLiveDocuments() const;
    239     Vector<String> consoleMessageArgumentCounts(Document*) const;
    240     PassRefPtr<DOMWindow> openDummyInspectorFrontend(const String& url);
    241     void closeDummyInspectorFrontend();
    242     Vector<unsigned long> setMemoryCacheCapacities(unsigned long minDeadBytes, unsigned long maxDeadBytes, unsigned long totalBytes);
    243     void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionState&);
    244 
    245     String counterValue(Element*);
    246 
    247     int pageNumber(Element*, float pageWidth = 800, float pageHeight = 600);
    248     Vector<String> shortcutIconURLs(Document*) const;
    249     Vector<String> allIconURLs(Document*) const;
    250 
    251     int numberOfPages(float pageWidthInPixels = 800, float pageHeightInPixels = 600);
    252     String pageProperty(String, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
    253     String pageSizeAndMarginsInPixels(int, int, int, int, int, int, int, ExceptionState& = ASSERT_NO_EXCEPTION) const;
    254 
    255     void setDeviceScaleFactor(float scaleFactor, ExceptionState&);
    256 
    257     void setIsCursorVisible(Document*, bool, ExceptionState&);
    258 
    259     void webkitWillEnterFullScreenForElement(Document*, Element*);
    260     void webkitDidEnterFullScreenForElement(Document*, Element*);
    261     void webkitWillExitFullScreenForElement(Document*, Element*);
    262     void webkitDidExitFullScreenForElement(Document*, Element*);
    263 
    264     void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
    265     void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
    266 
    267     PassRefPtr<MallocStatistics> mallocStatistics() const;
    268     PassRefPtr<TypeConversions> typeConversions() const;
    269 
    270     Vector<String> getReferencedFilePaths() const;
    271 
    272     void startTrackingRepaints(Document*, ExceptionState&);
    273     void stopTrackingRepaints(Document*, ExceptionState&);
    274 
    275     PassRefPtr<ArrayBuffer> serializeObject(PassRefPtr<SerializedScriptValue>) const;
    276     PassRefPtr<SerializedScriptValue> deserializeBuffer(PassRefPtr<ArrayBuffer>) const;
    277 
    278     void setUsesOverlayScrollbars(bool enabled);
    279 
    280     String getCurrentCursorInfo(Document*, ExceptionState&);
    281 
    282     String markerTextForListItem(Element*, ExceptionState&);
    283 
    284     void forceReload(bool endToEnd);
    285 
    286     void enableMockSpeechSynthesizer();
    287 
    288     String getImageSourceURL(Element*, ExceptionState&);
    289 
    290     bool isSelectPopupVisible(Node*);
    291 
    292     PassRefPtr<ClientRect> selectionBounds(ExceptionState&);
    293     String baseURL(Document*, ExceptionState&);
    294 
    295     bool loseSharedGraphicsContext3D();
    296 
    297 private:
    298     explicit Internals(Document*);
    299     Document* contextDocument() const;
    300     Frame* frame() const;
    301     Vector<String> iconURLs(Document*, int iconTypesMask) const;
    302 
    303     DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionState&);
    304     RefPtr<DOMWindow> m_frontendWindow;
    305     OwnPtr<InspectorFrontendChannelDummy> m_frontendChannel;
    306     RefPtr<InternalRuntimeFlags> m_runtimeFlags;
    307     RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
    308     int m_touchEventTargetRectUpdateCount;
    309     RefPtr<LayerRectList> m_currentTouchEventRects;
    310     RefPtr<InternalProfilers> m_profilers;
    311 };
    312 
    313 } // namespace WebCore
    314 
    315 #endif
    316