mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Ladybird/Qt: Add actions to set navigator compatibility mode
This commit is contained in:
parent
1128375dff
commit
197f57f5d2
Notes:
sideshowbarker
2024-07-17 11:29:41 +09:00
Author: https://github.com/jamierocks Commit: https://github.com/LadybirdBrowser/ladybird/commit/197f57f5d2 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/347
5 changed files with 52 additions and 0 deletions
|
@ -497,6 +497,30 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::Cook
|
|||
}
|
||||
});
|
||||
|
||||
auto* navigator_compatibility_mode_menu = debug_menu->addMenu("Navigator Compatibility Mode");
|
||||
navigator_compatibility_mode_menu->setIcon(load_icon_from_uri("resource://icons/16x16/spoof.png"sv));
|
||||
|
||||
auto* navigator_compatibility_mode_group = new QActionGroup(this);
|
||||
|
||||
auto add_navigator_compatibility_mode = [this, &navigator_compatibility_mode_group, &navigator_compatibility_mode_menu](auto name, auto const& compatibility_mode) {
|
||||
auto* action = new QAction(qstring_from_ak_string(name), this);
|
||||
action->setCheckable(true);
|
||||
navigator_compatibility_mode_group->addAction(action);
|
||||
navigator_compatibility_mode_menu->addAction(action);
|
||||
QObject::connect(action, &QAction::triggered, this, [this, compatibility_mode] {
|
||||
for_each_tab([compatibility_mode](auto& tab) {
|
||||
tab.set_navigator_compatibility_mode(compatibility_mode);
|
||||
});
|
||||
set_navigator_compatibility_mode(compatibility_mode);
|
||||
});
|
||||
return action;
|
||||
};
|
||||
auto* chrome_compatibility_mode = add_navigator_compatibility_mode("Chrome"_string, "chrome"sv.to_byte_string());
|
||||
chrome_compatibility_mode->setChecked(true);
|
||||
add_navigator_compatibility_mode("Gecko"_string, "gecko"sv.to_byte_string());
|
||||
add_navigator_compatibility_mode("WebKit"_string, "webkit"sv.to_byte_string());
|
||||
set_navigator_compatibility_mode("chrome");
|
||||
|
||||
debug_menu->addSeparator();
|
||||
|
||||
m_enable_scripting_action = new QAction("Enable Scripting", this);
|
||||
|
@ -782,6 +806,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_navigator_compatibility_mode(navigator_compatibility_mode());
|
||||
tab->set_enable_do_not_track(Settings::the()->enable_do_not_track());
|
||||
}
|
||||
|
||||
|
|
|
@ -173,6 +173,8 @@ private:
|
|||
|
||||
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; }
|
||||
ByteString navigator_compatibility_mode() const { return m_navigator_compatibility_mode; }
|
||||
void set_navigator_compatibility_mode(ByteString const& navigator_compatibility_mode) { m_navigator_compatibility_mode = navigator_compatibility_mode; }
|
||||
|
||||
QScreen* m_current_screen;
|
||||
double m_device_pixel_ratio { 0 };
|
||||
|
@ -200,6 +202,7 @@ private:
|
|||
QAction* m_enable_same_origin_policy_action { nullptr };
|
||||
|
||||
ByteString m_user_agent_string {};
|
||||
ByteString m_navigator_compatibility_mode {};
|
||||
|
||||
SettingsDialog* m_settings_dialog { nullptr };
|
||||
|
||||
|
|
|
@ -997,6 +997,11 @@ void Tab::set_user_agent_string(ByteString const& user_agent)
|
|||
debug_request("clear-cache");
|
||||
}
|
||||
|
||||
void Tab::set_navigator_compatibility_mode(ByteString const& compatibility_mode)
|
||||
{
|
||||
debug_request("navigator-compatibility-mode", compatibility_mode);
|
||||
}
|
||||
|
||||
void Tab::set_enable_do_not_track(bool enable)
|
||||
{
|
||||
m_view->set_enable_do_not_track(enable);
|
||||
|
|
|
@ -72,6 +72,7 @@ public:
|
|||
void set_same_origin_policy(bool);
|
||||
void set_scripting(bool);
|
||||
void set_user_agent_string(ByteString const&);
|
||||
void set_navigator_compatibility_mode(ByteString const&);
|
||||
|
||||
void set_enable_do_not_track(bool);
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <LibWeb/Loader/ContentFilter.h>
|
||||
#include <LibWeb/Loader/ProxyMappings.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
#include <LibWeb/Loader/UserAgent.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
#include <LibWeb/Painting/StackingContext.h>
|
||||
#include <LibWeb/Painting/ViewportPaintable.h>
|
||||
|
@ -398,6 +399,23 @@ void ConnectionFromClient::debug_request(u64 page_id, ByteString const& request,
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (request == "navigator-compatibility-mode") {
|
||||
Web::NavigatorCompatibilityMode compatibility_mode;
|
||||
if (argument == "chrome") {
|
||||
compatibility_mode = Web::NavigatorCompatibilityMode::Chrome;
|
||||
} else if (argument == "gecko") {
|
||||
compatibility_mode = Web::NavigatorCompatibilityMode::Gecko;
|
||||
} else if (argument == "webkit") {
|
||||
compatibility_mode = Web::NavigatorCompatibilityMode::WebKit;
|
||||
} else {
|
||||
dbgln("Unknown navigator compatibility mode '{}', defaulting to Chrome", argument);
|
||||
compatibility_mode = Web::NavigatorCompatibilityMode::Chrome;
|
||||
}
|
||||
|
||||
Web::ResourceLoader::the().set_navigator_compatibility_mode(compatibility_mode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionFromClient::get_source(u64 page_id)
|
||||
|
|
Loading…
Reference in a new issue