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
29namespace WebCore {
30class Text;
31class Node;
32}
33
34
35#if defined(WTF_USE_V8) && WTF_USE_V8
36namespace V8 {
37namespace Bindings {
38class QtDRTNodeRuntime;
39}
40}
41#else
42namespace JSC {
43namespace Bindings {
44class QtDRTNodeRuntime;
45}
46}
47#endif
48
49class QWebElement;
50class QWebFrame;
51class QWebPage;
52class QWebHistoryItem;
53class QWebScriptWorld;
54class QUrl;
55
56extern QMap<int, QWebScriptWorld*> m_worldMap;
57
58// Used to pass WebCore::Node's to layout tests using LayoutTestController
59class QWEBKIT_EXPORT QDRTNode {
60public:
61    QDRTNode();
62    QDRTNode(const QDRTNode&);
63    QDRTNode &operator=(const QDRTNode&);
64    ~QDRTNode();
65
66private:
67    explicit QDRTNode(WebCore::Node*);
68
69    friend class DumpRenderTreeSupportQt;
70
71#if defined(WTF_USE_V8) && WTF_USE_V8
72    friend class V8::Bindings::QtDRTNodeRuntime;
73#else
74    friend class JSC::Bindings::QtDRTNodeRuntime;
75#endif
76
77    WebCore::Node* m_node;
78};
79
80Q_DECLARE_METATYPE(QDRTNode)
81
82class QWEBKIT_EXPORT DumpRenderTreeSupportQt {
83
84public:
85
86    DumpRenderTreeSupportQt();
87    ~DumpRenderTreeSupportQt();
88
89
90    static void executeCoreCommandByName(QWebPage* page, const QString& name, const QString& value);
91    static bool isCommandEnabled(QWebPage* page, const QString& name);
92    static bool findString(QWebPage* page, const QString& string, const QStringList& optionArray);
93    static void setSmartInsertDeleteEnabled(QWebPage* page, bool enabled);
94    static void setSelectTrailingWhitespaceEnabled(QWebPage* page, bool enabled);
95    static QVariantList selectedRange(QWebPage* page);
96    static QVariantList firstRectForCharacterRange(QWebPage* page, int location, int length);
97
98    static bool pauseAnimation(QWebFrame*, const QString& name, double time, const QString& elementId);
99    static bool pauseTransitionOfProperty(QWebFrame*, const QString& name, double time, const QString& elementId);
100    static bool pauseSVGAnimation(QWebFrame*, const QString& animationId, double time, const QString& elementId);
101    static void suspendActiveDOMObjects(QWebFrame* frame);
102    static void resumeActiveDOMObjects(QWebFrame* frame);
103
104    static void setDomainRelaxationForbiddenForURLScheme(bool forbidden, const QString& scheme);
105    static void setFrameFlatteningEnabled(QWebPage*, bool);
106    static void setCaretBrowsingEnabled(QWebPage* page, bool value);
107    static void setMediaType(QWebFrame* qframe, const QString& type);
108    static void setDumpRenderTreeModeEnabled(bool b);
109
110    static void garbageCollectorCollect();
111    static void garbageCollectorCollectOnAlternateThread(bool waitUntilDone);
112    static void setJavaScriptProfilingEnabled(QWebFrame*, bool enabled);
113    static int javaScriptObjectsCount();
114    static void clearScriptWorlds();
115    static void evaluateScriptInIsolatedWorld(QWebFrame* frame, int worldID, const QString& script);
116
117    static void setTimelineProfilingEnabled(QWebPage*, bool enabled);
118    static void webInspectorExecuteScript(QWebPage* page, long callId, const QString& script);
119    static void webInspectorShow(QWebPage* page);
120    static void webInspectorClose(QWebPage* page);
121
122    static QString webPageGroupName(QWebPage *page);
123    static QString counterValueForElementById(QWebFrame* frame, const QString& id);
124    static void webPageSetGroupName(QWebPage* page, const QString& groupName);
125    static void clearFrameName(QWebFrame* frame);
126    static void overwritePluginDirectories();
127    static int numberOfActiveAnimations(QWebFrame*);
128    static void suspendAnimations(QWebFrame*);
129    static void resumeAnimations(QWebFrame*);
130    static int numberOfPages(QWebFrame* frame, float width, float height);
131    static int pageNumberForElementById(QWebFrame* frame, const QString& id, float width, float height);
132    static bool hasDocumentElement(QWebFrame* frame);
133    static bool elementDoesAutoCompleteForElementWithId(QWebFrame* frame, const QString& elementId);
134    static void setEditingBehavior(QWebPage* page, const QString& editingBehavior);
135
136    static void clearAllApplicationCaches();
137
138    static void whiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains);
139    static void removeWhiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains);
140    static void resetOriginAccessWhiteLists();
141
142    static void activeMockDeviceOrientationClient(bool b);
143    static void removeMockDeviceOrientation();
144    static void setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma);
145
146    static void resetGeolocationMock(QWebPage*);
147    static void setMockGeolocationPermission(QWebPage*, bool allowed);
148    static void setMockGeolocationPosition(QWebPage*, double latitude, double longitude, double accuracy);
149    static void setMockGeolocationError(QWebPage*, int errorCode, const QString& message);
150    static int numberOfPendingGeolocationPermissionRequests(QWebPage*);
151
152    static int workerThreadCount();
153
154    static QString markerTextForListItem(const QWebElement& listItem);
155    static QVariantMap computedStyleIncludingVisitedInfo(const QWebElement& element);
156    static QString plainText(const QVariant& rng);
157
158    static void dumpFrameLoader(bool b);
159    static void dumpUserGestureInFrameLoader(bool b);
160    static void dumpResourceLoadCallbacks(bool b);
161    static void dumpResourceResponseMIMETypes(bool b);
162    static void dumpResourceLoadCallbacksPath(const QString& path);
163    static void setWillSendRequestReturnsNullOnRedirect(bool b);
164    static void setWillSendRequestReturnsNull(bool b);
165    static void setWillSendRequestClearHeaders(const QStringList& headers);
166    static void dumpHistoryCallbacks(bool b);
167    static void dumpVisitedLinksCallbacks(bool b);
168
169    static void setDeferMainResourceDataLoad(bool b);
170
171    static void dumpEditingCallbacks(bool b);
172    static void dumpSetAcceptsEditing(bool b);
173
174    static void dumpNotification(bool b);
175
176    static QMap<QString, QWebHistoryItem> getChildHistoryItems(const QWebHistoryItem& historyItem);
177    static bool isTargetItem(const QWebHistoryItem& historyItem);
178    static QString historyItemTarget(const QWebHistoryItem& historyItem);
179
180    static bool shouldClose(QWebFrame* frame);
181
182    static void setCustomPolicyDelegate(bool enabled, bool permissive);
183
184    static bool isPageBoxVisible(QWebFrame* frame, int pageIndex);
185
186    static QString pageSizeAndMarginsInPixels(QWebFrame* frame, int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
187    static QString pageProperty(QWebFrame* frame, const QString& propertyName, int pageNumber);
188    static void addUserStyleSheet(QWebPage* page, const QString& sourceCode);
189    static void simulateDesktopNotificationClick(const QString& title);
190    static QString viewportAsText(QWebPage*, int deviceDPI, const QSize& deviceSize, const QSize& availableSize);
191
192    static QVariantList nodesFromRect(const QWebElement& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping);
193    static QString responseMimeType(QWebFrame*);
194    static void clearOpener(QWebFrame*);
195    static void addURLToRedirect(const QString& origin, const QString& destination);
196    static QStringList contextMenu(QWebPage*);
197
198    static double defaultMinimumTimerInterval(); // Not really tied to WebView
199    static void setMinimumTimerInterval(QWebPage*, double);
200
201    static QUrl mediaContentUrlByElementId(QWebFrame*, const QString& elementId);
202    static void setAlternateHtml(QWebFrame*, const QString& html, const QUrl& baseUrl, const QUrl& failingUrl);
203
204    static QVariant shadowRoot(const QWebElement&);
205};
206
207#endif
208