1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:37:45 +00:00

Browser: Move menu management from Tab to BrowserWindow

It was very confusing for every Tab to have their own GUI::Menubar that
got dynamically swapped in/out when switching tabs.

This change moves us to a single menubar per window, and BrowserWindow
is the owner of its own menubar.
This commit is contained in:
Andreas Kling 2021-05-18 17:32:28 +02:00
parent e5367c13d8
commit aed695d4b2
6 changed files with 345 additions and 304 deletions

View file

@ -10,6 +10,7 @@
namespace Browser {
extern bool g_single_process;
extern String g_home_url;
extern String g_search_engine;

View file

@ -6,21 +6,34 @@
#include "BrowserWindow.h"
#include "BookmarksBarWidget.h"
#include "Browser.h"
#include "ConsoleWidget.h"
#include "CookieJar.h"
#include "InspectorWidget.h"
#include "Tab.h"
#include <Applications/Browser/BrowserWindowGML.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/StandardPaths.h>
#include <LibGUI/AboutDialog.h>
#include <LibGUI/Application.h>
#include <LibGUI/Icon.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Menubar.h>
#include <LibGUI/SeparatorWidget.h>
#include <LibGUI/Statusbar.h>
#include <LibGUI/TabWidget.h>
#include <LibGUI/ToolbarContainer.h>
#include <LibGUI/Widget.h>
#include <LibJS/Interpreter.h>
#include <LibWeb/Dump.h>
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/OutOfProcessWebView.h>
namespace Browser {
extern bool g_single_process;
extern String g_home_url;
static String bookmarks_file_path()
{
StringBuilder builder;
@ -90,6 +103,8 @@ BrowserWindow::BrowserWindow(CookieJar& cookie_jar, URL url)
m_window_actions.show_bookmarks_bar_action().set_checked(true);
build_menus();
create_new_tab(move(url), true);
}
@ -97,11 +112,324 @@ BrowserWindow::~BrowserWindow()
{
}
void BrowserWindow::build_menus()
{
auto menubar = GUI::Menubar::construct();
auto& file_menu = menubar->add_menu("&File");
file_menu.add_action(WindowActions::the().create_new_tab_action());
auto close_tab_action = GUI::Action::create(
"&Close Tab", { Mod_Ctrl, Key_W }, Gfx::Bitmap::load_from_file("/res/icons/16x16/close-tab.png"), [this](auto&) {
active_tab().on_tab_close_request(active_tab());
},
this);
close_tab_action->set_status_tip("Close current tab");
file_menu.add_action(close_tab_action);
file_menu.add_separator();
file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();
}));
auto& view_menu = menubar->add_menu("&View");
view_menu.add_action(WindowActions::the().show_bookmarks_bar_action());
view_menu.add_separator();
view_menu.add_action(GUI::CommonActions::make_fullscreen_action(
[this](auto&) {
auto& tab = active_tab();
set_fullscreen(!is_fullscreen());
auto is_fullscreen = this->is_fullscreen();
tab_widget().set_bar_visible(!is_fullscreen && tab_widget().children().size() > 1);
tab.m_toolbar_container->set_visible(!is_fullscreen);
tab.m_statusbar->set_visible(!is_fullscreen);
if (is_fullscreen) {
tab.view().set_frame_thickness(0);
} else {
tab.view().set_frame_thickness(2);
}
},
this));
auto go_back_action = GUI::CommonActions::make_go_back_action([this](auto&) { active_tab().go_back(); }, this);
auto go_forward_action = GUI::CommonActions::make_go_forward_action([this](auto&) { active_tab().go_forward(); }, this);
auto go_home_action = GUI::CommonActions::make_go_home_action([this](auto&) { active_tab().load(g_home_url); }, this);
go_home_action->set_status_tip("Go to home page");
auto reload_action = GUI::CommonActions::make_reload_action([this](auto&) { active_tab().reload(); }, this);
reload_action->set_status_tip("Reload current page");
auto& go_menu = menubar->add_menu("&Go");
go_menu.add_action(*go_back_action);
go_menu.add_action(*go_forward_action);
go_menu.add_action(*go_home_action);
go_menu.add_separator();
go_menu.add_action(*reload_action);
auto view_source_action = GUI::Action::create(
"View &Source", { Mod_Ctrl, Key_U }, [this](auto&) {
auto& tab = active_tab();
if (tab.m_type == Tab::Type::InProcessWebView) {
VERIFY(tab.m_page_view->document());
auto url = tab.m_page_view->document()->url();
auto source = tab.m_page_view->document()->source();
tab.view_source(url, source);
} else {
tab.m_web_content_view->get_source();
}
},
this);
view_source_action->set_status_tip("View source code of the current page");
auto inspect_dom_tree_action = GUI::Action::create(
"Inspect &DOM Tree", { Mod_None, Key_F12 }, [this](auto&) {
auto& tab = active_tab();
if (tab.m_type == Tab::Type::InProcessWebView) {
if (!tab.m_dom_inspector_window) {
tab.m_dom_inspector_window = GUI::Window::construct(this);
tab.m_dom_inspector_window->resize(300, 500);
tab.m_dom_inspector_window->set_title("DOM inspector");
tab.m_dom_inspector_window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png"));
tab.m_dom_inspector_window->set_main_widget<InspectorWidget>();
}
auto* inspector_widget = static_cast<InspectorWidget*>(tab.m_dom_inspector_window->main_widget());
inspector_widget->set_document(tab.m_page_view->document());
tab.m_dom_inspector_window->show();
tab.m_dom_inspector_window->move_to_front();
} else {
TODO();
}
},
this);
inspect_dom_tree_action->set_status_tip("Open DOM inspector window for this page");
auto& inspect_menu = menubar->add_menu("&Inspect");
inspect_menu.add_action(*view_source_action);
inspect_menu.add_action(*inspect_dom_tree_action);
auto js_console_action = GUI::Action::create(
"Open &JS Console", { Mod_Ctrl, Key_I }, [this](auto&) {
auto& tab = active_tab();
if (tab.m_type == Tab::Type::InProcessWebView) {
if (!tab.m_console_window) {
tab.m_console_window = GUI::Window::construct(this);
tab.m_console_window->resize(500, 300);
tab.m_console_window->set_title("JS Console");
tab.m_console_window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-javascript.png"));
tab.m_console_window->set_main_widget<ConsoleWidget>();
}
auto* console_widget = static_cast<ConsoleWidget*>(tab.m_console_window->main_widget());
console_widget->set_interpreter(tab.m_page_view->document()->interpreter().make_weak_ptr());
tab.m_console_window->show();
tab.m_console_window->move_to_front();
} else {
if (!tab.m_console_window) {
tab.m_console_window = GUI::Window::construct(this);
tab.m_console_window->resize(500, 300);
tab.m_console_window->set_title("JS Console");
tab.m_console_window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-javascript.png"));
tab.m_console_window->set_main_widget<ConsoleWidget>();
}
auto* console_widget = static_cast<ConsoleWidget*>(tab.m_console_window->main_widget());
console_widget->on_js_input = [&tab](const String& js_source) {
tab.m_web_content_view->js_console_input(js_source);
};
console_widget->clear_output();
tab.m_web_content_view->js_console_initialize();
tab.m_console_window->show();
tab.m_console_window->move_to_front();
}
},
this);
js_console_action->set_status_tip("Open JavaScript console for this page");
inspect_menu.add_action(js_console_action);
auto& settings_menu = menubar->add_menu("&Settings");
m_search_engine_actions.set_exclusive(true);
auto& search_engine_menu = settings_menu.add_submenu("&Search Engine");
auto add_search_engine = [this, &search_engine_menu](auto& name, auto& url_format) {
auto action = GUI::Action::create_checkable(
name, [url_format](auto&) {
g_search_engine = url_format;
auto m_config = Core::ConfigFile::get_for_app("Browser");
m_config->write_entry("Preferences", "SearchEngine", g_search_engine);
},
this);
search_engine_menu.add_action(action);
m_search_engine_actions.add_action(action);
if (g_search_engine == url_format) {
action->set_checked(true);
}
action->set_status_tip(url_format);
};
auto disable_search_engine_action = GUI::Action::create_checkable(
"Disable", [](auto&) {
g_search_engine = {};
auto config = Core::ConfigFile::get_for_app("Browser");
config->write_entry("Preferences", "SearchEngine", g_search_engine);
},
this);
search_engine_menu.add_action(disable_search_engine_action);
m_search_engine_actions.add_action(disable_search_engine_action);
disable_search_engine_action->set_checked(true);
// FIXME: Support adding custom search engines
add_search_engine("Bing", "https://www.bing.com/search?q={}");
add_search_engine("DuckDuckGo", "https://duckduckgo.com/?q={}");
add_search_engine("FrogFind", "http://frogfind.com/?q={}");
add_search_engine("GitHub", "https://github.com/search?q={}");
add_search_engine("Google", "https://google.com/search?q={}");
add_search_engine("Yandex", "https://yandex.com/search/?text={}");
auto& debug_menu = menubar->add_menu("&Debug");
debug_menu.add_action(GUI::Action::create(
"Dump &DOM Tree", [this](auto&) {
auto& tab = active_tab();
if (tab.m_type == Tab::Type::InProcessWebView) {
Web::dump_tree(*tab.m_page_view->document());
} else {
tab.m_web_content_view->debug_request("dump-dom-tree");
}
},
this));
debug_menu.add_action(GUI::Action::create(
"Dump &Layout Tree", [this](auto&) {
auto& tab = active_tab();
if (tab.m_type == Tab::Type::InProcessWebView) {
Web::dump_tree(*tab.m_page_view->document()->layout_node());
} else {
tab.m_web_content_view->debug_request("dump-layout-tree");
}
},
this));
debug_menu.add_action(GUI::Action::create(
"Dump &Style Sheets", [this](auto&) {
auto& tab = active_tab();
if (tab.m_type == Tab::Type::InProcessWebView) {
for (auto& sheet : tab.m_page_view->document()->style_sheets().sheets()) {
Web::dump_sheet(sheet);
}
} else {
tab.m_web_content_view->debug_request("dump-style-sheets");
}
},
this));
debug_menu.add_action(GUI::Action::create("Dump &History", { Mod_Ctrl, Key_H }, [this](auto&) {
active_tab().m_history.dump();
}));
debug_menu.add_action(GUI::Action::create("Dump C&ookies", [this](auto&) {
auto& tab = active_tab();
if (tab.on_dump_cookies)
tab.on_dump_cookies();
}));
debug_menu.add_separator();
auto line_box_borders_action = GUI::Action::create_checkable(
"&Line Box Borders", [this](auto& action) {
auto& tab = active_tab();
if (tab.m_type == Tab::Type::InProcessWebView) {
tab.m_page_view->set_should_show_line_box_borders(action.is_checked());
tab.m_page_view->update();
} else {
tab.m_web_content_view->debug_request("set-line-box-borders", action.is_checked() ? "on" : "off");
}
},
this);
line_box_borders_action->set_checked(false);
debug_menu.add_action(line_box_borders_action);
debug_menu.add_separator();
debug_menu.add_action(GUI::Action::create("Collect &Garbage", { Mod_Ctrl | Mod_Shift, Key_G }, [this](auto&) {
auto& tab = active_tab();
if (tab.m_type == Tab::Type::InProcessWebView) {
if (auto* document = tab.m_page_view->document()) {
document->interpreter().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true);
}
} else {
tab.m_web_content_view->debug_request("collect-garbage");
}
}));
debug_menu.add_action(GUI::Action::create("Clear &Cache", { Mod_Ctrl | Mod_Shift, Key_C }, [this](auto&) {
auto& tab = active_tab();
if (tab.m_type == Tab::Type::InProcessWebView) {
Web::ResourceLoader::the().clear_cache();
} else {
tab.m_web_content_view->debug_request("clear-cache");
}
}));
m_user_agent_spoof_actions.set_exclusive(true);
auto& spoof_user_agent_menu = debug_menu.add_submenu("Spoof User Agent");
m_disable_user_agent_spoofing = GUI::Action::create_checkable("Disabled", [this](auto&) {
auto& tab = active_tab();
if (tab.m_type == Tab::Type::InProcessWebView) {
Web::ResourceLoader::the().set_user_agent(Web::default_user_agent);
} else {
tab.m_web_content_view->debug_request("spoof-user-agent", Web::default_user_agent);
}
});
m_disable_user_agent_spoofing->set_status_tip(Web::default_user_agent);
spoof_user_agent_menu.add_action(*m_disable_user_agent_spoofing);
m_user_agent_spoof_actions.add_action(*m_disable_user_agent_spoofing);
m_disable_user_agent_spoofing->set_checked(true);
auto add_user_agent = [this, &spoof_user_agent_menu](auto& name, auto& user_agent) {
auto action = GUI::Action::create_checkable(name, [this, user_agent](auto&) {
auto& tab = active_tab();
if (tab.m_type == Tab::Type::InProcessWebView) {
Web::ResourceLoader::the().set_user_agent(user_agent);
} else {
tab.m_web_content_view->debug_request("spoof-user-agent", user_agent);
}
});
action->set_status_tip(user_agent);
spoof_user_agent_menu.add_action(action);
m_user_agent_spoof_actions.add_action(action);
};
add_user_agent("Chrome Linux Desktop", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36");
add_user_agent("Firefox Linux Desktop", "Mozilla/5.0 (X11; Linux i686; rv:87.0) Gecko/20100101 Firefox/87.0");
add_user_agent("Safari macOS Desktop", "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15");
add_user_agent("Chrome Android Mobile", "Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.66 Mobile Safari/537.36");
add_user_agent("Firefox Android Mobile", "Mozilla/5.0 (Android 11; Mobile; rv:68.0) Gecko/68.0 Firefox/86.0");
add_user_agent("Safari iOS Mobile", "Mozilla/5.0 (iPhone; CPU iPhone OS 14_4_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1");
auto custom_user_agent = GUI::Action::create_checkable("Custom", [this](auto& action) {
auto& tab = active_tab();
String user_agent;
if (GUI::InputBox::show(this, user_agent, "Enter User Agent:", "Custom User Agent") != GUI::InputBox::ExecOK || user_agent.is_empty() || user_agent.is_null()) {
m_disable_user_agent_spoofing->activate();
return;
}
if (tab.m_type == Tab::Type::InProcessWebView) {
Web::ResourceLoader::the().set_user_agent(user_agent);
} else {
tab.m_web_content_view->debug_request("spoof-user-agent", user_agent);
}
action.set_status_tip(user_agent);
});
spoof_user_agent_menu.add_action(custom_user_agent);
m_user_agent_spoof_actions.add_action(custom_user_agent);
auto& help_menu = menubar->add_menu("&Help");
help_menu.add_action(WindowActions::the().about_action());
set_menubar(move(menubar));
}
GUI::TabWidget& BrowserWindow::tab_widget()
{
return *m_tab_widget;
}
Tab& BrowserWindow::active_tab()
{
return downcast<Tab>(*tab_widget().active_widget());
}
void BrowserWindow::set_window_title_for_tab(Tab const& tab)
{
auto& title = tab.title();

View file

@ -8,6 +8,7 @@
#include "BookmarksBarWidget.h"
#include "WindowActions.h"
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Window.h>
namespace Browser {
@ -22,17 +23,23 @@ public:
virtual ~BrowserWindow() override;
GUI::TabWidget& tab_widget();
Tab& active_tab();
void create_new_tab(URL, bool activate);
private:
explicit BrowserWindow(CookieJar&, URL);
void build_menus();
void set_window_title_for_tab(Tab const&);
CookieJar& m_cookie_jar;
WindowActions m_window_actions;
RefPtr<GUI::TabWidget> m_tab_widget;
RefPtr<BookmarksBarWidget> m_bookmarks_bar;
GUI::ActionGroup m_user_agent_spoof_actions;
GUI::ActionGroup m_search_engine_actions;
RefPtr<GUI::Action> m_disable_user_agent_spoofing;
};
}

