I'm creating a simple browser using QtWebkit, I managed to add support for Notification Web API it, using QWebPage::setFeaturePermission.
Example:
function notifyMe() {
if (Notification.permission === "granted") {
var notification = new Notification("Hi there!");
} else if (Notification.permission !== "denied") {
Notification.requestPermission(function(permission) {
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
}
<button onclick="notifyMe();">Notify me</button>
My code:
QObject::connect(page,
SIGNAL(featurePermissionRequested(QWebFrame*, QWebPage::Feature)), this,
SLOT(featurePermissionRequested(QWebFrame*,QWebPage::Feature))
);
...
void Form::featurePermissionRequested(QWebFrame* frame, QWebPage::Feature feature) {
switch (feature) {
case QWebPage::Notifications:
qDebug() << "Notification";
page->setFeaturePermission(frame, feature, QWebPage::PermissionGrantedByUser);
break;
case QWebPage::Geolocation:
qDebug() << "GEO";
break;
default:
qDebug() << "Unknown feature";
}
}
Every time I click on the "Notify me" button the following message appears on the desktop:

It is possible to customize the notifications in QT? In other words, leave similar to the GoogleChrome or Firefox, like this:

To customize
Notifications Web APIinQtWebkityou must use the "Webkit plugins", in other words create a plugin and put in theqtdir/plugins/webkit.Create the plugin:
In
.profile use (examplesrc.pro):Create mywebkitplugin.h
Create mywebkitplugin.cpp
Create
notificationfolderIn notification folder put notification class:
notification.h
notification.cpp
For create your notification customized change
Notification::showNotification(const QWebNotificationData* data)content and useQWebNotificationData* datafor get data fromJavaScript API.Create
notification.pri(included insrc.pro):Add
notification.priinsrc.pro:Compiling/build:
src.proin QtCreatorBuild(in Release Mode) (or use Ctrl+B) button (don't click inRunbutton, don't use Ctrl+R)src.prosrc.probin/releasefolderbin/debugfoldermywebkitplugin.dlltoQtDir/plugins/webkit/mywebkitplugin.dll(eg with mingw:C:/qt/qt5.4/mingw/plugin/webkit/mywebkitplugin.dll)mywebkitplugind.dlltoQtDir/plugins/webkit/mywebkitplugind.dll(eg with mingw:C:/qt/qt5.4/mingw/plugin/webkit/mywebkitplugind.dll)webkitfolder does not exist, create it.QWebViewand testNotification Web API.When running a project that uses
QWebView, it will automatically load thedll(no needs extras configurations in your project) and will "replace" the defaultNotifications(QtWebkitin Windows usesSystemTrayIconfor showNotification Web API) for your "custom widget".Folder structure for plugin projetct: