mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-27 19:59:17 +00:00
UI/Qt: Spoof user agent across all tabs
This commit is contained in:
committed by
Andreas Kling
parent
99555f19f4
commit
fdd2f9ebbd
@@ -386,12 +386,15 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::Cook
|
|||||||
user_agent_group->addAction(action);
|
user_agent_group->addAction(action);
|
||||||
spoof_user_agent_menu->addAction(action);
|
spoof_user_agent_menu->addAction(action);
|
||||||
QObject::connect(action, &QAction::triggered, this, [this, user_agent] {
|
QObject::connect(action, &QAction::triggered, this, [this, user_agent] {
|
||||||
debug_request("spoof-user-agent", user_agent);
|
for_each_tab([user_agent](auto& tab) {
|
||||||
debug_request("clear-cache"); // clear the cache to ensure requests are re-done with the new user agent
|
tab.set_user_agent_string(user_agent);
|
||||||
|
});
|
||||||
|
set_user_agent_string(user_agent);
|
||||||
});
|
});
|
||||||
return action;
|
return action;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
set_user_agent_string(Web::default_user_agent);
|
||||||
auto* disable_spoofing = add_user_agent("Disabled"sv, Web::default_user_agent);
|
auto* disable_spoofing = add_user_agent("Disabled"sv, Web::default_user_agent);
|
||||||
disable_spoofing->setChecked(true);
|
disable_spoofing->setChecked(true);
|
||||||
for (auto const& user_agent : WebView::user_agents)
|
for (auto const& user_agent : WebView::user_agents)
|
||||||
@@ -404,8 +407,11 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::Cook
|
|||||||
QObject::connect(custom_user_agent_action, &QAction::triggered, this, [this, disable_spoofing] {
|
QObject::connect(custom_user_agent_action, &QAction::triggered, this, [this, disable_spoofing] {
|
||||||
auto user_agent = QInputDialog::getText(this, "Custom User Agent", "Enter User Agent:");
|
auto user_agent = QInputDialog::getText(this, "Custom User Agent", "Enter User Agent:");
|
||||||
if (!user_agent.isEmpty()) {
|
if (!user_agent.isEmpty()) {
|
||||||
debug_request("spoof-user-agent", ak_byte_string_from_qstring(user_agent));
|
auto user_agent_byte_string = ak_byte_string_from_qstring(user_agent);
|
||||||
debug_request("clear-cache"); // clear the cache to ensure requests are re-done with the new user agent
|
for_each_tab([&](auto& tab) {
|
||||||
|
tab.set_user_agent_string(user_agent_byte_string);
|
||||||
|
});
|
||||||
|
set_user_agent_string(user_agent_byte_string);
|
||||||
} else {
|
} else {
|
||||||
disable_spoofing->activate(QAction::Trigger);
|
disable_spoofing->activate(QAction::Trigger);
|
||||||
}
|
}
|
||||||
@@ -690,6 +696,7 @@ void BrowserWindow::initialize_tab(Tab* tab)
|
|||||||
tab->set_scripting(m_enable_scripting_action->isChecked());
|
tab->set_scripting(m_enable_scripting_action->isChecked());
|
||||||
tab->set_block_popups(m_block_pop_ups_action->isChecked());
|
tab->set_block_popups(m_block_pop_ups_action->isChecked());
|
||||||
tab->set_same_origin_policy(m_enable_same_origin_policy_action->isChecked());
|
tab->set_same_origin_policy(m_enable_same_origin_policy_action->isChecked());
|
||||||
|
tab->set_user_agent_string(user_agent_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::activate_tab(int index)
|
void BrowserWindow::activate_tab(int index)
|
||||||
|
|||||||
@@ -164,6 +164,9 @@ private:
|
|||||||
|
|
||||||
void set_window_rect(Optional<Web::DevicePixels> x, Optional<Web::DevicePixels> y, Optional<Web::DevicePixels> width, Optional<Web::DevicePixels> height);
|
void set_window_rect(Optional<Web::DevicePixels> x, Optional<Web::DevicePixels> y, Optional<Web::DevicePixels> width, Optional<Web::DevicePixels> height);
|
||||||
|
|
||||||
|
ByteString user_agent_string() const { return m_user_agent_string; }
|
||||||
|
void set_user_agent_string(ByteString const& user_agent_string) { m_user_agent_string = user_agent_string; }
|
||||||
|
|
||||||
QScreen* m_current_screen;
|
QScreen* m_current_screen;
|
||||||
double m_device_pixel_ratio { 0 };
|
double m_device_pixel_ratio { 0 };
|
||||||
|
|
||||||
@@ -189,6 +192,8 @@ private:
|
|||||||
QAction* m_block_pop_ups_action { nullptr };
|
QAction* m_block_pop_ups_action { nullptr };
|
||||||
QAction* m_enable_same_origin_policy_action { nullptr };
|
QAction* m_enable_same_origin_policy_action { nullptr };
|
||||||
|
|
||||||
|
ByteString m_user_agent_string {};
|
||||||
|
|
||||||
SettingsDialog* m_settings_dialog { nullptr };
|
SettingsDialog* m_settings_dialog { nullptr };
|
||||||
|
|
||||||
WebView::CookieJar& m_cookie_jar;
|
WebView::CookieJar& m_cookie_jar;
|
||||||
|
|||||||
@@ -976,4 +976,11 @@ void Tab::set_scripting(bool enabled)
|
|||||||
debug_request("scripting", enabled ? "on" : "off");
|
debug_request("scripting", enabled ? "on" : "off");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tab::set_user_agent_string(ByteString const& user_agent)
|
||||||
|
{
|
||||||
|
debug_request("spoof-user-agent", user_agent);
|
||||||
|
// Clear the cache to ensure requests are re-done with the new user agent.
|
||||||
|
debug_request("clear-cache");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
void forward();
|
void forward();
|
||||||
void reload();
|
void reload();
|
||||||
|
|
||||||
void debug_request(ByteString const& request, ByteString const& argument);
|
void debug_request(ByteString const& request, ByteString const& argument = "");
|
||||||
|
|
||||||
void open_file();
|
void open_file();
|
||||||
void update_reset_zoom_button();
|
void update_reset_zoom_button();
|
||||||
@@ -69,6 +69,7 @@ public:
|
|||||||
void set_line_box_borders(bool);
|
void set_line_box_borders(bool);
|
||||||
void set_same_origin_policy(bool);
|
void set_same_origin_policy(bool);
|
||||||
void set_scripting(bool);
|
void set_scripting(bool);
|
||||||
|
void set_user_agent_string(ByteString const&);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void focus_location_editor();
|
void focus_location_editor();
|
||||||
|
|||||||
Reference in New Issue
Block a user