View file

@ -10,27 +10,20 @@
#include "Browser.h"
#include "ConsoleWidget.h"
#include "DownloadWidget.h"
#include "InspectorWidget.h"
#include "WindowActions.h"
#include <AK/StringBuilder.h>
#include <Applications/Browser/TabGML.h>
#include <LibCore/ConfigFile.h>
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/Clipboard.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Menubar.h>
#include <LibGUI/Statusbar.h>
#include <LibGUI/TabWidget.h>
#include <LibGUI/TextBox.h>
#include <LibGUI/Toolbar.h>
#include <LibGUI/ToolbarContainer.h>
#include <LibGUI/Window.h>
#include <LibJS/Interpreter.h>
#include <LibWeb/Dump.h>
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Layout/BlockBox.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
@ -40,8 +33,6 @@
namespace Browser {
String g_search_engine = {};
URL url_from_user_input(const String& input)
{
if (input.starts_with("?") && !g_search_engine.is_null()) {
@ -284,289 +275,6 @@ Tab::Tab(Type type)
load(url);
};
m_menubar = GUI::Menubar::construct();
auto& file_menu = m_menubar->add_menu("&File");
file_menu.add_action(WindowActions::the().create_new_tab_action());
auto close_tab_action = GUI::Action::create(
"&Close Tab", { Mod_Ctrl, Key_W }, Gfx::Bitmap::load_from_file("/res/icons/16x16/close-tab.png"), [this](auto&) {
on_tab_close_request(*this);
},
this);
close_tab_action->set_status_tip("Close current tab");
file_menu.add_action(close_tab_action);
file_menu.add_separator();
file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();
}));
auto& view_menu = m_menubar->add_menu("&View");
view_menu.add_action(WindowActions::the().show_bookmarks_bar_action());
view_menu.add_separator();
view_menu.add_action(GUI::CommonActions::make_fullscreen_action(
[this](auto&) {
window()->set_fullscreen(!window()->is_fullscreen());
auto is_fullscreen = window()->is_fullscreen();
auto* tab_widget = static_cast<GUI::TabWidget*>(parent_widget());
tab_widget->set_bar_visible(!is_fullscreen && tab_widget->children().size() > 1);
m_toolbar_container->set_visible(!is_fullscreen);
m_statusbar->set_visible(!is_fullscreen);
if (is_fullscreen) {
view().set_frame_thickness(0);
} else {
view().set_frame_thickness(2);
}
},
this));
auto& go_menu = m_menubar->add_menu("&Go");
go_menu.add_action(*m_go_back_action);
go_menu.add_action(*m_go_forward_action);
go_menu.add_action(*m_go_home_action);
go_menu.add_separator();
go_menu.add_action(*m_reload_action);
auto view_source_action = GUI::Action::create(
"View &Source", { Mod_Ctrl, Key_U }, [this](auto&) {
if (m_type == Type::InProcessWebView) {
VERIFY(m_page_view->document());
auto url = m_page_view->document()->url();
auto source = m_page_view->document()->source();
view_source(url, source);
} else {
m_web_content_view->get_source();
}
},
this);
view_source_action->set_status_tip("View source code of the current page");
auto inspect_dom_tree_action = GUI::Action::create(
"Inspect &DOM Tree", { Mod_None, Key_F12 }, [this](auto&) {
if (m_type == Type::InProcessWebView) {
if (!m_dom_inspector_window) {
m_dom_inspector_window = GUI::Window::construct(window());
m_dom_inspector_window->resize(300, 500);
m_dom_inspector_window->set_title("DOM inspector");
m_dom_inspector_window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png"));
m_dom_inspector_window->set_main_widget<InspectorWidget>();
}
auto* inspector_widget = static_cast<InspectorWidget*>(m_dom_inspector_window->main_widget());
inspector_widget->set_document(m_page_view->document());
m_dom_inspector_window->show();
m_dom_inspector_window->move_to_front();
} else {
TODO();
}
},
this);
inspect_dom_tree_action->set_status_tip("Open DOM inspector window for this page");
auto& inspect_menu = m_menubar->add_menu("&Inspect");
inspect_menu.add_action(*view_source_action);
inspect_menu.add_action(*inspect_dom_tree_action);
auto js_console_action = GUI::Action::create(
"Open &JS Console", { Mod_Ctrl, Key_I }, [this](auto&) {
if (m_type == Type::InProcessWebView) {
if (!m_console_window) {
m_console_window = GUI::Window::construct(window());
m_console_window->resize(500, 300);
m_console_window->set_title("JS Console");
m_console_window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-javascript.png"));
m_console_window->set_main_widget<ConsoleWidget>();
}
auto* console_widget = static_cast<ConsoleWidget*>(m_console_window->main_widget());
console_widget->set_interpreter(m_page_view->document()->interpreter().make_weak_ptr());
m_console_window->show();
m_console_window->move_to_front();
} else {
if (!m_console_window) {
m_console_window = GUI::Window::construct(window());
m_console_window->resize(500, 300);
m_console_window->set_title("JS Console");
m_console_window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-javascript.png"));
m_console_window->set_main_widget<ConsoleWidget>();
}
auto* console_widget = static_cast<ConsoleWidget*>(m_console_window->main_widget());
console_widget->on_js_input = [this](const String& js_source) {
m_web_content_view->js_console_input(js_source);
};
console_widget->clear_output();
m_web_content_view->js_console_initialize();
m_console_window->show();
m_console_window->move_to_front();
}
},
this);
js_console_action->set_status_tip("Open JavaScript console for this page");
inspect_menu.add_action(js_console_action);
auto& settings_menu = m_menubar->add_menu("&Settings");
m_search_engine_actions.set_exclusive(true);
auto& search_engine_menu = settings_menu.add_submenu("&Search Engine");
auto add_search_engine = [&](auto& name, auto& url_format) {
auto action = GUI::Action::create_checkable(
name, [&](auto&) {
g_search_engine = url_format;
auto m_config = Core::ConfigFile::get_for_app("Browser");
m_config->write_entry("Preferences", "SearchEngine", g_search_engine);
},
this);
search_engine_menu.add_action(action);
m_search_engine_actions.add_action(action);
if (g_search_engine == url_format) {
action->set_checked(true);
}
action->set_status_tip(url_format);
};
auto disable_search_engine_action = GUI::Action::create_checkable(
"Disable", [this](auto&) {
g_search_engine = {};
auto m_config = Core::ConfigFile::get_for_app("Browser");
m_config->write_entry("Preferences", "SearchEngine", g_search_engine);
},
this);
search_engine_menu.add_action(disable_search_engine_action);
m_search_engine_actions.add_action(disable_search_engine_action);
disable_search_engine_action->set_checked(true);
// FIXME: Support adding custom search engines
add_search_engine("Bing", "https://www.bing.com/search?q={}");
add_search_engine("DuckDuckGo", "https://duckduckgo.com/?q={}");
add_search_engine("FrogFind", "http://frogfind.com/?q={}");
add_search_engine("GitHub", "https://github.com/search?q={}");
add_search_engine("Google", "https://google.com/search?q={}");
add_search_engine("Yandex", "https://yandex.com/search/?text={}");
auto& debug_menu = m_menubar->add_menu("&Debug");
debug_menu.add_action(GUI::Action::create(
"Dump &DOM Tree", [this](auto&) {
if (m_type == Type::InProcessWebView) {
Web::dump_tree(*m_page_view->document());
} else {
m_web_content_view->debug_request("dump-dom-tree");
}
},
this));
debug_menu.add_action(GUI::Action::create(
"Dump &Layout Tree", [this](auto&) {
if (m_type == Type::InProcessWebView) {
Web::dump_tree(*m_page_view->document()->layout_node());
} else {
m_web_content_view->debug_request("dump-layout-tree");
}
},
this));
debug_menu.add_action(GUI::Action::create(
"Dump &Style Sheets", [this](auto&) {
if (m_type == Type::InProcessWebView) {
for (auto& sheet : m_page_view->document()->style_sheets().sheets()) {
Web::dump_sheet(sheet);
}
} else {
m_web_content_view->debug_request("dump-style-sheets");
}
},
this));
debug_menu.add_action(GUI::Action::create("Dump &History", { Mod_Ctrl, Key_H }, [&](auto&) {
m_history.dump();
}));
debug_menu.add_action(GUI::Action::create("Dump C&ookies", [&](auto&) {
if (on_dump_cookies)
on_dump_cookies();
}));
debug_menu.add_separator();
auto line_box_borders_action = GUI::Action::create_checkable(
"&Line Box Borders", [this](auto& action) {
if (m_type == Type::InProcessWebView) {
m_page_view->set_should_show_line_box_borders(action.is_checked());
m_page_view->update();
} else {
m_web_content_view->debug_request("set-line-box-borders", action.is_checked() ? "on" : "off");
}
},
this);
line_box_borders_action->set_checked(false);
debug_menu.add_action(line_box_borders_action);
debug_menu.add_separator();
debug_menu.add_action(GUI::Action::create("Collect &Garbage", { Mod_Ctrl | Mod_Shift, Key_G }, [this](auto&) {
if (m_type == Type::InProcessWebView) {
if (auto* document = m_page_view->document()) {
document->interpreter().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true);
}
} else {
m_web_content_view->debug_request("collect-garbage");
}
}));
debug_menu.add_action(GUI::Action::create("Clear &Cache", { Mod_Ctrl | Mod_Shift, Key_C }, [this](auto&) {
if (m_type == Type::InProcessWebView) {
Web::ResourceLoader::the().clear_cache();
} else {
m_web_content_view->debug_request("clear-cache");
}
}));
m_user_agent_spoof_actions.set_exclusive(true);
auto& spoof_user_agent_menu = debug_menu.add_submenu("Spoof User Agent");
m_disable_user_agent_spoofing = GUI::Action::create_checkable("Disabled", [&](auto&) {
if (m_type == Type::InProcessWebView) {
Web::ResourceLoader::the().set_user_agent(Web::default_user_agent);
} else {
m_web_content_view->debug_request("spoof-user-agent", Web::default_user_agent);
}
});
m_disable_user_agent_spoofing->set_status_tip(Web::default_user_agent);
spoof_user_agent_menu.add_action(*m_disable_user_agent_spoofing);
m_user_agent_spoof_actions.add_action(*m_disable_user_agent_spoofing);
m_disable_user_agent_spoofing->set_checked(true);
auto add_user_agent = [&](auto& name, auto& user_agent) {
auto action = GUI::Action::create_checkable(name, [&](auto&) {
if (m_type == Type::InProcessWebView) {
Web::ResourceLoader::the().set_user_agent(user_agent);
} else {
m_web_content_view->debug_request("spoof-user-agent", user_agent);
}
});
action->set_status_tip(user_agent);
spoof_user_agent_menu.add_action(action);
m_user_agent_spoof_actions.add_action(action);
};
add_user_agent("Chrome Linux Desktop", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36");
add_user_agent("Firefox Linux Desktop", "Mozilla/5.0 (X11; Linux i686; rv:87.0) Gecko/20100101 Firefox/87.0");
add_user_agent("Safari macOS Desktop", "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15");
add_user_agent("Chrome Android Mobile", "Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.66 Mobile Safari/537.36");
add_user_agent("Firefox Android Mobile", "Mozilla/5.0 (Android 11; Mobile; rv:68.0) Gecko/68.0 Firefox/86.0");
add_user_agent("Safari iOS Mobile", "Mozilla/5.0 (iPhone; CPU iPhone OS 14_4_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1");
auto custom_user_agent = GUI::Action::create_checkable("Custom", [&](auto& action) {
String user_agent;
if (GUI::InputBox::show(window(), user_agent, "Enter User Agent:", "Custom User Agent") != GUI::InputBox::ExecOK || user_agent.is_empty() || user_agent.is_null()) {
m_disable_user_agent_spoofing->activate();
return;
}
if (m_type == Type::InProcessWebView) {
Web::ResourceLoader::the().set_user_agent(user_agent);
} else {
m_web_content_view->debug_request("spoof-user-agent", user_agent);
}
action.set_status_tip(user_agent);
});
spoof_user_agent_menu.add_action(custom_user_agent);
m_user_agent_spoof_actions.add_action(custom_user_agent);
auto& help_menu = m_menubar->add_menu("&Help");
help_menu.add_action(WindowActions::the().about_action());
m_tab_context_menu = GUI::Menu::construct();
m_tab_context_menu->add_action(GUI::Action::create("&Reload Tab", [this](auto&) {
m_reload_action->activate();
@ -580,8 +288,8 @@ Tab::Tab(Type type)
m_page_context_menu->add_action(*m_go_forward_action);
m_page_context_menu->add_action(*m_reload_action);
m_page_context_menu->add_separator();
m_page_context_menu->add_action(*view_source_action);
m_page_context_menu->add_action(*inspect_dom_tree_action);
//m_page_context_menu->add_action(*view_source_action);
//m_page_context_menu->add_action(*inspect_dom_tree_action);
hooks().on_context_menu_request = [&](auto& screen_position) {
m_page_context_menu->popup(screen_position);
};
@ -673,8 +381,6 @@ void Tab::did_become_active()
auto is_fullscreen = window()->is_fullscreen();
m_toolbar_container->set_visible(!is_fullscreen);
m_statusbar->set_visible(!is_fullscreen);
window()->set_menubar(m_menubar);
}
void Tab::context_menu_requested(const Gfx::IntPoint& screen_position)

View file

@ -24,6 +24,9 @@ namespace Browser {
class Tab final : public GUI::Widget {
C_OBJECT(Tab);
// FIXME: This should go away eventually.
friend class BrowserWindow;
public:
enum class Type {
InProcessWebView,
@ -88,7 +91,6 @@ private:
RefPtr<GUI::Window> m_dom_inspector_window;
RefPtr<GUI::Window> m_console_window;
RefPtr<GUI::Statusbar> m_statusbar;
RefPtr<GUI::Menubar> m_menubar;
RefPtr<GUI::ToolbarContainer> m_toolbar_container;
RefPtr<GUI::Menu> m_link_context_menu;
@ -99,10 +101,6 @@ private:
Gfx::ShareableBitmap m_image_context_menu_bitmap;
URL m_image_context_menu_url;
GUI::ActionGroup m_user_agent_spoof_actions;
GUI::ActionGroup m_search_engine_actions;
RefPtr<GUI::Action> m_disable_user_agent_spoofing;
RefPtr<GUI::Menu> m_tab_context_menu;
RefPtr<GUI::Menu> m_page_context_menu;

View file

@ -27,6 +27,7 @@
namespace Browser {
String g_search_engine;
String g_home_url;
bool g_single_process = false;