summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@digia.com>2014-05-15 16:51:50 +0200
committerJocelyn Turcotte <jocelyn.turcotte@digia.com>2014-08-12 16:53:18 +0200
commit955a8d8a05d494f74238565d1a60fa6bd29c4f2b (patch)
treef8f49f95fe5ac2d80d90cdb4bd84a80bf7bf597b
parentd1ddc17b0fcb9ce809a81ddd71d0bc864b2738c9 (diff)
Widgets settings implementation
Implementing what is already available, namely the WebAttributes, font preferences and default text encoding, as well as a slightly different take on privateBrowsing. Change-Id: I128f060a4661d19aa1c9c4d6daae1f80fb33204b Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp39
-rw-r--r--src/webenginewidgets/api/qwebenginepage.h3
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h2
-rw-r--r--src/webenginewidgets/api/qwebenginesettings.cpp217
-rw-r--r--src/webenginewidgets/api/qwebenginesettings.h98
-rw-r--r--src/webenginewidgets/api/qwebenginesettings_p.h70
-rw-r--r--src/webenginewidgets/webenginewidgets.pro3
7 files changed, 408 insertions, 24 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 851ca8aea..71099e547 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -26,6 +26,8 @@
#include "javascript_dialog_controller.h"
#include "qwebenginehistory.h"
#include "qwebenginehistory_p.h"
+#include "qwebenginesettings.h"
+#include "qwebenginesettings_p.h"
#include "qwebengineview.h"
#include "qwebengineview_p.h"
#include "render_widget_host_view_qt_delegate_widget.h"
@@ -166,6 +168,7 @@ void CallbackDirectory::CallbackSharedDataPointer::doDeref()
QWebEnginePagePrivate::QWebEnginePagePrivate()
: adapter(new WebContentsAdapter)
, history(new QWebEngineHistory(new QWebEngineHistoryPrivate(this)))
+ , settings(new QWebEngineSettings(new QWebEngineSettingsPrivate(adapter.data())))
, view(0)
{
memset(actions, 0, sizeof(actions));
@@ -174,6 +177,7 @@ QWebEnginePagePrivate::QWebEnginePagePrivate()
QWebEnginePagePrivate::~QWebEnginePagePrivate()
{
delete history;
+ delete settings;
}
RenderWidgetHostViewQtDelegate *QWebEnginePagePrivate::CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client)
@@ -343,30 +347,6 @@ QObject *QWebEnginePagePrivate::accessibilityParentObject()
return view;
}
-namespace {
-class DummySettingsDelegate : public WebEngineSettingsDelegate {
-public:
- DummySettingsDelegate()
- : settings(0) {}
- void apply() { }
- WebEngineSettings* fallbackSettings() const { return settings; }
- WebEngineSettings *settings;
-};
-
-}// anonymous namespace
-
-WebEngineSettings *QWebEnginePagePrivate::webEngineSettings() const
-{
- static WebEngineSettings *dummySettings = 0;
- if (!dummySettings) {
- DummySettingsDelegate *dummyDelegate = new DummySettingsDelegate;
- dummySettings = new WebEngineSettings(dummyDelegate);
- dummyDelegate->settings = dummySettings;
- dummySettings->initDefaults();
- }
- return dummySettings;
-}
-
void QWebEnginePagePrivate::updateAction(QWebEnginePage::WebAction action) const
{
#ifdef QT_NO_ACTION
@@ -451,6 +431,12 @@ QWebEngineHistory *QWebEnginePage::history() const
return d->history;
}
+QWebEngineSettings *QWebEnginePage::settings() const
+{
+ Q_D(const QWebEnginePage);
+ return d->settings;
+}
+
void QWebEnginePage::setView(QWidget *view)
{
QWebEngineViewPrivate::bind(qobject_cast<QWebEngineView*>(view), this);
@@ -779,6 +765,11 @@ void QWebEnginePagePrivate::runFileChooser(WebContentsAdapterClient::FileChooser
adapter->filesSelectedInChooser(selectedFileNames, mode);
}
+WebEngineSettings *QWebEnginePagePrivate::webEngineSettings() const
+{
+ return settings->d->coreSettings.data();
+}
+
void QWebEnginePage::load(const QUrl& url)
{
Q_D(QWebEnginePage);
diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h
index 7d4a00e7e..7a709b363 100644
--- a/src/webenginewidgets/api/qwebenginepage.h
+++ b/src/webenginewidgets/api/qwebenginepage.h
@@ -34,6 +34,7 @@ QT_BEGIN_NAMESPACE
class QMenu;
class QWebEngineHistory;
class QWebEnginePage;
+class QWebEngineSettings;
class QWebEnginePagePrivate;
namespace QtWebEnginePrivate {
@@ -180,6 +181,8 @@ public:
void runJavaScript(const QString& scriptSource);
void runJavaScript(const QString& scriptSource, const QWebEngineCallback<const QVariant &> &resultCallback);
+ QWebEngineSettings *settings() const;
+
Q_SIGNALS:
void loadStarted();
void loadProgress(int progress);
diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
index f90c49216..3ace1804b 100644
--- a/src/webenginewidgets/api/qwebenginepage_p.h
+++ b/src/webenginewidgets/api/qwebenginepage_p.h
@@ -54,6 +54,7 @@ class WebContentsAdapter;
QT_BEGIN_NAMESPACE
class QWebEngineHistory;
class QWebEnginePage;
+class QWebEngineSettings;
class QWebEngineView;
class CallbackDirectory {
@@ -152,6 +153,7 @@ public:
QExplicitlySharedDataPointer<WebContentsAdapter> adapter;
QWebEngineHistory *history;
+ QWebEngineSettings *settings;
QWebEngineView *view;
QSize viewportSize;
QUrl m_explicitUrl;
diff --git a/src/webenginewidgets/api/qwebenginesettings.cpp b/src/webenginewidgets/api/qwebenginesettings.cpp
new file mode 100644
index 000000000..52cc59a80
--- /dev/null
+++ b/src/webenginewidgets/api/qwebenginesettings.cpp
@@ -0,0 +1,217 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qwebenginesettings.h"
+#include "qwebenginesettings_p.h"
+
+#include <QDebug>
+
+QT_USE_NAMESPACE
+
+static WebEngineSettings::Attribute toWebEngineAttribute(QWebEngineSettings::WebAttribute attribute) {
+ switch (attribute) {
+ case QWebEngineSettings::AutoLoadImages:
+ return WebEngineSettings::AutoLoadImages;
+ case QWebEngineSettings::JavascriptEnabled:
+ return WebEngineSettings::JavascriptEnabled;
+ case QWebEngineSettings::JavascriptCanOpenWindows:
+ return WebEngineSettings::JavascriptCanOpenWindows;
+ case QWebEngineSettings::JavascriptCanAccessClipboard:
+ return WebEngineSettings::JavascriptCanAccessClipboard;
+ case QWebEngineSettings::LinksIncludedInFocusChain:
+ return WebEngineSettings::LinksIncludedInFocusChain;
+ case QWebEngineSettings::LocalStorageEnabled:
+ return WebEngineSettings::LocalStorageEnabled;
+ case QWebEngineSettings::LocalContentCanAccessRemoteUrls:
+ return WebEngineSettings::LocalContentCanAccessRemoteUrls;
+ case QWebEngineSettings::XSSAuditingEnabled:
+ return WebEngineSettings::XSSAuditingEnabled;
+ case QWebEngineSettings::SpatialNavigationEnabled:
+ return WebEngineSettings::SpatialNavigationEnabled;
+ case QWebEngineSettings::LocalContentCanAccessFileUrls:
+ return WebEngineSettings::LocalContentCanAccessFileUrls;
+ case QWebEngineSettings::HyperlinkAuditingEnabled:
+ return WebEngineSettings::HyperlinkAuditingEnabled;
+ case QWebEngineSettings::ScrollAnimatorEnabled:
+ return WebEngineSettings::ScrollAnimatorEnabled;
+ default:
+ return WebEngineSettings::UnsupportedInCoreSettings;
+ }
+}
+
+Q_GLOBAL_STATIC(QList<QWebEngineSettingsPrivate*>, allSettings);
+
+QWebEngineSettingsPrivate::QWebEngineSettingsPrivate()
+ : coreSettings(new WebEngineSettings(this))
+{
+}
+
+QWebEngineSettingsPrivate::QWebEngineSettingsPrivate(WebContentsAdapter *adapter)
+ : coreSettings(new WebEngineSettings(this, adapter))
+{
+}
+
+void QWebEngineSettingsPrivate::apply()
+{
+ coreSettings->scheduleApply();
+ QWebEngineSettingsPrivate *globals = QWebEngineSettings::globalSettings()->d;
+ if (this == globals) {
+ Q_FOREACH (QWebEngineSettingsPrivate *settings, *allSettings)
+ settings->coreSettings->scheduleApply();
+ }
+}
+
+void QWebEngineSettingsPrivate::initDefaults()
+{
+ coreSettings->initDefaults();
+}
+
+WebEngineSettings *QWebEngineSettingsPrivate::fallbackSettings() const {
+ return QWebEngineSettings::globalSettings()->d->coreSettings.data();
+}
+
+QWebEngineSettings *QWebEngineSettings::globalSettings()
+{
+ static QWebEngineSettings* globalSettings = 0;
+ if (!globalSettings)
+ globalSettings = new QWebEngineSettings;
+ return globalSettings;
+}
+
+Q_STATIC_ASSERT_X(static_cast<int>(WebEngineSettings::StandardFont) == static_cast<int>(QWebEngineSettings::StandardFont), "The enum values must match");
+Q_STATIC_ASSERT_X(static_cast<int>(WebEngineSettings::FixedFont) == static_cast<int>(QWebEngineSettings::FixedFont), "The enum values must match");
+Q_STATIC_ASSERT_X(static_cast<int>(WebEngineSettings::SerifFont) == static_cast<int>(QWebEngineSettings::SerifFont), "The enum values must match");
+Q_STATIC_ASSERT_X(static_cast<int>(WebEngineSettings::SansSerifFont) == static_cast<int>(QWebEngineSettings::SansSerifFont), "The enum values must match");
+Q_STATIC_ASSERT_X(static_cast<int>(WebEngineSettings::CursiveFont) == static_cast<int>(QWebEngineSettings::CursiveFont), "The enum values must match");
+Q_STATIC_ASSERT_X(static_cast<int>(WebEngineSettings::FantasyFont) == static_cast<int>(QWebEngineSettings::FantasyFont), "The enum values must match");
+
+void QWebEngineSettings::setFontFamily(QWebEngineSettings::FontFamily which, const QString &family)
+{
+ d->coreSettings->setFontFamily(static_cast<WebEngineSettings::FontFamily>(which), family);
+}
+
+QString QWebEngineSettings::fontFamily(QWebEngineSettings::FontFamily which) const
+{
+ return d->coreSettings->fontFamily(static_cast<WebEngineSettings::FontFamily>(which));
+}
+
+void QWebEngineSettings::resetFontFamily(QWebEngineSettings::FontFamily which)
+{
+ d->coreSettings->resetFontFamily(static_cast<WebEngineSettings::FontFamily>(which));
+}
+
+Q_STATIC_ASSERT_X(static_cast<int>(WebEngineSettings::DefaultFixedFontSize) == static_cast<int>(QWebEngineSettings::DefaultFixedFontSize), "The enum values must match");
+Q_STATIC_ASSERT_X(static_cast<int>(WebEngineSettings::DefaultFontSize) == static_cast<int>(QWebEngineSettings::DefaultFontSize), "The enum values must match");
+Q_STATIC_ASSERT_X(static_cast<int>(WebEngineSettings::MinimumFontSize) == static_cast<int>(QWebEngineSettings::MinimumFontSize), "The enum values must match");
+Q_STATIC_ASSERT_X(static_cast<int>(WebEngineSettings::MinimumLogicalFontSize) == static_cast<int>(QWebEngineSettings::MinimumLogicalFontSize), "The enum values must match");
+
+void QWebEngineSettings::setFontSize(QWebEngineSettings::FontSize type, int size)
+{
+ d->coreSettings->setFontSize(static_cast<WebEngineSettings::FontSize>(type), size);
+}
+
+int QWebEngineSettings::fontSize(QWebEngineSettings::FontSize type) const
+{
+ return d->coreSettings->fontSize(static_cast<WebEngineSettings::FontSize>(type));
+}
+
+void QWebEngineSettings::resetFontSize(QWebEngineSettings::FontSize type)
+{
+ d->coreSettings->resetFontSize(static_cast<WebEngineSettings::FontSize>(type));
+}
+
+
+QWebEngineSettings::QWebEngineSettings()
+ : d(new QWebEngineSettingsPrivate)
+{
+ d->initDefaults();
+}
+
+
+QWebEngineSettings::QWebEngineSettings(QWebEngineSettingsPrivate *p)
+ : d(p)
+{
+ Q_ASSERT(d);
+ allSettings->append(d);
+ d->coreSettings->scheduleApply();
+}
+
+
+QWebEngineSettings::~QWebEngineSettings()
+{
+ allSettings->removeAll(d);
+ delete d;
+}
+
+void QWebEngineSettings::setDefaultTextEncoding(const QString &encoding)
+{
+ d->coreSettings->setDefaultTextEncoding(encoding);
+}
+
+QString QWebEngineSettings::defaultTextEncoding() const
+{
+ return d->coreSettings->defaultTextEncoding();
+}
+
+void QWebEngineSettings::setAttribute(QWebEngineSettings::WebAttribute attr, bool on)
+{
+ WebEngineSettings::Attribute webEngineAttribute = toWebEngineAttribute(attr);
+ if (webEngineAttribute != WebEngineSettings::UnsupportedInCoreSettings)
+ return d->coreSettings->setAttribute(webEngineAttribute, on);
+ qDebug() << Q_FUNC_INFO << "Missing support for:" << attr;
+}
+
+bool QWebEngineSettings::testAttribute(QWebEngineSettings::WebAttribute attr) const
+{
+ WebEngineSettings::Attribute webEngineAttribute = toWebEngineAttribute(attr);
+ if (webEngineAttribute != WebEngineSettings::UnsupportedInCoreSettings)
+ return d->coreSettings->testAttribute(webEngineAttribute);
+
+
+
+ qDebug() << Q_FUNC_INFO << "Missing support for:" << attr;
+ return false;
+}
+
+void QWebEngineSettings::resetAttribute(QWebEngineSettings::WebAttribute attr)
+{
+ setAttribute(attr, globalSettings()->testAttribute(attr));
+}
diff --git a/src/webenginewidgets/api/qwebenginesettings.h b/src/webenginewidgets/api/qwebenginesettings.h
new file mode 100644
index 000000000..bbb0cf899
--- /dev/null
+++ b/src/webenginewidgets/api/qwebenginesettings.h
@@ -0,0 +1,98 @@
+/*
+ Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QWEBENGINESETTINGS_H
+#define QWEBENGINESETTINGS_H
+
+#include <QtWebEngineWidgets/qtwebenginewidgetsglobal.h>
+#include <QtCore/qstring.h>
+
+QT_BEGIN_NAMESPACE
+
+class QIcon;
+class QPixmap;
+class QUrl;
+class QWebEngineSettingsPrivate;
+
+class QWEBENGINEWIDGETS_EXPORT QWebEngineSettings {
+public:
+ enum FontFamily {
+ StandardFont,
+ FixedFont,
+ SerifFont,
+ SansSerifFont,
+ CursiveFont,
+ FantasyFont
+ };
+ enum WebAttribute {
+ AutoLoadImages,
+ JavascriptEnabled,
+ JavascriptCanOpenWindows,
+ JavascriptCanAccessClipboard,
+ DeveloperExtrasEnabled,
+ LinksIncludedInFocusChain,
+ LocalStorageEnabled,
+ LocalContentCanAccessRemoteUrls,
+ XSSAuditingEnabled,
+ SpatialNavigationEnabled,
+ LocalContentCanAccessFileUrls,
+ HyperlinkAuditingEnabled,
+ ScrollAnimatorEnabled
+ };
+
+ enum FontSize {
+ MinimumFontSize,
+ MinimumLogicalFontSize,
+ DefaultFontSize,
+ DefaultFixedFontSize
+ };
+
+ static QWebEngineSettings *globalSettings();
+
+ void setFontFamily(FontFamily which, const QString &family);
+ QString fontFamily(FontFamily which) const;
+ void resetFontFamily(FontFamily which);
+
+ void setFontSize(FontSize type, int size);
+ int fontSize(FontSize type) const;
+ void resetFontSize(FontSize type);
+
+ void setAttribute(WebAttribute attr, bool on);
+ bool testAttribute(WebAttribute attr) const;
+ void resetAttribute(WebAttribute attr);
+
+ void setDefaultTextEncoding(const QString &encoding);
+ QString defaultTextEncoding() const;
+
+private:
+ Q_DISABLE_COPY(QWebEngineSettings)
+ friend class QWebEnginePagePrivate;
+ friend class QWebEngineSettingsPrivate;
+
+ QWebEngineSettings();
+ QWebEngineSettings(QWebEngineSettingsPrivate *);
+ ~QWebEngineSettings();
+
+ QWebEngineSettingsPrivate *d;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWEBENGINESETTINGS_H
diff --git a/src/webenginewidgets/api/qwebenginesettings_p.h b/src/webenginewidgets/api/qwebenginesettings_p.h
new file mode 100644
index 000000000..96fa9e27b
--- /dev/null
+++ b/src/webenginewidgets/api/qwebenginesettings_p.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWEBENGINESETTINGS_P_H
+#define QWEBENGINESETTINGS_P_H
+
+#include "web_engine_settings.h"
+#include <QtCore/qcompilerdetection.h>
+#include <QtCore/QScopedPointer>
+
+QT_BEGIN_NAMESPACE
+
+class QWebEngineSettingsPrivate : public WebEngineSettingsDelegate {
+
+public:
+ QWebEngineSettingsPrivate();
+ QWebEngineSettingsPrivate(WebContentsAdapter *adapter);
+
+ void initDefaults();
+ void apply() Q_DECL_OVERRIDE;
+ WebEngineSettings *fallbackSettings() const Q_DECL_OVERRIDE;
+
+ QScopedPointer<WebEngineSettings> coreSettings;
+
+ // This should only contain things specific to WebEngineWidgets which we don't want exposed to the core layer.
+ // For instance, the icon database would most likely be implemented at that level.
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QWEBENGINESETTINGS_P_H
diff --git a/src/webenginewidgets/webenginewidgets.pro b/src/webenginewidgets/webenginewidgets.pro
index d130f7461..d4cce2590 100644
--- a/src/webenginewidgets/webenginewidgets.pro
+++ b/src/webenginewidgets/webenginewidgets.pro
@@ -16,6 +16,7 @@ SOURCES = \
api/qtwebenginewidgetsglobal.cpp \
api/qwebenginehistory.cpp \
api/qwebenginepage.cpp \
+ api/qwebenginesettings.cpp \
api/qwebengineview.cpp\
render_widget_host_view_qt_delegate_widget.cpp
@@ -24,6 +25,8 @@ HEADERS = \
api/qwebenginehistory.h \
api/qwebenginepage.h \
api/qwebenginepage_p.h \
+ api/qwebenginesettings.h \
+ api/qwebenginesettings_p.h \
api/qwebengineview.h \
api/qwebengineview_p.h \
render_widget_host_view_qt_delegate_widget.h