webenginepart.h 5.88 KB
Newer Older
1 2 3 4
/*
 * This file is part of the KDE project.
 *
 * Copyright (C) 2007 Trolltech ASA
5
 * Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
6
 * Copyright (C) 2009 Dawit Alemayehu <adawit@kde.org>
7
 *
8 9 10 11
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
12
 *
13 14 15 16
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 * details.
17
 *
18 19
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20 21
 *
 */
Sune Vuorela's avatar
Sune Vuorela committed
22 23
#ifndef WEBENGINEPART_H
#define WEBENGINEPART_H
24

25 26
#include "kwebenginepartlib_export.h"

27
#include <QWebEnginePage>
28

Sune Vuorela's avatar
Sune Vuorela committed
29
#include <KParts/ReadOnlyPart>
Daniel Grosz's avatar
Daniel Grosz committed
30
#include <QUrl>
31

32 33
namespace KParts {
  class BrowserExtension;
34 35 36
  class StatusBarExtension;
}

37
class QWebEngineView;
38
class WebEngineView;
39
class WebEnginePage;
40 41
class SearchBar;
class PasswordBar;
42
class FeaturePermissionBar;
43
class KUrlLabel;
Sune Vuorela's avatar
Sune Vuorela committed
44
class WebEngineBrowserExtension;
45
class WebEngineWallet;
46

47
/**
Sune Vuorela's avatar
Sune Vuorela committed
48
 * A KPart wrapper for the QtWebEngine's browser rendering engine.
49
 *
50 51
 * This class attempts to provide the same type of integration into KPart
 * plugin applications, such as Konqueror, in much the same way as KHTML.
52
 *
53
 * Unlink the KHTML part however, access into the internals of the rendering
Sune Vuorela's avatar
Sune Vuorela committed
54
 * engine are provided through existing QtWebEngine class ; @see QWebEngineView.
55 56
 *
 */
57
class KWEBENGINEPARTLIB_EXPORT WebEnginePart : public KParts::ReadOnlyPart
58 59
{
    Q_OBJECT
60
    Q_PROPERTY( bool modified READ isModified )
61
public:
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
62
    explicit WebEnginePart(QWidget* parentWidget = nullptr, QObject* parent = nullptr,
63 64
                         const QByteArray& cachedHistory = QByteArray(),
                         const QStringList& = QStringList());
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
65
    ~WebEnginePart() override;
66

67 68 69 70 71
    /**
     * Re-implemented for internal reasons. API remains unaffected.
     *
     * @see KParts::ReadOnlyPart::openUrl
     */
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
72
    bool openUrl(const QUrl &) override;
73

74 75 76 77 78
    /**
     * Re-implemented for internal reasons. API remains unaffected.
     *
     * @see KParts::ReadOnlyPart::closeUrl
     */
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
79
    bool closeUrl() override;
80 81

    /**
82 83
     * Returns a pointer to the render widget used to display a web page.
     *
84
     * @see QWebEngineView.
85
     */
86
    QWebEngineView *view() const;
87

88 89 90 91 92 93 94
    /**
     * Checks whether the page contains unsubmitted form changes.
     *
     * @return @p true if form changes exist.
     */
    bool isModified() const;

95 96 97 98
    /**
     * Connects the appropriate signals from the given page to the slots
     * in this class.
     */
99
    void connectWebEnginePageSignals(WebEnginePage* page);
100

101
    void slotShowFeaturePermissionBar(QWebEnginePage::Feature);
102 103 104

    void setWallet(WebEngineWallet* wallet);

105 106 107
public Q_SLOTS:
    void exitFullScreen();

108
protected:
109 110 111 112 113
    /**
     * Re-implemented for internal reasons. API remains unaffected.
     *
     * @see KParts::ReadOnlyPart::guiActivateEvent
     */
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
114
    void guiActivateEvent(KParts::GUIActivateEvent *) override;
115

116 117 118 119 120
    /**
     * Re-implemented for internal reasons. API remains unaffected.
     *
     * @see KParts::ReadOnlyPart::openFile
     */
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
121
    bool openFile() override;
122

123 124 125 126
private Q_SLOTS:
    void slotShowSecurity();
    void slotShowSearchBar();
    void slotLoadStarted();
Daniel Grosz's avatar
Daniel Grosz committed
127
    void slotLoadAborted(const QUrl &);
128
    void slotLoadFinished(bool);
129 130

    void slotSearchForText(const QString &text, bool backward);
Sune Vuorela's avatar
Sune Vuorela committed
131
    void slotLinkHovered(const QString &);
132 133
    //void slotSaveFrameState(QWebFrame *frame, QWebHistoryItem *item);
    //void slotRestoreFrameState(QWebFrame *frame);
Daniel Grosz's avatar
Daniel Grosz committed
134 135
    void slotLinkMiddleOrCtrlClicked(const QUrl&);
    void slotSelectionClipboardUrlPasted(const QUrl&, const QString&);
136 137

    void slotUrlChanged(const QUrl &);
138
    void resetWallet();
139 140
    void slotShowWalletMenu();
    void slotLaunchWalletManager();
141
    void togglePasswordStorableState(bool on);
142 143 144 145
    void slotRemoveCachedPasswords();
    void slotSetTextEncoding(QTextCodec*);
    void slotSetStatusBarText(const QString& text);
    void slotWindowCloseRequested();
146 147
    void slotSaveFormDataRequested(const QString &, const QUrl &);
    void slotSaveFormDataDone();
148
    void slotWalletSavedForms(const QUrl &url, bool success);
149
    void slotFillFormRequestCompleted(bool);
150

151 152
    void slotFeaturePermissionGranted(QWebEnginePage::Feature);
    void slotFeaturePermissionDenied(QWebEnginePage::Feature);
153

154
    void updateWalletStatusBarIcon();
155
    void walletFinishedFormDetection(const QUrl &url, bool found, bool autoFillableFound);
156
    void updateWalletActions();
157

158
private:
159 160
    WebEnginePage* page();
    const WebEnginePage* page() const;
161
    static void initWebEngineUrlSchemes();
162
    void deleteStatusBarWalletLabel();
163

164 165 166 167 168 169 170 171 172 173
    struct WalletData{
        enum Member{HasForms, HasAutofillableForms, HasCachedData};
        bool hasForms;
        bool hasAutoFillableForms;
        bool hasCachedData;
    };
    //Always use the following functions to change the values of m_walletData, as they automatically update the UI
    void updateWalletData(WalletData::Member which, bool status);
    void updateWalletData(std::initializer_list<bool> data);

174
    void attemptInstallKIOSchemeHandler(const QUrl &url);
175

176
    void initActions();
177
    void createWalletActions();
178
    void updateActions();
179 180

    bool m_emitOpenUrlNotify;
181 182

    WalletData m_walletData;
183
    bool m_doLoadFinishedActions;
184
    KUrlLabel* m_statusBarWalletLabel;
185 186
    SearchBar* m_searchBar;
    PasswordBar* m_passwordBar;
187
    FeaturePermissionBar* m_featurePermissionBar;
Sune Vuorela's avatar
Sune Vuorela committed
188
    WebEngineBrowserExtension* m_browserExtension;
189
    KParts::StatusBarExtension* m_statusBarExtension;
190
    WebEngineView* m_webView;
191
    WebEngineWallet* m_wallet;
192 193
};

Sune Vuorela's avatar
Sune Vuorela committed
194
#endif // WEBENGINEPART_H