aboutsummaryrefslogtreecommitdiff
path: root/src/browsertab.cpp
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-06-17 00:11:50 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-06-17 00:11:50 +0200
commit03253a724b6fdb3f511510d10c3e62615e305cf2 (patch)
treed0fd5cb6471a942dd5e701f9f7a415eccc72b05d /src/browsertab.cpp
parentbc3bd1d7524dffcf9669ac252db0a79b7484ee80 (diff)
downloadkristall-03253a724b6fdb3f511510d10c3e62615e305cf2.tar.gz
Introduces cross-host and cross-scheme redirection warnings.
Diffstat (limited to 'src/browsertab.cpp')
-rw-r--r--src/browsertab.cpp119
1 files changed, 85 insertions, 34 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp
index d7e2e6c..4e5f25c 100644
--- a/src/browsertab.cpp
+++ b/src/browsertab.cpp
@@ -76,45 +76,15 @@ void BrowserTab::navigateTo(const QUrl &url, PushToHistory mode)
if ((this->current_handler != nullptr) and not this->current_handler->cancelRequest())
{
- QMessageBox::warning(this, "Kristall", "Failed to cancel running gemini request!");
+ QMessageBox::warning(this, "Kristall", "Failed to cancel running request!");
return;
}
- this->current_handler = nullptr;
- for(auto & ptr : this->protocol_handlers)
- {
- if(ptr->supportsScheme(url.scheme())) {
- this->current_handler = ptr.get();
- break;
- }
- }
-
- assert((this->current_handler != nullptr) and "If this error happens, someone forgot to add a new protocol handler class in the constructor. Shame on the programmer!");
-
- if(this->current_identitiy.isValid()) {
- if(not this->current_handler->enableClientCertificate(this->current_identitiy)) {
- auto answer = QMessageBox::question(
- this,
- "Kristall",
- QString("You requested a %1-URL with a client certificate, but these are not supported for this scheme. Continue?").arg(url.scheme())
- );
- if(answer != QMessageBox::Yes)
- return;
- this->current_handler->disableClientCertificate();
- }
- } else {
- this->current_handler->disableClientCertificate();
- }
-
- this->timer.start();
-
- this->current_location = url;
- this->ui->url_bar->setText(url.toString(QUrl::FormattingOptions(QUrl::FullyEncoded)));
-
this->redirection_count = 0;
this->successfully_loaded = false;
+ this->timer.start();
- if(not this->current_handler->startRequest(url)) {
+ if(not this->startRequest(url)) {
QMessageBox::critical(this, "Kristall", QString("Failed to execute request to %1").arg(url.toString()));
return;
}
@@ -430,14 +400,61 @@ void BrowserTab::on_redirected(const QUrl &uri, bool is_permanent)
}
else
{
+ bool is_cross_protocol = (this->current_location.scheme() != uri.scheme());
+ bool is_cross_host = (this->current_location.host() != uri.host());
+
+ QString question;
+ if(is_cross_protocol and is_cross_host)
+ {
+ question = QString(
+ "The location you visited wants to redirect you to another host and switch the protocol.\r\n"
+ "Protocol: %1\r\n"
+ "New Host: %2\r\n"
+ "Do you want to allow the redirection?"
+ ).arg(uri.scheme()).arg(uri.host());
+ }
+ else if(is_cross_protocol)
+ {
+ question = QString(
+ "The location you visited wants to switch the protocol.\r\n"
+ "Protocol: %1\r\n"
+ "Do you want to allow the redirection?"
+ ).arg(uri.scheme());
+ }
+ else if(is_cross_host)
+ {
+ question = QString(
+ "The location you visited wants to redirect you to another host.\r\n"
+ "New Host: %1\r\n"
+ "Do you want to allow the redirection?"
+ ).arg(uri.host());
+ }
+
+ if(is_cross_protocol or is_cross_host)
+ {
+ auto answer = QMessageBox::question(
+ this,
+ "Kristall",
+ question
+ );
+ if(answer != QMessageBox::Yes) {
+ setErrorMessage(QString("Redirection to %1 cancelled by user").arg(uri.toString()));
+ return;
+ }
+ }
+
// TODO: Implement cross-protocol redirections
// TODO: Implement cross-host redirection
- if (this->current_handler->startRequest(uri))
+ if (this->startRequest(uri))
{
redirection_count += 1;
this->current_location = uri;
this->ui->url_bar->setText(uri.toString());
}
+ else
+ {
+ setErrorMessage(QString("Redirection to %1 failed").arg(uri.toString()));
+ }
}
}
@@ -616,6 +633,40 @@ void BrowserTab::addProtocolHandler(std::unique_ptr<ProtocolHandler> &&handler)
this->protocol_handlers.emplace_back(std::move(handler));
}
+bool BrowserTab::startRequest(const QUrl &url)
+{
+ this->current_handler = nullptr;
+ for(auto & ptr : this->protocol_handlers)
+ {
+ if(ptr->supportsScheme(url.scheme())) {
+ this->current_handler = ptr.get();
+ break;
+ }
+ }
+
+ assert((this->current_handler != nullptr) and "If this error happens, someone forgot to add a new protocol handler class in the constructor. Shame on the programmer!");
+
+ if(this->current_identitiy.isValid()) {
+ if(not this->current_handler->enableClientCertificate(this->current_identitiy)) {
+ auto answer = QMessageBox::question(
+ this,
+ "Kristall",
+ QString("You requested a %1-URL with a client certificate, but these are not supported for this scheme. Continue?").arg(url.scheme())
+ );
+ if(answer != QMessageBox::Yes)
+ return false;
+ this->current_handler->disableClientCertificate();
+ }
+ } else {
+ this->current_handler->disableClientCertificate();
+ }
+
+ this->current_location = url;
+ this->ui->url_bar->setText(url.toString(QUrl::FormattingOptions(QUrl::FullyEncoded)));
+
+ return this->current_handler->startRequest(url);
+}
+
void BrowserTab::on_text_browser_customContextMenuRequested(const QPoint &pos)
{
QMenu menu;