1// Copyright (C) 2015 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QWEBVIEW_P_H
5#define QWEBVIEW_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qabstractwebview_p.h"
19#include "qwebviewinterface_p.h"
20#include "qnativeviewcontroller_p.h"
21#include <QtCore/qobject.h>
22#include <QtCore/qurl.h>
23#include <QtCore/qvariant.h>
24#include <QtGui/qimage.h>
25
26QT_BEGIN_NAMESPACE
27
28class QWebViewLoadRequestPrivate;
29
30class Q_WEBVIEW_EXPORT QWebViewSettings : public QObject
31{
32 Q_OBJECT
33 Q_PROPERTY(bool localStorageEnabled READ localStorageEnabled WRITE setLocalStorageEnabled NOTIFY localStorageEnabledChanged)
34 Q_PROPERTY(bool javaScriptEnabled READ javaScriptEnabled WRITE setJavaScriptEnabled NOTIFY javaScriptEnabledChanged)
35 Q_PROPERTY(bool allowFileAccess READ allowFileAccess WRITE setAllowFileAccess NOTIFY allowFileAccessChanged)
36 Q_PROPERTY(bool localContentCanAccessFileUrls READ localContentCanAccessFileUrls WRITE setLocalContentCanAccessFileUrls NOTIFY localContentCanAccessFileUrlsChanged)
37
38public:
39 explicit QWebViewSettings(QAbstractWebViewSettings *webview);
40 ~QWebViewSettings() override;
41
42 bool localStorageEnabled() const;
43 bool javaScriptEnabled() const;
44 bool allowFileAccess() const;
45 bool localContentCanAccessFileUrls() const;
46
47public Q_SLOTS:
48 void setLocalStorageEnabled(bool enabled);
49 void setJavaScriptEnabled(bool enabled);
50 void setAllowFileAccess(bool enabled);
51 void setLocalContentCanAccessFileUrls(bool enabled);
52
53signals:
54 void localStorageEnabledChanged();
55 void javaScriptEnabledChanged();
56 void allowFileAccessChanged();
57 void localContentCanAccessFileUrlsChanged();
58
59private:
60 QPointer<QAbstractWebViewSettings> d;
61};
62
63class Q_WEBVIEW_EXPORT QWebView
64 : public QObject
65 , public QWebViewInterface
66 , public QNativeViewController
67{
68 Q_OBJECT
69public:
70 enum LoadStatus { // Changes here needs to be done in QQuickWebView as well
71 LoadStartedStatus,
72 LoadStoppedStatus,
73 LoadSucceededStatus,
74 LoadFailedStatus
75 };
76
77 explicit QWebView(QObject *p = nullptr);
78 ~QWebView() override;
79
80 QString httpUserAgent() const override;
81 void setHttpUserAgent(const QString &httpUserAgent) override;
82 QUrl url() const override;
83 void setUrl(const QUrl &url) override;
84 bool canGoBack() const override;
85 bool canGoForward() const override;
86 QString title() const override;
87 int loadProgress() const override;
88 bool isLoading() const override;
89
90 void setParentView(QObject *view) override;
91 QObject *parentView() const override;
92 void setGeometry(const QRect &geometry) override;
93 void setVisibility(QWindow::Visibility visibility) override;
94 void setVisible(bool visible) override;
95 void setFocus(bool focus) override;
96 void updatePolish() override;
97 QWebViewSettings *getSettings() const;
98
99public Q_SLOTS:
100 void goBack() override;
101 void goForward() override;
102 void reload() override;
103 void stop() override;
104 void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()) override;
105 void setCookie(const QString &domain, const QString &name,
106 const QString &value) override;
107 void deleteCookie(const QString &domain, const QString &name) override;
108 void deleteAllCookies() override;
109
110Q_SIGNALS:
111 void titleChanged();
112 void urlChanged();
113 void loadingChanged(const QWebViewLoadRequestPrivate &loadRequest);
114 void loadProgressChanged();
115 void javaScriptResult(int id, const QVariant &result);
116 void requestFocus(bool focus);
117 void httpUserAgentChanged();
118 void cookieAdded(const QString &domain, const QString &name);
119 void cookieRemoved(const QString &domain, const QString &name);
120
121protected:
122 void init() override;
123 void runJavaScriptPrivate(const QString &script,
124 int callbackId) override;
125
126private Q_SLOTS:
127 void onTitleChanged(const QString &title);
128 void onUrlChanged(const QUrl &url);
129 void onLoadProgressChanged(int progress);
130 void onLoadingChanged(const QWebViewLoadRequestPrivate &loadRequest);
131 void onHttpUserAgentChanged(const QString &httpUserAgent);
132
133private:
134 friend class QQuickViewController;
135 friend class QQuickWebView;
136
137 QAbstractWebView *d;
138 QWebViewSettings *m_settings;
139
140 // provisional data
141 int m_progress;
142 QString m_title;
143 QUrl m_url;
144 mutable QString m_httpUserAgent;
145};
146
147QT_END_NAMESPACE
148
149#endif // QWEBVIEW_P_H
150

source code of qtwebview/src/webview/qwebview_p.h