blob: 0d2b499117ce6aa6aa1fb38c78b6e7fcfb1c5ff2 (
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
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "mainwindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, m_view(new QWebEngineView(this))
{
setCentralWidget(m_view);
QWebEnginePage *page = m_view->page();
connect(page, &QWebEnginePage::featurePermissionRequested,
[this, page](const QUrl &securityOrigin, QWebEnginePage::Feature feature) {
if (feature != QWebEnginePage::Geolocation)
return;
QMessageBox msgBox(this);
msgBox.setText(tr("%1 wants to know your location").arg(securityOrigin.host()));
msgBox.setInformativeText(tr("Do you want to send your current location to this website?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
if (msgBox.exec() == QMessageBox::Yes) {
page->setFeaturePermission(
securityOrigin, feature, QWebEnginePage::PermissionGrantedByUser);
} else {
page->setFeaturePermission(
securityOrigin, feature, QWebEnginePage::PermissionDeniedByUser);
}
});
page->load(QUrl(QStringLiteral("https://maps.google.com")));
}
|