aboutsummaryrefslogtreecommitdiff
path: root/plugins/ProfileEditor/forms/profileview.cpp
blob: e073dbb498acf8ca8010182fd6bae00ed20183ba (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * This file is part of smolbote. It's copyrighted by the contributors recorded
 * in the version control history of the file, available from its original
 * location: https://neueland.iserlohn-fortress.net/smolbote.hg
 *
 * SPDX-License-Identifier: GPL-3.0
 */

#include "profileview.h"
#include "ui_profileview.h"
#include <QWebEngineSettings>

inline void connectSetting(QCheckBox *checkBox, QWebEngineSettings *settings, QWebEngineSettings::WebAttribute attr)
{
    QObject::connect(checkBox, &QCheckBox::clicked, [settings, attr](bool checked){
        settings->setAttribute(attr, checked);
    });
}

ProfileView::ProfileView(QWebEngineProfile *profile, QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::ProfileView)
{
    Q_CHECK_PTR(profile);
    m_profile = profile;
    ui->setupUi(this);

    QWebEngineSettings *settings = m_profile->settings();
    connectSetting(ui->autoloadImages, settings, QWebEngineSettings::AutoLoadImages);
    connectSetting(ui->autoloadIcons, settings, QWebEngineSettings::AutoLoadIconsForPage);

    connectSetting(ui->javascriptEnabled, settings, QWebEngineSettings::JavascriptEnabled);
    connectSetting(ui->javascriptCanAccessClipboard, settings, QWebEngineSettings::JavascriptCanAccessClipboard);
    connectSetting(ui->javascriptCanOpenWindows, settings, QWebEngineSettings::JavascriptCanOpenWindows);
    connectSetting(ui->javascriptCanActivateWindows, settings, QWebEngineSettings::AllowWindowActivationFromJavaScript);

    connectSetting(ui->linksIncludedInFocusChain, settings, QWebEngineSettings::LinksIncludedInFocusChain);
    connectSetting(ui->spatialNavigationEnabled, settings, QWebEngineSettings::SpatialNavigationEnabled);
    connectSetting(ui->focusOnNavigationEnabled, settings, QWebEngineSettings::FocusOnNavigationEnabled);
    connectSetting(ui->touchIconsEnabled, settings, QWebEngineSettings::TouchIconsEnabled);

    connectSetting(ui->showScrollBars, settings, QWebEngineSettings::ShowScrollBars);
    connectSetting(ui->scrollAnimatorEnabled, settings, QWebEngineSettings::ScrollAnimatorEnabled);
    connectSetting(ui->errorPagesEnabled, settings, QWebEngineSettings::ErrorPageEnabled);

    connectSetting(ui->localContentCanAccessRemoteUrls, settings, QWebEngineSettings::LocalContentCanAccessRemoteUrls);
    connectSetting(ui->localContentCanAccessFileUrls, settings, QWebEngineSettings::LocalContentCanAccessFileUrls);

    connectSetting(ui->localStorageEnabled, settings, QWebEngineSettings::LocalStorageEnabled);
    connectSetting(ui->webglEnabled, settings, QWebEngineSettings::WebGLEnabled);
    connectSetting(ui->canvasEnabled, settings, QWebEngineSettings::Accelerated2dCanvasEnabled);

    connectSetting(ui->xssAuditingEnabled, settings, QWebEngineSettings::XSSAuditingEnabled);
    connectSetting(ui->hyperlinkAuditingEnabled, settings, QWebEngineSettings::HyperlinkAuditingEnabled);

    connectSetting(ui->allowRunningInsecureContent, settings, QWebEngineSettings::AllowRunningInsecureContent);
    connectSetting(ui->allowGeolocationOnInsecureContent, settings, QWebEngineSettings::AllowGeolocationOnInsecureOrigins);
    connectSetting(ui->ppapiPluginsEnabled, settings, QWebEngineSettings::PluginsEnabled);
    connectSetting(ui->fullscreenSupportEnabled, settings, QWebEngineSettings::FullScreenSupportEnabled);
    connectSetting(ui->screenCaptureEnabled, settings, QWebEngineSettings::ScreenCaptureEnabled);
    connectSetting(ui->printElementBackgrounds, settings, QWebEngineSettings::PrintElementBackgrounds);

    // actions
    connect(ui->clearCache_pushButton, &QPushButton::clicked, [this]() {
        this->m_profile->clearHttpCache();
    });
    connect(ui->clearHistory_pushButton, &QPushButton::clicked, [this]() {
        this->m_profile->clearAllVisitedLinks();
    });

    loadProfile();
}

ProfileView::~ProfileView()
{
    delete ui;
}

void ProfileView::loadProfile()
{
    if(m_profile->storageName().isEmpty())
        setWindowTitle(tr("Off-the-record"));
    else
        setWindowTitle(m_profile->storageName());

    // http
    ui->userAgent->setPlainText(m_profile->httpUserAgent());
    ui->acceptLanguage->setPlainText(m_profile->httpAcceptLanguage());
    ui->cacheType->setCurrentIndex(m_profile->httpCacheType());
    ui->cacheSize->setText(QString::number(m_profile->httpCacheMaximumSize()));

    // path
    ui->storagePath_lineEdit->setText(m_profile->persistentStoragePath());
    ui->cachePath_lineEdit->setText(m_profile->cachePath());

    // settings
    QWebEngineSettings *settings = m_profile->settings();
    ui->autoloadImages->setChecked(settings->testAttribute(QWebEngineSettings::AutoLoadImages));
    ui->javascriptEnabled->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptEnabled));
    ui->javascriptCanOpenWindows->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptCanOpenWindows));
    ui->javascriptCanAccessClipboard->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptCanAccessClipboard));
    ui->linksIncludedInFocusChain->setChecked(settings->testAttribute(QWebEngineSettings::LinksIncludedInFocusChain));
    ui->localStorageEnabled->setChecked(settings->testAttribute(QWebEngineSettings::LocalStorageEnabled));
    ui->localContentCanAccessRemoteUrls->setChecked(settings->testAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls));
    ui->xssAuditingEnabled->setChecked(settings->testAttribute(QWebEngineSettings::XSSAuditingEnabled));
    ui->spatialNavigationEnabled->setChecked(settings->testAttribute(QWebEngineSettings::SpatialNavigationEnabled));
    ui->localContentCanAccessFileUrls->setChecked(settings->testAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls));
    ui->hyperlinkAuditingEnabled->setChecked(settings->testAttribute(QWebEngineSettings::HyperlinkAuditingEnabled));
    ui->scrollAnimatorEnabled->setChecked(settings->testAttribute(QWebEngineSettings::ScrollAnimatorEnabled));
    ui->errorPagesEnabled->setChecked(settings->testAttribute(QWebEngineSettings::ErrorPageEnabled));
    ui->ppapiPluginsEnabled->setChecked(settings->testAttribute(QWebEngineSettings::PluginsEnabled));
    ui->fullscreenSupportEnabled->setChecked(settings->testAttribute(QWebEngineSettings::FullScreenSupportEnabled));
    ui->screenCaptureEnabled->setChecked(settings->testAttribute(QWebEngineSettings::ScreenCaptureEnabled));
    ui->webglEnabled->setChecked(settings->testAttribute(QWebEngineSettings::WebGLEnabled));
    ui->canvasEnabled->setChecked(settings->testAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled));
    ui->autoloadIcons->setChecked(settings->testAttribute(QWebEngineSettings::AutoLoadIconsForPage));
    ui->touchIconsEnabled->setChecked(settings->testAttribute(QWebEngineSettings::TouchIconsEnabled));
    ui->focusOnNavigationEnabled->setChecked(settings->testAttribute(QWebEngineSettings::FocusOnNavigationEnabled));
    ui->printElementBackgrounds->setChecked(settings->testAttribute(QWebEngineSettings::PrintElementBackgrounds));
    ui->allowRunningInsecureContent->setChecked(settings->testAttribute(QWebEngineSettings::AllowRunningInsecureContent));
    ui->allowGeolocationOnInsecureContent->setChecked(settings->testAttribute(QWebEngineSettings::AllowGeolocationOnInsecureOrigins));
    ui->javascriptCanActivateWindows->setChecked(settings->testAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript));
    ui->showScrollBars->setChecked(settings->testAttribute(QWebEngineSettings::ShowScrollBars));

    // policy
    ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy());
}

void ProfileView::updateProfile()
{
    // http
    m_profile->setHttpUserAgent(ui->userAgent->toPlainText());
    m_profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText());
    switch(ui->cacheType->currentIndex()) {
    case 0:
        m_profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
        break;
    case 1:
        m_profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
        break;
    case 2:
        m_profile->setHttpCacheType(QWebEngineProfile::NoCache);
        break;
    default:
        break;
    }
    m_profile->setHttpCacheMaximumSize(ui->cacheSize->text().toInt());

    // policy
    switch(ui->cookiePolicy->currentIndex()) {
    case 0:
        m_profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
        break;
    case 1:
        m_profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
        break;
    case 2:
        m_profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
        break;
    default:
        break;
    }
}