QWebPageAdapter.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
  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. #include "PlatformExportMacros.h"
  23. #include "QWebPageClient.h"
  24. #include "ViewportArguments.h"
  25. #include "qwebhistory.h"
  26. #include <qbasictimer.h>
  27. #include <qevent.h>
  28. #include <qnetworkrequest.h>
  29. #include <qrect.h>
  30. #include <qscopedpointer.h>
  31. #include <qsharedpointer.h>
  32. #include <qstring.h>
  33. #include <qurl.h>
  34. #include <wtf/ExportMacros.h>
  35. QT_BEGIN_NAMESPACE
  36. class QBitArray;
  37. class QKeyEvent;
  38. class QMimeData;
  39. class QMouseEvent;
  40. class QNetworkAccessManager;
  41. class QWheelEvent;
  42. class QInputMethodEvent;
  43. QT_END_NAMESPACE
  44. namespace WebCore {
  45. class ChromeClientQt;
  46. class GeolocationClientQt;
  47. class Page;
  48. class UndoStep;
  49. }
  50. class QtPluginWidgetAdapter;
  51. class QWebFrameAdapter;
  52. class QWebHistoryItem;
  53. class QWebHitTestResultPrivate;
  54. class QWebPageClient;
  55. class QWebPluginFactory;
  56. class QWebSecurityOrigin;
  57. class QWebSelectMethod;
  58. class QWebSettings;
  59. class QWebFullScreenVideoHandler;
  60. class UndoStepQt;
  61. class WEBKIT_EXPORTDATA QWebPageAdapter {
  62. public:
  63. #define FOR_EACH_MAPPED_MENU_ACTION(F, SEPARATOR) \
  64. F(OpenLink, WebCore::ContextMenuItemTagOpenLink) SEPARATOR \
  65. F(OpenLinkInNewWindow, WebCore::ContextMenuItemTagOpenLinkInNewWindow) SEPARATOR \
  66. F(OpenLinkInThisWindow, WebCore::ContextMenuItemTagOpenLinkInThisWindow) SEPARATOR \
  67. F(DownloadLinkToDisk, WebCore::ContextMenuItemTagDownloadLinkToDisk) SEPARATOR \
  68. F(CopyLinkToClipboard, WebCore::ContextMenuItemTagCopyLinkToClipboard) SEPARATOR \
  69. F(OpenImageInNewWindow, WebCore::ContextMenuItemTagOpenImageInNewWindow) SEPARATOR \
  70. F(DownloadImageToDisk, WebCore::ContextMenuItemTagDownloadImageToDisk) SEPARATOR \
  71. F(CopyImageToClipboard, WebCore::ContextMenuItemTagCopyImageToClipboard) SEPARATOR \
  72. F(CopyImageUrlToClipboard, WebCore::ContextMenuItemTagCopyImageUrlToClipboard) SEPARATOR \
  73. F(OpenFrameInNewWindow, WebCore::ContextMenuItemTagOpenFrameInNewWindow) SEPARATOR \
  74. F(Copy, WebCore::ContextMenuItemTagCopy) SEPARATOR \
  75. F(Back, WebCore::ContextMenuItemTagGoBack) SEPARATOR \
  76. F(Forward, WebCore::ContextMenuItemTagGoForward) SEPARATOR \
  77. F(Stop, WebCore::ContextMenuItemTagStop) SEPARATOR \
  78. F(Reload, WebCore::ContextMenuItemTagReload) SEPARATOR \
  79. F(Cut, WebCore::ContextMenuItemTagCut) SEPARATOR \
  80. F(Paste, WebCore::ContextMenuItemTagPaste) SEPARATOR \
  81. F(SetTextDirectionDefault, WebCore::ContextMenuItemTagDefaultDirection) SEPARATOR \
  82. F(SetTextDirectionLeftToRight, WebCore::ContextMenuItemTagLeftToRight) SEPARATOR \
  83. F(SetTextDirectionRightToLeft, WebCore::ContextMenuItemTagRightToLeft) SEPARATOR \
  84. F(ToggleBold, WebCore::ContextMenuItemTagBold) SEPARATOR \
  85. F(ToggleItalic, WebCore::ContextMenuItemTagItalic) SEPARATOR \
  86. F(ToggleUnderline, WebCore::ContextMenuItemTagUnderline) SEPARATOR \
  87. F(SelectAll, WebCore::ContextMenuItemTagSelectAll)
  88. #define COMMA_SEPARATOR ,
  89. #define SEMICOLON_SEPARATOR ;
  90. #define DEFINE_ACTION(Name, Value) \
  91. Name
  92. enum MenuAction {
  93. NoAction = - 1,
  94. FOR_EACH_MAPPED_MENU_ACTION(DEFINE_ACTION, COMMA_SEPARATOR)
  95. #if ENABLE(INSPECTOR)
  96. , InspectElement
  97. #endif
  98. , ActionCount
  99. };
  100. // Duplicated from qwebpage.h
  101. enum FindFlag {
  102. FindBackward = 1,
  103. FindCaseSensitively = 2,
  104. FindWrapsAroundDocument = 4,
  105. HighlightAllOccurrences = 8,
  106. FindAtWordBeginningsOnly = 16,
  107. TreatMedialCapitalAsWordBeginning = 32,
  108. FindBeginsInSelection = 64
  109. };
  110. // valid values matching those from ScrollTypes.h
  111. enum ScrollDirection {
  112. InvalidScrollDirection = -1,
  113. ScrollUp,
  114. ScrollDown,
  115. ScrollLeft,
  116. ScrollRight
  117. };
  118. // same here
  119. enum ScrollGranularity {
  120. InvalidScrollGranularity = -1,
  121. ScrollByLine,
  122. ScrollByPage,
  123. ScrollByDocument
  124. };
  125. QWebPageAdapter();
  126. virtual ~QWebPageAdapter();
  127. // Called manually from ~QWebPage destructor to ensure that
  128. // the QWebPageAdapter and the QWebPagePrivate are intact when
  129. // various destruction callbacks from WebCore::Page::~Page() hit us.
  130. void deletePage();
  131. // For similar reasons, we don't want to create the WebCore Page before
  132. // we properly initialized the style factory callbacks.
  133. void initializeWebCorePage();
  134. virtual void show() = 0;
  135. virtual void setFocus() = 0;
  136. virtual void unfocus() = 0;
  137. virtual void setWindowRect(const QRect&) = 0;
  138. virtual QSize viewportSize() const = 0;
  139. virtual QWebPageAdapter* createWindow(bool /*dialog*/) = 0;
  140. virtual QObject* handle() = 0;
  141. virtual void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) = 0;
  142. virtual void javaScriptAlert(QWebFrameAdapter*, const QString& msg) = 0;
  143. virtual bool javaScriptConfirm(QWebFrameAdapter*, const QString& msg) = 0;
  144. virtual bool javaScriptPrompt(QWebFrameAdapter*, const QString& msg, const QString& defaultValue, QString* result) = 0;
  145. virtual bool shouldInterruptJavaScript() = 0;
  146. virtual void printRequested(QWebFrameAdapter*) = 0;
  147. virtual void databaseQuotaExceeded(QWebFrameAdapter*, const QString& databaseName) = 0;
  148. virtual void applicationCacheQuotaExceeded(QWebSecurityOrigin*, quint64 defaultOriginQuota, quint64 totalSpaceNeeded) = 0;
  149. virtual void setToolTip(const QString&) = 0;
  150. virtual QStringList chooseFiles(QWebFrameAdapter*, bool allowMultiple, const QStringList& suggestedFileNames) = 0;
  151. virtual QColor colorSelectionRequested(const QColor& selectedColor) = 0;
  152. virtual QWebSelectMethod* createSelectPopup() = 0;
  153. virtual QRect viewRectRelativeToWindow() = 0;
  154. #if USE(QT_MULTIMEDIA)
  155. virtual QWebFullScreenVideoHandler* createFullScreenVideoHandler() = 0;
  156. #endif
  157. virtual void geolocationPermissionRequested(QWebFrameAdapter*) = 0;
  158. virtual void geolocationPermissionRequestCancelled(QWebFrameAdapter*) = 0;
  159. virtual void notificationsPermissionRequested(QWebFrameAdapter*) = 0;
  160. virtual void notificationsPermissionRequestCancelled(QWebFrameAdapter*) = 0;
  161. virtual void respondToChangedContents() = 0;
  162. virtual void respondToChangedSelection() = 0;
  163. virtual void microFocusChanged() = 0;
  164. virtual void triggerCopyAction() = 0;
  165. virtual void triggerActionForKeyEvent(QKeyEvent*) = 0;
  166. virtual void clearUndoStack() = 0;
  167. virtual bool canUndo() const = 0;
  168. virtual bool canRedo() const = 0;
  169. virtual void undo() = 0;
  170. virtual void redo() = 0;
  171. virtual const char* editorCommandForKeyEvent(QKeyEvent*) = 0;
  172. virtual void createUndoStep(QSharedPointer<UndoStepQt>) = 0;
  173. virtual void updateNavigationActions() = 0;
  174. virtual QWebFrameAdapter* mainFrameAdapter() = 0;
  175. virtual QObject* inspectorHandle() = 0;
  176. virtual void setInspectorFrontend(QObject*) = 0;
  177. virtual void setInspectorWindowTitle(const QString&) = 0;
  178. virtual void createWebInspector(QObject** inspectorView, QWebPageAdapter** inspectorPage) = 0;
  179. virtual QStringList menuActionsAsText() = 0;
  180. virtual void emitViewportChangeRequested() = 0;
  181. virtual bool acceptNavigationRequest(QWebFrameAdapter*, const QNetworkRequest&, int type) = 0;
  182. virtual void emitRestoreFrameStateRequested(QWebFrameAdapter *) = 0;
  183. virtual void emitSaveFrameStateRequested(QWebFrameAdapter *, QWebHistoryItem*) = 0;
  184. virtual void emitDownloadRequested(const QNetworkRequest&) = 0;
  185. virtual void emitFrameCreated(QWebFrameAdapter*) = 0;
  186. virtual QString userAgentForUrl(const QUrl&) const = 0;
  187. virtual bool supportsErrorPageExtension() const = 0;
  188. struct ErrorPageOption {
  189. QUrl url;
  190. QWebFrameAdapter* frame;
  191. QString domain;
  192. int error;
  193. QString errorString;
  194. };
  195. struct ErrorPageReturn {
  196. QString contentType;
  197. QString encoding;
  198. QUrl baseUrl;
  199. QByteArray content;
  200. };
  201. virtual bool errorPageExtension(ErrorPageOption*, ErrorPageReturn*) = 0;
  202. virtual QtPluginWidgetAdapter* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&) = 0;
  203. virtual QtPluginWidgetAdapter* adapterForWidget(QObject*) const = 0;
  204. virtual bool requestSoftwareInputPanel() const = 0;
  205. struct MenuItemDescription {
  206. MenuItemDescription()
  207. : type(NoType)
  208. , action(NoAction)
  209. , traits(None)
  210. { }
  211. enum Type {
  212. NoType,
  213. Action,
  214. Separator,
  215. SubMenu
  216. } type;
  217. MenuAction action;
  218. enum Trait {
  219. None = 0,
  220. Enabled = 1,
  221. Checkable = 2,
  222. Checked = 4
  223. };
  224. Q_DECLARE_FLAGS(Traits, Trait);
  225. Traits traits;
  226. QList<MenuItemDescription> subMenu;
  227. QString subMenuTitle;
  228. };
  229. virtual void createAndSetCurrentContextMenu(const QList<MenuItemDescription>&, QBitArray*) = 0;
  230. virtual bool handleScrollbarContextMenuEvent(QContextMenuEvent*, bool, ScrollDirection*, ScrollGranularity*) = 0;
  231. static QWebPageAdapter* kit(WebCore::Page*);
  232. WebCore::ViewportArguments viewportArguments() const;
  233. void registerUndoStep(WTF::PassRefPtr<WebCore::UndoStep>);
  234. void setNetworkAccessManager(QNetworkAccessManager*);
  235. QNetworkAccessManager* networkAccessManager();
  236. bool hasSelection() const;
  237. QString selectedText() const;
  238. QString selectedHtml() const;
  239. bool isContentEditable() const;
  240. void setContentEditable(bool);
  241. bool findText(const QString& subString, FindFlag options);
  242. void adjustPointForClicking(QMouseEvent*);
  243. void mouseMoveEvent(QMouseEvent*);
  244. void mousePressEvent(QMouseEvent*);
  245. void mouseDoubleClickEvent(QMouseEvent*);
  246. void mouseTripleClickEvent(QMouseEvent*);
  247. void mouseReleaseEvent(QMouseEvent*);
  248. void handleSoftwareInputPanel(Qt::MouseButton, const QPoint&);
  249. #ifndef QT_NO_WHEELEVENT
  250. void wheelEvent(QWheelEvent*, int wheelScrollLines);
  251. #endif
  252. #ifndef QT_NO_DRAGANDDROP
  253. Qt::DropAction dragEntered(const QMimeData*, const QPoint&, Qt::DropActions);
  254. void dragLeaveEvent();
  255. Qt::DropAction dragUpdated(const QMimeData*, const QPoint&, Qt::DropActions);
  256. bool performDrag(const QMimeData*, const QPoint&, Qt::DropActions);
  257. #endif
  258. void inputMethodEvent(QInputMethodEvent*);
  259. QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
  260. void dynamicPropertyChangeEvent(QObject*, QDynamicPropertyChangeEvent*);
  261. bool handleKeyEvent(QKeyEvent*);
  262. bool handleScrolling(QKeyEvent*);
  263. void focusInEvent(QFocusEvent*);
  264. void focusOutEvent(QFocusEvent*);
  265. bool handleShortcutOverrideEvent(QKeyEvent*);
  266. // Returns whether the default action was cancelled in the JS event handler
  267. bool touchEvent(QTouchEvent*);
  268. bool swallowContextMenuEvent(QContextMenuEvent *, QWebFrameAdapter*);
  269. QWebHitTestResultPrivate* updatePositionDependentMenuActions(const QPoint&, QBitArray*);
  270. void updateActionInternal(MenuAction, const char* commandName, bool* enabled, bool* checked);
  271. void triggerAction(MenuAction, QWebHitTestResultPrivate*, const char* commandName, bool endToEndReload);
  272. QString contextMenuItemTagForAction(MenuAction, bool* checkable) const;
  273. QStringList supportedContentTypes() const;
  274. #if ENABLE(GEOLOCATION) && HAVE(QTLOCATION)
  275. void setGeolocationEnabledForFrame(QWebFrameAdapter*, bool);
  276. #endif
  277. #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
  278. void setNotificationsAllowedForFrame(QWebFrameAdapter*, bool allowed);
  279. void addNotificationPresenterClient();
  280. #ifndef QT_NO_SYSTEMTRAYICON
  281. bool hasSystemTrayIcon() const;
  282. void setSystemTrayIcon(QObject*);
  283. #endif // QT_NO_SYSTEMTRAYICON
  284. #endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
  285. // Called from QWebPage as private slots.
  286. void _q_cleanupLeakMessages();
  287. void _q_onLoadProgressChanged(int);
  288. bool supportsContentType(const QString& mimeType) const;
  289. void didShowInspector();
  290. void didCloseInspector();
  291. static QString defaultUserAgentString();
  292. static bool treatSchemeAsLocal(const QString&);
  293. QObject* currentFrame() const;
  294. bool hasFocusedNode() const;
  295. struct ViewportAttributes {
  296. qreal initialScaleFactor;
  297. qreal minimumScaleFactor;
  298. qreal maximumScaleFactor;
  299. qreal devicePixelRatio;
  300. bool isUserScalable;
  301. QSizeF size;
  302. };
  303. ViewportAttributes viewportAttributesForSize(const QSize& availableSize, const QSize& deviceSize) const;
  304. QWebSettings *settings;
  305. WebCore::Page *page;
  306. QScopedPointer<QWebPageClient> client;
  307. QWebPluginFactory *pluginFactory;
  308. bool forwardUnsupportedContent;
  309. bool insideOpenCall;
  310. QPoint tripleClick;
  311. QBasicTimer tripleClickTimer;
  312. bool clickCausedFocus;
  313. quint64 m_totalBytes;
  314. quint64 m_bytesReceived;
  315. QWebHistory history;
  316. private:
  317. QNetworkAccessManager *networkManager;
  318. public:
  319. static bool drtRun;
  320. friend class WebCore::ChromeClientQt;
  321. friend class WebCore::GeolocationClientQt;
  322. };
  323. #endif // QWebPageAdapter_h