| 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 | |
| 26 | #include <QtCore/qpointer.h> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QWebViewLoadRequestPrivate; |
| 31 | |
| 32 | class Q_WEBVIEW_EXPORT QWebViewSettings : public QObject |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | Q_PROPERTY(bool localStorageEnabled READ localStorageEnabled WRITE setLocalStorageEnabled NOTIFY localStorageEnabledChanged) |
| 36 | Q_PROPERTY(bool javaScriptEnabled READ javaScriptEnabled WRITE setJavaScriptEnabled NOTIFY javaScriptEnabledChanged) |
| 37 | Q_PROPERTY(bool allowFileAccess READ allowFileAccess WRITE setAllowFileAccess NOTIFY allowFileAccessChanged) |
| 38 | Q_PROPERTY(bool localContentCanAccessFileUrls READ localContentCanAccessFileUrls WRITE setLocalContentCanAccessFileUrls NOTIFY localContentCanAccessFileUrlsChanged) |
| 39 | |
| 40 | public: |
| 41 | explicit QWebViewSettings(QAbstractWebViewSettings *webview); |
| 42 | ~QWebViewSettings() override; |
| 43 | |
| 44 | bool localStorageEnabled() const; |
| 45 | bool javaScriptEnabled() const; |
| 46 | bool allowFileAccess() const; |
| 47 | bool localContentCanAccessFileUrls() const; |
| 48 | |
| 49 | public Q_SLOTS: |
| 50 | void setLocalStorageEnabled(bool enabled); |
| 51 | void setJavaScriptEnabled(bool enabled); |
| 52 | void setAllowFileAccess(bool enabled); |
| 53 | void setLocalContentCanAccessFileUrls(bool enabled); |
| 54 | |
| 55 | signals: |
| 56 | void localStorageEnabledChanged(); |
| 57 | void javaScriptEnabledChanged(); |
| 58 | void allowFileAccessChanged(); |
| 59 | void localContentCanAccessFileUrlsChanged(); |
| 60 | |
| 61 | private: |
| 62 | QPointer<QAbstractWebViewSettings> d; |
| 63 | }; |
| 64 | |
| 65 | class Q_WEBVIEW_EXPORT QWebView |
| 66 | : public QObject |
| 67 | , public QWebViewInterface |
| 68 | , public QNativeViewController |
| 69 | { |
| 70 | Q_OBJECT |
| 71 | public: |
| 72 | enum LoadStatus { // Changes here needs to be done in QQuickWebView as well |
| 73 | LoadStartedStatus, |
| 74 | LoadStoppedStatus, |
| 75 | LoadSucceededStatus, |
| 76 | LoadFailedStatus |
| 77 | }; |
| 78 | |
| 79 | explicit QWebView(QObject *p = nullptr); |
| 80 | ~QWebView() override; |
| 81 | |
| 82 | QString httpUserAgent() const override; |
| 83 | void setHttpUserAgent(const QString &httpUserAgent) override; |
| 84 | QUrl url() const override; |
| 85 | void setUrl(const QUrl &url) override; |
| 86 | bool canGoBack() const override; |
| 87 | bool canGoForward() const override; |
| 88 | QString title() const override; |
| 89 | int loadProgress() const override; |
| 90 | bool isLoading() const override; |
| 91 | |
| 92 | void setParentView(QObject *view) override; |
| 93 | QObject *parentView() const override; |
| 94 | void setGeometry(const QRect &geometry) override; |
| 95 | void setVisibility(QWindow::Visibility visibility) override; |
| 96 | void setVisible(bool visible) override; |
| 97 | void setFocus(bool focus) override; |
| 98 | void updatePolish() override; |
| 99 | QWebViewSettings *getSettings() const; |
| 100 | |
| 101 | public Q_SLOTS: |
| 102 | void goBack() override; |
| 103 | void goForward() override; |
| 104 | void reload() override; |
| 105 | void stop() override; |
| 106 | void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()) override; |
| 107 | void setCookie(const QString &domain, const QString &name, |
| 108 | const QString &value) override; |
| 109 | void deleteCookie(const QString &domain, const QString &name) override; |
| 110 | void deleteAllCookies() override; |
| 111 | |
| 112 | Q_SIGNALS: |
| 113 | void titleChanged(); |
| 114 | void urlChanged(); |
| 115 | void loadingChanged(const QWebViewLoadRequestPrivate &loadRequest); |
| 116 | void loadProgressChanged(); |
| 117 | void javaScriptResult(int id, const QVariant &result); |
| 118 | void requestFocus(bool focus); |
| 119 | void httpUserAgentChanged(); |
| 120 | void cookieAdded(const QString &domain, const QString &name); |
| 121 | void cookieRemoved(const QString &domain, const QString &name); |
| 122 | |
| 123 | protected: |
| 124 | void init() override; |
| 125 | void runJavaScriptPrivate(const QString &script, |
| 126 | int callbackId) override; |
| 127 | |
| 128 | private Q_SLOTS: |
| 129 | void onTitleChanged(const QString &title); |
| 130 | void onUrlChanged(const QUrl &url); |
| 131 | void onLoadProgressChanged(int progress); |
| 132 | void onLoadingChanged(const QWebViewLoadRequestPrivate &loadRequest); |
| 133 | void onHttpUserAgentChanged(const QString &httpUserAgent); |
| 134 | |
| 135 | private: |
| 136 | friend class QQuickViewController; |
| 137 | friend class QQuickWebView; |
| 138 | |
| 139 | QAbstractWebView *d; |
| 140 | QWebViewSettings *m_settings; |
| 141 | |
| 142 | // provisional data |
| 143 | int m_progress; |
| 144 | QString m_title; |
| 145 | QUrl m_url; |
| 146 | mutable QString m_httpUserAgent; |
| 147 | }; |
| 148 | |
| 149 | QT_END_NAMESPACE |
| 150 | |
| 151 | #endif // QWEBVIEW_P_H |
| 152 | |