1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWebEngine module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49//
50
51#ifndef WEB_CONTENTS_ADAPTER_CLIENT_H
52#define WEB_CONTENTS_ADAPTER_CLIENT_H
53
54#include "qtwebenginecoreglobal_p.h"
55
56#include <QFlags>
57#include <QRect>
58#include <QSharedPointer>
59#include <QString>
60#include <QStringList>
61#include <QUrl>
62
63QT_FORWARD_DECLARE_CLASS(CertificateErrorController)
64QT_FORWARD_DECLARE_CLASS(ClientCertSelectController)
65QT_FORWARD_DECLARE_CLASS(QKeyEvent)
66QT_FORWARD_DECLARE_CLASS(QVariant)
67QT_FORWARD_DECLARE_CLASS(QWebEngineQuotaRequest)
68QT_FORWARD_DECLARE_CLASS(QWebEngineRegisterProtocolHandlerRequest)
69QT_FORWARD_DECLARE_CLASS(QWebEngineUrlRequestInfo)
70
71namespace content {
72struct DropData;
73}
74
75namespace QtWebEngineCore {
76
77class AuthenticationDialogController;
78class ProfileAdapter;
79class ColorChooserController;
80class FilePickerController;
81class JavaScriptDialogController;
82class RenderWidgetHostViewQt;
83class RenderWidgetHostViewQtDelegate;
84class RenderWidgetHostViewQtDelegateClient;
85class TouchHandleDrawableClient;
86class TouchSelectionMenuController;
87class WebContentsAdapter;
88class WebContentsDelegateQt;
89class WebEngineSettings;
90
91// Must match blink::WebReferrerPolicy
92enum class ReferrerPolicy {
93 Always,
94 Default,
95 NoReferrerWhenDowngrade,
96 Never,
97 Origin,
98 OriginWhenCrossOrigin,
99 NoReferrerWhenDowngradeOriginWhenCrossOrigin,
100 SameOrigin,
101 StrictOrigin,
102 Last = StrictOrigin,
103};
104
105class WebEngineContextMenuSharedData : public QSharedData {
106
107public:
108 WebEngineContextMenuSharedData()
109 : hasImageContent(false)
110 , isEditable(false)
111 , isSpellCheckerEnabled(false)
112 , mediaType(0)
113 , mediaFlags(0)
114 , editFlags(0)
115 {
116 }
117 bool hasImageContent;
118 bool isEditable;
119 bool isSpellCheckerEnabled;
120 uint mediaType;
121 uint mediaFlags;
122 uint editFlags;
123 QPoint pos;
124 QUrl linkUrl;
125 QUrl unfilteredLinkUrl;
126 QUrl mediaUrl;
127 QString linkText;
128 QString selectedText;
129 QString suggestedFileName;
130 QString misspelledWord;
131 QStringList spellCheckerSuggestions;
132 QUrl pageUrl;
133 QUrl frameUrl;
134 ReferrerPolicy referrerPolicy = ReferrerPolicy::Default;
135 // Some likely candidates for future additions as we add support for the related actions:
136 // bool isImageBlocked;
137 // <enum tbd> mediaType;
138 // ...
139};
140
141class WebEngineContextMenuData {
142public:
143 // Must match blink::WebContextMenuData::MediaType:
144 enum MediaType {
145 // No special node is in context.
146 MediaTypeNone = 0x0,
147 // An image node is selected.
148 MediaTypeImage,
149 // A video node is selected.
150 MediaTypeVideo,
151 // An audio node is selected.
152 MediaTypeAudio,
153 // A canvas node is selected.
154 MediaTypeCanvas,
155 // A file node is selected.
156 MediaTypeFile,
157 // A plugin node is selected.
158 MediaTypePlugin,
159 MediaTypeLast = MediaTypePlugin
160 };
161 // Must match blink::WebContextMenuData::MediaFlags:
162 enum MediaFlags {
163 MediaNone = 0x0,
164 MediaInError = 0x1,
165 MediaPaused = 0x2,
166 MediaMuted = 0x4,
167 MediaLoop = 0x8,
168 MediaCanSave = 0x10,
169 MediaHasAudio = 0x20,
170 MediaCanToggleControls = 0x40,
171 MediaControls = 0x80,
172 MediaCanPrint = 0x100,
173 MediaCanRotate = 0x200,
174 };
175
176 // Must match blink::WebContextMenuData::EditFlags:
177 enum EditFlags {
178 CanDoNone = 0x0,
179 CanUndo = 0x1,
180 CanRedo = 0x2,
181 CanCut = 0x4,
182 CanCopy = 0x8,
183 CanPaste = 0x10,
184 CanDelete = 0x20,
185 CanSelectAll = 0x40,
186 CanTranslate = 0x80,
187 CanEditRichly = 0x100,
188 };
189
190 WebEngineContextMenuData():d(new WebEngineContextMenuSharedData) {
191 }
192
193 void setPosition(const QPoint &pos) {
194 d->pos = pos;
195 }
196
197 QPoint position() const {
198 return d->pos;
199 }
200
201 void setLinkUrl(const QUrl &url) {
202 d->linkUrl = url;
203 }
204
205 QUrl linkUrl() const {
206 return d->linkUrl;
207 }
208
209 void setUnfilteredLinkUrl(const QUrl &url) {
210 d->unfilteredLinkUrl = url;
211 }
212
213 QUrl unfilteredLinkUrl() const {
214 return d->unfilteredLinkUrl;
215 }
216
217 void setLinkText(const QString &text) {
218 d->linkText = text;
219 }
220
221 QString linkText() const {
222 return d->linkText;
223 }
224
225 void setSelectedText(const QString &text) {
226 d->selectedText = text;
227 }
228
229 QString selectedText() const {
230 return d->selectedText;
231 }
232
233 void setMediaUrl(const QUrl &url) {
234 d->mediaUrl = url;
235 }
236
237 QUrl mediaUrl() const {
238 return d->mediaUrl;
239 }
240
241 void setMediaType(MediaType type) {
242 d->mediaType = type;
243 }
244
245 MediaType mediaType() const {
246 return MediaType(d->mediaType);
247 }
248
249 void setHasImageContent(bool imageContent) {
250 d->hasImageContent = imageContent;
251 }
252
253 bool hasImageContent() const {
254 return d->hasImageContent;
255 }
256
257 void setMediaFlags(MediaFlags flags) {
258 d->mediaFlags = flags;
259 }
260
261 MediaFlags mediaFlags() const {
262 return MediaFlags(d->mediaFlags);
263 }
264
265 void setEditFlags(EditFlags flags) {
266 d->editFlags = flags;
267 }
268
269 EditFlags editFlags() const {
270 return EditFlags(d->editFlags);
271 }
272
273 void setSuggestedFileName(const QString &filename) {
274 d->suggestedFileName = filename;
275 }
276
277 QString suggestedFileName() const {
278 return d->suggestedFileName;
279 }
280
281 void setIsEditable(bool editable) {
282 d->isEditable = editable;
283 }
284
285 bool isEditable() const {
286 return d->isEditable;
287 }
288
289 void setIsSpellCheckerEnabled(bool spellCheckerEnabled) {
290 d->isSpellCheckerEnabled = spellCheckerEnabled;
291 }
292
293 bool isSpellCheckerEnabled() const {
294 return d->isSpellCheckerEnabled;
295 }
296
297 void setMisspelledWord(const QString &word) {
298 d->misspelledWord = word;
299 }
300
301 QString misspelledWord() const {
302 return d->misspelledWord;
303 }
304
305 void setSpellCheckerSuggestions(const QStringList &suggestions) {
306 d->spellCheckerSuggestions = suggestions;
307 }
308
309 QStringList spellCheckerSuggestions() const {
310 return d->spellCheckerSuggestions;
311 }
312
313 void setFrameUrl(const QUrl &url) {
314 d->frameUrl = url;
315 }
316
317 QUrl frameUrl() const {
318 return d->frameUrl;
319 }
320
321 void setPageUrl(const QUrl &url) {
322 d->pageUrl = url;
323 }
324
325 QUrl pageUrl() const {
326 return d->pageUrl;
327 }
328
329 QUrl referrerUrl() const {
330 return !d->frameUrl.isEmpty() ? d->frameUrl : d->pageUrl;
331 }
332
333 void setReferrerPolicy(ReferrerPolicy referrerPolicy) {
334 d->referrerPolicy = referrerPolicy;
335 }
336
337 ReferrerPolicy referrerPolicy() const {
338 return d->referrerPolicy;
339 }
340
341private:
342 QSharedDataPointer<WebEngineContextMenuSharedData> d;
343};
344
345
346class Q_WEBENGINECORE_PRIVATE_EXPORT WebContentsAdapterClient {
347public:
348 // This must match window_open_disposition_list.h.
349 enum WindowOpenDisposition {
350 UnknownDisposition = 0,
351 CurrentTabDisposition = 1,
352 SingletonTabDisposition = 2,
353 NewForegroundTabDisposition = 3,
354 NewBackgroundTabDisposition = 4,
355 NewPopupDisposition = 5,
356 NewWindowDisposition = 6,
357 SaveToDiskDisposition = 7,
358 OffTheRecordDisposition = 8,
359 IgnoreActionDisposition = 9,
360 };
361
362 // Must match the values in javascript_dialog_type.h.
363 enum JavascriptDialogType {
364 AlertDialog,
365 ConfirmDialog,
366 PromptDialog,
367 UnloadDialog,
368 // Leave room for potential new specs
369 InternalAuthorizationDialog = 0x10,
370 };
371
372 enum NavigationRequestAction {
373 AcceptRequest,
374 // Make room in the valid range of the enum for extra actions exposed in Experimental.
375 IgnoreRequest = 0xFF
376 };
377
378 enum NavigationType {
379 LinkNavigation,
380 TypedNavigation,
381 FormSubmittedNavigation,
382 BackForwardNavigation,
383 ReloadNavigation,
384 OtherNavigation,
385 RedirectNavigation,
386 };
387
388 enum JavaScriptConsoleMessageLevel {
389 Info = 0,
390 Warning,
391 Error
392 };
393
394 enum RenderProcessTerminationStatus {
395 NormalTerminationStatus = 0,
396 AbnormalTerminationStatus,
397 CrashedTerminationStatus,
398 KilledTerminationStatus
399 };
400
401 enum ClientType {
402 QmlClient,
403 WidgetsClient
404 };
405
406 enum MediaRequestFlag {
407 MediaNone = 0,
408 MediaAudioCapture = 0x01,
409 MediaVideoCapture = 0x02,
410 MediaDesktopAudioCapture = 0x04,
411 MediaDesktopVideoCapture = 0x08
412 };
413 Q_DECLARE_FLAGS(MediaRequestFlags, MediaRequestFlag)
414
415 enum class LifecycleState {
416 Active,
417 Frozen,
418 Discarded,
419 };
420
421 enum class LoadingState {
422 Unloaded,
423 Loading,
424 Loaded,
425 };
426
427 virtual ~WebContentsAdapterClient() { }
428
429 virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client) = 0;
430 virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegateForPopup(RenderWidgetHostViewQtDelegateClient *client) = 0;
431 virtual void initializationFinished() = 0;
432 virtual void lifecycleStateChanged(LifecycleState) = 0;
433 virtual void recommendedStateChanged(LifecycleState) = 0;
434 virtual void visibleChanged(bool) = 0;
435 virtual void titleChanged(const QString&) = 0;
436 virtual void urlChanged(const QUrl&) = 0;
437 virtual void iconChanged(const QUrl&) = 0;
438 virtual void loadProgressChanged(int progress) = 0;
439 virtual void didUpdateTargetURL(const QUrl&) = 0;
440 virtual void selectionChanged() = 0;
441 virtual void recentlyAudibleChanged(bool recentlyAudible) = 0;
442 virtual QRectF viewportRect() const = 0;
443 virtual QColor backgroundColor() const = 0;
444 virtual void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) = 0;
445 virtual void loadCommitted() = 0;
446 virtual void loadVisuallyCommitted() = 0;
447 virtual void loadFinished(bool success, const QUrl &url, bool isErrorPage = false, int errorCode = 0, const QString &errorDescription = QString()) = 0;
448 virtual void focusContainer() = 0;
449 virtual void unhandledKeyEvent(QKeyEvent *event) = 0;
450 virtual void adoptNewWindow(QSharedPointer<WebContentsAdapter> newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect & initialGeometry, const QUrl &targetUrl) = 0;
451 virtual bool isBeingAdopted() = 0;
452 virtual void close() = 0;
453 virtual void windowCloseRejected() = 0;
454 virtual void contextMenuRequested(const WebEngineContextMenuData &) = 0;
455 virtual void navigationRequested(int navigationType, const QUrl &url, int &navigationRequestAction, bool isMainFrame) = 0;
456 virtual void requestFullScreenMode(const QUrl &origin, bool fullscreen) = 0;
457 virtual bool isFullScreenMode() const = 0;
458 virtual void javascriptDialog(QSharedPointer<JavaScriptDialogController>) = 0;
459 virtual void runFileChooser(QSharedPointer<FilePickerController>) = 0;
460 virtual void showColorDialog(QSharedPointer<ColorChooserController>) = 0;
461 virtual void didRunJavaScript(quint64 requestId, const QVariant& result) = 0;
462 virtual void didFetchDocumentMarkup(quint64 requestId, const QString& result) = 0;
463 virtual void didFetchDocumentInnerText(quint64 requestId, const QString& result) = 0;
464 virtual void didFindText(quint64 requestId, int matchCount) = 0;
465 virtual void didPrintPage(quint64 requestId, QSharedPointer<QByteArray>) = 0;
466 virtual void didPrintPageToPdf(const QString &filePath, bool success) = 0;
467 virtual bool passOnFocus(bool reverse) = 0;
468 // returns the last QObject (QWidget/QQuickItem) based object in the accessibility
469 // hierarchy before going into the BrowserAccessibility tree
470 virtual QObject *accessibilityParentObject() = 0;
471 virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID) = 0;
472 virtual void authenticationRequired(QSharedPointer<AuthenticationDialogController>) = 0;
473 virtual void runGeolocationPermissionRequest(const QUrl &securityOrigin) = 0;
474 virtual void runMediaAccessPermissionRequest(const QUrl &securityOrigin, MediaRequestFlags requestFlags) = 0;
475 virtual void runMouseLockPermissionRequest(const QUrl &securityOrigin) = 0;
476 virtual void runQuotaRequest(QWebEngineQuotaRequest) = 0;
477 virtual void runRegisterProtocolHandlerRequest(QWebEngineRegisterProtocolHandlerRequest) = 0;
478 virtual void runUserNotificationPermissionRequest(const QUrl &securityOrigin) = 0;
479 virtual WebEngineSettings *webEngineSettings() const = 0;
480 RenderProcessTerminationStatus renderProcessExitStatus(int);
481 virtual void renderProcessTerminated(RenderProcessTerminationStatus terminationStatus, int exitCode) = 0;
482 virtual void requestGeometryChange(const QRect &geometry, const QRect &frameGeometry) = 0;
483 virtual void allowCertificateError(const QSharedPointer<CertificateErrorController> &errorController) = 0;
484 virtual void selectClientCert(const QSharedPointer<ClientCertSelectController> &selectController) = 0;
485 virtual void updateScrollPosition(const QPointF &position) = 0;
486 virtual void updateContentsSize(const QSizeF &size) = 0;
487 virtual void updateNavigationActions() = 0;
488 virtual void updateEditActions() = 0;
489 virtual void startDragging(const content::DropData &dropData, Qt::DropActions allowedActions,
490 const QPixmap &pixmap, const QPoint &offset) = 0;
491 virtual bool supportsDragging() const = 0;
492 virtual bool isEnabled() const = 0;
493 virtual const QObject *holdingQObject() const = 0;
494 virtual void setToolTip(const QString& toolTipText) = 0;
495 virtual ClientType clientType() = 0;
496 virtual void printRequested() = 0;
497 virtual void widgetChanged(RenderWidgetHostViewQtDelegate *newWidget) = 0;
498 virtual void interceptRequest(QWebEngineUrlRequestInfo &) { }
499 virtual TouchHandleDrawableClient *createTouchHandle(const QMap<int, QImage> &images) = 0;
500 virtual void showTouchSelectionMenu(TouchSelectionMenuController *menuController, const QRect &bounds, const QSize &handleSize) = 0;
501 virtual void hideTouchSelectionMenu() = 0;
502
503 virtual ProfileAdapter *profileAdapter() = 0;
504 virtual WebContentsAdapter* webContentsAdapter() = 0;
505 virtual void releaseProfile() = 0;
506
507};
508
509} // namespace QtWebEngineCore
510
511#endif // WEB_CONTENTS_ADAPTER_CLIENT_H
512