1 | /* |
2 | * Copyright (C) 2015 The Qt Company Ltd. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | * |
19 | */ |
20 | #ifndef QWebPageAdapter_h |
21 | #define QWebPageAdapter_h |
22 | |
23 | #include "QWebPageClient.h" |
24 | #include "qwebelement.h" |
25 | #include "qwebhistory.h" |
26 | |
27 | #include <qbasictimer.h> |
28 | #include <qevent.h> |
29 | #include <qnetworkrequest.h> |
30 | #include <qrect.h> |
31 | #include <qscopedpointer.h> |
32 | #include <qsharedpointer.h> |
33 | #include <qstring.h> |
34 | #include <qurl.h> |
35 | #include <wtf/Forward.h> |
36 | |
37 | QT_BEGIN_NAMESPACE |
38 | class QBitArray; |
39 | class QKeyEvent; |
40 | class QMimeData; |
41 | class QMouseEvent; |
42 | class QNetworkAccessManager; |
43 | class QWheelEvent; |
44 | class QInputMethodEvent; |
45 | QT_END_NAMESPACE |
46 | |
47 | namespace WebCore { |
48 | class ChromeClientQt; |
49 | class DeviceOrientationClient; |
50 | class DeviceMotionClient; |
51 | class GeolocationClientQt; |
52 | class Page; |
53 | class UndoStep; |
54 | struct ViewportArguments; |
55 | } |
56 | |
57 | class QtPluginWidgetAdapter; |
58 | class QWebFrameAdapter; |
59 | class QWebFullScreenRequest; |
60 | class QWebHistoryItem; |
61 | class QWebHitTestResultPrivate; |
62 | class QWebPageClient; |
63 | class QWebPluginFactory; |
64 | class QWebSecurityOrigin; |
65 | class QWebSelectMethod; |
66 | class QWebSettings; |
67 | class QWebFullScreenVideoHandler; |
68 | class UndoStepQt; |
69 | |
70 | class QWEBKIT_EXPORT QWebPageAdapter { |
71 | public: |
72 | |
73 | #define (F, SEPARATOR) \ |
74 | F(OpenLink, WebCore::ContextMenuItemTagOpenLink) SEPARATOR \ |
75 | F(OpenLinkInNewWindow, WebCore::ContextMenuItemTagOpenLinkInNewWindow) SEPARATOR \ |
76 | F(OpenLinkInThisWindow, WebCore::ContextMenuItemTagOpenLinkInThisWindow) SEPARATOR \ |
77 | F(DownloadLinkToDisk, WebCore::ContextMenuItemTagDownloadLinkToDisk) SEPARATOR \ |
78 | F(CopyLinkToClipboard, WebCore::ContextMenuItemTagCopyLinkToClipboard) SEPARATOR \ |
79 | F(OpenImageInNewWindow, WebCore::ContextMenuItemTagOpenImageInNewWindow) SEPARATOR \ |
80 | F(DownloadImageToDisk, WebCore::ContextMenuItemTagDownloadImageToDisk) SEPARATOR \ |
81 | F(CopyImageToClipboard, WebCore::ContextMenuItemTagCopyImageToClipboard) SEPARATOR \ |
82 | F(CopyImageUrlToClipboard, WebCore::ContextMenuItemTagCopyImageUrlToClipboard) SEPARATOR \ |
83 | F(OpenFrameInNewWindow, WebCore::ContextMenuItemTagOpenFrameInNewWindow) SEPARATOR \ |
84 | F(Copy, WebCore::ContextMenuItemTagCopy) SEPARATOR \ |
85 | F(Back, WebCore::ContextMenuItemTagGoBack) SEPARATOR \ |
86 | F(Forward, WebCore::ContextMenuItemTagGoForward) SEPARATOR \ |
87 | F(Stop, WebCore::ContextMenuItemTagStop) SEPARATOR \ |
88 | F(Reload, WebCore::ContextMenuItemTagReload) SEPARATOR \ |
89 | F(Cut, WebCore::ContextMenuItemTagCut) SEPARATOR \ |
90 | F(Paste, WebCore::ContextMenuItemTagPaste) SEPARATOR \ |
91 | F(SetTextDirectionDefault, WebCore::ContextMenuItemTagDefaultDirection) SEPARATOR \ |
92 | F(SetTextDirectionLeftToRight, WebCore::ContextMenuItemTagLeftToRight) SEPARATOR \ |
93 | F(SetTextDirectionRightToLeft, WebCore::ContextMenuItemTagRightToLeft) SEPARATOR \ |
94 | F(ToggleBold, WebCore::ContextMenuItemTagBold) SEPARATOR \ |
95 | F(ToggleItalic, WebCore::ContextMenuItemTagItalic) SEPARATOR \ |
96 | F(ToggleUnderline, WebCore::ContextMenuItemTagUnderline) SEPARATOR \ |
97 | F(SelectAll, WebCore::ContextMenuItemTagSelectAll) SEPARATOR \ |
98 | F(DownloadMediaToDisk, WebCore::ContextMenuItemTagDownloadMediaToDisk) SEPARATOR \ |
99 | F(CopyMediaUrlToClipboard, WebCore::ContextMenuItemTagCopyMediaLinkToClipboard) SEPARATOR \ |
100 | F(ToggleMediaControls, WebCore::ContextMenuItemTagToggleMediaControls) SEPARATOR \ |
101 | F(ToggleMediaLoop, WebCore::ContextMenuItemTagToggleMediaLoop) SEPARATOR \ |
102 | F(ToggleMediaPlayPause, WebCore::ContextMenuItemTagMediaPlayPause) SEPARATOR \ |
103 | F(ToggleMediaMute, WebCore::ContextMenuItemTagMediaMute) SEPARATOR \ |
104 | F(ToggleVideoFullscreen, WebCore::ContextMenuItemTagToggleVideoFullscreen) |
105 | #define COMMA_SEPARATOR , |
106 | #define SEMICOLON_SEPARATOR ; |
107 | #define DEFINE_ACTION(Name, Value) \ |
108 | Name |
109 | |
110 | enum { |
111 | NoAction = - 1, |
112 | FOR_EACH_MAPPED_MENU_ACTION(DEFINE_ACTION, COMMA_SEPARATOR) |
113 | , InspectElement |
114 | , ActionCount |
115 | }; |
116 | |
117 | // Duplicated from qwebpage.h |
118 | enum FindFlag { |
119 | FindBackward = 1, |
120 | FindCaseSensitively = 2, |
121 | FindWrapsAroundDocument = 4, |
122 | HighlightAllOccurrences = 8, |
123 | FindAtWordBeginningsOnly = 16, |
124 | TreatMedialCapitalAsWordBeginning = 32, |
125 | FindBeginsInSelection = 64 |
126 | }; |
127 | |
128 | // valid values matching those from ScrollTypes.h |
129 | enum ScrollDirection { |
130 | InvalidScrollDirection = -1, |
131 | ScrollUp, |
132 | ScrollDown, |
133 | ScrollLeft, |
134 | ScrollRight |
135 | }; |
136 | // same here |
137 | enum ScrollGranularity { |
138 | InvalidScrollGranularity = -1, |
139 | ScrollByLine, |
140 | ScrollByPage, |
141 | ScrollByDocument |
142 | }; |
143 | |
144 | // Must match with values of QWebPage::VisibilityState enum. |
145 | enum VisibilityState { |
146 | VisibilityStateVisible, |
147 | VisibilityStateHidden, |
148 | VisibilityStatePrerender, |
149 | VisibilityStateUnloaded |
150 | }; |
151 | |
152 | // Must match with values of QWebPage::MessageSource enum. |
153 | enum MessageSource { |
154 | XmlMessageSource, |
155 | JSMessageSource, |
156 | NetworkMessageSource, |
157 | ConsoleAPIMessageSource, |
158 | StorageMessageSource, |
159 | AppCacheMessageSource, |
160 | RenderingMessageSource, |
161 | CSSMessageSource, |
162 | SecurityMessageSource, |
163 | ContentBlockerMessageSource, |
164 | OtherMessageSource, |
165 | }; |
166 | |
167 | // Must match with values of QWebPage::MessageLevel enum. |
168 | enum MessageLevel { |
169 | LogMessageLevel = 1, |
170 | WarningMessageLevel = 2, |
171 | ErrorMessageLevel = 3, |
172 | DebugMessageLevel = 4, |
173 | InfoMessageLevel = 5, |
174 | }; |
175 | |
176 | QWebPageAdapter(); |
177 | virtual ~QWebPageAdapter(); |
178 | |
179 | // Called manually from ~QWebPage destructor to ensure that |
180 | // the QWebPageAdapter and the QWebPagePrivate are intact when |
181 | // various destruction callbacks from WebCore::Page::~Page() hit us. |
182 | void deletePage(); |
183 | // For similar reasons, we don't want to create the WebCore Page before |
184 | // we properly initialized the style factory callbacks. |
185 | void initializeWebCorePage(); |
186 | |
187 | virtual void show() = 0; |
188 | virtual void setFocus() = 0; |
189 | virtual void unfocus() = 0; |
190 | virtual void setWindowRect(const QRect&) = 0; |
191 | virtual QSize viewportSize() const = 0; |
192 | virtual QWebPageAdapter* createWindow(bool /*dialog*/) = 0; |
193 | virtual QObject* handle() = 0; |
194 | virtual void consoleMessageReceived(MessageSource, MessageLevel, const QString& message, int lineNumber, const QString& sourceID) = 0; |
195 | virtual void javaScriptAlert(QWebFrameAdapter*, const QString& msg) = 0; |
196 | virtual bool javaScriptConfirm(QWebFrameAdapter*, const QString& msg) = 0; |
197 | virtual bool javaScriptPrompt(QWebFrameAdapter*, const QString& msg, const QString& defaultValue, QString* result) = 0; |
198 | virtual bool shouldInterruptJavaScript() = 0; |
199 | virtual void printRequested(QWebFrameAdapter*) = 0; |
200 | virtual void databaseQuotaExceeded(QWebFrameAdapter*, const QString& databaseName) = 0; |
201 | virtual void applicationCacheQuotaExceeded(QWebSecurityOrigin*, quint64 defaultOriginQuota, quint64 totalSpaceNeeded) = 0; |
202 | virtual void setToolTip(const QString&) = 0; |
203 | virtual QStringList chooseFiles(QWebFrameAdapter*, bool allowMultiple, const QStringList& suggestedFileNames) = 0; |
204 | virtual QColor colorSelectionRequested(const QColor& selectedColor) = 0; |
205 | virtual std::unique_ptr<QWebSelectMethod> () = 0; |
206 | virtual QRect viewRectRelativeToWindow() = 0; |
207 | |
208 | #if USE(QT_MULTIMEDIA) |
209 | virtual QWebFullScreenVideoHandler* createFullScreenVideoHandler() = 0; |
210 | #endif |
211 | virtual void fullScreenRequested(QWebFullScreenRequest) = 0; |
212 | virtual void geolocationPermissionRequested(QWebFrameAdapter*) = 0; |
213 | virtual void geolocationPermissionRequestCancelled(QWebFrameAdapter*) = 0; |
214 | virtual void notificationsPermissionRequested(QWebFrameAdapter*) = 0; |
215 | virtual void notificationsPermissionRequestCancelled(QWebFrameAdapter*) = 0; |
216 | |
217 | virtual void respondToChangedContents() = 0; |
218 | virtual void respondToChangedSelection() = 0; |
219 | virtual void microFocusChanged() = 0; |
220 | virtual void triggerCopyAction() = 0; |
221 | virtual void triggerActionForKeyEvent(QKeyEvent*) = 0; |
222 | virtual void clearUndoStack() = 0; |
223 | virtual bool canUndo() const = 0; |
224 | virtual bool canRedo() const = 0; |
225 | virtual void undo() = 0; |
226 | virtual void redo() = 0; |
227 | virtual const char* editorCommandForKeyEvent(QKeyEvent*) = 0; |
228 | virtual void createUndoStep(QSharedPointer<UndoStepQt>) = 0; |
229 | |
230 | virtual void updateNavigationActions() = 0; |
231 | virtual void clearCustomActions() = 0; |
232 | |
233 | virtual QWebFrameAdapter& mainFrameAdapter() = 0; |
234 | |
235 | virtual QObject* inspectorHandle() = 0; |
236 | virtual void setInspectorFrontend(QObject*) = 0; |
237 | virtual void setInspectorWindowTitle(const QString&) = 0; |
238 | virtual void createWebInspector(QObject** inspectorView, QWebPageAdapter** inspectorPage) = 0; |
239 | virtual QStringList () = 0; |
240 | virtual void emitViewportChangeRequested() = 0; |
241 | virtual bool acceptNavigationRequest(QWebFrameAdapter*, const QNetworkRequest&, int type) = 0; |
242 | virtual void emitRestoreFrameStateRequested(QWebFrameAdapter *) = 0; |
243 | virtual void emitSaveFrameStateRequested(QWebFrameAdapter *, QWebHistoryItem*) = 0; |
244 | virtual void emitDownloadRequested(const QNetworkRequest&) = 0; |
245 | virtual void emitFrameCreated(QWebFrameAdapter*) = 0; |
246 | virtual QString userAgentForUrl(const QUrl&) const = 0; |
247 | virtual bool supportsErrorPageExtension() const = 0; |
248 | struct ErrorPageOption { |
249 | QUrl url; |
250 | QWebFrameAdapter* frame; |
251 | QString domain; |
252 | int error; |
253 | QString errorString; |
254 | }; |
255 | struct { |
256 | QString ; |
257 | QString ; |
258 | QUrl ; |
259 | QByteArray ; |
260 | }; |
261 | virtual bool (ErrorPageOption*, ErrorPageReturn*) = 0; |
262 | virtual QtPluginWidgetAdapter* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&) = 0; |
263 | virtual QtPluginWidgetAdapter* adapterForWidget(QObject*) const = 0; |
264 | virtual bool requestSoftwareInputPanel() const = 0; |
265 | struct { |
266 | () |
267 | : type(NoType) |
268 | , action(NoAction) |
269 | , traits(None) |
270 | { } |
271 | enum { |
272 | , |
273 | , |
274 | , |
275 | |
276 | } ; |
277 | int ; |
278 | enum { |
279 | = 0, |
280 | = 1, |
281 | = 2, |
282 | = 4 |
283 | }; |
284 | Q_DECLARE_FLAGS(, Trait); |
285 | Traits ; |
286 | QList<MenuItemDescription> ; |
287 | QString ; |
288 | }; |
289 | virtual void createAndSetCurrentContextMenu(const QList<MenuItemDescription>&, QBitArray*) = 0; |
290 | virtual bool handleScrollbarContextMenuEvent(QContextMenuEvent*, bool, ScrollDirection*, ScrollGranularity*) = 0; |
291 | |
292 | virtual void recentlyAudibleChanged(bool) = 0; |
293 | virtual void focusedElementChanged(const QWebElement&) = 0; |
294 | |
295 | void setVisibilityState(VisibilityState); |
296 | VisibilityState visibilityState() const; |
297 | |
298 | void setPluginsVisible(bool); |
299 | |
300 | static QWebPageAdapter* kit(WebCore::Page*); |
301 | WebCore::ViewportArguments viewportArguments() const; |
302 | void registerUndoStep(WTF::PassRefPtr<WebCore::UndoStep>); |
303 | |
304 | void setNetworkAccessManager(QNetworkAccessManager*); |
305 | QNetworkAccessManager* networkAccessManager(); |
306 | |
307 | bool hasSelection() const; |
308 | QString selectedText() const; |
309 | QString selectedHtml() const; |
310 | |
311 | bool isContentEditable() const; |
312 | void setContentEditable(bool); |
313 | |
314 | bool findText(const QString& subString, FindFlag options); |
315 | |
316 | void adjustPointForClicking(QMouseEvent*); |
317 | |
318 | bool tryClosePage(); |
319 | void mouseMoveEvent(QMouseEvent*); |
320 | void mousePressEvent(QMouseEvent*); |
321 | void mouseDoubleClickEvent(QMouseEvent*); |
322 | void mouseTripleClickEvent(QMouseEvent*); |
323 | void mouseReleaseEvent(QMouseEvent*); |
324 | void handleSoftwareInputPanel(Qt::MouseButton, const QPoint&); |
325 | #ifndef QT_NO_WHEELEVENT |
326 | void wheelEvent(QWheelEvent*, int wheelScrollLines); |
327 | #endif |
328 | #if ENABLE(DRAG_SUPPORT) |
329 | Qt::DropAction dragEntered(const QMimeData*, const QPoint&, Qt::DropActions); |
330 | void dragLeaveEvent(); |
331 | Qt::DropAction dragUpdated(const QMimeData*, const QPoint&, Qt::DropActions); |
332 | bool performDrag(const QMimeData*, const QPoint&, Qt::DropActions); |
333 | #endif |
334 | void inputMethodEvent(QInputMethodEvent*); |
335 | QVariant inputMethodQuery(Qt::InputMethodQuery property) const; |
336 | void dynamicPropertyChangeEvent(QObject*, QDynamicPropertyChangeEvent*); |
337 | bool handleKeyEvent(QKeyEvent*); |
338 | bool handleScrolling(QKeyEvent*); |
339 | void focusInEvent(QFocusEvent*); |
340 | void focusOutEvent(QFocusEvent*); |
341 | bool handleShortcutOverrideEvent(QKeyEvent*); |
342 | // Returns whether the default action was cancelled in the JS event handler |
343 | bool touchEvent(QTouchEvent*); |
344 | bool (QContextMenuEvent *, QWebFrameAdapter*); |
345 | |
346 | QWebHitTestResultPrivate* (const QPoint&, QBitArray*); |
347 | void (MenuAction, const char* commandName, bool* enabled, bool* checked); |
348 | void (MenuAction, QWebHitTestResultPrivate*, const char* commandName, bool endToEndReload); |
349 | void triggerCustomAction(int action, const QString &title); |
350 | QString (MenuAction, bool* checkable) const; |
351 | |
352 | QStringList supportedContentTypes() const; |
353 | #if ENABLE(GEOLOCATION) && HAVE(QTPOSITIONING) |
354 | void setGeolocationEnabledForFrame(QWebFrameAdapter*, bool); |
355 | #endif |
356 | #if ENABLE(NOTIFICATIONS) |
357 | void setNotificationsAllowedForFrame(QWebFrameAdapter*, bool allowed); |
358 | void addNotificationPresenterClient(); |
359 | #ifndef QT_NO_SYSTEMTRAYICON |
360 | bool hasSystemTrayIcon() const; |
361 | void setSystemTrayIcon(QObject*); |
362 | #endif // QT_NO_SYSTEMTRAYICON |
363 | #endif // ENABLE(NOTIFICATIONS) |
364 | |
365 | // Called from QWebPage as private slots. |
366 | void _q_cleanupLeakMessages(); |
367 | void _q_onLoadProgressChanged(int); |
368 | |
369 | bool supportsContentType(const QString& mimeType) const; |
370 | |
371 | void didShowInspector(); |
372 | void didCloseInspector(); |
373 | |
374 | static QString defaultUserAgentString(); |
375 | static bool treatSchemeAsLocal(const QString&); |
376 | |
377 | QObject* currentFrame() const; |
378 | bool hasFocusedNode() const; |
379 | struct ViewportAttributes { |
380 | qreal initialScaleFactor; |
381 | qreal minimumScaleFactor; |
382 | qreal maximumScaleFactor; |
383 | qreal devicePixelRatio; |
384 | bool isUserScalable; |
385 | QSizeF size; |
386 | }; |
387 | |
388 | ViewportAttributes viewportAttributesForSize(const QSize& availableSize, const QSize& deviceSize) const; |
389 | void setDevicePixelRatio(float devicePixelRatio); |
390 | float devicePixelRatio(); |
391 | |
392 | bool isPlayingAudio() const; |
393 | |
394 | const QWebElement& fullScreenElement() const; |
395 | void setFullScreenElement(const QWebElement&); |
396 | |
397 | QWebSettings *settings; |
398 | |
399 | WebCore::Page *page; |
400 | QScopedPointer<QWebPageClient> client; |
401 | |
402 | QWebPluginFactory *pluginFactory; |
403 | |
404 | bool forwardUnsupportedContent; |
405 | bool insideOpenCall; |
406 | QPoint tripleClick; |
407 | QBasicTimer tripleClickTimer; |
408 | |
409 | bool clickCausedFocus; |
410 | bool mousePressed; |
411 | bool m_useNativeVirtualKeyAsDOMKey; |
412 | quint64 m_totalBytes; |
413 | quint64 m_bytesReceived; |
414 | QWebHistory history; |
415 | |
416 | private: |
417 | QNetworkAccessManager *networkManager; |
418 | WebCore::DeviceOrientationClient* m_deviceOrientationClient; |
419 | WebCore::DeviceMotionClient* m_deviceMotionClient; |
420 | |
421 | #if ENABLE(FULLSCREEN_API) |
422 | QWebElement m_fullScreenElement; |
423 | #endif |
424 | |
425 | public: |
426 | static bool drtRun; |
427 | |
428 | friend class WebCore::ChromeClientQt; |
429 | friend class WebCore::GeolocationClientQt; |
430 | }; |
431 | |
432 | #endif // QWebPageAdapter_h |
433 | |