Ladybird/Qt: Add setting for sending DNT header

This commit is contained in:
Jamie Mansfield 2024-07-02 20:31:14 +01:00 committed by Andreas Kling
parent fb20326979
commit e34254298a
Notes: sideshowbarker 2024-07-16 23:54:15 +09:00
7 changed files with 39 additions and 0 deletions

View file

@ -97,6 +97,12 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::Cook
});
}
QObject::connect(Settings::the(), &Settings::enable_do_not_track_changed, this, [this](bool enable) {
for_each_tab([enable](auto& tab) {
tab.set_enable_do_not_track(enable);
});
});
m_hamburger_menu = new HamburgerMenu(this);
if (!Settings::the()->show_menubar())
@ -776,6 +782,7 @@ void BrowserWindow::initialize_tab(Tab* tab)
tab->set_block_popups(m_block_pop_ups_action->isChecked());
tab->set_same_origin_policy(m_enable_same_origin_policy_action->isChecked());
tab->set_user_agent_string(user_agent_string());
tab->set_enable_do_not_track(Settings::the()->enable_do_not_track());
}
void BrowserWindow::activate_tab(int index)

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
* Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -113,6 +114,17 @@ void Settings::set_enable_search(bool enable)
emit enable_search_changed(enable);
}
bool Settings::enable_do_not_track()
{
return m_qsettings->value("enable_do_not_track", false).toBool();
}
void Settings::set_enable_do_not_track(bool enable)
{
m_qsettings->setValue("enable_do_not_track", enable);
emit enable_do_not_track_changed(enable);
}
bool Settings::show_menubar()
{
return m_qsettings->value("show_menubar", false).toBool();

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
* Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -58,6 +59,9 @@ public:
bool enable_search();
void set_enable_search(bool enable);
bool enable_do_not_track();
void set_enable_do_not_track(bool enable);
bool show_menubar();
void set_show_menubar(bool show_menubar);
@ -65,6 +69,7 @@ signals:
void show_menubar_changed(bool show_menubar);
void enable_search_changed(bool enable);
void search_engine_changed(WebView::SearchEngine engine);
void enable_do_not_track_changed(bool enable);
protected:
Settings();

View file

@ -50,6 +50,12 @@ SettingsDialog::SettingsDialog(QMainWindow* window)
close();
});
m_enable_do_not_track = new QCheckBox(this);
m_enable_do_not_track->setChecked(Settings::the()->enable_do_not_track());
QObject::connect(m_enable_do_not_track, &QCheckBox::stateChanged, this, [&](int state) {
Settings::the()->set_enable_do_not_track(state == Qt::Checked);
});
setup_search_engines();
m_layout->addRow(new QLabel("Page on New Tab", this), m_new_tab_page);
@ -57,6 +63,7 @@ SettingsDialog::SettingsDialog(QMainWindow* window)
m_layout->addRow(new QLabel("Search Engine", this), m_search_engine_dropdown);
m_layout->addRow(new QLabel("Enable Autocomplete", this), m_enable_autocomplete);
m_layout->addRow(new QLabel("Autocomplete Engine", this), m_autocomplete_engine_dropdown);
m_layout->addRow(new QLabel("Send web sites a \"Do Not Track\" request", this), m_enable_do_not_track);
setWindowTitle("Settings");
setLayout(m_layout);

View file

@ -32,6 +32,7 @@ private:
QPushButton* m_search_engine_dropdown { nullptr };
QCheckBox* m_enable_autocomplete { nullptr };
QPushButton* m_autocomplete_engine_dropdown { nullptr };
QCheckBox* m_enable_do_not_track { nullptr };
};
}

View file

@ -997,4 +997,9 @@ void Tab::set_user_agent_string(ByteString const& user_agent)
debug_request("clear-cache");
}
void Tab::set_enable_do_not_track(bool enable)
{
m_view->set_enable_do_not_track(enable);
}
}

View file

@ -73,6 +73,8 @@ public:
void set_scripting(bool);
void set_user_agent_string(ByteString const&);
void set_enable_do_not_track(bool);
bool url_is_hidden() const { return m_location_edit->url_is_hidden(); }
void set_url_is_hidden(bool url_is_hidden) { m_location_edit->set_url_is_hidden(url_is_hidden); }