summaryrefslogtreecommitdiffstats
path: root/src/plugins/wasm/qwasmwebview_p.h
blob: 6695f6609fc6115c9d8c96fa258f640e481d1064 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default

#ifndef QWASMWEBVIEW_P_H
#define QWASMWEBVIEW_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <QtCore/qobject.h>
#include <QtCore/qurl.h>
#include <QtCore/qpointer.h>
#include <QtGui/qwindow.h>
#include <QtGui/qpa/qplatformwindow.h>
#include <QtGui/qpa/qplatformwindow_p.h>
#include <emscripten/val.h>

#include <private/qwebview_p.h>

#include <optional>

QT_BEGIN_NAMESPACE

class QWasmWebViewSettingsPrivate final : public QWebViewSettingsPrivate
{
    Q_OBJECT
public:
    explicit QWasmWebViewSettingsPrivate(QObject *p = nullptr);

    bool localStorageEnabled() const final;
    bool javaScriptEnabled() const final;
    bool localContentCanAccessFileUrls() const final;
    bool allowFileAccess() const final;

    void setLocalContentCanAccessFileUrls(bool enabled) final;
    void setJavaScriptEnabled(bool enabled) final;
    void setLocalStorageEnabled(bool enabled) final;
    void setAllowFileAccess(bool enabled) final;
};

class QWasmWebViewPrivate final : public QWebViewPrivate
{
    Q_OBJECT
public:
    explicit QWasmWebViewPrivate(QWebView *view);
    ~QWasmWebViewPrivate() override;

    void initialize(QObject *context) override { Q_UNUSED(context); };
    QString httpUserAgent() const final;
    void setHttpUserAgent(const QString &httpUserAgent) final;
    QUrl url() const override;
    void setUrl(const QUrl &url) final;
    bool canGoBack() const final;
    bool canGoForward() const final;
    QString title() const final;
    int loadProgress() const final;
    bool isLoading() const final;

    QWindow *nativeWindow() const override { return m_window; }

    void goBack() final;
    void goForward() final;
    void reload() final;
    void stop() final;
    void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()) final;
    void setCookie(const QString &domain, const QString &name, const QString &value) final;
    void deleteCookie(const QString &domain, const QString &name) final;
    void deleteAllCookies() final;

protected:
    void runJavaScriptPrivate(const QString& script,
                              int callbackId) final;
    QWebViewSettingsPrivate *settings() const final;

private:
    Q_INVOKABLE void initializeIFrame();
    void updateGeometry();

    QWasmWebViewSettingsPrivate *m_settings;
    QWindow *m_window = nullptr;
    std::optional<emscripten::val> m_iframe;
    std::optional<QRect> m_geometry;
    QUrl m_currentUrl;
};

QT_END_NAMESPACE

#endif // QWASMWEBVIEW_P_H