Skip to content

Commit

Permalink
Add initial and very basic version of QtWebEngine (Blink) backend, re…
Browse files Browse the repository at this point in the history
…ferences #615
  • Loading branch information
Emdek committed Jan 12, 2015
1 parent 32ce46c commit fce5fc3
Show file tree
Hide file tree
Showing 14 changed files with 882 additions and 29 deletions.
30 changes: 28 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ if (MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\"")
endif (MSVC)

find_package(Qt5 5.2.0 REQUIRED COMPONENTS Core Gui Multimedia Network PrintSupport Script Sql Widgets WebKit WebKitWidgets)
option(EnableQtwebengine "Enable QtWebEngine backend (requires Qt 5.4)" OFF)

if (${EnableQtwebengine})
find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core Gui Multimedia Network PrintSupport Script Sql WebEngine WebEngineWidgets WebKit WebKitWidgets Widgets)
else (${EnableQtwebengine})
find_package(Qt5 5.2.0 REQUIRED COMPONENTS Core Gui Multimedia Network PrintSupport Script Sql WebKit WebKitWidgets Widgets)
endif (${EnableQtwebengine})

set(otter_src
src/main.cpp
Expand Down Expand Up @@ -216,9 +222,24 @@ qt5_wrap_ui(otter_ui
src/modules/windows/web/WebContentsWidget.ui
)

if (${EnableQtwebengine})
add_definitions(-DOTTER_ENABLE_QTWEBENGINE)

set(otter_src
${otter_src}
src/modules/backends/web/qtwebengine/QtWebEngineWebBackend.cpp
src/modules/backends/web/qtwebengine/QtWebEngineWebWidget.cpp
)
endif (${EnableQtwebengine})

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_definitions(-DUNICODE -D_UNICODE)
set(otter_src ${otter_src} otter-browser.rc src/modules/platforms/windows/WindowsPlatformIntegration.cpp)

set(otter_src
${otter_src}
otter-browser.rc
src/modules/platforms/windows/WindowsPlatformIntegration.cpp
)
endif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")

add_executable(otter-browser
Expand All @@ -227,8 +248,13 @@ add_executable(otter-browser
${otter_src}
)

if (${EnableQtwebengine})
qt5_use_modules(otter-browser WebEngine WebEngineWidgets)
endif (${EnableQtwebengine})

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
qt5_use_modules(otter-browser WinExtras)

target_link_libraries(otter-browser ole32 shell32 advapi32 user32)
endif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")

Expand Down
4 changes: 4 additions & 0 deletions resources/schemas/options.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ value=false
type=bool
value=true

[Backends/Web]
type=string
value=qtwebkit

[Browser/ActionMacrosProfilesOrder]
type=string
value=platform,default
Expand Down
16 changes: 15 additions & 1 deletion src/core/WebBackendsManager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**************************************************************************
* Otter Browser: Web browser controlled by the user, not vice-versa.
* Copyright (C) 2013 - 2014 Michal Dutkiewicz aka Emdek <michal@emdek.pl>
* Copyright (C) 2013 - 2015 Michal Dutkiewicz aka Emdek <michal@emdek.pl>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -18,7 +18,11 @@
**************************************************************************/

#include "WebBackendsManager.h"
#include "SettingsManager.h"
#include "WebBackend.h"
#ifdef OTTER_ENABLE_QTWEBENGINE
#include "../modules/backends/web/qtwebengine/QtWebEngineWebBackend.h"
#endif
#include "../modules/backends/web/qtwebkit/QtWebKitWebBackend.h"

namespace Otter
Expand All @@ -29,6 +33,9 @@ QHash<QString, WebBackend*> WebBackendsManager::m_backends;

WebBackendsManager::WebBackendsManager(QObject *parent) : QObject(parent)
{
#ifdef OTTER_ENABLE_QTWEBENGINE
registerBackend(new QtWebEngineWebBackend(this), QLatin1String("qtwebengine"));
#endif
registerBackend(new QtWebKitWebBackend(this), QLatin1String("qtwebkit"));
}

Expand Down Expand Up @@ -59,6 +66,13 @@ WebBackend* WebBackendsManager::getBackend(const QString &name)

if (name.isEmpty())
{
const QString defaultName = SettingsManager::getValue(QLatin1String("Backends/Web")).toString();

if (m_backends.contains(defaultName))
{
return m_backends[defaultName];
}

return m_backends.value(m_backends.keys().first(), NULL);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/WebBackendsManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**************************************************************************
* Otter Browser: Web browser controlled by the user, not vice-versa.
* Copyright (C) 2013 - 2014 Michal Dutkiewicz aka Emdek <michal@emdek.pl>
* Copyright (C) 2013 - 2015 Michal Dutkiewicz aka Emdek <michal@emdek.pl>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
107 changes: 107 additions & 0 deletions src/modules/backends/web/qtwebengine/QtWebEngineWebBackend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**************************************************************************
* Otter Browser: Web browser controlled by the user, not vice-versa.
* Copyright (C) 2015 Michal Dutkiewicz aka Emdek <michal@emdek.pl>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**************************************************************************/

#include "QtWebEngineWebBackend.h"
#include "QtWebEngineWebWidget.h"
#include "../../../../core/NetworkManagerFactory.h"
#include "../../../../core/SettingsManager.h"
#include "../../../../core/Utils.h"

#include <QtCore/QCoreApplication>
#include <QtWebEngineWidgets/QWebEngineSettings>

namespace Otter
{

QtWebEngineWebBackend::QtWebEngineWebBackend(QObject *parent) : WebBackend(parent),
m_isInitialized(false)
{
}

void QtWebEngineWebBackend::optionChanged(const QString &option)
{
if (!(option.startsWith(QLatin1String("Browser/")) || option.startsWith(QLatin1String("Content/"))))
{
return;
}

QWebEngineSettings *globalSettings = QWebEngineSettings::globalSettings();
globalSettings->setAttribute(QWebEngineSettings::AutoLoadImages, SettingsManager::getValue(QLatin1String("Browser/EnableImages")).toBool());
globalSettings->setAttribute(QWebEngineSettings::JavascriptEnabled, SettingsManager::getValue(QLatin1String("Browser/EnableJavaScript")).toBool());
globalSettings->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, SettingsManager::getValue(QLatin1String("Browser/JavaScriptCanAccessClipboard")).toBool());
globalSettings->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, SettingsManager::getValue(QLatin1String("Browser/JavaScriptCanOpenWindows")).toBool());
globalSettings->setAttribute(QWebEngineSettings::LocalStorageEnabled, SettingsManager::getValue(QLatin1String("Browser/EnableLocalStorage")).toBool());
globalSettings->setFontSize(QWebEngineSettings::DefaultFontSize, SettingsManager::getValue(QLatin1String("Content/DefaultFontSize")).toInt());
globalSettings->setFontSize(QWebEngineSettings::DefaultFixedFontSize, SettingsManager::getValue(QLatin1String("Content/DefaultFixedFontSize")).toInt());
globalSettings->setFontSize(QWebEngineSettings::MinimumFontSize, SettingsManager::getValue(QLatin1String("Content/MinimumFontSize")).toInt());
globalSettings->setFontFamily(QWebEngineSettings::StandardFont, SettingsManager::getValue(QLatin1String("Content/StandardFont")).toString());
globalSettings->setFontFamily(QWebEngineSettings::FixedFont, SettingsManager::getValue(QLatin1String("Content/FixedFont")).toString());
globalSettings->setFontFamily(QWebEngineSettings::SerifFont, SettingsManager::getValue(QLatin1String("Content/SerifFont")).toString());
globalSettings->setFontFamily(QWebEngineSettings::SansSerifFont, SettingsManager::getValue(QLatin1String("Content/SansSerifFont")).toString());
globalSettings->setFontFamily(QWebEngineSettings::CursiveFont, SettingsManager::getValue(QLatin1String("Content/CursiveFont")).toString());
globalSettings->setFontFamily(QWebEngineSettings::FantasyFont, SettingsManager::getValue(QLatin1String("Content/FantasyFont")).toString());
}

WebWidget* QtWebEngineWebBackend::createWidget(bool isPrivate, ContentsWidget *parent)
{
if (!m_isInitialized)
{
m_isInitialized = true;

optionChanged(QLatin1String("Browser/"));

connect(SettingsManager::getInstance(), SIGNAL(valueChanged(QString,QVariant)), this, SLOT(optionChanged(QString)));
}

return new QtWebEngineWebWidget(isPrivate, this, parent);
}

QString QtWebEngineWebBackend::getTitle() const
{
return tr("Blink Backend");
}

QString QtWebEngineWebBackend::getDescription() const
{
return tr("Backend utilizing QtWebEngine module");
}

QString QtWebEngineWebBackend::getVersion() const
{
return QCoreApplication::applicationVersion();
}

QString QtWebEngineWebBackend::getEngineVersion() const
{
return QLatin1String("37.0");
}

QString QtWebEngineWebBackend::getUserAgent(const QString &pattern) const
{
return pattern;
}

QIcon QtWebEngineWebBackend::getIconForUrl(const QUrl &url)
{
Q_UNUSED(url)

return Utils::getIcon(QLatin1String("text-html"));
}

}
52 changes: 52 additions & 0 deletions src/modules/backends/web/qtwebengine/QtWebEngineWebBackend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**************************************************************************
* Otter Browser: Web browser controlled by the user, not vice-versa.
* Copyright (C) 2015 Michal Dutkiewicz aka Emdek <michal@emdek.pl>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**************************************************************************/

#ifndef OTTER_QTWEBENGINEWEBBACKEND_H
#define OTTER_QTWEBENGINEWEBBACKEND_H

#include "../../../../core/WebBackend.h"

namespace Otter
{

class QtWebEngineWebBackend : public WebBackend
{
Q_OBJECT

public:
explicit QtWebEngineWebBackend(QObject *parent = NULL);

WebWidget* createWidget(bool isPrivate = false, ContentsWidget *parent = NULL);
QString getTitle() const;
QString getDescription() const;
QString getVersion() const;
QString getEngineVersion() const;
QString getUserAgent(const QString &pattern = QString()) const;
QIcon getIconForUrl(const QUrl &url);

protected slots:
void optionChanged(const QString &option);

private:
bool m_isInitialized;
};

}

#endif
Loading

0 comments on commit fce5fc3

Please sign in to comment.