1 /*
2     Copyright (C) 2010 Robert Hogan <robert@roberthogan.net>
3     Copyright (C) 2008,2009,2010 Nokia Corporation and/or its subsidiary(-ies)
4     Copyright (C) 2007 Staikos Computing Services Inc.
5     Copyright (C) 2007 Apple Inc.
6 
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Library General Public
9     License as published by the Free Software Foundation; either
10     version 2 of the License, or (at your option) any later version.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Library General Public License for more details.
16 
17     You should have received a copy of the GNU Library General Public License
18     along with this library; see the file COPYING.LIB.  If not, write to
19     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20     Boston, MA 02110-1301, USA.
21 */
22 
23 #ifndef DumpRenderTreeSupportQt_h
24 #define DumpRenderTreeSupportQt_h
25 
26 #include "qwebkitglobal.h"
27 #include <QVariant>
28 
29 namespace WebCore {
30 class Text;
31 class Node;
32 }
33 
34 
35 #if defined(WTF_USE_V8) && WTF_USE_V8
36 namespace V8 {
37 namespace Bindings {
38 class QtDRTNodeRuntime;
39 }
40 }
41 #else
42 namespace JSC {
43 namespace Bindings {
44 class QtDRTNodeRuntime;
45 }
46 }
47 #endif
48 
49 class QWebElement;
50 class QWebFrame;
51 class QWebPage;
52 class QWebHistoryItem;
53 class QWebScriptWorld;
54 
55 QT_BEGIN_NAMESPACE
56 class QUrl;
57 QT_END_NAMESPACE
58 
59 extern QMap<int, QWebScriptWorld*> m_worldMap;
60 
61 // Used to pass WebCore::Node's to layout tests using LayoutTestController
62 class QWEBKIT_EXPORT QDRTNode {
63 public:
64     QDRTNode();
65     QDRTNode(const QDRTNode&);
66     QDRTNode &operator=(const QDRTNode&);
67     ~QDRTNode();
68 
69 private:
70     explicit QDRTNode(WebCore::Node*);
71 
72     friend class DumpRenderTreeSupportQt;
73 
74 #if defined(WTF_USE_V8) && WTF_USE_V8
75     friend class V8::Bindings::QtDRTNodeRuntime;
76 #else
77     friend class JSC::Bindings::QtDRTNodeRuntime;
78 #endif
79 
80     WebCore::Node* m_node;
81 };
82 
Q_DECLARE_METATYPE(QDRTNode)83 Q_DECLARE_METATYPE(QDRTNode)
84 
85 class QWEBKIT_EXPORT DumpRenderTreeSupportQt {
86 
87 public:
88 
89     DumpRenderTreeSupportQt();
90     ~DumpRenderTreeSupportQt();
91 
92 
93     static void executeCoreCommandByName(QWebPage* page, const QString& name, const QString& value);
94     static bool isCommandEnabled(QWebPage* page, const QString& name);
95     static bool findString(QWebPage* page, const QString& string, const QStringList& optionArray);
96     static void setSmartInsertDeleteEnabled(QWebPage* page, bool enabled);
97     static void setSelectTrailingWhitespaceEnabled(QWebPage* page, bool enabled);
98     static QVariantList selectedRange(QWebPage* page);
99     static QVariantList firstRectForCharacterRange(QWebPage* page, int location, int length);
100     static void confirmComposition(QWebPage*, const char* text);
101 
102     static bool pauseAnimation(QWebFrame*, const QString& name, double time, const QString& elementId);
103     static bool pauseTransitionOfProperty(QWebFrame*, const QString& name, double time, const QString& elementId);
104     static bool pauseSVGAnimation(QWebFrame*, const QString& animationId, double time, const QString& elementId);
105     static void suspendActiveDOMObjects(QWebFrame* frame);
106     static void resumeActiveDOMObjects(QWebFrame* frame);
107 
108     static void setDomainRelaxationForbiddenForURLScheme(bool forbidden, const QString& scheme);
109     static void setFrameFlatteningEnabled(QWebPage*, bool);
110     static void setCaretBrowsingEnabled(QWebPage* page, bool value);
111     static void setAuthorAndUserStylesEnabled(QWebPage*, bool);
112     static void setMediaType(QWebFrame* qframe, const QString& type);
113     static void setDumpRenderTreeModeEnabled(bool b);
114 
115     static void garbageCollectorCollect();
116     static void garbageCollectorCollectOnAlternateThread(bool waitUntilDone);
117     static void setAutofilled(const QWebElement&, bool enabled);
118     static void setJavaScriptProfilingEnabled(QWebFrame*, bool enabled);
119     static void setValueForUser(const QWebElement&, const QString& value);
120     static int javaScriptObjectsCount();
121     static void clearScriptWorlds();
122     static void evaluateScriptInIsolatedWorld(QWebFrame* frame, int worldID, const QString& script);
123 
124     static void setTimelineProfilingEnabled(QWebPage*, bool enabled);
125     static void webInspectorExecuteScript(QWebPage* page, long callId, const QString& script);
126     static void webInspectorShow(QWebPage* page);
127     static void webInspectorClose(QWebPage* page);
128 
129     static QString webPageGroupName(QWebPage *page);
130     static QString counterValueForElementById(QWebFrame* frame, const QString& id);
131     static void webPageSetGroupName(QWebPage* page, const QString& groupName);
132     static void clearFrameName(QWebFrame* frame);
133     static void overwritePluginDirectories();
134     static int numberOfActiveAnimations(QWebFrame*);
135     static void suspendAnimations(QWebFrame*);
136     static void resumeAnimations(QWebFrame*);
137     static int numberOfPages(QWebFrame* frame, float width, float height);
138     static int pageNumberForElementById(QWebFrame* frame, const QString& id, float width, float height);
139     static bool hasDocumentElement(QWebFrame* frame);
140     static bool elementDoesAutoCompleteForElementWithId(QWebFrame* frame, const QString& elementId);
141     static void setEditingBehavior(QWebPage* page, const QString& editingBehavior);
142 
143     static void clearAllApplicationCaches();
144 
145     static void whiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains);
146     static void removeWhiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains);
147     static void resetOriginAccessWhiteLists();
148 
149     static void activeMockDeviceOrientationClient(bool b);
150     static void removeMockDeviceOrientation();
151     static void setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma);
152 
153     static void resetGeolocationMock(QWebPage*);
154     static void setMockGeolocationPermission(QWebPage*, bool allowed);
155     static void setMockGeolocationPosition(QWebPage*, double latitude, double longitude, double accuracy);
156     static void setMockGeolocationError(QWebPage*, int errorCode, const QString& message);
157     static int numberOfPendingGeolocationPermissionRequests(QWebPage*);
158 
159     static int workerThreadCount();
160 
161     static QString markerTextForListItem(const QWebElement& listItem);
162     static QVariantMap computedStyleIncludingVisitedInfo(const QWebElement& element);
163     static QString plainText(const QVariant& rng);
164 
165     static void dumpFrameLoader(bool b);
166     static void dumpProgressFinishedCallback(bool);
167     static void dumpUserGestureInFrameLoader(bool b);
168     static void dumpResourceLoadCallbacks(bool b);
169     static void dumpResourceResponseMIMETypes(bool b);
170     static void dumpResourceLoadCallbacksPath(const QString& path);
171     static void setWillSendRequestReturnsNullOnRedirect(bool b);
172     static void setWillSendRequestReturnsNull(bool b);
173     static void setWillSendRequestClearHeaders(const QStringList& headers);
174     static void dumpHistoryCallbacks(bool b);
175     static void dumpVisitedLinksCallbacks(bool b);
176 
177     static void setDeferMainResourceDataLoad(bool b);
178 
179     static void dumpEditingCallbacks(bool b);
180     static void dumpSetAcceptsEditing(bool b);
181 
182     static void dumpNotification(bool b);
183 
184     static QMap<QString, QWebHistoryItem> getChildHistoryItems(const QWebHistoryItem& historyItem);
185     static bool isTargetItem(const QWebHistoryItem& historyItem);
186     static QString historyItemTarget(const QWebHistoryItem& historyItem);
187 
188     static bool shouldClose(QWebFrame* frame);
189 
190     static void setCustomPolicyDelegate(bool enabled, bool permissive);
191 
192     static bool isPageBoxVisible(QWebFrame* frame, int pageIndex);
193 
194     static QString pageSizeAndMarginsInPixels(QWebFrame* frame, int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
195     static QString pageProperty(QWebFrame* frame, const QString& propertyName, int pageNumber);
196     static void addUserStyleSheet(QWebPage* page, const QString& sourceCode);
197     static void simulateDesktopNotificationClick(const QString& title);
198     static QString viewportAsText(QWebPage*, int deviceDPI, const QSize& deviceSize, const QSize& availableSize);
199 
200     static void scalePageBy(QWebFrame*, float scale, const QPoint& origin);
201 
202     static QVariantList nodesFromRect(const QWebElement& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping);
203     static QString responseMimeType(QWebFrame*);
204     static void clearOpener(QWebFrame*);
205     static void addURLToRedirect(const QString& origin, const QString& destination);
206     static QStringList contextMenu(QWebPage*);
207 
208     static double defaultMinimumTimerInterval(); // Not really tied to WebView
209     static void setMinimumTimerInterval(QWebPage*, double);
210 
211     static QUrl mediaContentUrlByElementId(QWebFrame*, const QString& elementId);
212     static void setAlternateHtml(QWebFrame*, const QString& html, const QUrl& baseUrl, const QUrl& failingUrl);
213 
214     static QVariant shadowRoot(const QWebElement&);
215     static QVariant ensureShadowRoot(const QWebElement&);
216     static void removeShadowRoot(const QWebElement&);
217     static QString shadowPseudoId(const QWebElement&);
218 
219     static QString layerTreeAsText(QWebFrame*);
220 
221     static void injectInternalsObject(QWebFrame*);
222     static void resetInternalsObject(QWebFrame*);
223 };
224 
225 #endif
226